author | iklam |
Fri, 09 Aug 2019 13:13:36 -0700 | |
changeset 57705 | 7cf02b2c1455 |
parent 57567 | b000362a89a0 |
child 58679 | 9c3209ff7550 |
permissions | -rw-r--r-- |
48138 | 1 |
/* |
57567
b000362a89a0
8202339: [TESTBUG] Consolidate the tests in runtime/SharedArchiveFile and runtime/appcds
coleenp
parents:
54552
diff
changeset
|
2 |
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved. |
48138 | 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 |
/* |
|
26 |
* @test |
|
54552 | 27 |
* @summary classes with major version < JDK_6 (50) should not be included in CDS |
48469
7312ae4465d6
8193672: [test] Enhance vm.cds property to check for all conditions required to run CDS tests
iklam
parents:
48138
diff
changeset
|
28 |
* @requires vm.cds |
48138 | 29 |
* @library /test/lib |
30 |
* @modules java.base/jdk.internal.org.objectweb.asm |
|
31 |
* jdk.jartool/sun.tools.jar |
|
32 |
* @compile test-classes/Hello.java |
|
33 |
* @run build TestCommon JarBuilder |
|
51990
6003e034cdd8
8209946: [TESTBUG] CDS tests should use "@run driver"
iklam
parents:
51507
diff
changeset
|
34 |
* @run driver OldClassTest |
48138 | 35 |
*/ |
36 |
||
37 |
import java.io.File; |
|
38 |
import java.io.FileOutputStream; |
|
39 |
import jdk.test.lib.process.OutputAnalyzer; |
|
40 |
import java.nio.file.Files; |
|
41 |
||
42 |
import java.util.*; |
|
43 |
import jdk.internal.org.objectweb.asm.*; |
|
44 |
||
45 |
public class OldClassTest implements Opcodes { |
|
46 |
||
47 |
public static void main(String[] args) throws Exception { |
|
48 |
File jarSrcFile = new File(JarBuilder.getOrCreateHelloJar()); |
|
49 |
||
50 |
File dir = new File(System.getProperty("test.classes", ".")); |
|
51 |
File jarFile = new File(dir, "OldClassTest_old.jar"); |
|
52 |
String jar = jarFile.getPath(); |
|
53 |
||
54 |
if (!jarFile.exists() || jarFile.lastModified() < jarSrcFile.lastModified()) { |
|
55 |
createTestJarFile(jarSrcFile, jarFile); |
|
56 |
} else { |
|
57 |
System.out.println("Already up-to-date: " + jarFile); |
|
58 |
} |
|
59 |
||
60 |
String appClasses[] = TestCommon.list("Hello"); |
|
61 |
||
54552 | 62 |
// CASE 1: pre-JDK 6 compiled classes should be excluded from the dump |
48138 | 63 |
OutputAnalyzer output = TestCommon.dump(jar, appClasses); |
54552 | 64 |
TestCommon.checkExecReturn(output, 0, true, "Pre JDK 6 class not supported by CDS"); |
48138 | 65 |
|
48979
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48469
diff
changeset
|
66 |
TestCommon.run( |
48138 | 67 |
"-cp", jar, |
48979
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48469
diff
changeset
|
68 |
"Hello") |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48469
diff
changeset
|
69 |
.assertNormalExit("Hello Unicode world (Old)"); |
48138 | 70 |
|
71 |
// CASE 2: if we exlcude old version of this class, we should not pick up |
|
72 |
// the newer version of this class in a subsequent classpath element. |
|
73 |
String classpath = jar + File.pathSeparator + jarSrcFile.getPath(); |
|
74 |
output = TestCommon.dump(classpath, appClasses); |
|
54552 | 75 |
TestCommon.checkExecReturn(output, 0, true, "Pre JDK 6 class not supported by CDS"); |
48138 | 76 |
|
48979
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48469
diff
changeset
|
77 |
TestCommon.run( |
48138 | 78 |
"-cp", classpath, |
48979
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48469
diff
changeset
|
79 |
"Hello") |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48469
diff
changeset
|
80 |
.assertNormalExit("Hello Unicode world (Old)"); |
48138 | 81 |
} |
82 |
||
83 |
static void createTestJarFile(File jarSrcFile, File jarFile) throws Exception { |
|
84 |
jarFile.delete(); |
|
85 |
Files.copy(jarSrcFile.toPath(), jarFile.toPath()); |
|
86 |
||
87 |
File dir = new File(System.getProperty("test.classes", ".")); |
|
88 |
File outdir = new File(dir, "old_class_test_classes"); |
|
89 |
outdir.delete(); |
|
90 |
outdir.mkdir(); |
|
91 |
||
92 |
writeClassFile(new File(outdir, "Hello.class"), makeOldHello()); |
|
93 |
||
94 |
JarBuilder.update(jarFile.getPath(), outdir.getPath()); |
|
95 |
} |
|
96 |
||
97 |
static void writeClassFile(File file, byte bytecodes[]) throws Exception { |
|
98 |
try (FileOutputStream fos = new FileOutputStream(file)) { |
|
99 |
fos.write(bytecodes); |
|
100 |
} |
|
101 |
} |
|
102 |
||
103 |
/* makeOldHello() was obtained using JDK8. We use a method name > 128 that would |
|
104 |
trigger a call to java.lang.Character.isJavaIdentifierStart() during class |
|
105 |
file parsing. |
|
106 |
||
107 |
cat > Hello.java <<EOF |
|
108 |
public class Hello { |
|
109 |
public static void main(String args[]) { |
|
110 |
System.out.println(\u1234()); |
|
111 |
} |
|
112 |
static String \u1234() { |
|
113 |
return "Hello Unicode world (Old)"; |
|
114 |
} |
|
115 |
} |
|
116 |
EOF |
|
117 |
javac Hello.java |
|
118 |
java jdk.internal.org.objectweb.asm.util.ASMifier Hello.class |
|
119 |
||
120 |
*/ |
|
121 |
||
122 |
static byte[] makeOldHello() throws Exception { |
|
123 |
ClassWriter cw = new ClassWriter(0); |
|
124 |
FieldVisitor fv; |
|
125 |
MethodVisitor mv; |
|
126 |
AnnotationVisitor av0; |
|
127 |
||
54552 | 128 |
cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, "Hello", null, "java/lang/Object", null); |
48138 | 129 |
|
130 |
{ |
|
131 |
mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); |
|
132 |
mv.visitCode(); |
|
133 |
mv.visitVarInsn(ALOAD, 0); |
|
134 |
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); |
|
135 |
mv.visitInsn(RETURN); |
|
136 |
mv.visitMaxs(1, 1); |
|
137 |
mv.visitEnd(); |
|
138 |
} |
|
139 |
{ |
|
140 |
mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "main", "([Ljava/lang/String;)V", null, null); |
|
141 |
mv.visitCode(); |
|
142 |
mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;"); |
|
143 |
mv.visitMethodInsn(INVOKESTATIC, "Hello", "\u1234", "()Ljava/lang/String;", false); |
|
144 |
mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", false); |
|
145 |
mv.visitInsn(RETURN); |
|
146 |
mv.visitMaxs(2, 1); |
|
147 |
mv.visitEnd(); |
|
148 |
} |
|
149 |
{ |
|
150 |
mv = cw.visitMethod(ACC_STATIC, "\u1234", "()Ljava/lang/String;", null, null); |
|
151 |
mv.visitCode(); |
|
152 |
mv.visitLdcInsn("Hello Unicode world (Old)"); |
|
153 |
mv.visitInsn(ARETURN); |
|
154 |
mv.visitMaxs(1, 0); |
|
155 |
mv.visitEnd(); |
|
156 |
} |
|
157 |
cw.visitEnd(); |
|
158 |
||
159 |
return cw.toByteArray(); |
|
160 |
} |
|
161 |
} |