Mercurial > hg > truffle
comparison graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java @ 2616:3558ca7088c0
FrameState and Graphviz changes:
* removed popx, pushx methods from GraphBuilder
* FrameState subclass of Value
* added String shortName() to Node
* added GraphvizPrinter option to use short names
* small hack in GraphvizPrinter: omit FrameState->Local connections
* added GraalGraphviz to implicit classpatch (read from GRAAL env var)
author | Lukas Stadler <lukas.stadler@jku.at> |
---|---|
date | Mon, 09 May 2011 17:00:25 +0200 |
parents | 5768534fd4e5 |
children | dd115f80acf8 |
comparison
equal
deleted
inserted
replaced
2615:5768534fd4e5 | 2616:3558ca7088c0 |
---|---|
180 exceptionHandlers.add(h); | 180 exceptionHandlers.add(h); |
181 } | 181 } |
182 flags |= Flag.HasHandler.mask; | 182 flags |= Flag.HasHandler.mask; |
183 } | 183 } |
184 | 184 |
185 FrameState initialState = frameState.create(-1); | 185 startBlock.mergeOrClone(frameState, rootMethod); |
186 startBlock.mergeOrClone(initialState, rootMethod); | |
187 BlockBegin syncHandler = null; | 186 BlockBegin syncHandler = null; |
188 | 187 |
189 // 3. setup internal state for appending instructions | 188 // 3. setup internal state for appending instructions |
190 curBlock = startBlock; | 189 curBlock = startBlock; |
191 lastInstr = startBlock; | 190 lastInstr = startBlock; |
192 lastInstr.appendNext(null, -1); | 191 lastInstr.appendNext(null, -1); |
193 | 192 |
194 if (isSynchronized(rootMethod.accessFlags())) { | 193 if (isSynchronized(rootMethod.accessFlags())) { |
195 // 4A.1 add a monitor enter to the start block | 194 // 4A.1 add a monitor enter to the start block |
196 rootMethodSynchronizedObject = synchronizedObject(initialState, compilation.method); | 195 rootMethodSynchronizedObject = synchronizedObject(frameState, compilation.method); |
197 genMonitorEnter(rootMethodSynchronizedObject, Instruction.SYNCHRONIZATION_ENTRY_BCI); | 196 genMonitorEnter(rootMethodSynchronizedObject, Instruction.SYNCHRONIZATION_ENTRY_BCI); |
198 // 4A.2 finish the start block | 197 // 4A.2 finish the start block |
199 finishStartBlock(startBlock, stdEntry); | 198 finishStartBlock(startBlock, stdEntry); |
200 | 199 |
201 // 4A.3 setup an exception handler to unlock the root method synchronized object | 200 // 4A.3 setup an exception handler to unlock the root method synchronized object |
249 | 248 |
250 public int nextBCI() { | 249 public int nextBCI() { |
251 return stream.nextBCI(); | 250 return stream.nextBCI(); |
252 } | 251 } |
253 | 252 |
254 private void ipush(Value x) { | |
255 frameState.ipush(x); | |
256 } | |
257 | |
258 private void lpush(Value x) { | |
259 frameState.lpush(x); | |
260 } | |
261 | |
262 private void fpush(Value x) { | |
263 frameState.fpush(x); | |
264 } | |
265 | |
266 private void dpush(Value x) { | |
267 frameState.dpush(x); | |
268 } | |
269 | |
270 private void apush(Value x) { | |
271 frameState.apush(x); | |
272 } | |
273 | |
274 private void wpush(Value x) { | |
275 frameState.wpush(x); | |
276 } | |
277 | |
278 private void push(CiKind kind, Value x) { | |
279 frameState.push(kind, x); | |
280 } | |
281 | |
282 private void pushReturn(CiKind kind, Value x) { | |
283 if (kind != CiKind.Void) { | |
284 frameState.push(kind.stackKind(), x); | |
285 } | |
286 } | |
287 | |
288 private Value ipop() { | |
289 return frameState.ipop(); | |
290 } | |
291 | |
292 private Value lpop() { | |
293 return frameState.lpop(); | |
294 } | |
295 | |
296 private Value fpop() { | |
297 return frameState.fpop(); | |
298 } | |
299 | |
300 private Value dpop() { | |
301 return frameState.dpop(); | |
302 } | |
303 | |
304 private Value apop() { | |
305 return frameState.apop(); | |
306 } | |
307 | |
308 private Value wpop() { | |
309 return frameState.wpop(); | |
310 } | |
311 | |
312 private Value pop(CiKind kind) { | |
313 return frameState.pop(kind); | |
314 } | |
315 | |
316 private CiKind peekKind() { | |
317 Value top = frameState.stackAt(frameState.stackSize() - 1); | |
318 if (top == null) { | |
319 top = frameState.stackAt(frameState.stackSize() - 2); | |
320 assert top != null; | |
321 assert top.kind.isDoubleWord(); | |
322 } | |
323 return top.kind; | |
324 } | |
325 | |
326 private void loadLocal(int index, CiKind kind) { | 253 private void loadLocal(int index, CiKind kind) { |
327 push(kind, frameState.loadLocal(index)); | 254 frameState.push(kind, frameState.loadLocal(index)); |
328 } | 255 } |
329 | 256 |
330 private void storeLocal(CiKind kind, int index) { | 257 private void storeLocal(CiKind kind, int index) { |
331 frameState.storeLocal(index, pop(kind)); | 258 frameState.storeLocal(index, frameState.pop(kind)); |
332 } | 259 } |
333 | 260 |
334 List<ExceptionHandler> handleException(Instruction x, int bci) { | 261 List<ExceptionHandler> handleException(Instruction x, int bci) { |
335 if (!hasHandler()) { | 262 if (!hasHandler()) { |
336 return Util.uncheckedCast(Collections.EMPTY_LIST); | 263 return Util.uncheckedCast(Collections.EMPTY_LIST); |
378 | 305 |
379 assert entry.bci() == handler.handler.handlerBCI(); | 306 assert entry.bci() == handler.handler.handlerBCI(); |
380 assert entryState == null || curState.locksSize() == entryState.locksSize() : "locks do not match : cur:" + curState.locksSize() + " entry:" + entryState.locksSize(); | 307 assert entryState == null || curState.locksSize() == entryState.locksSize() : "locks do not match : cur:" + curState.locksSize() + " entry:" + entryState.locksSize(); |
381 | 308 |
382 // exception handler starts with an empty expression stack | 309 // exception handler starts with an empty expression stack |
383 curState = curState.copyWithEmptyStack(); | 310 curState = curState.duplicateWithEmptyStack(); |
384 | 311 |
385 entry.mergeOrClone(curState, method()); | 312 entry.mergeOrClone(curState, method()); |
386 | 313 |
387 // add current state for correct handling of phi functions | 314 // add current state for correct handling of phi functions |
388 int phiOperand = entry.addExceptionState(curState); | 315 int phiOperand = entry.addExceptionState(curState); |
420 | 347 |
421 if (con instanceof RiType) { | 348 if (con instanceof RiType) { |
422 // this is a load of class constant which might be unresolved | 349 // this is a load of class constant which might be unresolved |
423 RiType riType = (RiType) con; | 350 RiType riType = (RiType) con; |
424 if (!riType.isResolved() || C1XOptions.TestPatching) { | 351 if (!riType.isResolved() || C1XOptions.TestPatching) { |
425 push(CiKind.Object, append(new ResolveClass(riType, RiType.Representation.JavaClass, null, graph))); | 352 frameState.push(CiKind.Object, append(new ResolveClass(riType, RiType.Representation.JavaClass, null, graph))); |
426 } else { | 353 } else { |
427 push(CiKind.Object, append(new Constant(riType.getEncoding(Representation.JavaClass), graph))); | 354 frameState.push(CiKind.Object, append(new Constant(riType.getEncoding(Representation.JavaClass), graph))); |
428 } | 355 } |
429 } else if (con instanceof CiConstant) { | 356 } else if (con instanceof CiConstant) { |
430 CiConstant constant = (CiConstant) con; | 357 CiConstant constant = (CiConstant) con; |
431 push(constant.kind.stackKind(), appendConstant(constant)); | 358 frameState.push(constant.kind.stackKind(), appendConstant(constant)); |
432 } else { | 359 } else { |
433 throw new Error("lookupConstant returned an object of incorrect type"); | 360 throw new Error("lookupConstant returned an object of incorrect type"); |
434 } | 361 } |
435 } | 362 } |
436 | 363 |
437 void genLoadIndexed(CiKind kind) { | 364 void genLoadIndexed(CiKind kind) { |
438 FrameState stateBefore = frameState.create(bci()); | 365 FrameState stateBefore = frameState.create(bci()); |
439 Value index = ipop(); | 366 Value index = frameState.ipop(); |
440 Value array = apop(); | 367 Value array = frameState.apop(); |
441 Value length = null; | 368 Value length = null; |
442 if (cseArrayLength(array)) { | 369 if (cseArrayLength(array)) { |
443 length = append(new ArrayLength(array, stateBefore, graph)); | 370 length = append(new ArrayLength(array, stateBefore, graph)); |
444 } | 371 } |
445 Value v = append(new LoadIndexed(array, index, length, kind, stateBefore, graph)); | 372 Value v = append(new LoadIndexed(array, index, length, kind, stateBefore, graph)); |
446 push(kind.stackKind(), v); | 373 frameState.push(kind.stackKind(), v); |
447 } | 374 } |
448 | 375 |
449 void genStoreIndexed(CiKind kind) { | 376 void genStoreIndexed(CiKind kind) { |
450 FrameState stateBefore = frameState.create(bci()); | 377 FrameState stateBefore = frameState.create(bci()); |
451 Value value = pop(kind.stackKind()); | 378 Value value = frameState.pop(kind.stackKind()); |
452 Value index = ipop(); | 379 Value index = frameState.ipop(); |
453 Value array = apop(); | 380 Value array = frameState.apop(); |
454 Value length = null; | 381 Value length = null; |
455 if (cseArrayLength(array)) { | 382 if (cseArrayLength(array)) { |
456 length = append(new ArrayLength(array, stateBefore, graph)); | 383 length = append(new ArrayLength(array, stateBefore, graph)); |
457 } | 384 } |
458 StoreIndexed result = new StoreIndexed(array, index, length, kind, value, stateBefore, graph); | 385 StoreIndexed result = new StoreIndexed(array, index, length, kind, value, stateBefore, graph); |
550 void genArithmeticOp(CiKind kind, int opcode, FrameState state) { | 477 void genArithmeticOp(CiKind kind, int opcode, FrameState state) { |
551 genArithmeticOp(kind, opcode, kind, kind, state); | 478 genArithmeticOp(kind, opcode, kind, kind, state); |
552 } | 479 } |
553 | 480 |
554 void genArithmeticOp(CiKind result, int opcode, CiKind x, CiKind y, FrameState state) { | 481 void genArithmeticOp(CiKind result, int opcode, CiKind x, CiKind y, FrameState state) { |
555 Value yValue = pop(y); | 482 Value yValue = frameState.pop(y); |
556 Value xValue = pop(x); | 483 Value xValue = frameState.pop(x); |
557 Value result1 = append(new ArithmeticOp(opcode, result, xValue, yValue, isStrict(method().accessFlags()), state, graph)); | 484 Value result1 = append(new ArithmeticOp(opcode, result, xValue, yValue, isStrict(method().accessFlags()), state, graph)); |
558 push(result, result1); | 485 frameState.push(result, result1); |
559 } | 486 } |
560 | 487 |
561 void genNegateOp(CiKind kind) { | 488 void genNegateOp(CiKind kind) { |
562 push(kind, append(new NegateOp(pop(kind), graph))); | 489 frameState.push(kind, append(new NegateOp(frameState.pop(kind), graph))); |
563 } | 490 } |
564 | 491 |
565 void genShiftOp(CiKind kind, int opcode) { | 492 void genShiftOp(CiKind kind, int opcode) { |
566 Value s = ipop(); | 493 Value s = frameState.ipop(); |
567 Value x = pop(kind); | 494 Value x = frameState.pop(kind); |
568 // note that strength reduction of e << K >>> K is correctly handled in canonicalizer now | 495 // note that strength reduction of e << K >>> K is correctly handled in canonicalizer now |
569 push(kind, append(new ShiftOp(opcode, x, s, graph))); | 496 frameState.push(kind, append(new ShiftOp(opcode, x, s, graph))); |
570 } | 497 } |
571 | 498 |
572 void genLogicOp(CiKind kind, int opcode) { | 499 void genLogicOp(CiKind kind, int opcode) { |
573 Value y = pop(kind); | 500 Value y = frameState.pop(kind); |
574 Value x = pop(kind); | 501 Value x = frameState.pop(kind); |
575 push(kind, append(new LogicOp(opcode, x, y, graph))); | 502 frameState.push(kind, append(new LogicOp(opcode, x, y, graph))); |
576 } | 503 } |
577 | 504 |
578 void genCompareOp(CiKind kind, int opcode, CiKind resultKind) { | 505 void genCompareOp(CiKind kind, int opcode, CiKind resultKind) { |
579 Value y = pop(kind); | 506 Value y = frameState.pop(kind); |
580 Value x = pop(kind); | 507 Value x = frameState.pop(kind); |
581 Value value = append(new CompareOp(opcode, resultKind, x, y, graph)); | 508 Value value = append(new CompareOp(opcode, resultKind, x, y, graph)); |
582 if (!resultKind.isVoid()) { | 509 if (!resultKind.isVoid()) { |
583 ipush(value); | 510 frameState.ipush(value); |
584 } | 511 } |
585 } | 512 } |
586 | 513 |
587 void genConvert(int opcode, CiKind from, CiKind to) { | 514 void genConvert(int opcode, CiKind from, CiKind to) { |
588 CiKind tt = to.stackKind(); | 515 CiKind tt = to.stackKind(); |
589 push(tt, append(new Convert(opcode, pop(from.stackKind()), tt, graph))); | 516 frameState.push(tt, append(new Convert(opcode, frameState.pop(from.stackKind()), tt, graph))); |
590 } | 517 } |
591 | 518 |
592 void genIncrement() { | 519 void genIncrement() { |
593 int index = stream().readLocalIndex(); | 520 int index = stream().readLocalIndex(); |
594 int delta = stream().readIncrement(); | 521 int delta = stream().readIncrement(); |
611 } | 538 } |
612 | 539 |
613 void genIfZero(Condition cond) { | 540 void genIfZero(Condition cond) { |
614 Value y = appendConstant(CiConstant.INT_0); | 541 Value y = appendConstant(CiConstant.INT_0); |
615 FrameState stateBefore = frameState.create(bci()); | 542 FrameState stateBefore = frameState.create(bci()); |
616 Value x = ipop(); | 543 Value x = frameState.ipop(); |
617 ifNode(x, cond, y, stateBefore); | 544 ifNode(x, cond, y, stateBefore); |
618 } | 545 } |
619 | 546 |
620 void genIfNull(Condition cond) { | 547 void genIfNull(Condition cond) { |
621 FrameState stateBefore = frameState.create(bci()); | 548 FrameState stateBefore = frameState.create(bci()); |
622 Value y = appendConstant(CiConstant.NULL_OBJECT); | 549 Value y = appendConstant(CiConstant.NULL_OBJECT); |
623 Value x = apop(); | 550 Value x = frameState.apop(); |
624 ifNode(x, cond, y, stateBefore); | 551 ifNode(x, cond, y, stateBefore); |
625 } | 552 } |
626 | 553 |
627 void genIfSame(CiKind kind, Condition cond) { | 554 void genIfSame(CiKind kind, Condition cond) { |
628 FrameState stateBefore = frameState.create(bci()); | 555 FrameState stateBefore = frameState.create(bci()); |
629 Value y = pop(kind); | 556 Value y = frameState.pop(kind); |
630 Value x = pop(kind); | 557 Value x = frameState.pop(kind); |
631 ifNode(x, cond, y, stateBefore); | 558 ifNode(x, cond, y, stateBefore); |
632 } | 559 } |
633 | 560 |
634 void genThrow(int bci) { | 561 void genThrow(int bci) { |
635 FrameState stateBefore = frameState.create(bci()); | 562 FrameState stateBefore = frameState.create(bci()); |
636 Throw t = new Throw(apop(), stateBefore, !noSafepoints(), graph); | 563 Throw t = new Throw(frameState.apop(), stateBefore, !noSafepoints(), graph); |
637 appendWithoutOptimization(t, bci); | 564 appendWithoutOptimization(t, bci); |
638 } | 565 } |
639 | 566 |
640 void genCheckCast() { | 567 void genCheckCast() { |
641 int cpi = stream().readCPI(); | 568 int cpi = stream().readCPI(); |
642 RiType type = constantPool().lookupType(cpi, CHECKCAST); | 569 RiType type = constantPool().lookupType(cpi, CHECKCAST); |
643 boolean isInitialized = !C1XOptions.TestPatching && type.isResolved() && type.isInitialized(); | 570 boolean isInitialized = !C1XOptions.TestPatching && type.isResolved() && type.isInitialized(); |
644 Value typeInstruction = genResolveClass(RiType.Representation.ObjectHub, type, isInitialized, cpi); | 571 Value typeInstruction = genResolveClass(RiType.Representation.ObjectHub, type, isInitialized, cpi); |
645 CheckCast c = new CheckCast(type, typeInstruction, apop(), null, graph); | 572 CheckCast c = new CheckCast(type, typeInstruction, frameState.apop(), null, graph); |
646 apush(append(c)); | 573 frameState.apush(append(c)); |
647 checkForDirectCompare(c); | 574 checkForDirectCompare(c); |
648 } | 575 } |
649 | 576 |
650 void genInstanceOf() { | 577 void genInstanceOf() { |
651 int cpi = stream().readCPI(); | 578 int cpi = stream().readCPI(); |
652 RiType type = constantPool().lookupType(cpi, INSTANCEOF); | 579 RiType type = constantPool().lookupType(cpi, INSTANCEOF); |
653 boolean isInitialized = !C1XOptions.TestPatching && type.isResolved() && type.isInitialized(); | 580 boolean isInitialized = !C1XOptions.TestPatching && type.isResolved() && type.isInitialized(); |
654 Value typeInstruction = genResolveClass(RiType.Representation.ObjectHub, type, isInitialized, cpi); | 581 Value typeInstruction = genResolveClass(RiType.Representation.ObjectHub, type, isInitialized, cpi); |
655 InstanceOf i = new InstanceOf(type, typeInstruction, apop(), null, graph); | 582 InstanceOf i = new InstanceOf(type, typeInstruction, frameState.apop(), null, graph); |
656 ipush(append(i)); | 583 frameState.ipush(append(i)); |
657 checkForDirectCompare(i); | 584 checkForDirectCompare(i); |
658 } | 585 } |
659 | 586 |
660 private void checkForDirectCompare(TypeCheck check) { | 587 private void checkForDirectCompare(TypeCheck check) { |
661 RiType type = check.targetClass(); | 588 RiType type = check.targetClass(); |
669 RiType type = constantPool().lookupType(cpi, NEW); | 596 RiType type = constantPool().lookupType(cpi, NEW); |
670 NewInstance n = new NewInstance(type, cpi, constantPool(), stateBefore, graph); | 597 NewInstance n = new NewInstance(type, cpi, constantPool(), stateBefore, graph); |
671 if (memoryMap != null) { | 598 if (memoryMap != null) { |
672 memoryMap.newInstance(n); | 599 memoryMap.newInstance(n); |
673 } | 600 } |
674 apush(append(n)); | 601 frameState.apush(append(n)); |
675 } | 602 } |
676 | 603 |
677 void genNewTypeArray(int typeCode) { | 604 void genNewTypeArray(int typeCode) { |
678 FrameState stateBefore = frameState.create(bci()); | 605 FrameState stateBefore = frameState.create(bci()); |
679 CiKind kind = CiKind.fromArrayTypeCode(typeCode); | 606 CiKind kind = CiKind.fromArrayTypeCode(typeCode); |
680 RiType elementType = compilation.runtime.asRiType(kind); | 607 RiType elementType = compilation.runtime.asRiType(kind); |
681 apush(append(new NewTypeArray(ipop(), elementType, stateBefore, graph))); | 608 frameState.apush(append(new NewTypeArray(frameState.ipop(), elementType, stateBefore, graph))); |
682 } | 609 } |
683 | 610 |
684 void genNewObjectArray(int cpi) { | 611 void genNewObjectArray(int cpi) { |
685 RiType type = constantPool().lookupType(cpi, ANEWARRAY); | 612 RiType type = constantPool().lookupType(cpi, ANEWARRAY); |
686 FrameState stateBefore = frameState.create(bci()); | 613 FrameState stateBefore = frameState.create(bci()); |
687 NewArray n = new NewObjectArray(type, ipop(), stateBefore, graph); | 614 NewArray n = new NewObjectArray(type, frameState.ipop(), stateBefore, graph); |
688 apush(append(n)); | 615 frameState.apush(append(n)); |
689 } | 616 } |
690 | 617 |
691 void genNewMultiArray(int cpi) { | 618 void genNewMultiArray(int cpi) { |
692 RiType type = constantPool().lookupType(cpi, MULTIANEWARRAY); | 619 RiType type = constantPool().lookupType(cpi, MULTIANEWARRAY); |
693 FrameState stateBefore = frameState.create(bci()); | 620 FrameState stateBefore = frameState.create(bci()); |
694 int rank = stream().readUByte(bci() + 3); | 621 int rank = stream().readUByte(bci() + 3); |
695 Value[] dims = new Value[rank]; | 622 Value[] dims = new Value[rank]; |
696 for (int i = rank - 1; i >= 0; i--) { | 623 for (int i = rank - 1; i >= 0; i--) { |
697 dims[i] = ipop(); | 624 dims[i] = frameState.ipop(); |
698 } | 625 } |
699 NewArray n = new NewMultiArray(type, dims, stateBefore, cpi, constantPool(), graph); | 626 NewArray n = new NewMultiArray(type, dims, stateBefore, cpi, constantPool(), graph); |
700 apush(append(n)); | 627 frameState.apush(append(n)); |
701 } | 628 } |
702 | 629 |
703 void genGetField(int cpi, RiField field) { | 630 void genGetField(int cpi, RiField field) { |
704 // Must copy the state here, because the field holder must still be on the stack. | 631 // Must copy the state here, because the field holder must still be on the stack. |
705 FrameState stateBefore = frameState.create(bci()); | 632 FrameState stateBefore = frameState.create(bci()); |
706 LoadField load = new LoadField(apop(), field, stateBefore, graph); | 633 LoadField load = new LoadField(frameState.apop(), field, stateBefore, graph); |
707 appendOptimizedLoadField(field.kind(), load); | 634 appendOptimizedLoadField(field.kind(), load); |
708 } | 635 } |
709 | 636 |
710 void genPutField(int cpi, RiField field) { | 637 void genPutField(int cpi, RiField field) { |
711 // Must copy the state here, because the field holder must still be on the stack. | 638 // Must copy the state here, because the field holder must still be on the stack. |
712 FrameState stateBefore = frameState.create(bci()); | 639 FrameState stateBefore = frameState.create(bci()); |
713 Value value = pop(field.kind().stackKind()); | 640 Value value = frameState.pop(field.kind().stackKind()); |
714 appendOptimizedStoreField(new StoreField(apop(), field, value, stateBefore, graph)); | 641 appendOptimizedStoreField(new StoreField(frameState.apop(), field, value, stateBefore, graph)); |
715 } | 642 } |
716 | 643 |
717 void genGetStatic(int cpi, RiField field) { | 644 void genGetStatic(int cpi, RiField field) { |
718 RiType holder = field.holder(); | 645 RiType holder = field.holder(); |
719 boolean isInitialized = !C1XOptions.TestPatching && field.isResolved(); | 646 boolean isInitialized = !C1XOptions.TestPatching && field.isResolved(); |
720 CiConstant constantValue = null; | 647 CiConstant constantValue = null; |
721 if (isInitialized) { | 648 if (isInitialized) { |
722 constantValue = field.constantValue(null); | 649 constantValue = field.constantValue(null); |
723 } | 650 } |
724 if (constantValue != null) { | 651 if (constantValue != null) { |
725 push(constantValue.kind.stackKind(), appendConstant(constantValue)); | 652 frameState.push(constantValue.kind.stackKind(), appendConstant(constantValue)); |
726 } else { | 653 } else { |
727 Value container = genResolveClass(RiType.Representation.StaticFields, holder, field.isResolved(), cpi); | 654 Value container = genResolveClass(RiType.Representation.StaticFields, holder, field.isResolved(), cpi); |
728 LoadField load = new LoadField(container, field, null, graph); | 655 LoadField load = new LoadField(container, field, null, graph); |
729 appendOptimizedLoadField(field.kind(), load); | 656 appendOptimizedLoadField(field.kind(), load); |
730 } | 657 } |
731 } | 658 } |
732 | 659 |
733 void genPutStatic(int cpi, RiField field) { | 660 void genPutStatic(int cpi, RiField field) { |
734 RiType holder = field.holder(); | 661 RiType holder = field.holder(); |
735 Value container = genResolveClass(RiType.Representation.StaticFields, holder, field.isResolved(), cpi); | 662 Value container = genResolveClass(RiType.Representation.StaticFields, holder, field.isResolved(), cpi); |
736 Value value = pop(field.kind().stackKind()); | 663 Value value = frameState.pop(field.kind().stackKind()); |
737 StoreField store = new StoreField(container, field, value, null, graph); | 664 StoreField store = new StoreField(container, field, value, null, graph); |
738 appendOptimizedStoreField(store); | 665 appendOptimizedStoreField(store); |
739 } | 666 } |
740 | 667 |
741 private Value genResolveClass(RiType.Representation representation, RiType holder, boolean initialized, int cpi) { | 668 private Value genResolveClass(RiType.Representation representation, RiType holder, boolean initialized, int cpi) { |
762 private void appendOptimizedLoadField(CiKind kind, LoadField load) { | 689 private void appendOptimizedLoadField(CiKind kind, LoadField load) { |
763 if (memoryMap != null) { | 690 if (memoryMap != null) { |
764 Value replacement = memoryMap.load(load); | 691 Value replacement = memoryMap.load(load); |
765 if (replacement != load) { | 692 if (replacement != load) { |
766 // the memory buffer found a replacement for this load (no need to append) | 693 // the memory buffer found a replacement for this load (no need to append) |
767 push(kind.stackKind(), replacement); | 694 frameState.push(kind.stackKind(), replacement); |
768 return; | 695 return; |
769 } | 696 } |
770 } | 697 } |
771 // append the load to the instruction | 698 // append the load to the instruction |
772 Value optimized = append(load); | 699 Value optimized = append(load); |
773 if (memoryMap != null && optimized != load) { | 700 if (memoryMap != null && optimized != load) { |
774 // local optimization happened, replace its value in the memory map | 701 // local optimization happened, replace its value in the memory map |
775 memoryMap.setResult(load, optimized); | 702 memoryMap.setResult(load, optimized); |
776 } | 703 } |
777 push(kind.stackKind(), optimized); | 704 frameState.push(kind.stackKind(), optimized); |
778 } | 705 } |
779 | 706 |
780 void genInvokeStatic(RiMethod target, int cpi, RiConstantPool constantPool) { | 707 void genInvokeStatic(RiMethod target, int cpi, RiConstantPool constantPool) { |
781 RiType holder = target.holder(); | 708 RiType holder = target.holder(); |
782 boolean isInitialized = !C1XOptions.TestPatching && target.isResolved() && holder.isInitialized(); | 709 boolean isInitialized = !C1XOptions.TestPatching && target.isResolved() && holder.isInitialized(); |
902 } | 829 } |
903 | 830 |
904 private void appendInvoke(int opcode, RiMethod target, Value[] args, int cpi, RiConstantPool constantPool, FrameState stateBefore) { | 831 private void appendInvoke(int opcode, RiMethod target, Value[] args, int cpi, RiConstantPool constantPool, FrameState stateBefore) { |
905 CiKind resultType = returnKind(target); | 832 CiKind resultType = returnKind(target); |
906 Value result = append(new Invoke(opcode, resultType.stackKind(), args, target, target.signature().returnType(compilation.method.holder()), stateBefore, graph)); | 833 Value result = append(new Invoke(opcode, resultType.stackKind(), args, target, target.signature().returnType(compilation.method.holder()), stateBefore, graph)); |
907 pushReturn(resultType, result); | 834 frameState.pushReturn(resultType, result); |
908 } | 835 } |
909 | 836 |
910 private RiType getExactType(RiType staticType, Value receiver) { | 837 private RiType getExactType(RiType staticType, Value receiver) { |
911 RiType exact = staticType.exactType(); | 838 RiType exact = staticType.exactType(); |
912 if (exact == null) { | 839 if (exact == null) { |
1090 int offset = ts.defaultOffset(); | 1017 int offset = ts.defaultOffset(); |
1091 isBackwards |= offset < 0; // if the default successor is backwards | 1018 isBackwards |= offset < 0; // if the default successor is backwards |
1092 list.add(blockAt(bci + offset)); | 1019 list.add(blockAt(bci + offset)); |
1093 boolean isSafepoint = isBackwards && !noSafepoints(); | 1020 boolean isSafepoint = isBackwards && !noSafepoints(); |
1094 FrameState stateBefore = isSafepoint ? frameState.create(bci()) : null; | 1021 FrameState stateBefore = isSafepoint ? frameState.create(bci()) : null; |
1095 append(new TableSwitch(ipop(), list, ts.lowKey(), stateBefore, isSafepoint, graph)); | 1022 append(new TableSwitch(frameState.ipop(), list, ts.lowKey(), stateBefore, isSafepoint, graph)); |
1096 } | 1023 } |
1097 | 1024 |
1098 void genLookupswitch() { | 1025 void genLookupswitch() { |
1099 int bci = bci(); | 1026 int bci = bci(); |
1100 BytecodeLookupSwitch ls = new BytecodeLookupSwitch(stream(), bci); | 1027 BytecodeLookupSwitch ls = new BytecodeLookupSwitch(stream(), bci); |
1112 int offset = ls.defaultOffset(); | 1039 int offset = ls.defaultOffset(); |
1113 isBackwards |= offset < 0; // if the default successor is backwards | 1040 isBackwards |= offset < 0; // if the default successor is backwards |
1114 list.add(blockAt(bci + offset)); | 1041 list.add(blockAt(bci + offset)); |
1115 boolean isSafepoint = isBackwards && !noSafepoints(); | 1042 boolean isSafepoint = isBackwards && !noSafepoints(); |
1116 FrameState stateBefore = isSafepoint ? frameState.create(bci()) : null; | 1043 FrameState stateBefore = isSafepoint ? frameState.create(bci()) : null; |
1117 append(new LookupSwitch(ipop(), list, keys, stateBefore, isSafepoint, graph)); | 1044 append(new LookupSwitch(frameState.ipop(), list, keys, stateBefore, isSafepoint, graph)); |
1118 } | 1045 } |
1119 | 1046 |
1120 /** | 1047 /** |
1121 * Determines whether the length of an array should be extracted out as a separate instruction | 1048 * Determines whether the length of an array should be extracted out as a separate instruction |
1122 * before an array indexing instruction. This exposes it to CSE. | 1049 * before an array indexing instruction. This exposes it to CSE. |
1215 BlockBegin result = blockAtOrNull(bci); | 1142 BlockBegin result = blockAtOrNull(bci); |
1216 assert result != null : "Expected a block to begin at " + bci; | 1143 assert result != null : "Expected a block to begin at " + bci; |
1217 return result; | 1144 return result; |
1218 } | 1145 } |
1219 | 1146 |
1220 private Value synchronizedObject(FrameState curState2, RiMethod target) { | 1147 private Value synchronizedObject(FrameStateAccess curState2, RiMethod target) { |
1221 if (isStatic(target.accessFlags())) { | 1148 if (isStatic(target.accessFlags())) { |
1222 Constant classConstant = new Constant(target.holder().getEncoding(Representation.JavaClass), graph); | 1149 Constant classConstant = new Constant(target.holder().getEncoding(Representation.JavaClass), graph); |
1223 return appendWithoutOptimization(classConstant, Instruction.SYNCHRONIZATION_ENTRY_BCI); | 1150 return appendWithoutOptimization(classConstant, Instruction.SYNCHRONIZATION_ENTRY_BCI); |
1224 } else { | 1151 } else { |
1225 return curState2.localAt(0); | 1152 return curState2.localAt(0); |
1250 } | 1177 } |
1251 } | 1178 } |
1252 // exit the monitor | 1179 // exit the monitor |
1253 genMonitorExit(lock, Instruction.SYNCHRONIZATION_ENTRY_BCI); | 1180 genMonitorExit(lock, Instruction.SYNCHRONIZATION_ENTRY_BCI); |
1254 | 1181 |
1255 apush(exception); | 1182 frameState.apush(exception); |
1256 genThrow(bci); | 1183 genThrow(bci); |
1257 BlockEnd end = (BlockEnd) lastInstr; | 1184 BlockEnd end = (BlockEnd) lastInstr; |
1258 curBlock.setEnd(end); | 1185 curBlock.setEnd(end); |
1259 end.setStateAfter(frameState.create(bci())); | 1186 end.setStateAfter(frameState.create(bci())); |
1260 | 1187 |
1261 curBlock = origBlock; | 1188 curBlock = origBlock; |
1262 frameState.initializeFrom(origState); | 1189 frameState.initializeFrom(origState); |
1190 origState.delete(); | |
1263 lastInstr = origLast; | 1191 lastInstr = origLast; |
1264 } | 1192 } |
1265 | 1193 |
1266 private void iterateAllBlocks() { | 1194 private void iterateAllBlocks() { |
1267 BlockBegin b; | 1195 BlockBegin b; |
1312 int opcode = stream.currentBC(); | 1240 int opcode = stream.currentBC(); |
1313 | 1241 |
1314 // push an exception object onto the stack if we are parsing an exception handler | 1242 // push an exception object onto the stack if we are parsing an exception handler |
1315 if (pushException) { | 1243 if (pushException) { |
1316 FrameState stateBefore = frameState.create(bci()); | 1244 FrameState stateBefore = frameState.create(bci()); |
1317 apush(append(new ExceptionObject(stateBefore, graph))); | 1245 frameState.apush(append(new ExceptionObject(stateBefore, graph))); |
1318 pushException = false; | 1246 pushException = false; |
1319 } | 1247 } |
1320 | 1248 |
1321 traceState(); | 1249 traceState(); |
1322 traceInstruction(bci, stream, opcode, blockStart); | 1250 traceInstruction(bci, stream, opcode, blockStart); |
1380 int cpi; | 1308 int cpi; |
1381 | 1309 |
1382 // Checkstyle: stop | 1310 // Checkstyle: stop |
1383 switch (opcode) { | 1311 switch (opcode) { |
1384 case NOP : /* nothing to do */ break; | 1312 case NOP : /* nothing to do */ break; |
1385 case ACONST_NULL : apush(appendConstant(CiConstant.NULL_OBJECT)); break; | 1313 case ACONST_NULL : frameState.apush(appendConstant(CiConstant.NULL_OBJECT)); break; |
1386 case ICONST_M1 : ipush(appendConstant(CiConstant.INT_MINUS_1)); break; | 1314 case ICONST_M1 : frameState.ipush(appendConstant(CiConstant.INT_MINUS_1)); break; |
1387 case ICONST_0 : ipush(appendConstant(CiConstant.INT_0)); break; | 1315 case ICONST_0 : frameState.ipush(appendConstant(CiConstant.INT_0)); break; |
1388 case ICONST_1 : ipush(appendConstant(CiConstant.INT_1)); break; | 1316 case ICONST_1 : frameState.ipush(appendConstant(CiConstant.INT_1)); break; |
1389 case ICONST_2 : ipush(appendConstant(CiConstant.INT_2)); break; | 1317 case ICONST_2 : frameState.ipush(appendConstant(CiConstant.INT_2)); break; |
1390 case ICONST_3 : ipush(appendConstant(CiConstant.INT_3)); break; | 1318 case ICONST_3 : frameState.ipush(appendConstant(CiConstant.INT_3)); break; |
1391 case ICONST_4 : ipush(appendConstant(CiConstant.INT_4)); break; | 1319 case ICONST_4 : frameState.ipush(appendConstant(CiConstant.INT_4)); break; |
1392 case ICONST_5 : ipush(appendConstant(CiConstant.INT_5)); break; | 1320 case ICONST_5 : frameState.ipush(appendConstant(CiConstant.INT_5)); break; |
1393 case LCONST_0 : lpush(appendConstant(CiConstant.LONG_0)); break; | 1321 case LCONST_0 : frameState.lpush(appendConstant(CiConstant.LONG_0)); break; |
1394 case LCONST_1 : lpush(appendConstant(CiConstant.LONG_1)); break; | 1322 case LCONST_1 : frameState.lpush(appendConstant(CiConstant.LONG_1)); break; |
1395 case FCONST_0 : fpush(appendConstant(CiConstant.FLOAT_0)); break; | 1323 case FCONST_0 : frameState.fpush(appendConstant(CiConstant.FLOAT_0)); break; |
1396 case FCONST_1 : fpush(appendConstant(CiConstant.FLOAT_1)); break; | 1324 case FCONST_1 : frameState.fpush(appendConstant(CiConstant.FLOAT_1)); break; |
1397 case FCONST_2 : fpush(appendConstant(CiConstant.FLOAT_2)); break; | 1325 case FCONST_2 : frameState.fpush(appendConstant(CiConstant.FLOAT_2)); break; |
1398 case DCONST_0 : dpush(appendConstant(CiConstant.DOUBLE_0)); break; | 1326 case DCONST_0 : frameState.dpush(appendConstant(CiConstant.DOUBLE_0)); break; |
1399 case DCONST_1 : dpush(appendConstant(CiConstant.DOUBLE_1)); break; | 1327 case DCONST_1 : frameState.dpush(appendConstant(CiConstant.DOUBLE_1)); break; |
1400 case BIPUSH : ipush(appendConstant(CiConstant.forInt(s.readByte()))); break; | 1328 case BIPUSH : frameState.ipush(appendConstant(CiConstant.forInt(s.readByte()))); break; |
1401 case SIPUSH : ipush(appendConstant(CiConstant.forInt(s.readShort()))); break; | 1329 case SIPUSH : frameState.ipush(appendConstant(CiConstant.forInt(s.readShort()))); break; |
1402 case LDC : // fall through | 1330 case LDC : // fall through |
1403 case LDC_W : // fall through | 1331 case LDC_W : // fall through |
1404 case LDC2_W : genLoadConstant(s.readCPI()); break; | 1332 case LDC2_W : genLoadConstant(s.readCPI()); break; |
1405 case ILOAD : loadLocal(s.readLocalIndex(), CiKind.Int); break; | 1333 case ILOAD : loadLocal(s.readLocalIndex(), CiKind.Int); break; |
1406 case LLOAD : loadLocal(s.readLocalIndex(), CiKind.Long); break; | 1334 case LLOAD : loadLocal(s.readLocalIndex(), CiKind.Long); break; |
1544 case IF_ICMPNE : genIfSame(CiKind.Int, Condition.NE); break; | 1472 case IF_ICMPNE : genIfSame(CiKind.Int, Condition.NE); break; |
1545 case IF_ICMPLT : genIfSame(CiKind.Int, Condition.LT); break; | 1473 case IF_ICMPLT : genIfSame(CiKind.Int, Condition.LT); break; |
1546 case IF_ICMPGE : genIfSame(CiKind.Int, Condition.GE); break; | 1474 case IF_ICMPGE : genIfSame(CiKind.Int, Condition.GE); break; |
1547 case IF_ICMPGT : genIfSame(CiKind.Int, Condition.GT); break; | 1475 case IF_ICMPGT : genIfSame(CiKind.Int, Condition.GT); break; |
1548 case IF_ICMPLE : genIfSame(CiKind.Int, Condition.LE); break; | 1476 case IF_ICMPLE : genIfSame(CiKind.Int, Condition.LE); break; |
1549 case IF_ACMPEQ : genIfSame(peekKind(), Condition.EQ); break; | 1477 case IF_ACMPEQ : genIfSame(frameState.peekKind(), Condition.EQ); break; |
1550 case IF_ACMPNE : genIfSame(peekKind(), Condition.NE); break; | 1478 case IF_ACMPNE : genIfSame(frameState.peekKind(), Condition.NE); break; |
1551 case GOTO : genGoto(s.currentBCI(), s.readBranchDest()); break; | 1479 case GOTO : genGoto(s.currentBCI(), s.readBranchDest()); break; |
1552 case JSR : genJsr(s.readBranchDest()); break; | 1480 case JSR : genJsr(s.readBranchDest()); break; |
1553 case RET : genRet(s.readLocalIndex()); break; | 1481 case RET : genRet(s.readLocalIndex()); break; |
1554 case TABLESWITCH : genTableswitch(); break; | 1482 case TABLESWITCH : genTableswitch(); break; |
1555 case LOOKUPSWITCH : genLookupswitch(); break; | 1483 case LOOKUPSWITCH : genLookupswitch(); break; |
1556 case IRETURN : genReturn(ipop()); break; | 1484 case IRETURN : genReturn(frameState.ipop()); break; |
1557 case LRETURN : genReturn(lpop()); break; | 1485 case LRETURN : genReturn(frameState.lpop()); break; |
1558 case FRETURN : genReturn(fpop()); break; | 1486 case FRETURN : genReturn(frameState.fpop()); break; |
1559 case DRETURN : genReturn(dpop()); break; | 1487 case DRETURN : genReturn(frameState.dpop()); break; |
1560 case ARETURN : genReturn(apop()); break; | 1488 case ARETURN : genReturn(frameState.apop()); break; |
1561 case RETURN : genReturn(null ); break; | 1489 case RETURN : genReturn(null ); break; |
1562 case GETSTATIC : cpi = s.readCPI(); genGetStatic(cpi, constantPool().lookupField(cpi, opcode)); break; | 1490 case GETSTATIC : cpi = s.readCPI(); genGetStatic(cpi, constantPool().lookupField(cpi, opcode)); break; |
1563 case PUTSTATIC : cpi = s.readCPI(); genPutStatic(cpi, constantPool().lookupField(cpi, opcode)); break; | 1491 case PUTSTATIC : cpi = s.readCPI(); genPutStatic(cpi, constantPool().lookupField(cpi, opcode)); break; |
1564 case GETFIELD : cpi = s.readCPI(); genGetField(cpi, constantPool().lookupField(cpi, opcode)); break; | 1492 case GETFIELD : cpi = s.readCPI(); genGetField(cpi, constantPool().lookupField(cpi, opcode)); break; |
1565 case PUTFIELD : cpi = s.readCPI(); genPutField(cpi, constantPool().lookupField(cpi, opcode)); break; | 1493 case PUTFIELD : cpi = s.readCPI(); genPutField(cpi, constantPool().lookupField(cpi, opcode)); break; |
1572 case ANEWARRAY : genNewObjectArray(s.readCPI()); break; | 1500 case ANEWARRAY : genNewObjectArray(s.readCPI()); break; |
1573 case ARRAYLENGTH : genArrayLength(); break; | 1501 case ARRAYLENGTH : genArrayLength(); break; |
1574 case ATHROW : genThrow(s.currentBCI()); break; | 1502 case ATHROW : genThrow(s.currentBCI()); break; |
1575 case CHECKCAST : genCheckCast(); break; | 1503 case CHECKCAST : genCheckCast(); break; |
1576 case INSTANCEOF : genInstanceOf(); break; | 1504 case INSTANCEOF : genInstanceOf(); break; |
1577 case MONITORENTER : genMonitorEnter(apop(), s.currentBCI()); break; | 1505 case MONITORENTER : genMonitorEnter(frameState.apop(), s.currentBCI()); break; |
1578 case MONITOREXIT : genMonitorExit(apop(), s.currentBCI()); break; | 1506 case MONITOREXIT : genMonitorExit(frameState.apop(), s.currentBCI()); break; |
1579 case MULTIANEWARRAY : genNewMultiArray(s.readCPI()); break; | 1507 case MULTIANEWARRAY : genNewMultiArray(s.readCPI()); break; |
1580 case IFNULL : genIfNull(Condition.EQ); break; | 1508 case IFNULL : genIfNull(Condition.EQ); break; |
1581 case IFNONNULL : genIfNull(Condition.NE); break; | 1509 case IFNONNULL : genIfNull(Condition.NE); break; |
1582 case GOTO_W : genGoto(s.currentBCI(), s.readFarBranchDest()); break; | 1510 case GOTO_W : genGoto(s.currentBCI(), s.readFarBranchDest()); break; |
1583 case JSR_W : genJsr(s.readFarBranchDest()); break; | 1511 case JSR_W : genJsr(s.readFarBranchDest()); break; |
1606 } | 1534 } |
1607 } | 1535 } |
1608 | 1536 |
1609 private void genArrayLength() { | 1537 private void genArrayLength() { |
1610 FrameState stateBefore = frameState.create(bci()); | 1538 FrameState stateBefore = frameState.create(bci()); |
1611 ipush(append(new ArrayLength(apop(), stateBefore, graph))); | 1539 frameState.ipush(append(new ArrayLength(frameState.apop(), stateBefore, graph))); |
1612 } | 1540 } |
1613 | 1541 |
1614 void killMemoryMap() { | 1542 void killMemoryMap() { |
1615 if (localValueMap != null) { | 1543 if (localValueMap != null) { |
1616 localValueMap.killAll(); | 1544 localValueMap.killAll(); |