Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/vm/runtime/defmeth/AccessibilityFlagsTest.java
41159 views
1
/*
2
* Copyright (c) 2013, 2021, 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
* @test
26
*
27
* @modules java.base/jdk.internal.org.objectweb.asm:+open java.base/jdk.internal.org.objectweb.asm.util:+open
28
* @library /vmTestbase /test/lib
29
*
30
* @comment build retransform.jar in current dir
31
* @run driver vm.runtime.defmeth.shared.BuildJar
32
*
33
* @run driver jdk.test.lib.FileInstaller . .
34
* @run main/othervm/native
35
* -agentlib:redefineClasses
36
* -javaagent:retransform.jar
37
* vm.runtime.defmeth.AccessibilityFlagsTest
38
*/
39
package vm.runtime.defmeth;
40
41
import java.util.Set;
42
43
import vm.runtime.defmeth.shared.DefMethTest;
44
import vm.runtime.defmeth.shared.data.*;
45
import vm.runtime.defmeth.shared.data.method.body.EmptyBody;
46
import vm.runtime.defmeth.shared.builder.TestBuilder;
47
48
import static jdk.internal.org.objectweb.asm.Opcodes.*;
49
import static vm.runtime.defmeth.shared.ExecutionMode.*;
50
51
/*
52
* Test allowed combinations of access flags on methods in interfaces.
53
* Based on assertions from JVMS.
54
*/
55
public class AccessibilityFlagsTest extends DefMethTest {
56
public static void main(String[] args) {
57
DefMethTest.runTest(AccessibilityFlagsTest.class,
58
/* majorVer */ Set.of(MAX_MAJOR_VER),
59
/* flags */ Set.of(0, ACC_SYNCHRONIZED),
60
/* redefine */ Set.of(false, true),
61
/* execMode */ Set.of(DIRECT, REFLECTION, INVOKE_EXACT, INVOKE_GENERIC, INVOKE_WITH_ARGS, INDY));
62
}
63
64
/* ====================================================================== */
65
66
// Methods of interfaces may set any of the flags in Table 4.5 except
67
// ACC_PROTECTED, ACC_FINAL, ACC_NATIVE, and ACC_SYNCHRONIZED (9.4);
68
69
/**
70
* interface I { protected void m(); }
71
*
72
* TEST: ClassLoader.loadClass("I") ==> ClassFormatError
73
*/
74
public void testProtectedMethodAbstract() {
75
expectClassFormatError(
76
createAbstractMethodInterface(ACC_PROTECTED));
77
78
expectClassFormatError(
79
createAbstractMethodInterface(ACC_PROTECTED | ACC_PUBLIC));
80
81
expectClassFormatError(
82
createAbstractMethodInterface(ACC_PROTECTED | ACC_PRIVATE));
83
84
}
85
86
/**
87
* interface I { protected void m() default {}; }
88
*
89
* TEST: ClassLoader.loadClass("I") ==> ClassFormatError
90
*/
91
public void testProtectedMethodDefault() {
92
expectClassFormatError(
93
createDefaultMethodInterface(ACC_PROTECTED));
94
95
expectClassFormatError(
96
createDefaultMethodInterface(ACC_PROTECTED | ACC_PUBLIC));
97
98
expectClassFormatError(
99
createDefaultMethodInterface(ACC_PROTECTED | ACC_PRIVATE));
100
}
101
102
/**
103
* interface I { final void m() default {}; }
104
*
105
* TEST: ClassLoader.loadClass("I") ==> ClassFormatError
106
*/
107
public void testFinalMethodDefault() {
108
expectClassFormatError(
109
createDefaultMethodInterface(ACC_FINAL));
110
111
expectClassFormatError(
112
createDefaultMethodInterface(ACC_FINAL | ACC_PUBLIC));
113
114
expectClassFormatError(
115
createDefaultMethodInterface(ACC_FINAL | ACC_PRIVATE));
116
}
117
118
/**
119
* interface I { native void m() default {}; }
120
*
121
* TEST: ClassLoader.loadClass("I") ==> ClassFormatError
122
*/
123
public void testNativeMethodDefault() {
124
expectClassFormatError(
125
createDefaultMethodInterface(ACC_NATIVE));
126
127
expectClassFormatError(
128
createDefaultMethodInterface(ACC_NATIVE | ACC_PUBLIC));
129
130
expectClassFormatError(
131
createDefaultMethodInterface(ACC_NATIVE | ACC_PRIVATE));
132
}
133
134
135
/**
136
* interface I { synchronized void m(); }
137
*
138
* TEST: ClassLoader.loadClass("I") ==> ClassFormatError
139
*/
140
public void testSynchronizedMethodAbstract() {
141
expectClassFormatError(
142
createAbstractMethodInterface(ACC_SYNCHRONIZED));
143
144
expectClassFormatError(
145
createAbstractMethodInterface(ACC_SYNCHRONIZED | ACC_PUBLIC));
146
147
expectClassFormatError(
148
createAbstractMethodInterface(ACC_SYNCHRONIZED | ACC_PRIVATE));
149
}
150
151
/**
152
* interface I { synchronized void m() default {}; }
153
*
154
* TEST: ClassLoader.loadClass("I") ==> ClassFormatError
155
*/
156
public void testSynchronizedMethodDefault() {
157
expectClassFormatError(
158
createDefaultMethodInterface(ACC_SYNCHRONIZED));
159
160
expectClassFormatError(
161
createDefaultMethodInterface(ACC_SYNCHRONIZED | ACC_PUBLIC));
162
163
expectClassFormatError(
164
createDefaultMethodInterface(ACC_SYNCHRONIZED | ACC_PRIVATE));
165
}
166
167
/* ===================================================================== */
168
169
// [methods of interfaces] must have exactly one of the ACC_PUBLIC or ACC_PRIVATE flags set.
170
171
/**
172
* interface I { private void m() default {}; }
173
*
174
* TEST: ClassLoader.loadClass("I") == succeeds
175
*/
176
public void testPrivateMethodDefault() {
177
loadClass(
178
createDefaultMethodInterface(ACC_PRIVATE));
179
}
180
181
/**
182
* interface I { public void m(); }
183
*
184
* TEST: ClassLoader.loadClass("I") == succeeds
185
*/
186
public void testPublicMethodAbstract() {
187
loadClass(
188
createAbstractMethodInterface(ACC_PUBLIC));
189
}
190
191
/**
192
* interface I { public void m() default {}; }
193
*
194
*/
195
public void testPublicMethodDefault() {
196
loadClass(
197
createDefaultMethodInterface(ACC_PUBLIC));
198
}
199
200
/**
201
* interface I { private public void m(); }
202
*
203
* TEST: ClassLoader.loadClass("I") ==> ClassFormatError
204
*/
205
public void testPrivatePublicMethodAbstract() {
206
expectClassFormatError(
207
createAbstractMethodInterface(ACC_PUBLIC | ACC_PRIVATE));
208
}
209
210
/**
211
* interface I { private public void m() default {}; }
212
*
213
* TEST: ClassLoader.loadClass("I") ==> ClassFormatError
214
*/
215
public void testPrivatePublicMethodDefault() {
216
expectClassFormatError(
217
createDefaultMethodInterface(ACC_PUBLIC | ACC_PRIVATE));
218
}
219
220
/* ===================================================================== */
221
222
// Methods of classes may set any of the flags in Table 4.5 except
223
// ACC_PROTECTED, ACC_FINAL, ACC_NATIVE, and ACC_SYNCHRONIZED (9.4);
224
// they must have exactly one of the ACC_PUBLIC or ACC_PRIVATE flags set.
225
//
226
// The following flags are allowed:
227
// ACC_PUBLIC 0x0001 Declared public; may be accessed from outside its package.
228
// ACC_PRIVATE 0x0002 Declared private; accessible only within the defining class.
229
// ACC_STATIC 0x0008 Declared static.
230
// ACC_BRIDGE 0x0040 A bridge method, generated by the compiler.
231
// ACC_VARARGS 0x0080 Declared with variable number of arguments.
232
// ACC_SYNTHETIC 0x1000 Declared synthetic; not present in the source code.
233
234
/**
235
* interface I { static void m() default {}; }
236
*
237
* TEST: ClassLoader.loadClass("I") == succeeds
238
*/
239
public void testStaticMethodDefault() {
240
loadClass(
241
createDefaultMethodInterface(ACC_STATIC | ACC_PUBLIC));
242
loadClass(
243
createDefaultMethodInterface(ACC_STATIC | ACC_PRIVATE));
244
}
245
246
/* =============================================================================== */
247
248
// If a specific method of a class or interface has its ACC_ABSTRACT flag set,
249
// it must not have any of its ACC_FINAL, ACC_NATIVE, ACC_PRIVATE, ACC_STATIC,
250
// or ACC_SYNCHRONIZED flags set (8.4.3.1, 8.4.3.3, 8.4.3.4).
251
252
/**
253
* interface I { final void m(); }
254
* abstract class C { abstract final void m(); }
255
*
256
* TEST: ClassLoader.loadClass("I") ==> ClassFormatError
257
* TEST: ClassLoader.loadClass("C") ==> ClassFormatError
258
*/
259
public void testFinalMethodAbstract() {
260
/* interface I */
261
expectClassFormatError(
262
createAbstractMethodInterface(ACC_FINAL));
263
264
expectClassFormatError(
265
createAbstractMethodInterface(ACC_FINAL | ACC_PUBLIC));
266
267
/* abstract class C */
268
expectClassFormatError(
269
createAbstractMethodClass(ACC_FINAL));
270
}
271
272
/**
273
* interface I { native void m(); }
274
* interface K { native void m() default {}; }
275
* abstract class C { abstract native m(); }
276
*
277
* TEST: ClassLoader.loadClass("I") ==> ClassFormatError
278
* TEST: ClassLoader.loadClass("K") ==> ClassFormatError
279
* TEST: ClassLoader.loadClass("C") ==> ClassFormatError
280
*/
281
public void testNativeMethodAbstract() {
282
/* interface I */
283
expectClassFormatError(
284
createDefaultMethodInterface(ACC_NATIVE));
285
286
expectClassFormatError(
287
createDefaultMethodInterface(ACC_NATIVE | ACC_PUBLIC));
288
289
/* interface K */
290
expectClassFormatError(
291
createAbstractMethodInterface(ACC_NATIVE));
292
293
expectClassFormatError(
294
createAbstractMethodInterface(ACC_NATIVE | ACC_PUBLIC));
295
296
/* abstract class C */
297
expectClassFormatError(
298
createAbstractMethodClass(ACC_NATIVE));
299
}
300
301
/**
302
* interface I { private void m(); }
303
* abstract class C { abstract private void m(); }
304
*
305
* TEST: ClassLoader.loadClass("I") ==> ClassFormatError
306
* TEST: ClassLoader.loadClass("C") ==> ClassFormatError
307
*/
308
public void testPrivateMethodAbstract() {
309
/* interface I */
310
expectClassFormatError(
311
createAbstractMethodInterface(ACC_PRIVATE));
312
313
/* abstract class C */
314
expectClassFormatError(
315
createAbstractMethodClass(ACC_PRIVATE));
316
}
317
318
/**
319
* interface I { static void m(); }
320
* abstract class C { abstract static void m(); }
321
*
322
* TEST: ClassLoader.loadClass("I") ==> ClassFormatError
323
* TEST: ClassLoader.loadClass("C") ==> ClassFormatError
324
*/
325
public void testStaticMethodAbstract() {
326
/* interface I */
327
expectClassFormatError(
328
createAbstractMethodInterface(ACC_STATIC));
329
330
expectClassFormatError(
331
createAbstractMethodInterface(ACC_STATIC | ACC_PUBLIC));
332
333
/* abstract class C */
334
expectClassFormatError(
335
createAbstractMethodClass(ACC_STATIC));
336
}
337
338
/* =============================================================================== */
339
340
/**
341
* interface I { abstract void m() default {}; }
342
*
343
* TEST: ClassLoader.loadClass("I") ==> ClassFormatError
344
*/
345
public void testAbstractMethodDefault() {
346
expectClassFormatError(
347
createDefaultMethodInterface(ACC_ABSTRACT));
348
}
349
350
/* ====================================================================== */
351
352
// Helper methods
353
private Interface createAbstractMethodInterface(int acc) {
354
return factory.getBuilder()
355
.intf("I")
356
.abstractMethod("m", "()V").flags(acc)
357
.build()
358
.build();
359
}
360
361
private Clazz createAbstractMethodClass(int acc) {
362
return factory.getBuilder()
363
.clazz("I")
364
.abstractMethod("m", "()V").flags(acc)
365
.build()
366
.build();
367
}
368
369
private Interface createDefaultMethodInterface(int acc) {
370
return factory.getBuilder()
371
.intf("I")
372
.defaultMethod("m", "()V").flags(acc)
373
.body(new EmptyBody())
374
.build()
375
.build();
376
}
377
378
private void expectException(Clazz clz, Class<? extends Throwable> exc) {
379
TestBuilder b = factory.getBuilder()
380
.register(clz);
381
382
b.test().loadClass(clz).throws_(exc).done()
383
.run();
384
}
385
386
private void loadClass(Clazz clz) {
387
TestBuilder b = factory.getBuilder()
388
.register(clz);
389
390
b.test().loadClass(clz).ignoreResult().done()
391
.run();
392
}
393
394
private void expectClassFormatError(Clazz clz) {
395
expectException(clz, ClassFormatError.class);
396
}
397
}
398
399