1 /*
2 * Copyright (c) 2016, 2018, 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 */
70 import static org.graalvm.compiler.bytecode.Bytecodes.LOOKUPSWITCH;
71 import static org.graalvm.compiler.bytecode.Bytecodes.LSTORE;
72 import static org.graalvm.compiler.bytecode.Bytecodes.MULTIANEWARRAY;
73 import static org.graalvm.compiler.bytecode.Bytecodes.NEW;
74 import static org.graalvm.compiler.bytecode.Bytecodes.NEWARRAY;
75 import static org.graalvm.compiler.bytecode.Bytecodes.PUTFIELD;
76 import static org.graalvm.compiler.bytecode.Bytecodes.PUTSTATIC;
77 import static org.graalvm.compiler.bytecode.Bytecodes.RET;
78 import static org.graalvm.compiler.bytecode.Bytecodes.SIPUSH;
79 import static org.graalvm.compiler.bytecode.Bytecodes.TABLESWITCH;
80
81 import java.io.File;
82 import java.io.IOException;
83 import java.lang.reflect.Executable;
84 import java.lang.reflect.Method;
85 import java.util.Enumeration;
86 import java.util.Formatter;
87 import java.util.zip.ZipEntry;
88 import java.util.zip.ZipFile;
89
90 import org.graalvm.compiler.test.SubprocessUtil;
91 import org.junit.Assert;
92 import org.junit.Assume;
93 import org.junit.Before;
94 import org.junit.Test;
95
96 import org.graalvm.compiler.api.replacements.SnippetReflectionProvider;
97 import org.graalvm.compiler.api.test.Graal;
98 import org.graalvm.compiler.bytecode.Bytecode;
99 import org.graalvm.compiler.bytecode.BytecodeDisassembler;
100 import org.graalvm.compiler.bytecode.BytecodeLookupSwitch;
101 import org.graalvm.compiler.bytecode.BytecodeStream;
102 import org.graalvm.compiler.bytecode.BytecodeSwitch;
103 import org.graalvm.compiler.bytecode.BytecodeTableSwitch;
104 import org.graalvm.compiler.bytecode.Bytecodes;
105 import org.graalvm.compiler.bytecode.ResolvedJavaMethodBytecode;
106 import org.graalvm.compiler.core.test.GraalCompilerTest;
107 import org.graalvm.compiler.phases.VerifyPhase;
108 import org.graalvm.compiler.phases.util.Providers;
109 import org.graalvm.compiler.replacements.classfile.ClassfileBytecode;
129
130 @Before
131 public void checkJavaAgent() {
132 assumeManagementLibraryIsLoadable();
133 Assume.assumeFalse("Java Agent found -> skipping", SubprocessUtil.isJavaAgentAttached());
134 }
135
136 private static boolean shouldProcess(String classpathEntry) {
137 if (classpathEntry.endsWith(".jar")) {
138 String name = new File(classpathEntry).getName();
139 return name.contains("jvmci") || name.contains("graal");
140 }
141 return false;
142 }
143
144 /**
145 * Keep test time down by only sampling a limited number of class files per jar.
146 */
147 private static final int CLASSES_PER_JAR = 250;
148
149 @Test
150 public void test() {
151 RuntimeProvider rt = Graal.getRequiredCapability(RuntimeProvider.class);
152 Providers providers = rt.getHostBackend().getProviders();
153 MetaAccessProvider metaAccess = providers.getMetaAccess();
154
155 Assume.assumeTrue(VerifyPhase.class.desiredAssertionStatus());
156
157 String propertyName = JavaVersionUtil.JAVA_SPEC <= 8 ? "sun.boot.class.path" : "jdk.module.path";
158 String bootclasspath = System.getProperty(propertyName);
159 Assert.assertNotNull("Cannot find value of " + propertyName, bootclasspath);
160
161 for (String path : bootclasspath.split(File.pathSeparator)) {
162 if (shouldProcess(path)) {
163 try {
164 final ZipFile zipFile = new ZipFile(new File(path));
165 int index = 0;
166 int step = zipFile.size() > CLASSES_PER_JAR ? zipFile.size() / CLASSES_PER_JAR : 1;
167 for (final Enumeration<? extends ZipEntry> entry = zipFile.entries(); entry.hasMoreElements();) {
168 final ZipEntry zipEntry = entry.nextElement();
169 if ((index % step) == 0) {
170 String name = zipEntry.getName();
171 if (name.endsWith(".class") && !name.equals("module-info.class") && !name.startsWith("META-INF/versions/")) {
172 String className = name.substring(0, name.length() - ".class".length()).replace('/', '.');
173 if (isInNativeImage(className)) {
174 /*
175 * Native image requires non-graalsdk classes to be present in
176 * the classpath.
177 */
178 continue;
179 }
180 if (isGSON(className)) {
181 /* uses old class format */
182 continue;
183 }
184 try {
185 checkClass(metaAccess, getSnippetReflection(), className);
186 } catch (ClassNotFoundException e) {
187 throw new AssertionError(e);
188 }
189 }
190 }
191 index++;
192 }
193 } catch (IOException ex) {
194 Assert.fail(ex.toString());
195 }
196 }
197 }
198 }
199
200 private static boolean isInNativeImage(String className) {
201 return className.startsWith("org.graalvm.nativeimage");
202 }
203
204 private static boolean isGSON(String className) {
205 return className.contains("com.google.gson");
206 }
207
208 protected void checkClass(MetaAccessProvider metaAccess, SnippetReflectionProvider snippetReflection, String className) throws ClassNotFoundException {
209 if (className.equals("jdk.vm.ci.services.JVMCIClassLoaderFactory")) {
210 // JVMCIClassLoaderFactory must only be initialized by the VM
211 return;
|
1 /*
2 * Copyright (c) 2016, 2019, 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 */
70 import static org.graalvm.compiler.bytecode.Bytecodes.LOOKUPSWITCH;
71 import static org.graalvm.compiler.bytecode.Bytecodes.LSTORE;
72 import static org.graalvm.compiler.bytecode.Bytecodes.MULTIANEWARRAY;
73 import static org.graalvm.compiler.bytecode.Bytecodes.NEW;
74 import static org.graalvm.compiler.bytecode.Bytecodes.NEWARRAY;
75 import static org.graalvm.compiler.bytecode.Bytecodes.PUTFIELD;
76 import static org.graalvm.compiler.bytecode.Bytecodes.PUTSTATIC;
77 import static org.graalvm.compiler.bytecode.Bytecodes.RET;
78 import static org.graalvm.compiler.bytecode.Bytecodes.SIPUSH;
79 import static org.graalvm.compiler.bytecode.Bytecodes.TABLESWITCH;
80
81 import java.io.File;
82 import java.io.IOException;
83 import java.lang.reflect.Executable;
84 import java.lang.reflect.Method;
85 import java.util.Enumeration;
86 import java.util.Formatter;
87 import java.util.zip.ZipEntry;
88 import java.util.zip.ZipFile;
89
90 import org.graalvm.compiler.test.ModuleSupport;
91 import org.graalvm.compiler.test.SubprocessUtil;
92 import org.junit.Assert;
93 import org.junit.Assume;
94 import org.junit.Before;
95 import org.junit.Test;
96
97 import org.graalvm.compiler.api.replacements.SnippetReflectionProvider;
98 import org.graalvm.compiler.api.test.Graal;
99 import org.graalvm.compiler.bytecode.Bytecode;
100 import org.graalvm.compiler.bytecode.BytecodeDisassembler;
101 import org.graalvm.compiler.bytecode.BytecodeLookupSwitch;
102 import org.graalvm.compiler.bytecode.BytecodeStream;
103 import org.graalvm.compiler.bytecode.BytecodeSwitch;
104 import org.graalvm.compiler.bytecode.BytecodeTableSwitch;
105 import org.graalvm.compiler.bytecode.Bytecodes;
106 import org.graalvm.compiler.bytecode.ResolvedJavaMethodBytecode;
107 import org.graalvm.compiler.core.test.GraalCompilerTest;
108 import org.graalvm.compiler.phases.VerifyPhase;
109 import org.graalvm.compiler.phases.util.Providers;
110 import org.graalvm.compiler.replacements.classfile.ClassfileBytecode;
130
131 @Before
132 public void checkJavaAgent() {
133 assumeManagementLibraryIsLoadable();
134 Assume.assumeFalse("Java Agent found -> skipping", SubprocessUtil.isJavaAgentAttached());
135 }
136
137 private static boolean shouldProcess(String classpathEntry) {
138 if (classpathEntry.endsWith(".jar")) {
139 String name = new File(classpathEntry).getName();
140 return name.contains("jvmci") || name.contains("graal");
141 }
142 return false;
143 }
144
145 /**
146 * Keep test time down by only sampling a limited number of class files per jar.
147 */
148 private static final int CLASSES_PER_JAR = 250;
149
150 /**
151 * Magic token to denote the classes in the Java runtime image (i.e. in the {@code jrt:/} file
152 * system).
153 */
154 public static final String JRT_CLASS_PATH_ENTRY = "<jrt>";
155
156 @Test
157 public void test() {
158 RuntimeProvider rt = Graal.getRequiredCapability(RuntimeProvider.class);
159 Providers providers = rt.getHostBackend().getProviders();
160 MetaAccessProvider metaAccess = providers.getMetaAccess();
161
162 Assume.assumeTrue(VerifyPhase.class.desiredAssertionStatus());
163 String bootclasspath;
164 if (JavaVersionUtil.JAVA_SPEC <= 8) {
165 String propertyName = "sun.boot.class.path";
166 bootclasspath = System.getProperty(propertyName);
167 Assert.assertNotNull("Cannot find value of " + propertyName, bootclasspath);
168 } else {
169 bootclasspath = JRT_CLASS_PATH_ENTRY;
170 }
171
172 for (String path : bootclasspath.split(File.pathSeparator)) {
173 if (shouldProcess(path)) {
174 try {
175 if (path.equals(JRT_CLASS_PATH_ENTRY)) {
176 for (String className : ModuleSupport.getJRTGraalClassNames()) {
177 if (isGSON(className)) {
178 /*
179 * GSON classes are compiled with old JDK
180 */
181 continue;
182 }
183 try {
184 checkClass(metaAccess, getSnippetReflection(), className);
185 } catch (ClassNotFoundException e) {
186 throw new AssertionError(e);
187 }
188 }
189 } else {
190 final ZipFile zipFile = new ZipFile(new File(path));
191 int index = 0;
192 int step = zipFile.size() > CLASSES_PER_JAR ? zipFile.size() / CLASSES_PER_JAR : 1;
193 for (final Enumeration<? extends ZipEntry> entry = zipFile.entries(); entry.hasMoreElements();) {
194 final ZipEntry zipEntry = entry.nextElement();
195 if ((index % step) == 0) {
196 String name = zipEntry.getName();
197 if (name.endsWith(".class") && !name.equals("module-info.class") && !name.startsWith("META-INF/versions/")) {
198 String className = name.substring(0, name.length() - ".class".length()).replace('/', '.');
199 if (isInNativeImage(className)) {
200 /*
201 * Native image requires non-graalsdk classes to be present
202 * in the classpath.
203 */
204 continue;
205 }
206 if (isGSON(className)) {
207 /* uses old class format */
208 continue;
209 }
210 try {
211 checkClass(metaAccess, getSnippetReflection(), className);
212 } catch (ClassNotFoundException e) {
213 throw new AssertionError(e);
214 }
215 }
216 }
217 index++;
218 }
219 }
220 } catch (IOException ex) {
221 Assert.fail(ex.toString());
222 }
223 }
224 }
225 }
226
227 private static boolean isInNativeImage(String className) {
228 return className.startsWith("org.graalvm.nativeimage");
229 }
230
231 private static boolean isGSON(String className) {
232 return className.contains("com.google.gson");
233 }
234
235 protected void checkClass(MetaAccessProvider metaAccess, SnippetReflectionProvider snippetReflection, String className) throws ClassNotFoundException {
236 if (className.equals("jdk.vm.ci.services.JVMCIClassLoaderFactory")) {
237 // JVMCIClassLoaderFactory must only be initialized by the VM
238 return;
|