# HG changeset patch # User Doug Simon # Date 1407145105 -7200 # Node ID ffb014884c12e9d37a70f714442b6c3ddf810788 # Parent e342886ed4377b824fe2eafd54307e249c1f42ff removed tests diff -r e342886ed437 -r ffb014884c12 graal/com.oracle.graal.api.meta.test/src/com/oracle/graal/api/meta/test/TestJavaType.java --- a/graal/com.oracle.graal.api.meta.test/src/com/oracle/graal/api/meta/test/TestJavaType.java Sat Aug 02 11:14:27 2014 +0200 +++ b/graal/com.oracle.graal.api.meta.test/src/com/oracle/graal/api/meta/test/TestJavaType.java Mon Aug 04 11:38:25 2014 +0200 @@ -24,11 +24,6 @@ import static org.junit.Assert.*; -import java.io.*; -import java.net.*; -import java.util.*; -import java.util.stream.*; - import org.junit.*; import com.oracle.graal.api.meta.*; @@ -50,91 +45,4 @@ assertEquals(expected, actual); } } - - static class A { - A or(A other) { - return other; - } - } - - @Test - public void testResolve() throws ClassNotFoundException { - String classPath = System.getProperty("java.class.path"); - String[] parts = classPath.split(File.pathSeparator); - URL[] urls = Arrays.asList(parts).stream().map(e -> asURL(e)).collect(Collectors.toList()).toArray(new URL[parts.length]); - URLClassLoader clOne = newClassLoader(urls); - URLClassLoader clTwo = newClassLoader(urls); - - String className = getClass().getName() + "$A"; - Class aClassOne = Class.forName(className, true, clOne); - Class aClassTwo = Class.forName(getClass().getName() + "$A", true, clTwo); - - assertNotEquals(aClassOne, aClassTwo); - assertNotEquals(aClassOne.getClassLoader(), aClassTwo.getClassLoader()); - - ResolvedJavaType aTypeOne = metaAccess.lookupJavaType(aClassOne); - ResolvedJavaType aTypeTwo = metaAccess.lookupJavaType(aClassTwo); - - assertNotEquals(aTypeOne, aTypeTwo); - - checkResolveWithoutAccessingClass(aTypeOne); - checkResolveWithoutAccessingClass(aTypeTwo); - - assertEquals(aTypeOne.resolve(aTypeOne), aTypeOne); - assertNotEquals(aTypeOne.resolve(aTypeTwo), aTypeOne); - assertEquals(aTypeOne.resolve(aTypeTwo), aTypeTwo); - - assertEquals(aTypeTwo.resolve(aTypeTwo), aTypeTwo); - assertNotEquals(aTypeTwo.resolve(aTypeOne), aTypeTwo); - assertEquals(aTypeTwo.resolve(aTypeOne), aTypeOne); - - ResolvedJavaMethod m = ResolvedJavaTypeResolveMethodTest.getMethod(aTypeOne, "or"); - JavaType resolvedTypeOne = m.getSignature().getParameterType(0, aTypeOne); - JavaType resolvedTypeTwo = m.getSignature().getReturnType(aTypeOne); - JavaType unresolvedTypeOne = m.getSignature().getParameterType(0, null); - JavaType unresolvedTypeTwo = m.getSignature().getReturnType(null); - - assertTrue(resolvedTypeOne instanceof ResolvedJavaType); - assertTrue(resolvedTypeTwo instanceof ResolvedJavaType); - assertFalse(unresolvedTypeOne instanceof ResolvedJavaType); - assertFalse(unresolvedTypeTwo instanceof ResolvedJavaType); - - assertEquals(resolvedTypeOne.resolve(aTypeOne), aTypeOne); - assertEquals(resolvedTypeOne.resolve(aTypeTwo), aTypeTwo); - assertEquals(resolvedTypeTwo.resolve(aTypeOne), aTypeOne); - assertEquals(resolvedTypeTwo.resolve(aTypeTwo), aTypeTwo); - - checkResolveWithoutAccessingClass(unresolvedTypeOne); - checkResolveWithoutAccessingClass(unresolvedTypeTwo); - - assertEquals(unresolvedTypeOne.resolve(aTypeOne), aTypeOne); - assertEquals(unresolvedTypeOne.resolve(aTypeTwo), aTypeTwo); - } - - private static void checkResolveWithoutAccessingClass(JavaType type) { - try { - type.resolve(null); - fail(); - } catch (NullPointerException e) { - } - } - - private static URLClassLoader newClassLoader(URL[] urls) { - URLClassLoader cl = new URLClassLoader(urls) { - @Override - protected java.lang.Class loadClass(String name, boolean resolve) throws ClassNotFoundException { - boolean callSuper = name.startsWith("java/") || name.startsWith("java."); - return callSuper ? super.loadClass(name, resolve) : super.findClass(name); - } - }; - return cl; - } - - private static URL asURL(String e) { - try { - return new File(e).toURI().toURL(); - } catch (MalformedURLException e1) { - throw new RuntimeException(e1); - } - } } diff -r e342886ed437 -r ffb014884c12 graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/BytecodeVerificationTest.java --- a/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/BytecodeVerificationTest.java Sat Aug 02 11:14:27 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,122 +0,0 @@ -/* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.hotspot.test; - -import java.io.*; - -import jdk.internal.org.objectweb.asm.*; - -import org.junit.*; - -import com.oracle.graal.compiler.test.*; - -/** - * Tests that the Graal API can only be used to access verified bytecode. - */ -public class BytecodeVerificationTest extends GraalCompilerTest { - - @Test(expected = VerifyError.class) - public void test() throws Exception { - BadClassLoader loader = new BadClassLoader(); - String className = BytecodeVerificationTest.class.getName() + "$BadClass"; - Class c = loader.findClass(className); - - // Should fail with a verification error as long as -XX:-BytecodeVerificationRemote is not - // specified on the command line - getMetaAccess().lookupJavaMethod(c.getDeclaredMethod("getValue")).getCode(); - } - - /** - * Class that will be rewritten during loading to be unverifiable. - */ - public static class BadClass { - - public static String value; - - public static String getValue() { - // Re-written to "return 5;" - return value; - } - } - - /** - * Rewrites {@link BadClass#getValue()} to: - * - *
-     * public static String getValue() {
-     *     return 5;
-     * }
-     * 
- */ - private static class BadClassRewriter extends ClassVisitor { - - public BadClassRewriter(ClassWriter cw) { - super(Opcodes.ASM5, cw); - } - - @Override - public MethodVisitor visitMethod(int access, String name, String d, String signature, String[] exceptions) { - MethodVisitor mv = super.visitMethod(access, name, d, signature, exceptions); - if (name.equals("getValue")) { - return new MethodVisitor(Opcodes.ASM5, mv) { - @Override - public void visitFieldInsn(int opcode, String owner, String fieldName, String fieldDesc) { - if (opcode == Opcodes.GETSTATIC) { - visitInsn(Opcodes.ICONST_5); - } else { - super.visitFieldInsn(opcode, owner, name, fieldDesc); - } - } - }; - } - return mv; - } - } - - /** - * Class loader used for loading {@link BadClass}. Using a separate class loader ensure the - * class is treated as "remote" so that it will be subject to verification by default. - */ - private static class BadClassLoader extends ClassLoader { - - @Override - protected Class findClass(final String name) throws ClassNotFoundException { - byte[] classData = null; - try { - InputStream is = BytecodeVerificationTest.class.getResourceAsStream("/" + name.replace('.', '/') + ".class"); - classData = new byte[is.available()]; - new DataInputStream(is).readFully(classData); - } catch (IOException e) { - Assert.fail("can't access class: " + name); - } - - ClassReader cr = new ClassReader(classData); - ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_FRAMES); - - BadClassRewriter rewriter = new BadClassRewriter(cw); - cr.accept(rewriter, ClassReader.SKIP_FRAMES); - classData = cw.toByteArray(); - return defineClass(null, classData, 0, classData.length); - } - } -} diff -r e342886ed437 -r ffb014884c12 graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/GraalClassLoaderTest.java --- a/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/GraalClassLoaderTest.java Sat Aug 02 11:14:27 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.hotspot.test; - -import org.junit.*; - -import sun.management.*; - -import com.oracle.graal.api.runtime.*; -import com.sun.management.*; - -/** - * Tests that the Graal API is inaccessible when -XX:+UseGraalClassLoader is specified. Execute as - * follows to show class loader based isolation: - * - *
- * mx unittest -XX:+UseGraalClassLoader GraalClassLoaderTest
- * 
- */ -public class GraalClassLoaderTest { - - @Test - public void test() throws Exception { - if (System.getProperty("java.vm.version").contains("graal")) { - HotSpotDiagnosticMXBean diag = ManagementFactoryHelper.getDiagnosticMXBean(); - VMOption option = diag.getVMOption("UseGraalClassLoader"); - if (option.getValue().equals("true")) { - try { - Graal.getRuntime(); - Assert.fail(); - } catch (NoClassDefFoundError e) { - // expected - } - } - } - } - -} \ No newline at end of file