Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/test/functional/cmdLineTests/lockWordAlignment/src/CreateTestObjectJar.java
6004 views
1
/*******************************************************************************
2
* Copyright (c) 2015, 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 java.lang.IllegalArgumentException;
24
import java.io.File;
25
26
import static jdk.internal.org.objectweb.asm.Opcodes.ACC_PRIVATE;
27
28
import java.io.FileOutputStream;
29
import java.io.ByteArrayInputStream;
30
import java.util.zip.ZipOutputStream;
31
import java.util.zip.ZipEntry;
32
33
import jdk.internal.org.objectweb.asm.ClassWriter;
34
import jdk.internal.org.objectweb.asm.FieldVisitor;
35
import jdk.internal.org.objectweb.asm.ClassReader;
36
37
public class CreateTestObjectJar {
38
39
/* Length of buffer used to write JAR file. It can be set to any value */
40
private final static int bufLen = 1024;
41
42
private static void printUsage() {
43
System.out.println("CreateTestObjectJar Usage:");
44
System.out.println();
45
System.out.println("CreateTestObjectJar <dir> <testType>");
46
System.out.println();
47
System.out.println("dir : Directory where the test object jar file will be written to");
48
System.out.println("testType : Must be one of the following: 'i', 'ii', 'iii', or 'd'");
49
System.out.println();
50
}
51
52
public static void main(String[] args) throws Throwable {
53
54
File testDir = new File(args[0]);
55
String testType = args[1];
56
57
String jarFileName = null;
58
59
ClassReader cr = new ClassReader("java/lang/Object");
60
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
61
FieldVisitor fv = null;
62
63
cr.accept(cw, 0);
64
65
if (!testDir.isDirectory()) {
66
printUsage();
67
throw new IllegalArgumentException("Invalid directory: " + testDir.getPath());
68
}
69
70
/* Modify the Object class according with the test type */
71
if (testType.equalsIgnoreCase("d")) {
72
fv = cw.visitField(ACC_PRIVATE, "d", "D", null, null);
73
jarFileName = "object_d.jar";
74
} else if (testType.equalsIgnoreCase("i")) {
75
fv = cw.visitField(ACC_PRIVATE, "i", "I", null, null);
76
jarFileName = "object_i.jar";
77
} else if (testType.equalsIgnoreCase("ii")) {
78
fv = cw.visitField(ACC_PRIVATE, "i", "I", null, null);
79
fv = cw.visitField(ACC_PRIVATE, "ii", "I", null, null);
80
jarFileName = "object_ii.jar";
81
} else if (testType.equalsIgnoreCase("iii")) {
82
fv = cw.visitField(ACC_PRIVATE, "i", "I", null, null);
83
fv = cw.visitField(ACC_PRIVATE, "ii", "I", null, null);
84
fv = cw.visitField(ACC_PRIVATE, "iii", "I", null, null);
85
jarFileName = "object_iii.jar";
86
} else {
87
printUsage();
88
throw new IllegalArgumentException("Invalid test type: " + testType);
89
}
90
91
if (null != fv) {
92
fv.visitEnd();
93
}
94
95
/* Write the final jar file with the modified Object class in it */
96
if (null != jarFileName) {
97
ZipOutputStream outJar = new ZipOutputStream(new FileOutputStream(testDir.getPath() + "/" + jarFileName));
98
outJar.putNextEntry(new ZipEntry("java/lang/Object.class"));
99
ByteArrayInputStream inJar = new ByteArrayInputStream(cw.toByteArray());
100
int len;
101
byte[] buf = new byte[bufLen];
102
while ((len = inJar.read(buf)) > 0) {
103
outJar.write(buf, 0, len);
104
}
105
outJar.closeEntry();
106
outJar.close();
107
}
108
109
}
110
111
}
112
113
114