test/compiler/tiered/ConstantGettersTransitionsTest.java

changeset 9689
89dcef434423
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/compiler/tiered/ConstantGettersTransitionsTest.java	Mon Jun 03 16:14:54 2019 +0100
     1.3 @@ -0,0 +1,193 @@
     1.4 +/*
     1.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + */
    1.26 +
    1.27 +import java.lang.reflect.Executable;
    1.28 +import java.util.concurrent.Callable;
    1.29 +
    1.30 +/**
    1.31 + * @test ConstantGettersTransitionsTest
    1.32 + * @library /testlibrary /testlibrary/whitebox /compiler/whitebox
    1.33 + * @build TransitionsTestExecutor ConstantGettersTransitionsTest
    1.34 + * @run main ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
    1.35 + * @run main/othervm/timeout=240 -Xmixed -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
    1.36 + *                   -XX:+WhiteBoxAPI -XX:+TieredCompilation
    1.37 + *                   -XX:CompileCommand=compileonly,ConstantGettersTestCase$TrivialMethods::*
    1.38 + *                   TransitionsTestExecutor ConstantGettersTransitionsTest
    1.39 + * @summary Test the correctness of compilation level transitions for constant getters methods
    1.40 + */
    1.41 +public class ConstantGettersTransitionsTest extends LevelTransitionTest {
    1.42 +    public static void main(String[] args) {
    1.43 +        assert (!CompilerWhiteBoxTest.skipOnTieredCompilation(false));
    1.44 +
    1.45 +        // run test cases
    1.46 +        for (TestCase testCase : ConstantGettersTestCase.values()) {
    1.47 +            new ConstantGettersTransitionsTest(testCase).runTest();
    1.48 +        }
    1.49 +    }
    1.50 +
    1.51 +    @Override
    1.52 +    protected boolean isTrivial() {
    1.53 +        return true;
    1.54 +    }
    1.55 +
    1.56 +    private ConstantGettersTransitionsTest(TestCase testCase) {
    1.57 +        super(testCase);
    1.58 +    }
    1.59 +}
    1.60 +
    1.61 +enum ConstantGettersTestCase implements CompilerWhiteBoxTest.TestCase {
    1.62 +    ICONST_M1,
    1.63 +    ICONST_0,
    1.64 +    ICONST_1,
    1.65 +    ICONST_2,
    1.66 +    ICONST_3,
    1.67 +    ICONST_4,
    1.68 +    ICONST_5,
    1.69 +    LCONST_0,
    1.70 +    LCONST_1,
    1.71 +    FCONST_0,
    1.72 +    FCONST_1,
    1.73 +    FCONST_2,
    1.74 +    DCONST_0,
    1.75 +    DCONST_1,
    1.76 +    DCONST_W,
    1.77 +    BYTE,
    1.78 +    SHORT,
    1.79 +    CHAR;
    1.80 +
    1.81 +    private final Executable executable;
    1.82 +    private final Callable<Integer> callable;
    1.83 +
    1.84 +    @Override
    1.85 +    public Executable getExecutable() {
    1.86 +        return executable;
    1.87 +    }
    1.88 +
    1.89 +    @Override
    1.90 +    public Callable<Integer> getCallable() {
    1.91 +        return callable;
    1.92 +    }
    1.93 +
    1.94 +    @Override
    1.95 +    public boolean isOsr() {
    1.96 +        return false;
    1.97 +    }
    1.98 +
    1.99 +    private ConstantGettersTestCase() {
   1.100 +        String name = "make" + this.name();
   1.101 +        this.executable = LevelTransitionTest.Helper.getMethod(TrivialMethods.class, name);
   1.102 +        this.callable = LevelTransitionTest.Helper.getCallable(new TrivialMethods(), name);
   1.103 +    }
   1.104 +
   1.105 +    /**
   1.106 +     * Contains methods that load constants with certain types of bytecodes
   1.107 +     * See JVMS 2.11.2. Load and Store Instructions
   1.108 +     * Note that it doesn't have a method for ldc_w instruction
   1.109 +     */
   1.110 +    private static class TrivialMethods {
   1.111 +        public static int makeICONST_M1() {
   1.112 +            return -1;
   1.113 +        }
   1.114 +
   1.115 +        public static int makeICONST_0() {
   1.116 +            return 0;
   1.117 +        }
   1.118 +
   1.119 +        public static int makeICONST_1() {
   1.120 +            return 1;
   1.121 +        }
   1.122 +
   1.123 +        public static int makeICONST_2() {
   1.124 +            return 2;
   1.125 +        }
   1.126 +
   1.127 +        public static int makeICONST_3() {
   1.128 +            return 3;
   1.129 +        }
   1.130 +
   1.131 +        public static int makeICONST_4() {
   1.132 +            return 4;
   1.133 +        }
   1.134 +
   1.135 +        public static int makeICONST_5() {
   1.136 +            return 5;
   1.137 +        }
   1.138 +
   1.139 +        public static long makeLCONST_0() {
   1.140 +            return 0L;
   1.141 +        }
   1.142 +
   1.143 +        public static long makeLCONST_1() {
   1.144 +            return 1L;
   1.145 +        }
   1.146 +
   1.147 +        public static float makeFCONST_0() {
   1.148 +            return 0F;
   1.149 +        }
   1.150 +
   1.151 +        public static float makeFCONST_1() {
   1.152 +            return 1F;
   1.153 +        }
   1.154 +
   1.155 +        public static float makeFCONST_2() {
   1.156 +            return 2F;
   1.157 +        }
   1.158 +
   1.159 +        public static double makeDCONST_0() {
   1.160 +            return 0D;
   1.161 +        }
   1.162 +
   1.163 +        public static double makeDCONST_1() {
   1.164 +            return 1D;
   1.165 +        }
   1.166 +
   1.167 +        public static double makeDCONST_W() {
   1.168 +            // ldc2_w
   1.169 +            return Double.MAX_VALUE;
   1.170 +        }
   1.171 +
   1.172 +        public static Object makeOBJECT() {
   1.173 +            // aconst_null
   1.174 +            return null;
   1.175 +        }
   1.176 +
   1.177 +        public static byte makeBYTE() {
   1.178 +            // bipush
   1.179 +            return (byte) 0x7F;
   1.180 +        }
   1.181 +
   1.182 +        public static short makeSHORT() {
   1.183 +            // sipush
   1.184 +            return (short) 0x7FFF;
   1.185 +        }
   1.186 +
   1.187 +        public static char makeCHAR() {
   1.188 +            // ldc
   1.189 +            return (char) 0xFFFF;
   1.190 +        }
   1.191 +
   1.192 +        public static boolean makeBOOLEAN() {
   1.193 +            return true;
   1.194 +        }
   1.195 +    }
   1.196 +}

mercurial