# HG changeset patch # User redestad # Date 1519823599 -3600 # Wed Feb 28 14:13:19 2018 +0100 # Node ID 306644c8043e56577240e028d0fded3e3728a962 # Parent aef762ff9b23da747995c40a9dac09048d5f7521 8198831: Lazy initialization of ValueConversions MethodHandles Reviewed-by: tbd diff --git a/src/java.base/share/classes/sun/invoke/util/ValueConversions.java b/src/java.base/share/classes/sun/invoke/util/ValueConversions.java --- a/src/java.base/share/classes/sun/invoke/util/ValueConversions.java +++ b/src/java.base/share/classes/sun/invoke/util/ValueConversions.java @@ -377,7 +377,7 @@ MethodType type = MethodType.methodType(wrap.primitiveType()); switch (wrap) { case VOID: - mh = EMPTY; + mh = Handles.EMPTY; break; case OBJECT: case INT: case LONG: case FLOAT: case DOUBLE: @@ -400,26 +400,28 @@ throw new IllegalArgumentException("cannot find zero constant for " + wrap); } - private static final MethodHandle CAST_REFERENCE, IGNORE, EMPTY; - static { - try { - MethodType idType = MethodType.genericMethodType(1); - MethodType ignoreType = idType.changeReturnType(void.class); - CAST_REFERENCE = IMPL_LOOKUP.findVirtual(Class.class, "cast", idType); - IGNORE = IMPL_LOOKUP.findStatic(THIS_CLASS, "ignore", ignoreType); - EMPTY = IMPL_LOOKUP.findStatic(THIS_CLASS, "empty", ignoreType.dropParameterTypes(0, 1)); - } catch (NoSuchMethodException | IllegalAccessException ex) { - throw newInternalError("uncaught exception", ex); + private static class Handles { + static final MethodHandle CAST_REFERENCE, IGNORE, EMPTY; + static { + try { + MethodType idType = MethodType.genericMethodType(1); + MethodType ignoreType = idType.changeReturnType(void.class); + CAST_REFERENCE = IMPL_LOOKUP.findVirtual(Class.class, "cast", idType); + IGNORE = IMPL_LOOKUP.findStatic(THIS_CLASS, "ignore", ignoreType); + EMPTY = IMPL_LOOKUP.findStatic(THIS_CLASS, "empty", ignoreType.dropParameterTypes(0, 1)); + } catch (NoSuchMethodException | IllegalAccessException ex) { + throw newInternalError("uncaught exception", ex); + } } } public static MethodHandle ignore() { - return IGNORE; + return Handles.IGNORE; } /** Return a method that casts its second argument (an Object) to the given type (a Class). */ public static MethodHandle cast() { - return CAST_REFERENCE; + return Handles.CAST_REFERENCE; } /// Primitive conversions.