8000989: smaller code changes to make future JSR 292 backports easier

Reviewed-by: jrose
This commit is contained in:
Christian Thalinger 2012-10-19 17:04:35 -07:00
parent d9aab5025e
commit 01d0ba69ce
13 changed files with 52 additions and 39 deletions

View file

@ -27,6 +27,7 @@ package java.lang.invoke;
import java.util.Arrays; import java.util.Arrays;
import sun.invoke.empty.Empty; import sun.invoke.empty.Empty;
import static java.lang.invoke.MethodHandleStatics.*;
import static java.lang.invoke.MethodHandleNatives.Constants.*; import static java.lang.invoke.MethodHandleNatives.Constants.*;
import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP; import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
import static java.lang.invoke.LambdaForm.*; import static java.lang.invoke.LambdaForm.*;
@ -128,7 +129,6 @@ class Invokers {
try { try {
//Lookup.findVirtual(MethodHandle.class, name, type); //Lookup.findVirtual(MethodHandle.class, name, type);
return IMPL_LOOKUP.resolveOrFail(REF_invokeVirtual, MethodHandle.class, name, type); return IMPL_LOOKUP.resolveOrFail(REF_invokeVirtual, MethodHandle.class, name, type);
} catch (ReflectiveOperationException ex) { } catch (ReflectiveOperationException ex) {
throw newInternalError("JVM cannot find invoker for "+type, ex); throw newInternalError("JVM cannot find invoker for "+type, ex);
} }

View file

@ -93,6 +93,12 @@ import sun.misc.Unsafe;
} }
// handy shared exception makers (they simplify the common case code) // handy shared exception makers (they simplify the common case code)
/*non-public*/ static InternalError newInternalError(String message, Throwable cause) {
return new InternalError(message, cause);
}
/*non-public*/ static InternalError newInternalError(Throwable cause) {
return new InternalError(cause);
}
/*non-public*/ static RuntimeException newIllegalStateException(String message) { /*non-public*/ static RuntimeException newIllegalStateException(String message) {
return new IllegalStateException(message); return new IllegalStateException(message);
} }

View file

@ -527,7 +527,6 @@ public class ValueConversions {
MethodHandle.class, int.class, MethodHandle.class); MethodHandle.class, int.class, MethodHandle.class);
m.setAccessible(true); m.setAccessible(true);
mh = IMPL_LOOKUP.unreflect(m); mh = IMPL_LOOKUP.unreflect(m);
} catch (ReflectiveOperationException | SecurityException ex) { } catch (ReflectiveOperationException | SecurityException ex) {
throw newInternalError(ex); throw newInternalError(ex);
} }
@ -1209,4 +1208,12 @@ public class ValueConversions {
private static MethodHandle buildVarargsList(int nargs) { private static MethodHandle buildVarargsList(int nargs) {
return MethodHandles.filterReturnValue(varargsArray(nargs), LazyStatics.MAKE_LIST); 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) {
return new InternalError(message, cause);
}
private static InternalError newInternalError(Throwable cause) {
return new InternalError(cause);
}
} }

View file

@ -70,7 +70,7 @@ public class BigArityTest {
MethodHandles.lookup().unreflect( MethodHandles.lookup().unreflect(
BigArityTest.class.getDeclaredMethod("hashArguments", Object[].class)); BigArityTest.class.getDeclaredMethod("hashArguments", Object[].class));
} catch (ReflectiveOperationException ex) { } catch (ReflectiveOperationException ex) {
throw new InternalError(ex); throw new Error(ex);
} }
} }
static MethodHandle MH_hashArguments(int arity) { static MethodHandle MH_hashArguments(int arity) {

View file

@ -145,21 +145,21 @@ public class PrivateInvokeTest {
MH_DEBUG_STRING = DIRECT_INVOKER_LOOKUP MH_DEBUG_STRING = DIRECT_INVOKER_LOOKUP
.findVirtual(MethodHandle.class, "debugString", methodType(String.class)); .findVirtual(MethodHandle.class, "debugString", methodType(String.class));
} catch (ReflectiveOperationException ex) { } catch (ReflectiveOperationException ex) {
throw new InternalError(ex); throw new Error(ex);
} }
} }
private Object internalMemberName(MethodHandle mh) { private Object internalMemberName(MethodHandle mh) {
try { try {
return MH_INTERNAL_MEMBER_NAME.invokeExact(mh); return MH_INTERNAL_MEMBER_NAME.invokeExact(mh);
} catch (Throwable ex) { } catch (Throwable ex) {
throw new InternalError(ex); throw new Error(ex);
} }
} }
private String debugString(MethodHandle mh) { private String debugString(MethodHandle mh) {
try { try {
return (String) MH_DEBUG_STRING.invokeExact(mh); return (String) MH_DEBUG_STRING.invokeExact(mh);
} catch (Throwable ex) { } catch (Throwable ex) {
throw new InternalError(ex); throw new Error(ex);
} }
} }
private static MethodHandle directInvoker(int refKind, MethodType mtype) { private static MethodHandle directInvoker(int refKind, MethodType mtype) {