src/share/classes/java/lang/invoke/MethodHandleImpl.java
Index
Unified diffs
Context diffs
Sdiffs
Patch
New
Old
Previous File
Next File
jdk Cdiff src/share/classes/java/lang/invoke/MethodHandleImpl.java
src/share/classes/java/lang/invoke/MethodHandleImpl.java
Print this page
rev 9328 : 8027827: Improve performance of catchException combinator
8034120: MethodHandles.catchException doesn't handle VarargsCollector right
Reviewed-by: lagergren, psandoz, ?
rev 9329 : 8033666: Make sure @ForceInline is everywhere it needs to be in sun.misc and java.lang.invoke
Reviewed-by: ?
*** 251,261 ****
} else {
// Simple reference conversion.
// Note: Do not check for a class hierarchy relation
// between src and dst. In all cases a 'null' argument
// will pass the cast conversion.
! fn = ValueConversions.cast(dst);
}
}
Name conv = new Name(fn, names[INARG_BASE + i]);
assert(names[nameCursor] == null);
names[nameCursor++] = conv;
--- 251,261 ----
} else {
// Simple reference conversion.
// Note: Do not check for a class hierarchy relation
// between src and dst. In all cases a 'null' argument
// will pass the cast conversion.
! fn = ValueConversions.cast(dst, Lazy.MH_castReference);
}
}
Name conv = new Name(fn, names[INARG_BASE + i]);
assert(names[nameCursor] == null);
names[nameCursor++] = conv;
*** 291,300 ****
--- 291,319 ----
LambdaForm form = new LambdaForm("convert", lambdaType.parameterCount(), names);
return SimpleMethodHandle.make(srcType, form);
}
+ /**
+ * Identity function, with reference cast.
+ * @param t an arbitrary reference type
+ * @param x an arbitrary reference value
+ * @return the same value x
+ */
+ @ForceInline
+ @SuppressWarnings("unchecked")
+ static <T,U> T castReference(Class<? extends T> t, U x) {
+ // inlined Class.cast because we can't ForceInline it
+ if (x != null && !t.isInstance(x))
+ throw newClassCastException(t, x);
+ return (T) x;
+ }
+
+ private static ClassCastException newClassCastException(Class<?> t, Object obj) {
+ return new ClassCastException("Cannot cast " + obj.getClass().getName() + " to " + t.getName());
+ }
+
static MethodHandle makeReferenceIdentity(Class<?> refType) {
MethodType lambdaType = MethodType.genericMethodType(1).invokerType();
Name[] names = arguments(1, lambdaType);
names[names.length - 1] = new Name(ValueConversions.identity(), names[1]);
LambdaForm form = new LambdaForm("identity", lambdaType.parameterCount(), names);
*** 486,495 ****
--- 505,516 ----
static final NamedFunction NF_checkSpreadArgument;
static final NamedFunction NF_guardWithCatch;
static final NamedFunction NF_selectAlternative;
static final NamedFunction NF_throwException;
+ static final MethodHandle MH_castReference;
+
static {
try {
NF_checkSpreadArgument = new NamedFunction(MHI.getDeclaredMethod("checkSpreadArgument", Object.class, int.class));
NF_guardWithCatch = new NamedFunction(MHI.getDeclaredMethod("guardWithCatch", MethodHandle.class, Class.class,
MethodHandle.class, Object[].class));
*** 499,508 ****
--- 520,532 ----
NF_checkSpreadArgument.resolve();
NF_guardWithCatch.resolve();
NF_selectAlternative.resolve();
NF_throwException.resolve();
+
+ MethodType mt = MethodType.methodType(Object.class, Class.class, Object.class);
+ MH_castReference = IMPL_LOOKUP.findStatic(MHI, "castReference", mt);
} catch (ReflectiveOperationException ex) {
throw newInternalError(ex);
}
}
}
src/share/classes/java/lang/invoke/MethodHandleImpl.java
Index
Unified diffs
Context diffs
Sdiffs
Patch
New
Old
Previous File
Next File