< prev index next >
src/jdk.jfr/share/classes/jdk/jfr/internal/SecuritySupport.java
Print this page
*** 29,38 ****
--- 29,39 ----
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;
import java.io.Reader;
+ import java.lang.invoke.MethodHandles;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.ReflectPermission;
import java.nio.channels.FileChannel;
*** 69,78 ****
--- 70,80 ----
* Contains JFR code that does
* {@link AccessController#doPrivileged(PrivilegedAction)}
*/
public final class SecuritySupport {
private final static Unsafe unsafe = Unsafe.getUnsafe();
+ private final static MethodHandles.Lookup LOOKUP = MethodHandles.lookup();
private final static Module JFR_MODULE = Event.class.getModule();
public final static SafePath JFC_DIRECTORY = getPathInProperty("java.home", "lib/jfr");
static final SafePath USER_HOME = getPathInProperty("user.home", null);
static final SafePath JAVA_IO_TMPDIR = getPathInProperty("java.io.tmpdir", null);
*** 379,390 ****
static void ensureClassIsInitialized(Class<?> clazz) {
unsafe.ensureClassInitialized(clazz);
}
! static Class<?> defineClass(String name, byte[] bytes, ClassLoader classLoader) {
! return unsafe.defineClass(name, bytes, 0, bytes.length, classLoader, null);
}
static Thread createThreadWitNoPermissions(String threadName, Runnable runnable) {
return doPrivilegedWithReturn(() -> new Thread(runnable, threadName), new Permission[0]);
}
--- 381,401 ----
static void ensureClassIsInitialized(Class<?> clazz) {
unsafe.ensureClassInitialized(clazz);
}
! static Class<?> defineClass(Class<?> lookupClass, byte[] bytes) {
! return AccessController.doPrivileged(new PrivilegedAction<>() {
! @Override
! public Class<?> run() {
! try {
! return MethodHandles.privateLookupIn(lookupClass, LOOKUP).defineClass(bytes);
! } catch (IllegalAccessException e) {
! throw new InternalError(e);
! }
! }
! });
}
static Thread createThreadWitNoPermissions(String threadName, Runnable runnable) {
return doPrivilegedWithReturn(() -> new Thread(runnable, threadName), new Permission[0]);
}
< prev index next >