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.StackMapGenerator;
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 *
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 a new stack map frame}
83 *
84 * @param target the location of the frame
85 * @param locals the complete list of frame locals
86 * @param stack the complete frame stack
87 * @throws IllegalArgumentException if the number of types in {@code locals}
88 * or {@code stack} exceeds the limit of {@link java.lang.classfile##u2 u2}
89 */
90 public static StackMapFrameInfo of(Label target,
91 List<VerificationTypeInfo> locals,
92 List<VerificationTypeInfo> stack) {
93 return new StackMapDecoder.StackMapFrameImpl(255, target, locals, stack);
94 }
95
96 /**
97 * The type of a stack or local variable value.
98 *
99 * @see #locals()
100 * @see #stack()
101 * @jvms 4.7.4 The {@code StackMapTable} Attribute
102 * @since 24
103 */
104 sealed interface VerificationTypeInfo {
105
106 /** The {@link #tag() tag} for verification type info {@link SimpleVerificationTypeInfo#TOP TOP}. */
107 int ITEM_TOP = StackMapGenerator.ITEM_TOP;
108
109 /** The {@link #tag() tag} for verification type info {@link SimpleVerificationTypeInfo#INTEGER INTEGER}. */
110 int ITEM_INTEGER = StackMapGenerator.ITEM_INTEGER;
111
112 /** The {@link #tag() tag} for verification type info {@link SimpleVerificationTypeInfo#FLOAT FLOAT}. */
113 int ITEM_FLOAT = StackMapGenerator.ITEM_FLOAT;
|
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.StackMapGenerator;
39 import jdk.internal.classfile.impl.TemporaryConstantPool;
40
41 /**
42 * Models a stack map frame in a {@link StackMapTableAttribute StackMapTable}
43 * attribute (JVMS {@jvms 4.7.4}). A stack map frame must appear at the
44 * beginning of each basic block in a method (JVMS {@jvms 4.10.1}).
45 *
46 * @apiNote
47 * In general, a stack map frame should be defined for each target of a
48 * {@link BranchInstruction}, or unreachable code right after an unconditional
49 * branch instruction like {@link Opcode#GOTO goto}. The automatic stack map
50 * generation cannot handle unreachable code right after an unconditional jump;
51 * The {@link ClassFile.DeadCodeOption} allows substituting such code, or
52 * advanced users can provide their own stack maps for dead code.
53 *
62 /**
63 * {@return the raw {@code u1 frame_type}}
64 */
65 int frameType();
66
67 /**
68 * {@return the frame target label}
69 */
70 Label target();
71
72 /**
73 * {@return the expanded local variable types}
74 */
75 List<VerificationTypeInfo> locals();
76
77 /**
78 * {@return the expanded operand stack types}
79 */
80 List<VerificationTypeInfo> stack();
81
82 /**
83 * {@return the expanded unset fields}
84 *
85 * @see <a href="https://cr.openjdk.org/~dlsmith/jep401/jep401-20250409/specs/strict-fields-jvms.html">Specs</a>
86 */
87 List<NameAndTypeEntry> unsetFields();
88
89 /**
90 * {@return a new stack map frame}
91 *
92 * @param target the location of the frame
93 * @param locals the complete list of frame locals
94 * @param stack the complete frame stack
95 * @throws IllegalArgumentException if the number of types in {@code locals}
96 * or {@code stack} exceeds the limit of {@link java.lang.classfile##u2 u2}
97 */
98 public static StackMapFrameInfo of(Label target,
99 List<VerificationTypeInfo> locals,
100 List<VerificationTypeInfo> stack) {
101
102 return of(target, locals, stack, List.of());
103 }
104
105 /**
106 * {@return a new stack map frame}
107 * @param target the location of the frame
108 * @param locals the complete list of frame locals
109 * @param stack the complete frame stack
110 * @param unsetFields the complete list of unset fields
111 * @throws IllegalArgumentException if unset fields has entries but no
112 * {@link SimpleVerificationTypeInfo#UNINITIALIZED_THIS uninitializedThis}
113 * is present in {@code locals}
114 */
115 public static StackMapFrameInfo of(Label target,
116 List<VerificationTypeInfo> locals,
117 List<VerificationTypeInfo> stack,
118 List<NameAndTypeEntry> unsetFields) {
119
120 return new StackMapDecoder.StackMapFrameImpl(255, target, locals, stack, unsetFields);
121 }
122
123 /**
124 * The type of a stack or local variable value.
125 *
126 * @see #locals()
127 * @see #stack()
128 * @jvms 4.7.4 The {@code StackMapTable} Attribute
129 * @since 24
130 */
131 sealed interface VerificationTypeInfo {
132
133 /** The {@link #tag() tag} for verification type info {@link SimpleVerificationTypeInfo#TOP TOP}. */
134 int ITEM_TOP = StackMapGenerator.ITEM_TOP;
135
136 /** The {@link #tag() tag} for verification type info {@link SimpleVerificationTypeInfo#INTEGER INTEGER}. */
137 int ITEM_INTEGER = StackMapGenerator.ITEM_INTEGER;
138
139 /** The {@link #tag() tag} for verification type info {@link SimpleVerificationTypeInfo#FLOAT FLOAT}. */
140 int ITEM_FLOAT = StackMapGenerator.ITEM_FLOAT;
|