src/java.base/share/classes/java/lang/invoke/SerializedLambda.java
author darcy
Thu, 19 Jul 2018 09:20:08 -0700
changeset 51118 2467bd84c59b
parent 50725 d5c59fab1bdb
child 57956 e0b8b019d2f5
child 58678 9cf78a70fa4f
permissions -rw-r--r--
8207816: Align declaration of SerializedLambda.readResolve with serialization conventions Reviewed-by: briangoetz
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
     1
/*
18569
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
     2
 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
     4
 *
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    10
 *
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    15
 * accompanied this code).
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    16
 *
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    20
 *
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    23
 * questions.
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    24
 */
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    25
package java.lang.invoke;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    26
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    27
import java.io.Serializable;
51118
2467bd84c59b 8207816: Align declaration of SerializedLambda.readResolve with serialization conventions
darcy
parents: 50725
diff changeset
    28
import java.io.InvalidObjectException;
2467bd84c59b 8207816: Align declaration of SerializedLambda.readResolve with serialization conventions
darcy
parents: 50725
diff changeset
    29
import java.io.ObjectStreamException;
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    30
import java.lang.reflect.Method;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    31
import java.security.AccessController;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    32
import java.security.PrivilegedActionException;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    33
import java.security.PrivilegedExceptionAction;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    34
import java.util.Objects;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    35
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    36
/**
21339
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 19804
diff changeset
    37
 * Serialized form of a lambda expression.  The properties of this class
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 19804
diff changeset
    38
 * represent the information that is present at the lambda factory site, including
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 19804
diff changeset
    39
 * static metafactory arguments such as the identity of the primary functional
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 19804
diff changeset
    40
 * interface method and the identity of the implementation method, as well as
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 19804
diff changeset
    41
 * dynamic metafactory arguments such as values captured from the lexical scope
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 19804
diff changeset
    42
 * at the time of lambda capture.
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 19804
diff changeset
    43
 *
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 19804
diff changeset
    44
 * <p>Implementors of serializable lambdas, such as compilers or language
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 19804
diff changeset
    45
 * runtime libraries, are expected to ensure that instances deserialize properly.
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 19804
diff changeset
    46
 * One means to do so is to ensure that the {@code writeReplace} method returns
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 19804
diff changeset
    47
 * an instance of {@code SerializedLambda}, rather than allowing default
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 19804
diff changeset
    48
 * serialization to proceed.
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 19804
diff changeset
    49
 *
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 19804
diff changeset
    50
 * <p>{@code SerializedLambda} has a {@code readResolve} method that looks for
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 19804
diff changeset
    51
 * a (possibly private) static method called
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 19804
diff changeset
    52
 * {@code $deserializeLambda$(SerializedLambda)} in the capturing class, invokes
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 19804
diff changeset
    53
 * that with itself as the first argument, and returns the result.  Lambda classes
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 19804
diff changeset
    54
 * implementing {@code $deserializeLambda$} are responsible for validating
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 19804
diff changeset
    55
 * that the properties of the {@code SerializedLambda} are consistent with a
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 19804
diff changeset
    56
 * lambda actually captured by that class.
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    57
 *
50725
d5c59fab1bdb 8202922: Method reference identity is broken by serialization
psandoz
parents: 47216
diff changeset
    58
 * <p>The identity of a function object produced by deserializing the serialized
d5c59fab1bdb 8202922: Method reference identity is broken by serialization
psandoz
parents: 47216
diff changeset
    59
 * form is unpredictable, and therefore identity-sensitive operations (such as
d5c59fab1bdb 8202922: Method reference identity is broken by serialization
psandoz
parents: 47216
diff changeset
    60
 * reference equality, object locking, and {@code System.identityHashCode()} may
d5c59fab1bdb 8202922: Method reference identity is broken by serialization
psandoz
parents: 47216
diff changeset
    61
 * produce different results in different implementations, or even upon
d5c59fab1bdb 8202922: Method reference identity is broken by serialization
psandoz
parents: 47216
diff changeset
    62
 * different deserializations in the same implementation.
d5c59fab1bdb 8202922: Method reference identity is broken by serialization
psandoz
parents: 47216
diff changeset
    63
 *
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    64
 * @see LambdaMetafactory
44255
515cf13d7791 8176566: @since value errors in types of java.base module
mli
parents: 29986
diff changeset
    65
 * @since 1.8
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    66
 */
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    67
public final class SerializedLambda implements Serializable {
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    68
    private static final long serialVersionUID = 8025925345765570181L;
16034
cb5fbea1ecec 8008770: SerializedLambda incorrect class loader for lambda deserializing class
rfield
parents: 16001
diff changeset
    69
    private final Class<?> capturingClass;
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    70
    private final String functionalInterfaceClass;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    71
    private final String functionalInterfaceMethodName;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    72
    private final String functionalInterfaceMethodSignature;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    73
    private final String implClass;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    74
    private final String implMethodName;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    75
    private final String implMethodSignature;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    76
    private final int implMethodKind;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    77
    private final String instantiatedMethodType;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    78
    private final Object[] capturedArgs;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    79
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    80
    /**
18716
9723e722b955 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents: 18569
diff changeset
    81
     * Create a {@code SerializedLambda} from the low-level information present
9723e722b955 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents: 18569
diff changeset
    82
     * at the lambda factory site.
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    83
     *
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    84
     * @param capturingClass The class in which the lambda expression appears
18716
9723e722b955 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents: 18569
diff changeset
    85
     * @param functionalInterfaceClass Name, in slash-delimited form, of static
9723e722b955 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents: 18569
diff changeset
    86
     *                                 type of the returned lambda object
9723e722b955 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents: 18569
diff changeset
    87
     * @param functionalInterfaceMethodName Name of the functional interface
9723e722b955 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents: 18569
diff changeset
    88
     *                                      method for the present at the
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    89
     *                                      lambda factory site
18716
9723e722b955 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents: 18569
diff changeset
    90
     * @param functionalInterfaceMethodSignature Signature of the functional
9723e722b955 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents: 18569
diff changeset
    91
     *                                           interface method present at
9723e722b955 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents: 18569
diff changeset
    92
     *                                           the lambda factory site
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    93
     * @param implMethodKind Method handle kind for the implementation method
18716
9723e722b955 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents: 18569
diff changeset
    94
     * @param implClass Name, in slash-delimited form, for the class holding
9723e722b955 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents: 18569
diff changeset
    95
     *                  the implementation method
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    96
     * @param implMethodName Name of the implementation method
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    97
     * @param implMethodSignature Signature of the implementation method
18716
9723e722b955 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents: 18569
diff changeset
    98
     * @param instantiatedMethodType The signature of the primary functional
9723e722b955 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents: 18569
diff changeset
    99
     *                               interface method after type variables
9723e722b955 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents: 18569
diff changeset
   100
     *                               are substituted with their instantiation
9723e722b955 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents: 18569
diff changeset
   101
     *                               from the capture site
9723e722b955 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents: 18569
diff changeset
   102
     * @param capturedArgs The dynamic arguments to the lambda factory site,
9723e722b955 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents: 18569
diff changeset
   103
     *                     which represent variables captured by
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   104
     *                     the lambda
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   105
     */
16034
cb5fbea1ecec 8008770: SerializedLambda incorrect class loader for lambda deserializing class
rfield
parents: 16001
diff changeset
   106
    public SerializedLambda(Class<?> capturingClass,
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   107
                            String functionalInterfaceClass,
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   108
                            String functionalInterfaceMethodName,
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   109
                            String functionalInterfaceMethodSignature,
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   110
                            int implMethodKind,
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   111
                            String implClass,
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   112
                            String implMethodName,
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   113
                            String implMethodSignature,
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   114
                            String instantiatedMethodType,
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   115
                            Object[] capturedArgs) {
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   116
        this.capturingClass = capturingClass;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   117
        this.functionalInterfaceClass = functionalInterfaceClass;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   118
        this.functionalInterfaceMethodName = functionalInterfaceMethodName;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   119
        this.functionalInterfaceMethodSignature = functionalInterfaceMethodSignature;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   120
        this.implMethodKind = implMethodKind;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   121
        this.implClass = implClass;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   122
        this.implMethodName = implMethodName;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   123
        this.implMethodSignature = implMethodSignature;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   124
        this.instantiatedMethodType = instantiatedMethodType;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   125
        this.capturedArgs = Objects.requireNonNull(capturedArgs).clone();
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   126
    }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   127
18569
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   128
    /**
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   129
     * Get the name of the class that captured this lambda.
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   130
     * @return the name of the class that captured this lambda
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   131
     */
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   132
    public String getCapturingClass() {
16034
cb5fbea1ecec 8008770: SerializedLambda incorrect class loader for lambda deserializing class
rfield
parents: 16001
diff changeset
   133
        return capturingClass.getName().replace('.', '/');
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   134
    }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   135
18569
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   136
    /**
18716
9723e722b955 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents: 18569
diff changeset
   137
     * Get the name of the invoked type to which this
18569
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   138
     * lambda has been converted
18716
9723e722b955 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents: 18569
diff changeset
   139
     * @return the name of the functional interface class to which
9723e722b955 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents: 18569
diff changeset
   140
     * this lambda has been converted
18569
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   141
     */
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   142
    public String getFunctionalInterfaceClass() {
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   143
        return functionalInterfaceClass;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   144
    }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   145
18569
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   146
    /**
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   147
     * Get the name of the primary method for the functional interface
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   148
     * to which this lambda has been converted.
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   149
     * @return the name of the primary methods of the functional interface
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   150
     */
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   151
    public String getFunctionalInterfaceMethodName() {
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   152
        return functionalInterfaceMethodName;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   153
    }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   154
18569
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   155
    /**
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   156
     * Get the signature of the primary method for the functional
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   157
     * interface to which this lambda has been converted.
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   158
     * @return the signature of the primary method of the functional
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   159
     * interface
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   160
     */
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   161
    public String getFunctionalInterfaceMethodSignature() {
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   162
        return functionalInterfaceMethodSignature;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   163
    }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   164
18569
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   165
    /**
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   166
     * Get the name of the class containing the implementation
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   167
     * method.
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   168
     * @return the name of the class containing the implementation
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   169
     * method
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   170
     */
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   171
    public String getImplClass() {
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   172
        return implClass;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   173
    }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   174
18569
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   175
    /**
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   176
     * Get the name of the implementation method.
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   177
     * @return the name of the implementation method
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   178
     */
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   179
    public String getImplMethodName() {
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   180
        return implMethodName;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   181
    }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   182
18569
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   183
    /**
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   184
     * Get the signature of the implementation method.
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   185
     * @return the signature of the implementation method
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   186
     */
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   187
    public String getImplMethodSignature() {
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   188
        return implMethodSignature;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   189
    }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   190
18569
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   191
    /**
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   192
     * Get the method handle kind (see {@link MethodHandleInfo}) of
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   193
     * the implementation method.
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   194
     * @return the method handle kind of the implementation method
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   195
     */
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   196
    public int getImplMethodKind() {
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   197
        return implMethodKind;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   198
    }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   199
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   200
    /**
18569
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   201
     * Get the signature of the primary functional interface method
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   202
     * after type variables are substituted with their instantiation
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   203
     * from the capture site.
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   204
     * @return the signature of the primary functional interface method
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   205
     * after type variable processing
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   206
     */
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   207
    public final String getInstantiatedMethodType() {
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   208
        return instantiatedMethodType;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   209
    }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   210
18569
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   211
    /**
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   212
     * Get the count of dynamic arguments to the lambda capture site.
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   213
     * @return the count of dynamic arguments to the lambda capture site
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   214
     */
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   215
    public int getCapturedArgCount() {
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   216
        return capturedArgs.length;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   217
    }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   218
18569
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   219
    /**
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   220
     * Get a dynamic argument to the lambda capture site.
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   221
     * @param i the argument to capture
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   222
     * @return a dynamic argument to the lambda capture site
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   223
     */
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   224
    public Object getCapturedArg(int i) {
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   225
        return capturedArgs[i];
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   226
    }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   227
51118
2467bd84c59b 8207816: Align declaration of SerializedLambda.readResolve with serialization conventions
darcy
parents: 50725
diff changeset
   228
    private Object readResolve() throws ObjectStreamException {
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   229
        try {
29986
97167d851fc4 8078467: Update core libraries to use diamond with anonymous classes
darcy
parents: 25859
diff changeset
   230
            Method deserialize = AccessController.doPrivileged(new PrivilegedExceptionAction<>() {
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   231
                @Override
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   232
                public Method run() throws Exception {
16034
cb5fbea1ecec 8008770: SerializedLambda incorrect class loader for lambda deserializing class
rfield
parents: 16001
diff changeset
   233
                    Method m = capturingClass.getDeclaredMethod("$deserializeLambda$", SerializedLambda.class);
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   234
                    m.setAccessible(true);
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   235
                    return m;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   236
                }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   237
            });
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   238
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   239
            return deserialize.invoke(null, this);
51118
2467bd84c59b 8207816: Align declaration of SerializedLambda.readResolve with serialization conventions
darcy
parents: 50725
diff changeset
   240
        } catch (ReflectiveOperationException roe) {
2467bd84c59b 8207816: Align declaration of SerializedLambda.readResolve with serialization conventions
darcy
parents: 50725
diff changeset
   241
            ObjectStreamException ose = new InvalidObjectException("ReflectiveOperationException during deserialization");
2467bd84c59b 8207816: Align declaration of SerializedLambda.readResolve with serialization conventions
darcy
parents: 50725
diff changeset
   242
            ose.initCause(roe);
2467bd84c59b 8207816: Align declaration of SerializedLambda.readResolve with serialization conventions
darcy
parents: 50725
diff changeset
   243
            throw ose;
2467bd84c59b 8207816: Align declaration of SerializedLambda.readResolve with serialization conventions
darcy
parents: 50725
diff changeset
   244
        } catch (PrivilegedActionException e) {
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   245
            Exception cause = e.getException();
51118
2467bd84c59b 8207816: Align declaration of SerializedLambda.readResolve with serialization conventions
darcy
parents: 50725
diff changeset
   246
            if (cause instanceof RuntimeException)
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   247
                throw (RuntimeException) cause;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   248
            else
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   249
                throw new RuntimeException("Exception in SerializedLambda.readResolve", e);
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   250
        }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   251
    }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   252
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   253
    @Override
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   254
    public String toString() {
19804
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 18716
diff changeset
   255
        String implKind=MethodHandleInfo.referenceKindToString(implMethodKind);
18716
9723e722b955 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents: 18569
diff changeset
   256
        return String.format("SerializedLambda[%s=%s, %s=%s.%s:%s, " +
9723e722b955 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents: 18569
diff changeset
   257
                             "%s=%s %s.%s:%s, %s=%s, %s=%d]",
9723e722b955 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents: 18569
diff changeset
   258
                             "capturingClass", capturingClass,
9723e722b955 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents: 18569
diff changeset
   259
                             "functionalInterfaceMethod", functionalInterfaceClass,
9723e722b955 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents: 18569
diff changeset
   260
                               functionalInterfaceMethodName,
9723e722b955 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents: 18569
diff changeset
   261
                               functionalInterfaceMethodSignature,
9723e722b955 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents: 18569
diff changeset
   262
                             "implementation",
9723e722b955 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents: 18569
diff changeset
   263
                               implKind,
9723e722b955 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents: 18569
diff changeset
   264
                               implClass, implMethodName, implMethodSignature,
9723e722b955 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents: 18569
diff changeset
   265
                             "instantiatedMethodType", instantiatedMethodType,
9723e722b955 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents: 18569
diff changeset
   266
                             "numCaptured", capturedArgs.length);
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   267
    }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   268
}