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 package org.graalvm.compiler.hotspot.test; 25 26 import static org.graalvm.compiler.test.JLModule.uncheckedAddExports; 27 28 import java.lang.reflect.Method; 29 30 import org.graalvm.compiler.core.test.GraalCompilerTest; 31 import org.graalvm.compiler.debug.Debug; 32 import org.graalvm.compiler.debug.Debug.Scope; 33 import org.graalvm.compiler.graph.Node; 34 import org.graalvm.compiler.nodes.Invoke; 35 import org.graalvm.compiler.nodes.StructuredGraph; 36 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions; 37 import org.graalvm.compiler.test.JLModule; 38 import org.junit.BeforeClass; 39 import org.junit.Test; 40 import org.objectweb.asm.ClassWriter; 41 import org.objectweb.asm.MethodVisitor; 42 import org.objectweb.asm.Opcodes; 43 44 import jdk.vm.ci.meta.ResolvedJavaMethod; 45 46 public class ConstantPoolSubstitutionsTests extends GraalCompilerTest { 47 48 public ConstantPoolSubstitutionsTests() { 49 exportPackage(JAVA_BASE, "jdk.internal.org.objectweb.asm"); 50 } 51 52 @SuppressWarnings("try") 53 protected StructuredGraph test(final String snippet) { 54 ResolvedJavaMethod method = getMetaAccess().lookupJavaMethod(getMethod(snippet)); 55 try (Scope s = Debug.scope("ConstantPoolSubstitutionsTests", method)) { 56 StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES); 57 compile(graph.method(), graph); 58 assertNotInGraph(graph, Invoke.class); 59 Debug.dump(Debug.BASIC_LEVEL, graph, snippet); 60 return graph; 61 } catch (Throwable e) { 62 throw Debug.handle(e); 63 } 64 } 65 66 protected static StructuredGraph assertNotInGraph(StructuredGraph graph, Class<?> clazz) { 67 for (Node node : graph.getNodes()) { 68 if (clazz.isInstance(node)) { 69 fail(node.toString()); 70 } 71 } 72 return graph; 73 } 74 75 private static Object getConstantPoolForObject() { 76 String miscPackage = Java8OrEarlier ? "sun.misc" : "jdk.internal.misc"; 77 try { 78 Class<?> sharedSecretsClass = Class.forName(miscPackage + ".SharedSecrets"); 79 Class<?> javaLangAccessClass = Class.forName(miscPackage + ".JavaLangAccess"); 80 Object jla = sharedSecretsClass.getDeclaredMethod("getJavaLangAccess").invoke(null); 81 return javaLangAccessClass.getDeclaredMethod("getConstantPool", Class.class).invoke(jla, Object.class); 82 } catch (Exception e) { | 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 package org.graalvm.compiler.hotspot.test; 25 26 import static org.graalvm.compiler.test.JLModule.uncheckedAddExports; 27 28 import java.lang.reflect.Method; 29 30 import org.graalvm.compiler.core.test.GraalCompilerTest; 31 import org.graalvm.compiler.debug.DebugContext; 32 import org.graalvm.compiler.graph.Node; 33 import org.graalvm.compiler.nodes.Invoke; 34 import org.graalvm.compiler.nodes.StructuredGraph; 35 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions; 36 import org.graalvm.compiler.test.JLModule; 37 import org.junit.BeforeClass; 38 import org.junit.Test; 39 import org.objectweb.asm.ClassWriter; 40 import org.objectweb.asm.MethodVisitor; 41 import org.objectweb.asm.Opcodes; 42 43 import jdk.vm.ci.meta.ResolvedJavaMethod; 44 45 public class ConstantPoolSubstitutionsTests extends GraalCompilerTest { 46 47 public ConstantPoolSubstitutionsTests() { 48 exportPackage(JAVA_BASE, "jdk.internal.org.objectweb.asm"); 49 } 50 51 @SuppressWarnings("try") 52 protected StructuredGraph test(final String snippet) { 53 ResolvedJavaMethod method = getMetaAccess().lookupJavaMethod(getMethod(snippet)); 54 DebugContext debug = getDebugContext(); 55 try (DebugContext.Scope s = debug.scope("ConstantPoolSubstitutionsTests", method)) { 56 StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES); 57 compile(graph.method(), graph); 58 assertNotInGraph(graph, Invoke.class); 59 debug.dump(DebugContext.BASIC_LEVEL, graph, snippet); 60 return graph; 61 } catch (Throwable e) { 62 throw debug.handle(e); 63 } 64 } 65 66 protected static StructuredGraph assertNotInGraph(StructuredGraph graph, Class<?> clazz) { 67 for (Node node : graph.getNodes()) { 68 if (clazz.isInstance(node)) { 69 fail(node.toString()); 70 } 71 } 72 return graph; 73 } 74 75 private static Object getConstantPoolForObject() { 76 String miscPackage = Java8OrEarlier ? "sun.misc" : "jdk.internal.misc"; 77 try { 78 Class<?> sharedSecretsClass = Class.forName(miscPackage + ".SharedSecrets"); 79 Class<?> javaLangAccessClass = Class.forName(miscPackage + ".JavaLangAccess"); 80 Object jla = sharedSecretsClass.getDeclaredMethod("getJavaLangAccess").invoke(null); 81 return javaLangAccessClass.getDeclaredMethod("getConstantPool", Class.class).invoke(jla, Object.class); 82 } catch (Exception e) { |