src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/CustomizedBytecodePatternTest.java
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/CustomizedBytecodePatternTest.java Thu Oct 17 20:27:44 2019 +0100
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/CustomizedBytecodePatternTest.java Thu Oct 17 20:53:35 2019 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -24,14 +24,45 @@
package org.graalvm.compiler.core.test;
+import java.lang.invoke.MethodHandles;
+import java.lang.reflect.Method;
+import java.security.ProtectionDomain;
+
+import org.graalvm.compiler.serviceprovider.JavaVersionUtil;
import org.objectweb.asm.Opcodes;
+import sun.misc.Unsafe;
+
public abstract class CustomizedBytecodePatternTest extends GraalCompilerTest implements Opcodes {
protected Class<?> getClass(String className) throws ClassNotFoundException {
return new CachedLoader(CustomizedBytecodePatternTest.class.getClassLoader(), className).findClass(className);
}
+ /**
+ * @param className
+ * @param lookUp lookup object with boot class load capability (required for jdk 9 and above)
+ * @return loaded class
+ * @throws ClassNotFoundException
+ */
+ protected Class<?> getClassBL(String className, MethodHandles.Lookup lookUp) throws ClassNotFoundException {
+ byte[] gen = generateClass(className.replace('.', '/'));
+ Method defineClass = null;
+ Class<?> loadedClass = null;
+ try {
+ if (JavaVersionUtil.JAVA_SPEC <= 8) {
+ defineClass = Unsafe.class.getDeclaredMethod("defineClass", String.class, byte[].class, int.class, int.class, ClassLoader.class, ProtectionDomain.class);
+ loadedClass = (Class<?>) defineClass.invoke(UNSAFE, className, gen, 0, gen.length, null, null);
+ } else {
+ defineClass = MethodHandles.lookup().getClass().getDeclaredMethod("defineClass", byte[].class);
+ loadedClass = (Class<?>) defineClass.invoke(lookUp, gen);
+ }
+ } catch (Exception e) {
+ throw new ClassNotFoundException(className, e);
+ }
+ return loadedClass;
+ }
+
private class CachedLoader extends ClassLoader {
final String className;