Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/intrinsics/object/TestClone.java
41153 views
1
/*
2
* Copyright (c) 2014, 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
* @bug 8033626 8246453 8248467
27
* @summary assert(ex_map->jvms()->same_calls_as(_exceptions->jvms())) failed: all collected exceptions must come from the same place
28
* @modules java.base/jdk.internal.misc
29
* @library /test/lib
30
*
31
* @run main/othervm -XX:-TieredCompilation -Xbatch
32
* -XX:CompileCommand=compileonly,compiler.intrinsics.object.TestClone::test*
33
* compiler.intrinsics.object.TestClone
34
* @run main/othervm -XX:-TieredCompilation -Xbatch
35
* -XX:+IgnoreUnrecognizedVMOptions -XX:+StressReflectiveCode
36
* -XX:CompileCommand=compileonly,compiler.intrinsics.object.TestClone::test*
37
* compiler.intrinsics.object.TestClone
38
* @run main/othervm -XX:-TieredCompilation -Xbatch
39
* -XX:+IgnoreUnrecognizedVMOptions -XX:+StressReflectiveCode -XX:+VerifyGraphEdges
40
* -XX:CompileCommand=compileonly,compiler.intrinsics.object.TestClone::test*
41
* compiler.intrinsics.object.TestClone
42
*/
43
44
package compiler.intrinsics.object;
45
46
import jdk.test.lib.Asserts;
47
48
abstract class MyAbstract {
49
50
public Object myClone1() throws CloneNotSupportedException {
51
return this.clone();
52
}
53
54
public Object myClone2() throws CloneNotSupportedException {
55
return this.clone();
56
}
57
58
public Object myClone3() throws CloneNotSupportedException {
59
return this.clone();
60
}
61
}
62
63
class MyClass1 extends MyAbstract {
64
@Override
65
public Object clone() throws CloneNotSupportedException {
66
return super.clone();
67
}
68
}
69
70
class MyClass2 extends MyAbstract {
71
72
}
73
74
class MyClass3 extends MyAbstract implements Cloneable {
75
@Override
76
public Object clone() throws CloneNotSupportedException {
77
return super.clone();
78
}
79
}
80
81
class MyClass4 extends MyAbstract implements Cloneable {
82
83
}
84
85
public class TestClone implements Cloneable {
86
static class A extends TestClone {}
87
static class B extends TestClone {
88
public B clone() {
89
return (B)TestClone.b;
90
}
91
}
92
static class C extends TestClone {
93
public C clone() {
94
return (C)TestClone.c;
95
}
96
}
97
static class D extends TestClone {
98
public D clone() {
99
return (D)TestClone.d;
100
}
101
}
102
static TestClone a = new A(), b = new B(), c = new C(), d = new D();
103
104
public static Object test1(TestClone o) throws CloneNotSupportedException {
105
// Polymorphic call site: >90% Object::clone / <10% other methods
106
return o.clone();
107
}
108
109
public static void test2(MyAbstract obj, boolean shouldThrow) throws Exception {
110
try {
111
obj.myClone1();
112
} catch (Exception e) {
113
return; // Expected
114
}
115
Asserts.assertFalse(shouldThrow, "No exception thrown");
116
}
117
118
public static void test3(MyAbstract obj, boolean shouldThrow) throws Exception {
119
try {
120
obj.myClone2();
121
} catch (Exception e) {
122
return; // Expected
123
}
124
Asserts.assertFalse(shouldThrow, "No exception thrown");
125
}
126
127
public static void test4(MyAbstract obj, boolean shouldThrow) throws Exception {
128
try {
129
obj.myClone3();
130
} catch (Exception e) {
131
return; // Expected
132
}
133
Asserts.assertFalse(shouldThrow, "No exception thrown");
134
}
135
136
public static void main(String[] args) throws Exception {
137
TestClone[] params1 = {a, a, a, a, a, a, a, a, a, a, a,
138
a, a, a, a, a, a, a, a, a, a, a,
139
a, a, a, a, a, a, a, a, a, a, a,
140
b, c, d};
141
142
MyClass1 obj1 = new MyClass1();
143
MyClass2 obj2 = new MyClass2();
144
MyClass3 obj3 = new MyClass3();
145
MyClass4 obj4 = new MyClass4();
146
147
for (int i = 0; i < 15000; i++) {
148
test1(params1[i % params1.length]);
149
150
test2(obj1, true);
151
test2(obj2, true);
152
153
test3(obj3, false);
154
test3(obj2, true);
155
156
test4(obj3, false);
157
test4(obj4, false);
158
}
159
160
Asserts.assertTrue(test1(a) != a);
161
Asserts.assertTrue(test1(b) == b);
162
Asserts.assertTrue(test1(c) == c);
163
Asserts.assertTrue(test1(d) == d);
164
165
try {
166
test1(null);
167
throw new AssertionError("No exception thrown");
168
} catch (NullPointerException e) { /* expected */ }
169
170
System.out.println("TEST PASSED");
171
}
172
}
173
174