1 /* 2 * Copyright (c) 2015, 2019, 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 26 * @bug 8136421 27 * @requires vm.jvmci 28 * @library /test/lib / 29 * @library ../common/patches 30 * @ignore Not supported JVMCI API 31 * @modules java.base/jdk.internal.misc 32 * @modules java.base/jdk.internal.org.objectweb.asm 33 * java.base/jdk.internal.org.objectweb.asm.tree 34 * jdk.internal.vm.ci/jdk.vm.ci.hotspot 35 * jdk.internal.vm.ci/jdk.vm.ci.meta 36 * jdk.internal.vm.ci/jdk.vm.ci.code 37 * 38 * @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper 39 * @run main/othervm -Xbootclasspath/a:. 40 * -XX:+UnlockDiagnosticVMOptions 41 * -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI 42 * -XX:-UseJVMCICompiler 43 * compiler.jvmci.compilerToVM.GetConstantPoolTest 44 */ 45 package compiler.jvmci.compilerToVM; 46 47 import jdk.test.lib.Utils; 48 import compiler.jvmci.common.CTVMUtilities; 49 import compiler.jvmci.common.testcases.TestCase; 50 import jdk.vm.ci.hotspot.CompilerToVMHelper; 51 import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod; 52 import jdk.vm.ci.hotspot.HotSpotResolvedObjectType; 53 import jdk.vm.ci.meta.ConstantPool; 54 55 import java.lang.reflect.Field; 56 import java.lang.reflect.Executable; 57 58 /** 59 * Tests for jdk.vm.ci.hotspot.CompilerToVM::getConstantPool method 60 */ 61 public class GetConstantPoolTest { 62 63 public static void testMethod(Executable executable) { 64 test(CTVMUtilities.getResolvedMethod(executable)); 65 } 66 67 public static void testClass(Class cls) { 68 HotSpotResolvedObjectType type = CompilerToVMHelper 69 .lookupTypeHelper(Utils.toJVMTypeSignature(cls), 70 GetConstantPoolTest.class, /* resolve = */ true); 71 test(type); 72 } 73 74 private static void test(Object object) { 75 ConstantPool cp = CompilerToVMHelper.getConstantPool(object); 76 System.out.println(object + " -> " + cp); 77 } 78 79 public static void main(String[] args) { 80 TestCase.getAllClasses().forEach(GetConstantPoolTest::testClass); 81 TestCase.getAllExecutables().forEach(GetConstantPoolTest::testMethod); 82 testNull(); 83 testObject(); 84 } 85 86 private static void testNull() { 87 try { 88 Object cp = CompilerToVMHelper.getConstantPool(null); 89 throw new AssertionError("Test OBJECT." 90 + " Expected IllegalArgumentException has not been caught"); 91 } catch (NullPointerException npe) { 92 // expected 93 } 94 } 95 private static void testObject() { 96 try { 97 Object cp = CompilerToVMHelper.getConstantPool(new Object()); 98 throw new AssertionError("Test OBJECT." 99 + " Expected IllegalArgumentException has not been caught"); 100 } catch (IllegalArgumentException iae) { 101 // expected 102 } 103 } 104 }