src/java.base/share/classes/jdk/internal/reflect/ClassDefiner.java
changeset 52015 821bfc24d750
parent 47216 71c04702a3d5
child 52427 3c6aa484536c
equal deleted inserted replaced
52014:1aa9beac610e 52015:821bfc24d750
    25 
    25 
    26 package jdk.internal.reflect;
    26 package jdk.internal.reflect;
    27 
    27 
    28 import java.security.AccessController;
    28 import java.security.AccessController;
    29 import java.security.PrivilegedAction;
    29 import java.security.PrivilegedAction;
    30 import jdk.internal.misc.Unsafe;
       
    31 
    30 
    32 /** Utility class which assists in calling Unsafe.defineClass() by
    31 import jdk.internal.misc.JavaLangAccess;
       
    32 import jdk.internal.misc.SharedSecrets;
       
    33 
       
    34 /** Utility class which assists in calling defineClass() by
    33     creating a new class loader which delegates to the one needed in
    35     creating a new class loader which delegates to the one needed in
    34     order for proper resolution of the given bytecodes to occur. */
    36     order for proper resolution of the given bytecodes to occur. */
    35 
    37 
    36 class ClassDefiner {
    38 class ClassDefiner {
    37     static final Unsafe unsafe = Unsafe.getUnsafe();
    39     static final JavaLangAccess JLA = SharedSecrets.getJavaLangAccess();
    38 
    40 
    39     /** <P> We define generated code into a new class loader which
    41     /** <P> We define generated code into a new class loader which
    40       delegates to the defining loader of the target class. It is
    42       delegates to the defining loader of the target class. It is
    41       necessary for the VM to be able to resolve references to the
    43       necessary for the VM to be able to resolve references to the
    42       target class from the generated bytecodes, which could not occur
    44       target class from the generated bytecodes, which could not occur
    58             new PrivilegedAction<ClassLoader>() {
    60             new PrivilegedAction<ClassLoader>() {
    59                 public ClassLoader run() {
    61                 public ClassLoader run() {
    60                         return new DelegatingClassLoader(parentClassLoader);
    62                         return new DelegatingClassLoader(parentClassLoader);
    61                     }
    63                     }
    62                 });
    64                 });
    63         return unsafe.defineClass(name, bytes, off, len, newLoader, null);
    65         return JLA.defineClass(newLoader, name, bytes, null, "__ClassDefiner__");
    64     }
    66     }
    65 }
    67 }
    66 
    68 
    67 
    69 
    68 // NOTE: this class's name and presence are known to the virtual
    70 // NOTE: this class's name and presence are known to the virtual