hotspot/test/compiler/codecache/dtrace/SegmentedCodeCacheDtraceTestWorker.java
author tpivovarova
Tue, 12 Jul 2016 18:24:48 +0300
changeset 40059 c2304140ed64
parent 30604 b8d532cb6420
permissions -rw-r--r--
8132919: Put compiler tests in packages Reviewed-by: vlivanov, dpochepk Contributed-by: igor.ignatyev@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28392
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
     1
/*
30604
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 28392
diff changeset
     2
 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
28392
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
     4
 *
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
     7
 * published by the Free Software Foundation.
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
     8
 *
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    13
 * accompanied this code).
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    14
 *
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    18
 *
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    21
 * questions.
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    22
 */
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    23
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 30604
diff changeset
    24
package compiler.codecache.dtrace;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 30604
diff changeset
    25
30604
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 28392
diff changeset
    26
import jdk.test.lib.Utils;
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 30604
diff changeset
    27
import sun.hotspot.WhiteBox;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 30604
diff changeset
    28
28392
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    29
import java.lang.reflect.Executable;
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    30
import java.util.ArrayList;
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    31
import java.util.Arrays;
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    32
import java.util.Collections;
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    33
import java.util.List;
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    34
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    35
public class SegmentedCodeCacheDtraceTestWorker {
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    36
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    37
    private static final String METHOD1_NAME = "foo";
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    38
    private static final String METHOD2_NAME = "bar";
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    39
    private static final String METHOD3_NAME = "baz";
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    40
    public static final List<Executable> TESTED_METHODS_LIST;
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    41
    private final WhiteBox wb;
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    42
    private final int compLevels[];
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    43
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    44
    static {
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    45
        List<Executable> methods = new ArrayList<>();
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    46
        try {
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    47
            // method order is important. Need to place methods in call order,
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    48
            // to be able to verify results later
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    49
            methods.add(SegmentedCodeCacheDtraceTestWorker.class.getMethod(METHOD1_NAME));
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    50
            methods.add(SegmentedCodeCacheDtraceTestWorker.class.getMethod(METHOD2_NAME));
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    51
            methods.add(SegmentedCodeCacheDtraceTestWorker.class.getMethod(METHOD3_NAME));
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    52
        } catch (NoSuchMethodException e) {
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    53
            throw new Error("TESTBUG: no expected method found", e);
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    54
        }
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    55
        TESTED_METHODS_LIST = Collections.unmodifiableList(methods);
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    56
    }
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    57
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    58
    protected static final boolean BACKGROUND_COMPILATION
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    59
            = WhiteBox.getWhiteBox().getBooleanVMFlag("BackgroundCompilation");
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    60
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    61
    public static void main(String[] args) {
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    62
        if (args.length != 2 * TESTED_METHODS_LIST.size()) {
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    63
            throw new Error("Usage: java <thisClass> <fooCompLevel> <fooInlined>"
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    64
                    + "<barCompLevel> <barInlined> "
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    65
                    + "<bazCompLevel> <bazInlined>");
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    66
        } else {
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    67
            int compLevels[] = new int[TESTED_METHODS_LIST.size()];
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    68
            boolean inlines[] = new boolean[TESTED_METHODS_LIST.size()];
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    69
            for (int i = 0; i < TESTED_METHODS_LIST.size(); i++) {
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    70
                compLevels[i] = Integer.parseInt(args[2 * i]);
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    71
                inlines[i] = Boolean.parseBoolean(args[2 * i + 1]);
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    72
            }
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    73
            new SegmentedCodeCacheDtraceTestWorker(compLevels, inlines).test();
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    74
        }
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    75
    }
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    76
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    77
    public SegmentedCodeCacheDtraceTestWorker(int compLevels[], boolean inlines[]) {
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    78
        wb = WhiteBox.getWhiteBox();
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    79
        this.compLevels = Arrays.copyOf(compLevels, compLevels.length);
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    80
        for (int i = 0; i < compLevels.length; i++) {
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    81
            if (inlines[i]) {
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    82
                wb.testSetForceInlineMethod(TESTED_METHODS_LIST.get(i), true);
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    83
            } else {
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    84
                wb.testSetDontInlineMethod(TESTED_METHODS_LIST.get(i), true);
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    85
            }
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    86
        }
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    87
    }
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    88
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    89
    private void waitForCompilation(Executable executable, int compLevel) {
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    90
        if (compLevel > 0) {
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    91
            Utils.waitForCondition(() -> wb.isMethodCompiled(executable));
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    92
        }
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    93
    }
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    94
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    95
    protected void test() {
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    96
        for (int i = 0; i < TESTED_METHODS_LIST.size(); i++) {
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    97
            Executable method = TESTED_METHODS_LIST.get(i);
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    98
            int compLevel = compLevels[i];
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
    99
            wb.enqueueMethodForCompilation(method, compLevel);
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
   100
            waitForCompilation(method, compLevel);
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
   101
        }
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
   102
        foo();
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
   103
    }
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
   104
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
   105
    public static void foo() {
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
   106
        bar();
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
   107
    }
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
   108
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
   109
    public static void bar() {
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
   110
        baz();
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
   111
    }
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
   112
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
   113
    public static void baz() {
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
   114
        System.out.println("Reached baz method");
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
   115
    }
f64a0abbff20 8059625: JEP-JDK-8043304: Test task: DTrace- tests for segmented codecache feature
dpochepk
parents:
diff changeset
   116
}