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 hotspot Sdiff src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/UnbalancedMonitorsTest.java

Print this page




  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 package org.graalvm.compiler.core.test;
  24 
  25 import org.graalvm.compiler.java.GraphBuilderPhase;
  26 import org.graalvm.compiler.nodes.StructuredGraph;
  27 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
  28 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins;
  29 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins;

  30 import org.graalvm.compiler.phases.OptimisticOptimizations;
  31 import org.junit.Test;
  32 import org.objectweb.asm.ClassWriter;
  33 import org.objectweb.asm.Label;
  34 import org.objectweb.asm.MethodVisitor;
  35 import org.objectweb.asm.Opcodes;
  36 
  37 import jdk.vm.ci.code.BailoutException;
  38 import jdk.vm.ci.meta.ResolvedJavaMethod;
  39 
  40 /**
  41  * Exercise handling of unbalanced monitor operations by the parser. Algorithmically Graal assumes
  42  * that locks are statically block structured but that isn't something enforced by the bytecodes. In
  43  * HotSpot a dataflow is performed to ensure they are properly structured and methods with
  44  * unstructured locking aren't compiled and fall back to the interpreter. Having the Graal parser
  45  * handle this directly is simplifying for targets of Graal since they don't have to provide a data
  46  * flow that checks this property.
  47  */
  48 public class UnbalancedMonitorsTest extends GraalCompilerTest {
  49     private static final String CLASS_NAME = UnbalancedMonitorsTest.class.getName();


  68     }
  69 
  70     @Test
  71     public void runTooManyExits() throws Exception {
  72         checkForBailout("tooManyExits");
  73     }
  74 
  75     @Test
  76     public void runTooFewExitsExceptional() throws Exception {
  77         checkForBailout("tooFewExitsExceptional");
  78     }
  79 
  80     @Test
  81     public void runTooManyExitsExceptional() throws Exception {
  82         checkForBailout("tooManyExitsExceptional");
  83     }
  84 
  85     private void checkForBailout(String name) throws ClassNotFoundException {
  86         ResolvedJavaMethod method = getResolvedJavaMethod(LOADER.findClass(INNER_CLASS_NAME), name);
  87         try {
  88             StructuredGraph graph = new StructuredGraph.Builder(getInitialOptions()).method(method).build();

  89             Plugins plugins = new Plugins(new InvocationPlugins());
  90             GraphBuilderConfiguration graphBuilderConfig = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true);
  91             OptimisticOptimizations optimisticOpts = OptimisticOptimizations.NONE;
  92 
  93             GraphBuilderPhase.Instance graphBuilder = new GraphBuilderPhase.Instance(getMetaAccess(), getProviders().getStampProvider(), null, null, graphBuilderConfig, optimisticOpts, null);
  94             graphBuilder.apply(graph);
  95         } catch (BailoutException e) {
  96             if (e.getMessage().contains("unbalanced monitors")) {
  97                 return;
  98             }
  99             throw e;
 100         }
 101         assertTrue("should have bailed out", false);
 102     }
 103 
 104     static class Gen implements Opcodes {
 105 
 106     // @formatter:off
 107     // Template class used with Bytecode Outline to generate ASM code
 108     //    public static class UnbalancedMonitors {




  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 package org.graalvm.compiler.core.test;
  24 
  25 import org.graalvm.compiler.java.GraphBuilderPhase;
  26 import org.graalvm.compiler.nodes.StructuredGraph;
  27 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
  28 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins;
  29 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins;
  30 import org.graalvm.compiler.options.OptionValues;
  31 import org.graalvm.compiler.phases.OptimisticOptimizations;
  32 import org.junit.Test;
  33 import org.objectweb.asm.ClassWriter;
  34 import org.objectweb.asm.Label;
  35 import org.objectweb.asm.MethodVisitor;
  36 import org.objectweb.asm.Opcodes;
  37 
  38 import jdk.vm.ci.code.BailoutException;
  39 import jdk.vm.ci.meta.ResolvedJavaMethod;
  40 
  41 /**
  42  * Exercise handling of unbalanced monitor operations by the parser. Algorithmically Graal assumes
  43  * that locks are statically block structured but that isn't something enforced by the bytecodes. In
  44  * HotSpot a dataflow is performed to ensure they are properly structured and methods with
  45  * unstructured locking aren't compiled and fall back to the interpreter. Having the Graal parser
  46  * handle this directly is simplifying for targets of Graal since they don't have to provide a data
  47  * flow that checks this property.
  48  */
  49 public class UnbalancedMonitorsTest extends GraalCompilerTest {
  50     private static final String CLASS_NAME = UnbalancedMonitorsTest.class.getName();


  69     }
  70 
  71     @Test
  72     public void runTooManyExits() throws Exception {
  73         checkForBailout("tooManyExits");
  74     }
  75 
  76     @Test
  77     public void runTooFewExitsExceptional() throws Exception {
  78         checkForBailout("tooFewExitsExceptional");
  79     }
  80 
  81     @Test
  82     public void runTooManyExitsExceptional() throws Exception {
  83         checkForBailout("tooManyExitsExceptional");
  84     }
  85 
  86     private void checkForBailout(String name) throws ClassNotFoundException {
  87         ResolvedJavaMethod method = getResolvedJavaMethod(LOADER.findClass(INNER_CLASS_NAME), name);
  88         try {
  89             OptionValues options = getInitialOptions();
  90             StructuredGraph graph = new StructuredGraph.Builder(options, getDebugContext(options)).method(method).build();
  91             Plugins plugins = new Plugins(new InvocationPlugins());
  92             GraphBuilderConfiguration graphBuilderConfig = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true);
  93             OptimisticOptimizations optimisticOpts = OptimisticOptimizations.NONE;
  94 
  95             GraphBuilderPhase.Instance graphBuilder = new GraphBuilderPhase.Instance(getMetaAccess(), getProviders().getStampProvider(), null, null, graphBuilderConfig, optimisticOpts, null);
  96             graphBuilder.apply(graph);
  97         } catch (BailoutException e) {
  98             if (e.getMessage().contains("unbalanced monitors")) {
  99                 return;
 100             }
 101             throw e;
 102         }
 103         assertTrue("should have bailed out", false);
 104     }
 105 
 106     static class Gen implements Opcodes {
 107 
 108     // @formatter:off
 109     // Template class used with Bytecode Outline to generate ASM code
 110     //    public static class UnbalancedMonitors {


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