Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/jit/deoptimization/test08/test08.java
40948 views
1
/*
2
* Copyright (c) 2008, 2020, 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
* @summary converted from VM Testbase jit/deoptimization/test08.
28
* VM Testbase keywords: [jit, quick]
29
*
30
* @library /vmTestbase
31
* /test/lib
32
* @run main/othervm jit.deoptimization.test08.test08
33
*/
34
35
package jit.deoptimization.test08;
36
37
import nsk.share.TestFailure;
38
39
/*
40
* Simple recursion that should causes hotspot to deoptimize
41
* used_alot and A.foo and A.bar methods
42
* Expected result for the test is: 0
43
*
44
* run with the -XX:TraceDeoptimization to observ the result.
45
*/
46
47
public class test08 {
48
public static void main (String[] args) {
49
A obj = new A();
50
for (int index = 0; index < 1; index++) {
51
obj.used_alot();
52
}
53
}
54
}
55
56
class A {
57
static int result = 0;
58
59
synchronized public int foo(int index, int iter) {
60
synchronized (A.a_ext) {
61
if (index == 0)
62
return result;
63
else if (iter <= sIteration / 2) {
64
result = bar(index) * foo(--index, iter);
65
} else {
66
try {
67
// halfway through the max iterations
68
// create a B. This should cause the
69
// used_alot to be deoptimized
70
// Call b.frame for the remaining part of the recursion
71
if (b == null)
72
b = Class.forName("jit.deoptimization.test08.B").newInstance();
73
result *= ((B)b).foo(index, iter);
74
} catch (Exception x) {
75
throw new TestFailure("Class not found: B");
76
}
77
}
78
}
79
return result;
80
}
81
82
// Does nothing but it will let be over written in class C, See Below
83
synchronized public int bar(int index) {
84
synchronized (a_ext) {
85
for (int i=0; i<5; i++)
86
index--;
87
}
88
return 0;
89
}
90
91
synchronized public void used_alot() {
92
int result = 1;
93
94
synchronized (a_ext) {
95
for (int index = 1; index <= sIteration; index++) {
96
result *= foo(index, index);
97
}
98
}
99
100
if (result != 0) {
101
System.err.println ("Result: " + result);
102
System.exit (1);
103
}
104
}
105
106
protected Object b = null;
107
protected static final int sIteration = 1000;
108
protected static final Object a_ext = new Object();
109
}
110
111
class B extends A {
112
// Override foo in order to force deoptimization.
113
// Also creates and instance of class C in the last
114
// iteration in order to force A.foo to get deoptimized
115
// otherwise just do something stupid.
116
synchronized public int foo(int index, int iter) {
117
synchronized (A.a_ext) {
118
synchronized (B.b_ext) {
119
// Make sure that this class was created at least
120
// halfway through the iteration. Simple sanity check
121
if (iter < sIteration /2) {
122
System.out.println ("class B create to early");
123
System.exit(1);
124
}
125
126
if (iter == sIteration) {
127
try {
128
result = ((C)(Class.forName("jit.deoptimization.test08.C").newInstance())).foo(index,iter);
129
result *= ((C)(Class.forName("jit.deoptimization.test08.C").newInstance())).bar(index);
130
131
} catch (Exception x) {
132
throw new TestFailure("Class not found: C");
133
}
134
} else {
135
result = bar(index);
136
if (index != 0)
137
result += foo(--index, iter);
138
}
139
}
140
}
141
return result;
142
}
143
protected static final Object b_ext = new Object();
144
}
145
146
class C extends B {
147
synchronized public int foo(int index, int iter) {
148
synchronized (A.a_ext) {
149
synchronized (B.b_ext) {
150
synchronized (C.c_ext) {
151
for (int i=0; i<iter; i++) {
152
result = bar(i);
153
if (i == iter-2) {
154
try {
155
result = ((D)(Class.forName("jit.deoptimization.test08.D").newInstance())).bar(index);
156
} catch (Exception x) {
157
throw new TestFailure("Class not found: D");
158
}
159
}
160
}
161
}
162
}
163
}
164
return result;
165
}
166
protected static final Object c_ext = new Object();
167
}
168
169
class D extends C {
170
synchronized public int bar(int index) {
171
return 1;
172
}
173
}
174
175