changeset 7289:b8ce179b70fb

serialization metafactory protocol changes
author mcimadamore
date Thu, 07 Feb 2013 12:51:52 +0000
parents 12e4114be8d9
children 83d2ed4895b1
files src/share/classes/java/lang/invoke/LambdaMetafactory.java
diffstat 1 files changed, 23 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/lang/invoke/LambdaMetafactory.java	Wed Feb 06 23:07:17 2013 -0500
+++ b/src/share/classes/java/lang/invoke/LambdaMetafactory.java	Thu Feb 07 12:51:52 2013 +0000
@@ -147,6 +147,14 @@
     /** Flag for alternate metafactories indicating the lambda object is intended to be serializable */
     public static final int FLAG_SERIALIZABLE = 1 << 0;
 
+    /**
+     * Flag for alternate metafactories indicating the lambda object implements other marker interfaces
+     * besides Serializable
+     */
+    public static final int FLAG_MARKERS = 1 << 1;
+
+    private static final Class[] EMPTY_CLASS_ARRAY = new Class[0];
+
 /**
      * Standard meta-factory for conversion of lambda expressions or method references to functional interfaces.
      *
@@ -220,8 +228,10 @@
      *                   functional interface instance are invoked.
      * @param instantiatedMethodType The signature of the SAM method from the functional interface's perspective
      * @param flags A bitmask containing flags that may influence the translation of this lambda expression.  Defined
-     *              fields include FLAG_SERIALIZABLE.
-     * @param markerInterfaces Additional interfaces which the lambda object should implement.
+     *              fields include FLAG_SERIALIZABLE and FLAG_MARKERS.
+     * @param markerInterfaces If the FLAG_MARKERS flag is set, this consists of an integer count followed by
+     *                         that number of Class objects identifying additional marker interfaces which the
+     *                         lambda object should implement
      * @return a CallSite, which, when invoked, will return an instance of the functional interface
      * @throws ReflectiveOperationException
      * @throws LambdaConversionException If any of the meta-factory protocol invariants are violated
@@ -234,9 +244,17 @@
         MethodHandle samMethod = (MethodHandle)args[0];
         MethodHandle implMethod = (MethodHandle)args[1];
         MethodType instantiatedMethodType = (MethodType)args[2];
-        int flags = (int)args[3];
-        Class[] markerInterfaces = new Class[args.length - 4];
-        System.arraycopy(args, 4, markerInterfaces, 0, args.length - 4);
+        int flags = (Integer) args[3];
+        Class[] markerInterfaces;
+        int argIndex = 4;
+        if ((flags & FLAG_MARKERS) != 0) {
+            int markerCount = (Integer) args[argIndex++];
+            markerInterfaces = new Class[markerCount];
+            System.arraycopy(args, argIndex, markerInterfaces, 0, markerCount);
+            argIndex += markerCount;
+        }
+        else
+            markerInterfaces = EMPTY_CLASS_ARRAY;
         AbstractValidatingLambdaMetafactory mf;
         mf = new InnerClassLambdaMetafactory(caller, invokedType, samMethod, implMethod, instantiatedMethodType,
                                              flags, markerInterfaces);