changeset 6249:448626eae40d jdk7u12-b01

8000989: smaller code changes to make future JSR 292 backports easier Reviewed-by: jrose
author twisti
date Fri, 19 Oct 2012 16:49:25 -0700
parents 93ec22695111
children 173091eea32d 0b7293b9e964
files src/share/classes/java/lang/invoke/BoundMethodHandle.java src/share/classes/java/lang/invoke/CallSite.java src/share/classes/java/lang/invoke/DirectMethodHandle.java src/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java src/share/classes/java/lang/invoke/Invokers.java src/share/classes/java/lang/invoke/LambdaForm.java src/share/classes/java/lang/invoke/MemberName.java src/share/classes/java/lang/invoke/MethodHandle.java src/share/classes/java/lang/invoke/MethodHandleImpl.java src/share/classes/java/lang/invoke/MethodHandleStatics.java src/share/classes/sun/invoke/util/ValueConversions.java test/java/lang/invoke/BigArityTest.java test/java/lang/invoke/PrivateInvokeTest.java
diffstat 13 files changed, 65 insertions(+), 50 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/lang/invoke/BoundMethodHandle.java	Tue Aug 28 14:57:43 2012 -0700
+++ b/src/share/classes/java/lang/invoke/BoundMethodHandle.java	Fri Oct 19 16:49:25 2012 -0700
@@ -79,7 +79,7 @@
             default : throw new InternalError("unexpected xtype: " + xtype);
             }
         } catch (Throwable t) {
-            throw new InternalError(t);
+            throw newInternalError(t);
         }
     }
 
@@ -97,7 +97,7 @@
             case 'D': return cloneExtendD(type, form, (double) x);
             }
         } catch (Throwable t) {
-            throw new InternalError(t);
+            throw newInternalError(t);
         }
         throw new InternalError("unexpected type: " + xtype);
     }
@@ -115,7 +115,7 @@
         try {
              return clone(srcType, form);
          } catch (Throwable t) {
-             throw new InternalError(t);
+             throw newInternalError(t);
          }
     }
 
@@ -124,7 +124,7 @@
         try {
              return clone(newType, form.permuteArguments(1, reorder, basicTypes(newType.parameterList())));
          } catch (Throwable t) {
-             throw new InternalError(t);
+             throw newInternalError(t);
          }
     }
 
@@ -166,7 +166,7 @@
             case 'J': return argJ(i);
             }
         } catch (Throwable ex) {
-            throw new InternalError(ex);
+            throw newInternalError(ex);
         }
         throw new InternalError("unexpected type: " + speciesData().types+"."+i);
     }
@@ -192,7 +192,7 @@
         try {
             return (MethodHandle) argL(0);
         } catch (Throwable ex) {
-            throw new InternalError(ex);
+            throw newInternalError(ex);
         }
     }
 
@@ -464,7 +464,7 @@
                     }
                 }
             } catch (Throwable e) {
-                throw new InternalError(e);
+                throw newInternalError(e);
             }
 
             for (SpeciesData d : CACHE.values()) {
@@ -748,7 +748,7 @@
             try {
                 return LOOKUP.findGetter(cbmhClass, fieldName, fieldType);
             } catch (NoSuchFieldException | IllegalAccessException e) {
-                throw new InternalError(e);
+                throw newInternalError(e);
             }
         }
 
@@ -776,7 +776,7 @@
                 Field F_SPECIES_DATA = cbmh.getDeclaredField("SPECIES_DATA");
                 return (SpeciesData) F_SPECIES_DATA.get(null);
             } catch (ReflectiveOperationException ex) {
-                throw new InternalError(ex);
+                throw newInternalError(ex);
             }
         }
 
@@ -802,7 +802,7 @@
             try {
                 return linkConstructor(LOOKUP.findConstructor(cbmh, MethodType.fromMethodDescriptorString(makeSignature(types, true), null)));
             } catch (NoSuchMethodException | IllegalAccessException | IllegalArgumentException | TypeNotPresentException e) {
-                throw new InternalError(e);
+                throw newInternalError(e);
             }
         }
 
@@ -833,7 +833,7 @@
                 linkerMN = MemberName.getFactory().resolveOrFail(REF_invokeStatic, linkerMN, null, NoSuchMethodException.class);
                 assert(linkerMN.isStatic());
             } catch (ReflectiveOperationException ex) {
-                throw new InternalError(ex);
+                throw newInternalError(ex);
             }
             // extend arguments array
             Object[] newArgs = Arrays.copyOf(initName.arguments, initName.arguments.length + 1);
--- a/src/share/classes/java/lang/invoke/CallSite.java	Tue Aug 28 14:57:43 2012 -0700
+++ b/src/share/classes/java/lang/invoke/CallSite.java	Fri Oct 19 16:49:25 2012 -0700
@@ -221,8 +221,8 @@
         try {
             GET_TARGET = IMPL_LOOKUP.
                 findVirtual(CallSite.class, "getTarget", MethodType.methodType(MethodHandle.class));
-        } catch (ReflectiveOperationException ignore) {
-            throw new InternalError();
+        } catch (ReflectiveOperationException e) {
+            throw newInternalError(e);
         }
     }
 
--- a/src/share/classes/java/lang/invoke/DirectMethodHandle.java	Tue Aug 28 14:57:43 2012 -0700
+++ b/src/share/classes/java/lang/invoke/DirectMethodHandle.java	Fri Oct 19 16:49:25 2012 -0700
@@ -218,7 +218,7 @@
         try {
             linker = IMPL_NAMES.resolveOrFail(REF_invokeStatic, linker, null, NoSuchMethodException.class);
         } catch (ReflectiveOperationException ex) {
-            throw new InternalError(ex);
+            throw newInternalError(ex);
         }
         final int DMH_THIS    = 0;
         final int ARG_BASE    = 1;
@@ -554,7 +554,7 @@
         try {
             linker = IMPL_NAMES.resolveOrFail(REF_invokeVirtual, linker, null, NoSuchMethodException.class);
         } catch (ReflectiveOperationException ex) {
-            throw new InternalError(ex);
+            throw newInternalError(ex);
         }
 
         // What is the external type of the lambda form?
@@ -653,7 +653,7 @@
                 nf.resolve();
             }
         } catch (ReflectiveOperationException ex) {
-            throw new InternalError(ex);
+            throw newInternalError(ex);
         }
     }
 }
--- a/src/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java	Tue Aug 28 14:57:43 2012 -0700
+++ b/src/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java	Fri Oct 19 16:49:25 2012 -0700
@@ -138,7 +138,7 @@
                 DUMP_CLASS_FILES_DIR = dumpDir;
                 System.out.println("Dumping class files to "+DUMP_CLASS_FILES_DIR+"/...");
             } catch (Exception e) {
-                throw new InternalError(e);
+                throw newInternalError(e);
             }
         } else {
             DUMP_CLASS_FILES_COUNTERS = null;
@@ -162,7 +162,7 @@
                         file.close();
                         return null;
                     } catch (IOException ex) {
-                        throw new InternalError(ex);
+                        throw newInternalError(ex);
                     }
                 }
             });
@@ -279,7 +279,7 @@
         try {
             member = MEMBERNAME_FACTORY.resolveOrFail(REF_invokeStatic, member, HOST_CLASS, ReflectiveOperationException.class);
         } catch (ReflectiveOperationException e) {
-            throw new InternalError(e);
+            throw newInternalError(e);
         }
         //System.out.println("resolveInvokerMember => "+member);
         return member;
--- a/src/share/classes/java/lang/invoke/Invokers.java	Tue Aug 28 14:57:43 2012 -0700
+++ b/src/share/classes/java/lang/invoke/Invokers.java	Fri Oct 19 16:49:25 2012 -0700
@@ -27,6 +27,7 @@
 
 import java.util.Arrays;
 import sun.invoke.empty.Empty;
+import static java.lang.invoke.MethodHandleStatics.*;
 import static java.lang.invoke.MethodHandleNatives.Constants.*;
 import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
 import static java.lang.invoke.LambdaForm.*;
@@ -128,9 +129,8 @@
         try {
             //Lookup.findVirtual(MethodHandle.class, name, type);
             return IMPL_LOOKUP.resolveOrFail(REF_invokeVirtual, MethodHandle.class, name, type);
-
         } catch (ReflectiveOperationException ex) {
-            throw new InternalError("JVM cannot find invoker for "+type);
+            throw newInternalError("JVM cannot find invoker for "+type, ex);
         }
     }
 
@@ -176,7 +176,7 @@
                     .findVirtual(MethodHandle.class, "asSpreader",
                         MethodType.methodType(MethodHandle.class, Class.class, int.class));
             } catch (ReflectiveOperationException ex) {
-                throw new InternalError(ex);
+                throw newInternalError(ex);
             }
             makeSpreader = MethodHandles.insertArguments(makeSpreader, 1, Object[].class, spreadArgCount);
             vaInvoker = MethodHandles.filterArgument(arrayInvoker, 0, makeSpreader);
@@ -215,7 +215,7 @@
                     .findStatic(CallSite.class, "uninitializedCallSite",
                                 MethodType.methodType(Empty.class));
             } catch (ReflectiveOperationException ex) {
-                throw new InternalError(ex);
+                throw newInternalError(ex);
             }
         }
         invoker = MethodHandles.explicitCastArguments(invoker, MethodType.methodType(targetType.returnType()));
@@ -389,7 +389,7 @@
             form.genericInvoker = gamh;
             return gamh;
         } catch (Exception ex) {
-            throw new InternalError("Exception while resolving inexact invoke", ex);
+            throw newInternalError("Exception while resolving inexact invoke", ex);
         }
     }
 
@@ -456,7 +456,7 @@
             NF_getCallSiteTarget.resolve();
             // bound
         } catch (ReflectiveOperationException ex) {
-            throw new InternalError(ex);
+            throw newInternalError(ex);
         }
     }
 
--- a/src/share/classes/java/lang/invoke/LambdaForm.java	Tue Aug 28 14:57:43 2012 -0700
+++ b/src/share/classes/java/lang/invoke/LambdaForm.java	Fri Oct 19 16:49:25 2012 -0700
@@ -457,7 +457,7 @@
             isCompiled = true;
             return vmentry;
         } catch (Error | Exception ex) {
-            throw new InternalError(this.toString(), ex);
+            throw newInternalError(this.toString(), ex);
         }
     }
 
@@ -1547,7 +1547,7 @@
             try {
                 zmem = IMPL_NAMES.resolveOrFail(REF_invokeStatic, zmem, null, NoSuchMethodException.class);
             } catch (IllegalAccessException|NoSuchMethodException ex) {
-                throw new InternalError(ex);
+                throw newInternalError(ex);
             }
             NamedFunction zcon = new NamedFunction(zmem);
             Name n = new Name(zcon).newIndex(0);
--- a/src/share/classes/java/lang/invoke/MemberName.java	Tue Aug 28 14:57:43 2012 -0700
+++ b/src/share/classes/java/lang/invoke/MemberName.java	Fri Oct 19 16:49:25 2012 -0700
@@ -558,7 +558,7 @@
         try {
             return (MemberName) super.clone();
         } catch (CloneNotSupportedException ex) {
-            throw new InternalError();
+            throw newInternalError(ex);
         }
      }
 
--- a/src/share/classes/java/lang/invoke/MethodHandle.java	Tue Aug 28 14:57:43 2012 -0700
+++ b/src/share/classes/java/lang/invoke/MethodHandle.java	Fri Oct 19 16:49:25 2012 -0700
@@ -1372,7 +1372,7 @@
             NF_reinvokerTarget = new LambdaForm.NamedFunction(MethodHandle.class
                 .getDeclaredMethod("reinvokerTarget"));
         } catch (ReflectiveOperationException ex) {
-            throw new InternalError(ex);
+            throw newInternalError(ex);
         }
     }
 
@@ -1397,7 +1397,7 @@
         try {
             FORM_OFFSET = UNSAFE.objectFieldOffset(MethodHandle.class.getDeclaredField("form"));
         } catch (ReflectiveOperationException ex) {
-            throw new InternalError(ex);
+            throw newInternalError(ex);
         }
     }
 }
--- a/src/share/classes/java/lang/invoke/MethodHandleImpl.java	Tue Aug 28 14:57:43 2012 -0700
+++ b/src/share/classes/java/lang/invoke/MethodHandleImpl.java	Fri Oct 19 16:49:25 2012 -0700
@@ -480,7 +480,7 @@
                     .getDeclaredMethod("checkSpreadArgument", Object.class, int.class));
             NF_checkSpreadArgument.resolve();
         } catch (ReflectiveOperationException ex) {
-            throw new InternalError(ex);
+            throw newInternalError(ex);
         }
     }
 
@@ -829,7 +829,7 @@
                 if (tramp.getClassLoader() == BindCaller.class.getClassLoader())
                     throw new RuntimeException(tramp.getName()+" class loader");
             } catch (Throwable ex) {
-                throw new InternalError(ex.toString());
+                throw newInternalError(ex);
             }
             C_Trampoline = tramp;
         }
@@ -865,7 +865,7 @@
                 MethodHandle vamh = prepareForInvoker(MH_checkCallerClass);
                 Object ok = bccInvoker.invokeExact(vamh, new Object[]{hostClass, bcc});
             } catch (Throwable ex) {
-                throw new InternalError(ex.toString());
+                throw newInternalError(ex);
             }
             return bccInvoker;
         }
@@ -902,7 +902,7 @@
                                 MethodType.methodType(boolean.class, Class.class, Class.class));
                 assert((boolean) MH_checkCallerClass.invokeExact(THIS_CLASS, THIS_CLASS));
             } catch (Throwable ex) {
-                throw new InternalError(ex.toString());
+                throw newInternalError(ex);
             }
         }
 
@@ -933,7 +933,7 @@
                             }
                             values[0] = bytes;
                         } catch (java.io.IOException ex) {
-                            throw new InternalError(ex.toString());
+                            throw newInternalError(ex);
                         }
                         return null;
                     }
--- a/src/share/classes/java/lang/invoke/MethodHandleStatics.java	Tue Aug 28 14:57:43 2012 -0700
+++ b/src/share/classes/java/lang/invoke/MethodHandleStatics.java	Fri Oct 19 16:49:25 2012 -0700
@@ -93,6 +93,16 @@
     }
 
     // handy shared exception makers (they simplify the common case code)
+    /*non-public*/ static InternalError newInternalError(String message, Throwable cause) {
+        InternalError e = new InternalError(message);
+        e.initCause(cause);
+        return e;
+    }
+    /*non-public*/ static InternalError newInternalError(Throwable cause) {
+        InternalError e = new InternalError();
+        e.initCause(cause);
+        return e;
+    }
     /*non-public*/ static RuntimeException newIllegalStateException(String message) {
         return new IllegalStateException(message);
     }
@@ -109,9 +119,7 @@
         return new IllegalArgumentException(message(message, obj, obj2));
     }
     /*non-public*/ static Error uncaughtException(Throwable ex) {
-        Error err = new InternalError("uncaught exception");
-        err.initCause(ex);
-        return err;
+        throw newInternalError("uncaught exception", ex);
     }
     static Error NYI() {
         throw new AssertionError("NYI");
--- a/src/share/classes/sun/invoke/util/ValueConversions.java	Tue Aug 28 14:57:43 2012 -0700
+++ b/src/share/classes/sun/invoke/util/ValueConversions.java	Fri Oct 19 16:49:25 2012 -0700
@@ -475,9 +475,7 @@
                     .findStatic(THIS_CLASS, "fillNewTypedArray",
                           MethodType.methodType(Object[].class, Object[].class, Integer.class, Object[].class));
         } catch (NoSuchMethodException | IllegalAccessException ex) {
-            Error err = new InternalError("uncaught exception");
-            err.initCause(ex);
-            throw err;
+            throw newInternalError("uncaught exception", ex);
         }
     }
 
@@ -491,9 +489,7 @@
                 COPY_AS_PRIMITIVE_ARRAY = IMPL_LOOKUP.findStatic(THIS_CLASS, "copyAsPrimitiveArray", MethodType.methodType(Object.class, Wrapper.class, Object[].class));
                 MAKE_LIST = IMPL_LOOKUP.findStatic(THIS_CLASS, "makeList", MethodType.methodType(List.class, Object[].class));
             } catch (ReflectiveOperationException ex) {
-                Error err = new InternalError("uncaught exception");
-                err.initCause(ex);
-                throw err;
+                throw newInternalError("uncaught exception", ex);
             }
         }
     }
@@ -537,9 +533,8 @@
                     }
                 });
             mh = IMPL_LOOKUP.unreflect(m);
-
         } catch (ReflectiveOperationException ex) {
-            throw new InternalError(ex);
+            throw newInternalError(ex);
         }
         COLLECT_ARGUMENTS = mh;
     }
@@ -1219,4 +1214,16 @@
     private static MethodHandle buildVarargsList(int nargs) {
         return MethodHandles.filterReturnValue(varargsArray(nargs), LazyStatics.MAKE_LIST);
     }
+
+    // handy shared exception makers (they simplify the common case code)
+    private static InternalError newInternalError(String message, Throwable cause) {
+        InternalError e = new InternalError(message);
+        e.initCause(cause);
+        return e;
+    }
+    private static InternalError newInternalError(Throwable cause) {
+        InternalError e = new InternalError();
+        e.initCause(cause);
+        return e;
+    }
 }
--- a/test/java/lang/invoke/BigArityTest.java	Tue Aug 28 14:57:43 2012 -0700
+++ b/test/java/lang/invoke/BigArityTest.java	Fri Oct 19 16:49:25 2012 -0700
@@ -70,7 +70,7 @@
                 MethodHandles.lookup().unreflect(
                     BigArityTest.class.getDeclaredMethod("hashArguments", Object[].class));
         } catch (ReflectiveOperationException ex) {
-            throw new InternalError(ex);
+            throw new Error(ex);
         }
     }
     static MethodHandle MH_hashArguments(int arity) {
--- a/test/java/lang/invoke/PrivateInvokeTest.java	Tue Aug 28 14:57:43 2012 -0700
+++ b/test/java/lang/invoke/PrivateInvokeTest.java	Fri Oct 19 16:49:25 2012 -0700
@@ -145,21 +145,21 @@
             MH_DEBUG_STRING = DIRECT_INVOKER_LOOKUP
                     .findVirtual(MethodHandle.class, "debugString", methodType(String.class));
         } catch (ReflectiveOperationException ex) {
-            throw new InternalError(ex);
+            throw new Error(ex);
         }
     }
     private Object internalMemberName(MethodHandle mh) {
         try {
             return MH_INTERNAL_MEMBER_NAME.invokeExact(mh);
         } catch (Throwable ex) {
-            throw new InternalError(ex);
+            throw new Error(ex);
         }
     }
     private String debugString(MethodHandle mh) {
         try {
             return (String) MH_DEBUG_STRING.invokeExact(mh);
         } catch (Throwable ex) {
-            throw new InternalError(ex);
+            throw new Error(ex);
         }
     }
     private static MethodHandle directInvoker(int refKind, MethodType mtype) {