Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8267612: Declare package-private VarHandle.AccessMode/AccessType counts
Reviewed-by: mchung
  • Loading branch information
cl4es committed May 25, 2021
1 parent a52c4ed commit 66b190e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
Expand Up @@ -45,7 +45,7 @@
/* package */ class IndirectVarHandle extends VarHandle {

@Stable
private final MethodHandle[] handleMap = new MethodHandle[AccessMode.values().length];
private final MethodHandle[] handleMap = new MethodHandle[AccessMode.COUNT];
private final VarHandle directTarget; // cache, for performance reasons
private final VarHandle target;
private final BiFunction<AccessMode, MethodHandle, MethodHandle> handleFactory;
Expand Down
4 changes: 2 additions & 2 deletions src/java.base/share/classes/java/lang/invoke/Invokers.java
Expand Up @@ -55,8 +55,8 @@ class Invokers {
INV_GENERIC = 1, // MethodHandles.invoker (generic invocation)
INV_BASIC = 2, // MethodHandles.basicInvoker
VH_INV_EXACT = 3, // MethodHandles.varHandleExactInvoker
VH_INV_GENERIC = VH_INV_EXACT + VarHandle.AccessMode.values().length, // MethodHandles.varHandleInvoker
INV_LIMIT = VH_INV_GENERIC + VarHandle.AccessMode.values().length;
VH_INV_GENERIC = VH_INV_EXACT + VarHandle.AccessMode.COUNT, // MethodHandles.varHandleInvoker
INV_LIMIT = VH_INV_GENERIC + VarHandle.AccessMode.COUNT;

/** Compute and cache information common to all collecting adapters
* that implement members of the erasure-family of the given erased type.
Expand Down
6 changes: 3 additions & 3 deletions src/java.base/share/classes/java/lang/invoke/VarForm.java
Expand Up @@ -49,8 +49,8 @@ final class VarForm {
final @Stable MemberName[] memberName_table;

VarForm(Class<?> implClass, Class<?> receiver, Class<?> value, Class<?>... intermediate) {
this.methodType_table = new MethodType[VarHandle.AccessType.values().length];
this.memberName_table = new MemberName[VarHandle.AccessMode.values().length];
this.methodType_table = new MethodType[VarHandle.AccessType.COUNT];
this.memberName_table = new MemberName[VarHandle.AccessMode.COUNT];
this.implClass = implClass;
if (receiver == null) {
initMethodTypes(value, intermediate);
Expand All @@ -64,7 +64,7 @@ final class VarForm {

// Used by IndirectVarHandle
VarForm(Class<?> value, Class<?>[] coordinates) {
this.methodType_table = new MethodType[VarHandle.AccessType.values().length];
this.methodType_table = new MethodType[VarHandle.AccessType.COUNT];
this.memberName_table = null;
this.implClass = null;
initMethodTypes(value, coordinates);
Expand Down
14 changes: 10 additions & 4 deletions src/java.base/share/classes/java/lang/invoke/VarHandle.java
Expand Up @@ -1637,6 +1637,10 @@ enum AccessType {
COMPARE_AND_EXCHANGE(Object.class),
GET_AND_UPDATE(Object.class);

static final int COUNT = GET_AND_UPDATE.ordinal() + 1;
static {
assert (COUNT == values().length);
}
final Class<?> returnType;
final boolean isMonomorphicInReturnType;

Expand Down Expand Up @@ -1891,6 +1895,10 @@ public enum AccessMode {
GET_AND_BITWISE_XOR_ACQUIRE("getAndBitwiseXorAcquire", AccessType.GET_AND_UPDATE),
;

static final int COUNT = GET_AND_BITWISE_XOR_ACQUIRE.ordinal() + 1;
static {
assert (COUNT == values().length);
}
final String methodName;
final AccessType at;

Expand Down Expand Up @@ -2126,12 +2134,10 @@ public Optional<VarHandleDesc> describeConstable() {

static class TypesAndInvokers {
final @Stable
MethodType[] methodType_table =
new MethodType[VarHandle.AccessType.values().length];
MethodType[] methodType_table = new MethodType[VarHandle.AccessType.COUNT];

final @Stable
MethodHandle[] methodHandle_table =
new MethodHandle[AccessMode.values().length];
MethodHandle[] methodHandle_table = new MethodHandle[AccessMode.COUNT];
}

@ForceInline
Expand Down

1 comment on commit 66b190e

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.