comparison graal/com.oracle.max.cri/src/com/oracle/max/cri/ci/CiFrame.java @ 4199:aaac4894175c

Renamed cri packages from sun to oracle.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Tue, 03 Jan 2012 16:29:28 +0100
parents graal/com.oracle.max.cri/src/com/sun/cri/ci/CiFrame.java@de7b3e7ae528
children a03f3fd16b22
comparison
equal deleted inserted replaced
4198:8c9c0e1eaab1 4199:aaac4894175c
1 /*
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.
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.oracle.max.cri.ci;
24
25 import java.io.*;
26
27 import com.oracle.max.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 private static final long serialVersionUID = -345025397165977565L;
36
37 /**
38 * An array of values representing how to reconstruct the state of the Java frame.
39 * This is array is partitioned as follows:
40 * <p>
41 * <table border="1" cellpadding="5" frame="void", rules="all">
42 * <tr><th>Start index (inclusive)</th><th>End index (exclusive)</th><th>Description</th></tr>
43 * <tr><td>0</td> <td>numLocals</td> <td>Local variables</td></tr>
44 * <tr><td>numLocals</td> <td>numLocals + numStack</td><td>Operand stack</td></tr>
45 * <tr><td>numLocals + numStack</td><td>values.length</td> <td>Locked objects</td></tr>
46 * </table>
47 * <p>
48 * Note that the number of locals and the number of stack slots may be smaller than the
49 * maximum number of locals and stack slots as specified in the compiled method.
50 */
51 public final CiValue[] values;
52
53 /**
54 * The number of locals in the values array.
55 */
56 public final int numLocals;
57
58 /**
59 * The number of stack slots in the values array.
60 */
61 public final int numStack;
62
63 /**
64 * The number of locks in the values array.
65 */
66 public final int numLocks;
67
68 public final boolean rethrowException;
69
70 /**
71 * Creates a new frame object.
72 *
73 * @param caller the caller frame (which may be {@code null})
74 * @param method the method
75 * @param bci a BCI within the method
76 * @param rethrowException specifies if the VM should re-throw the pending exception when deopt'ing using this frame
77 * @param values the frame state {@link #values}
78 * @param numLocals the number of local variables
79 * @param numStack the depth of the stack
80 * @param numLocks the number of locked objects
81 */
82 public CiFrame(CiFrame caller, RiResolvedMethod method, int bci, boolean rethrowException, CiValue[] values, int numLocals, int numStack, int numLocks) {
83 super(caller, method, bci);
84 assert values != null;
85 this.rethrowException = rethrowException;
86 this.values = values;
87 this.numLocks = numLocks;
88 this.numLocals = numLocals;
89 this.numStack = numStack;
90 assert !rethrowException || numStack == 1 : "must have exception on top of the stack";
91 }
92
93 /**
94 * Gets the value representing the specified local variable.
95 * @param i the local variable index
96 * @return the value that can be used to reconstruct the local's current value
97 */
98 public CiValue getLocalValue(int i) {
99 return values[i];
100 }
101
102 /**
103 * Gets the value representing the specified stack slot.
104 * @param i the stack index
105 * @return the value that can be used to reconstruct the stack slot's current value
106 */
107 public CiValue getStackValue(int i) {
108 return values[i + numLocals];
109 }
110
111 /**
112 * Gets the value representing the specified lock.
113 * @param i the lock index
114 * @return the value that can be used to reconstruct the lock's current value
115 */
116 public CiValue getLockValue(int i) {
117 return values[i + numLocals + numStack];
118 }
119
120 /**
121 * Gets the caller of this frame.
122 *
123 * @return {@code null} if this frame has no caller
124 */
125 public CiFrame caller() {
126 return (CiFrame) caller;
127 }
128
129 @Override
130 public String toString() {
131 return CiUtil.append(new StringBuilder(100), this).toString();
132 }
133 }