Mercurial > hg > graal-compiler
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.max.cri/src/com/oracle/max/cri/ci/CiFrame.java Tue Jan 03 16:29:28 2012 +0100 @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.max.cri.ci; + +import java.io.*; + +import com.oracle.max.cri.ri.*; + +/** + * Represents the Java bytecode frame state(s) at a given position + * including {@link CiValue locations} where to find the local variables, + * operand stack values and locked objects of the bytecode frame(s). + */ +public class CiFrame extends CiCodePos implements Serializable { + private static final long serialVersionUID = -345025397165977565L; + + /** + * An array of values representing how to reconstruct the state of the Java frame. + * This is array is partitioned as follows: + * <p> + * <table border="1" cellpadding="5" frame="void", rules="all"> + * <tr><th>Start index (inclusive)</th><th>End index (exclusive)</th><th>Description</th></tr> + * <tr><td>0</td> <td>numLocals</td> <td>Local variables</td></tr> + * <tr><td>numLocals</td> <td>numLocals + numStack</td><td>Operand stack</td></tr> + * <tr><td>numLocals + numStack</td><td>values.length</td> <td>Locked objects</td></tr> + * </table> + * <p> + * Note that the number of locals and the number of stack slots may be smaller than the + * maximum number of locals and stack slots as specified in the compiled method. + */ + public final CiValue[] values; + + /** + * The number of locals in the values array. + */ + public final int numLocals; + + /** + * The number of stack slots in the values array. + */ + public final int numStack; + + /** + * The number of locks in the values array. + */ + public final int numLocks; + + public final boolean rethrowException; + + /** + * Creates a new frame object. + * + * @param caller the caller frame (which may be {@code null}) + * @param method the method + * @param bci a BCI within the method + * @param rethrowException specifies if the VM should re-throw the pending exception when deopt'ing using this frame + * @param values the frame state {@link #values} + * @param numLocals the number of local variables + * @param numStack the depth of the stack + * @param numLocks the number of locked objects + */ + public CiFrame(CiFrame caller, RiResolvedMethod method, int bci, boolean rethrowException, CiValue[] values, int numLocals, int numStack, int numLocks) { + super(caller, method, bci); + assert values != null; + this.rethrowException = rethrowException; + this.values = values; + this.numLocks = numLocks; + this.numLocals = numLocals; + this.numStack = numStack; + assert !rethrowException || numStack == 1 : "must have exception on top of the stack"; + } + + /** + * Gets the value representing the specified local variable. + * @param i the local variable index + * @return the value that can be used to reconstruct the local's current value + */ + public CiValue getLocalValue(int i) { + return values[i]; + } + + /** + * Gets the value representing the specified stack slot. + * @param i the stack index + * @return the value that can be used to reconstruct the stack slot's current value + */ + public CiValue getStackValue(int i) { + return values[i + numLocals]; + } + + /** + * Gets the value representing the specified lock. + * @param i the lock index + * @return the value that can be used to reconstruct the lock's current value + */ + public CiValue getLockValue(int i) { + return values[i + numLocals + numStack]; + } + + /** + * Gets the caller of this frame. + * + * @return {@code null} if this frame has no caller + */ + public CiFrame caller() { + return (CiFrame) caller; + } + + @Override + public String toString() { + return CiUtil.append(new StringBuilder(100), this).toString(); + } +}