comparison graal/com.oracle.max.cri/src/com/sun/cri/ci/CiFrame.java @ 3733:e233f5660da4

Added Java files from Maxine project.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Sat, 17 Dec 2011 19:59:18 +0100
parents
children bc8527f3071c
comparison
equal deleted inserted replaced
3732:3e2e8b8abdaf 3733:e233f5660da4
1 /*
2 * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23 package com.sun.cri.ci;
24
25 import java.io.*;
26
27 import com.sun.cri.ri.*;
28
29 /**
30 * Represents the Java bytecode frame state(s) at a given position
31 * including {@link CiValue locations} where to find the local variables,
32 * operand stack values and locked objects of the bytecode frame(s).
33 */
34 public class CiFrame extends CiCodePos implements Serializable {
35 /**
36 * An array of values representing how to reconstruct the state of the Java frame.
37 * This is array is partitioned as follows:
38 * <p>
39 * <table border="1" cellpadding="5" frame="void", rules="all">
40 * <tr><th>Start index (inclusive)</th><th>End index (exclusive)</th><th>Description</th></tr>
41 * <tr><td>0</td> <td>numLocals</td> <td>Local variables</td></tr>
42 * <tr><td>numLocals</td> <td>numLocals + numStack</td><td>Operand stack</td></tr>
43 * <tr><td>numLocals + numStack</td><td>values.length</td> <td>Locked objects</td></tr>
44 * </table>
45 * <p>
46 * Note that the number of locals and the number of stack slots may be smaller than the
47 * maximum number of locals and stack slots as specified in the compiled method.
48 */
49 public final CiValue[] values;
50
51 /**
52 * The number of locals in the values array.
53 */
54 public final int numLocals;
55
56 /**
57 * The number of stack slots in the values array.
58 */
59 public final int numStack;
60
61 /**
62 * The number of locks in the values array.
63 */
64 public final int numLocks;
65
66 public final boolean rethrowException;
67
68 /**
69 * Creates a new frame object.
70 *
71 * @param caller the caller frame (which may be {@code null})
72 * @param method the method
73 * @param bci a BCI within the method
74 * @param rethrowException specifies if the VM should re-throw the pending exception when deopt'ing using this frame
75 * @param values the frame state {@link #values}
76 * @param numLocals the number of local variables
77 * @param numStack the depth of the stack
78 * @param numLocks the number of locked objects
79 */
80 public CiFrame(CiFrame caller, RiResolvedMethod method, int bci, boolean rethrowException, CiValue[] values, int numLocals, int numStack, int numLocks) {
81 super(caller, method, bci);
82 assert values != null;
83 this.rethrowException = rethrowException;
84 this.values = values;
85 this.numLocks = numLocks;
86 this.numLocals = numLocals;
87 this.numStack = numStack;
88 assert !rethrowException || numStack == 1 : "must have exception on top of the stack";
89 }
90
91 /**
92 * Gets the value representing the specified local variable.
93 * @param i the local variable index
94 * @return the value that can be used to reconstruct the local's current value
95 */
96 public CiValue getLocalValue(int i) {
97 return values[i];
98 }
99
100 /**
101 * Gets the value representing the specified stack slot.
102 * @param i the stack index
103 * @return the value that can be used to reconstruct the stack slot's current value
104 */
105 public CiValue getStackValue(int i) {
106 return values[i + numLocals];
107 }
108
109 /**
110 * Gets the value representing the specified lock.
111 * @param i the lock index
112 * @return the value that can be used to reconstruct the lock's current value
113 */
114 public CiValue getLockValue(int i) {
115 return values[i + numLocals + numStack];
116 }
117
118 /**
119 * Gets the caller of this frame.
120 *
121 * @return {@code null} if this frame has no caller
122 */
123 public CiFrame caller() {
124 return (CiFrame) caller;
125 }
126
127 /**
128 * Deep equality test.
129 */
130 @Override
131 public boolean equals(Object obj) {
132 if (obj == this) {
133 return true;
134 }
135 if (obj instanceof CiFrame) {
136 CiFrame other = (CiFrame) obj;
137 return equals(other, false, false);
138 }
139 return false;
140 }
141
142 /**
143 * Deep equality test.
144 *
145 * @param ignoreKinds if {@code true}, compares values but {@link CiValue#equalsIgnoringKind(CiValue) ignore} their kinds
146 * @param ignoreNegativeBCIs if {@code true}, negative BCIs are treated as equal
147 */
148 public boolean equals(CiFrame other, boolean ignoreKinds, boolean ignoreNegativeBCIs) {
149 if ((other.bci == bci || (ignoreNegativeBCIs && other.bci < 0 && bci < 0)) &&
150 numLocals == other.numLocals &&
151 numStack == other.numStack &&
152 numLocks == other.numLocks &&
153 values.length == other.values.length) {
154
155 if (ignoreKinds) {
156 for (int i = 0; i < values.length; i++) {
157 if (!values[i].equalsIgnoringKind(other.values[i])) {
158 return false;
159 }
160 }
161 } else {
162 for (int i = 0; i < values.length; i++) {
163 if (!values[i].equals(other.values[i])) {
164 return false;
165 }
166 }
167 }
168 if (caller == null) {
169 return other.caller == null;
170 }
171 if (other.caller == null) {
172 return false;
173 }
174 return caller().equals(other.caller(), ignoreKinds, ignoreNegativeBCIs);
175 }
176 return false;
177 }
178
179 @Override
180 public String toString() {
181 return CiUtil.append(new StringBuilder(100), this).toString();
182 }
183
184 /**
185 * Gets a copy of this frame but with an empty stack.
186 */
187 public CiFrame withEmptyStack() {
188 if (numStack == 0) {
189 return this;
190 }
191 CiValue[] values = new CiValue[numLocals + numLocks];
192 System.arraycopy(this.values, 0, values, 0, numLocals);
193 System.arraycopy(this.values, numLocals + numStack, values, numLocals, numLocks);
194 return new CiFrame(caller(), method, bci, rethrowException, values, numLocals, 0, numLocks);
195 }
196 }