jdk/src/java.base/share/classes/java/lang/invoke/VarHandle.java
author amurillo
Sat, 14 May 2016 09:11:07 -0700
changeset 38367 21801e8e9344
parent 37792 dd626e6f5967
parent 38358 cb99c6d2af1b
child 38368 c8eb5d6812c5
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
     1
/*
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
     2
 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
     4
 *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    10
 *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    15
 * accompanied this code).
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    16
 *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    20
 *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    23
 * questions.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    24
 */
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    25
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    26
package java.lang.invoke;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    27
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    28
import jdk.internal.HotSpotIntrinsicCandidate;
38356
1e4ecca97792 8155794: Move Objects.checkIndex BiFunction accepting methods to an internal package
psandoz
parents: 37345
diff changeset
    29
import jdk.internal.util.Preconditions;
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    30
import jdk.internal.vm.annotation.ForceInline;
37792
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
    31
import jdk.internal.vm.annotation.Stable;
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    32
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    33
import java.lang.reflect.Method;
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
    34
import java.util.HashMap;
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    35
import java.util.List;
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
    36
import java.util.Map;
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    37
import java.util.function.BiFunction;
37345
9cb6e1141bdb 8146458: Improve exception reporting for Objects.checkIndex/checkFromToIndex/checkFromIndexSize
psandoz
parents: 37344
diff changeset
    38
import java.util.function.Function;
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    39
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    40
import static java.lang.invoke.MethodHandleStatics.UNSAFE;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    41
import static java.lang.invoke.MethodHandleStatics.newInternalError;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    42
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    43
/**
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    44
 * A VarHandle is a dynamically typed reference to a variable, or to a
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    45
 * parametrically-defined family of variables, including static fields,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    46
 * non-static fields, array elements, or components of an off-heap data
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    47
 * structure.  Access to such variables is supported under various
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    48
 * <em>access modes</em>, including plain read/write access, volatile
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    49
 * read/write access, and compare-and-swap.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    50
 *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    51
 * <p>VarHandles are immutable and have no visible state.  VarHandles cannot be
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    52
 * subclassed by the user.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    53
 *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    54
 * <p>A VarHandle has:
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    55
 * <ul>
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    56
 * <li>a {@link #varType variable type}, referred to as {@code T}, which is the
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    57
 * type of variable(s) referenced by this VarHandle;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    58
 * <li>a list of {@link #coordinateTypes coordinate types}, referred to as
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    59
 * {@code CT}, where the types (primitive and reference) are represented by
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    60
 * {@link Class} objects).  A list of arguments corresponding to instances of
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    61
 * the coordinate types uniquely locates a variable referenced by this
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    62
 * VarHandle; and
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    63
 * <li>a <em>shape</em>, that combines the variable type and coordinate types,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    64
 * and is declared with the notation {@code (CT : T)}.  An empty list of
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    65
 * coordinate types is declared as {@code (empty)}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    66
 * </ul>
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    67
 *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    68
 * <p>Factory methods that produce or {@link java.lang.invoke.MethodHandles.Lookup
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    69
 * lookup} VarHandle instances document the supported variable type, coordinate
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    70
 * types, and shape.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    71
 *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    72
 * For example, a VarHandle referencing a non-static field will declare a shape
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    73
 * of {@code (R : T)}, where {@code R} is the receiver type and
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    74
 * {@code T} is the field type, and where the VarHandle and an instance of the
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    75
 * receiver type can be utilized to access the field variable.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    76
 * A VarHandle referencing array elements will declare a shape of
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    77
 * {@code (T[], int : T)}, where {@code T[]} is the array type and {@code T}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    78
 * its component type, and where the VarHandle, an instance of the array type,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    79
 * and an {@code int} index can be utilized to access an array element variable.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    80
 *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    81
 * <p>Each access mode is associated with a
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    82
 * <a href="MethodHandle.html#sigpoly">signature polymorphic</a> method of the
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    83
 * same name, where the VarHandle shape and access mode uniquely determine the
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    84
 * canonical {@link #accessModeType(AccessMode) access mode type},
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    85
 * which in turn determines the matching constraints on a valid symbolic
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    86
 * type descriptor at the call site of an access mode's method
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    87
 * <a href="VarHandle.html#invoke">invocation</a>.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    88
 *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    89
 * As such, VarHandles are dynamically and strongly typed.  Their arity,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    90
 * argument types, and return type of an access mode method invocation are not
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    91
 * statically checked.  If they, and associated values, do not match the arity
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    92
 * and types of the access mode's type, an exception will be thrown.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    93
 *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    94
 * The parameter types of an access mode method type will consist of those that
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    95
 * are the VarHandles's coordinate types (in order), followed by access mode
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    96
 * parameter types specific to the access mode.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    97
 *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    98
 * <p>An access mode's method documents the form of its method signature, which
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    99
 * is derived from the access mode parameter types.  The form is declared with
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   100
 * the notation {@code (CT, P1 p1, P2 p2, ..., PN pn)R}, where {@code CT} is the
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   101
 * coordinate types (as documented by a VarHandle factory method), {@code P1},
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   102
 * {@code P2} and {@code PN} are the first, second and the n'th access mode
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   103
 * parameters named {@code p1}, {@code p2} and {@code pn} respectively, and
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   104
 * {@code R} is the return type.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   105
 *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   106
 * For example, for the generic shape of {@code (CT : T)} the
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   107
 * {@link #compareAndSet} access mode method documents that its method
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   108
 * signature is of the form {@code (CT, T expectedValue, T newValue)boolean},
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   109
 * where the parameter types named {@code extendedValue} and {@code newValue}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   110
 * are the access mode parameter types.  If the VarHandle accesses array
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   111
 * elements with a shape of say {@code (T[], int : T)} then the access mode
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   112
 * method type is {@code (T[], int, T, T)boolean}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   113
 *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   114
 * <p>Access modes are grouped into the following categories:
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   115
 * <ul>
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   116
 * <li>read access modes that get the value of a variable under specified
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   117
 * memory ordering effects.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   118
 * The set of corresponding access mode methods belonging to this group
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   119
 * consists of the methods
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   120
 * {@link #get get},
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   121
 * {@link #getVolatile getVolatile},
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   122
 * {@link #getAcquire getAcquire},
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   123
 * {@link #getOpaque getOpaque}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   124
 * <li>write access modes that set the value of a variable under specified
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   125
 * memory ordering effects.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   126
 * The set of corresponding access mode methods belonging to this group
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   127
 * consists of the methods
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   128
 * {@link #set set},
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   129
 * {@link #setVolatile setVolatile},
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   130
 * {@link #setRelease setRelease},
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   131
 * {@link #setOpaque setOpaque}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   132
 * <li>atomic update access modes that, for example, atomically compare and set
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   133
 * the value of a variable under specified memory ordering effects.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   134
 * The set of corresponding access mode methods belonging to this group
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   135
 * consists of the methods
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   136
 * {@link #compareAndSet compareAndSet},
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   137
 * {@link #weakCompareAndSet weakCompareAndSet},
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   138
 * {@link #weakCompareAndSetVolatile weakCompareAndSetVolatile},
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   139
 * {@link #weakCompareAndSetAcquire weakCompareAndSetAcquire},
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   140
 * {@link #weakCompareAndSetRelease weakCompareAndSetRelease},
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   141
 * {@link #compareAndExchangeAcquire compareAndExchangeAcquire},
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   142
 * {@link #compareAndExchangeVolatile compareAndExchangeVolatile},
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   143
 * {@link #compareAndExchangeRelease compareAndExchangeRelease},
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   144
 * {@link #getAndSet getAndSet}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   145
 * <li>numeric atomic update access modes that, for example, atomically get and
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   146
 * set with addition the value of a variable under specified memory ordering
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   147
 * effects.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   148
 * The set of corresponding access mode methods belonging to this group
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   149
 * consists of the methods
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   150
 * {@link #getAndAdd getAndAdd},
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   151
 * {@link #addAndGet addAndGet}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   152
 * </ul>
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   153
 *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   154
 * <p>Factory methods that produce or {@link java.lang.invoke.MethodHandles.Lookup
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   155
 * lookup} VarHandle instances document the set of access modes that are
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   156
 * supported, which may also include documenting restrictions based on the
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   157
 * variable type and whether a variable is read-only.  If an access mode is not
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   158
 * supported then the corresponding signature-polymorphic method will on
37344
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
   159
 * invocation throw an {@code UnsupportedOperationException}.  Factory methods
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
   160
 * should document any additional undeclared exceptions that may be thrown by
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
   161
 * access mode methods.
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   162
 * The {@link #get get} access mode is supported for all
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   163
 * VarHandle instances and the corresponding method never throws
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   164
 * {@code UnsupportedOperationException}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   165
 * If a VarHandle references a read-only variable (for example a {@code final}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   166
 * field) then write, atomic update and numeric atomic update access modes are
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   167
 * not supported and corresponding methods throw
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   168
 * {@code UnsupportedOperationException}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   169
 * Read/write access modes (if supported), with the exception of
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   170
 * {@code get} and {@code set}, provide atomic access for
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   171
 * reference types and all primitive types.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   172
 * Unless stated otherwise in the documentation of a factory method, the access
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   173
 * modes {@code get} and {@code set} (if supported) provide atomic access for
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   174
 * reference types and all primitives types, with the exception of {@code long}
37344
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
   175
 * and {@code double} on 32-bit platforms.
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   176
 *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   177
 * <p>Access modes will override any memory ordering effects specified at
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   178
 * the declaration site of a variable.  For example, a VarHandle accessing a
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   179
 * a field using the {@code get} access mode will access the field as
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   180
 * specified <em>by its access mode</em> even if that field is declared
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   181
 * {@code volatile}.  When mixed access is performed extreme care should be
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   182
 * taken since the Java Memory Model may permit surprising results.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   183
 *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   184
 * <p>In addition to supporting access to variables under various access modes,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   185
 * a set of static methods, referred to as memory fence methods, is also
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   186
 * provided for fine-grained control of memory ordering.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   187
 *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   188
 * The Java Language Specification permits other threads to observe operations
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   189
 * as if they were executed in orders different than are apparent in program
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   190
 * source code, subject to constraints arising, for example, from the use of
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   191
 * locks, {@code volatile} fields or VarHandles.  The static methods,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   192
 * {@link #fullFence fullFence}, {@link #acquireFence acquireFence},
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   193
 * {@link #releaseFence releaseFence}, {@link #loadLoadFence loadLoadFence} and
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   194
 * {@link #storeStoreFence storeStoreFence}, can also be used to impose
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   195
 * constraints.  Their specifications, as is the case for certain access modes,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   196
 * are phrased in terms of the lack of "reorderings" -- observable ordering
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   197
 * effects that might otherwise occur if the fence was not present.  More
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   198
 * precise phrasing of the specification of access mode methods and memory fence
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   199
 * methods may accompany future updates of the Java Language Specification.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   200
 *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   201
 * <h1>Compilation of an access mode's method</h1>
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   202
 * A Java method call expression naming an access mode method can invoke a
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   203
 * VarHandle from Java source code.  From the viewpoint of source code, these
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   204
 * methods can take any arguments and their polymorphic result (if expressed)
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   205
 * can be cast to any return type.  Formally this is accomplished by giving the
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   206
 * access mode methods variable arity {@code Object} arguments and
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   207
 * {@code Object} return types (if the return type is polymorphic), but they
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   208
 * have an additional quality called <em>signature polymorphism</em> which
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   209
 * connects this freedom of invocation directly to the JVM execution stack.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   210
 * <p>
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   211
 * As is usual with virtual methods, source-level calls to access mode methods
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   212
 * compile to an {@code invokevirtual} instruction.  More unusually, the
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   213
 * compiler must record the actual argument types, and may not perform method
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   214
 * invocation conversions on the arguments.  Instead, it must generate
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   215
 * instructions to push them on the stack according to their own unconverted
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   216
 * types.  The VarHandle object itself will be pushed on the stack before the
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   217
 * arguments.  The compiler then generates an {@code invokevirtual} instruction
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   218
 * that invokes the access mode method with a symbolic type descriptor which
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   219
 * describes the argument and return types.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   220
 * <p>
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   221
 * To issue a complete symbolic type descriptor, the compiler must also
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   222
 * determine the return type (if polymorphic).  This is based on a cast on the
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   223
 * method invocation expression, if there is one, or else {@code Object} if the
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   224
 * invocation is an expression, or else {@code void} if the invocation is a
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   225
 * statement.  The cast may be to a primitive type (but not {@code void}).
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   226
 * <p>
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   227
 * As a corner case, an uncasted {@code null} argument is given a symbolic type
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   228
 * descriptor of {@code java.lang.Void}.  The ambiguity with the type
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   229
 * {@code Void} is harmless, since there are no references of type {@code Void}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   230
 * except the null reference.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   231
 *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   232
 *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   233
 * <h1><a name="invoke">Invocation of an access mode's method</a></h1>
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   234
 * The first time an {@code invokevirtual} instruction is executed it is linked
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   235
 * by symbolically resolving the names in the instruction and verifying that
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   236
 * the method call is statically legal.  This also holds for calls to access mode
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   237
 * methods.  In this case, the symbolic type descriptor emitted by the compiler
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   238
 * is checked for correct syntax, and names it contains are resolved.  Thus, an
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   239
 * {@code invokevirtual} instruction which invokes an access mode method will
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   240
 * always link, as long as the symbolic type descriptor is syntactically
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   241
 * well-formed and the types exist.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   242
 * <p>
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   243
 * When the {@code invokevirtual} is executed after linking, the receiving
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   244
 * VarHandle's access mode type is first checked by the JVM to ensure that it
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   245
 * matches the symbolic type descriptor.  If the type
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   246
 * match fails, it means that the access mode method which the caller is
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   247
 * invoking is not present on the individual VarHandle being invoked.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   248
 *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   249
 * <p>
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   250
 * Invocation of an access mode's signature-polymorphic method behaves as if an
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   251
 * invocation of {@link MethodHandle#invoke}, where the receiving method handle
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   252
 * is bound to a VarHandle instance and the access mode.  More specifically, the
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   253
 * following:
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   254
 * <pre> {@code
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   255
 * VarHandle vh = ..
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   256
 * R r = (R) vh.{access-mode}(p1, p2, ..., pN);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   257
 * }</pre>
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   258
 * behaves as if (modulo the access mode methods do not declare throwing of
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   259
 * {@code Throwable}):
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   260
 * <pre> {@code
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   261
 * VarHandle vh = ..
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   262
 * MethodHandle mh = MethodHandles.varHandleExactInvoker(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   263
 *                       VarHandle.AccessMode.{access-mode},
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   264
 *                       vh.accessModeType(VarHandle.AccessMode.{access-mode}));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   265
 *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   266
 * mh = mh.bindTo(vh);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   267
 * R r = (R) mh.invoke(p1, p2, ..., pN)
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   268
 * }</pre>
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   269
 * or, more concisely, behaves as if:
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   270
 * <pre> {@code
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   271
 * VarHandle vh = ..
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   272
 * MethodHandle mh = vh.toMethodHandle(VarHandle.AccessMode.{access-mode});
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   273
 *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   274
 * R r = (R) mh.invoke(p1, p2, ..., pN)
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   275
 * }</pre>
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   276
 * In terms of equivalent {@code invokevirtual} bytecode behaviour an access
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   277
 * mode method invocation is equivalent to:
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   278
 * <pre> {@code
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   279
 * MethodHandle mh = MethodHandles.lookup().findVirtual(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   280
 *                       VarHandle.class,
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
   281
 *                       VarHandle.AccessMode.{access-mode}.methodName(),
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   282
 *                       MethodType.methodType(R, p1, p2, ..., pN));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   283
 *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   284
 * R r = (R) mh.invokeExact(vh, p1, p2, ..., pN)
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   285
 * }</pre>
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   286
 * where the desired method type is the symbolic type descriptor and a
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   287
 * {@link MethodHandle#invokeExact} is performed, since before invocation of the
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   288
 * target, the handle will apply reference casts as necessary and box, unbox, or
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   289
 * widen primitive values, as if by {@link MethodHandle#asType asType} (see also
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   290
 * {@link MethodHandles#varHandleInvoker}).
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   291
 *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   292
 * <h1>Invocation checking</h1>
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   293
 * In typical programs, VarHandle access mode type matching will usually
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   294
 * succeed.  But if a match fails, the JVM will throw a
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   295
 * {@link WrongMethodTypeException}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   296
 * <p>
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   297
 * Thus, an access mode type mismatch which might show up as a linkage error
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   298
 * in a statically typed program can show up as a dynamic
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   299
 * {@code WrongMethodTypeException} in a program which uses VarHandles.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   300
 * <p>
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   301
 * Because access mode types contain "live" {@code Class} objects, method type
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   302
 * matching takes into account both type names and class loaders.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   303
 * Thus, even if a VarHandle {@code VH} is created in one class loader
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   304
 * {@code L1} and used in another {@code L2}, VarHandle access mode method
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   305
 * calls are type-safe, because the caller's symbolic type descriptor, as
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   306
 * resolved in {@code L2}, is matched against the original callee method's
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   307
 * symbolic type descriptor, as resolved in {@code L1}.  The resolution in
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   308
 * {@code L1} happens when {@code VH} is created and its access mode types are
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   309
 * assigned, while the resolution in {@code L2} happens when the
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   310
 * {@code invokevirtual} instruction is linked.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   311
 * <p>
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   312
 * Apart from type descriptor checks, a VarHandles's capability to
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   313
 * access it's variables is unrestricted.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   314
 * If a VarHandle is formed on a non-public variable by a class that has access
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   315
 * to that variable, the resulting VarHandle can be used in any place by any
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   316
 * caller who receives a reference to it.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   317
 * <p>
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   318
 * Unlike with the Core Reflection API, where access is checked every time a
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   319
 * reflective method is invoked, VarHandle access checking is performed
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   320
 * <a href="MethodHandles.Lookup.html#access">when the VarHandle is
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   321
 * created</a>.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   322
 * Thus, VarHandles to non-public variables, or to variables in non-public
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   323
 * classes, should generally be kept secret.  They should not be passed to
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   324
 * untrusted code unless their use from the untrusted code would be harmless.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   325
 *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   326
 *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   327
 * <h1>VarHandle creation</h1>
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   328
 * Java code can create a VarHandle that directly accesses any field that is
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   329
 * accessible to that code.  This is done via a reflective, capability-based
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   330
 * API called {@link java.lang.invoke.MethodHandles.Lookup
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   331
 * MethodHandles.Lookup}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   332
 * For example, a VarHandle for a non-static field can be obtained
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   333
 * from {@link java.lang.invoke.MethodHandles.Lookup#findVarHandle
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   334
 * Lookup.findVarHandle}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   335
 * There is also a conversion method from Core Reflection API objects,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   336
 * {@link java.lang.invoke.MethodHandles.Lookup#unreflectVarHandle
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   337
 * Lookup.unreflectVarHandle}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   338
 * <p>
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   339
 * Access to protected field members is restricted to receivers only of the
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   340
 * accessing class, or one of its subclasses, and the accessing class must in
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   341
 * turn be a subclass (or package sibling) of the protected member's defining
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   342
 * class.  If a VarHandle refers to a protected non-static field of a declaring
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   343
 * class outside the current package, the receiver argument will be narrowed to
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   344
 * the type of the accessing class.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   345
 *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   346
 * <h1>Interoperation between VarHandles and the Core Reflection API</h1>
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   347
 * Using factory methods in the {@link java.lang.invoke.MethodHandles.Lookup
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   348
 * Lookup} API, any field represented by a Core Reflection API object
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   349
 * can be converted to a behaviorally equivalent VarHandle.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   350
 * For example, a reflective {@link java.lang.reflect.Field Field} can
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   351
 * be converted to a VarHandle using
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   352
 * {@link java.lang.invoke.MethodHandles.Lookup#unreflectVarHandle
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   353
 * Lookup.unreflectVarHandle}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   354
 * The resulting VarHandles generally provide more direct and efficient
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   355
 * access to the underlying fields.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   356
 * <p>
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   357
 * As a special case, when the Core Reflection API is used to view the
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   358
 * signature polymorphic access mode methods in this class, they appear as
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   359
 * ordinary non-polymorphic methods.  Their reflective appearance, as viewed by
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   360
 * {@link java.lang.Class#getDeclaredMethod Class.getDeclaredMethod},
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   361
 * is unaffected by their special status in this API.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   362
 * For example, {@link java.lang.reflect.Method#getModifiers
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   363
 * Method.getModifiers}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   364
 * will report exactly those modifier bits required for any similarly
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   365
 * declared method, including in this case {@code native} and {@code varargs}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   366
 * bits.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   367
 * <p>
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   368
 * As with any reflected method, these methods (when reflected) may be invoked
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   369
 * directly via {@link java.lang.reflect.Method#invoke java.lang.reflect.Method.invoke},
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   370
 * via JNI, or indirectly via
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   371
 * {@link java.lang.invoke.MethodHandles.Lookup#unreflect Lookup.unreflect}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   372
 * However, such reflective calls do not result in access mode method
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   373
 * invocations.  Such a call, if passed the required argument (a single one, of
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   374
 * type {@code Object[]}), will ignore the argument and will throw an
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   375
 * {@code UnsupportedOperationException}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   376
 * <p>
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   377
 * Since {@code invokevirtual} instructions can natively invoke VarHandle
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   378
 * access mode methods under any symbolic type descriptor, this reflective view
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   379
 * conflicts with the normal presentation of these methods via bytecodes.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   380
 * Thus, these native methods, when reflectively viewed by
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   381
 * {@code Class.getDeclaredMethod}, may be regarded as placeholders only.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   382
 * <p>
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   383
 * In order to obtain an invoker method for a particular access mode type,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   384
 * use {@link java.lang.invoke.MethodHandles#varHandleExactInvoker} or
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   385
 * {@link java.lang.invoke.MethodHandles#varHandleInvoker}.  The
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   386
 * {@link java.lang.invoke.MethodHandles.Lookup#findVirtual Lookup.findVirtual}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   387
 * API is also able to return a method handle to call an access mode method for
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   388
 * any specified access mode type and is equivalent in behaviour to
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   389
 * {@link java.lang.invoke.MethodHandles#varHandleInvoker}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   390
 *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   391
 * <h1>Interoperation between VarHandles and Java generics</h1>
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   392
 * A VarHandle can be obtained for a variable, such as a a field, which is
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   393
 * declared with Java generic types.  As with the Core Reflection API, the
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   394
 * VarHandle's variable type will be constructed from the erasure of the
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   395
 * source-level type.  When a VarHandle access mode method is invoked, the
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   396
 * types
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   397
 * of its arguments or the return value cast type may be generic types or type
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   398
 * instances.  If this occurs, the compiler will replace those types by their
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   399
 * erasures when it constructs the symbolic type descriptor for the
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   400
 * {@code invokevirtual} instruction.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   401
 *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   402
 * @see MethodHandle
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   403
 * @see MethodHandles
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   404
 * @see MethodType
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   405
 * @since 9
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   406
 */
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   407
public abstract class VarHandle {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   408
    final VarForm vform;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   409
37792
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
   410
    VarHandle(VarForm vform) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   411
        this.vform = vform;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   412
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   413
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   414
    RuntimeException unsupported() {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   415
        return new UnsupportedOperationException();
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   416
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   417
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   418
    // Plain accessors
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   419
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   420
    /**
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   421
     * Returns the value of a variable, with memory semantics of reading as
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   422
     * if the variable was declared non-{@code volatile}.  Commonly referred to
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   423
     * as plain read access.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   424
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   425
     * <p>The method signature is of the form {@code (CT)T}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   426
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   427
     * <p>The symbolic type descriptor at the call site of {@code get}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   428
     * must match the access mode type that is the result of calling
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   429
     * {@code accessModeType(VarHandle.AccessMode.GET)} on this VarHandle.
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   430
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   431
     * <p>This access mode is supported by all VarHandle instances and never
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   432
     * throws {@code UnsupportedOperationException}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   433
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   434
     * @param args the signature-polymorphic parameter list of the form
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   435
     * {@code (CT)}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   436
     * , statically represented using varargs.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   437
     * @return the signature-polymorphic result that is the value of the
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   438
     * variable
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   439
     * , statically represented using {@code Object}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   440
     * @throws WrongMethodTypeException if the access mode type is not
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   441
     * compatible with the caller's symbolic type descriptor.
37344
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
   442
     * @throws ClassCastException if the access mode type is compatible with the
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
   443
     * caller's symbolic type descriptor, but a reference cast fails.
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   444
     */
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   445
    public final native
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   446
    @MethodHandle.PolymorphicSignature
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   447
    @HotSpotIntrinsicCandidate
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   448
    Object get(Object... args);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   449
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   450
    /**
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   451
     * Sets the value of a variable to the {@code newValue}, with memory
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   452
     * semantics of setting as if the variable was declared non-{@code volatile}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   453
     * and non-{@code final}.  Commonly referred to as plain write access.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   454
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   455
     * <p>The method signature is of the form {@code (CT, T newValue)void}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   456
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   457
     * <p>The symbolic type descriptor at the call site of {@code set}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   458
     * must match the access mode type that is the result of calling
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   459
     * {@code accessModeType(VarHandle.AccessMode.SET)} on this VarHandle.
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   460
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   461
     * @param args the signature-polymorphic parameter list of the form
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   462
     * {@code (CT, T newValue)}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   463
     * , statically represented using varargs.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   464
     * @throws UnsupportedOperationException if the access mode is unsupported
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   465
     * for this VarHandle.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   466
     * @throws WrongMethodTypeException if the access mode type is not
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   467
     * compatible with the caller's symbolic type descriptor.
37344
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
   468
     * @throws ClassCastException if the access mode type is compatible with the
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
   469
     * caller's symbolic type descriptor, but a reference cast fails.
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   470
     */
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   471
    public final native
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   472
    @MethodHandle.PolymorphicSignature
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   473
    @HotSpotIntrinsicCandidate
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   474
    void set(Object... args);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   475
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   476
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   477
    // Volatile accessors
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   478
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   479
    /**
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   480
     * Returns the value of a variable, with memory semantics of reading as if
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   481
     * the variable was declared {@code volatile}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   482
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   483
     * <p>The method signature is of the form {@code (CT)T}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   484
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   485
     * <p>The symbolic type descriptor at the call site of {@code getVolatile}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   486
     * must match the access mode type that is the result of calling
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   487
     * {@code accessModeType(VarHandle.AccessMode.GET_VOLATILE)} on this
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   488
     * VarHandle.
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   489
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   490
     * @param args the signature-polymorphic parameter list of the form
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   491
     * {@code (CT)}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   492
     * , statically represented using varargs.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   493
     * @return the signature-polymorphic result that is the value of the
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   494
     * variable
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   495
     * , statically represented using {@code Object}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   496
     * @throws UnsupportedOperationException if the access mode is unsupported
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   497
     * for this VarHandle.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   498
     * @throws WrongMethodTypeException if the access mode type is not
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   499
     * compatible with the caller's symbolic type descriptor.
37344
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
   500
     * @throws ClassCastException if the access mode type is compatible with the
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
   501
     * caller's symbolic type descriptor, but a reference cast fails.
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   502
     */
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   503
    public final native
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   504
    @MethodHandle.PolymorphicSignature
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   505
    @HotSpotIntrinsicCandidate
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   506
    Object getVolatile(Object... args);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   507
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   508
    /**
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   509
     * Sets the value of a variable to the {@code newValue}, with memory
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   510
     * semantics of setting as if the variable was declared {@code volatile}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   511
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   512
     * <p>The method signature is of the form {@code (CT, T newValue)void}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   513
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   514
     * <p>The symbolic type descriptor at the call site of {@code setVolatile}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   515
     * must match the access mode type that is the result of calling
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   516
     * {@code accessModeType(VarHandle.AccessMode.SET_VOLATILE)} on this
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   517
     * VarHandle.
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   518
     *
37344
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
   519
     * @apiNote
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
   520
     * Ignoring the many semantic differences from C and C++, this method has
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
   521
     * memory ordering effects compatible with {@code memory_order_seq_cst}.
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
   522
     *
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   523
     * @param args the signature-polymorphic parameter list of the form
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   524
     * {@code (CT, T newValue)}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   525
     * , statically represented using varargs.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   526
     * @throws UnsupportedOperationException if the access mode is unsupported
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   527
     * for this VarHandle.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   528
     * @throws WrongMethodTypeException if the access mode type is not
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   529
     * compatible with the caller's symbolic type descriptor.
37344
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
   530
     * @throws ClassCastException if the access mode type is compatible with the
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
   531
     * caller's symbolic type descriptor, but a reference cast fails.
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   532
     */
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   533
    public final native
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   534
    @MethodHandle.PolymorphicSignature
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   535
    @HotSpotIntrinsicCandidate
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   536
    void setVolatile(Object... args);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   537
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   538
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   539
    /**
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   540
     * Returns the value of a variable, accessed in program order, but with no
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   541
     * assurance of memory ordering effects with respect to other threads.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   542
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   543
     * <p>The method signature is of the form {@code (CT)T}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   544
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   545
     * <p>The symbolic type descriptor at the call site of {@code getOpaque}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   546
     * must match the access mode type that is the result of calling
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   547
     * {@code accessModeType(VarHandle.AccessMode.GET_OPAQUE)} on this
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   548
     * VarHandle.
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   549
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   550
     * @param args the signature-polymorphic parameter list of the form
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   551
     * {@code (CT)}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   552
     * , statically represented using varargs.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   553
     * @return the signature-polymorphic result that is the value of the
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   554
     * variable
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   555
     * , statically represented using {@code Object}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   556
     * @throws UnsupportedOperationException if the access mode is unsupported
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   557
     * for this VarHandle.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   558
     * @throws WrongMethodTypeException if the access mode type is not
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   559
     * compatible with the caller's symbolic type descriptor.
37344
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
   560
     * @throws ClassCastException if the access mode type is compatible with the
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
   561
     * caller's symbolic type descriptor, but a reference cast fails.
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   562
     */
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   563
    public final native
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   564
    @MethodHandle.PolymorphicSignature
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   565
    @HotSpotIntrinsicCandidate
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   566
    Object getOpaque(Object... args);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   567
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   568
    /**
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   569
     * Sets the value of a variable to the {@code newValue}, in program order,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   570
     * but with no assurance of memory ordering effects with respect to other
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   571
     * threads.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   572
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   573
     * <p>The method signature is of the form {@code (CT, T newValue)void}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   574
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   575
     * <p>The symbolic type descriptor at the call site of {@code setOpaque}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   576
     * must match the access mode type that is the result of calling
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   577
     * {@code accessModeType(VarHandle.AccessMode.SET_OPAQUE)} on this
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   578
     * VarHandle.
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   579
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   580
     * @param args the signature-polymorphic parameter list of the form
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   581
     * {@code (CT, T newValue)}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   582
     * , statically represented using varargs.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   583
     * @throws UnsupportedOperationException if the access mode is unsupported
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   584
     * for this VarHandle.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   585
     * @throws WrongMethodTypeException if the access mode type is not
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   586
     * compatible with the caller's symbolic type descriptor.
37344
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
   587
     * @throws ClassCastException if the access mode type is compatible with the
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
   588
     * caller's symbolic type descriptor, but a reference cast fails.
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   589
     */
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   590
    public final native
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   591
    @MethodHandle.PolymorphicSignature
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   592
    @HotSpotIntrinsicCandidate
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   593
    void setOpaque(Object... args);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   594
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   595
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   596
    // Lazy accessors
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   597
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   598
    /**
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   599
     * Returns the value of a variable, and ensures that subsequent loads and
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   600
     * stores are not reordered before this access.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   601
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   602
     * <p>The method signature is of the form {@code (CT)T}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   603
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   604
     * <p>The symbolic type descriptor at the call site of {@code getAcquire}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   605
     * must match the access mode type that is the result of calling
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   606
     * {@code accessModeType(VarHandle.AccessMode.GET_ACQUIRE)} on this
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   607
     * VarHandle.
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   608
     *
37344
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
   609
     * @apiNote
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
   610
     * Ignoring the many semantic differences from C and C++, this method has
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
   611
     * memory ordering effects compatible with {@code memory_order_acquire}
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
   612
     * ordering.
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
   613
     *
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   614
     * @param args the signature-polymorphic parameter list of the form
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   615
     * {@code (CT)}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   616
     * , statically represented using varargs.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   617
     * @return the signature-polymorphic result that is the value of the
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   618
     * variable
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   619
     * , statically represented using {@code Object}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   620
     * @throws UnsupportedOperationException if the access mode is unsupported
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   621
     * for this VarHandle.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   622
     * @throws WrongMethodTypeException if the access mode type is not
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   623
     * compatible with the caller's symbolic type descriptor.
37344
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
   624
     * @throws ClassCastException if the access mode type is compatible with the
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
   625
     * caller's symbolic type descriptor, but a reference cast fails.
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   626
     */
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   627
    public final native
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   628
    @MethodHandle.PolymorphicSignature
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   629
    @HotSpotIntrinsicCandidate
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   630
    Object getAcquire(Object... args);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   631
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   632
    /**
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   633
     * Sets the value of a variable to the {@code newValue}, and ensures that
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   634
     * prior loads and stores are not reordered after this access.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   635
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   636
     * <p>The method signature is of the form {@code (CT, T newValue)void}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   637
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   638
     * <p>The symbolic type descriptor at the call site of {@code setRelease}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   639
     * must match the access mode type that is the result of calling
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   640
     * {@code accessModeType(VarHandle.AccessMode.SET_RELEASE)} on this
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   641
     * VarHandle.
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   642
     *
37344
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
   643
     * @apiNote
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
   644
     * Ignoring the many semantic differences from C and C++, this method has
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
   645
     * memory ordering effects compatible with {@code memory_order_release}
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
   646
     * ordering.
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
   647
     *
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   648
     * @param args the signature-polymorphic parameter list of the form
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   649
     * {@code (CT, T newValue)}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   650
     * , statically represented using varargs.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   651
     * @throws UnsupportedOperationException if the access mode is unsupported
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   652
     * for this VarHandle.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   653
     * @throws WrongMethodTypeException if the access mode type is not
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   654
     * compatible with the caller's symbolic type descriptor.
37344
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
   655
     * @throws ClassCastException if the access mode type is compatible with the
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
   656
     * caller's symbolic type descriptor, but a reference cast fails.
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   657
     */
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   658
    public final native
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   659
    @MethodHandle.PolymorphicSignature
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   660
    @HotSpotIntrinsicCandidate
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   661
    void setRelease(Object... args);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   662
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   663
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   664
    // Compare and set accessors
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   665
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   666
    /**
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   667
     * Atomically sets the value of a variable to the {@code newValue} with the
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   668
     * memory semantics of {@link #setVolatile} if the variable's current value,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   669
     * referred to as the <em>witness value</em>, {@code ==} the
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   670
     * {@code expectedValue}, as accessed with the memory semantics of
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   671
     * {@link #getVolatile}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   672
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   673
     * <p>The method signature is of the form {@code (CT, T expectedValue, T newValue)boolean}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   674
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   675
     * <p>The symbolic type descriptor at the call site of {@code
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   676
     * compareAndSet} must match the access mode type that is the result of
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   677
     * calling {@code accessModeType(VarHandle.AccessMode.COMPARE_AND_SET)} on
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   678
     * this VarHandle.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   679
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   680
     * @param args the signature-polymorphic parameter list of the form
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   681
     * {@code (CT, T expectedValue, T newValue)}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   682
     * , statically represented using varargs.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   683
     * @return {@code true} if successful, otherwise {@code false} if the
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   684
     * witness value was not the same as the {@code expectedValue}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   685
     * @throws UnsupportedOperationException if the access mode is unsupported
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   686
     * for this VarHandle.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   687
     * @throws WrongMethodTypeException if the access mode type is not
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   688
     * compatible with the caller's symbolic type descriptor.
37344
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
   689
     * @throws ClassCastException if the access mode type is compatible with the
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
   690
     * caller's symbolic type descriptor, but a reference cast fails.
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   691
     * @see #setVolatile(Object...)
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   692
     * @see #getVolatile(Object...)
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   693
     */
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   694
    public final native
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   695
    @MethodHandle.PolymorphicSignature
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   696
    @HotSpotIntrinsicCandidate
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   697
    boolean compareAndSet(Object... args);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   698
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   699
    /**
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   700
     * Atomically sets the value of a variable to the {@code newValue} with the
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   701
     * memory semantics of {@link #setVolatile} if the variable's current value,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   702
     * referred to as the <em>witness value</em>, {@code ==} the
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   703
     * {@code expectedValue}, as accessed with the memory semantics of
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   704
     * {@link #getVolatile}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   705
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   706
     * <p>The method signature is of the form {@code (CT, T expectedValue, T newValue)T}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   707
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   708
     * <p>The symbolic type descriptor at the call site of {@code
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   709
     * compareAndExchangeVolatile}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   710
     * must match the access mode type that is the result of calling
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   711
     * {@code accessModeType(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_VOLATILE)}
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   712
     * on this VarHandle.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   713
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   714
     * @param args the signature-polymorphic parameter list of the form
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   715
     * {@code (CT, T expectedValue, T newValue)}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   716
     * , statically represented using varargs.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   717
     * @return the signature-polymorphic result that is the witness value, which
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   718
     * will be the same as the {@code expectedValue} if successful
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   719
     * , statically represented using {@code Object}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   720
     * @throws UnsupportedOperationException if the access mode is unsupported
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   721
     * for this VarHandle.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   722
     * @throws WrongMethodTypeException if the access mode type is not
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   723
     * compatible with the caller's symbolic type descriptor.
37344
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
   724
     * @throws ClassCastException if the access mode type is compatible with the
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
   725
     * caller's symbolic type descriptor, but a reference cast fails.
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   726
     * @see #setVolatile(Object...)
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   727
     * @see #getVolatile(Object...)
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   728
     */
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   729
    public final native
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   730
    @MethodHandle.PolymorphicSignature
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   731
    @HotSpotIntrinsicCandidate
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   732
    Object compareAndExchangeVolatile(Object... args);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   733
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   734
    /**
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   735
     * Atomically sets the value of a variable to the {@code newValue} with the
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   736
     * memory semantics of {@link #set} if the variable's current value,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   737
     * referred to as the <em>witness value</em>, {@code ==} the
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   738
     * {@code expectedValue}, as accessed with the memory semantics of
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   739
     * {@link #getAcquire}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   740
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   741
     * <p>The method signature is of the form {@code (CT, T expectedValue, T newValue)T}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   742
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   743
     * <p>The symbolic type descriptor at the call site of {@code
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   744
     * compareAndExchangeAcquire}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   745
     * must match the access mode type that is the result of calling
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   746
     * {@code accessModeType(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE)} on
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   747
     * this VarHandle.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   748
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   749
     * @param args the signature-polymorphic parameter list of the form
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   750
     * {@code (CT, T expectedValue, T newValue)}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   751
     * , statically represented using varargs.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   752
     * @return the signature-polymorphic result that is the witness value, which
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   753
     * will be the same as the {@code expectedValue} if successful
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   754
     * , statically represented using {@code Object}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   755
     * @throws UnsupportedOperationException if the access mode is unsupported
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   756
     * for this VarHandle.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   757
     * @throws WrongMethodTypeException if the access mode type is not
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   758
     * compatible with the caller's symbolic type descriptor.
37344
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
   759
     * @throws ClassCastException if the access mode type is compatible with the
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
   760
     * caller's symbolic type descriptor, but a reference cast fails.
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   761
     * @see #set(Object...)
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   762
     * @see #getAcquire(Object...)
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   763
     */
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   764
    public final native
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   765
    @MethodHandle.PolymorphicSignature
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   766
    @HotSpotIntrinsicCandidate
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   767
    Object compareAndExchangeAcquire(Object... args);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   768
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   769
    /**
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   770
     * Atomically sets the value of a variable to the {@code newValue} with the
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   771
     * memory semantics of {@link #setRelease} if the variable's current value,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   772
     * referred to as the <em>witness value</em>, {@code ==} the
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   773
     * {@code expectedValue}, as accessed with the memory semantics of
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   774
     * {@link #get}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   775
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   776
     * <p>The method signature is of the form {@code (CT, T expectedValue, T newValue)T}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   777
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   778
     * <p>The symbolic type descriptor at the call site of {@code
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   779
     * compareAndExchangeRelease}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   780
     * must match the access mode type that is the result of calling
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   781
     * {@code accessModeType(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE)}
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   782
     * on this VarHandle.
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   783
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   784
     * @param args the signature-polymorphic parameter list of the form
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   785
     * {@code (CT, T expectedValue, T newValue)}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   786
     * , statically represented using varargs.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   787
     * @return the signature-polymorphic result that is the witness value, which
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   788
     * will be the same as the {@code expectedValue} if successful
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   789
     * , statically represented using {@code Object}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   790
     * @throws UnsupportedOperationException if the access mode is unsupported
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   791
     * for this VarHandle.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   792
     * @throws WrongMethodTypeException if the access mode type is not
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   793
     * compatible with the caller's symbolic type descriptor.
37344
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
   794
     * @throws ClassCastException if the access mode type is compatible with the
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
   795
     * caller's symbolic type descriptor, but a reference cast fails.
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   796
     * @see #setRelease(Object...)
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   797
     * @see #get(Object...)
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   798
     */
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   799
    public final native
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   800
    @MethodHandle.PolymorphicSignature
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   801
    @HotSpotIntrinsicCandidate
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   802
    Object compareAndExchangeRelease(Object... args);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   803
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   804
    // Weak (spurious failures allowed)
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   805
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   806
    /**
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   807
     * Possibly atomically sets the value of a variable to the {@code newValue}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   808
     * with the semantics of {@link #set} if the variable's current value,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   809
     * referred to as the <em>witness value</em>, {@code ==} the
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   810
     * {@code expectedValue}, as accessed with the memory semantics of
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   811
     * {@link #get}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   812
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   813
     * <p>This operation may fail spuriously (typically, due to memory
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   814
     * contention) even if the witness value does match the expected value.
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   815
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   816
     * <p>The method signature is of the form {@code (CT, T expectedValue, T newValue)boolean}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   817
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   818
     * <p>The symbolic type descriptor at the call site of {@code
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   819
     * weakCompareAndSet} must match the access mode type that is the result of
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   820
     * calling {@code accessModeType(VarHandle.AccessMode.WEAK_COMPARE_AND_SET)}
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   821
     * on this VarHandle.
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   822
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   823
     * @param args the signature-polymorphic parameter list of the form
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   824
     * {@code (CT, T expectedValue, T newValue)}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   825
     * , statically represented using varargs.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   826
     * @return {@code true} if successful, otherwise {@code false} if the
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   827
     * witness value was not the same as the {@code expectedValue} or if this
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   828
     * operation spuriously failed.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   829
     * @throws UnsupportedOperationException if the access mode is unsupported
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   830
     * for this VarHandle.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   831
     * @throws WrongMethodTypeException if the access mode type is not
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   832
     * compatible with the caller's symbolic type descriptor.
37344
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
   833
     * @throws ClassCastException if the access mode type is compatible with the
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
   834
     * caller's symbolic type descriptor, but a reference cast fails.
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   835
     * @see #set(Object...)
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   836
     * @see #get(Object...)
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   837
     */
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   838
    public final native
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   839
    @MethodHandle.PolymorphicSignature
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   840
    @HotSpotIntrinsicCandidate
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   841
    boolean weakCompareAndSet(Object... args);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   842
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   843
    /**
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   844
     * Possibly atomically sets the value of a variable to the {@code newValue}
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   845
     * with the memory semantics of {@link #setVolatile} if the variable's
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   846
     * current value, referred to as the <em>witness value</em>, {@code ==} the
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   847
     * {@code expectedValue}, as accessed with the memory semantics of
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   848
     * {@link #getVolatile}.
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   849
     *
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   850
     * <p>This operation may fail spuriously (typically, due to memory
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   851
     * contention) even if the witness value does match the expected value.
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   852
     *
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   853
     * <p>The method signature is of the form {@code (CT, T expectedValue, T newValue)boolean}.
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   854
     *
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   855
     * <p>The symbolic type descriptor at the call site of {@code
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   856
     * weakCompareAndSetVolatile} must match the access mode type that is the
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   857
     * result of calling {@code accessModeType(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_VOLATILE)}
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   858
     * on this VarHandle.
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   859
     *
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   860
     * @param args the signature-polymorphic parameter list of the form
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   861
     * {@code (CT, T expectedValue, T newValue)}
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   862
     * , statically represented using varargs.
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   863
     * @return {@code true} if successful, otherwise {@code false} if the
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   864
     * witness value was not the same as the {@code expectedValue} or if this
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   865
     * operation spuriously failed.
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   866
     * @throws UnsupportedOperationException if the access mode is unsupported
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   867
     * for this VarHandle.
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   868
     * @throws WrongMethodTypeException if the access mode type is not
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   869
     * compatible with the caller's symbolic type descriptor.
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   870
     * @throws ClassCastException if the access mode type is compatible with the
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   871
     * caller's symbolic type descriptor, but a reference cast fails.
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   872
     * @see #setVolatile(Object...)
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   873
     * @see #getVolatile(Object...)
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   874
     */
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   875
    public final native
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   876
    @MethodHandle.PolymorphicSignature
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   877
    @HotSpotIntrinsicCandidate
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   878
    boolean weakCompareAndSetVolatile(Object... args);
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   879
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   880
    /**
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   881
     * Possibly atomically sets the value of a variable to the {@code newValue}
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   882
     * with the semantics of {@link #set} if the variable's current value,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   883
     * referred to as the <em>witness value</em>, {@code ==} the
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   884
     * {@code expectedValue}, as accessed with the memory semantics of
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   885
     * {@link #getAcquire}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   886
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   887
     * <p>This operation may fail spuriously (typically, due to memory
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   888
     * contention) even if the witness value does match the expected value.
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   889
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   890
     * <p>The method signature is of the form {@code (CT, T expectedValue, T newValue)boolean}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   891
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   892
     * <p>The symbolic type descriptor at the call site of {@code
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   893
     * weakCompareAndSetAcquire}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   894
     * must match the access mode type that is the result of calling
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   895
     * {@code accessModeType(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE)}
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   896
     * on this VarHandle.
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   897
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   898
     * @param args the signature-polymorphic parameter list of the form
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   899
     * {@code (CT, T expectedValue, T newValue)}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   900
     * , statically represented using varargs.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   901
     * @return {@code true} if successful, otherwise {@code false} if the
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   902
     * witness value was not the same as the {@code expectedValue} or if this
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   903
     * operation spuriously failed.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   904
     * @throws UnsupportedOperationException if the access mode is unsupported
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   905
     * for this VarHandle.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   906
     * @throws WrongMethodTypeException if the access mode type is not
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   907
     * compatible with the caller's symbolic type descriptor.
37344
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
   908
     * @throws ClassCastException if the access mode type is compatible with the
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
   909
     * caller's symbolic type descriptor, but a reference cast fails.
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   910
     * @see #set(Object...)
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   911
     * @see #getAcquire(Object...)
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   912
     */
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   913
    public final native
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   914
    @MethodHandle.PolymorphicSignature
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   915
    @HotSpotIntrinsicCandidate
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   916
    boolean weakCompareAndSetAcquire(Object... args);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   917
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   918
    /**
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   919
     * Possibly atomically sets the value of a variable to the {@code newValue}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   920
     * with the semantics of {@link #setRelease} if the variable's current
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   921
     * value, referred to as the <em>witness value</em>, {@code ==} the
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   922
     * {@code expectedValue}, as accessed with the memory semantics of
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   923
     * {@link #get}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   924
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   925
     * <p>This operation may fail spuriously (typically, due to memory
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   926
     * contention) even if the witness value does match the expected value.
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   927
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   928
     * <p>The method signature is of the form {@code (CT, T expectedValue, T newValue)boolean}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   929
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   930
     * <p>The symbolic type descriptor at the call site of {@code
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   931
     * weakCompareAndSetRelease}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   932
     * must match the access mode type that is the result of calling
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   933
     * {@code accessModeType(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE)}
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   934
     * on this VarHandle.
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   935
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   936
     * @param args the signature-polymorphic parameter list of the form
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   937
     * {@code (CT, T expectedValue, T newValue)}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   938
     * , statically represented using varargs.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   939
     * @return {@code true} if successful, otherwise {@code false} if the
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   940
     * witness value was not the same as the {@code expectedValue} or if this
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   941
     * operation spuriously failed.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   942
     * @throws UnsupportedOperationException if the access mode is unsupported
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   943
     * for this VarHandle.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   944
     * @throws WrongMethodTypeException if the access mode type is not
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   945
     * compatible with the caller's symbolic type descriptor.
37344
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
   946
     * @throws ClassCastException if the access mode type is compatible with the
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
   947
     * caller's symbolic type descriptor, but a reference cast fails.
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   948
     * @see #setRelease(Object...)
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   949
     * @see #get(Object...)
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   950
     */
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   951
    public final native
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   952
    @MethodHandle.PolymorphicSignature
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   953
    @HotSpotIntrinsicCandidate
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   954
    boolean weakCompareAndSetRelease(Object... args);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   955
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   956
    /**
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   957
     * Atomically sets the value of a variable to the {@code newValue} with the
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   958
     * memory semantics of {@link #setVolatile} and returns the variable's
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   959
     * previous value, as accessed with the memory semantics of
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   960
     * {@link #getVolatile}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   961
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   962
     * <p>The method signature is of the form {@code (CT, T newValue)T}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   963
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   964
     * <p>The symbolic type descriptor at the call site of {@code getAndSet}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   965
     * must match the access mode type that is the result of calling
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   966
     * {@code accessModeType(VarHandle.AccessMode.GET_AND_SET)} on this
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
   967
     * VarHandle.
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   968
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   969
     * @param args the signature-polymorphic parameter list of the form
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   970
     * {@code (CT, T newValue)}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   971
     * , statically represented using varargs.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   972
     * @return the signature-polymorphic result that is the previous value of
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   973
     * the variable
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   974
     * , statically represented using {@code Object}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   975
     * @throws UnsupportedOperationException if the access mode is unsupported
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   976
     * for this VarHandle.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   977
     * @throws WrongMethodTypeException if the access mode type is not
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   978
     * compatible with the caller's symbolic type descriptor.
37344
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
   979
     * @throws ClassCastException if the access mode type is compatible with the
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
   980
     * caller's symbolic type descriptor, but a reference cast fails.
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   981
     * @see #setVolatile(Object...)
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   982
     * @see #getVolatile(Object...)
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   983
     */
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   984
    public final native
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   985
    @MethodHandle.PolymorphicSignature
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   986
    @HotSpotIntrinsicCandidate
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   987
    Object getAndSet(Object... args);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   988
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   989
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   990
    // Primitive adders
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   991
    // Throw UnsupportedOperationException for refs
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   992
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   993
    /**
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   994
     * Atomically adds the {@code value} to the current value of a variable with
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   995
     * the memory semantics of {@link #setVolatile}, and returns the variable's
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   996
     * previous value, as accessed with the memory semantics of
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   997
     * {@link #getVolatile}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   998
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   999
     * <p>The method signature is of the form {@code (CT, T value)T}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1000
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1001
     * <p>The symbolic type descriptor at the call site of {@code getAndAdd}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1002
     * must match the access mode type that is the result of calling
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
  1003
     * {@code accessModeType(VarHandle.AccessMode.GET_AND_ADD)} on this
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
  1004
     * VarHandle.
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1005
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1006
     * @param args the signature-polymorphic parameter list of the form
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1007
     * {@code (CT, T value)}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1008
     * , statically represented using varargs.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1009
     * @return the signature-polymorphic result that is the previous value of
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1010
     * the variable
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1011
     * , statically represented using {@code Object}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1012
     * @throws UnsupportedOperationException if the access mode is unsupported
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1013
     * for this VarHandle.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1014
     * @throws WrongMethodTypeException if the access mode type is not
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1015
     * compatible with the caller's symbolic type descriptor.
37344
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
  1016
     * @throws ClassCastException if the access mode type is compatible with the
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
  1017
     * caller's symbolic type descriptor, but a reference cast fails.
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1018
     * @see #setVolatile(Object...)
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1019
     * @see #getVolatile(Object...)
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1020
     */
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1021
    public final native
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1022
    @MethodHandle.PolymorphicSignature
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1023
    @HotSpotIntrinsicCandidate
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1024
    Object getAndAdd(Object... args);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1025
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1026
    /**
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1027
     * Atomically adds the {@code value} to the current value of a variable with
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1028
     * the memory semantics of {@link #setVolatile}, and returns the variable's
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1029
     * current (updated) value, as accessed with the memory semantics of
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1030
     * {@link #getVolatile}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1031
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1032
     * <p>The method signature is of the form {@code (CT, T value)T}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1033
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1034
     * <p>The symbolic type descriptor at the call site of {@code addAndGet}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1035
     * must match the access mode type that is the result of calling
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
  1036
     * {@code accessModeType(VarHandle.AccessMode.ADD_AND_GET)} on this
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
  1037
     * VarHandle.
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1038
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1039
     * @param args the signature-polymorphic parameter list of the form
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1040
     * {@code (CT, T value)}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1041
     * , statically represented using varargs.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1042
     * @return the signature-polymorphic result that is the current value of
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1043
     * the variable
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1044
     * , statically represented using {@code Object}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1045
     * @throws UnsupportedOperationException if the access mode is unsupported
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1046
     * for this VarHandle.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1047
     * @throws WrongMethodTypeException if the access mode type is not
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1048
     * compatible with the caller's symbolic type descriptor.
37344
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
  1049
     * @throws ClassCastException if the access mode type is compatible with the
52d3d8517efc 8151198: VarHandle factory-specific exceptions
psandoz
parents: 37343
diff changeset
  1050
     * caller's symbolic type descriptor, but a reference cast fails.
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1051
     * @see #setVolatile(Object...)
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1052
     * @see #getVolatile(Object...)
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1053
     */
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1054
    public final native
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1055
    @MethodHandle.PolymorphicSignature
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1056
    @HotSpotIntrinsicCandidate
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1057
    Object addAndGet(Object... args);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1058
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1059
    enum AccessType {
37792
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1060
        GET(Object.class) {
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1061
            @Override
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1062
            MethodType accessModeType(Class<?> receiver, Class<?> value,
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1063
                                      Class<?>... intermediate) {
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1064
                Class<?>[] ps =  allocateParameters(0, receiver, intermediate);
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1065
                fillParameters(ps, receiver, intermediate);
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1066
                return MethodType.methodType(value, ps);
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1067
            }
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1068
        },
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1069
        SET(void.class) {
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1070
            @Override
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1071
            MethodType accessModeType(Class<?> receiver, Class<?> value,
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1072
                                      Class<?>... intermediate) {
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1073
                Class<?>[] ps =  allocateParameters(1, receiver, intermediate);
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1074
                int i = fillParameters(ps, receiver, intermediate);
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1075
                ps[i] = value;
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1076
                return MethodType.methodType(void.class, ps);
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1077
            }
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1078
        },
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1079
        COMPARE_AND_SWAP(boolean.class) {
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1080
            @Override
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1081
            MethodType accessModeType(Class<?> receiver, Class<?> value,
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1082
                                      Class<?>... intermediate) {
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1083
                Class<?>[] ps =  allocateParameters(2, receiver, intermediate);
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1084
                int i = fillParameters(ps, receiver, intermediate);
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1085
                ps[i++] = value;
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1086
                ps[i] = value;
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1087
                return MethodType.methodType(boolean.class, ps);
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1088
            }
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1089
        },
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1090
        COMPARE_AND_EXCHANGE(Object.class) {
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1091
            @Override
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1092
            MethodType accessModeType(Class<?> receiver, Class<?> value,
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1093
                                      Class<?>... intermediate) {
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1094
                Class<?>[] ps =  allocateParameters(2, receiver, intermediate);
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1095
                int i = fillParameters(ps, receiver, intermediate);
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1096
                ps[i++] = value;
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1097
                ps[i] = value;
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1098
                return MethodType.methodType(value, ps);
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1099
            }
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1100
        },
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1101
        GET_AND_UPDATE(Object.class) {
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1102
            @Override
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1103
            MethodType accessModeType(Class<?> receiver, Class<?> value,
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1104
                                      Class<?>... intermediate) {
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1105
                Class<?>[] ps =  allocateParameters(1, receiver, intermediate);
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1106
                int i = fillParameters(ps, receiver, intermediate);
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1107
                ps[i] = value;
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1108
                return MethodType.methodType(value, ps);
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1109
            }
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1110
        };
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1111
37792
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1112
        final Class<?> returnType;
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1113
        final boolean isMonomorphicInReturnType;
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1114
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1115
        AccessType(Class<?> returnType) {
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1116
            this.returnType = returnType;
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1117
            isMonomorphicInReturnType = returnType != Object.class;
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1118
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1119
37792
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1120
        abstract MethodType accessModeType(Class<?> receiver, Class<?> value,
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1121
                                           Class<?>... intermediate);
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1122
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1123
        private static Class<?>[] allocateParameters(int values,
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1124
                                                     Class<?> receiver, Class<?>... intermediate) {
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1125
            int size = ((receiver != null) ? 1 : 0) + intermediate.length + values;
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1126
            return new Class<?>[size];
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1127
        }
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1128
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1129
        private static int fillParameters(Class<?>[] ps,
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1130
                                          Class<?> receiver, Class<?>... intermediate) {
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1131
            int i = 0;
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1132
            if (receiver != null)
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1133
                ps[i++] = receiver;
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1134
            for (int j = 0; j < intermediate.length; j++)
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1135
                ps[i++] = intermediate[j];
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1136
            return i;
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1137
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1138
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1139
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1140
    /**
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1141
     * The set of access modes that specify how a variable, referenced by a
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1142
     * VarHandle, is accessed.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1143
     */
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1144
    public enum AccessMode {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1145
        /**
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1146
         * The access mode whose access is specified by the corresponding
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1147
         * method
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1148
         * {@link VarHandle#get VarHandle.get}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1149
         */
37792
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1150
        GET("get", AccessType.GET),
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1151
        /**
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1152
         * The access mode whose access is specified by the corresponding
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1153
         * method
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1154
         * {@link VarHandle#set VarHandle.set}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1155
         */
37792
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1156
        SET("set", AccessType.SET),
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1157
        /**
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1158
         * The access mode whose access is specified by the corresponding
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1159
         * method
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1160
         * {@link VarHandle#getVolatile VarHandle.getVolatile}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1161
         */
37792
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1162
        GET_VOLATILE("getVolatile", AccessType.GET),
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1163
        /**
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1164
         * The access mode whose access is specified by the corresponding
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1165
         * method
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1166
         * {@link VarHandle#setVolatile VarHandle.setVolatile}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1167
         */
37792
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1168
        SET_VOLATILE("setVolatile", AccessType.SET),
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1169
        /**
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1170
         * The access mode whose access is specified by the corresponding
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1171
         * method
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1172
         * {@link VarHandle#getAcquire VarHandle.getAcquire}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1173
         */
37792
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1174
        GET_ACQUIRE("getAcquire", AccessType.GET),
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1175
        /**
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1176
         * The access mode whose access is specified by the corresponding
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1177
         * method
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1178
         * {@link VarHandle#setRelease VarHandle.setRelease}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1179
         */
37792
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1180
        SET_RELEASE("setRelease", AccessType.SET),
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1181
        /**
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1182
         * The access mode whose access is specified by the corresponding
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1183
         * method
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1184
         * {@link VarHandle#getOpaque VarHandle.getOpaque}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1185
         */
37792
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1186
        GET_OPAQUE("getOpaque", AccessType.GET),
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1187
        /**
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1188
         * The access mode whose access is specified by the corresponding
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1189
         * method
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1190
         * {@link VarHandle#setOpaque VarHandle.setOpaque}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1191
         */
37792
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1192
        SET_OPAQUE("setOpaque", AccessType.SET),
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1193
        /**
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1194
         * The access mode whose access is specified by the corresponding
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1195
         * method
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1196
         * {@link VarHandle#compareAndSet VarHandle.compareAndSet}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1197
         */
37792
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1198
        COMPARE_AND_SET("compareAndSet", AccessType.COMPARE_AND_SWAP),
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1199
        /**
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1200
         * The access mode whose access is specified by the corresponding
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1201
         * method
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1202
         * {@link VarHandle#compareAndExchangeVolatile VarHandle.compareAndExchangeVolatile}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1203
         */
37792
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1204
        COMPARE_AND_EXCHANGE_VOLATILE("compareAndExchangeVolatile", AccessType.COMPARE_AND_EXCHANGE),
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1205
        /**
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1206
         * The access mode whose access is specified by the corresponding
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1207
         * method
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1208
         * {@link VarHandle#compareAndExchangeAcquire VarHandle.compareAndExchangeAcquire}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1209
         */
37792
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1210
        COMPARE_AND_EXCHANGE_ACQUIRE("compareAndExchangeAcquire", AccessType.COMPARE_AND_EXCHANGE),
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1211
        /**
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1212
         * The access mode whose access is specified by the corresponding
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1213
         * method
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1214
         * {@link VarHandle#compareAndExchangeRelease VarHandle.compareAndExchangeRelease}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1215
         */
37792
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1216
        COMPARE_AND_EXCHANGE_RELEASE("compareAndExchangeRelease", AccessType.COMPARE_AND_EXCHANGE),
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1217
        /**
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1218
         * The access mode whose access is specified by the corresponding
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1219
         * method
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1220
         * {@link VarHandle#weakCompareAndSet VarHandle.weakCompareAndSet}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1221
         */
37792
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1222
        WEAK_COMPARE_AND_SET("weakCompareAndSet", AccessType.COMPARE_AND_SWAP),
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
  1223
        /**
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
  1224
         * The access mode whose access is specified by the corresponding
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
  1225
         * method
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
  1226
         * {@link VarHandle#weakCompareAndSetVolatile VarHandle.weakCompareAndSetVolatile}
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37345
diff changeset
  1227
         */
37792
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1228
        WEAK_COMPARE_AND_SET_VOLATILE("weakCompareAndSetVolatile", AccessType.COMPARE_AND_SWAP),
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1229
        /**
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1230
         * The access mode whose access is specified by the corresponding
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1231
         * method
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1232
         * {@link VarHandle#weakCompareAndSetAcquire VarHandle.weakCompareAndSetAcquire}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1233
         */
37792
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1234
        WEAK_COMPARE_AND_SET_ACQUIRE("weakCompareAndSetAcquire", AccessType.COMPARE_AND_SWAP),
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1235
        /**
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1236
         * The access mode whose access is specified by the corresponding
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1237
         * method
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1238
         * {@link VarHandle#weakCompareAndSetRelease VarHandle.weakCompareAndSetRelease}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1239
         */
37792
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1240
        WEAK_COMPARE_AND_SET_RELEASE("weakCompareAndSetRelease", AccessType.COMPARE_AND_SWAP),
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1241
        /**
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1242
         * The access mode whose access is specified by the corresponding
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1243
         * method
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1244
         * {@link VarHandle#getAndSet VarHandle.getAndSet}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1245
         */
37792
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1246
        GET_AND_SET("getAndSet", AccessType.GET_AND_UPDATE),
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1247
        /**
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1248
         * The access mode whose access is specified by the corresponding
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1249
         * method
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1250
         * {@link VarHandle#getAndAdd VarHandle.getAndAdd}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1251
         */
37792
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1252
        GET_AND_ADD("getAndAdd", AccessType.GET_AND_UPDATE),
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1253
        /**
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1254
         * The access mode whose access is specified by the corresponding
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1255
         * method
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1256
         * {@link VarHandle#addAndGet VarHandle.addAndGet}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1257
         */
37792
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1258
        ADD_AND_GET("addAndGet", AccessType.GET_AND_UPDATE),
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1259
        ;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1260
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1261
        static final Map<String, AccessMode> methodNameToAccessMode;
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1262
        static {
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1263
            // Initial capacity of # values is sufficient to avoid resizes
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1264
            // for the smallest table size (32)
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1265
            methodNameToAccessMode = new HashMap<>(AccessMode.values().length);
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1266
            for (AccessMode am : AccessMode.values()) {
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1267
                methodNameToAccessMode.put(am.methodName, am);
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1268
            }
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1269
        }
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1270
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1271
        final String methodName;
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1272
        final AccessType at;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1273
37792
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1274
        AccessMode(final String methodName, AccessType at) {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1275
            this.methodName = methodName;
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1276
            this.at = at;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1277
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1278
            // Assert method name is correctly derived from value name
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1279
            assert methodName.equals(toMethodName(name()));
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1280
            // Assert that return type is correct
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1281
            // Otherwise, when disabled avoid using reflection
37792
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1282
            assert at.returnType == getReturnType(methodName);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1283
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1284
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1285
        /**
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1286
         * Returns the {@code VarHandle} signature-polymorphic method name
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1287
         * associated with this {@code AccessMode} value
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1288
         *
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1289
         * @return the signature-polymorphic method name
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1290
         * @see #valueFromMethodName
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1291
         */
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1292
        public String methodName() {
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1293
            return methodName;
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1294
        }
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1295
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1296
        /**
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1297
         * Returns the {@code AccessMode} value associated with the specified
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1298
         * {@code VarHandle} signature-polymorphic method name.
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1299
         *
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1300
         * @param methodName the signature-polymorphic method name
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1301
         * @return the {@code AccessMode} value
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1302
         * @throws IllegalArgumentException if there is no {@code AccessMode}
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1303
         *         value associated with method name (indicating the method
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1304
         *         name does not correspond to a {@code VarHandle}
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1305
         *         signature-polymorphic method name).
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1306
         * @see #methodName
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1307
         */
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1308
        public static AccessMode valueFromMethodName(String methodName) {
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1309
            AccessMode am = methodNameToAccessMode.get(methodName);
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1310
            if (am != null) return am;
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1311
            throw new IllegalArgumentException("No AccessMode value for method name " + methodName);
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1312
        }
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1313
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1314
        private static String toMethodName(String name) {
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1315
            StringBuilder s = new StringBuilder(name.toLowerCase());
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1316
            int i;
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1317
            while ((i = s.indexOf("_")) !=  -1) {
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1318
                s.deleteCharAt(i);
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1319
                s.setCharAt(i, Character.toUpperCase(s.charAt(i)));
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1320
            }
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1321
            return s.toString();
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1322
        }
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36973
diff changeset
  1323
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1324
        private static Class<?> getReturnType(String name) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1325
            try {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1326
                Method m = VarHandle.class.getMethod(name, Object[].class);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1327
                return m.getReturnType();
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1328
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1329
            catch (Exception e) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1330
                throw newInternalError(e);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1331
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1332
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1333
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1334
        @ForceInline
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1335
        static MemberName getMemberName(int ordinal, VarForm vform) {
37792
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1336
            return vform.memberName_table[ordinal];
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1337
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1338
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1339
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1340
    static final class AccessDescriptor {
37792
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1341
        final MethodType symbolicMethodTypeErased;
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1342
        final MethodType symbolicMethodTypeInvoker;
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1343
        final Class<?> returnType;
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1344
        final int type;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1345
        final int mode;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1346
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1347
        public AccessDescriptor(MethodType symbolicMethodType, int type, int mode) {
37792
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1348
            this.symbolicMethodTypeErased = symbolicMethodType.erase();
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1349
            this.symbolicMethodTypeInvoker = symbolicMethodType.insertParameterTypes(0, VarHandle.class);
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1350
            this.returnType = symbolicMethodType.returnType();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1351
            this.type = type;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1352
            this.mode = mode;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1353
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1354
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1355
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1356
    /**
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1357
     * Returns the variable type of variables referenced by this VarHandle.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1358
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1359
     * @return the variable type of variables referenced by this VarHandle
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1360
     */
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1361
    public final Class<?> varType() {
37792
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1362
        MethodType typeSet = accessModeType(AccessMode.SET);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1363
        return typeSet.parameterType(typeSet.parameterCount() - 1);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1364
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1365
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1366
    /**
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1367
     * Returns the coordinate types for this VarHandle.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1368
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1369
     * @return the coordinate types for this VarHandle. The returned
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1370
     * list is unmodifiable
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1371
     */
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1372
    public final List<Class<?>> coordinateTypes() {
37792
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1373
        MethodType typeGet = accessModeType(AccessMode.GET);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1374
        return typeGet.parameterList();
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1375
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1376
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1377
    /**
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1378
     * Obtains the canonical access mode type for this VarHandle and a given
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1379
     * access mode.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1380
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1381
     * <p>The access mode type's parameter types will consist of a prefix that
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1382
     * is the coordinate types of this VarHandle followed by further
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1383
     * types as defined by the access mode's method.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1384
     * The access mode type's return type is defined by the return type of the
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1385
     * access mode's method.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1386
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1387
     * @param accessMode the access mode, corresponding to the
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1388
     * signature-polymorphic method of the same name
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1389
     * @return the access mode type for the given access mode
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1390
     */
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1391
    public final MethodType accessModeType(AccessMode accessMode) {
37792
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1392
        TypesAndInvokers tis = getTypesAndInvokers();
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1393
        MethodType mt = tis.methodType_table[accessMode.at.ordinal()];
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1394
        if (mt == null) {
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1395
            mt = tis.methodType_table[accessMode.at.ordinal()] =
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1396
                    accessModeTypeUncached(accessMode);
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1397
        }
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1398
        return mt;
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1399
    }
37792
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1400
    abstract MethodType accessModeTypeUncached(AccessMode accessMode);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1401
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1402
    /**
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1403
     * Returns {@code true} if the given access mode is supported, otherwise
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1404
     * {@code false}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1405
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1406
     * <p>The return of a {@code false} value for a given access mode indicates
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1407
     * that an {@code UnsupportedOperationException} is thrown on invocation
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1408
     * of the corresponding access mode's signature-polymorphic method.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1409
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1410
     * @param accessMode the access mode, corresponding to the
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1411
     * signature-polymorphic method of the same name
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1412
     * @return {@code true} if the given access mode is supported, otherwise
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1413
     * {@code false}.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1414
     */
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1415
    public final boolean isAccessModeSupported(AccessMode accessMode) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1416
        return AccessMode.getMemberName(accessMode.ordinal(), vform) != null;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1417
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1418
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1419
    /**
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1420
     * Obtains a method handle bound to this VarHandle and the given access
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1421
     * mode.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1422
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1423
     * @apiNote This method, for a VarHandle {@code vh} and access mode
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1424
     * {@code {access-mode}}, returns a method handle that is equivalent to
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1425
     * method handle {@code bhm} in the following code (though it may be more
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1426
     * efficient):
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1427
     * <pre>{@code
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1428
     * MethodHandle mh = MethodHandles.varHandleExactInvoker(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1429
     *                       vh.accessModeType(VarHandle.AccessMode.{access-mode}));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1430
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1431
     * MethodHandle bmh = mh.bindTo(vh);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1432
     * }</pre>
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1433
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1434
     * @param accessMode the access mode, corresponding to the
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1435
     * signature-polymorphic method of the same name
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1436
     * @return a method handle bound to this VarHandle and the given access mode
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1437
     */
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1438
    public final MethodHandle toMethodHandle(AccessMode accessMode) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1439
        MemberName mn = AccessMode.getMemberName(accessMode.ordinal(), vform);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1440
        if (mn != null) {
37792
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1441
            MethodHandle mh = getMethodHandle(accessMode.ordinal());
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1442
            return mh.bindTo(this);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1443
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1444
        else {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1445
            // Ensure an UnsupportedOperationException is thrown
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1446
            return MethodHandles.varHandleInvoker(accessMode, accessModeType(accessMode)).
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1447
                    bindTo(this);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1448
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1449
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1450
37792
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1451
    @Stable
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1452
    TypesAndInvokers typesAndInvokers;
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1453
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1454
    static class TypesAndInvokers {
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1455
        final @Stable
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1456
        MethodType[] methodType_table =
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1457
                new MethodType[VarHandle.AccessType.values().length];
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1458
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1459
        final @Stable
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1460
        MethodHandle[] methodHandle_table =
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1461
                new MethodHandle[AccessMode.values().length];
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1462
    }
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1463
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1464
    @ForceInline
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1465
    private final TypesAndInvokers getTypesAndInvokers() {
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1466
        TypesAndInvokers tis = typesAndInvokers;
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1467
        if (tis == null) {
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1468
            tis = typesAndInvokers = new TypesAndInvokers();
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1469
        }
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1470
        return tis;
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1471
    }
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1472
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1473
    @ForceInline
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1474
    final MethodHandle getMethodHandle(int mode) {
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1475
        TypesAndInvokers tis = getTypesAndInvokers();
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1476
        MethodHandle mh = tis.methodHandle_table[mode];
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1477
        if (mh == null) {
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1478
            mh = tis.methodHandle_table[mode] = getMethodHandleUncached(tis, mode);
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1479
        }
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1480
        return mh;
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1481
    }
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1482
    private final MethodHandle getMethodHandleUncached(TypesAndInvokers tis, int mode) {
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1483
        MethodType mt = accessModeType(AccessMode.values()[mode]).
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1484
                insertParameterTypes(0, VarHandle.class);
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1485
        MemberName mn = vform.getMemberName(mode);
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1486
        DirectMethodHandle dmh = DirectMethodHandle.make(mn);
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1487
        // Such a method handle must not be publically exposed directly
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1488
        // otherwise it can be cracked, it must be transformed or rebound
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1489
        // before exposure
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1490
        MethodHandle mh = dmh.copyWith(mt, dmh.form);
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1491
        assert mh.type().erase() == mn.getMethodType().erase();
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1492
        return mh;
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1493
    }
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1494
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1495
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1496
    /*non-public*/
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1497
    final void updateVarForm(VarForm newVForm) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1498
        if (vform == newVForm) return;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1499
        UNSAFE.putObject(this, VFORM_OFFSET, newVForm);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1500
        UNSAFE.fullFence();
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1501
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1502
37345
9cb6e1141bdb 8146458: Improve exception reporting for Objects.checkIndex/checkFromToIndex/checkFromIndexSize
psandoz
parents: 37344
diff changeset
  1503
    static final BiFunction<String, List<Integer>, ArrayIndexOutOfBoundsException>
38356
1e4ecca97792 8155794: Move Objects.checkIndex BiFunction accepting methods to an internal package
psandoz
parents: 37345
diff changeset
  1504
            AIOOBE_SUPPLIER = Preconditions.outOfBoundsExceptionFormatter(
37345
9cb6e1141bdb 8146458: Improve exception reporting for Objects.checkIndex/checkFromToIndex/checkFromIndexSize
psandoz
parents: 37344
diff changeset
  1505
            new Function<String, ArrayIndexOutOfBoundsException>() {
9cb6e1141bdb 8146458: Improve exception reporting for Objects.checkIndex/checkFromToIndex/checkFromIndexSize
psandoz
parents: 37344
diff changeset
  1506
                @Override
9cb6e1141bdb 8146458: Improve exception reporting for Objects.checkIndex/checkFromToIndex/checkFromIndexSize
psandoz
parents: 37344
diff changeset
  1507
                public ArrayIndexOutOfBoundsException apply(String s) {
9cb6e1141bdb 8146458: Improve exception reporting for Objects.checkIndex/checkFromToIndex/checkFromIndexSize
psandoz
parents: 37344
diff changeset
  1508
                    return new ArrayIndexOutOfBoundsException(s);
9cb6e1141bdb 8146458: Improve exception reporting for Objects.checkIndex/checkFromToIndex/checkFromIndexSize
psandoz
parents: 37344
diff changeset
  1509
                }
9cb6e1141bdb 8146458: Improve exception reporting for Objects.checkIndex/checkFromToIndex/checkFromIndexSize
psandoz
parents: 37344
diff changeset
  1510
            });
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1511
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1512
    private static final long VFORM_OFFSET;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1513
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1514
    static {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1515
        try {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1516
            VFORM_OFFSET = UNSAFE.objectFieldOffset(VarHandle.class.getDeclaredField("vform"));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1517
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1518
        catch (ReflectiveOperationException e) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1519
            throw newInternalError(e);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1520
        }
37792
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1521
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1522
        // The VarHandleGuards must be initialized to ensure correct
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1523
        // compilation of the guard methods
dd626e6f5967 8155258: VarHandle implementation improvements
psandoz
parents: 37719
diff changeset
  1524
        UNSAFE.ensureClassInitialized(VarHandleGuards.class);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1525
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1526
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1527
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1528
    // Fence methods
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1529
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1530
    /**
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1531
     * Ensures that loads and stores before the fence will not be reordered
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1532
     * with
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1533
     * loads and stores after the fence.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1534
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1535
     * @apiNote Ignoring the many semantic differences from C and C++, this
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1536
     * method has memory ordering effects compatible with
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1537
     * {@code atomic_thread_fence(memory_order_seq_cst)}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1538
     */
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1539
    @ForceInline
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1540
    public static void fullFence() {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1541
        UNSAFE.fullFence();
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1542
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1543
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1544
    /**
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1545
     * Ensures that loads before the fence will not be reordered with loads and
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1546
     * stores after the fence.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1547
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1548
     * @apiNote Ignoring the many semantic differences from C and C++, this
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1549
     * method has memory ordering effects compatible with
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1550
     * {@code atomic_thread_fence(memory_order_acquire)}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1551
     */
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1552
    @ForceInline
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1553
    public static void acquireFence() {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1554
        UNSAFE.loadFence();
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1555
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1556
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1557
    /**
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1558
     * Ensures that loads and stores before the fence will not be
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1559
     * reordered with stores after the fence.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1560
     *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1561
     * @apiNote Ignoring the many semantic differences from C and C++, this
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1562
     * method has memory ordering effects compatible with
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1563
     * {@code atomic_thread_fence(memory_order_release)}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1564
     */
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1565
    @ForceInline
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1566
    public static void releaseFence() {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1567
        UNSAFE.storeFence();
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1568
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1569
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1570
    /**
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1571
     * Ensures that loads before the fence will not be reordered with
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1572
     * loads after the fence.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1573
     */
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1574
    @ForceInline
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1575
    public static void loadLoadFence() {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1576
        UNSAFE.loadLoadFence();
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1577
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1578
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1579
    /**
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1580
     * Ensures that stores before the fence will not be reordered with
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1581
     * stores after the fence.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1582
     */
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1583
    @ForceInline
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1584
    public static void storeStoreFence() {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1585
        UNSAFE.storeStoreFence();
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1586
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1587
}