src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/UnbalancedMonitorsTest.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File
*** old/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/UnbalancedMonitorsTest.java	Mon Mar 20 17:37:35 2017
--- new/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/UnbalancedMonitorsTest.java	Mon Mar 20 17:37:35 2017

*** 20,62 **** --- 20,62 ---- * or visit www.oracle.com if you need additional information or have any * questions. */ package org.graalvm.compiler.core.test; import jdk.vm.ci.code.BailoutException; import jdk.vm.ci.meta.ResolvedJavaMethod; import jdk.internal.org.objectweb.asm.ClassWriter; import jdk.internal.org.objectweb.asm.Label; import jdk.internal.org.objectweb.asm.MethodVisitor; import jdk.internal.org.objectweb.asm.Opcodes; import static org.graalvm.compiler.core.common.CompilationIdentifier.INVALID_COMPILATION_ID; import org.junit.Test; import org.graalvm.compiler.java.GraphBuilderPhase; import org.graalvm.compiler.nodes.StructuredGraph; import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions; import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration; import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins; import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins; + import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins; import org.graalvm.compiler.phases.OptimisticOptimizations; + import org.junit.Test; + import org.objectweb.asm.ClassWriter; + import org.objectweb.asm.Label; + import org.objectweb.asm.MethodVisitor; + import org.objectweb.asm.Opcodes; + + import jdk.vm.ci.code.BailoutException; + import jdk.vm.ci.meta.ResolvedJavaMethod; /** * Exercise handling of unbalanced monitor operations by the parser. Algorithmically Graal assumes * that locks are statically block structured but that isn't something enforced by the bytecodes. In * HotSpot a dataflow is performed to ensure they are properly structured and methods with * unstructured locking aren't compiled and fall back to the interpreter. Having the Graal parser * handle this directly is simplifying for targets of Graal since they don't have to provide a data * flow that checks this property. */ - public class UnbalancedMonitorsTest extends GraalCompilerTest implements Opcodes { private static final String CLASS_NAME = UnbalancedMonitorsTest.class.getName(); private static final String INNER_CLASS_NAME = CLASS_NAME + "$UnbalancedMonitors"; private static final String CLASS_NAME_INTERNAL = CLASS_NAME.replace('.', '/'); private static final String INNER_CLASS_NAME_INTERNAL = INNER_CLASS_NAME.replace('.', '/'); + public UnbalancedMonitorsTest() { + exportPackage(JAVA_BASE, "jdk.internal.org.objectweb.asm"); + } + private static AsmLoader LOADER = new AsmLoader(UnbalancedMonitorsTest.class.getClassLoader()); @Test public void runWrongOrder() throws Exception { checkForBailout("wrongOrder");
*** 83,93 **** --- 83,93 ---- } private void checkForBailout(String name) throws ClassNotFoundException { ResolvedJavaMethod method = getResolvedJavaMethod(LOADER.findClass(INNER_CLASS_NAME), name); try { ! StructuredGraph graph = new StructuredGraph(method, AllowAssumptions.NO, INVALID_COMPILATION_ID); ! StructuredGraph graph = new StructuredGraph.Builder(getInitialOptions()).method(method).build(); Plugins plugins = new Plugins(new InvocationPlugins(getMetaAccess())); GraphBuilderConfiguration graphBuilderConfig = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true); OptimisticOptimizations optimisticOpts = OptimisticOptimizations.NONE; GraphBuilderPhase.Instance graphBuilder = new GraphBuilderPhase.Instance(getMetaAccess(), getProviders().getStampProvider(), null, null, graphBuilderConfig, optimisticOpts, null);
*** 99,108 **** --- 99,110 ---- throw e; } assertTrue("should have bailed out", false); } + static class Gen implements Opcodes { + // @formatter:off // Template class used with Bytecode Outline to generate ASM code // public static class UnbalancedMonitors { // // public UnbalancedMonitors() {
*** 155,165 **** --- 157,168 ---- return cw.toByteArray(); } private static void visitBlockStructured(ClassWriter cw, boolean normalReturnError, boolean tooMany) { String name = (tooMany ? "tooMany" : "tooFew") + "Exits" + (normalReturnError ? "" : "Exceptional"); // Generate too many or too few exits down the either the normal or exceptional return paths + // Generate too many or too few exits down the either the normal or exceptional return + // paths int exceptionalExitCount = normalReturnError ? 1 : (tooMany ? 2 : 0); int normalExitCount = normalReturnError ? (tooMany ? 2 : 0) : 1; MethodVisitor mv; mv = cw.visitMethod(ACC_PUBLIC, name, "(Ljava/lang/Object;Ljava/lang/Object;)Z", null, null); mv.visitCode();
*** 292,301 **** --- 295,305 ---- Label l2 = new Label(); mv.visitLabel(l2); mv.visitMaxs(1, 1); mv.visitEnd(); } + } public static class AsmLoader extends ClassLoader { Class<?> loaded; public AsmLoader(ClassLoader parent) {
*** 306,316 **** --- 310,320 ---- protected Class<?> findClass(String name) throws ClassNotFoundException { if (name.equals(INNER_CLASS_NAME)) { if (loaded != null) { return loaded; } ! byte[] bytes = Gen.generateClass(); return (loaded = defineClass(name, bytes, 0, bytes.length)); } else { return super.findClass(name); } }

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/UnbalancedMonitorsTest.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File