hotspot/test/compiler/whitebox/DeoptimizeMultipleOSRTest.java
author cjplummer
Thu, 29 Oct 2015 12:04:04 -0700
changeset 33730 30e064828045
parent 29678 dd2f3932c21e
child 34185 ee71c590a456
permissions -rw-r--r--
8140189: [TESTBUG] Get rid of "@library /../../test/lib" in jtreg tests Summary: Use new external.lib.roots property in TEST.ROOT so /../../test/lib is not needed. Reviewed-by: mseledtsov, sla, iklam
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
/*
29678
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 28190
diff changeset
     2
 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
27434
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
33730
30e064828045 8140189: [TESTBUG] Get rid of "@library /../../test/lib" in jtreg tests
cjplummer
parents: 29678
diff changeset
    31
 * @library /testlibrary /test/lib
29678
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 28190
diff changeset
    32
 * @modules java.management
27434
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    33
 * @build DeoptimizeMultipleOSRTest
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    34
 * @run main ClassFileInstaller sun.hotspot.WhiteBox
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    35
 *                              sun.hotspot.WhiteBox$WhiteBoxPermission
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    36
 * @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
    37
 * @summary testing of WB::deoptimizeMethod()
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    38
 */
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    39
public class DeoptimizeMultipleOSRTest {
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    40
    private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    41
    private static final long BACKEDGE_THRESHOLD = 150000;
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    42
    private Method method;
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    43
    private int counter = 0;
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    44
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    45
    public static void main(String[] args) throws Exception {
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    46
        DeoptimizeMultipleOSRTest test = new DeoptimizeMultipleOSRTest();
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    47
        test.test();
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
    /**
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    51
     * 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
    52
     * checks if WhiteBox.deoptimizeMethod() deoptimizes both.
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    53
     *
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    54
     * @throws Exception
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    55
     */
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    56
    public void test() throws Exception {
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    57
        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
    58
        // Trigger two OSR compiled versions
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    59
        triggerOSR(true, BACKEDGE_THRESHOLD);
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    60
        triggerOSR(false, BACKEDGE_THRESHOLD);
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    61
        // Wait for compilation
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    62
        CompilerWhiteBoxTest.waitBackgroundCompilation(method);
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    63
        // Deoptimize
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    64
        WHITE_BOX.deoptimizeMethod(method, true);
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    65
        if (WHITE_BOX.isMethodCompiled(method, true)) {
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    66
            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
    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
    /**
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    71
     * Triggers OSR compilations by executing loops.
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    72
     *
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    73
     * @param first Determines which loop to execute
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    74
     * @param limit The number of loop iterations
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    75
     */
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    76
    public void triggerOSR(boolean first, long limit) {
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    77
        if (limit != 1) {
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    78
            // Warmup method to avoid uncommon traps
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    79
            for (int i = 0; i < limit; ++i) {
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    80
                triggerOSR(first, 1);
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    81
            }
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    82
            CompilerWhiteBoxTest.waitBackgroundCompilation(method);
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    83
        }
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    84
        if (first) {
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    85
            // Trigger OSR compilation 1
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    86
            for (int i = 0; i < limit; ++i) {
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    87
                counter++;
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    88
            }
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    89
        } else {
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    90
            // Trigger OSR compilation 2
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    91
            for (int i = 0; i < limit; ++i) {
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    92
                counter++;
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
    }
b4b185d05bb5 8061817: Whitebox.deoptimizeMethod() does not deoptimize all OSR versions of method
thartmann
parents:
diff changeset
    96
}