< prev index next >

src/java.base/share/classes/java/lang/classfile/attribute/StackMapFrameInfo.java

Print this page

 13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any
 23  * questions.
 24  */
 25 
 26 package java.lang.classfile.attribute;
 27 
 28 import java.lang.classfile.ClassFile;
 29 import java.lang.classfile.Label;
 30 import java.lang.classfile.Opcode;
 31 import java.lang.classfile.constantpool.ClassEntry;
 32 import java.lang.classfile.instruction.BranchInstruction;

 33 import java.lang.constant.ClassDesc;
 34 import java.util.List;
 35 
 36 import jdk.internal.classfile.impl.StackMapDecoder;
 37 import jdk.internal.classfile.impl.TemporaryConstantPool;
 38 
 39 /**
 40  * Models a stack map frame in a {@link StackMapTableAttribute StackMapTable}
 41  * attribute (JVMS {@jvms 4.7.4}).  A stack map frame must appear at the
 42  * beginning of each basic block in a method (JVMS {@jvms 4.10.1}).
 43  *
 44  * @apiNote
 45  * In general, a stack map frame should be defined for each target of a
 46  * {@link BranchInstruction}, or unreachable code right after an unconditional
 47  * branch instruction like {@link Opcode#GOTO goto}.  The automatic stack map
 48  * generation cannot handle unreachable code right after an unconditional jump;
 49  * The {@link ClassFile.DeadCodeOption} allows substituting such code, or
 50  * advanced users can provide their own stack maps for dead code.
 51  *
 52  * @see StackMapTableAttribute#entries()

 60     /**
 61      * {@return the raw {@code u1 frame_type}}
 62      */
 63     int frameType();
 64 
 65     /**
 66      * {@return the frame target label}
 67      */
 68     Label target();
 69 
 70     /**
 71      * {@return the expanded local variable types}
 72      */
 73     List<VerificationTypeInfo> locals();
 74 
 75     /**
 76      * {@return the expanded operand stack types}
 77      */
 78     List<VerificationTypeInfo> stack();
 79 







 80     /**
 81      * {@return a new stack map frame}
 82      *
 83      * @param target the location of the frame
 84      * @param locals the complete list of frame locals
 85      * @param stack the complete frame stack
 86      */
 87     public static StackMapFrameInfo of(Label target,
 88             List<VerificationTypeInfo> locals,
 89             List<VerificationTypeInfo> stack) {
 90         return new StackMapDecoder.StackMapFrameImpl(255, target, locals, stack);
















 91     }
 92 
 93     /**
 94      * The type of a stack or local variable value.
 95      *
 96      * @see #locals()
 97      * @see #stack()
 98      * @jvms 4.7.4 The {@code StackMapTable} Attribute
 99      * @since 24
100      */
101     sealed interface VerificationTypeInfo {
102 
103         /** The {@link #tag() tag} for verification type info {@link SimpleVerificationTypeInfo#TOP TOP}. */
104         int ITEM_TOP = 0;
105 
106         /** The {@link #tag() tag} for verification type info {@link SimpleVerificationTypeInfo#INTEGER INTEGER}. */
107         int ITEM_INTEGER = 1;
108 
109         /** The {@link #tag() tag} for verification type info {@link SimpleVerificationTypeInfo#FLOAT FLOAT}. */
110         int ITEM_FLOAT = 2;

 13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any
 23  * questions.
 24  */
 25 
 26 package java.lang.classfile.attribute;
 27 
 28 import java.lang.classfile.ClassFile;
 29 import java.lang.classfile.Label;
 30 import java.lang.classfile.Opcode;
 31 import java.lang.classfile.constantpool.ClassEntry;
 32 import java.lang.classfile.instruction.BranchInstruction;
 33 import java.lang.classfile.constantpool.NameAndTypeEntry;
 34 import java.lang.constant.ClassDesc;
 35 import java.util.List;
 36 
 37 import jdk.internal.classfile.impl.StackMapDecoder;
 38 import jdk.internal.classfile.impl.TemporaryConstantPool;
 39 
 40 /**
 41  * Models a stack map frame in a {@link StackMapTableAttribute StackMapTable}
 42  * attribute (JVMS {@jvms 4.7.4}).  A stack map frame must appear at the
 43  * beginning of each basic block in a method (JVMS {@jvms 4.10.1}).
 44  *
 45  * @apiNote
 46  * In general, a stack map frame should be defined for each target of a
 47  * {@link BranchInstruction}, or unreachable code right after an unconditional
 48  * branch instruction like {@link Opcode#GOTO goto}.  The automatic stack map
 49  * generation cannot handle unreachable code right after an unconditional jump;
 50  * The {@link ClassFile.DeadCodeOption} allows substituting such code, or
 51  * advanced users can provide their own stack maps for dead code.
 52  *
 53  * @see StackMapTableAttribute#entries()

 61     /**
 62      * {@return the raw {@code u1 frame_type}}
 63      */
 64     int frameType();
 65 
 66     /**
 67      * {@return the frame target label}
 68      */
 69     Label target();
 70 
 71     /**
 72      * {@return the expanded local variable types}
 73      */
 74     List<VerificationTypeInfo> locals();
 75 
 76     /**
 77      * {@return the expanded operand stack types}
 78      */
 79     List<VerificationTypeInfo> stack();
 80 
 81     /**
 82      * {@return the expanded unset fields}
 83      *
 84      * @see <a href="https://cr.openjdk.org/~dlsmith/jep401/jep401-20241108/specs/value-objects-jvms.html">Specs</a>
 85      */
 86     List<NameAndTypeEntry> unsetFields();
 87 
 88     /**
 89      * {@return a new stack map frame}
 90      *
 91      * @param target the location of the frame
 92      * @param locals the complete list of frame locals
 93      * @param stack the complete frame stack
 94      */
 95     public static StackMapFrameInfo of(Label target,
 96             List<VerificationTypeInfo> locals,
 97             List<VerificationTypeInfo> stack) {
 98 
 99         return of(target, locals, stack, List.of());
100     }
101 
102     /**
103      * {@return a new stack map frame}
104      * @param target the location of the frame
105      * @param locals the complete list of frame locals
106      * @param stack the complete frame stack
107      * @param unsetFields the complete list of unset fields
108      */
109     public static StackMapFrameInfo of(Label target,
110                                        List<VerificationTypeInfo> locals,
111                                        List<VerificationTypeInfo> stack,
112                                        List<NameAndTypeEntry> unsetFields) {
113 
114         return new StackMapDecoder.StackMapFrameImpl(255, target, locals, stack, unsetFields);
115     }
116 
117     /**
118      * The type of a stack or local variable value.
119      *
120      * @see #locals()
121      * @see #stack()
122      * @jvms 4.7.4 The {@code StackMapTable} Attribute
123      * @since 24
124      */
125     sealed interface VerificationTypeInfo {
126 
127         /** The {@link #tag() tag} for verification type info {@link SimpleVerificationTypeInfo#TOP TOP}. */
128         int ITEM_TOP = 0;
129 
130         /** The {@link #tag() tag} for verification type info {@link SimpleVerificationTypeInfo#INTEGER INTEGER}. */
131         int ITEM_INTEGER = 1;
132 
133         /** The {@link #tag() tag} for verification type info {@link SimpleVerificationTypeInfo#FLOAT FLOAT}. */
134         int ITEM_FLOAT = 2;
< prev index next >