85 import java.util.Enumeration; |
85 import java.util.Enumeration; |
86 import java.util.Formatter; |
86 import java.util.Formatter; |
87 import java.util.zip.ZipEntry; |
87 import java.util.zip.ZipEntry; |
88 import java.util.zip.ZipFile; |
88 import java.util.zip.ZipFile; |
89 |
89 |
|
90 import org.graalvm.compiler.test.ModuleSupport; |
90 import org.graalvm.compiler.test.SubprocessUtil; |
91 import org.graalvm.compiler.test.SubprocessUtil; |
91 import org.junit.Assert; |
92 import org.junit.Assert; |
92 import org.junit.Assume; |
93 import org.junit.Assume; |
93 import org.junit.Before; |
94 import org.junit.Before; |
94 import org.junit.Test; |
95 import org.junit.Test; |
144 /** |
145 /** |
145 * Keep test time down by only sampling a limited number of class files per jar. |
146 * Keep test time down by only sampling a limited number of class files per jar. |
146 */ |
147 */ |
147 private static final int CLASSES_PER_JAR = 250; |
148 private static final int CLASSES_PER_JAR = 250; |
148 |
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 |
149 @Test |
156 @Test |
150 public void test() { |
157 public void test() { |
151 RuntimeProvider rt = Graal.getRequiredCapability(RuntimeProvider.class); |
158 RuntimeProvider rt = Graal.getRequiredCapability(RuntimeProvider.class); |
152 Providers providers = rt.getHostBackend().getProviders(); |
159 Providers providers = rt.getHostBackend().getProviders(); |
153 MetaAccessProvider metaAccess = providers.getMetaAccess(); |
160 MetaAccessProvider metaAccess = providers.getMetaAccess(); |
154 |
161 |
155 Assume.assumeTrue(VerifyPhase.class.desiredAssertionStatus()); |
162 Assume.assumeTrue(VerifyPhase.class.desiredAssertionStatus()); |
156 |
163 String bootclasspath; |
157 String propertyName = JavaVersionUtil.JAVA_SPEC <= 8 ? "sun.boot.class.path" : "jdk.module.path"; |
164 if (JavaVersionUtil.JAVA_SPEC <= 8) { |
158 String bootclasspath = System.getProperty(propertyName); |
165 String propertyName = "sun.boot.class.path"; |
159 Assert.assertNotNull("Cannot find value of " + propertyName, bootclasspath); |
166 bootclasspath = System.getProperty(propertyName); |
|
167 Assert.assertNotNull("Cannot find value of " + propertyName, bootclasspath); |
|
168 } else { |
|
169 bootclasspath = JRT_CLASS_PATH_ENTRY; |
|
170 } |
160 |
171 |
161 for (String path : bootclasspath.split(File.pathSeparator)) { |
172 for (String path : bootclasspath.split(File.pathSeparator)) { |
162 if (shouldProcess(path)) { |
173 if (shouldProcess(path)) { |
163 try { |
174 try { |
164 final ZipFile zipFile = new ZipFile(new File(path)); |
175 if (path.equals(JRT_CLASS_PATH_ENTRY)) { |
165 int index = 0; |
176 for (String className : ModuleSupport.getJRTGraalClassNames()) { |
166 int step = zipFile.size() > CLASSES_PER_JAR ? zipFile.size() / CLASSES_PER_JAR : 1; |
177 if (isGSON(className)) { |
167 for (final Enumeration<? extends ZipEntry> entry = zipFile.entries(); entry.hasMoreElements();) { |
178 /* |
168 final ZipEntry zipEntry = entry.nextElement(); |
179 * GSON classes are compiled with old JDK |
169 if ((index % step) == 0) { |
180 */ |
170 String name = zipEntry.getName(); |
181 continue; |
171 if (name.endsWith(".class") && !name.equals("module-info.class") && !name.startsWith("META-INF/versions/")) { |
182 } |
172 String className = name.substring(0, name.length() - ".class".length()).replace('/', '.'); |
183 try { |
173 if (isInNativeImage(className)) { |
184 checkClass(metaAccess, getSnippetReflection(), className); |
174 /* |
185 } catch (ClassNotFoundException e) { |
175 * Native image requires non-graalsdk classes to be present in |
186 throw new AssertionError(e); |
176 * the classpath. |
187 } |
177 */ |
188 } |
178 continue; |
189 } else { |
179 } |
190 final ZipFile zipFile = new ZipFile(new File(path)); |
180 if (isGSON(className)) { |
191 int index = 0; |
181 /* uses old class format */ |
192 int step = zipFile.size() > CLASSES_PER_JAR ? zipFile.size() / CLASSES_PER_JAR : 1; |
182 continue; |
193 for (final Enumeration<? extends ZipEntry> entry = zipFile.entries(); entry.hasMoreElements();) { |
183 } |
194 final ZipEntry zipEntry = entry.nextElement(); |
184 try { |
195 if ((index % step) == 0) { |
185 checkClass(metaAccess, getSnippetReflection(), className); |
196 String name = zipEntry.getName(); |
186 } catch (ClassNotFoundException e) { |
197 if (name.endsWith(".class") && !name.equals("module-info.class") && !name.startsWith("META-INF/versions/")) { |
187 throw new AssertionError(e); |
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 } |
188 } |
215 } |
189 } |
216 } |
190 } |
217 index++; |
191 index++; |
218 } |
192 } |
219 } |
193 } catch (IOException ex) { |
220 } catch (IOException ex) { |
194 Assert.fail(ex.toString()); |
221 Assert.fail(ex.toString()); |
195 } |
222 } |
196 } |
223 } |