Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/jsr292/LongReferenceCastingTest.java
41152 views
1
/*
2
* Copyright (c) 2016, 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 8148752
27
* @summary Test correct casting of MH arguments during inlining.
28
*
29
* @run main compiler.jsr292.LongReferenceCastingTest
30
*/
31
32
package compiler.jsr292;
33
34
import java.lang.invoke.MethodHandle;
35
import java.lang.invoke.MethodHandles;
36
import java.lang.invoke.MethodType;
37
38
public class LongReferenceCastingTest {
39
static final String MY_STRING = "myString";
40
static final MethodHandle MH;
41
42
static {
43
try {
44
MethodHandles.Lookup lookup = MethodHandles.lookup();
45
MethodType mt = MethodType.methodType(String.class, long.class, Object.class, String.class);
46
MH = lookup.findVirtual(LongReferenceCastingTest.class, "myMethod", mt);
47
} catch (Exception e) {
48
throw new Error(e);
49
}
50
}
51
52
public String myMethod(long l, Object o, String s) {
53
// The long argument occupies two stack slots, causing C2 to treat it as
54
// two arguments and casting the fist one two long and the second one to Object.
55
// As a result, Object o is casted to String and the o.toString() call is
56
// inlined as String::toString(). We fail at runtime because 'o' is not a String.
57
return o.toString();
58
}
59
60
public String toString() {
61
return MY_STRING;
62
}
63
64
public static void main(String[] args) throws Exception {
65
LongReferenceCastingTest test = new LongReferenceCastingTest();
66
try {
67
for (int i = 0; i < 20_000; ++i) {
68
if (!test.invoke().equals(MY_STRING)) {
69
throw new RuntimeException("Invalid string");
70
}
71
}
72
} catch (Throwable t) {
73
throw new RuntimeException("Test failed", t);
74
}
75
}
76
77
public String invoke() throws Throwable {
78
return (String) MH.invokeExact(this, 0L, (Object)this, MY_STRING);
79
}
80
}
81
82