1 /* 2 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 import java.lang.reflect.Executable; 25 import java.util.concurrent.Callable; 26 27 /** 28 * @test ConstantGettersTransitionsTest 29 * @library /testlibrary /../../test/lib /compiler/whitebox 30 * @modules java.base/sun.misc 31 * java.management 32 * @build TransitionsTestExecutor ConstantGettersTransitionsTest 33 * @run main ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission 34 * @run main/othervm/timeout=240 -Xmixed -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions 35 * -XX:+WhiteBoxAPI -XX:+TieredCompilation 36 * -XX:CompileCommand=compileonly,ConstantGettersTestCase$TrivialMethods::* 37 * TransitionsTestExecutor ConstantGettersTransitionsTest 38 * @summary Test the correctness of compilation level transitions for constant getters methods 39 */ 40 public class ConstantGettersTransitionsTest extends LevelTransitionTest { 41 public static void main(String[] args) { 42 assert (!CompilerWhiteBoxTest.skipOnTieredCompilation(false)); 43 44 // run test cases 45 for (TestCase testCase : ConstantGettersTestCase.values()) { 46 new ConstantGettersTransitionsTest(testCase).runTest(); 47 } 48 } 49 50 @Override 51 protected boolean isTrivial() { 52 return true; 53 } 54 55 private ConstantGettersTransitionsTest(TestCase testCase) { 56 super(testCase); 57 } 58 } 59 60 enum ConstantGettersTestCase implements CompilerWhiteBoxTest.TestCase { 61 ICONST_M1, 62 ICONST_0, 63 ICONST_1, 64 ICONST_2, 65 ICONST_3, 66 ICONST_4, 67 ICONST_5, 68 LCONST_0, 69 LCONST_1, 70 FCONST_0, 71 FCONST_1, 72 FCONST_2, 73 DCONST_0, 74 DCONST_1, 75 DCONST_W, 76 BYTE, 77 SHORT, 78 CHAR; 79 80 private final Executable executable; 81 private final Callable<Integer> callable; 82 83 @Override 84 public Executable getExecutable() { 85 return executable; 86 } 87 88 @Override 89 public Callable<Integer> getCallable() { 90 return callable; 91 } 92 93 @Override 94 public boolean isOsr() { 95 return false; 96 } 97 98 private ConstantGettersTestCase() { 99 String name = "make" + this.name(); 100 this.executable = LevelTransitionTest.Helper.getMethod(TrivialMethods.class, name); 101 this.callable = LevelTransitionTest.Helper.getCallable(new TrivialMethods(), name); 102 } 103 104 /** 105 * Contains methods that load constants with certain types of bytecodes 106 * See JVMS 2.11.2. Load and Store Instructions 107 * Note that it doesn't have a method for ldc_w instruction 108 */ 109 private static class TrivialMethods { 110 public static int makeICONST_M1() { 111 return -1; 112 } 113 114 public static int makeICONST_0() { 115 return 0; 116 } 117 118 public static int makeICONST_1() { 119 return 1; 120 } 121 122 public static int makeICONST_2() { 123 return 2; 124 } 125 126 public static int makeICONST_3() { 127 return 3; 128 } 129 130 public static int makeICONST_4() { 131 return 4; 132 } 133 134 public static int makeICONST_5() { 135 return 5; 136 } 137 138 public static long makeLCONST_0() { 139 return 0L; 140 } 141 142 public static long makeLCONST_1() { 143 return 1L; 144 } 145 146 public static float makeFCONST_0() { 147 return 0F; 148 } 149 150 public static float makeFCONST_1() { 151 return 1F; 152 } 153 154 public static float makeFCONST_2() { 155 return 2F; 156 } 157 158 public static double makeDCONST_0() { 159 return 0D; 160 } 161 162 public static double makeDCONST_1() { 163 return 1D; 164 } 165 166 public static double makeDCONST_W() { 167 // ldc2_w 168 return Double.MAX_VALUE; 169 } 170 171 public static Object makeOBJECT() { 172 // aconst_null 173 return null; 174 } 175 176 public static byte makeBYTE() { 177 // bipush 178 return (byte) 0x7F; 179 } 180 181 public static short makeSHORT() { 182 // sipush 183 return (short) 0x7FFF; 184 } 185 186 public static char makeCHAR() { 187 // ldc 188 return (char) 0xFFFF; 189 } 190 191 public static boolean makeBOOLEAN() { 192 return true; 193 } 194 } 195 }