hotspot/test/compiler/compilercontrol/TestCompilerDirectivesCompatibilityBase.java
author dsamersoff
Sun, 01 May 2016 12:47:00 +0300
changeset 38152 80e5da81fb2c
parent 36851 03e2f4d0a421
child 40059 c2304140ed64
permissions -rw-r--r--
8154258: [TESTBUG] Various serviceability tests fail compilation Summary: Replace sun.misc.Unsafe with jdk.internal.misc.Unsafe Reviewed-by: chegar, kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33451
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
     1
/*
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
     4
 *
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
     7
 * published by the Free Software Foundation.
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
     8
 *
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    13
 * accompanied this code).
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    14
 *
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    18
 *
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    21
 * questions.
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    22
 */
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    23
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    24
/*
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    25
 * @test TestCompilerDirectivesCompatibilityBase
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    26
 * @bug 8137167
36321
d3618f1ff1bb 8148159: [TESTBUG] TestCompilerDirectivesCompatibility tests fails on non-tiered server VMs
neliasso
parents: 35753
diff changeset
    27
 * @library /testlibrary /test/lib /
36851
03e2f4d0a421 8153737: Unsupported Module
chegar
parents: 36321
diff changeset
    28
 * @modules java.base/jdk.internal.misc
33451
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    29
 *          java.compiler
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    30
 *          java.management
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    31
 * @build jdk.test.lib.*
36321
d3618f1ff1bb 8148159: [TESTBUG] TestCompilerDirectivesCompatibility tests fails on non-tiered server VMs
neliasso
parents: 35753
diff changeset
    32
 *        jdk.test.lib.dcmd.*
d3618f1ff1bb 8148159: [TESTBUG] TestCompilerDirectivesCompatibility tests fails on non-tiered server VMs
neliasso
parents: 35753
diff changeset
    33
 *        sun.hotspot.WhiteBox
d3618f1ff1bb 8148159: [TESTBUG] TestCompilerDirectivesCompatibility tests fails on non-tiered server VMs
neliasso
parents: 35753
diff changeset
    34
 *        compiler.testlibrary.CompilerUtils
d3618f1ff1bb 8148159: [TESTBUG] TestCompilerDirectivesCompatibility tests fails on non-tiered server VMs
neliasso
parents: 35753
diff changeset
    35
 * @run driver ClassFileInstaller sun.hotspot.WhiteBox
d3618f1ff1bb 8148159: [TESTBUG] TestCompilerDirectivesCompatibility tests fails on non-tiered server VMs
neliasso
parents: 35753
diff changeset
    36
 *                                sun.hotspot.WhiteBox$WhiteBoxPermission
d3618f1ff1bb 8148159: [TESTBUG] TestCompilerDirectivesCompatibility tests fails on non-tiered server VMs
neliasso
parents: 35753
diff changeset
    37
 * @run testng/othervm -Xbootclasspath/a:. -Xmixed -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI TestCompilerDirectivesCompatibilityBase
33451
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    38
 * @summary Test compiler control compatibility with compile command
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    39
 */
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    40
36321
d3618f1ff1bb 8148159: [TESTBUG] TestCompilerDirectivesCompatibility tests fails on non-tiered server VMs
neliasso
parents: 35753
diff changeset
    41
import compiler.testlibrary.CompilerUtils;
d3618f1ff1bb 8148159: [TESTBUG] TestCompilerDirectivesCompatibility tests fails on non-tiered server VMs
neliasso
parents: 35753
diff changeset
    42
import compiler.whitebox.CompilerWhiteBoxTest;
33451
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    43
import jdk.test.lib.dcmd.CommandExecutor;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    44
import jdk.test.lib.dcmd.JMXExecutor;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    45
import org.testng.annotations.Test;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    46
import org.testng.Assert;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    47
import sun.hotspot.WhiteBox;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    48
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    49
import java.io.BufferedReader;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    50
import java.io.File;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    51
import java.io.StringReader;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    52
import java.lang.reflect.Method;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    53
import java.util.Objects;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    54
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    55
public class TestCompilerDirectivesCompatibilityBase {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    56
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    57
    public static final WhiteBox WB = WhiteBox.getWhiteBox();
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    58
    public static String control_on, control_off;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    59
    Method method, nomatch;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    60
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    61
    public void run(CommandExecutor executor) throws Exception {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    62
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    63
        control_on = System.getProperty("test.src", ".") + File.separator + "control_on.txt";
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    64
        control_off = System.getProperty("test.src", ".") + File.separator + "control_off.txt";
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    65
        method  = getMethod(TestCompilerDirectivesCompatibilityBase.class, "helper");
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    66
        nomatch = getMethod(TestCompilerDirectivesCompatibilityBase.class, "another");
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    67
36321
d3618f1ff1bb 8148159: [TESTBUG] TestCompilerDirectivesCompatibility tests fails on non-tiered server VMs
neliasso
parents: 35753
diff changeset
    68
        int[] levels = CompilerUtils.getAvailableCompilationLevels();
d3618f1ff1bb 8148159: [TESTBUG] TestCompilerDirectivesCompatibility tests fails on non-tiered server VMs
neliasso
parents: 35753
diff changeset
    69
        for (int complevel : levels) {
d3618f1ff1bb 8148159: [TESTBUG] TestCompilerDirectivesCompatibility tests fails on non-tiered server VMs
neliasso
parents: 35753
diff changeset
    70
            // Only test the major compilers, ignore profiling levels
d3618f1ff1bb 8148159: [TESTBUG] TestCompilerDirectivesCompatibility tests fails on non-tiered server VMs
neliasso
parents: 35753
diff changeset
    71
            if (complevel == CompilerWhiteBoxTest.COMP_LEVEL_SIMPLE || complevel == CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION){
d3618f1ff1bb 8148159: [TESTBUG] TestCompilerDirectivesCompatibility tests fails on non-tiered server VMs
neliasso
parents: 35753
diff changeset
    72
                testCompatibility(executor, complevel);
d3618f1ff1bb 8148159: [TESTBUG] TestCompilerDirectivesCompatibility tests fails on non-tiered server VMs
neliasso
parents: 35753
diff changeset
    73
            }
d3618f1ff1bb 8148159: [TESTBUG] TestCompilerDirectivesCompatibility tests fails on non-tiered server VMs
neliasso
parents: 35753
diff changeset
    74
        }
33451
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    75
    }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    76
36321
d3618f1ff1bb 8148159: [TESTBUG] TestCompilerDirectivesCompatibility tests fails on non-tiered server VMs
neliasso
parents: 35753
diff changeset
    77
    public void testCompatibility(CommandExecutor executor, int comp_level) throws Exception {
33451
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    78
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    79
        // Call all validation twice to catch error when overwriting a directive
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    80
        // Flag is default off
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    81
        expect(!WB.getBooleanVMFlag("PrintAssembly"));
36321
d3618f1ff1bb 8148159: [TESTBUG] TestCompilerDirectivesCompatibility tests fails on non-tiered server VMs
neliasso
parents: 35753
diff changeset
    82
        expect(!WB.shouldPrintAssembly(method, comp_level));
d3618f1ff1bb 8148159: [TESTBUG] TestCompilerDirectivesCompatibility tests fails on non-tiered server VMs
neliasso
parents: 35753
diff changeset
    83
        expect(!WB.shouldPrintAssembly(nomatch, comp_level));
d3618f1ff1bb 8148159: [TESTBUG] TestCompilerDirectivesCompatibility tests fails on non-tiered server VMs
neliasso
parents: 35753
diff changeset
    84
        expect(!WB.shouldPrintAssembly(method, comp_level));
d3618f1ff1bb 8148159: [TESTBUG] TestCompilerDirectivesCompatibility tests fails on non-tiered server VMs
neliasso
parents: 35753
diff changeset
    85
        expect(!WB.shouldPrintAssembly(nomatch, comp_level));
33451
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    86
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    87
        // load directives that turn it on
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    88
        executor.execute("Compiler.directives_add " + control_on);
36321
d3618f1ff1bb 8148159: [TESTBUG] TestCompilerDirectivesCompatibility tests fails on non-tiered server VMs
neliasso
parents: 35753
diff changeset
    89
        expect(WB.shouldPrintAssembly(method, comp_level));
d3618f1ff1bb 8148159: [TESTBUG] TestCompilerDirectivesCompatibility tests fails on non-tiered server VMs
neliasso
parents: 35753
diff changeset
    90
        expect(!WB.shouldPrintAssembly(nomatch, comp_level));
d3618f1ff1bb 8148159: [TESTBUG] TestCompilerDirectivesCompatibility tests fails on non-tiered server VMs
neliasso
parents: 35753
diff changeset
    91
        expect(WB.shouldPrintAssembly(method, comp_level));
d3618f1ff1bb 8148159: [TESTBUG] TestCompilerDirectivesCompatibility tests fails on non-tiered server VMs
neliasso
parents: 35753
diff changeset
    92
        expect(!WB.shouldPrintAssembly(nomatch, comp_level));
33451
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    93
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    94
        // remove and see that it is true again
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    95
        executor.execute("Compiler.directives_remove");
36321
d3618f1ff1bb 8148159: [TESTBUG] TestCompilerDirectivesCompatibility tests fails on non-tiered server VMs
neliasso
parents: 35753
diff changeset
    96
        expect(!WB.shouldPrintAssembly(method, comp_level));
d3618f1ff1bb 8148159: [TESTBUG] TestCompilerDirectivesCompatibility tests fails on non-tiered server VMs
neliasso
parents: 35753
diff changeset
    97
        expect(!WB.shouldPrintAssembly(nomatch, comp_level));
d3618f1ff1bb 8148159: [TESTBUG] TestCompilerDirectivesCompatibility tests fails on non-tiered server VMs
neliasso
parents: 35753
diff changeset
    98
        expect(!WB.shouldPrintAssembly(method, comp_level));
d3618f1ff1bb 8148159: [TESTBUG] TestCompilerDirectivesCompatibility tests fails on non-tiered server VMs
neliasso
parents: 35753
diff changeset
    99
        expect(!WB.shouldPrintAssembly(nomatch, comp_level));
33451
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   100
    }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   101
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   102
    public void expect(boolean test) throws Exception {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   103
        if (!test) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   104
            throw new Exception("Test failed");
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   105
        }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   106
    }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   107
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   108
    public void expect(boolean test, String msg) throws Exception {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   109
        if (!test) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   110
            throw new Exception(msg);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   111
        }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   112
    }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   113
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   114
    @Test
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   115
    public void jmx() throws Exception {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   116
        run(new JMXExecutor());
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   117
    }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   118
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   119
    public void helper() {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   120
    }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   121
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   122
    public void another() {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   123
    }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   124
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   125
    public static Method getMethod(Class klass, String name, Class<?>... parameterTypes) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   126
        try {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   127
            return klass.getDeclaredMethod(name, parameterTypes);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   128
        } catch (NoSuchMethodException | SecurityException e) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   129
            throw new RuntimeException("exception on getting method Helper." + name, e);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   130
        }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   131
    }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   132
}