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