Mercurial > hg > truffle
comparison graal/GraalCompiler/src/com/sun/c1x/value/FrameState.java @ 2564:274360f98f97
Remove inlining (2nd part) removed IRScope
author | Gilles Duboscq <gilles.duboscq@oracle.com> |
---|---|
date | Fri, 29 Apr 2011 13:19:17 +0200 |
parents | e1b3db8031ee |
children | cc1f1d396288 |
comparison
equal
deleted
inserted
replaced
2563:491896f81cae | 2564:274360f98f97 |
---|---|
60 /** | 60 /** |
61 * The number of local variables. | 61 * The number of local variables. |
62 */ | 62 */ |
63 protected final int maxLocals; | 63 protected final int maxLocals; |
64 | 64 |
65 protected final IRScope scope; | 65 //XXX temporary while removing IRScope |
66 @Deprecated | |
67 public final RiMethod method; | |
66 | 68 |
67 /** | 69 /** |
68 * The bytecode index to which this frame state applies. This will be {@code -1} | 70 * The bytecode index to which this frame state applies. This will be {@code -1} |
69 * iff this state is mutable. | 71 * iff this state is mutable. |
70 */ | 72 */ |
90 * @param irScope the inlining context of the method | 92 * @param irScope the inlining context of the method |
91 * @param bci the bytecode index of the frame state | 93 * @param bci the bytecode index of the frame state |
92 * @param maxLocals maximum number of locals | 94 * @param maxLocals maximum number of locals |
93 * @param maxStack maximum size of the stack | 95 * @param maxStack maximum size of the stack |
94 */ | 96 */ |
95 public FrameState(IRScope irScope, int bci, int maxLocals, int maxStack) { | 97 public FrameState(RiMethod method, int bci, int maxLocals, int maxStack) { |
96 this.scope = irScope; | 98 this.method = method; |
97 this.bci = bci; | 99 this.bci = bci; |
98 this.values = new Value[maxLocals + Math.max(maxStack, MINIMUM_STACK_SLOTS)]; | 100 this.values = new Value[maxLocals + Math.max(maxStack, MINIMUM_STACK_SLOTS)]; |
99 this.maxLocals = maxLocals; | 101 this.maxLocals = maxLocals; |
100 C1XMetrics.FrameStatesCreated++; | 102 C1XMetrics.FrameStatesCreated++; |
101 C1XMetrics.FrameStateValuesCreated += this.values.length; | 103 C1XMetrics.FrameStateValuesCreated += this.values.length; |
109 * @param withLocks indicates whether to copy the lock state | 111 * @param withLocks indicates whether to copy the lock state |
110 * | 112 * |
111 * @return a new frame state with the specified components | 113 * @return a new frame state with the specified components |
112 */ | 114 */ |
113 public MutableFrameState copy(int bci, boolean withLocals, boolean withStack, boolean withLocks) { | 115 public MutableFrameState copy(int bci, boolean withLocals, boolean withStack, boolean withLocks) { |
114 final MutableFrameState other = new MutableFrameState(scope, bci, localsSize(), maxStackSize()); | 116 final MutableFrameState other = new MutableFrameState(method, bci, localsSize(), maxStackSize()); |
115 if (withLocals && withStack) { | 117 if (withLocals && withStack) { |
116 // fast path: use array copy | 118 // fast path: use array copy |
117 int valuesSize = valuesSize(); | 119 int valuesSize = valuesSize(); |
118 assert other.values.length >= valuesSize : "array size: " + other.values.length + ", valuesSize: " + valuesSize + ", maxStackSize: " + maxStackSize() + ", localsSize: " + localsSize(); | 120 assert other.values.length >= valuesSize : "array size: " + other.values.length + ", valuesSize: " + valuesSize + ", maxStackSize: " + maxStackSize() + ", localsSize: " + localsSize(); |
119 assert values.length >= valuesSize : "array size: " + values.length + ", valuesSize: " + valuesSize + ", maxStackSize: " + maxStackSize() + ", localsSize: " + localsSize(); | 121 assert values.length >= valuesSize : "array size: " + values.length + ", valuesSize: " + valuesSize + ", maxStackSize: " + maxStackSize() + ", localsSize: " + localsSize(); |
174 } | 176 } |
175 return true; | 177 return true; |
176 } | 178 } |
177 | 179 |
178 /** | 180 /** |
179 * Returns the inlining context associated with this frame state. | |
180 * | |
181 * @return the inlining context | |
182 */ | |
183 public IRScope scope() { | |
184 return scope; | |
185 } | |
186 | |
187 /** | |
188 * Returns the size of the local variables. | 181 * Returns the size of the local variables. |
189 * | 182 * |
190 * @return the size of the local variables | 183 * @return the size of the local variables |
191 */ | 184 */ |
192 public int localsSize() { | 185 public int localsSize() { |
198 */ | 191 */ |
199 public int locksSize() { | 192 public int locksSize() { |
200 return locks == null ? 0 : locks.size(); | 193 return locks == null ? 0 : locks.size(); |
201 } | 194 } |
202 | 195 |
196 @Deprecated | |
203 public int totalLocksSize() { | 197 public int totalLocksSize() { |
204 return locksSize() + ((callerState() == null) ? 0 : callerState().totalLocksSize()); | 198 return locksSize(); |
205 } | 199 } |
206 | 200 |
207 /** | 201 /** |
208 * Gets the current size (height) of the stack. | 202 * Gets the current size (height) of the stack. |
209 */ | 203 */ |
369 * | 363 * |
370 * @return the number of local variables in this frame | 364 * @return the number of local variables in this frame |
371 */ | 365 */ |
372 public final int valuesSize() { | 366 public final int valuesSize() { |
373 return maxLocals + stackIndex; | 367 return maxLocals + stackIndex; |
374 } | |
375 | |
376 public final int callerStackSize() { | |
377 FrameState callerState = scope().callerState; | |
378 return callerState == null ? 0 : callerState.stackSize(); | |
379 } | 368 } |
380 | 369 |
381 public void checkPhis(BlockBegin block, FrameState other) { | 370 public void checkPhis(BlockBegin block, FrameState other) { |
382 checkSize(other); | 371 checkSize(other); |
383 final int max = valuesSize(); | 372 final int max = valuesSize(); |
523 /** | 512 /** |
524 * Iterates over all the values of a given frame state and its callers, including the stack, locals, and locks. | 513 * Iterates over all the values of a given frame state and its callers, including the stack, locals, and locks. |
525 * @param closure the closure to apply to each value | 514 * @param closure the closure to apply to each value |
526 */ | 515 */ |
527 public static void valuesDo(FrameState state, ValueClosure closure) { | 516 public static void valuesDo(FrameState state, ValueClosure closure) { |
528 do { | 517 final int max = state.valuesSize(); |
529 final int max = state.valuesSize(); | 518 for (int i = 0; i < max; i++) { |
530 for (int i = 0; i < max; i++) { | 519 if (state.values[i] != null) { |
531 if (state.values[i] != null) { | 520 Value newValue = closure.apply(state.values[i]); |
532 Value newValue = closure.apply(state.values[i]); | 521 state.values[i] = newValue; |
533 state.values[i] = newValue; | 522 } |
534 } | 523 } |
535 } | 524 if (state.locks != null) { |
536 if (state.locks != null) { | 525 for (int i = 0; i < state.locks.size(); i++) { |
537 for (int i = 0; i < state.locks.size(); i++) { | 526 Value instr = state.locks.get(i); |
538 Value instr = state.locks.get(i); | 527 if (instr != null) { |
539 if (instr != null) { | 528 state.locks.set(i, closure.apply(instr)); |
540 state.locks.set(i, closure.apply(instr)); | 529 } |
541 } | 530 } |
542 } | 531 } |
543 } | |
544 state = state.callerState(); | |
545 } while (state != null); | |
546 } | 532 } |
547 | 533 |
548 /** | 534 /** |
549 * The interface implemented by a client of {@link FrameState#forEachLiveStateValue(ValueProcedure)}. | 535 * The interface implemented by a client of {@link FrameState#forEachLiveStateValue(ValueProcedure)}. |
550 */ | 536 */ |
556 * Traverses all {@linkplain Value#isLive() live values} of this frame state and it's callers. | 542 * Traverses all {@linkplain Value#isLive() live values} of this frame state and it's callers. |
557 * | 543 * |
558 * @param proc the call back called to process each live value traversed | 544 * @param proc the call back called to process each live value traversed |
559 */ | 545 */ |
560 public final void forEachLiveStateValue(ValueProcedure proc) { | 546 public final void forEachLiveStateValue(ValueProcedure proc) { |
561 FrameState state = this; | 547 final int max = this.valuesSize(); |
562 while (state != null) { | 548 for (int i = 0; i < max; i++) { |
563 final int max = state.valuesSize(); | 549 Value value = this.values[i]; |
564 for (int i = 0; i < max; i++) { | 550 if (value != null) { |
565 Value value = state.values[i]; | 551 proc.doValue(value); |
566 if (value != null) { | 552 } |
567 proc.doValue(value); | 553 } |
568 } | 554 } |
569 } | 555 |
570 state = state.callerState(); | 556 @Override |
571 } | 557 public String toString() { |
572 } | |
573 | |
574 public static String toString(FrameState fs) { | |
575 StringBuilder sb = new StringBuilder(); | 558 StringBuilder sb = new StringBuilder(); |
576 String nl = String.format("%n"); | 559 String nl = String.format("%n"); |
577 while (fs != null) { | 560 CiUtil.appendLocation(sb, this.method, this.bci).append(nl); |
578 if (fs.scope == null) { | 561 for (int i = 0; i < this.localsSize(); ++i) { |
579 sb.append("<no method>").append(" [bci: ").append(fs.bci).append(']'); | 562 Value value = this.localAt(i); |
580 break; | 563 sb.append(String.format(" local[%d] = %-8s : %s%n", i, value == null ? "bogus" : value.kind.javaName, value)); |
581 } else { | 564 } |
582 CiUtil.appendLocation(sb, fs.scope.method, fs.bci).append(nl); | 565 for (int i = 0; i < this.stackSize(); ++i) { |
583 for (int i = 0; i < fs.localsSize(); ++i) { | 566 Value value = this.stackAt(i); |
584 Value value = fs.localAt(i); | 567 sb.append(String.format(" stack[%d] = %-8s : %s%n", i, value == null ? "bogus" : value.kind.javaName, value)); |
585 sb.append(String.format(" local[%d] = %-8s : %s%n", i, value == null ? "bogus" : value.kind.javaName, value)); | 568 } |
586 } | 569 for (int i = 0; i < this.locksSize(); ++i) { |
587 for (int i = 0; i < fs.stackSize(); ++i) { | 570 Value value = this.lockAt(i); |
588 Value value = fs.stackAt(i); | 571 sb.append(String.format(" lock[%d] = %-8s : %s%n", i, value == null ? "bogus" : value.kind.javaName, value)); |
589 sb.append(String.format(" stack[%d] = %-8s : %s%n", i, value == null ? "bogus" : value.kind.javaName, value)); | |
590 } | |
591 for (int i = 0; i < fs.locksSize(); ++i) { | |
592 Value value = fs.lockAt(i); | |
593 sb.append(String.format(" lock[%d] = %-8s : %s%n", i, value == null ? "bogus" : value.kind.javaName, value)); | |
594 } | |
595 fs = fs.callerState(); | |
596 } | |
597 } | 572 } |
598 return sb.toString(); | 573 return sb.toString(); |
599 } | 574 } |
600 | 575 |
601 @Override | |
602 public String toString() { | |
603 return toString(this); | |
604 } | |
605 | |
606 public CiCodePos toCodePos() { | 576 public CiCodePos toCodePos() { |
607 FrameState caller = callerState(); | 577 return new CiCodePos(null, method, bci); |
608 CiCodePos callerCodePos = null; | |
609 if (caller != null) { | |
610 callerCodePos = caller.toCodePos(); | |
611 } | |
612 return new CiCodePos(callerCodePos, scope.method, bci); | |
613 } | |
614 | |
615 /** | |
616 * Creates a new {@code MutableFrameState} corresponding to inlining the specified method into this point in this frame state. | |
617 * @param scope the IRScope representing the inlined method | |
618 * @return a new frame state representing the state at the beginning of inlining the specified method into this one | |
619 */ | |
620 public MutableFrameState pushScope(IRScope scope) { | |
621 assert scope.caller == this.scope; | |
622 RiMethod method = scope.method; | |
623 return new MutableFrameState(scope, -1, method.maxLocals(), method.maxStackSize()); | |
624 } | |
625 | |
626 /** | |
627 * Creates a new {@code MutableFrameState} corresponding to the state upon returning from this inlined method into the outer | |
628 * IRScope. | |
629 * @return a new frame state representing the state at exit from this frame state | |
630 */ | |
631 public MutableFrameState popScope() { | |
632 IRScope callingScope = scope.caller; | |
633 assert callingScope != null; | |
634 FrameState callerState = scope.callerState; | |
635 MutableFrameState res = new MutableFrameState(callingScope, bci, callerState.maxLocals, callerState.maxStackSize() + stackIndex); | |
636 System.arraycopy(callerState.values, 0, res.values, 0, callerState.values.length); | |
637 System.arraycopy(values, maxLocals, res.values, res.maxLocals + callerState.stackIndex, stackIndex); | |
638 res.stackIndex = callerState.stackIndex + stackIndex; | |
639 assert res.stackIndex >= 0; | |
640 res.replaceLocks(callerState); | |
641 return res; | |
642 } | |
643 | |
644 /** | |
645 * Gets the caller frame state. | |
646 * | |
647 * @return the caller frame state or {@code null} if this is a top-level state | |
648 */ | |
649 public FrameState callerState() { | |
650 return scope.callerState; | |
651 } | 578 } |
652 } | 579 } |