comparison graal/GraalCompiler/src/com/sun/c1x/value/FrameState.java @ 2610:39aa89baa165

cleanup: FrameState copy methods, ImmutableFrameState
author Lukas Stadler <lukas.stadler@jku.at>
date Fri, 06 May 2011 13:03:33 +0200
parents 01c5c0443158
children bd235cb4375a
comparison
equal deleted inserted replaced
2603:01c5c0443158 2610:39aa89baa165
26 26
27 import com.oracle.graal.graph.*; 27 import com.oracle.graal.graph.*;
28 import com.sun.c1x.*; 28 import com.sun.c1x.*;
29 import com.sun.c1x.graph.*; 29 import com.sun.c1x.graph.*;
30 import com.sun.c1x.ir.*; 30 import com.sun.c1x.ir.*;
31 import com.sun.c1x.util.*;
31 import com.sun.cri.ci.*; 32 import com.sun.cri.ci.*;
32 33
33 /** 34 /**
34 * The {@code FrameState} class encapsulates the frame state (i.e. local variables and 35 * The {@code FrameState} class encapsulates the frame state (i.e. local variables and
35 * operand stack) at a particular point in the abstract interpretation. 36 * operand stack) at a particular point in the abstract interpretation.
103 * @param withStack indicates whether to copy the stack state 104 * @param withStack indicates whether to copy the stack state
104 * @param withLocks indicates whether to copy the lock state 105 * @param withLocks indicates whether to copy the lock state
105 * 106 *
106 * @return a new frame state with the specified components 107 * @return a new frame state with the specified components
107 */ 108 */
108 public MutableFrameState copy(int bci, boolean withLocals, boolean withStack, boolean withLocks) { 109 public FrameState immutableCopy(int bci, boolean withLocals, boolean withStack, boolean withLocks) {
109 final MutableFrameState other = new MutableFrameState(bci, localsSize(), maxStackSize()); 110 final ImmutableFrameState other = new ImmutableFrameState(bci, localsSize(), maxStackSize());
110 if (withLocals && withStack) { 111 if (withLocals && withStack) {
111 // fast path: use array copy 112 // fast path: use array copy
112 System.arraycopy(values, 0, other.values, 0, valuesSize()); 113 System.arraycopy(values, 0, other.values, 0, valuesSize());
113 other.stackIndex = stackIndex; 114 other.stackIndex = stackIndex;
114 } else { 115 } else {
115 if (withLocals) { 116 if (withLocals) {
116 other.replaceLocals(this); 117 System.arraycopy(values, 0, other.values, 0, maxLocals);
117 } 118 }
118 if (withStack) { 119 if (withStack) {
119 other.replaceStack(this); 120 System.arraycopy(values, maxLocals, other.values, other.maxLocals, stackIndex);
121 other.stackIndex = stackIndex;
120 } 122 }
121 } 123 }
122 if (withLocks) { 124 if (withLocks) {
123 other.replaceLocks(this); 125 if (locks != null) {
126 other.locks = new ArrayList<Value>(locks);
127 }
124 } 128 }
125 return other; 129 return other;
126 } 130 }
127 131
128 /** 132 /**
129 * Gets a mutable copy ({@link MutableFrameState}) of this frame state. 133 * Gets a mutable copy ({@link MutableFrameState}) of this frame state.
130 */ 134 */
131 public MutableFrameState copy() { 135 public MutableFrameState copy() {
132 return copy(bci, true, true, true); 136 final MutableFrameState other = new MutableFrameState(bci, localsSize(), maxStackSize());
137 System.arraycopy(values, 0, other.values, 0, valuesSize());
138 other.stackIndex = stackIndex;
139 if (locks != null) {
140 other.locks = new ArrayList<Value>(locks);
141 }
142 return other;
143 }
144
145 /**
146 * Gets a immutable copy ({@link MutableFrameState}) of this frame state.
147 */
148 public FrameState immutableCopy() {
149 return immutableCopy(bci, true, true, true);
133 } 150 }
134 151
135 /** 152 /**
136 * Gets an immutable copy of this frame state but without the stack. 153 * Gets an immutable copy of this frame state but without the stack.
137 */ 154 */
138 public FrameState immutableCopyWithEmptyStack() { 155 public FrameState immutableCopyWithEmptyStack() {
139 return copy(bci, true, false, true); 156 return immutableCopy(bci, true, false, true);
140 } 157 }
141 158
142 /** 159 /**
143 * Gets an immutable copy of this frame state but without the frame info. 160 * Gets an immutable copy of this frame state but without the frame info.
144 */ 161 */
145 public FrameState immutableCopyCodePosOnly() { 162 public FrameState immutableCopyCodePosOnly() {
146 return copy(bci, false, false, false); 163 return immutableCopy(bci, false, false, false);
147 } 164 }
148 165
149 public boolean isCompatibleWith(FrameState other) { 166 public boolean isCompatibleWith(FrameState other) {
150 if (stackSize() != other.stackSize() || localsSize() != other.localsSize() || locksSize() != other.locksSize()) { 167 if (stackSize() != other.stackSize() || localsSize() != other.localsSize() || locksSize() != other.locksSize()) {
151 return false; 168 return false;
429 public static interface PhiProcedure { 446 public static interface PhiProcedure {
430 boolean doPhi(Phi phi); 447 boolean doPhi(Phi phi);
431 } 448 }
432 449
433 /** 450 /**
434 * Traverses all {@linkplain Phi phis} of a given block in this frame state.
435 *
436 * @param block only phis {@linkplain Phi#block() associated} with this block are traversed
437 * @param proc the call back invoked for each live phi traversed
438 */
439 public boolean forEachPhi(BlockBegin block, PhiProcedure proc) {
440 int max = this.valuesSize();
441 for (int i = 0; i < max; i++) {
442 Value instr = values[i];
443 if (instr instanceof Phi && !instr.isDeadPhi()) {
444 Phi phi = (Phi) instr;
445 if (block == null || phi.block() == block) {
446 if (!proc.doPhi(phi)) {
447 return false;
448 }
449 }
450 }
451 }
452 return true;
453 }
454
455 /**
456 * Traverses all live {@linkplain Phi phis} of a given block in this frame state. 451 * Traverses all live {@linkplain Phi phis} of a given block in this frame state.
457 * 452 *
458 * @param block only phis {@linkplain Phi#block() associated} with this block are traversed 453 * @param block only phis {@linkplain Phi#block() associated} with this block are traversed
459 * @param proc the call back invoked for each live phi traversed 454 * @param proc the call back invoked for each live phi traversed
460 */ 455 */