< prev index next >

test/compiler/jvmci/compilerToVM/ResolveConstantInPoolTest.java

Print this page


   1 /*
   2  * Copyright (c) 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 
  25 /*
  26  * @test
  27  * @bug 8136421
  28  * @requires (os.simpleArch == "x64" | os.simpleArch == "sparcv9" | os.simpleArch == "aarch64")
  29  * @library /testlibrary /test/lib /
  30  * @compile ../common/CompilerToVMHelper.java
  31  * @build compiler.jvmci.compilerToVM.ResolveConstantInPoolTest
  32  * @run main ClassFileInstaller jdk.vm.ci.hotspot.CompilerToVMHelper
  33  * @run main/othervm -Xbootclasspath/a:.
  34  *                   -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI



  35  *                   compiler.jvmci.compilerToVM.ResolveConstantInPoolTest
  36  */
  37 
  38 package compiler.jvmci.compilerToVM;
  39 




  40 import java.lang.invoke.MethodHandle;
  41 import java.lang.invoke.MethodType;
  42 import java.util.HashMap;
  43 import java.util.Map;
  44 import jdk.vm.ci.hotspot.CompilerToVMHelper;
  45 import jdk.test.lib.Asserts;
  46 import sun.reflect.ConstantPool;

  47 
  48 /**
  49  * Test for {@code compiler.jvmci.CompilerToVM.resolveConstantInPool} method
  50  */
  51 public class ResolveConstantInPoolTest {
  52 



  53     public static void main(String[] args) throws Exception {
  54         Map<ConstantPoolTestsHelper.ConstantTypes,
  55                 ConstantPoolTestCase.Validator> typeTests = new HashMap<>(2);
  56         typeTests.put(ConstantPoolTestsHelper.ConstantTypes.CONSTANT_METHODHANDLE,
  57                 ResolveConstantInPoolTest::validateMethodHandle);
  58         typeTests.put(ConstantPoolTestsHelper.ConstantTypes.CONSTANT_METHODTYPE,
  59                 ResolveConstantInPoolTest::validateMethodType);
  60         ConstantPoolTestCase testCase = new ConstantPoolTestCase(typeTests);
  61         testCase.test();











  62     }
  63 
  64     private static void validateMethodHandle(
  65             jdk.vm.ci.meta.ConstantPool constantPoolCTVM,
  66             ConstantPool constantPoolSS,
  67             ConstantPoolTestsHelper.DummyClasses dummyClass, int index) {
  68         Object constantInPool = CompilerToVMHelper
  69                 .resolveConstantInPool(constantPoolCTVM, index);

  70         if (!(constantInPool instanceof MethodHandle)) {
  71             String msg = String.format(
  72                     "Wrong constant pool entry accessed by index"
  73                             + " %d: %s, but should be subclass of %s",
  74                     index + 1, constantInPool.getClass(),

  75                     MethodHandle.class.getName());
  76             throw new AssertionError(msg);
  77         }
  78     }
  79 
  80     private static void validateMethodType(
  81             jdk.vm.ci.meta.ConstantPool constantPoolCTVM,
  82             ConstantPool constantPoolSS,
  83             ConstantPoolTestsHelper.DummyClasses dummyClass, int index) {
  84         Object constantInPool = CompilerToVMHelper
  85                 .resolveConstantInPool(constantPoolCTVM, index);

  86         Class mtToVerify = constantInPool.getClass();
  87         Class mtToRefer = MethodType.class;
  88         String msg = String.format("Wrong %s accessed by constant pool index"
  89                             + " %d: %s, but should be %s", "method type class",
  90                             index, mtToVerify, mtToRefer);
  91         Asserts.assertEQ(mtToRefer, mtToVerify, msg);
  92     }
  93 }
   1 /*
   2  * Copyright (c) 2015, 2016, 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 /*
  26  * @test
  27  * @bug 8136421
  28  * @requires (os.simpleArch == "x64" | os.simpleArch == "sparcv9" | os.simpleArch == "aarch64")
  29  * @library /testlibrary /test/lib /
  30  * @compile ../common/CompilerToVMHelper.java
  31  * @build sun.hotspot.WhiteBox
  32  *        compiler.jvmci.compilerToVM.ResolveConstantInPoolTest
  33  * @run main ClassFileInstaller sun.hotspot.WhiteBox
  34  *                              sun.hotspot.WhiteBox$WhiteBoxPermission
  35  *                              jdk.vm.ci.hotspot.CompilerToVMHelper
  36  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
  37  *                   -XX:+WhiteBoxAPI -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
  38  *                   compiler.jvmci.compilerToVM.ResolveConstantInPoolTest
  39  */
  40 
  41 package compiler.jvmci.compilerToVM;
  42 
  43 import compiler.jvmci.compilerToVM.ConstantPoolTestsHelper.DummyClasses;
  44 import compiler.jvmci.compilerToVM.ConstantPoolTestCase.ConstantTypes;
  45 import static compiler.jvmci.compilerToVM.ConstantPoolTestCase.ConstantTypes.*;
  46 import compiler.jvmci.compilerToVM.ConstantPoolTestCase.Validator;
  47 import java.lang.invoke.MethodHandle;
  48 import java.lang.invoke.MethodType;
  49 import java.util.HashMap;
  50 import java.util.Map;

  51 import jdk.test.lib.Asserts;
  52 import jdk.vm.ci.hotspot.CompilerToVMHelper;
  53 import jdk.vm.ci.meta.ConstantPool;
  54 
  55 /**
  56  * Test for {@code jdk.vm.ci.hotspot.CompilerToVM.resolveConstantInPool} method
  57  */
  58 public class ResolveConstantInPoolTest {
  59 
  60     private static final String NOT_NULL_MSG
  61             = "Object returned by resolveConstantInPool method should not be null";
  62 
  63     public static void main(String[] args) throws Exception {
  64         Map<ConstantTypes, Validator> typeTests = new HashMap<>();
  65         typeTests.put(CONSTANT_METHODHANDLE, ResolveConstantInPoolTest::validateMethodHandle);
  66         typeTests.put(CONSTANT_METHODTYPE, ResolveConstantInPoolTest::validateMethodType);



  67         ConstantPoolTestCase testCase = new ConstantPoolTestCase(typeTests);
  68         testCase.test();
  69         // The next "Class.forName" and repeating "testCase.test()"
  70         // are here for the following reason.
  71         // The first test run is without dummy class initialization,
  72         // which means no constant pool cache exists.
  73         // The second run is with initialized class (with constant pool cache available).
  74         // Some CompilerToVM methods require different input
  75         // depending on whether CP cache exists or not.
  76         for (DummyClasses dummy : DummyClasses.values()) {
  77             Class.forName(dummy.klass.getName());
  78         }
  79         testCase.test();
  80     }
  81 
  82     private static void validateMethodHandle(ConstantPool constantPoolCTVM,
  83                                              ConstantTypes cpType,
  84                                              DummyClasses dummyClass,
  85                                              int index) {
  86         Object constantInPool = CompilerToVMHelper.resolveConstantInPool(constantPoolCTVM, index);
  87         String msg = String.format("%s for index %d", NOT_NULL_MSG, index);
  88         Asserts.assertNotNull(constantInPool, msg);
  89         if (!(constantInPool instanceof MethodHandle)) {
  90             msg = String.format("Wrong constant pool entry accessed by index"

  91                                         + " %d: %s, but should be subclass of %s",
  92                                 index,
  93                                 constantInPool.getClass(),
  94                                 MethodHandle.class.getName());
  95             throw new AssertionError(msg);
  96         }
  97     }
  98 
  99     private static void validateMethodType(ConstantPool constantPoolCTVM,
 100                                            ConstantTypes cpType,
 101                                            DummyClasses dummyClass,
 102                                            int index) {
 103         Object constantInPool = CompilerToVMHelper.resolveConstantInPool(constantPoolCTVM, index);
 104         String msg = String.format("%s for index %d", NOT_NULL_MSG, index);
 105         Asserts.assertNotNull(constantInPool, msg);
 106         Class mtToVerify = constantInPool.getClass();
 107         Class mtToRefer = MethodType.class;
 108         msg = String.format("Wrong method type class accessed by"
 109                                     + " constant pool index %d",
 110                             index);
 111         Asserts.assertEQ(mtToRefer, mtToVerify, msg);
 112     }
 113 }
< prev index next >