jdk/src/share/classes/sun/misc/Unsafe.java
changeset 16906 44dfee24cb71
parent 14853 72f0bc58bb95
child 21851 f21f49c7c265
equal deleted inserted replaced
16905:0419f45c7761 16906:44dfee24cb71
    26 package sun.misc;
    26 package sun.misc;
    27 
    27 
    28 import java.security.*;
    28 import java.security.*;
    29 import java.lang.reflect.*;
    29 import java.lang.reflect.*;
    30 
    30 
       
    31 import sun.reflect.CallerSensitive;
       
    32 import sun.reflect.Reflection;
       
    33 
    31 
    34 
    32 /**
    35 /**
    33  * A collection of methods for performing low-level, unsafe operations.
    36  * A collection of methods for performing low-level, unsafe operations.
    34  * Although the class and all methods are public, use of this class is
    37  * Although the class and all methods are public, use of this class is
    35  * limited because only trusted code can obtain instances of it.
    38  * limited because only trusted code can obtain instances of it.
    78      *
    81      *
    79      * @exception  SecurityException  if a security manager exists and its
    82      * @exception  SecurityException  if a security manager exists and its
    80      *             <code>checkPropertiesAccess</code> method doesn't allow
    83      *             <code>checkPropertiesAccess</code> method doesn't allow
    81      *             access to the system properties.
    84      *             access to the system properties.
    82      */
    85      */
       
    86     @CallerSensitive
    83     public static Unsafe getUnsafe() {
    87     public static Unsafe getUnsafe() {
    84         Class<?> cc = sun.reflect.Reflection.getCallerClass(2);
    88         Class<?> caller = Reflection.getCallerClass();
    85         if (!VM.isSystemDomainLoader(cc.getClassLoader()))
    89         if (!VM.isSystemDomainLoader(caller.getClassLoader()))
    86             throw new SecurityException("Unsafe");
    90             throw new SecurityException("Unsafe");
    87         return theUnsafe;
    91         return theUnsafe;
    88     }
    92     }
    89 
    93 
    90     /// peek and poke operations
    94     /// peek and poke operations
   815      */
   819      */
   816     public native Class<?> defineClass(String name, byte[] b, int off, int len,
   820     public native Class<?> defineClass(String name, byte[] b, int off, int len,
   817                                        ClassLoader loader,
   821                                        ClassLoader loader,
   818                                        ProtectionDomain protectionDomain);
   822                                        ProtectionDomain protectionDomain);
   819 
   823 
   820     public native Class<?> defineClass(String name, byte[] b, int off, int len);
       
   821 
       
   822     /**
   824     /**
   823      * Define a class but do not make it known to the class loader or system dictionary.
   825      * Define a class but do not make it known to the class loader or system dictionary.
   824      * <p>
   826      * <p>
   825      * For each CP entry, the corresponding CP patch must either be null or have
   827      * For each CP entry, the corresponding CP patch must either be null or have
   826      * the a format that matches its tag:
   828      * the a format that matches its tag: