src/share/classes/java/lang/invoke/SerializedLambda.java

Print this page


   1 /*
   2  * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  80                             String functionalInterfaceMethodSignature,
  81                             int implMethodKind,
  82                             String implClass,
  83                             String implMethodName,
  84                             String implMethodSignature,
  85                             String instantiatedMethodType,
  86                             Object[] capturedArgs) {
  87         this.capturingClass = capturingClass;
  88         this.functionalInterfaceMethodKind = functionalInterfaceMethodKind;
  89         this.functionalInterfaceClass = functionalInterfaceClass;
  90         this.functionalInterfaceMethodName = functionalInterfaceMethodName;
  91         this.functionalInterfaceMethodSignature = functionalInterfaceMethodSignature;
  92         this.implMethodKind = implMethodKind;
  93         this.implClass = implClass;
  94         this.implMethodName = implMethodName;
  95         this.implMethodSignature = implMethodSignature;
  96         this.instantiatedMethodType = instantiatedMethodType;
  97         this.capturedArgs = Objects.requireNonNull(capturedArgs).clone();
  98     }
  99 
 100     /** Get the name of the class that captured this lambda */



 101     public String getCapturingClass() {
 102         return capturingClass.getName().replace('.', '/');
 103     }
 104 
 105     /** Get the name of the functional interface class to which this lambda has been converted */





 106     public String getFunctionalInterfaceClass() {
 107         return functionalInterfaceClass;
 108     }
 109 
 110     /** Get the name of the primary method for the functional interface to which this lambda has been converted */




 111     public String getFunctionalInterfaceMethodName() {
 112         return functionalInterfaceMethodName;
 113     }
 114 
 115     /** Get the signature of the primary method for the functional interface to which this lambda has been converted */





 116     public String getFunctionalInterfaceMethodSignature() {
 117         return functionalInterfaceMethodSignature;
 118     }
 119 
 120     /** Get the method handle kind (see {@link MethodHandleInfo}) of the primary method for the functional interface
 121      * to which this lambda has been converted */





 122     public int getFunctionalInterfaceMethodKind() {
 123         return functionalInterfaceMethodKind;
 124     }
 125 
 126     /** Get the name of the class containing the implementation method */





 127     public String getImplClass() {
 128         return implClass;
 129     }
 130 
 131     /** Get the name of the implementation method */



 132     public String getImplMethodName() {
 133         return implMethodName;
 134     }
 135 
 136     /** Get the signature of the implementation method */



 137     public String getImplMethodSignature() {
 138         return implMethodSignature;
 139     }
 140 
 141     /** Get the method handle kind (see {@link MethodHandleInfo}) of the implementation method */




 142     public int getImplMethodKind() {
 143         return implMethodKind;
 144     }
 145 
 146     /**
 147      * Get the signature of the primary functional interface method after type variables are substituted with
 148      * their instantiation from the capture site



 149      */
 150     public final String getInstantiatedMethodType() {
 151         return instantiatedMethodType;
 152     }
 153 
 154     /** Get the count of dynamic arguments to the lambda capture site */



 155     public int getCapturedArgCount() {
 156         return capturedArgs.length;
 157     }
 158 
 159     /** Get a dynamic argument to the lambda capture site */




 160     public Object getCapturedArg(int i) {
 161         return capturedArgs[i];
 162     }
 163 
 164     private Object readResolve() throws ReflectiveOperationException {
 165         try {
 166             Method deserialize = AccessController.doPrivileged(new PrivilegedExceptionAction<Method>() {
 167                 @Override
 168                 public Method run() throws Exception {
 169                     Method m = capturingClass.getDeclaredMethod("$deserializeLambda$", SerializedLambda.class);
 170                     m.setAccessible(true);
 171                     return m;
 172                 }
 173             });
 174 
 175             return deserialize.invoke(null, this);
 176         }
 177         catch (PrivilegedActionException e) {
 178             Exception cause = e.getException();
 179             if (cause instanceof ReflectiveOperationException)
   1 /*
   2  * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  80                             String functionalInterfaceMethodSignature,
  81                             int implMethodKind,
  82                             String implClass,
  83                             String implMethodName,
  84                             String implMethodSignature,
  85                             String instantiatedMethodType,
  86                             Object[] capturedArgs) {
  87         this.capturingClass = capturingClass;
  88         this.functionalInterfaceMethodKind = functionalInterfaceMethodKind;
  89         this.functionalInterfaceClass = functionalInterfaceClass;
  90         this.functionalInterfaceMethodName = functionalInterfaceMethodName;
  91         this.functionalInterfaceMethodSignature = functionalInterfaceMethodSignature;
  92         this.implMethodKind = implMethodKind;
  93         this.implClass = implClass;
  94         this.implMethodName = implMethodName;
  95         this.implMethodSignature = implMethodSignature;
  96         this.instantiatedMethodType = instantiatedMethodType;
  97         this.capturedArgs = Objects.requireNonNull(capturedArgs).clone();
  98     }
  99 
 100     /**
 101      * Get the name of the class that captured this lambda.
 102      * @return the name of the class that captured this lambda
 103      */
 104     public String getCapturingClass() {
 105         return capturingClass.getName().replace('.', '/');
 106     }
 107 
 108     /**
 109      * Get the name of the functional interface class to which this
 110      * lambda has been converted
 111      * @return the name of the functional interface this lambda has
 112      * been converted to
 113      */
 114     public String getFunctionalInterfaceClass() {
 115         return functionalInterfaceClass;
 116     }
 117 
 118     /**
 119      * Get the name of the primary method for the functional interface
 120      * to which this lambda has been converted.
 121      * @return the name of the primary methods of the functional interface
 122      */
 123     public String getFunctionalInterfaceMethodName() {
 124         return functionalInterfaceMethodName;
 125     }
 126 
 127     /**
 128      * Get the signature of the primary method for the functional
 129      * interface to which this lambda has been converted.
 130      * @return the signature of the primary method of the functional
 131      * interface
 132      */
 133     public String getFunctionalInterfaceMethodSignature() {
 134         return functionalInterfaceMethodSignature;
 135     }
 136 
 137     /**
 138      * Get the method handle kind (see {@link MethodHandleInfo}) of
 139      * the primary method for the functional interface to which this
 140      * lambda has been converted
 141      * @return the method handle kind of the primary method of
 142      * functional interface
 143      */
 144     public int getFunctionalInterfaceMethodKind() {
 145         return functionalInterfaceMethodKind;
 146     }
 147 
 148     /**
 149      * Get the name of the class containing the implementation
 150      * method.
 151      * @return the name of the class containing the implementation
 152      * method
 153      */
 154     public String getImplClass() {
 155         return implClass;
 156     }
 157 
 158     /** 
 159      * Get the name of the implementation method.
 160      * @return the name of the implementation method
 161      */
 162     public String getImplMethodName() {
 163         return implMethodName;
 164     }
 165 
 166     /**
 167      * Get the signature of the implementation method.
 168      * @return the signature of the implementation method
 169      */
 170     public String getImplMethodSignature() {
 171         return implMethodSignature;
 172     }
 173 
 174     /**
 175      * Get the method handle kind (see {@link MethodHandleInfo}) of
 176      * the implementation method.
 177      * @return the method handle kind of the implementation method
 178      */
 179     public int getImplMethodKind() {
 180         return implMethodKind;
 181     }
 182 
 183     /**
 184      * Get the signature of the primary functional interface method
 185      * after type variables are substituted with their instantiation
 186      * from the capture site.
 187      * @return the signature of the primary functional interface method
 188      * after type variable processing
 189      */
 190     public final String getInstantiatedMethodType() {
 191         return instantiatedMethodType;
 192     }
 193 
 194     /**
 195      * Get the count of dynamic arguments to the lambda capture site.
 196      * @return the count of dynamic arguments to the lambda capture site
 197      */
 198     public int getCapturedArgCount() {
 199         return capturedArgs.length;
 200     }
 201 
 202     /**
 203      * Get a dynamic argument to the lambda capture site.
 204      * @param i the argument to capture
 205      * @return a dynamic argument to the lambda capture site
 206      */
 207     public Object getCapturedArg(int i) {
 208         return capturedArgs[i];
 209     }
 210 
 211     private Object readResolve() throws ReflectiveOperationException {
 212         try {
 213             Method deserialize = AccessController.doPrivileged(new PrivilegedExceptionAction<Method>() {
 214                 @Override
 215                 public Method run() throws Exception {
 216                     Method m = capturingClass.getDeclaredMethod("$deserializeLambda$", SerializedLambda.class);
 217                     m.setAccessible(true);
 218                     return m;
 219                 }
 220             });
 221 
 222             return deserialize.invoke(null, this);
 223         }
 224         catch (PrivilegedActionException e) {
 225             Exception cause = e.getException();
 226             if (cause instanceof ReflectiveOperationException)