src/java.base/share/classes/java/lang/invoke/SerializedLambda.java
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 58520 e036ee8bae56
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
     1
/*
57956
e0b8b019d2f5 8229997: Apply java.io.Serial annotations in java.base
darcy
parents: 51118
diff changeset
     2
 * Copyright (c) 2012, 2019, 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 {
57956
e0b8b019d2f5 8229997: Apply java.io.Serial annotations in java.base
darcy
parents: 51118
diff changeset
    68
    @java.io.Serial
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    69
    private static final long serialVersionUID = 8025925345765570181L;
16034
cb5fbea1ecec 8008770: SerializedLambda incorrect class loader for lambda deserializing class
rfield
parents: 16001
diff changeset
    70
    private final Class<?> capturingClass;
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    71
    private final String functionalInterfaceClass;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    72
    private final String functionalInterfaceMethodName;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    73
    private final String functionalInterfaceMethodSignature;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    74
    private final String implClass;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    75
    private final String implMethodName;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    76
    private final String implMethodSignature;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    77
    private final int implMethodKind;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    78
    private final String instantiatedMethodType;
58520
e036ee8bae56 8231202: Suppress warnings on non-serializable non-transient instance fields in serializable classes
darcy
parents: 57956
diff changeset
    79
    @SuppressWarnings("serial") // Not statically typed as Serializable
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    80
    private final Object[] capturedArgs;
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
    /**
18716
9723e722b955 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents: 18569
diff changeset
    83
     * 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
    84
     * at the lambda factory site.
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    85
     *
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    86
     * @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
    87
     * @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
    88
     *                                 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
    89
     * @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
    90
     *                                      method for the present at the
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    91
     *                                      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
    92
     * @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
    93
     *                                           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
    94
     *                                           the lambda factory site
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    95
     * @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
    96
     * @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
    97
     *                  the implementation method
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    98
     * @param implMethodName Name of the implementation method
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
    99
     * @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
   100
     * @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
   101
     *                               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
   102
     *                               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
   103
     *                               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
   104
     * @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
   105
     *                     which represent variables captured by
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   106
     *                     the lambda
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   107
     */
16034
cb5fbea1ecec 8008770: SerializedLambda incorrect class loader for lambda deserializing class
rfield
parents: 16001
diff changeset
   108
    public SerializedLambda(Class<?> capturingClass,
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   109
                            String functionalInterfaceClass,
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   110
                            String functionalInterfaceMethodName,
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   111
                            String functionalInterfaceMethodSignature,
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   112
                            int implMethodKind,
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   113
                            String implClass,
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   114
                            String implMethodName,
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   115
                            String implMethodSignature,
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   116
                            String instantiatedMethodType,
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   117
                            Object[] capturedArgs) {
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   118
        this.capturingClass = capturingClass;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   119
        this.functionalInterfaceClass = functionalInterfaceClass;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   120
        this.functionalInterfaceMethodName = functionalInterfaceMethodName;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   121
        this.functionalInterfaceMethodSignature = functionalInterfaceMethodSignature;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   122
        this.implMethodKind = implMethodKind;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   123
        this.implClass = implClass;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   124
        this.implMethodName = implMethodName;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   125
        this.implMethodSignature = implMethodSignature;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   126
        this.instantiatedMethodType = instantiatedMethodType;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   127
        this.capturedArgs = Objects.requireNonNull(capturedArgs).clone();
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   128
    }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   129
18569
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   130
    /**
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   131
     * Get the name of the class that captured this lambda.
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   132
     * @return the name of the class that captured this lambda
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   133
     */
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   134
    public String getCapturingClass() {
16034
cb5fbea1ecec 8008770: SerializedLambda incorrect class loader for lambda deserializing class
rfield
parents: 16001
diff changeset
   135
        return capturingClass.getName().replace('.', '/');
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   136
    }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   137
18569
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   138
    /**
18716
9723e722b955 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents: 18569
diff changeset
   139
     * 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
   140
     * 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
   141
     * @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
   142
     * this lambda has been converted
18569
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   143
     */
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   144
    public String getFunctionalInterfaceClass() {
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   145
        return functionalInterfaceClass;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   146
    }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   147
18569
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   148
    /**
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   149
     * 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
   150
     * to which this lambda has been converted.
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   151
     * @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
   152
     */
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   153
    public String getFunctionalInterfaceMethodName() {
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   154
        return functionalInterfaceMethodName;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   155
    }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   156
18569
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   157
    /**
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   158
     * Get the signature of the primary method for the functional
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   159
     * interface to which this lambda has been converted.
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   160
     * @return the signature of the primary method of the functional
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   161
     * interface
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   162
     */
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   163
    public String getFunctionalInterfaceMethodSignature() {
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   164
        return functionalInterfaceMethodSignature;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   165
    }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   166
18569
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   167
    /**
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   168
     * Get 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
     * @return the name of the class containing the implementation
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   171
     * method
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   172
     */
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   173
    public String getImplClass() {
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   174
        return implClass;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   175
    }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   176
18569
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   177
    /**
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   178
     * Get the name of the implementation method.
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   179
     * @return the name of the implementation method
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   180
     */
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   181
    public String getImplMethodName() {
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   182
        return implMethodName;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   183
    }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   184
18569
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   185
    /**
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   186
     * Get the signature of the implementation method.
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   187
     * @return the signature of the implementation method
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   188
     */
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   189
    public String getImplMethodSignature() {
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   190
        return implMethodSignature;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   191
    }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   192
18569
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   193
    /**
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   194
     * Get the method handle kind (see {@link MethodHandleInfo}) of
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   195
     * the implementation method.
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   196
     * @return the method handle kind of the implementation method
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   197
     */
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   198
    public int getImplMethodKind() {
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   199
        return implMethodKind;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   200
    }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   201
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   202
    /**
18569
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   203
     * Get the signature of the primary functional interface method
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   204
     * after type variables are substituted with their instantiation
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   205
     * from the capture site.
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   206
     * @return the signature of the primary functional interface method
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   207
     * after type variable processing
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   208
     */
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   209
    public final String getInstantiatedMethodType() {
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   210
        return instantiatedMethodType;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   211
    }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   212
18569
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   213
    /**
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   214
     * 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
   215
     * @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
   216
     */
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   217
    public int getCapturedArgCount() {
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   218
        return capturedArgs.length;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   219
    }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   220
18569
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   221
    /**
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   222
     * Get a dynamic argument to the lambda capture site.
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   223
     * @param i the argument to capture
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   224
     * @return a dynamic argument to the lambda capture site
0e46c17766b7 8019357: Fix doclint warnings in java.lang.invoke
darcy
parents: 16034
diff changeset
   225
     */
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   226
    public Object getCapturedArg(int i) {
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   227
        return capturedArgs[i];
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   228
    }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   229
57956
e0b8b019d2f5 8229997: Apply java.io.Serial annotations in java.base
darcy
parents: 51118
diff changeset
   230
    @java.io.Serial
51118
2467bd84c59b 8207816: Align declaration of SerializedLambda.readResolve with serialization conventions
darcy
parents: 50725
diff changeset
   231
    private Object readResolve() throws ObjectStreamException {
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   232
        try {
29986
97167d851fc4 8078467: Update core libraries to use diamond with anonymous classes
darcy
parents: 25859
diff changeset
   233
            Method deserialize = AccessController.doPrivileged(new PrivilegedExceptionAction<>() {
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   234
                @Override
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   235
                public Method run() throws Exception {
16034
cb5fbea1ecec 8008770: SerializedLambda incorrect class loader for lambda deserializing class
rfield
parents: 16001
diff changeset
   236
                    Method m = capturingClass.getDeclaredMethod("$deserializeLambda$", SerializedLambda.class);
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   237
                    m.setAccessible(true);
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   238
                    return m;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   239
                }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   240
            });
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   241
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   242
            return deserialize.invoke(null, this);
51118
2467bd84c59b 8207816: Align declaration of SerializedLambda.readResolve with serialization conventions
darcy
parents: 50725
diff changeset
   243
        } catch (ReflectiveOperationException roe) {
2467bd84c59b 8207816: Align declaration of SerializedLambda.readResolve with serialization conventions
darcy
parents: 50725
diff changeset
   244
            ObjectStreamException ose = new InvalidObjectException("ReflectiveOperationException during deserialization");
2467bd84c59b 8207816: Align declaration of SerializedLambda.readResolve with serialization conventions
darcy
parents: 50725
diff changeset
   245
            ose.initCause(roe);
2467bd84c59b 8207816: Align declaration of SerializedLambda.readResolve with serialization conventions
darcy
parents: 50725
diff changeset
   246
            throw ose;
2467bd84c59b 8207816: Align declaration of SerializedLambda.readResolve with serialization conventions
darcy
parents: 50725
diff changeset
   247
        } catch (PrivilegedActionException e) {
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   248
            Exception cause = e.getException();
51118
2467bd84c59b 8207816: Align declaration of SerializedLambda.readResolve with serialization conventions
darcy
parents: 50725
diff changeset
   249
            if (cause instanceof RuntimeException)
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   250
                throw (RuntimeException) cause;
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   251
            else
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   252
                throw new RuntimeException("Exception in SerializedLambda.readResolve", e);
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   253
        }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   254
    }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   255
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   256
    @Override
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   257
    public String toString() {
19804
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 18716
diff changeset
   258
        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
   259
        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
   260
                             "%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
   261
                             "capturingClass", capturingClass,
9723e722b955 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents: 18569
diff changeset
   262
                             "functionalInterfaceMethod", functionalInterfaceClass,
9723e722b955 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents: 18569
diff changeset
   263
                               functionalInterfaceMethodName,
9723e722b955 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents: 18569
diff changeset
   264
                               functionalInterfaceMethodSignature,
9723e722b955 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents: 18569
diff changeset
   265
                             "implementation",
9723e722b955 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents: 18569
diff changeset
   266
                               implKind,
9723e722b955 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents: 18569
diff changeset
   267
                               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
   268
                             "instantiatedMethodType", instantiatedMethodType,
9723e722b955 8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents: 18569
diff changeset
   269
                             "numCaptured", capturedArgs.length);
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   270
    }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents:
diff changeset
   271
}