jdk/src/java.base/share/classes/java/lang/invoke/SimpleMethodHandle.java
author shade
Tue, 17 May 2016 22:28:00 +0300
changeset 38372 017d7578731c
parent 26472 71b6a6f208c0
permissions -rw-r--r--
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles Reviewed-by: psandoz, redestad
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
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 13610
diff changeset
     2
 * Copyright (c) 2008, 2012, 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: 2764
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: 2764
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: 2764
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2764
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2764
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
26472
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    28
import static java.lang.invoke.LambdaForm.BasicType.*;
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    29
import static java.lang.invoke.MethodHandleStatics.*;
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    30
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    31
/**
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 8822
diff changeset
    32
 * A method handle whose behavior is determined only by its LambdaForm.
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    33
 * @author jrose
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    34
 */
26472
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    35
final class SimpleMethodHandle extends BoundMethodHandle {
13610
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 13423
diff changeset
    36
    private SimpleMethodHandle(MethodType type, LambdaForm form) {
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 8822
diff changeset
    37
        super(type, form);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 8822
diff changeset
    38
    }
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    39
26472
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    40
    /*non-public*/ static BoundMethodHandle make(MethodType type, LambdaForm form) {
13610
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 13423
diff changeset
    41
        return new SimpleMethodHandle(type, form);
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 13423
diff changeset
    42
    }
26470
1586df597397 8050173: Add j.l.i.MethodHandle.copyWith(MethodType, LambdaForm)
vlivanov
parents: 26469
diff changeset
    43
26472
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    44
    /*non-public*/ static final SpeciesData SPECIES_DATA = SpeciesData.EMPTY;
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    45
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    46
    /*non-public*/ public SpeciesData speciesData() {
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    47
            return SPECIES_DATA;
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    48
    }
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    49
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    50
    @Override
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    51
    /*non-public*/ BoundMethodHandle copyWith(MethodType mt, LambdaForm lf) {
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    52
        return make(mt, lf);
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    53
    }
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    54
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    55
    @Override
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    56
    String internalProperties() {
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    57
        return "\n& Class="+getClass().getSimpleName();
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    58
    }
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    59
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    60
    @Override
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    61
    /*non-public*/ public int fieldCount() {
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    62
        return 0;
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    63
    }
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    64
26470
1586df597397 8050173: Add j.l.i.MethodHandle.copyWith(MethodType, LambdaForm)
vlivanov
parents: 26469
diff changeset
    65
    @Override
26472
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    66
    /*non-public*/ final BoundMethodHandle copyWithExtendL(MethodType mt, LambdaForm lf, Object narg) {
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    67
        return BoundMethodHandle.bindSingle(mt, lf, narg); // Use known fast path.
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    68
    }
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    69
    @Override
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    70
    /*non-public*/ final BoundMethodHandle copyWithExtendI(MethodType mt, LambdaForm lf, int narg) {
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    71
        try {
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    72
            return (BoundMethodHandle) SPECIES_DATA.extendWith(I_TYPE).constructor().invokeBasic(mt, lf, narg);
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    73
        } catch (Throwable ex) {
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    74
            throw uncaughtException(ex);
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    75
        }
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    76
    }
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    77
    @Override
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    78
    /*non-public*/ final BoundMethodHandle copyWithExtendJ(MethodType mt, LambdaForm lf, long narg) {
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    79
        try {
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    80
            return (BoundMethodHandle) SPECIES_DATA.extendWith(J_TYPE).constructor().invokeBasic(mt, lf, narg);
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    81
        } catch (Throwable ex) {
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    82
            throw uncaughtException(ex);
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    83
        }
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    84
    }
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    85
    @Override
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    86
    /*non-public*/ final BoundMethodHandle copyWithExtendF(MethodType mt, LambdaForm lf, float narg) {
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    87
        try {
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    88
            return (BoundMethodHandle) SPECIES_DATA.extendWith(F_TYPE).constructor().invokeBasic(mt, lf, narg);
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    89
        } catch (Throwable ex) {
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    90
            throw uncaughtException(ex);
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    91
        }
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    92
    }
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    93
    @Override
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    94
    /*non-public*/ final BoundMethodHandle copyWithExtendD(MethodType mt, LambdaForm lf, double narg) {
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    95
        try {
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    96
            return (BoundMethodHandle) SPECIES_DATA.extendWith(D_TYPE).constructor().invokeBasic(mt, lf, narg);
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    97
        } catch (Throwable ex) {
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    98
            throw uncaughtException(ex);
71b6a6f208c0 8050057: Improve caching of MethodHandle reinvokers
vlivanov
parents: 26470
diff changeset
    99
        }
26470
1586df597397 8050173: Add j.l.i.MethodHandle.copyWith(MethodType, LambdaForm)
vlivanov
parents: 26469
diff changeset
   100
    }
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   101
}