src/java.base/share/classes/java/lang/invoke/BoundMethodHandle.java
author redestad
Thu, 16 Nov 2017 00:58:50 +0100
changeset 47753 a2008587c13f
parent 47216 71c04702a3d5
child 59201 b24f4caa1411
permissions -rw-r--r--
8184777: Factor out species generation logic from BoundMethodHandle Reviewed-by: vlivanov Contributed-by: john.r.rose@oracle.com, claes.redestad@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
     1
/*
39342
f66a89ed6fca 8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents: 36757
diff changeset
     2
 * Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
     4
 *
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4537
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4537
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    10
 *
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    15
 * accompanied this code).
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    16
 *
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4537
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4537
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4537
diff changeset
    23
 * questions.
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    24
 */
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    25
8822
8145ab9f5f86 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8821
diff changeset
    26
package java.lang.invoke;
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    27
39342
f66a89ed6fca 8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents: 36757
diff changeset
    28
import jdk.internal.vm.annotation.Stable;
35252
754852fba784 8144223: Move j.l.invoke.{ForceInline, DontInline, Stable} to jdk.internal.vm.annotation package
psandoz
parents: 33646
diff changeset
    29
import sun.invoke.util.ValueConversions;
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
    30
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
    31
import java.util.ArrayList;
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
    32
import java.util.List;
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
    33
35252
754852fba784 8144223: Move j.l.invoke.{ForceInline, DontInline, Stable} to jdk.internal.vm.annotation package
psandoz
parents: 33646
diff changeset
    34
import static java.lang.invoke.LambdaForm.BasicType;
754852fba784 8144223: Move j.l.invoke.{ForceInline, DontInline, Stable} to jdk.internal.vm.annotation package
psandoz
parents: 33646
diff changeset
    35
import static java.lang.invoke.LambdaForm.BasicType.*;
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
    36
import static java.lang.invoke.LambdaForm.BasicType.V_TYPE_NUM;
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
    37
import static java.lang.invoke.LambdaForm.BasicType.V_TYPE_NUM;
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
    38
import static java.lang.invoke.LambdaForm.BasicType.V_TYPE_NUM;
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
    39
import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
    40
import static java.lang.invoke.MethodHandleNatives.Constants.*;
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
    41
import static java.lang.invoke.MethodHandleStatics.newInternalError;
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
    42
import static java.lang.invoke.MethodHandleStatics.uncaughtException;
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    43
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    44
/**
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    45
 * The flavor of method handle which emulates an invoke instruction
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    46
 * on a predetermined argument.  The JVM dispatches to the correct method
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    47
 * when the handle is created, not when it is invoked.
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
    48
 *
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
    49
 * All bound arguments are encapsulated in dedicated species.
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    50
 */
26467
d69abed3a07d 8050052: Small cleanups in java.lang.invoke code
vlivanov
parents: 25859
diff changeset
    51
/*non-public*/ abstract class BoundMethodHandle extends MethodHandle {
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    52
26467
d69abed3a07d 8050052: Small cleanups in java.lang.invoke code
vlivanov
parents: 25859
diff changeset
    53
    /*non-public*/ BoundMethodHandle(MethodType type, LambdaForm form) {
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
    54
        super(type, form);
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
    55
        assert(speciesData() == speciesDataFor(form));
4537
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2707
diff changeset
    56
    }
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    57
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
    58
    //
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
    59
    // BMH API and internals
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
    60
    //
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    61
26469
e6bc14fae1cf 8050166: Get rid of some package-private methods on arguments in j.l.i.MethodHandle
vlivanov
parents: 26467
diff changeset
    62
    static BoundMethodHandle bindSingle(MethodType type, LambdaForm form, BasicType xtype, Object x) {
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
    63
        // for some type signatures, there exist pre-defined concrete BMH classes
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
    64
        try {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
    65
            switch (xtype) {
24572
5c9e5961d21c 8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents: 23918
diff changeset
    66
            case L_TYPE:
26469
e6bc14fae1cf 8050166: Get rid of some package-private methods on arguments in j.l.i.MethodHandle
vlivanov
parents: 26467
diff changeset
    67
                return bindSingle(type, form, x);  // Use known fast path.
24572
5c9e5961d21c 8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents: 23918
diff changeset
    68
            case I_TYPE:
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
    69
                return (BoundMethodHandle) SPECIALIZER.topSpecies().extendWith(I_TYPE_NUM).factory().invokeBasic(type, form, ValueConversions.widenSubword(x));
24572
5c9e5961d21c 8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents: 23918
diff changeset
    70
            case J_TYPE:
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
    71
                return (BoundMethodHandle) SPECIALIZER.topSpecies().extendWith(J_TYPE_NUM).factory().invokeBasic(type, form, (long) x);
24572
5c9e5961d21c 8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents: 23918
diff changeset
    72
            case F_TYPE:
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
    73
                return (BoundMethodHandle) SPECIALIZER.topSpecies().extendWith(F_TYPE_NUM).factory().invokeBasic(type, form, (float) x);
24572
5c9e5961d21c 8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents: 23918
diff changeset
    74
            case D_TYPE:
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
    75
                return (BoundMethodHandle) SPECIALIZER.topSpecies().extendWith(D_TYPE_NUM).factory().invokeBasic(type, form, (double) x);
24572
5c9e5961d21c 8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents: 23918
diff changeset
    76
            default : throw newInternalError("unexpected xtype: " + xtype);
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
    77
            }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
    78
        } catch (Throwable t) {
42105
d04ede5f10e7 8163553: java.lang.LinkageError from test java/lang/ThreadGroup/Stop.java
psandoz
parents: 41125
diff changeset
    79
            throw uncaughtException(t);
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    80
        }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    81
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    82
26481
c5b74a88a3c0 8057042: LambdaFormEditor: derive new LFs from a base LF
vlivanov
parents: 26479
diff changeset
    83
    /*non-public*/
c5b74a88a3c0 8057042: LambdaFormEditor: derive new LFs from a base LF
vlivanov
parents: 26479
diff changeset
    84
    LambdaFormEditor editor() {
c5b74a88a3c0 8057042: LambdaFormEditor: derive new LFs from a base LF
vlivanov
parents: 26479
diff changeset
    85
        return form.editor();
c5b74a88a3c0 8057042: LambdaFormEditor: derive new LFs from a base LF
vlivanov
parents: 26479
diff changeset
    86
    }
c5b74a88a3c0 8057042: LambdaFormEditor: derive new LFs from a base LF
vlivanov
parents: 26479
diff changeset
    87
26469
e6bc14fae1cf 8050166: Get rid of some package-private methods on arguments in j.l.i.MethodHandle
vlivanov
parents: 26467
diff changeset
    88
    static BoundMethodHandle bindSingle(MethodType type, LambdaForm form, Object x) {
e6bc14fae1cf 8050166: Get rid of some package-private methods on arguments in j.l.i.MethodHandle
vlivanov
parents: 26467
diff changeset
    89
        return Species_L.make(type, form, x);
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    90
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    91
26469
e6bc14fae1cf 8050166: Get rid of some package-private methods on arguments in j.l.i.MethodHandle
vlivanov
parents: 26467
diff changeset
    92
    @Override // there is a default binder in the super class, for 'L' types only
e6bc14fae1cf 8050166: Get rid of some package-private methods on arguments in j.l.i.MethodHandle
vlivanov
parents: 26467
diff changeset
    93
    /*non-public*/
e6bc14fae1cf 8050166: Get rid of some package-private methods on arguments in j.l.i.MethodHandle
vlivanov
parents: 26467
diff changeset
    94
    BoundMethodHandle bindArgumentL(int pos, Object value) {
26481
c5b74a88a3c0 8057042: LambdaFormEditor: derive new LFs from a base LF
vlivanov
parents: 26479
diff changeset
    95
        return editor().bindArgumentL(this, pos, value);
26469
e6bc14fae1cf 8050166: Get rid of some package-private methods on arguments in j.l.i.MethodHandle
vlivanov
parents: 26467
diff changeset
    96
    }
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
    97
26469
e6bc14fae1cf 8050166: Get rid of some package-private methods on arguments in j.l.i.MethodHandle
vlivanov
parents: 26467
diff changeset
    98
    /*non-public*/
e6bc14fae1cf 8050166: Get rid of some package-private methods on arguments in j.l.i.MethodHandle
vlivanov
parents: 26467
diff changeset
    99
    BoundMethodHandle bindArgumentI(int pos, int value) {
26481
c5b74a88a3c0 8057042: LambdaFormEditor: derive new LFs from a base LF
vlivanov
parents: 26479
diff changeset
   100
        return editor().bindArgumentI(this, pos, value);
26469
e6bc14fae1cf 8050166: Get rid of some package-private methods on arguments in j.l.i.MethodHandle
vlivanov
parents: 26467
diff changeset
   101
    }
e6bc14fae1cf 8050166: Get rid of some package-private methods on arguments in j.l.i.MethodHandle
vlivanov
parents: 26467
diff changeset
   102
    /*non-public*/
e6bc14fae1cf 8050166: Get rid of some package-private methods on arguments in j.l.i.MethodHandle
vlivanov
parents: 26467
diff changeset
   103
    BoundMethodHandle bindArgumentJ(int pos, long value) {
26481
c5b74a88a3c0 8057042: LambdaFormEditor: derive new LFs from a base LF
vlivanov
parents: 26479
diff changeset
   104
        return editor().bindArgumentJ(this, pos, value);
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   105
    }
26469
e6bc14fae1cf 8050166: Get rid of some package-private methods on arguments in j.l.i.MethodHandle
vlivanov
parents: 26467
diff changeset
   106
    /*non-public*/
e6bc14fae1cf 8050166: Get rid of some package-private methods on arguments in j.l.i.MethodHandle
vlivanov
parents: 26467
diff changeset
   107
    BoundMethodHandle bindArgumentF(int pos, float value) {
26481
c5b74a88a3c0 8057042: LambdaFormEditor: derive new LFs from a base LF
vlivanov
parents: 26479
diff changeset
   108
        return editor().bindArgumentF(this, pos, value);
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   109
    }
26469
e6bc14fae1cf 8050166: Get rid of some package-private methods on arguments in j.l.i.MethodHandle
vlivanov
parents: 26467
diff changeset
   110
    /*non-public*/
e6bc14fae1cf 8050166: Get rid of some package-private methods on arguments in j.l.i.MethodHandle
vlivanov
parents: 26467
diff changeset
   111
    BoundMethodHandle bindArgumentD(int pos, double value) {
26481
c5b74a88a3c0 8057042: LambdaFormEditor: derive new LFs from a base LF
vlivanov
parents: 26479
diff changeset
   112
        return editor().bindArgumentD(this, pos, value);
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   113
    }
26472
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26469
diff changeset
   114
    @Override
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26469
diff changeset
   115
    BoundMethodHandle rebind() {
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26469
diff changeset
   116
        if (!tooComplex()) {
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26469
diff changeset
   117
            return this;
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26469
diff changeset
   118
        }
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26469
diff changeset
   119
        return makeReinvoker(this);
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26469
diff changeset
   120
    }
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26469
diff changeset
   121
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26469
diff changeset
   122
    private boolean tooComplex() {
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26469
diff changeset
   123
        return (fieldCount() > FIELD_COUNT_THRESHOLD ||
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26469
diff changeset
   124
                form.expressionCount() > FORM_EXPRESSION_THRESHOLD);
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26469
diff changeset
   125
    }
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26469
diff changeset
   126
    private static final int FIELD_COUNT_THRESHOLD = 12;      // largest convenient BMH field count
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26469
diff changeset
   127
    private static final int FORM_EXPRESSION_THRESHOLD = 24;  // largest convenient BMH expression count
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26469
diff changeset
   128
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26469
diff changeset
   129
    /**
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26469
diff changeset
   130
     * A reinvoker MH has this form:
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26469
diff changeset
   131
     * {@code lambda (bmh, arg*) { thismh = bmh[0]; invokeBasic(thismh, arg*) }}
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26469
diff changeset
   132
     */
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26469
diff changeset
   133
    static BoundMethodHandle makeReinvoker(MethodHandle target) {
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26469
diff changeset
   134
        LambdaForm form = DelegatingMethodHandle.makeReinvokerForm(
26479
a60a19ec5ce5 8057657: Annotate LambdaForm parameters with types
vlivanov
parents: 26472
diff changeset
   135
                target, MethodTypeForm.LF_REBIND,
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   136
                Species_L.BMH_SPECIES, Species_L.BMH_SPECIES.getterFunction(0));
26472
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26469
diff changeset
   137
        return Species_L.make(target.type(), form, target);
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26469
diff changeset
   138
    }
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26469
diff changeset
   139
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   140
    /**
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   141
     * Return the {@link BoundMethodHandle.SpeciesData} instance representing this BMH species. All subclasses must provide a
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   142
     * static field containing this value, and they must accordingly implement this method.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   143
     */
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   144
    /*non-public*/ abstract BoundMethodHandle.SpeciesData speciesData();
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   145
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   146
    /*non-public*/ static BoundMethodHandle.SpeciesData speciesDataFor(LambdaForm form) {
26481
c5b74a88a3c0 8057042: LambdaFormEditor: derive new LFs from a base LF
vlivanov
parents: 26479
diff changeset
   147
        Object c = form.names[0].constraint;
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   148
        if (c instanceof SpeciesData) {
26481
c5b74a88a3c0 8057042: LambdaFormEditor: derive new LFs from a base LF
vlivanov
parents: 26479
diff changeset
   149
            return (SpeciesData) c;
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   150
        }
26481
c5b74a88a3c0 8057042: LambdaFormEditor: derive new LFs from a base LF
vlivanov
parents: 26479
diff changeset
   151
        // if there is no BMH constraint, then use the null constraint
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   152
        return SPECIALIZER.topSpecies();
26481
c5b74a88a3c0 8057042: LambdaFormEditor: derive new LFs from a base LF
vlivanov
parents: 26479
diff changeset
   153
    }
c5b74a88a3c0 8057042: LambdaFormEditor: derive new LFs from a base LF
vlivanov
parents: 26479
diff changeset
   154
24572
5c9e5961d21c 8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents: 23918
diff changeset
   155
    /**
5c9e5961d21c 8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents: 23918
diff changeset
   156
     * Return the number of fields in this BMH.  Equivalent to speciesData().fieldCount().
5c9e5961d21c 8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents: 23918
diff changeset
   157
     */
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   158
    /*non-public*/ final int fieldCount() { return speciesData().fieldCount(); }
24572
5c9e5961d21c 8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents: 23918
diff changeset
   159
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   160
    @Override
26467
d69abed3a07d 8050052: Small cleanups in java.lang.invoke code
vlivanov
parents: 25859
diff changeset
   161
    Object internalProperties() {
d69abed3a07d 8050052: Small cleanups in java.lang.invoke code
vlivanov
parents: 25859
diff changeset
   162
        return "\n& BMH="+internalValues();
13610
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 13424
diff changeset
   163
    }
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 13424
diff changeset
   164
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 13424
diff changeset
   165
    @Override
39342
f66a89ed6fca 8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents: 36757
diff changeset
   166
    final String internalValues() {
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   167
        int count = fieldCount();
39342
f66a89ed6fca 8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents: 36757
diff changeset
   168
        if (count == 1) {
f66a89ed6fca 8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents: 36757
diff changeset
   169
            return "[" + arg(0) + "]";
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   170
        }
39342
f66a89ed6fca 8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents: 36757
diff changeset
   171
        StringBuilder sb = new StringBuilder("[");
f66a89ed6fca 8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents: 36757
diff changeset
   172
        for (int i = 0; i < count; ++i) {
f66a89ed6fca 8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents: 36757
diff changeset
   173
            sb.append("\n  ").append(i).append(": ( ").append(arg(i)).append(" )");
f66a89ed6fca 8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents: 36757
diff changeset
   174
        }
f66a89ed6fca 8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents: 36757
diff changeset
   175
        return sb.append("\n]").toString();
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   176
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   177
23918
5f40f1d88890 8032686: Issues with method invoke
twisti
parents: 23038
diff changeset
   178
    /*non-public*/ final Object arg(int i) {
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   179
        try {
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   180
            Class<?> fieldType = speciesData().fieldTypes().get(i);
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   181
            switch (BasicType.basicType(fieldType)) {
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   182
                case L_TYPE: return          speciesData().getter(i).invokeBasic(this);
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   183
                case I_TYPE: return (int)    speciesData().getter(i).invokeBasic(this);
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   184
                case J_TYPE: return (long)   speciesData().getter(i).invokeBasic(this);
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   185
                case F_TYPE: return (float)  speciesData().getter(i).invokeBasic(this);
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   186
                case D_TYPE: return (double) speciesData().getter(i).invokeBasic(this);
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   187
            }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   188
        } catch (Throwable ex) {
42105
d04ede5f10e7 8163553: java.lang.LinkageError from test java/lang/ThreadGroup/Stop.java
psandoz
parents: 41125
diff changeset
   189
            throw uncaughtException(ex);
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   190
        }
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   191
        throw new InternalError("unexpected type: " + speciesData().key()+"."+i);
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   192
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   193
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   194
    //
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   195
    // cloning API
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   196
    //
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   197
24572
5c9e5961d21c 8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents: 23918
diff changeset
   198
    /*non-public*/ abstract BoundMethodHandle copyWith(MethodType mt, LambdaForm lf);
5c9e5961d21c 8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents: 23918
diff changeset
   199
    /*non-public*/ abstract BoundMethodHandle copyWithExtendL(MethodType mt, LambdaForm lf, Object narg);
5c9e5961d21c 8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents: 23918
diff changeset
   200
    /*non-public*/ abstract BoundMethodHandle copyWithExtendI(MethodType mt, LambdaForm lf, int    narg);
5c9e5961d21c 8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents: 23918
diff changeset
   201
    /*non-public*/ abstract BoundMethodHandle copyWithExtendJ(MethodType mt, LambdaForm lf, long   narg);
5c9e5961d21c 8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents: 23918
diff changeset
   202
    /*non-public*/ abstract BoundMethodHandle copyWithExtendF(MethodType mt, LambdaForm lf, float  narg);
5c9e5961d21c 8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents: 23918
diff changeset
   203
    /*non-public*/ abstract BoundMethodHandle copyWithExtendD(MethodType mt, LambdaForm lf, double narg);
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   204
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   205
    //
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   206
    // concrete BMH classes required to close bootstrap loops
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   207
    //
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   208
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   209
    private  // make it private to force users to access the enclosing class first
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   210
    static final class Species_L extends BoundMethodHandle {
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   211
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   212
        final Object argL0;
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   213
24572
5c9e5961d21c 8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents: 23918
diff changeset
   214
        private Species_L(MethodType mt, LambdaForm lf, Object argL0) {
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   215
            super(mt, lf);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   216
            this.argL0 = argL0;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   217
        }
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   218
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   219
        @Override
23918
5f40f1d88890 8032686: Issues with method invoke
twisti
parents: 23038
diff changeset
   220
        /*non-public*/ SpeciesData speciesData() {
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   221
            return BMH_SPECIES;
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   222
        }
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   223
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   224
        /*non-public*/ static @Stable SpeciesData BMH_SPECIES;
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   225
24572
5c9e5961d21c 8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents: 23918
diff changeset
   226
        /*non-public*/ static BoundMethodHandle make(MethodType mt, LambdaForm lf, Object argL0) {
5c9e5961d21c 8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents: 23918
diff changeset
   227
            return new Species_L(mt, lf, argL0);
5c9e5961d21c 8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents: 23918
diff changeset
   228
        }
5c9e5961d21c 8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents: 23918
diff changeset
   229
        @Override
5c9e5961d21c 8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents: 23918
diff changeset
   230
        /*non-public*/ final BoundMethodHandle copyWith(MethodType mt, LambdaForm lf) {
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   231
            return new Species_L(mt, lf, argL0);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   232
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   233
        @Override
24572
5c9e5961d21c 8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents: 23918
diff changeset
   234
        /*non-public*/ final BoundMethodHandle copyWithExtendL(MethodType mt, LambdaForm lf, Object narg) {
5c9e5961d21c 8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents: 23918
diff changeset
   235
            try {
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   236
                return (BoundMethodHandle) BMH_SPECIES.extendWith(L_TYPE_NUM).factory().invokeBasic(mt, lf, argL0, narg);
24572
5c9e5961d21c 8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents: 23918
diff changeset
   237
            } catch (Throwable ex) {
5c9e5961d21c 8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents: 23918
diff changeset
   238
                throw uncaughtException(ex);
5c9e5961d21c 8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents: 23918
diff changeset
   239
            }
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   240
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   241
        @Override
24572
5c9e5961d21c 8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents: 23918
diff changeset
   242
        /*non-public*/ final BoundMethodHandle copyWithExtendI(MethodType mt, LambdaForm lf, int narg) {
5c9e5961d21c 8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents: 23918
diff changeset
   243
            try {
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   244
                return (BoundMethodHandle) BMH_SPECIES.extendWith(I_TYPE_NUM).factory().invokeBasic(mt, lf, argL0, narg);
24572
5c9e5961d21c 8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents: 23918
diff changeset
   245
            } catch (Throwable ex) {
5c9e5961d21c 8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents: 23918
diff changeset
   246
                throw uncaughtException(ex);
5c9e5961d21c 8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents: 23918
diff changeset
   247
            }
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   248
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   249
        @Override
24572
5c9e5961d21c 8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents: 23918
diff changeset
   250
        /*non-public*/ final BoundMethodHandle copyWithExtendJ(MethodType mt, LambdaForm lf, long narg) {
5c9e5961d21c 8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents: 23918
diff changeset
   251
            try {
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   252
                return (BoundMethodHandle) BMH_SPECIES.extendWith(J_TYPE_NUM).factory().invokeBasic(mt, lf, argL0, narg);
24572
5c9e5961d21c 8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents: 23918
diff changeset
   253
            } catch (Throwable ex) {
5c9e5961d21c 8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents: 23918
diff changeset
   254
                throw uncaughtException(ex);
5c9e5961d21c 8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents: 23918
diff changeset
   255
            }
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   256
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   257
        @Override
24572
5c9e5961d21c 8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents: 23918
diff changeset
   258
        /*non-public*/ final BoundMethodHandle copyWithExtendF(MethodType mt, LambdaForm lf, float narg) {
5c9e5961d21c 8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents: 23918
diff changeset
   259
            try {
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   260
                return (BoundMethodHandle) BMH_SPECIES.extendWith(F_TYPE_NUM).factory().invokeBasic(mt, lf, argL0, narg);
24572
5c9e5961d21c 8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents: 23918
diff changeset
   261
            } catch (Throwable ex) {
5c9e5961d21c 8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents: 23918
diff changeset
   262
                throw uncaughtException(ex);
5c9e5961d21c 8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents: 23918
diff changeset
   263
            }
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   264
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   265
        @Override
24572
5c9e5961d21c 8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents: 23918
diff changeset
   266
        /*non-public*/ final BoundMethodHandle copyWithExtendD(MethodType mt, LambdaForm lf, double narg) {
5c9e5961d21c 8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents: 23918
diff changeset
   267
            try {
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   268
                return (BoundMethodHandle) BMH_SPECIES.extendWith(D_TYPE_NUM).factory().invokeBasic(mt, lf, argL0, narg);
24572
5c9e5961d21c 8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents: 23918
diff changeset
   269
            } catch (Throwable ex) {
5c9e5961d21c 8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents: 23918
diff changeset
   270
                throw uncaughtException(ex);
5c9e5961d21c 8037210: Get rid of char-based descriptions 'J' of basic types
vlivanov
parents: 23918
diff changeset
   271
            }
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   272
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   273
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   274
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   275
    //
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   276
    // BMH species meta-data
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   277
    //
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   278
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   279
    /*non-public*/
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   280
    static final class SpeciesData extends ClassSpecializer<BoundMethodHandle, String, SpeciesData>.SpeciesData {
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   281
        // This array is filled in lazily, as new species come into being over time.
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   282
        @Stable final private SpeciesData[] extensions = new SpeciesData[ARG_TYPE_LIMIT];
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   283
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   284
        public SpeciesData(Specializer outer, String key) {
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   285
            outer.super(key);
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   286
        }
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   287
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   288
        @Override
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   289
        protected String deriveClassName() {
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   290
            String typeString = deriveTypeString();
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   291
            if (typeString.isEmpty()) {
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   292
                return SimpleMethodHandle.class.getName();
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   293
            }
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   294
            return BoundMethodHandle.class.getName() + "$Species_" + typeString;
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   295
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   296
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   297
        @Override
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   298
        protected List<Class<?>> deriveFieldTypes(String key) {
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   299
            ArrayList<Class<?>> types = new ArrayList<>(key.length());
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   300
            for (int i = 0; i < key.length(); i++) {
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   301
                types.add(basicType(key.charAt(i)).basicTypeClass());
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   302
            }
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   303
            return types;
20527
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 16906
diff changeset
   304
        }
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 16906
diff changeset
   305
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   306
        @Override
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   307
        protected String deriveTypeString() {
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   308
            // (If/when we have to add nominal types, just inherit the more complex default.)
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   309
            return key();
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   310
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   311
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   312
        @Override
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   313
        protected MethodHandle deriveTransformHelper(MemberName transform, int whichtm) {
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   314
            if (whichtm == Specializer.TN_COPY_NO_EXTEND) {
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   315
                return factory();
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   316
            } else if (whichtm < ARG_TYPE_LIMIT) {
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   317
                return extendWith((byte) whichtm).factory();
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   318
            } else {
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   319
                throw newInternalError("bad transform");
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   320
            }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   321
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   322
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   323
        @Override
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   324
        protected <X> List<X> deriveTransformHelperArguments(MemberName transform, int whichtm, List<X> args, List<X> fields) {
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   325
            assert(verifyTHAargs(transform, whichtm, args, fields));
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   326
            // The rule is really simple:  Keep the first two arguments
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   327
            // the same, then put in the fields, then put any other argument.
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   328
            args.addAll(2, fields);
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   329
            return args;
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   330
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   331
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   332
        private boolean verifyTHAargs(MemberName transform, int whichtm, List<?> args, List<?> fields) {
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   333
            assert(transform == Specializer.BMH_TRANSFORMS.get(whichtm));
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   334
            assert(args.size() == transform.getMethodType().parameterCount());
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   335
            assert(fields.size() == this.fieldCount());
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   336
            final int MH_AND_LF = 2;
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   337
            if (whichtm == Specializer.TN_COPY_NO_EXTEND) {
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   338
                assert(transform.getMethodType().parameterCount() == MH_AND_LF);
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   339
            } else if (whichtm < ARG_TYPE_LIMIT) {
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   340
                assert(transform.getMethodType().parameterCount() == MH_AND_LF+1);
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   341
                final BasicType type = basicType((byte) whichtm);
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   342
                assert(transform.getParameterTypes()[MH_AND_LF] == type.basicTypeClass());
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   343
            } else {
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   344
                return false;
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   345
            }
33646
aeed9f07a50c 8131129: Attempt to define a duplicate BMH$Species class
plevart
parents: 33312
diff changeset
   346
            return true;
aeed9f07a50c 8131129: Attempt to define a duplicate BMH$Species class
plevart
parents: 33312
diff changeset
   347
        }
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   348
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   349
        /*non-public*/ SpeciesData extendWith(byte typeNum) {
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   350
            SpeciesData sd = extensions[typeNum];
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   351
            if (sd != null)  return sd;
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   352
            sd = SPECIALIZER.findSpecies(key() + BasicType.basicType(typeNum).basicTypeChar());
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   353
            extensions[typeNum] = sd;
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   354
            return sd;
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   355
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   356
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   357
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   358
    /*non-public*/
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   359
    static final Specializer SPECIALIZER = new Specializer();
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   360
    static {
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   361
        SimpleMethodHandle.BMH_SPECIES = BoundMethodHandle.SPECIALIZER.findSpecies("");
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   362
        Species_L.BMH_SPECIES = BoundMethodHandle.SPECIALIZER.findSpecies("L");
7555
a279ebc3b25c 6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents: 7554
diff changeset
   363
    }
a279ebc3b25c 6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents: 7554
diff changeset
   364
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   365
    /*non-public*/
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   366
    static final class Specializer extends ClassSpecializer<BoundMethodHandle, String, SpeciesData> {
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   367
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   368
        private static final MemberName SPECIES_DATA_ACCESSOR;
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   369
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   370
        static {
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   371
            try {
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   372
                SPECIES_DATA_ACCESSOR = IMPL_LOOKUP.resolveOrFail(REF_invokeVirtual, BoundMethodHandle.class,
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   373
                        "speciesData", MethodType.methodType(BoundMethodHandle.SpeciesData.class));
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   374
            } catch (ReflectiveOperationException ex) {
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   375
                throw newInternalError("Bootstrap link error", ex);
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   376
            }
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   377
        }
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   378
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   379
        private Specializer() {
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   380
            super(  // Reified type parameters:
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   381
                    BoundMethodHandle.class, String.class, BoundMethodHandle.SpeciesData.class,
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   382
                    // Principal constructor type:
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   383
                    MethodType.methodType(void.class, MethodType.class, LambdaForm.class),
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   384
                    // Required linkage between class and species:
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   385
                    SPECIES_DATA_ACCESSOR,
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   386
                    "BMH_SPECIES",
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   387
                    BMH_TRANSFORMS);
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   388
        }
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   389
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   390
        @Override
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   391
        protected String topSpeciesKey() {
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   392
            return "";
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   393
        }
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   394
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   395
        @Override
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   396
        protected BoundMethodHandle.SpeciesData newSpeciesData(String key) {
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   397
            return new BoundMethodHandle.SpeciesData(this, key);
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   398
        }
33646
aeed9f07a50c 8131129: Attempt to define a duplicate BMH$Species class
plevart
parents: 33312
diff changeset
   399
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   400
        static final List<MemberName> BMH_TRANSFORMS;
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   401
        static final int TN_COPY_NO_EXTEND = V_TYPE_NUM;
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   402
        static {
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   403
            final Class<BoundMethodHandle> BMH = BoundMethodHandle.class;
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   404
            // copyWithExtendLIJFD + copyWith
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   405
            try {
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   406
                BMH_TRANSFORMS = List.of(
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   407
                        IMPL_LOOKUP.resolveOrFail(REF_invokeVirtual, BMH, "copyWithExtendL", MethodType.methodType(BMH, MethodType.class, LambdaForm.class, Object.class)),
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   408
                        IMPL_LOOKUP.resolveOrFail(REF_invokeVirtual, BMH, "copyWithExtendI", MethodType.methodType(BMH, MethodType.class, LambdaForm.class, int.class)),
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   409
                        IMPL_LOOKUP.resolveOrFail(REF_invokeVirtual, BMH, "copyWithExtendJ", MethodType.methodType(BMH, MethodType.class, LambdaForm.class, long.class)),
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   410
                        IMPL_LOOKUP.resolveOrFail(REF_invokeVirtual, BMH, "copyWithExtendF", MethodType.methodType(BMH, MethodType.class, LambdaForm.class, float.class)),
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   411
                        IMPL_LOOKUP.resolveOrFail(REF_invokeVirtual, BMH, "copyWithExtendD", MethodType.methodType(BMH, MethodType.class, LambdaForm.class, double.class)),
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   412
                        IMPL_LOOKUP.resolveOrFail(REF_invokeVirtual, BMH, "copyWith", MethodType.methodType(BMH, MethodType.class, LambdaForm.class))
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   413
                );
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   414
            } catch (ReflectiveOperationException ex) {
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   415
                throw newInternalError("Failed resolving copyWith methods", ex);
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   416
            }
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   417
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   418
            // as it happens, there is one transform per BasicType including V_TYPE
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   419
            assert(BMH_TRANSFORMS.size() == TYPE_LIMIT);
33646
aeed9f07a50c 8131129: Attempt to define a duplicate BMH$Species class
plevart
parents: 33312
diff changeset
   420
        }
aeed9f07a50c 8131129: Attempt to define a duplicate BMH$Species class
plevart
parents: 33312
diff changeset
   421
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   422
        /**
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   423
         * Generation of concrete BMH classes.
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   424
         *
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   425
         * A concrete BMH species is fit for binding a number of values adhering to a
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   426
         * given type pattern. Reference types are erased.
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   427
         *
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   428
         * BMH species are cached by type pattern.
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   429
         *
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   430
         * A BMH species has a number of fields with the concrete (possibly erased) types of
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   431
         * bound values. Setters are provided as an API in BMH. Getters are exposed as MHs,
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   432
         * which can be included as names in lambda forms.
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   433
         */
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   434
        class Factory extends ClassSpecializer<BoundMethodHandle, String, BoundMethodHandle.SpeciesData>.Factory {
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   435
            @Override
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   436
            protected String chooseFieldName(Class<?> type, int index) {
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   437
                return "arg" + super.chooseFieldName(type, index);
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   438
            }
4537
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2707
diff changeset
   439
        }
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   440
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   441
        @Override
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   442
        protected Factory makeFactory() {
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   443
            return new Factory();
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   444
        }
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   445
      }
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9752
diff changeset
   446
47753
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   447
    static SpeciesData speciesData_L()      { return Species_L.BMH_SPECIES; }
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   448
    static SpeciesData speciesData_LL()     { return SPECIALIZER.findSpecies("LL"); }
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   449
    static SpeciesData speciesData_LLL()    { return SPECIALIZER.findSpecies("LLL"); }
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   450
    static SpeciesData speciesData_LLLL()   { return SPECIALIZER.findSpecies("LLLL"); }
a2008587c13f 8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents: 47216
diff changeset
   451
    static SpeciesData speciesData_LLLLL()  { return SPECIALIZER.findSpecies("LLLLL"); }
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   452
}