hotspot/test/compiler/intrinsics/bmi/verifycode/BmiIntrinsicBase.java
author tpivovarova
Wed, 13 Jul 2016 18:03:15 +0300
changeset 40067 db6c74a53556
parent 40059 c2304140ed64
child 41705 332239c052cc
permissions -rw-r--r--
8151280: update hotspot tests to use vm.compMode instead of their own logic Summary: Update hs compiler tests to use vm.compMode instead of their own logic and to get VM mode using j.t.l.Platform Reviewed-by: kvn, dpochepk Contributed-by: igor.ignatyev@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24003
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
     1
/*
30604
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 25735
diff changeset
     2
 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
24003
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
     4
 *
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
     7
 * published by the Free Software Foundation.
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
     8
 *
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    13
 * accompanied this code).
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    14
 *
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    18
 *
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    21
 * questions.
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    22
 *
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    23
 */
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    24
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 40033
diff changeset
    25
package compiler.intrinsics.bmi.verifycode;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 40033
diff changeset
    26
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 40033
diff changeset
    27
import compiler.whitebox.CompilerWhiteBoxTest;
30604
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 25735
diff changeset
    28
import jdk.test.lib.Asserts;
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 25735
diff changeset
    29
import jdk.test.lib.Platform;
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 25735
diff changeset
    30
import jdk.test.lib.Utils;
24003
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    31
import sun.hotspot.code.NMethod;
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    32
import sun.hotspot.cpuinfo.CPUInfo;
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    33
40033
dbd5f9838049 8143081: [ctw] Test CompileTheWorld.java needs to be updated for Jigsaw
tpivovarova
parents: 34155
diff changeset
    34
import java.lang.invoke.MethodHandle;
dbd5f9838049 8143081: [ctw] Test CompileTheWorld.java needs to be updated for Jigsaw
tpivovarova
parents: 34155
diff changeset
    35
import java.lang.invoke.MethodType;
24003
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    36
import java.lang.reflect.Executable;
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    37
import java.lang.reflect.Method;
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    38
import java.util.concurrent.Callable;
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    39
import java.util.function.Function;
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    40
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    41
public class BmiIntrinsicBase extends CompilerWhiteBoxTest {
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    42
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    43
    protected BmiIntrinsicBase(BmiTestCase testCase) {
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    44
        super(testCase);
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    45
    }
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    46
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    47
    public static void verifyTestCase(Function<Method, BmiTestCase> constructor, Method... methods) throws Exception {
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    48
        for (Method method : methods) {
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    49
            new BmiIntrinsicBase(constructor.apply(method)).test();
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    50
        }
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    51
    }
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    52
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    53
    @Override
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    54
    protected void test() throws Exception {
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    55
        BmiTestCase bmiTestCase = (BmiTestCase) testCase;
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    56
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    57
        if (!(Platform.isX86() || Platform.isX64())) {
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    58
            System.out.println("Unsupported platform, test SKIPPED");
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    59
            return;
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    60
        }
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    61
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    62
        if (!Platform.isServer()) {
40067
db6c74a53556 8151280: update hotspot tests to use vm.compMode instead of their own logic
tpivovarova
parents: 40059
diff changeset
    63
            throw new Error("TESTBUG: Not server VM");
db6c74a53556 8151280: update hotspot tests to use vm.compMode instead of their own logic
tpivovarova
parents: 40059
diff changeset
    64
        }
db6c74a53556 8151280: update hotspot tests to use vm.compMode instead of their own logic
tpivovarova
parents: 40059
diff changeset
    65
db6c74a53556 8151280: update hotspot tests to use vm.compMode instead of their own logic
tpivovarova
parents: 40059
diff changeset
    66
        if (Platform.isInt()) {
db6c74a53556 8151280: update hotspot tests to use vm.compMode instead of their own logic
tpivovarova
parents: 40059
diff changeset
    67
            throw new Error("TESTBUG: test can not be run in interpreter");
24003
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    68
        }
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    69
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    70
        if (!CPUInfo.hasFeature(bmiTestCase.getCpuFlag())) {
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    71
            System.out.println("Unsupported hardware, no required CPU flag " + bmiTestCase.getCpuFlag() + " , test SKIPPED");
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    72
            return;
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    73
        }
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    74
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    75
        if (!Boolean.valueOf(getVMOption(bmiTestCase.getVMFlag()))) {
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    76
            System.out.println("VM flag " + bmiTestCase.getVMFlag() + " disabled, test SKIPPED");
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    77
            return;
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    78
        }
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    79
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    80
        System.out.println(testCase.name());
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    81
40067
db6c74a53556 8151280: update hotspot tests to use vm.compMode instead of their own logic
tpivovarova
parents: 40059
diff changeset
    82
        if (TIERED_COMPILATION && TIERED_STOP_AT_LEVEL != CompilerWhiteBoxTest.COMP_LEVEL_MAX) {
db6c74a53556 8151280: update hotspot tests to use vm.compMode instead of their own logic
tpivovarova
parents: 40059
diff changeset
    83
            System.out.println("TieredStopAtLevel value (" + TIERED_STOP_AT_LEVEL + ") is too low, test SKIPPED");
db6c74a53556 8151280: update hotspot tests to use vm.compMode instead of their own logic
tpivovarova
parents: 40059
diff changeset
    84
            return;
24003
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    85
        }
40067
db6c74a53556 8151280: update hotspot tests to use vm.compMode instead of their own logic
tpivovarova
parents: 40059
diff changeset
    86
        deoptimize();
db6c74a53556 8151280: update hotspot tests to use vm.compMode instead of their own logic
tpivovarova
parents: 40059
diff changeset
    87
        compileAtLevelAndCheck(CompilerWhiteBoxTest.COMP_LEVEL_MAX);
24003
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    88
    }
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    89
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    90
    protected void compileAtLevelAndCheck(int level) {
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    91
        WHITE_BOX.enqueueMethodForCompilation(method, level);
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    92
        waitBackgroundCompilation();
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    93
        checkCompilation(method, level);
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    94
        checkEmittedCode(method);
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    95
    }
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    96
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    97
    protected void checkCompilation(Executable executable, int level) {
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    98
        if (!WHITE_BOX.isMethodCompiled(executable)) {
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
    99
            throw new AssertionError("Test bug, expected compilation (level): " + level + ", but not compiled" + WHITE_BOX.isMethodCompilable(executable, level));
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   100
        }
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   101
        final int compilationLevel = WHITE_BOX.getMethodCompilationLevel(executable);
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   102
        if (compilationLevel != level) {
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   103
            throw new AssertionError("Test bug, expected compilation (level): " + level + ", but level: " + compilationLevel);
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   104
        }
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   105
    }
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   106
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   107
    protected void checkEmittedCode(Executable executable) {
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   108
        final byte[] nativeCode = NMethod.get(executable, false).insts;
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   109
        if (!((BmiTestCase) testCase).verifyPositive(nativeCode)) {
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   110
            throw new AssertionError(testCase.name() + "CPU instructions expected not found: " + Utils.toHexString(nativeCode));
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   111
        } else {
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   112
            System.out.println("CPU instructions found, PASSED");
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   113
        }
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   114
    }
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   115
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   116
    abstract static class BmiTestCase implements CompilerWhiteBoxTest.TestCase {
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   117
        private final Method method;
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   118
        protected byte[] instrMask;
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   119
        protected byte[] instrPattern;
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   120
        protected boolean isLongOperation;
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   121
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   122
        public BmiTestCase(Method method) {
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   123
            this.method = method;
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   124
        }
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   125
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   126
        @Override
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   127
        public String name() {
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   128
            return method.toGenericString();
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   129
        }
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   130
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   131
        @Override
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   132
        public Executable getExecutable() {
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   133
            return method;
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   134
        }
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   135
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   136
        @Override
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   137
        public Callable<Integer> getCallable() {
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   138
            return null;
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   139
        }
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   140
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   141
        @Override
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   142
        public boolean isOsr() {
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   143
            return false;
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   144
        }
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   145
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   146
        protected int countCpuInstructions(byte[] nativeCode) {
25735
990d2378e01d 8049348: compiler/intrinsics/bmi/verifycode tests on lzcnt and tzcnt use incorrect assumption about REXB prefix usage
aaivanov
parents: 24003
diff changeset
   147
            return countCpuInstructions(nativeCode, instrMask, instrPattern);
990d2378e01d 8049348: compiler/intrinsics/bmi/verifycode tests on lzcnt and tzcnt use incorrect assumption about REXB prefix usage
aaivanov
parents: 24003
diff changeset
   148
        }
990d2378e01d 8049348: compiler/intrinsics/bmi/verifycode tests on lzcnt and tzcnt use incorrect assumption about REXB prefix usage
aaivanov
parents: 24003
diff changeset
   149
990d2378e01d 8049348: compiler/intrinsics/bmi/verifycode tests on lzcnt and tzcnt use incorrect assumption about REXB prefix usage
aaivanov
parents: 24003
diff changeset
   150
        public static int countCpuInstructions(byte[] nativeCode, byte[] instrMask, byte[] instrPattern) {
24003
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   151
            int count = 0;
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   152
            int patternSize = Math.min(instrMask.length, instrPattern.length);
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   153
            boolean found;
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   154
            Asserts.assertGreaterThan(patternSize, 0);
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   155
            for (int i = 0, n = nativeCode.length - patternSize; i < n; i++) {
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   156
                found = true;
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   157
                for (int j = 0; j < patternSize; j++) {
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   158
                    if ((nativeCode[i + j] & instrMask[j]) != instrPattern[j]) {
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   159
                        found = false;
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   160
                        break;
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   161
                    }
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   162
                }
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   163
                if (found) {
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   164
                    ++count;
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   165
                    i += patternSize - 1;
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   166
                }
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   167
            }
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   168
            return count;
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   169
        }
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   170
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   171
        public boolean verifyPositive(byte[] nativeCode) {
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   172
            final int cnt = countCpuInstructions(nativeCode);
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   173
            if (Platform.isX86()) {
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   174
                return cnt >= (isLongOperation ? 2 : 1);
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   175
            } else {
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   176
                return Platform.isX64() && cnt >= 1;
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   177
            }
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   178
        }
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   179
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   180
        protected String getCpuFlag() {
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   181
            return "bmi1";
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   182
        }
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   183
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   184
        protected String getVMFlag() {
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   185
            return "UseBMI1Instructions";
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   186
        }
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   187
    }
25735
990d2378e01d 8049348: compiler/intrinsics/bmi/verifycode tests on lzcnt and tzcnt use incorrect assumption about REXB prefix usage
aaivanov
parents: 24003
diff changeset
   188
990d2378e01d 8049348: compiler/intrinsics/bmi/verifycode tests on lzcnt and tzcnt use incorrect assumption about REXB prefix usage
aaivanov
parents: 24003
diff changeset
   189
    abstract static class BmiTestCase_x64 extends BmiTestCase {
990d2378e01d 8049348: compiler/intrinsics/bmi/verifycode tests on lzcnt and tzcnt use incorrect assumption about REXB prefix usage
aaivanov
parents: 24003
diff changeset
   190
        protected byte[] instrMask_x64;
990d2378e01d 8049348: compiler/intrinsics/bmi/verifycode tests on lzcnt and tzcnt use incorrect assumption about REXB prefix usage
aaivanov
parents: 24003
diff changeset
   191
        protected byte[] instrPattern_x64;
990d2378e01d 8049348: compiler/intrinsics/bmi/verifycode tests on lzcnt and tzcnt use incorrect assumption about REXB prefix usage
aaivanov
parents: 24003
diff changeset
   192
990d2378e01d 8049348: compiler/intrinsics/bmi/verifycode tests on lzcnt and tzcnt use incorrect assumption about REXB prefix usage
aaivanov
parents: 24003
diff changeset
   193
        protected BmiTestCase_x64(Method method) {
990d2378e01d 8049348: compiler/intrinsics/bmi/verifycode tests on lzcnt and tzcnt use incorrect assumption about REXB prefix usage
aaivanov
parents: 24003
diff changeset
   194
            super(method);
990d2378e01d 8049348: compiler/intrinsics/bmi/verifycode tests on lzcnt and tzcnt use incorrect assumption about REXB prefix usage
aaivanov
parents: 24003
diff changeset
   195
        }
990d2378e01d 8049348: compiler/intrinsics/bmi/verifycode tests on lzcnt and tzcnt use incorrect assumption about REXB prefix usage
aaivanov
parents: 24003
diff changeset
   196
990d2378e01d 8049348: compiler/intrinsics/bmi/verifycode tests on lzcnt and tzcnt use incorrect assumption about REXB prefix usage
aaivanov
parents: 24003
diff changeset
   197
        protected int countCpuInstructions(byte[] nativeCode) {
990d2378e01d 8049348: compiler/intrinsics/bmi/verifycode tests on lzcnt and tzcnt use incorrect assumption about REXB prefix usage
aaivanov
parents: 24003
diff changeset
   198
            int cnt = super.countCpuInstructions(nativeCode);
990d2378e01d 8049348: compiler/intrinsics/bmi/verifycode tests on lzcnt and tzcnt use incorrect assumption about REXB prefix usage
aaivanov
parents: 24003
diff changeset
   199
            if (Platform.isX64()) { // on x64 platform the instruction we search for can be encoded in 2 different ways
990d2378e01d 8049348: compiler/intrinsics/bmi/verifycode tests on lzcnt and tzcnt use incorrect assumption about REXB prefix usage
aaivanov
parents: 24003
diff changeset
   200
                cnt += countCpuInstructions(nativeCode, instrMask_x64, instrPattern_x64);
990d2378e01d 8049348: compiler/intrinsics/bmi/verifycode tests on lzcnt and tzcnt use incorrect assumption about REXB prefix usage
aaivanov
parents: 24003
diff changeset
   201
            }
990d2378e01d 8049348: compiler/intrinsics/bmi/verifycode tests on lzcnt and tzcnt use incorrect assumption about REXB prefix usage
aaivanov
parents: 24003
diff changeset
   202
            return cnt;
990d2378e01d 8049348: compiler/intrinsics/bmi/verifycode tests on lzcnt and tzcnt use incorrect assumption about REXB prefix usage
aaivanov
parents: 24003
diff changeset
   203
        }
990d2378e01d 8049348: compiler/intrinsics/bmi/verifycode tests on lzcnt and tzcnt use incorrect assumption about REXB prefix usage
aaivanov
parents: 24003
diff changeset
   204
    }
24003
372cef87666e 8038953: Add sanity tests for BMI1 and LZCNT instructions
iignatyev
parents:
diff changeset
   205
}