Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/c1/Test6932496.java
41149 views
1
/*
2
* Copyright (c) 2010, 2015, 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 6932496
27
* @summary incorrect deopt of jsr subroutine on 64 bit c1
28
* @modules java.base/jdk.internal.org.objectweb.asm
29
*
30
* @run main/othervm -Xcomp
31
* -XX:CompileCommand=compileonly,compiler.c1.Test6932496::test
32
* compiler.c1.Test6932496
33
*/
34
35
package compiler.c1;
36
37
import jdk.internal.org.objectweb.asm.ClassWriter;
38
import jdk.internal.org.objectweb.asm.FieldVisitor;
39
import jdk.internal.org.objectweb.asm.Label;
40
import jdk.internal.org.objectweb.asm.MethodVisitor;
41
import jdk.internal.org.objectweb.asm.Opcodes;
42
import jdk.internal.org.objectweb.asm.Type;
43
44
import java.io.IOException;
45
import java.lang.reflect.Method;
46
import java.nio.file.Files;
47
import java.nio.file.Paths;
48
49
public class Test6932496 extends ClassLoader {
50
private static final int CLASS_FILE_VERSION = 49;
51
private static final String CLASS_TEST = "Test";
52
private static final String CLASS_OBJECT = "java/lang/Object";
53
private static final String METHOD_INIT = "<init>";
54
private static final String METHOD_TEST = "test";
55
private static final String DESC_VOID_METHOD = "()V";
56
private static final String FIELD_FLAG = "flag";
57
58
public static void main(String[] args) {
59
Test6932496 test = new Test6932496();
60
test.execute();
61
}
62
63
private void execute() {
64
byte[] bytecode = Test6932496.generateTestClass();
65
66
try {
67
Files.write(Paths.get("Test.class.dump"), bytecode);
68
} catch (IOException e) {
69
System.err.println("classfile dump failed : " + e.getMessage());
70
e.printStackTrace();
71
}
72
try {
73
Class aClass = defineClass(CLASS_TEST, bytecode, 0, bytecode.length);
74
Method test = aClass.getDeclaredMethod(METHOD_TEST);
75
test.invoke(null);
76
} catch (ClassFormatError | IllegalArgumentException
77
| ReflectiveOperationException e) {
78
throw new RuntimeException("TESTBUG : generated class is invalid", e);
79
}
80
}
81
82
/*
83
public class Test {
84
volatile boolean flag = false;
85
public static void m() {
86
try {
87
} finally {
88
Test test = new Test();
89
test.flag = true;
90
}
91
}
92
}
93
*/
94
private static byte[] generateTestClass() {
95
ClassWriter cw = new ClassWriter(0);
96
cw.visit(CLASS_FILE_VERSION, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER,
97
CLASS_TEST, null, CLASS_OBJECT, null);
98
// volatile boolean flag;
99
{
100
FieldVisitor fv = cw.visitField(Opcodes.ACC_VOLATILE, FIELD_FLAG,
101
Type.BOOLEAN_TYPE.getDescriptor(),
102
/* signature = */ null, /* value = */ null);
103
}
104
105
/*
106
public Test() {
107
flag = false;
108
}
109
*/
110
{
111
MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC,
112
METHOD_INIT, DESC_VOID_METHOD,
113
/* signature = */ null, /* exceptions = */ null);
114
115
mv.visitCode();
116
mv.visitVarInsn(Opcodes.ALOAD, 0);
117
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, CLASS_OBJECT, METHOD_INIT,
118
DESC_VOID_METHOD, false);
119
120
mv.visitVarInsn(Opcodes.ALOAD, 0);
121
mv.visitInsn(Opcodes.ICONST_0);
122
mv.visitFieldInsn(Opcodes.PUTFIELD, CLASS_TEST, FIELD_FLAG,
123
Type.BOOLEAN_TYPE.getDescriptor());
124
125
mv.visitInsn(Opcodes.RETURN);
126
mv.visitMaxs(/* stack = */ 2, /* locals = */ 1);
127
mv.visitEnd();
128
}
129
130
/*
131
public static void m() {
132
try {
133
} finally {
134
Test test = new Test();
135
test.flag = true;
136
}
137
}
138
*/
139
{
140
MethodVisitor mv = cw.visitMethod(
141
Opcodes.ACC_STATIC + Opcodes.ACC_PUBLIC,
142
METHOD_TEST, DESC_VOID_METHOD,
143
/* signature = */ null, /* exceptions = */ null);
144
Label beginLabel = new Label();
145
Label block1EndLabel = new Label();
146
Label handlerLabel = new Label();
147
Label block2EndLabel = new Label();
148
Label label = new Label();
149
Label endLabel = new Label();
150
151
mv.visitCode();
152
mv.visitTryCatchBlock(beginLabel, block1EndLabel, handlerLabel,
153
/* type = <any> */ null);
154
mv.visitTryCatchBlock(handlerLabel, block2EndLabel, handlerLabel,
155
/* type = <any> */ null);
156
157
mv.visitLabel(beginLabel);
158
mv.visitJumpInsn(Opcodes.JSR, label);
159
mv.visitLabel(block1EndLabel);
160
mv.visitJumpInsn(Opcodes.GOTO, endLabel);
161
162
mv.visitLabel(handlerLabel);
163
mv.visitVarInsn(Opcodes.ASTORE, 0);
164
mv.visitJumpInsn(Opcodes.JSR, label);
165
mv.visitLabel(block2EndLabel);
166
mv.visitVarInsn(Opcodes.ALOAD, 0);
167
mv.visitInsn(Opcodes.ATHROW);
168
169
mv.visitLabel(label);
170
mv.visitVarInsn(Opcodes.ASTORE, 1);
171
mv.visitTypeInsn(Opcodes.NEW, CLASS_TEST);
172
mv.visitInsn(Opcodes.DUP);
173
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, CLASS_TEST, METHOD_INIT,
174
DESC_VOID_METHOD);
175
mv.visitVarInsn(Opcodes.ASTORE, 2);
176
177
mv.visitVarInsn(Opcodes.ALOAD, 2);
178
mv.visitInsn(Opcodes.ICONST_1);
179
mv.visitFieldInsn(Opcodes.PUTFIELD, CLASS_TEST, FIELD_FLAG,
180
Type.BOOLEAN_TYPE.getDescriptor());
181
182
mv.visitVarInsn(Opcodes.RET, 1);
183
184
mv.visitLabel(endLabel);
185
mv.visitInsn(Opcodes.RETURN);
186
mv.visitMaxs(/* stack = */ 2, /* locals = */ 3);
187
mv.visitEnd();
188
}
189
190
cw.visitEnd();
191
return cw.toByteArray();
192
}
193
}
194
195