25 * @test |
25 * @test |
26 * @library /test/lib |
26 * @library /test/lib |
27 * |
27 * |
28 * @requires !vm.graal.enabled |
28 * @requires !vm.graal.enabled |
29 * |
29 * |
30 * @run main/othervm/native -Xbatch -XX:CompileCommand=dontinline,*::test* -Xint -DTHROW=false ClassInitBarrier |
30 * @run main/othervm/native -Xbatch -XX:CompileCommand=dontinline,*::test* -Xint -DTHROW=false -Xcheck:jni ClassInitBarrier |
31 * @run main/othervm/native -Xbatch -XX:CompileCommand=dontinline,*::test* -Xint -DTHROW=true ClassInitBarrier |
31 * @run main/othervm/native -Xbatch -XX:CompileCommand=dontinline,*::test* -Xint -DTHROW=true -Xcheck:jni ClassInitBarrier |
32 * |
32 * |
33 * @run main/othervm/native -Xbatch -XX:CompileCommand=dontinline,*::test* -XX:TieredStopAtLevel=1 -DTHROW=false ClassInitBarrier |
33 * @run main/othervm/native -Xbatch -XX:CompileCommand=dontinline,*::test* -XX:TieredStopAtLevel=1 -DTHROW=false -Xcheck:jni ClassInitBarrier |
34 * @run main/othervm/native -Xbatch -XX:CompileCommand=dontinline,*::test* -XX:TieredStopAtLevel=1 -DTHROW=true ClassInitBarrier |
34 * @run main/othervm/native -Xbatch -XX:CompileCommand=dontinline,*::test* -XX:TieredStopAtLevel=1 -DTHROW=true -Xcheck:jni ClassInitBarrier |
35 * |
35 * |
36 * @run main/othervm/native -Xbatch -XX:CompileCommand=dontinline,*::test* -XX:-TieredCompilation -DTHROW=false ClassInitBarrier |
36 * @run main/othervm/native -Xbatch -XX:CompileCommand=dontinline,*::test* -XX:-TieredCompilation -DTHROW=false -Xcheck:jni ClassInitBarrier |
37 * @run main/othervm/native -Xbatch -XX:CompileCommand=dontinline,*::test* -XX:-TieredCompilation -DTHROW=true ClassInitBarrier |
37 * @run main/othervm/native -Xbatch -XX:CompileCommand=dontinline,*::test* -XX:-TieredCompilation -DTHROW=true -Xcheck:jni ClassInitBarrier |
38 * |
38 * |
39 * @run main/othervm/native -Xbatch -XX:CompileCommand=dontinline,*::test* -XX:TieredStopAtLevel=1 -DTHROW=false -XX:CompileCommand=dontinline,*::static* ClassInitBarrier |
39 * @run main/othervm/native -Xbatch -XX:CompileCommand=dontinline,*::test* -XX:TieredStopAtLevel=1 -DTHROW=false -XX:CompileCommand=dontinline,*::static* -Xcheck:jni ClassInitBarrier |
40 * @run main/othervm/native -Xbatch -XX:CompileCommand=dontinline,*::test* -XX:TieredStopAtLevel=1 -DTHROW=true -XX:CompileCommand=dontinline,*::static* ClassInitBarrier |
40 * @run main/othervm/native -Xbatch -XX:CompileCommand=dontinline,*::test* -XX:TieredStopAtLevel=1 -DTHROW=true -XX:CompileCommand=dontinline,*::static* -Xcheck:jni ClassInitBarrier |
41 * @run main/othervm/native -Xbatch -XX:CompileCommand=dontinline,*::test* -XX:-TieredCompilation -DTHROW=false -XX:CompileCommand=dontinline,*::static* ClassInitBarrier |
41 * @run main/othervm/native -Xbatch -XX:CompileCommand=dontinline,*::test* -XX:-TieredCompilation -DTHROW=false -XX:CompileCommand=dontinline,*::static* -Xcheck:jni ClassInitBarrier |
42 * @run main/othervm/native -Xbatch -XX:CompileCommand=dontinline,*::test* -XX:-TieredCompilation -DTHROW=true -XX:CompileCommand=dontinline,*::static* ClassInitBarrier |
42 * @run main/othervm/native -Xbatch -XX:CompileCommand=dontinline,*::test* -XX:-TieredCompilation -DTHROW=true -XX:CompileCommand=dontinline,*::static* -Xcheck:jni ClassInitBarrier |
43 * |
43 * |
44 * @run main/othervm/native -Xbatch -XX:CompileCommand=dontinline,*::test* -XX:TieredStopAtLevel=1 -DTHROW=false -XX:CompileCommand=exclude,*::static* ClassInitBarrier |
44 * @run main/othervm/native -Xbatch -XX:CompileCommand=dontinline,*::test* -XX:TieredStopAtLevel=1 -DTHROW=false -XX:CompileCommand=exclude,*::static* -Xcheck:jni ClassInitBarrier |
45 * @run main/othervm/native -Xbatch -XX:CompileCommand=dontinline,*::test* -XX:TieredStopAtLevel=1 -DTHROW=true -XX:CompileCommand=exclude,*::static* ClassInitBarrier |
45 * @run main/othervm/native -Xbatch -XX:CompileCommand=dontinline,*::test* -XX:TieredStopAtLevel=1 -DTHROW=true -XX:CompileCommand=exclude,*::static* -Xcheck:jni ClassInitBarrier |
46 * @run main/othervm/native -Xbatch -XX:CompileCommand=dontinline,*::test* -XX:-TieredCompilation -DTHROW=false -XX:CompileCommand=exclude,*::static* ClassInitBarrier |
46 * @run main/othervm/native -Xbatch -XX:CompileCommand=dontinline,*::test* -XX:-TieredCompilation -DTHROW=false -XX:CompileCommand=exclude,*::static* -Xcheck:jni ClassInitBarrier |
47 * @run main/othervm/native -Xbatch -XX:CompileCommand=dontinline,*::test* -XX:-TieredCompilation -DTHROW=true -XX:CompileCommand=exclude,*::static* ClassInitBarrier |
47 * @run main/othervm/native -Xbatch -XX:CompileCommand=dontinline,*::test* -XX:-TieredCompilation -DTHROW=true -XX:CompileCommand=exclude,*::static* -Xcheck:jni ClassInitBarrier |
48 */ |
48 */ |
49 |
49 |
50 import jdk.test.lib.Asserts; |
50 import jdk.test.lib.Asserts; |
51 |
51 |
52 import java.util.*; |
52 import java.util.*; |
87 |
91 |
88 static int staticF; |
92 static int staticF; |
89 |
93 |
90 int f; |
94 int f; |
91 void m() {} |
95 void m() {} |
|
96 |
|
97 static native boolean init(Class<B> cls); |
92 } |
98 } |
93 |
99 |
94 static class B extends A {} |
100 static class B extends A {} |
95 |
101 |
96 static void testInvokeStatic(Runnable action) { A.staticM(action); } |
102 static void testInvokeStatic(Runnable action) { A.staticM(action); } |
97 static void testInvokeStaticSync(Runnable action) { A.staticS(action); } |
103 static void testInvokeStaticSync(Runnable action) { A.staticS(action); } |
98 static void testInvokeStaticNative(Runnable action) { A.staticN(action); } |
104 static void testInvokeStaticNative(Runnable action) { A.staticN(action); } |
99 |
105 |
100 static int testGetStatic(Runnable action) { int v = A.staticF; action.run(); return v; } |
106 static int testGetStatic(Runnable action) { int v = A.staticF; action.run(); return v; } |
101 static void testPutStatic(Runnable action) { A.staticF = 1; action.run(); } |
107 static void testPutStatic(Runnable action) { A.staticF = 1; action.run(); } |
102 static A testNewInstanceA(Runnable action) { A obj = new A(); action.run(); return obj; } |
108 static A testNewInstanceA(Runnable action) { A obj = new A(); action.run(); return obj; } |
103 static B testNewInstanceB(Runnable action) { B obj = new B(); action.run(); return obj; } |
109 static B testNewInstanceB(Runnable action) { B obj = new B(); action.run(); return obj; } |
104 |
110 |
105 static int testGetField(A recv, Runnable action) { int v = recv.f; action.run(); return v; } |
111 static int testGetField(A recv, Runnable action) { int v = recv.f; action.run(); return v; } |
106 static void testPutField(A recv, Runnable action) { recv.f = 1; action.run(); } |
112 static void testPutField(A recv, Runnable action) { recv.f = 1; action.run(); } |
107 static void testInvokeVirtual(A recv, Runnable action) { recv.m(); action.run(); } |
113 static void testInvokeVirtual(A recv, Runnable action) { recv.m(); action.run(); } |
108 |
114 |
|
115 static native void testInvokeStaticJNI(Runnable action); |
|
116 static native void testInvokeStaticSyncJNI(Runnable action); |
|
117 static native void testInvokeStaticNativeJNI(Runnable action); |
|
118 |
|
119 static native int testGetStaticJNI(Runnable action); |
|
120 static native void testPutStaticJNI(Runnable action); |
|
121 static native A testNewInstanceAJNI(Runnable action); |
|
122 static native B testNewInstanceBJNI(Runnable action); |
|
123 |
|
124 static native int testGetFieldJNI(A recv, Runnable action); |
|
125 static native void testPutFieldJNI(A recv, Runnable action); |
|
126 static native void testInvokeVirtualJNI(A recv, Runnable action); |
|
127 |
109 static void runTests() { |
128 static void runTests() { |
110 checkBlockingAction(Test::testInvokeStatic); // invokestatic |
129 checkBlockingAction(Test::testInvokeStatic); // invokestatic |
|
130 checkBlockingAction(Test::testInvokeStaticSync); // invokestatic |
111 checkBlockingAction(Test::testInvokeStaticNative); // invokestatic |
131 checkBlockingAction(Test::testInvokeStaticNative); // invokestatic |
112 checkBlockingAction(Test::testInvokeStaticSync); // invokestatic |
|
113 checkBlockingAction(Test::testGetStatic); // getstatic |
132 checkBlockingAction(Test::testGetStatic); // getstatic |
114 checkBlockingAction(Test::testPutStatic); // putstatic |
133 checkBlockingAction(Test::testPutStatic); // putstatic |
115 checkBlockingAction(Test::testNewInstanceA); // new |
134 checkBlockingAction(Test::testNewInstanceA); // new |
116 |
135 |
|
136 checkNonBlockingAction(Test::testInvokeStaticJNI); // invokestatic |
|
137 checkNonBlockingAction(Test::testInvokeStaticSyncJNI); // invokestatic |
|
138 checkNonBlockingAction(Test::testInvokeStaticNativeJNI); // invokestatic |
|
139 checkNonBlockingAction(Test::testGetStaticJNI); // getstatic |
|
140 checkNonBlockingAction(Test::testPutStaticJNI); // putstatic |
|
141 checkBlockingAction(Test::testNewInstanceAJNI); // new |
|
142 |
117 A recv = testNewInstanceB(NON_BLOCKING.get()); // trigger B initialization |
143 A recv = testNewInstanceB(NON_BLOCKING.get()); // trigger B initialization |
118 checkNonBlockingAction(Test::testNewInstanceB); // new: NO BLOCKING: same thread: A being initialized, B fully initialized |
144 checkNonBlockingAction(Test::testNewInstanceB); // new: NO BLOCKING: same thread: A being initialized, B fully initialized |
119 |
145 |
120 checkNonBlockingAction(recv, Test::testGetField); // getfield |
146 checkNonBlockingAction(recv, Test::testGetField); // getfield |
121 checkNonBlockingAction(recv, Test::testPutField); // putfield |
147 checkNonBlockingAction(recv, Test::testPutField); // putfield |
122 checkNonBlockingAction(recv, Test::testInvokeVirtual); // invokevirtual |
148 checkNonBlockingAction(recv, Test::testInvokeVirtual); // invokevirtual |
|
149 |
|
150 checkNonBlockingAction(Test::testNewInstanceBJNI); // new: NO BLOCKING: same thread: A being initialized, B fully initialized |
|
151 checkNonBlockingAction(recv, Test::testGetFieldJNI); // getfield |
|
152 checkNonBlockingAction(recv, Test::testPutFieldJNI); // putfield |
|
153 checkNonBlockingAction(recv, Test::testInvokeVirtualJNI); // invokevirtual |
123 } |
154 } |
124 |
155 |
125 static void warmup() { |
156 static void warmup() { |
126 for (int i = 0; i < 20_000; i++) { |
157 for (int i = 0; i < 20_000; i++) { |
127 testInvokeStatic( NON_BLOCKING_WARMUP); |
158 testInvokeStatic( NON_BLOCKING_WARMUP); |