test/compiler/osr/TestOSRWithNonEmptyStack.java

Mon, 28 Jul 2014 15:06:38 -0700

author
fzhinkin
date
Mon, 28 Jul 2014 15:06:38 -0700
changeset 6997
dbb05f6d93c4
permissions
-rw-r--r--

8051344: JVM crashed in Compile::start() during method parsing w/ UseRTMDeopt turned on
Summary: call rtm_deopt() only if there were no compilation bailouts before.
Reviewed-by: kvn

     1 /*
     2  * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     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  */
    24 import java.lang.reflect.Constructor;
    25 import java.lang.reflect.Method;
    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 static jdk.internal.org.objectweb.asm.Opcodes.*;
    32 /**
    33  * @test
    34  * @bug 8051344
    35  * @summary Force OSR compilation with non-empty stack at the OSR entry point.
    36  * @compile -XDignore.symbol.file TestOSRWithNonEmptyStack.java
    37  * @run main/othervm -XX:CompileOnly=TestCase.test TestOSRWithNonEmptyStack
    38  */
    39 public class TestOSRWithNonEmptyStack extends ClassLoader {
    40     private static final int CLASS_FILE_VERSION = 52;
    41     private static final String CLASS_NAME = "TestCase";
    42     private static final String METHOD_NAME = "test";
    43     private static final int ITERATIONS = 1_000_000;
    45     private static byte[] generateTestClass() {
    46         ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
    48         cw.visit(TestOSRWithNonEmptyStack.CLASS_FILE_VERSION, ACC_PUBLIC,
    49                 TestOSRWithNonEmptyStack.CLASS_NAME, null, "java/lang/Object",
    50                 null);
    52         TestOSRWithNonEmptyStack.generateConstructor(cw);
    53         TestOSRWithNonEmptyStack.generateTestMethod(cw);
    55         cw.visitEnd();
    56         return cw.toByteArray();
    57     }
    59     private static void generateConstructor(ClassWriter classWriter) {
    60         MethodVisitor mv = classWriter.visitMethod(ACC_PUBLIC, "<init>", "()V",
    61                 null, null);
    63         mv.visitCode();
    65         mv.visitVarInsn(ALOAD, 0);
    66         mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V",
    67                 false);
    68         mv.visitInsn(RETURN);
    70         mv.visitMaxs(0, 0);
    71         mv.visitEnd();
    72     }
    74     private static void generateTestMethod(ClassWriter classWriter) {
    75         MethodVisitor mv = classWriter.visitMethod(ACC_PUBLIC,
    76                 TestOSRWithNonEmptyStack.METHOD_NAME, "()V", null, null);
    77         Label osrEntryPoint = new Label();
    79         mv.visitCode();
    80         // Push 'this' into stack before OSR entry point to bail out compilation
    81         mv.visitVarInsn(ALOAD, 0);
    82         // Setup loop counter
    83         mv.visitInsn(ICONST_0);
    84         mv.visitVarInsn(ISTORE, 1);
    85         // Begin loop
    86         mv.visitLabel(osrEntryPoint);
    87         // Increment loop counter
    88         mv.visitVarInsn(ILOAD, 1);
    89         mv.visitInsn(ICONST_1);
    90         mv.visitInsn(IADD);
    91         // Duplicate it for loop condition check
    92         mv.visitInsn(DUP);
    93         mv.visitVarInsn(ISTORE, 1);
    94         // Check loop condition
    95         mv.visitLdcInsn(TestOSRWithNonEmptyStack.ITERATIONS);
    96         mv.visitJumpInsn(IF_ICMPLT, osrEntryPoint);
    97         // Pop 'this'.
    98         mv.visitInsn(POP);
    99         mv.visitInsn(RETURN);
   101         mv.visitMaxs(0, 0);
   102         mv.visitEnd();
   103     }
   105     private void run() {
   106         byte[] bytecode = TestOSRWithNonEmptyStack.generateTestClass();
   108         try {
   109             Class klass = defineClass(TestOSRWithNonEmptyStack.CLASS_NAME,
   110                     bytecode, 0, bytecode.length);
   112             Constructor ctor = klass.getConstructor();
   113             Method method = klass.getDeclaredMethod(
   114                     TestOSRWithNonEmptyStack.METHOD_NAME);
   116             Object testCase = ctor.newInstance();
   117             method.invoke(testCase);
   118         } catch (Exception e) {
   119             throw new RuntimeException(
   120                     "Test bug: generated class should be valid.", e);
   121         }
   122     }
   124     public static void main(String args[]) {
   125         new TestOSRWithNonEmptyStack().run();
   126     }
   127 }

mercurial