Mercurial > hg > truffle
comparison graal/com.oracle.max.cri/src/com/sun/cri/ci/CiFrame.java @ 4182:de7b3e7ae528
Simplify CiValue
author | Christian Wimmer <Christian.Wimmer@Oracle.com> |
---|---|
date | Mon, 02 Jan 2012 14:38:17 -0800 |
parents | bc8527f3071c |
children |
comparison
equal
deleted
inserted
replaced
4181:319860ae697a | 4182:de7b3e7ae528 |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. | 2 * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
30 * Represents the Java bytecode frame state(s) at a given position | 30 * Represents the Java bytecode frame state(s) at a given position |
31 * including {@link CiValue locations} where to find the local variables, | 31 * including {@link CiValue locations} where to find the local variables, |
32 * operand stack values and locked objects of the bytecode frame(s). | 32 * operand stack values and locked objects of the bytecode frame(s). |
33 */ | 33 */ |
34 public class CiFrame extends CiCodePos implements Serializable { | 34 public class CiFrame extends CiCodePos implements Serializable { |
35 /** | |
36 * | |
37 */ | |
38 private static final long serialVersionUID = -345025397165977565L; | 35 private static final long serialVersionUID = -345025397165977565L; |
39 | 36 |
40 /** | 37 /** |
41 * An array of values representing how to reconstruct the state of the Java frame. | 38 * An array of values representing how to reconstruct the state of the Java frame. |
42 * This is array is partitioned as follows: | 39 * This is array is partitioned as follows: |
127 */ | 124 */ |
128 public CiFrame caller() { | 125 public CiFrame caller() { |
129 return (CiFrame) caller; | 126 return (CiFrame) caller; |
130 } | 127 } |
131 | 128 |
132 /** | |
133 * Deep equality test. | |
134 */ | |
135 @Override | |
136 public boolean equals(Object obj) { | |
137 if (obj == this) { | |
138 return true; | |
139 } | |
140 if (obj instanceof CiFrame) { | |
141 CiFrame other = (CiFrame) obj; | |
142 return equals(other, false, false); | |
143 } | |
144 return false; | |
145 } | |
146 | |
147 /** | |
148 * Deep equality test. | |
149 * | |
150 * @param ignoreKinds if {@code true}, compares values but {@link CiValue#equalsIgnoringKind(CiValue) ignore} their kinds | |
151 * @param ignoreNegativeBCIs if {@code true}, negative BCIs are treated as equal | |
152 */ | |
153 public boolean equals(CiFrame other, boolean ignoreKinds, boolean ignoreNegativeBCIs) { | |
154 if ((other.bci == bci || (ignoreNegativeBCIs && other.bci < 0 && bci < 0)) && | |
155 numLocals == other.numLocals && | |
156 numStack == other.numStack && | |
157 numLocks == other.numLocks && | |
158 values.length == other.values.length) { | |
159 | |
160 if (ignoreKinds) { | |
161 for (int i = 0; i < values.length; i++) { | |
162 if (!values[i].equalsIgnoringKind(other.values[i])) { | |
163 return false; | |
164 } | |
165 } | |
166 } else { | |
167 for (int i = 0; i < values.length; i++) { | |
168 if (!values[i].equals(other.values[i])) { | |
169 return false; | |
170 } | |
171 } | |
172 } | |
173 if (caller == null) { | |
174 return other.caller == null; | |
175 } | |
176 if (other.caller == null) { | |
177 return false; | |
178 } | |
179 return caller().equals(other.caller(), ignoreKinds, ignoreNegativeBCIs); | |
180 } | |
181 return false; | |
182 } | |
183 | |
184 @Override | 129 @Override |
185 public String toString() { | 130 public String toString() { |
186 return CiUtil.append(new StringBuilder(100), this).toString(); | 131 return CiUtil.append(new StringBuilder(100), this).toString(); |
187 } | 132 } |
188 | |
189 /** | |
190 * Gets a copy of this frame but with an empty stack. | |
191 */ | |
192 public CiFrame withEmptyStack() { | |
193 if (numStack == 0) { | |
194 return this; | |
195 } | |
196 CiValue[] ciValues = new CiValue[numLocals + numLocks]; | |
197 System.arraycopy(this.values, 0, ciValues, 0, numLocals); | |
198 System.arraycopy(this.values, numLocals + numStack, ciValues, numLocals, numLocks); | |
199 return new CiFrame(caller(), method, bci, rethrowException, ciValues, numLocals, 0, numLocks); | |
200 } | |
201 } | 133 } |