1 /*
2 * Copyright (c) 2018, 2022, 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
24 /*
25 * This test contains a CONSTANT_InvokeDynamic_info structure whose bootstrap_method_attr_index
26 * points to a BSM for an CONSTANT_Dynamic. Both the condy & indy point at element 0 in the
27 * bootstrap methods array. BootstrapMethodError expected.
28 */
29
30 /*
31 class IndyUsesCondyBSM {
32 IndyUsesCondyBSM() { }
33 public static Object Condybsm(java.lang.invoke.MethodHandles$Lookup, java.lang.String, java.lang.Class) {
34 System.out.println("In Condybsm");
35 return String(0);
36 }
37 public static int foo() {
38 System.out.println("In Indybsm target CallSite method foo");
39 return 100;
40 }
41 public static MethodHandle MH_foo() {
42 // Constructs a MethodHandle for foo
43 Lookup lookup = MethodHandles.lookup();
44 MethodType mt = MethodType.methodType(int.class);
45 return lookup.findStatic(IndyUsesCondyBSM.class, "foo", mt);
46 }
47 public static CallSite Indybsm(java.lang.invoke.MethodHandles$Lookup, java.lang.String, java.lang.invoke.MethodType) {
48 return new CallSite(IndyUsesCondyBSM.MH_foo());
49 }
50 public static int m() {
51 // ldc_w dynamic where the BSM = slot #0 in the BootstrapMethods array is IndyUsesCondyBSM.Condybsm() -> succeeds
52 // invokedynamic where the BSM = slot #0 in the BootstrapMethods array is IndyUsesCondyBSM.Condybsm() -> receives a BootstrapMethodError
53 return Callsite.foo();
54 }
55 public static void main(String[] args) {
56 IndyUsesCondyBSM.m();
57 return;
58 }
59
60 BootstrapMethods:
61 0: #65 REF_invokeStatic IndyUsesCondyBSM.Condybsm:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/Class;)Ljava/lang/Object;
62 Method arguments:
63 1: #74 REF_invokeStatic IndyUsesCondyBSM.Indybsm:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;
64 Method arguments:
65 }
66 */
67
68 class IndyUsesCondyBSM {
69 0xCAFEBABE;
70 0; // minor version
71 55; // version
72 [88] { // Constant Pool
73 ; // first element is empty
74 String #48; // #1 at 0x0A
75 String #49; // #2 at 0x0D
76 String #56; // #3 at 0x10
77 String #58; // #4 at 0x13
78 class #51; // #5 at 0x16
79 Method #62 #20; // #6 at 0x19
80 InvokeDynamic 0s #53; // #7 at 0x1E
81 Method #5 #71; // #8 at 0x23
82 Method #26 #47; // #9 at 0x28
83 Field #21 #86; // #10 at 0x2D
84 Method #28 #75; // #11 at 0x32
85 Field #61 #82; // #12 at 0x37
86 Method #18 #36; // #13 at 0x3C
87 Method #29 #46; // #14 at 0x41
88 Method #57 #87; // #15 at 0x46
89 Method #5 #73; // #16 at 0x4B
90 Dynamic 0s #23; // #17 at 0x50
91 class #80; // #18 at 0x55
92 Utf8 "java/io/PrintStream"; // #19 at 0x58
93 NameAndType #81 #59; // #20 at 0x6E
94 class #85; // #21 at 0x73
95 Utf8 "java/lang/invoke/MethodType"; // #22 at 0x76
96 NameAndType #31 #77; // #23 at 0x94
97 Utf8 "m"; // #24 at 0x99
98 Utf8 "java/lang/invoke/MethodHandles$Lookup"; // #25 at 0x9D
99 class #19; // #26 at 0xC5
100 Utf8 "SourceFile"; // #27 at 0xC8
101 class #22; // #28 at 0xD5
102 class #25; // #29 at 0xD8
103 Utf8 "IndyUsesCondyBSM.jasm"; // #30 at 0xDB
104 Utf8 "name"; // #31 at 0xF3
105 Utf8 "Indybsm"; // #32 at 0xFA
106 Utf8 "findStatic"; // #33 at 0x0104
107 Utf8 "(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/Class;)Ljava/lang/Object;"; // #34 at 0x0111
108 Utf8 "()Ljava/lang/invoke/MethodHandles$Lookup;"; // #35 at 0x0172
109 NameAndType #81 #66; // #36 at 0x019E
110 Utf8 "MH_foo"; // #37 at 0x01A3
111 Method #5 #84; // #38 at 0x01AC
112 Utf8 "Code"; // #39 at 0x01B1
113 Utf8 "lookup"; // #40 at 0x01B8
114 Utf8 "([Ljava/lang/String;)V"; // #41 at 0x01C1
115 Utf8 "out"; // #42 at 0x01DA
116 Utf8 "BootstrapMethods"; // #43 at 0x01E0
117 Utf8 "(Ljava/lang/Class;Ljava/lang/String;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/MethodHandle;"; // #44 at 0x01F3
118 Utf8 "Ljava/lang/Class;"; // #45 at 0x0257
119 NameAndType #33 #44; // #46 at 0x026B
120 NameAndType #52 #63; // #47 at 0x0270
121 Utf8 "0"; // #48 at 0x0275
122 Utf8 "In Condybsm"; // #49 at 0x0279
123 Utf8 "java/lang/invoke/MethodHandles"; // #50 at 0x0287
124 Utf8 "IndyUsesCondyBSM"; // #51 at 0x02A8
125 Utf8 "println"; // #52 at 0x02BB
126 NameAndType #58 #67; // #53 at 0x02C5
127 Utf8 "java/lang/Object"; // #54 at 0x02CA
128 Utf8 "java/lang/System"; // #55 at 0x02DD
129 Utf8 "In Indybsm target CallSite method foo"; // #56 at 0x02F0
130 class #50; // #57 at 0x0318
131 Utf8 "foo"; // #58 at 0x031B
132 Utf8 "()V"; // #59 at 0x0321
133 Utf8 "()Ljava/lang/invoke/MethodHandle;"; // #60 at 0x0327
134 class #55; // #61 at 0x034B
135 class #54; // #62 at 0x034E
136 Utf8 "(Ljava/lang/String;)V"; // #63 at 0x0351
137 Utf8 "main"; // #64 at 0x0369
138 MethodHandle 6b #79; // #65 at 0x0370
139 Utf8 "(Ljava/lang/invoke/MethodHandle;)V"; // #66 at 0x0374
140 Utf8 "()I"; // #67 at 0x0399
141 Utf8 "(Ljava/lang/Class;)Ljava/lang/invoke/MethodType;"; // #68 at 0x039F
142 Utf8 "(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;"; // #69 at 0x03D2
143 Utf8 "Condybsm"; // #70 at 0x0448
144 NameAndType #37 #60; // #71 at 0x0453
145 NameAndType #70 #34; // #72 at 0x0458
146 NameAndType #24 #67; // #73 at 0x045D
147 MethodHandle 6b #38; // #74 at 0x0462
148 NameAndType #78 #68; // #75 at 0x0466
149 Utf8 "Ljava/io/PrintStream;"; // #76 at 0x046B
150 Utf8 "Ljava/lang/Object;"; // #77 at 0x0483
151 Utf8 "methodType"; // #78 at 0x0498
152 Method #5 #72; // #79 at 0x04A5
153 Utf8 "java/lang/invoke/ConstantCallSite"; // #80 at 0x04AA
154 Utf8 "<init>"; // #81 at 0x04CE
155 NameAndType #42 #76; // #82 at 0x04D7
156 Utf8 "TYPE"; // #83 at 0x04DC
157 NameAndType #32 #69; // #84 at 0x04E3
158 Utf8 "java/lang/Integer"; // #85 at 0x04E8
159 NameAndType #83 #45; // #86 at 0x04FC
160 NameAndType #40 #35; // #87 at 0x0501
161 } // Constant Pool
162
163 0x0020; // access ACC_SUPER
164 #5;// this_cpx
165 #62;// super_cpx
166
167 [0] { // Interfaces
168 } // Interfaces
169
170 [0] { // fields
171 } // fields
172
173 [7] { // methods
174 { // Member at 0x0512
175 0x0001; // access
176 #81; // name_cpx
177 #59; // sig_cpx
178 [1] { // Attributes
179 Attr(#39, 17) { // Code at 0x051A
180 1; // max_stack
181 1; // max_locals
182 Bytes[5]{
183 0x2AB70006B1;
184 }
185 [0] { // Traps
186 } // end Traps
187 [0] { // Attributes
188 } // Attributes
189 } // end Code
190 } // Attributes
191 } // Member
192 ;
193 { // Member at 0x0531
194 0x0009; // access
195 #70; // name_cpx
196 #34; // sig_cpx
197 [1] { // Attributes
198 Attr(#39, 23) { // Code at 0x0539
199 2; // max_stack
200 3; // max_locals
201 Bytes[11]{
202 0xB2000C1202B60009;
203 0x1201B0;
204 }
205 [0] { // Traps
206 } // end Traps
207 [0] { // Attributes
208 } // Attributes
209 } // end Code
210 } // Attributes
211 } // Member
212 ;
213 { // Member at 0x0556
214 0x0009; // access
215 #58; // name_cpx
216 #67; // sig_cpx
217 [1] { // Attributes
218 Attr(#39, 23) { // Code at 0x055E
219 2; // max_stack
220 0; // max_locals
221 Bytes[11]{
222 0xB2000C1203B60009;
223 0x1064AC;
224 }
225 [0] { // Traps
226 } // end Traps
227 [0] { // Attributes
228 } // Attributes
229 } // end Code
230 } // Attributes
231 } // Member
232 ;
233 { // Member at 0x057B
234 0x0009; // access
235 #37; // name_cpx
236 #60; // sig_cpx
237 [1] { // Attributes
238 Attr(#39, 29) { // Code at 0x0583
239 4; // max_stack
240 0; // max_locals
241 Bytes[17]{
242 0xB8000F12051204B2;
243 0x000AB8000BB6000E;
244 0xB0;
245 }
246 [0] { // Traps
247 } // end Traps
248 [0] { // Attributes
249 } // Attributes
250 } // end Code
251 } // Attributes
252 } // Member
253 ;
254 { // Member at 0x05A6
255 0x0009; // access
256 #32; // name_cpx
257 #69; // sig_cpx
258 [1] { // Attributes
259 Attr(#39, 23) { // Code at 0x05AE
260 3; // max_stack
261 3; // max_locals
262 Bytes[11]{
263 0xBB001259B80008B7;
264 0x000DB0;
265 }
266 [0] { // Traps
267 } // end Traps
268 [0] { // Attributes
269 } // Attributes
270 } // end Code
271 } // Attributes
272 } // Member
273 ;
274 { // Member at 0x05CB
275 0x0009; // access
276 #24; // name_cpx
277 #67; // sig_cpx
278 [1] { // Attributes
279 Attr(#39, 21) { // Code at 0x05D3
280 2; // max_stack
281 0; // max_locals
282 Bytes[9]{
283 0x130011BA00070000;
284 0xAC;
285 }
286 [0] { // Traps
287 } // end Traps
288 [0] { // Attributes
289 } // Attributes
290 } // end Code
291 } // Attributes
292 } // Member
293 ;
294 { // Member at 0x05EE
295 0x0009; // access
296 #64; // name_cpx
297 #41; // sig_cpx
298 [1] { // Attributes
299 Attr(#39, 16) { // Code at 0x05F6
300 1; // max_stack
301 1; // max_locals
302 Bytes[4]{
303 0xB80010B1;
304 }
305 [0] { // Traps
306 } // end Traps
307 [0] { // Attributes
308 } // Attributes
309 } // end Code
310 } // Attributes
311 } // Member
312 } // methods
313
314 [2] { // Attributes
315 Attr(#27, 2) { // SourceFile at 0x060E
316 #30;
317 } // end SourceFile
318 ;
319 Attr(#43, 10) { // BootstrapMethods at 0x0616
320 [2] { // bootstrap_methods
321 { // bootstrap_method
322 #65; // bootstrap_method_ref
323 [0] { // bootstrap_arguments
324 } // bootstrap_arguments
325 } // bootstrap_method
326 ;
327 { // bootstrap_method
328 #74; // bootstrap_method_ref
329 [0] { // bootstrap_arguments
330 } // bootstrap_arguments
331 } // bootstrap_method
332 }
333 } // end BootstrapMethods
334 } // Attributes
335 } // end class IndyUsesCondyBSM