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