src/java.base/share/classes/java/lang/invoke/MethodTypeForm.java
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 58238 3386b9a8ef4d
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
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
/*
58038
aa3715655834 8230662: Remove dead code from MethodTypeForm
redestad
parents: 49935
diff changeset
     2
 * Copyright (c) 2008, 2019, 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: 2707
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: 2707
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: 2707
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2707
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2707
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
8822
8145ab9f5f86 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8821
diff changeset
    28
import sun.invoke.util.Wrapper;
39342
f66a89ed6fca 8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents: 35252
diff changeset
    29
27803
d04ca9d519ce 8057020: LambdaForm caches should support eviction
vlivanov
parents: 27295
diff changeset
    30
import java.lang.ref.SoftReference;
39342
f66a89ed6fca 8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents: 35252
diff changeset
    31
f66a89ed6fca 8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents: 35252
diff changeset
    32
import static java.lang.invoke.MethodHandleStatics.newIllegalArgumentException;
8821
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    33
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    34
/**
8821
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    35
 * Shared information for a group of method types, which differ
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    36
 * only by reference types, and therefore share a common erasure
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    37
 * and wrapping.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    38
 * <p>
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    39
 * For an empirical discussion of the structure of method types,
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    40
 * see <a href="http://groups.google.com/group/jvm-languages/browse_thread/thread/ac9308ae74da9b7e/">
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    41
 * the thread "Avoiding Boxing" on jvm-languages</a>.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    42
 * There are approximately 2000 distinct erased method types in the JDK.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    43
 * There are a little over 10 times that number of unerased types.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    44
 * No more than half of these are likely to be loaded at once.
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    45
 * @author John Rose
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    46
 */
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
    47
final class MethodTypeForm {
58038
aa3715655834 8230662: Remove dead code from MethodTypeForm
redestad
parents: 49935
diff changeset
    48
    final short parameterSlotCount;
aa3715655834 8230662: Remove dead code from MethodTypeForm
redestad
parents: 49935
diff changeset
    49
    final short primitiveCount;
8821
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    50
    final MethodType erasedType;        // the canonical erasure
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
    51
    final MethodType basicType;         // the canonical erasure, with primitives simplified
8821
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    52
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    53
    // Cached adapter information:
58238
3386b9a8ef4d 8230768: Arrays of SoftReferences in MethodTypeForm should not be @Stable
redestad
parents: 58038
diff changeset
    54
    final SoftReference<MethodHandle>[] methodHandles;
3386b9a8ef4d 8230768: Arrays of SoftReferences in MethodTypeForm should not be @Stable
redestad
parents: 58038
diff changeset
    55
26468
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
    56
    // Indexes into methodHandles:
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
    57
    static final int
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
    58
            MH_BASIC_INV      =  0,  // cached instance of MH.invokeBasic
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
    59
            MH_NF_INV         =  1,  // cached helper for LF.NamedFunction
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
    60
            MH_UNINIT_CS      =  2,  // uninitialized call site
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
    61
            MH_LIMIT          =  3;
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
    62
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
    63
    // Cached lambda form information, for basic types only:
58238
3386b9a8ef4d 8230768: Arrays of SoftReferences in MethodTypeForm should not be @Stable
redestad
parents: 58038
diff changeset
    64
    final SoftReference<LambdaForm>[] lambdaForms;
3386b9a8ef4d 8230768: Arrays of SoftReferences in MethodTypeForm should not be @Stable
redestad
parents: 58038
diff changeset
    65
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
    66
    // Indexes into lambdaForms:
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
    67
    static final int
27295
8ed31033bf48 8059877: GWT branch frequencies pollution due to LF sharing
vlivanov
parents: 26480
diff changeset
    68
            LF_INVVIRTUAL              =  0,  // DMH invokeVirtual
8ed31033bf48 8059877: GWT branch frequencies pollution due to LF sharing
vlivanov
parents: 26480
diff changeset
    69
            LF_INVSTATIC               =  1,
8ed31033bf48 8059877: GWT branch frequencies pollution due to LF sharing
vlivanov
parents: 26480
diff changeset
    70
            LF_INVSPECIAL              =  2,
8ed31033bf48 8059877: GWT branch frequencies pollution due to LF sharing
vlivanov
parents: 26480
diff changeset
    71
            LF_NEWINVSPECIAL           =  3,
8ed31033bf48 8059877: GWT branch frequencies pollution due to LF sharing
vlivanov
parents: 26480
diff changeset
    72
            LF_INVINTERFACE            =  4,
8ed31033bf48 8059877: GWT branch frequencies pollution due to LF sharing
vlivanov
parents: 26480
diff changeset
    73
            LF_INVSTATIC_INIT          =  5,  // DMH invokeStatic with <clinit> barrier
8ed31033bf48 8059877: GWT branch frequencies pollution due to LF sharing
vlivanov
parents: 26480
diff changeset
    74
            LF_INTERPRET               =  6,  // LF interpreter
8ed31033bf48 8059877: GWT branch frequencies pollution due to LF sharing
vlivanov
parents: 26480
diff changeset
    75
            LF_REBIND                  =  7,  // BoundMethodHandle
8ed31033bf48 8059877: GWT branch frequencies pollution due to LF sharing
vlivanov
parents: 26480
diff changeset
    76
            LF_DELEGATE                =  8,  // DelegatingMethodHandle
8ed31033bf48 8059877: GWT branch frequencies pollution due to LF sharing
vlivanov
parents: 26480
diff changeset
    77
            LF_DELEGATE_BLOCK_INLINING =  9,  // Counting DelegatingMethodHandle w/ @DontInline
8ed31033bf48 8059877: GWT branch frequencies pollution due to LF sharing
vlivanov
parents: 26480
diff changeset
    78
            LF_EX_LINKER               = 10,  // invokeExact_MT (for invokehandle)
8ed31033bf48 8059877: GWT branch frequencies pollution due to LF sharing
vlivanov
parents: 26480
diff changeset
    79
            LF_EX_INVOKER              = 11,  // MHs.invokeExact
8ed31033bf48 8059877: GWT branch frequencies pollution due to LF sharing
vlivanov
parents: 26480
diff changeset
    80
            LF_GEN_LINKER              = 12,  // generic invoke_MT (for invokehandle)
8ed31033bf48 8059877: GWT branch frequencies pollution due to LF sharing
vlivanov
parents: 26480
diff changeset
    81
            LF_GEN_INVOKER             = 13,  // generic MHs.invoke
8ed31033bf48 8059877: GWT branch frequencies pollution due to LF sharing
vlivanov
parents: 26480
diff changeset
    82
            LF_CS_LINKER               = 14,  // linkToCallSite_CS
8ed31033bf48 8059877: GWT branch frequencies pollution due to LF sharing
vlivanov
parents: 26480
diff changeset
    83
            LF_MH_LINKER               = 15,  // linkToCallSite_MH
8ed31033bf48 8059877: GWT branch frequencies pollution due to LF sharing
vlivanov
parents: 26480
diff changeset
    84
            LF_GWC                     = 16,  // guardWithCatch (catchException)
8ed31033bf48 8059877: GWT branch frequencies pollution due to LF sharing
vlivanov
parents: 26480
diff changeset
    85
            LF_GWT                     = 17,  // guardWithTest
39342
f66a89ed6fca 8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents: 35252
diff changeset
    86
            LF_TF                      = 18,  // tryFinally
f66a89ed6fca 8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents: 35252
diff changeset
    87
            LF_LOOP                    = 19,  // loop
49935
2ace90aec488 8200167: Validate more special case invocations
dholmes
parents: 47216
diff changeset
    88
            LF_INVSPECIAL_IFC          = 20,  // DMH invokeSpecial of (private) interface method
2ace90aec488 8200167: Validate more special case invocations
dholmes
parents: 47216
diff changeset
    89
            LF_LIMIT                   = 21;
8821
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    90
26467
d69abed3a07d 8050052: Small cleanups in java.lang.invoke code
vlivanov
parents: 25859
diff changeset
    91
    /** Return the type corresponding uniquely (1-1) to this MT-form.
d69abed3a07d 8050052: Small cleanups in java.lang.invoke code
vlivanov
parents: 25859
diff changeset
    92
     *  It might have any primitive returns or arguments, but will have no references except Object.
d69abed3a07d 8050052: Small cleanups in java.lang.invoke code
vlivanov
parents: 25859
diff changeset
    93
     */
8821
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    94
    public MethodType erasedType() {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    95
        return erasedType;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    96
    }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    97
26467
d69abed3a07d 8050052: Small cleanups in java.lang.invoke code
vlivanov
parents: 25859
diff changeset
    98
    /** Return the basic type derived from the erased type of this MT-form.
d69abed3a07d 8050052: Small cleanups in java.lang.invoke code
vlivanov
parents: 25859
diff changeset
    99
     *  A basic type is erased (all references Object) and also has all primitive
d69abed3a07d 8050052: Small cleanups in java.lang.invoke code
vlivanov
parents: 25859
diff changeset
   100
     *  types (except int, long, float, double, void) normalized to int.
d69abed3a07d 8050052: Small cleanups in java.lang.invoke code
vlivanov
parents: 25859
diff changeset
   101
     *  Such basic types correspond to low-level JVM calling sequences.
d69abed3a07d 8050052: Small cleanups in java.lang.invoke code
vlivanov
parents: 25859
diff changeset
   102
     */
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   103
    public MethodType basicType() {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   104
        return basicType;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   105
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   106
26468
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   107
    public MethodHandle cachedMethodHandle(int which) {
27803
d04ca9d519ce 8057020: LambdaForm caches should support eviction
vlivanov
parents: 27295
diff changeset
   108
        SoftReference<MethodHandle> entry = methodHandles[which];
d04ca9d519ce 8057020: LambdaForm caches should support eviction
vlivanov
parents: 27295
diff changeset
   109
        return (entry != null) ? entry.get() : null;
26468
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   110
    }
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   111
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 27803
diff changeset
   112
    public synchronized MethodHandle setCachedMethodHandle(int which, MethodHandle mh) {
26468
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   113
        // Simulate a CAS, to avoid racy duplication of results.
27803
d04ca9d519ce 8057020: LambdaForm caches should support eviction
vlivanov
parents: 27295
diff changeset
   114
        SoftReference<MethodHandle> entry = methodHandles[which];
d04ca9d519ce 8057020: LambdaForm caches should support eviction
vlivanov
parents: 27295
diff changeset
   115
        if (entry != null) {
d04ca9d519ce 8057020: LambdaForm caches should support eviction
vlivanov
parents: 27295
diff changeset
   116
            MethodHandle prev = entry.get();
d04ca9d519ce 8057020: LambdaForm caches should support eviction
vlivanov
parents: 27295
diff changeset
   117
            if (prev != null) {
d04ca9d519ce 8057020: LambdaForm caches should support eviction
vlivanov
parents: 27295
diff changeset
   118
                return prev;
d04ca9d519ce 8057020: LambdaForm caches should support eviction
vlivanov
parents: 27295
diff changeset
   119
            }
d04ca9d519ce 8057020: LambdaForm caches should support eviction
vlivanov
parents: 27295
diff changeset
   120
        }
d04ca9d519ce 8057020: LambdaForm caches should support eviction
vlivanov
parents: 27295
diff changeset
   121
        methodHandles[which] = new SoftReference<>(mh);
d04ca9d519ce 8057020: LambdaForm caches should support eviction
vlivanov
parents: 27295
diff changeset
   122
        return mh;
26468
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   123
    }
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   124
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   125
    public LambdaForm cachedLambdaForm(int which) {
27803
d04ca9d519ce 8057020: LambdaForm caches should support eviction
vlivanov
parents: 27295
diff changeset
   126
        SoftReference<LambdaForm> entry = lambdaForms[which];
d04ca9d519ce 8057020: LambdaForm caches should support eviction
vlivanov
parents: 27295
diff changeset
   127
        return (entry != null) ? entry.get() : null;
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   128
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   129
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 27803
diff changeset
   130
    public synchronized LambdaForm setCachedLambdaForm(int which, LambdaForm form) {
24696
00479fa7c27f 8005873: JRuby test_respond_to.rb asserts with: MT-unsafe modification of inline cache
thartmann
parents: 23038
diff changeset
   131
        // Simulate a CAS, to avoid racy duplication of results.
27803
d04ca9d519ce 8057020: LambdaForm caches should support eviction
vlivanov
parents: 27295
diff changeset
   132
        SoftReference<LambdaForm> entry = lambdaForms[which];
d04ca9d519ce 8057020: LambdaForm caches should support eviction
vlivanov
parents: 27295
diff changeset
   133
        if (entry != null) {
d04ca9d519ce 8057020: LambdaForm caches should support eviction
vlivanov
parents: 27295
diff changeset
   134
            LambdaForm prev = entry.get();
d04ca9d519ce 8057020: LambdaForm caches should support eviction
vlivanov
parents: 27295
diff changeset
   135
            if (prev != null) {
d04ca9d519ce 8057020: LambdaForm caches should support eviction
vlivanov
parents: 27295
diff changeset
   136
                return prev;
d04ca9d519ce 8057020: LambdaForm caches should support eviction
vlivanov
parents: 27295
diff changeset
   137
            }
d04ca9d519ce 8057020: LambdaForm caches should support eviction
vlivanov
parents: 27295
diff changeset
   138
        }
d04ca9d519ce 8057020: LambdaForm caches should support eviction
vlivanov
parents: 27295
diff changeset
   139
        lambdaForms[which] = new SoftReference<>(form);
d04ca9d519ce 8057020: LambdaForm caches should support eviction
vlivanov
parents: 27295
diff changeset
   140
        return form;
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   141
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   142
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   143
    /**
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   144
     * Build an MTF for a given type, which must have all references erased to Object.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   145
     * This MTF will stand for that type and all un-erased variations.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   146
     * Eagerly compute some basic properties of the type, common to all variations.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   147
     */
27803
d04ca9d519ce 8057020: LambdaForm caches should support eviction
vlivanov
parents: 27295
diff changeset
   148
    @SuppressWarnings({"rawtypes", "unchecked"})
8821
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   149
    protected MethodTypeForm(MethodType erasedType) {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   150
        this.erasedType = erasedType;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   151
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   152
        Class<?>[] ptypes = erasedType.ptypes();
58038
aa3715655834 8230662: Remove dead code from MethodTypeForm
redestad
parents: 49935
diff changeset
   153
        int pslotCount = ptypes.length;
8821
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   154
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   155
        // Walk the argument types, looking for primitives.
58038
aa3715655834 8230662: Remove dead code from MethodTypeForm
redestad
parents: 49935
diff changeset
   156
        short primitiveCount = 0, longArgCount = 0;
58238
3386b9a8ef4d 8230768: Arrays of SoftReferences in MethodTypeForm should not be @Stable
redestad
parents: 58038
diff changeset
   157
        Class<?>[] erasedPtypes = ptypes;
3386b9a8ef4d 8230768: Arrays of SoftReferences in MethodTypeForm should not be @Stable
redestad
parents: 58038
diff changeset
   158
        Class<?>[] basicPtypes = erasedPtypes;
3386b9a8ef4d 8230768: Arrays of SoftReferences in MethodTypeForm should not be @Stable
redestad
parents: 58038
diff changeset
   159
        for (int i = 0; i < erasedPtypes.length; i++) {
3386b9a8ef4d 8230768: Arrays of SoftReferences in MethodTypeForm should not be @Stable
redestad
parents: 58038
diff changeset
   160
            Class<?> ptype = erasedPtypes[i];
3386b9a8ef4d 8230768: Arrays of SoftReferences in MethodTypeForm should not be @Stable
redestad
parents: 58038
diff changeset
   161
            if (ptype != Object.class) {
58038
aa3715655834 8230662: Remove dead code from MethodTypeForm
redestad
parents: 49935
diff changeset
   162
                ++primitiveCount;
58238
3386b9a8ef4d 8230768: Arrays of SoftReferences in MethodTypeForm should not be @Stable
redestad
parents: 58038
diff changeset
   163
                Wrapper w = Wrapper.forPrimitiveType(ptype);
58038
aa3715655834 8230662: Remove dead code from MethodTypeForm
redestad
parents: 49935
diff changeset
   164
                if (w.isDoubleWord())  ++longArgCount;
58238
3386b9a8ef4d 8230768: Arrays of SoftReferences in MethodTypeForm should not be @Stable
redestad
parents: 58038
diff changeset
   165
                if (w.isSubwordOrInt() && ptype != int.class) {
3386b9a8ef4d 8230768: Arrays of SoftReferences in MethodTypeForm should not be @Stable
redestad
parents: 58038
diff changeset
   166
                    if (basicPtypes == erasedPtypes)
3386b9a8ef4d 8230768: Arrays of SoftReferences in MethodTypeForm should not be @Stable
redestad
parents: 58038
diff changeset
   167
                        basicPtypes = basicPtypes.clone();
3386b9a8ef4d 8230768: Arrays of SoftReferences in MethodTypeForm should not be @Stable
redestad
parents: 58038
diff changeset
   168
                    basicPtypes[i] = int.class;
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   169
                }
8821
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   170
            }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   171
        }
58038
aa3715655834 8230662: Remove dead code from MethodTypeForm
redestad
parents: 49935
diff changeset
   172
        pslotCount += longArgCount;                  // #slots = #args + #longs
58238
3386b9a8ef4d 8230768: Arrays of SoftReferences in MethodTypeForm should not be @Stable
redestad
parents: 58038
diff changeset
   173
        Class<?> returnType = erasedType.returnType();
3386b9a8ef4d 8230768: Arrays of SoftReferences in MethodTypeForm should not be @Stable
redestad
parents: 58038
diff changeset
   174
        Class<?> basicReturnType = returnType;
3386b9a8ef4d 8230768: Arrays of SoftReferences in MethodTypeForm should not be @Stable
redestad
parents: 58038
diff changeset
   175
        if (returnType != Object.class) {
58038
aa3715655834 8230662: Remove dead code from MethodTypeForm
redestad
parents: 49935
diff changeset
   176
            ++primitiveCount; // even void.class counts as a prim here
58238
3386b9a8ef4d 8230768: Arrays of SoftReferences in MethodTypeForm should not be @Stable
redestad
parents: 58038
diff changeset
   177
            Wrapper w = Wrapper.forPrimitiveType(returnType);
3386b9a8ef4d 8230768: Arrays of SoftReferences in MethodTypeForm should not be @Stable
redestad
parents: 58038
diff changeset
   178
            if (w.isSubwordOrInt() && returnType != int.class)
3386b9a8ef4d 8230768: Arrays of SoftReferences in MethodTypeForm should not be @Stable
redestad
parents: 58038
diff changeset
   179
                basicReturnType = int.class;
8821
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   180
        }
58238
3386b9a8ef4d 8230768: Arrays of SoftReferences in MethodTypeForm should not be @Stable
redestad
parents: 58038
diff changeset
   181
        if (erasedPtypes == basicPtypes && basicReturnType == returnType) {
3386b9a8ef4d 8230768: Arrays of SoftReferences in MethodTypeForm should not be @Stable
redestad
parents: 58038
diff changeset
   182
            // Basic type
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   183
            this.basicType = erasedType;
58238
3386b9a8ef4d 8230768: Arrays of SoftReferences in MethodTypeForm should not be @Stable
redestad
parents: 58038
diff changeset
   184
3386b9a8ef4d 8230768: Arrays of SoftReferences in MethodTypeForm should not be @Stable
redestad
parents: 58038
diff changeset
   185
            if (pslotCount >= 256)  throw newIllegalArgumentException("too many arguments");
3386b9a8ef4d 8230768: Arrays of SoftReferences in MethodTypeForm should not be @Stable
redestad
parents: 58038
diff changeset
   186
3386b9a8ef4d 8230768: Arrays of SoftReferences in MethodTypeForm should not be @Stable
redestad
parents: 58038
diff changeset
   187
            this.primitiveCount = primitiveCount;
3386b9a8ef4d 8230768: Arrays of SoftReferences in MethodTypeForm should not be @Stable
redestad
parents: 58038
diff changeset
   188
            this.parameterSlotCount = (short)pslotCount;
3386b9a8ef4d 8230768: Arrays of SoftReferences in MethodTypeForm should not be @Stable
redestad
parents: 58038
diff changeset
   189
            this.lambdaForms   = new SoftReference[LF_LIMIT];
3386b9a8ef4d 8230768: Arrays of SoftReferences in MethodTypeForm should not be @Stable
redestad
parents: 58038
diff changeset
   190
            this.methodHandles = new SoftReference[MH_LIMIT];
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   191
        } else {
58238
3386b9a8ef4d 8230768: Arrays of SoftReferences in MethodTypeForm should not be @Stable
redestad
parents: 58038
diff changeset
   192
            this.basicType = MethodType.makeImpl(basicReturnType, basicPtypes, true);
26467
d69abed3a07d 8050052: Small cleanups in java.lang.invoke code
vlivanov
parents: 25859
diff changeset
   193
            // fill in rest of data from the basic type:
d69abed3a07d 8050052: Small cleanups in java.lang.invoke code
vlivanov
parents: 25859
diff changeset
   194
            MethodTypeForm that = this.basicType.form();
d69abed3a07d 8050052: Small cleanups in java.lang.invoke code
vlivanov
parents: 25859
diff changeset
   195
            assert(this != that);
58238
3386b9a8ef4d 8230768: Arrays of SoftReferences in MethodTypeForm should not be @Stable
redestad
parents: 58038
diff changeset
   196
58038
aa3715655834 8230662: Remove dead code from MethodTypeForm
redestad
parents: 49935
diff changeset
   197
            this.parameterSlotCount = that.parameterSlotCount;
aa3715655834 8230662: Remove dead code from MethodTypeForm
redestad
parents: 49935
diff changeset
   198
            this.primitiveCount = that.primitiveCount;
26468
2d57604f9299 8050053: Improve caching of different invokers
vlivanov
parents: 26467
diff changeset
   199
            this.methodHandles = null;
26467
d69abed3a07d 8050052: Small cleanups in java.lang.invoke code
vlivanov
parents: 25859
diff changeset
   200
            this.lambdaForms = null;
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10419
diff changeset
   201
        }
8821
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   202
    }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   203
58238
3386b9a8ef4d 8230768: Arrays of SoftReferences in MethodTypeForm should not be @Stable
redestad
parents: 58038
diff changeset
   204
    public int parameterCount() {
58038
aa3715655834 8230662: Remove dead code from MethodTypeForm
redestad
parents: 49935
diff changeset
   205
        return erasedType.parameterCount();
8821
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   206
    }
58238
3386b9a8ef4d 8230768: Arrays of SoftReferences in MethodTypeForm should not be @Stable
redestad
parents: 58038
diff changeset
   207
    public int parameterSlotCount() {
58038
aa3715655834 8230662: Remove dead code from MethodTypeForm
redestad
parents: 49935
diff changeset
   208
        return parameterSlotCount;
8821
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   209
    }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   210
    public boolean hasPrimitives() {
58038
aa3715655834 8230662: Remove dead code from MethodTypeForm
redestad
parents: 49935
diff changeset
   211
        return primitiveCount != 0;
8821
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   212
    }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   213
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   214
    static MethodTypeForm findForm(MethodType mt) {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   215
        MethodType erased = canonicalize(mt, ERASE, ERASE);
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   216
        if (erased == null) {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   217
            // It is already erased.  Make a new MethodTypeForm.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   218
            return new MethodTypeForm(mt);
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   219
        } else {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   220
            // Share the MethodTypeForm with the erased version.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   221
            return erased.form();
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   222
        }
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   223
    }
8821
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   224
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   225
    /** Codes for {@link #canonicalize(java.lang.Class, int)}.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   226
     * ERASE means change every reference to {@code Object}.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   227
     * WRAP means convert primitives (including {@code void} to their
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   228
     * corresponding wrapper types.  UNWRAP means the reverse of WRAP.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   229
     * INTS means convert all non-void primitive types to int or long,
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   230
     * according to size.  LONGS means convert all non-void primitives
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   231
     * to long, regardless of size.  RAW_RETURN means convert a type
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   232
     * (assumed to be a return type) to int if it is smaller than an int,
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   233
     * or if it is void.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   234
     */
58038
aa3715655834 8230662: Remove dead code from MethodTypeForm
redestad
parents: 49935
diff changeset
   235
    public static final int ERASE = 1, WRAP = 2, UNWRAP = 3, INTS = 4, LONGS = 5, RAW_RETURN = 6;
8821
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   236
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   237
    /** Canonicalize the types in the given method type.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   238
     * If any types change, intern the new type, and return it.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   239
     * Otherwise return null.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   240
     */
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   241
    public static MethodType canonicalize(MethodType mt, int howRet, int howArgs) {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   242
        Class<?>[] ptypes = mt.ptypes();
58238
3386b9a8ef4d 8230768: Arrays of SoftReferences in MethodTypeForm should not be @Stable
redestad
parents: 58038
diff changeset
   243
        Class<?>[] ptypesCanonical = canonicalizeAll(ptypes, howArgs);
8821
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   244
        Class<?> rtype = mt.returnType();
58238
3386b9a8ef4d 8230768: Arrays of SoftReferences in MethodTypeForm should not be @Stable
redestad
parents: 58038
diff changeset
   245
        Class<?> rtypeCanonical = canonicalize(rtype, howRet);
3386b9a8ef4d 8230768: Arrays of SoftReferences in MethodTypeForm should not be @Stable
redestad
parents: 58038
diff changeset
   246
        if (ptypesCanonical == null && rtypeCanonical == null) {
8821
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   247
            // It is already canonical.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   248
            return null;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   249
        }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   250
        // Find the erased version of the method type:
58238
3386b9a8ef4d 8230768: Arrays of SoftReferences in MethodTypeForm should not be @Stable
redestad
parents: 58038
diff changeset
   251
        if (rtypeCanonical == null)  rtypeCanonical = rtype;
3386b9a8ef4d 8230768: Arrays of SoftReferences in MethodTypeForm should not be @Stable
redestad
parents: 58038
diff changeset
   252
        if (ptypesCanonical == null)  ptypesCanonical = ptypes;
3386b9a8ef4d 8230768: Arrays of SoftReferences in MethodTypeForm should not be @Stable
redestad
parents: 58038
diff changeset
   253
        return MethodType.makeImpl(rtypeCanonical, ptypesCanonical, true);
8821
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   254
    }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   255
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   256
    /** Canonicalize the given return or param type.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   257
     *  Return null if the type is already canonicalized.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   258
     */
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   259
    static Class<?> canonicalize(Class<?> t, int how) {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   260
        Class<?> ct;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   261
        if (t == Object.class) {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   262
            // no change, ever
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   263
        } else if (!t.isPrimitive()) {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   264
            switch (how) {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   265
                case UNWRAP:
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   266
                    ct = Wrapper.asPrimitiveType(t);
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   267
                    if (ct != t)  return ct;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   268
                    break;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   269
                case RAW_RETURN:
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   270
                case ERASE:
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   271
                    return Object.class;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   272
            }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   273
        } else if (t == void.class) {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   274
            // no change, usually
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   275
            switch (how) {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   276
                case RAW_RETURN:
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   277
                    return int.class;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   278
                case WRAP:
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   279
                    return Void.class;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   280
            }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   281
        } else {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   282
            // non-void primitive
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   283
            switch (how) {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   284
                case WRAP:
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   285
                    return Wrapper.asWrapperType(t);
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   286
                case INTS:
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   287
                    if (t == int.class || t == long.class)
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   288
                        return null;  // no change
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   289
                    if (t == double.class)
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   290
                        return long.class;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   291
                    return int.class;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   292
                case LONGS:
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   293
                    if (t == long.class)
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   294
                        return null;  // no change
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   295
                    return long.class;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   296
                case RAW_RETURN:
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   297
                    if (t == int.class || t == long.class ||
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   298
                        t == float.class || t == double.class)
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   299
                        return null;  // no change
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   300
                    // everything else returns as an int
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   301
                    return int.class;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   302
            }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   303
        }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   304
        // no change; return null to signify
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   305
        return null;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   306
    }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   307
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   308
    /** Canonicalize each param type in the given array.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   309
     *  Return null if all types are already canonicalized.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   310
     */
26467
d69abed3a07d 8050052: Small cleanups in java.lang.invoke code
vlivanov
parents: 25859
diff changeset
   311
    static Class<?>[] canonicalizeAll(Class<?>[] ts, int how) {
8821
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   312
        Class<?>[] cs = null;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   313
        for (int imax = ts.length, i = 0; i < imax; i++) {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   314
            Class<?> c = canonicalize(ts[i], how);
58038
aa3715655834 8230662: Remove dead code from MethodTypeForm
redestad
parents: 49935
diff changeset
   315
            // Void parameters may be unwrapped to void; ignore those
aa3715655834 8230662: Remove dead code from MethodTypeForm
redestad
parents: 49935
diff changeset
   316
            if (c != null && c != void.class) {
8821
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   317
                if (cs == null)
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   318
                    cs = ts.clone();
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   319
                cs[i] = c;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   320
            }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   321
        }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   322
        return cs;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   323
    }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   324
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   325
    @Override
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   326
    public String toString() {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   327
        return "Form"+erasedType;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   328
    }
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   329
}