< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/ConstantPoolSubstitutionsTests.java

Print this page
rev 51958 : 8211122: Reduce the number of internal classes made accessible to jdk.unsupported
Reviewed-by: alanb, dfuchs, kvn
   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  */


  58             StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
  59             compile(graph.method(), graph);
  60             assertNotInGraph(graph, Invoke.class);
  61             debug.dump(DebugContext.BASIC_LEVEL, graph, snippet);
  62             return graph;
  63         } catch (Throwable e) {
  64             throw debug.handle(e);
  65         }
  66     }
  67 
  68     protected static StructuredGraph assertNotInGraph(StructuredGraph graph, Class<?> clazz) {
  69         for (Node node : graph.getNodes()) {
  70             if (clazz.isInstance(node)) {
  71                 fail(node.toString());
  72             }
  73         }
  74         return graph;
  75     }
  76 
  77     private static Object getConstantPoolForObject() {
  78         String miscPackage = Java8OrEarlier ? "sun.misc" : "jdk.internal.misc";

  79         try {
  80             Class<?> sharedSecretsClass = Class.forName(miscPackage + ".SharedSecrets");
  81             Class<?> javaLangAccessClass = Class.forName(miscPackage + ".JavaLangAccess");
  82             Object jla = sharedSecretsClass.getDeclaredMethod("getJavaLangAccess").invoke(null);
  83             return javaLangAccessClass.getDeclaredMethod("getConstantPool", Class.class).invoke(jla, Object.class);
  84         } catch (Exception e) {
  85             throw new AssertionError(e);
  86         }
  87     }
  88 
  89     /**
  90      * Get the test methods from the generated class.
  91      */
  92     @Override
  93     protected Method getMethod(String methodName) {
  94         Class<?> cl;
  95         try {
  96             cl = LOADER.findClass(AsmLoader.NAME);
  97             addExports(cl);
  98         } catch (ClassNotFoundException e) {
  99             throw new AssertionError(e);
 100         }
 101         return getMethod(cl, methodName);
 102     }
 103 
 104     @BeforeClass
 105     public static void beforeClass() {
 106         addExports(AsmLoader.class);
 107     }
 108 
 109     /**
 110      * This test uses some API hidden by the JDK9 module system.
 111      */
 112     private static void addExports(Class<?> c) {
 113         if (!Java8OrEarlier) {
 114             Object javaBaseModule = JLModule.fromClass(String.class);
 115             Object cModule = JLModule.fromClass(c);
 116             uncheckedAddExports(javaBaseModule, "jdk.internal.reflect", cModule);
 117             uncheckedAddExports(javaBaseModule, "jdk.internal.misc", cModule);



 118         }
 119     }
 120 
 121     @Test
 122     public void testGetSize() {
 123         Object cp = getConstantPoolForObject();
 124         test("getSize", cp);
 125     }
 126 
 127     @Test
 128     public void testGetIntAt() {
 129         test("getIntAt");
 130     }
 131 
 132     @Test
 133     public void testGetLongAt() {
 134         test("getLongAt");
 135     }
 136 
 137     @Test


   1 /*
   2  * Copyright (c) 2015, 2018, 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  */


  58             StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
  59             compile(graph.method(), graph);
  60             assertNotInGraph(graph, Invoke.class);
  61             debug.dump(DebugContext.BASIC_LEVEL, graph, snippet);
  62             return graph;
  63         } catch (Throwable e) {
  64             throw debug.handle(e);
  65         }
  66     }
  67 
  68     protected static StructuredGraph assertNotInGraph(StructuredGraph graph, Class<?> clazz) {
  69         for (Node node : graph.getNodes()) {
  70             if (clazz.isInstance(node)) {
  71                 fail(node.toString());
  72             }
  73         }
  74         return graph;
  75     }
  76 
  77     private static Object getConstantPoolForObject() {
  78         String miscPackage = Java8OrEarlier ? "sun.misc"
  79             : (Java11OrEarlier ? "jdk.internal.misc" : "jdk.internal.access");
  80         try {
  81             Class<?> sharedSecretsClass = Class.forName(miscPackage + ".SharedSecrets");
  82             Class<?> javaLangAccessClass = Class.forName(miscPackage + ".JavaLangAccess");
  83             Object jla = sharedSecretsClass.getDeclaredMethod("getJavaLangAccess").invoke(null);
  84             return javaLangAccessClass.getDeclaredMethod("getConstantPool", Class.class).invoke(jla, Object.class);
  85         } catch (Exception e) {
  86             throw new AssertionError(e);
  87         }
  88     }
  89 
  90     /**
  91      * Get the test methods from the generated class.
  92      */
  93     @Override
  94     protected Method getMethod(String methodName) {
  95         Class<?> cl;
  96         try {
  97             cl = LOADER.findClass(AsmLoader.NAME);
  98             addExports(cl);
  99         } catch (ClassNotFoundException e) {
 100             throw new AssertionError(e);
 101         }
 102         return getMethod(cl, methodName);
 103     }
 104 
 105     @BeforeClass
 106     public static void beforeClass() {
 107         addExports(AsmLoader.class);
 108     }
 109 
 110     /**
 111      * This test uses some API hidden by the JDK9 module system.
 112      */
 113     private static void addExports(Class<?> c) {
 114         if (!Java8OrEarlier) {
 115             Object javaBaseModule = JLModule.fromClass(String.class);
 116             Object cModule = JLModule.fromClass(c);
 117             uncheckedAddExports(javaBaseModule, "jdk.internal.reflect", cModule);
 118             if (Java11OrEarlier)
 119                 uncheckedAddExports(javaBaseModule, "jdk.internal.misc", cModule);
 120             else
 121                 uncheckedAddExports(javaBaseModule, "jdk.internal.access", cModule);
 122         }
 123     }
 124 
 125     @Test
 126     public void testGetSize() {
 127         Object cp = getConstantPoolForObject();
 128         test("getSize", cp);
 129     }
 130 
 131     @Test
 132     public void testGetIntAt() {
 133         test("getIntAt");
 134     }
 135 
 136     @Test
 137     public void testGetLongAt() {
 138         test("getLongAt");
 139     }
 140 
 141     @Test


< prev index next >