< prev index next >

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

Print this page




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


  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(method, AllowAssumptions.NO, INVALID_COMPILATION_ID);
  89             Plugins plugins = new Plugins(new InvocationPlugins(getMetaAccess()));
  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     // @formatter:off
 105     // Template class used with Bytecode Outline to generate ASM code
 106     //    public static class UnbalancedMonitors {
 107     //
 108     //        public UnbalancedMonitors() {
 109     //        }




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


  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(method, AllowAssumptions.NO, INVALID_COMPILATION_ID);
  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     // @formatter:off
 105     // Template class used with Bytecode Outline to generate ASM code
 106     //    public static class UnbalancedMonitors {
 107     //
 108     //        public UnbalancedMonitors() {
 109     //        }


< prev index next >