src/java.base/share/classes/java/lang/invoke/MethodHandleStatics.java
changeset 59201 b24f4caa1411
parent 48826 c4d9d1b08e2e
equal deleted inserted replaced
59200:a686b67a59d9 59201:b24f4caa1411
    34  * This class consists exclusively of static names internal to the
    34  * This class consists exclusively of static names internal to the
    35  * method handle implementation.
    35  * method handle implementation.
    36  * Usage:  {@code import static java.lang.invoke.MethodHandleStatics.*}
    36  * Usage:  {@code import static java.lang.invoke.MethodHandleStatics.*}
    37  * @author John Rose, JSR 292 EG
    37  * @author John Rose, JSR 292 EG
    38  */
    38  */
    39 /*non-public*/ class MethodHandleStatics {
    39 /*non-public*/
       
    40 class MethodHandleStatics {
    40 
    41 
    41     private MethodHandleStatics() { }  // do not instantiate
    42     private MethodHandleStatics() { }  // do not instantiate
    42 
    43 
    43     static final Unsafe UNSAFE = Unsafe.getUnsafe();
    44     static final Unsafe UNSAFE = Unsafe.getUnsafe();
    44 
    45 
    93     }
    94     }
    94 
    95 
    95     /** Tell if any of the debugging switches are turned on.
    96     /** Tell if any of the debugging switches are turned on.
    96      *  If this is the case, it is reasonable to perform extra checks or save extra information.
    97      *  If this is the case, it is reasonable to perform extra checks or save extra information.
    97      */
    98      */
    98     /*non-public*/ static boolean debugEnabled() {
    99     /*non-public*/
       
   100     static boolean debugEnabled() {
    99         return (DEBUG_METHOD_HANDLE_NAMES |
   101         return (DEBUG_METHOD_HANDLE_NAMES |
   100                 DUMP_CLASS_FILES |
   102                 DUMP_CLASS_FILES |
   101                 TRACE_INTERPRETER |
   103                 TRACE_INTERPRETER |
   102                 TRACE_METHOD_LINKAGE |
   104                 TRACE_METHOD_LINKAGE |
   103                 LOG_LF_COMPILATION_FAILURE);
   105                 LOG_LF_COMPILATION_FAILURE);
   104     }
   106     }
   105 
   107 
   106     // handy shared exception makers (they simplify the common case code)
   108     // handy shared exception makers (they simplify the common case code)
   107     /*non-public*/ static InternalError newInternalError(String message) {
   109     /*non-public*/
       
   110     static InternalError newInternalError(String message) {
   108         return new InternalError(message);
   111         return new InternalError(message);
   109     }
   112     }
   110     /*non-public*/ static InternalError newInternalError(String message, Exception cause) {
   113     /*non-public*/
       
   114     static InternalError newInternalError(String message, Exception cause) {
   111         return new InternalError(message, cause);
   115         return new InternalError(message, cause);
   112     }
   116     }
   113     /*non-public*/ static InternalError newInternalError(Exception cause) {
   117     /*non-public*/
       
   118     static InternalError newInternalError(Exception cause) {
   114         return new InternalError(cause);
   119         return new InternalError(cause);
   115     }
   120     }
   116     /*non-public*/ static RuntimeException newIllegalStateException(String message) {
   121     /*non-public*/
       
   122     static RuntimeException newIllegalStateException(String message) {
   117         return new IllegalStateException(message);
   123         return new IllegalStateException(message);
   118     }
   124     }
   119     /*non-public*/ static RuntimeException newIllegalStateException(String message, Object obj) {
   125     /*non-public*/
       
   126     static RuntimeException newIllegalStateException(String message, Object obj) {
   120         return new IllegalStateException(message(message, obj));
   127         return new IllegalStateException(message(message, obj));
   121     }
   128     }
   122     /*non-public*/ static RuntimeException newIllegalArgumentException(String message) {
   129     /*non-public*/
       
   130     static RuntimeException newIllegalArgumentException(String message) {
   123         return new IllegalArgumentException(message);
   131         return new IllegalArgumentException(message);
   124     }
   132     }
   125     /*non-public*/ static RuntimeException newIllegalArgumentException(String message, Object obj) {
   133     /*non-public*/
       
   134     static RuntimeException newIllegalArgumentException(String message, Object obj) {
   126         return new IllegalArgumentException(message(message, obj));
   135         return new IllegalArgumentException(message(message, obj));
   127     }
   136     }
   128     /*non-public*/ static RuntimeException newIllegalArgumentException(String message, Object obj, Object obj2) {
   137     /*non-public*/
       
   138     static RuntimeException newIllegalArgumentException(String message, Object obj, Object obj2) {
   129         return new IllegalArgumentException(message(message, obj, obj2));
   139         return new IllegalArgumentException(message(message, obj, obj2));
   130     }
   140     }
   131     /** Propagate unchecked exceptions and errors, but wrap anything checked and throw that instead. */
   141     /** Propagate unchecked exceptions and errors, but wrap anything checked and throw that instead. */
   132     /*non-public*/ static Error uncaughtException(Throwable ex) {
   142     /*non-public*/
       
   143     static Error uncaughtException(Throwable ex) {
   133         if (ex instanceof Error)  throw (Error) ex;
   144         if (ex instanceof Error)  throw (Error) ex;
   134         if (ex instanceof RuntimeException)  throw (RuntimeException) ex;
   145         if (ex instanceof RuntimeException)  throw (RuntimeException) ex;
   135         throw new InternalError("uncaught exception", ex);
   146         throw new InternalError("uncaught exception", ex);
   136     }
   147     }
   137     private static String message(String message, Object obj) {
   148     private static String message(String message, Object obj) {
   140     }
   151     }
   141     private static String message(String message, Object obj, Object obj2) {
   152     private static String message(String message, Object obj, Object obj2) {
   142         if (obj != null || obj2 != null)  message = message + ": " + obj + ", " + obj2;
   153         if (obj != null || obj2 != null)  message = message + ": " + obj + ", " + obj2;
   143         return message;
   154         return message;
   144     }
   155     }
   145     /*non-public*/ static void rangeCheck2(int start, int end, int size) {
   156     /*non-public*/
       
   157     static void rangeCheck2(int start, int end, int size) {
   146         if (0 > start || start > end || end > size)
   158         if (0 > start || start > end || end > size)
   147             throw new IndexOutOfBoundsException(start+".."+end);
   159             throw new IndexOutOfBoundsException(start+".."+end);
   148     }
   160     }
   149     /*non-public*/ static int rangeCheck1(int index, int size) {
   161     /*non-public*/
       
   162     static int rangeCheck1(int index, int size) {
   150         if (0 > index || index >= size)
   163         if (0 > index || index >= size)
   151             throw new IndexOutOfBoundsException(index);
   164             throw new IndexOutOfBoundsException(index);
   152         return index;
   165         return index;
   153     }
   166     }
   154 }
   167 }