Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/vm/runtime/defmeth/ObjectMethodOverridesTest.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.ObjectMethodOverridesTest
38
*/
39
package vm.runtime.defmeth;
40
41
import java.util.Set;
42
43
import nsk.share.TestFailure;
44
import vm.runtime.defmeth.shared.DefMethTest;
45
import vm.runtime.defmeth.shared.data.*;
46
import vm.runtime.defmeth.shared.data.method.body.*;
47
import vm.runtime.defmeth.shared.builder.TestBuilder;
48
49
import static vm.runtime.defmeth.shared.ExecutionMode.*;
50
import static vm.runtime.defmeth.shared.data.method.body.CallMethod.IndexbyteOp.*;
51
52
/**
53
* Test that default methods don't override methods inherited from Object class.
54
*/
55
public class ObjectMethodOverridesTest extends DefMethTest {
56
57
public static void main(String[] args) {
58
DefMethTest.runTest(ObjectMethodOverridesTest.class,
59
/* majorVer */ Set.of(MAX_MAJOR_VER),
60
/* flags */ Set.of(0),
61
/* redefine */ Set.of(false, true),
62
/* execMode */ Set.of(DIRECT, REFLECTION, INVOKE_EXACT, INVOKE_GENERIC, INVOKE_WITH_ARGS, INDY));
63
}
64
65
/* protected Object clone() */
66
public void testClone(TestBuilder b) {
67
Interface I = b.intf("I")
68
.defaultMethod("clone", "()Ljava/lang/Object;")
69
.throw_(TestFailure.class)
70
.build()
71
.build();
72
73
ConcreteClass C = b.clazz("C").implement(I)
74
.concreteMethod("m", "()V")
75
// force an invokevirtual MR
76
.invoke(CallMethod.Invoke.VIRTUAL,
77
b.clazzByName("C"), b.clazzByName("C"),
78
"clone", "()Ljava/lang/Object;", METHODREF)
79
.build()
80
.build();
81
82
b.test().callSite(C, C, "m", "()V")
83
.throws_(CloneNotSupportedException.class)
84
.done();
85
}
86
87
/* boolean equals(Object obj) */
88
public void testEquals(TestBuilder b) throws ReflectiveOperationException {
89
Interface I = b.intf("I")
90
.defaultMethod("equals", "(Ljava/lang/Object;)Z")
91
.throw_(TestFailure.class)
92
.build()
93
.build();
94
95
ConcreteClass C = b.clazz("C").implement(I).build();
96
97
b.test().callSite(I, C, "equals", "(Ljava/lang/Object;)Z")
98
.ignoreResult()
99
.done();
100
b.test().callSite(C, C, "equals", "(Ljava/lang/Object;)Z")
101
.ignoreResult()
102
.done();
103
}
104
105
/* void finalize() */
106
public void testFinalize(TestBuilder b) {
107
Interface I = b.intf("I")
108
.defaultMethod("finalize", "()V")
109
.throw_(TestFailure.class)
110
.build()
111
.build();
112
113
ConcreteClass C = b.clazz("C").implement(I)
114
.concreteMethod("m", "()V")
115
// force an invokevirtual MR
116
.invoke(CallMethod.Invoke.VIRTUAL,
117
b.clazzByName("C"), b.clazzByName("C"), "finalize", "()V", METHODREF)
118
.build()
119
.build();
120
121
b.test().callSite(C, C, "m", "()V")
122
.ignoreResult()
123
.done();
124
}
125
126
/* final Class<?> getClass() */
127
public void testGetClass(TestBuilder b) throws Exception {
128
Interface I = b.intf("I")
129
.defaultMethod("getClass", "()Ljava/lang/Class;")
130
.sig("()Ljava/lang/Class<*>;")
131
.throw_(TestFailure.class)
132
.build()
133
.build();
134
135
ConcreteClass C = b.clazz("C").implement(I).build();
136
137
b.test().loadClass(I).throws_(IncompatibleClassChangeError.class).done();
138
b.test().loadClass(C).throws_(IncompatibleClassChangeError.class).done();
139
}
140
141
/* int hashCode() */
142
public void testHashCode(TestBuilder b) {
143
Interface I = b.intf("I")
144
.defaultMethod("hashCode", "()I")
145
.throw_(TestFailure.class)
146
.build()
147
.build();
148
149
ConcreteClass C = b.clazz("C").implement(I).build();
150
151
b.test().callSite(I, C, "hashCode", "()I")
152
.ignoreResult()
153
.done();
154
b.test().callSite(C, C, "hashCode", "()I")
155
.ignoreResult()
156
.done();
157
}
158
159
160
/* final void notify() */
161
public void testNotify(TestBuilder b) throws Exception {
162
Interface I = b.intf("I")
163
.defaultMethod("notify", "()V")
164
.throw_(TestFailure.class)
165
.build()
166
.build();
167
168
ConcreteClass C = b.clazz("C").implement(I).build();
169
170
b.test().loadClass(I).throws_(IncompatibleClassChangeError.class).done();
171
b.test().loadClass(C).throws_(IncompatibleClassChangeError.class).done();
172
}
173
174
/* void notifyAll() */
175
public void testNotifyAll(TestBuilder b) {
176
Interface I = b.intf("I")
177
.defaultMethod("notifyAll", "()V")
178
.throw_(TestFailure.class)
179
.build()
180
.build();
181
182
ConcreteClass C = b.clazz("C").implement(I).build();
183
184
b.test().loadClass(I).throws_(IncompatibleClassChangeError.class).done();
185
b.test().loadClass(C).throws_(IncompatibleClassChangeError.class).done();
186
}
187
188
/* String toString() */
189
public void testToString(TestBuilder b) {
190
Interface I = b.intf("I")
191
.defaultMethod("toString()", "()Ljava/lang/String;")
192
.throw_(TestFailure.class)
193
.build()
194
.build();
195
196
ConcreteClass C = b.clazz("C").implement(I).build();
197
198
if (factory.getExecutionMode() == "REFLECTION") {
199
// Class.get*Method() don't find any implicitly declared method from Object on interfaces.
200
b.test().callSite(I, C, "toString", "()Ljava/lang/String;")
201
.throws_(NoSuchMethodException.class)
202
.done();
203
} else {
204
b.test().callSite(I, C, "toString", "()Ljava/lang/String;")
205
.ignoreResult()
206
.done();
207
}
208
b.test().callSite(C, C, "toString", "()Ljava/lang/String;")
209
.ignoreResult()
210
.done();
211
}
212
213
/* final void wait() */
214
public void testWait(TestBuilder b) {
215
Interface I = b.intf("I")
216
.defaultMethod("wait", "()V")
217
.throw_(TestFailure.class)
218
.build()
219
.build();
220
221
ConcreteClass C = b.clazz("C").implement(I).build();
222
223
b.test().loadClass(I).throws_(IncompatibleClassChangeError.class).done();
224
b.test().loadClass(C).throws_(IncompatibleClassChangeError.class).done();
225
}
226
227
/* final void wait(long timeout) */
228
public void testTimedWait(TestBuilder b) {
229
Interface I = b.intf("I")
230
.defaultMethod("wait", "(J)V")
231
.throw_(TestFailure.class)
232
.build()
233
.build();
234
235
ConcreteClass C = b.clazz("C").implement(I).build();
236
237
b.test().loadClass(I).throws_(IncompatibleClassChangeError.class).done();
238
b.test().loadClass(C).throws_(IncompatibleClassChangeError.class).done();
239
}
240
241
/* final void wait(long timeout, int nanos) */
242
public void testTimedWait1(TestBuilder b) {
243
Interface I = b.intf("I")
244
.defaultMethod("wait", "(JI)V")
245
.throw_(TestFailure.class)
246
.build()
247
.build();
248
249
ConcreteClass C = b.clazz("C").implement(I).build();
250
251
b.test().loadClass(I).throws_(IncompatibleClassChangeError.class).done();
252
b.test().loadClass(C).throws_(IncompatibleClassChangeError.class).done();
253
}
254
}
255
256