1 /* 2 * Copyright (c) 2014, 2023, 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 /** 25 * @test ConstantGettersTransitionsTest 26 * @summary Test the correctness of compilation level transitions for constant getters methods 27 * @library /test/lib / 28 * @modules java.base/jdk.internal.misc 29 * java.management 30 * 31 * @build jdk.test.whitebox.WhiteBox 32 * compiler.tiered.ConstantGettersTransitionsTest 33 * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox 34 * @run main/othervm/timeout=240 -Xmixed -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions 35 * -XX:+WhiteBoxAPI -XX:+TieredCompilation 36 * -XX:CompileCommand=compileonly,compiler.tiered.ConstantGettersTransitionsTest$ConstantGettersTestCase$TrivialMethods::* 37 * compiler.tiered.ConstantGettersTransitionsTest 38 */ 39 40 package compiler.tiered; 41 42 import compiler.whitebox.CompilerWhiteBoxTest; 43 import jtreg.SkippedException; 44 45 import java.lang.reflect.Executable; 46 import java.util.concurrent.Callable; 47 48 public class ConstantGettersTransitionsTest extends LevelTransitionTest { 49 public static void main(String[] args) { 50 if (CompilerWhiteBoxTest.skipOnTieredCompilation(false)) { 51 throw new SkippedException("Test isn't applicable for non-tiered mode"); 52 } 53 54 // run test cases 55 for (TestCase testCase : ConstantGettersTestCase.values()) { 56 new ConstantGettersTransitionsTest(testCase).runTest(); 57 } 58 } 59 60 @Override 61 protected boolean isTrivial() { 62 return true; 63 } 64 65 private ConstantGettersTransitionsTest(TestCase testCase) { 66 super(testCase); 67 } 68 69 private static enum ConstantGettersTestCase implements CompilerWhiteBoxTest.TestCase { 70 ICONST_M1, 71 ICONST_0, 72 ICONST_1, 73 ICONST_2, 74 ICONST_3, 75 ICONST_4, 76 ICONST_5, 77 LCONST_0, 78 LCONST_1, 79 FCONST_0, 80 FCONST_1, 81 FCONST_2, 82 DCONST_0, 83 DCONST_1, 84 DCONST_W, 85 BYTE, 86 SHORT, 87 CHAR; 88 89 private final Executable executable; 90 private final Callable<Integer> callable; 91 92 @Override 93 public Executable getExecutable() { 94 return executable; 95 } 96 97 @Override 98 public Callable<Integer> getCallable() { 99 return callable; 100 } 101 102 @Override 103 public boolean isOsr() { 104 return false; 105 } 106 107 private ConstantGettersTestCase() { 108 String name = "make" + this.name(); 109 this.executable = MethodHelper.getMethod(TrivialMethods.class, name); 110 this.callable = MethodHelper.getCallable(new TrivialMethods(), name); 111 } 112 113 /** 114 * Contains methods that load constants with certain types of bytecodes 115 * See JVMS 2.11.2. Load and Store Instructions 116 * Note that it doesn't have a method for ldc_w instruction 117 */ 118 private static class TrivialMethods { 119 public static int makeICONST_M1() { 120 return -1; 121 } 122 123 public static int makeICONST_0() { 124 return 0; 125 } 126 127 public static int makeICONST_1() { 128 return 1; 129 } 130 131 public static int makeICONST_2() { 132 return 2; 133 } 134 135 public static int makeICONST_3() { 136 return 3; 137 } 138 139 public static int makeICONST_4() { 140 return 4; 141 } 142 143 public static int makeICONST_5() { 144 return 5; 145 } 146 147 public static long makeLCONST_0() { 148 return 0L; 149 } 150 151 public static long makeLCONST_1() { 152 return 1L; 153 } 154 155 public static float makeFCONST_0() { 156 return 0F; 157 } 158 159 public static float makeFCONST_1() { 160 return 1F; 161 } 162 163 public static float makeFCONST_2() { 164 return 2F; 165 } 166 167 public static double makeDCONST_0() { 168 return 0D; 169 } 170 171 public static double makeDCONST_1() { 172 return 1D; 173 } 174 175 public static double makeDCONST_W() { 176 // ldc2_w 177 return Double.MAX_VALUE; 178 } 179 180 public static Object makeOBJECT() { 181 // aconst_null 182 return null; 183 } 184 185 public static byte makeBYTE() { 186 // bipush 187 return (byte) 0x7F; 188 } 189 190 public static short makeSHORT() { 191 // sipush 192 return (short) 0x7FFF; 193 } 194 195 public static char makeCHAR() { 196 // ldc 197 return (char) 0xFFFF; 198 } 199 200 public static boolean makeBOOLEAN() { 201 return true; 202 } 203 } 204 } 205 }