src/java.base/share/classes/java/lang/invoke/SerializedLambda.java
author psandoz
Fri, 22 Jun 2018 12:05:36 -0700
changeset 50725 d5c59fab1bdb
parent 47216 71c04702a3d5
child 51118 2467bd84c59b
permissions -rw-r--r--
8202922: Method reference identity is broken by serialization Reviewed-by: jlaskey, mchung
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;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    28
import java.lang.reflect.Method;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    29
import java.security.AccessController;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    30
import java.security.PrivilegedActionException;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    31
import java.security.PrivilegedExceptionAction;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    32
import java.util.Objects;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    33
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    34
/**
21339
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 19804
diff changeset
    35
 * Serialized form of a lambda expression.  The properties of this class
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 19804
diff changeset
    36
 * represent the information that is present at the lambda factory site, including
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 19804
diff changeset
    37
 * static metafactory arguments such as the identity of the primary functional
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 19804
diff changeset
    38
 * interface method and the identity of the implementation method, as well as
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 19804
diff changeset
    39
 * dynamic metafactory arguments such as values captured from the lexical scope
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 19804
diff changeset
    40
 * at the time of lambda capture.
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 19804
diff changeset
    41
 *
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 19804
diff changeset
    42
 * <p>Implementors of serializable lambdas, such as compilers or language
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 19804
diff changeset
    43
 * runtime libraries, are expected to ensure that instances deserialize properly.
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 19804
diff changeset
    44
 * 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
    45
 * an instance of {@code SerializedLambda}, rather than allowing default
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 19804
diff changeset
    46
 * serialization to proceed.
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 19804
diff changeset
    47
 *
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 19804
diff changeset
    48
 * <p>{@code SerializedLambda} has a {@code readResolve} method that looks for
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 19804
diff changeset
    49
 * a (possibly private) static method called
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 19804
diff changeset
    50
 * {@code $deserializeLambda$(SerializedLambda)} in the capturing class, invokes
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 19804
diff changeset
    51
 * that with itself as the first argument, and returns the result.  Lambda classes
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 19804
diff changeset
    52
 * implementing {@code $deserializeLambda$} are responsible for validating
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 19804
diff changeset
    53
 * that the properties of the {@code SerializedLambda} are consistent with a
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 19804
diff changeset
    54
 * lambda actually captured by that class.
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    55
 *
50725
d5c59fab1bdb 8202922: Method reference identity is broken by serialization
psandoz
parents: 47216
diff changeset
    56
 * <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
    57
 * form is unpredictable, and therefore identity-sensitive operations (such as
d5c59fab1bdb 8202922: Method reference identity is broken by serialization
psandoz
parents: 47216
diff changeset
    58
 * reference equality, object locking, and {@code System.identityHashCode()} may
d5c59fab1bdb 8202922: Method reference identity is broken by serialization
psandoz
parents: 47216
diff changeset
    59
 * produce different results in different implementations, or even upon
d5c59fab1bdb 8202922: Method reference identity is broken by serialization
psandoz
parents: 47216
diff changeset
    60
 * different deserializations in the same implementation.
d5c59fab1bdb 8202922: Method reference identity is broken by serialization
psandoz
parents: 47216
diff changeset
    61
 *
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    62
 * @see LambdaMetafactory
44255
515cf13d7791 8176566: @since value errors in types of java.base module
mli
parents: 29986
diff changeset
    63
 * @since 1.8
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    64
 */
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    65
public final class SerializedLambda implements Serializable {
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    66
    private static final long serialVersionUID = 8025925345765570181L;
16034
cb5fbea1ecec 8008770: SerializedLambda incorrect class loader for lambda deserializing class
rfield
parents: 16001
diff changeset
    67
    private final Class<?> capturingClass;
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    68
    private final String functionalInterfaceClass;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    69
    private final String functionalInterfaceMethodName;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    70
    private final String functionalInterfaceMethodSignature;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    71
    private final String implClass;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    72
    private final String implMethodName;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    73
    private final String implMethodSignature;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    74
    private final int implMethodKind;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    75
    private final String instantiatedMethodType;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    76
    private final Object[] capturedArgs;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    77
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    78
    /**
18716
9723e722b955 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents: 18569
diff changeset
    79
     * 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
    80
     * at the lambda factory site.
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    81
     *
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    82
     * @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
    83
     * @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
    84
     *                                 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
    85
     * @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
    86
     *                                      method for the present at the
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    87
     *                                      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
    88
     * @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
    89
     *                                           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
    90
     *                                           the lambda factory site
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    91
     * @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
    92
     * @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
    93
     *                  the implementation method
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    94
     * @param implMethodName Name of the implementation method
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    95
     * @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
    96
     * @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
    97
     *                               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
    98
     *                               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
    99
     *                               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
   100
     * @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
   101
     *                     which represent variables captured by
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   102
     *                     the lambda
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   103
     */
16034
cb5fbea1ecec 8008770: SerializedLambda incorrect class loader for lambda deserializing class
rfield
parents: 16001
diff changeset
   104
    public SerializedLambda(Class<?> capturingClass,
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   105
                            String functionalInterfaceClass,
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   106
                            String functionalInterfaceMethodName,
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   107
                            String functionalInterfaceMethodSignature,
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   108
                            int implMethodKind,
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   109
                            String implClass,
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   110
                            String implMethodName,
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   111
                            String implMethodSignature,
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   112
                            String instantiatedMethodType,
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   113
                            Object[] capturedArgs) {
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   114
        this.capturingClass = capturingClass;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   115
        this.functionalInterfaceClass = functionalInterfaceClass;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   116
        this.functionalInterfaceMethodName = functionalInterfaceMethodName;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   117
        this.functionalInterfaceMethodSignature = functionalInterfaceMethodSignature;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   118
        this.implMethodKind = implMethodKind;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   119
        this.implClass = implClass;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   120
        this.implMethodName = implMethodName;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   121
        this.implMethodSignature = implMethodSignature;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   122
        this.instantiatedMethodType = instantiatedMethodType;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   123
        this.capturedArgs = Objects.requireNonNull(capturedArgs).clone();
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   124
    }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   125
18569
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   126
    /**
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   127
     * Get the name of the class that captured this lambda.
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   128
     * @return the name of the class that captured this lambda
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   129
     */
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   130
    public String getCapturingClass() {
16034
cb5fbea1ecec 8008770: SerializedLambda incorrect class loader for lambda deserializing class
rfield
parents: 16001
diff changeset
   131
        return capturingClass.getName().replace('.', '/');
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   132
    }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   133
18569
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   134
    /**
18716
9723e722b955 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents: 18569
diff changeset
   135
     * 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
   136
     * 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
   137
     * @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
   138
     * this lambda has been converted
18569
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   139
     */
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   140
    public String getFunctionalInterfaceClass() {
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   141
        return functionalInterfaceClass;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   142
    }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   143
18569
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   144
    /**
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   145
     * 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
   146
     * to which this lambda has been converted.
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   147
     * @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
   148
     */
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   149
    public String getFunctionalInterfaceMethodName() {
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   150
        return functionalInterfaceMethodName;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   151
    }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   152
18569
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   153
    /**
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   154
     * Get the signature of the primary method for the functional
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   155
     * interface to which this lambda has been converted.
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   156
     * @return the signature of the primary method of the functional
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   157
     * interface
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   158
     */
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   159
    public String getFunctionalInterfaceMethodSignature() {
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   160
        return functionalInterfaceMethodSignature;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   161
    }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   162
18569
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   163
    /**
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   164
     * Get the name of the class containing the implementation
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   165
     * method.
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   166
     * @return 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
     */
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   169
    public String getImplClass() {
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   170
        return implClass;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   171
    }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   172
18569
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   173
    /**
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   174
     * Get the name of the implementation method.
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   175
     * @return the name of the implementation method
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   176
     */
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   177
    public String getImplMethodName() {
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   178
        return implMethodName;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   179
    }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   180
18569
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   181
    /**
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   182
     * Get the signature of the implementation method.
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   183
     * @return the signature of the implementation method
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   184
     */
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   185
    public String getImplMethodSignature() {
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   186
        return implMethodSignature;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   187
    }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   188
18569
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   189
    /**
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   190
     * Get the method handle kind (see {@link MethodHandleInfo}) of
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   191
     * the implementation method.
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   192
     * @return the method handle kind of the implementation method
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   193
     */
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   194
    public int getImplMethodKind() {
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   195
        return implMethodKind;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   196
    }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   197
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   198
    /**
18569
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   199
     * Get the signature of the primary functional interface method
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   200
     * after type variables are substituted with their instantiation
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   201
     * from the capture site.
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   202
     * @return the signature of the primary functional interface method
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   203
     * after type variable processing
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   204
     */
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   205
    public final String getInstantiatedMethodType() {
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   206
        return instantiatedMethodType;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   207
    }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   208
18569
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   209
    /**
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   210
     * 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
   211
     * @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
   212
     */
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   213
    public int getCapturedArgCount() {
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   214
        return capturedArgs.length;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   215
    }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   216
18569
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   217
    /**
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   218
     * Get a dynamic argument to the lambda capture site.
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   219
     * @param i the argument to capture
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   220
     * @return a dynamic argument to the lambda capture site
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   221
     */
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   222
    public Object getCapturedArg(int i) {
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   223
        return capturedArgs[i];
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   224
    }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   225
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   226
    private Object readResolve() throws ReflectiveOperationException {
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   227
        try {
29986
97167d851fc4 8078467: Update core libraries to use diamond with anonymous classes
darcy
parents: 25859
diff changeset
   228
            Method deserialize = AccessController.doPrivileged(new PrivilegedExceptionAction<>() {
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   229
                @Override
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   230
                public Method run() throws Exception {
16034
cb5fbea1ecec 8008770: SerializedLambda incorrect class loader for lambda deserializing class
rfield
parents: 16001
diff changeset
   231
                    Method m = capturingClass.getDeclaredMethod("$deserializeLambda$", SerializedLambda.class);
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   232
                    m.setAccessible(true);
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   233
                    return m;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   234
                }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   235
            });
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
            return deserialize.invoke(null, this);
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
        catch (PrivilegedActionException e) {
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   240
            Exception cause = e.getException();
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   241
            if (cause instanceof ReflectiveOperationException)
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   242
                throw (ReflectiveOperationException) cause;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   243
            else if (cause instanceof RuntimeException)
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   244
                throw (RuntimeException) cause;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   245
            else
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   246
                throw new RuntimeException("Exception in SerializedLambda.readResolve", e);
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   247
        }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   248
    }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   249
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   250
    @Override
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   251
    public String toString() {
19804
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 18716
diff changeset
   252
        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
   253
        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
   254
                             "%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
   255
                             "capturingClass", capturingClass,
9723e722b955 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents: 18569
diff changeset
   256
                             "functionalInterfaceMethod", functionalInterfaceClass,
9723e722b955 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents: 18569
diff changeset
   257
                               functionalInterfaceMethodName,
9723e722b955 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents: 18569
diff changeset
   258
                               functionalInterfaceMethodSignature,
9723e722b955 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents: 18569
diff changeset
   259
                             "implementation",
9723e722b955 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents: 18569
diff changeset
   260
                               implKind,
9723e722b955 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents: 18569
diff changeset
   261
                               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
   262
                             "instantiatedMethodType", instantiatedMethodType,
9723e722b955 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents: 18569
diff changeset
   263
                             "numCaptured", capturedArgs.length);
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   264
    }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   265
}