Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/test/functional/cmdLineTests/lockWordAlignment/src/IntLongObjectAlignmentTestGenerator.java
6004 views
1
/*******************************************************************************
2
* Copyright (c) 2001, 2021 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7
* or the Apache License, Version 2.0 which accompanies this distribution and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
20
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
21
*******************************************************************************/
22
23
import static jdk.internal.org.objectweb.asm.Opcodes.ACC_PRIVATE;
24
import static jdk.internal.org.objectweb.asm.Opcodes.ACC_PUBLIC;
25
import static jdk.internal.org.objectweb.asm.Opcodes.ACC_STATIC;
26
import static jdk.internal.org.objectweb.asm.Opcodes.ACC_SUPER;
27
import static jdk.internal.org.objectweb.asm.Opcodes.ALOAD;
28
import static jdk.internal.org.objectweb.asm.Opcodes.ASTORE;
29
import static jdk.internal.org.objectweb.asm.Opcodes.GETSTATIC;
30
import static jdk.internal.org.objectweb.asm.Opcodes.IFEQ;
31
import static jdk.internal.org.objectweb.asm.Opcodes.INVOKESPECIAL;
32
import static jdk.internal.org.objectweb.asm.Opcodes.INVOKESTATIC;
33
import static jdk.internal.org.objectweb.asm.Opcodes.INVOKEVIRTUAL;
34
import static jdk.internal.org.objectweb.asm.Opcodes.LCMP;
35
import static jdk.internal.org.objectweb.asm.Opcodes.LCONST_0;
36
import static jdk.internal.org.objectweb.asm.Opcodes.LLOAD;
37
import static jdk.internal.org.objectweb.asm.Opcodes.LREM;
38
import static jdk.internal.org.objectweb.asm.Opcodes.LSTORE;
39
import static jdk.internal.org.objectweb.asm.Opcodes.RETURN;
40
import static jdk.internal.org.objectweb.asm.Opcodes.V1_7;
41
42
import java.io.FileOutputStream;
43
import java.io.IOException;
44
import java.util.Arrays;
45
46
import jdk.internal.org.objectweb.asm.ClassWriter;
47
import jdk.internal.org.objectweb.asm.FieldVisitor;
48
import jdk.internal.org.objectweb.asm.Label;
49
import jdk.internal.org.objectweb.asm.MethodVisitor;
50
import jdk.internal.org.objectweb.asm.Opcodes;
51
import jdk.internal.org.objectweb.asm.Type;
52
53
public class IntLongObjectAlignmentTestGenerator {
54
55
private static String className;
56
private static String fileName;
57
private static String parent = "level_2_I";
58
59
public static void main(String[] args) throws Throwable {
60
61
parent = "level_2_I";
62
permuteString("", "ijo");
63
64
parent = "level_2_J";
65
permuteString("", "ijo");
66
67
parent = "level_2_O";
68
permuteString("", "ijo");
69
70
}
71
72
public static void printCommand() {
73
//System.out.println("java -Xbootclasspath/p:. " + className );
74
//System.out.println("java -Xbootclasspath/p:. -Xlockword:noLockword=" + className + " " + className);
75
76
System.out.println("<test id=\"Check " + className + " is aligned\">");
77
System.out.println(" <command>$EXE$ $TESTSBOOTCLASSPATH$ $OBJECTTESTSBOOTCLASSPATH$ main " + className + "</command>");
78
System.out.println(" <return value=\"0\" />");
79
System.out.println(" <output type=\"failure\">not aligned</output>");
80
System.out.println(" <output type=\"failure\">Unhandled Exception</output>");
81
System.out.println(" <output type=\"failure\">Exception:</output>");
82
System.out.println(" <output type=\"failure\">Processing dump event</output>");
83
System.out.println("</test>");
84
85
System.out.println("<test id=\"Check " + className + " is still aligned with -Xlockword:noLockword\">");
86
System.out.println(" <command>$EXE$ $TESTSBOOTCLASSPATH$ $OBJECTTESTSBOOTCLASSPATH$ -Xlockword:noLockword=" + className + " main " + className + "</command>");
87
System.out.println(" <return value=\"0\" />");
88
System.out.println(" <output type=\"failure\">not aligned</output>");
89
System.out.println(" <output type=\"failure\">Unhandled Exception</output>");
90
System.out.println(" <output type=\"failure\">Exception:</output>");
91
System.out.println(" <output type=\"failure\">Processing dump event</output>");
92
System.out.println("</test>");
93
}
94
95
public static void permuteString(String beginningString, String endingString) throws Throwable {
96
if (endingString.length() <= 1) {
97
98
className = beginningString + endingString + "_extends_" + parent;
99
fileName = className + ".class";
100
101
FileOutputStream fos = new FileOutputStream(fileName);
102
fos.write(makeExample("level_2_I", beginningString + endingString));
103
fos.flush();
104
fos.close();
105
printCommand();
106
} else {
107
for (int i = 0; i < endingString.length(); i++) {
108
String newString = endingString.substring(0, i) + endingString.substring(i + 1);
109
permuteString(beginningString + endingString.charAt(i), newString);
110
}
111
}
112
}
113
114
public static byte[] makeExample(String parent, String args)
115
throws Throwable {
116
117
ClassWriter cw = new ClassWriter(0);
118
FieldVisitor fv = null;
119
MethodVisitor mv;
120
cw.visit(V1_7, ACC_SUPER, className, null, parent, null);
121
122
char argsArr[] = args.toCharArray();
123
for (char ch : argsArr) {
124
switch (ch) {
125
case 'i':
126
fv = cw.visitField(ACC_PRIVATE, "i", "I", null, null);
127
break;
128
case 'j':
129
fv = cw.visitField(ACC_PRIVATE, "l", "J", null, null);
130
break;
131
case 'o':
132
fv = cw.visitField(ACC_PRIVATE, "o", "Ljava/lang/Object;",
133
null, null);
134
break;
135
default:
136
}
137
fv.visitEnd();
138
}
139
140
{
141
mv = cw.visitMethod(0, "<init>", "()V", null, null);
142
mv.visitCode();
143
mv.visitVarInsn(ALOAD, 0);
144
mv.visitMethodInsn(INVOKESPECIAL, parent, "<init>", "()V");
145
mv.visitInsn(RETURN);
146
mv.visitMaxs(1, 1);
147
mv.visitEnd();
148
}
149
150
cw.visitEnd();
151
152
return cw.toByteArray();
153
154
}
155
}
156
157