hotspot/test/compiler/whitebox/DeoptimizeMultipleOSRTest.java
author thartmann
Fri, 12 Dec 2014 09:37:38 +0100
changeset 28190 5a6b07edeb21
parent 27434 b4b185d05bb5
child 29678 dd2f3932c21e
permissions -rw-r--r--
8066433: Move Whitebox test library to top level repository Summary: Moved Whitebox test library to top level repository. Reviewed-by: iignatyev, sla, mr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
27434
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
     1
/*
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
     2
 * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
     4
 *
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
     7
 * published by the Free Software Foundation.
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
     8
 *
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    13
 * accompanied this code).
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    14
 *
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    18
 *
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    21
 * questions.
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    22
 */
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    23
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    24
import sun.hotspot.WhiteBox;
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    25
import java.lang.reflect.Executable;
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    26
import java.lang.reflect.Method;
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    27
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    28
/*
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    29
 * @test DeoptimizeMultipleOSRTest
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    30
 * @bug 8061817
28190
5a6b07edeb21 8066433: Move Whitebox test library to top level repository
thartmann
parents: 27434
diff changeset
    31
 * @library /testlibrary /../../test/lib
27434
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    32
 * @build DeoptimizeMultipleOSRTest
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    33
 * @run main ClassFileInstaller sun.hotspot.WhiteBox
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    34
 *                              sun.hotspot.WhiteBox$WhiteBoxPermission
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    35
 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:CompileCommand=compileonly,DeoptimizeMultipleOSRTest::triggerOSR DeoptimizeMultipleOSRTest
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    36
 * @summary testing of WB::deoptimizeMethod()
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    37
 */
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    38
public class DeoptimizeMultipleOSRTest {
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    39
    private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    40
    private static final long BACKEDGE_THRESHOLD = 150000;
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    41
    private Method method;
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    42
    private int counter = 0;
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    43
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    44
    public static void main(String[] args) throws Exception {
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    45
        DeoptimizeMultipleOSRTest test = new DeoptimizeMultipleOSRTest();
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    46
        test.test();
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    47
    }
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    48
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    49
    /**
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    50
     * Triggers two different OSR compilations for the same method and
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    51
     * checks if WhiteBox.deoptimizeMethod() deoptimizes both.
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    52
     *
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    53
     * @throws Exception
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    54
     */
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    55
    public void test() throws Exception {
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    56
        method = DeoptimizeMultipleOSRTest.class.getDeclaredMethod("triggerOSR", boolean.class, long.class);
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    57
        // Trigger two OSR compiled versions
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    58
        triggerOSR(true, BACKEDGE_THRESHOLD);
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    59
        triggerOSR(false, BACKEDGE_THRESHOLD);
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    60
        // Wait for compilation
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    61
        CompilerWhiteBoxTest.waitBackgroundCompilation(method);
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    62
        // Deoptimize
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    63
        WHITE_BOX.deoptimizeMethod(method, true);
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    64
        if (WHITE_BOX.isMethodCompiled(method, true)) {
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    65
            throw new AssertionError("Not all OSR compiled versions were deoptimized");
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    66
        }
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    67
    }
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    68
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    69
    /**
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    70
     * Triggers OSR compilations by executing loops.
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    71
     *
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    72
     * @param first Determines which loop to execute
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    73
     * @param limit The number of loop iterations
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    74
     */
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    75
    public void triggerOSR(boolean first, long limit) {
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    76
        if (limit != 1) {
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    77
            // Warmup method to avoid uncommon traps
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    78
            for (int i = 0; i < limit; ++i) {
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    79
                triggerOSR(first, 1);
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    80
            }
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    81
            CompilerWhiteBoxTest.waitBackgroundCompilation(method);
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    82
        }
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    83
        if (first) {
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    84
            // Trigger OSR compilation 1
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    85
            for (int i = 0; i < limit; ++i) {
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    86
                counter++;
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    87
            }
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    88
        } else {
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    89
            // Trigger OSR compilation 2
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    90
            for (int i = 0; i < limit; ++i) {
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    91
                counter++;
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    92
            }
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    93
        }
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    94
    }
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    95
}