8283470: Update java.lang.invoke.VarHandle to use sealed classes
Reviewed-by: darcy, psandoz
This commit is contained in:
parent
e85fa2f04b
commit
e61ccfba7f
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -42,7 +42,7 @@ import java.util.function.BiFunction;
|
||||
* (using the method handle combinator API) and then repackaging the adapted method handles into a new, indirect
|
||||
* var handle.
|
||||
*/
|
||||
/* package */ class IndirectVarHandle extends VarHandle {
|
||||
/* package */ final class IndirectVarHandle extends VarHandle {
|
||||
|
||||
@Stable
|
||||
private final MethodHandle[] handleMap = new MethodHandle[AccessMode.COUNT];
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -28,7 +28,15 @@ package java.lang.invoke;
|
||||
/**
|
||||
* Base class for memory access var handle implementations.
|
||||
*/
|
||||
abstract class MemoryAccessVarHandleBase extends VarHandle {
|
||||
abstract sealed class MemoryAccessVarHandleBase extends VarHandle permits
|
||||
MemoryAccessVarHandleByteHelper,
|
||||
MemoryAccessVarHandleCharHelper,
|
||||
MemoryAccessVarHandleDoubleHelper,
|
||||
MemoryAccessVarHandleFloatHelper,
|
||||
MemoryAccessVarHandleIntHelper,
|
||||
MemoryAccessVarHandleLongHelper,
|
||||
MemoryAccessVarHandleShortHelper
|
||||
{
|
||||
|
||||
/** endianness **/
|
||||
final boolean be;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -31,15 +31,10 @@ import java.lang.constant.ConstantDesc;
|
||||
import java.lang.constant.ConstantDescs;
|
||||
import java.lang.constant.DirectMethodHandleDesc;
|
||||
import java.lang.constant.DynamicConstantDesc;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
|
||||
import jdk.internal.util.Preconditions;
|
||||
import jdk.internal.vm.annotation.DontInline;
|
||||
import jdk.internal.vm.annotation.ForceInline;
|
||||
import jdk.internal.vm.annotation.IntrinsicCandidate;
|
||||
@ -476,7 +471,41 @@ import static java.lang.invoke.MethodHandleStatics.UNSAFE;
|
||||
* @see MethodType
|
||||
* @since 9
|
||||
*/
|
||||
public abstract class VarHandle implements Constable {
|
||||
public abstract sealed class VarHandle implements Constable
|
||||
permits IndirectVarHandle, MemoryAccessVarHandleBase,
|
||||
VarHandleByteArrayAsChars.ByteArrayViewVarHandle,
|
||||
VarHandleByteArrayAsDoubles.ByteArrayViewVarHandle,
|
||||
VarHandleByteArrayAsFloats.ByteArrayViewVarHandle,
|
||||
VarHandleByteArrayAsInts.ByteArrayViewVarHandle,
|
||||
VarHandleByteArrayAsLongs.ByteArrayViewVarHandle,
|
||||
VarHandleByteArrayAsShorts.ByteArrayViewVarHandle,
|
||||
VarHandleBooleans.Array,
|
||||
VarHandleBooleans.FieldInstanceReadOnly,
|
||||
VarHandleBooleans.FieldStaticReadOnly,
|
||||
VarHandleBytes.Array,
|
||||
VarHandleBytes.FieldInstanceReadOnly,
|
||||
VarHandleBytes.FieldStaticReadOnly,
|
||||
VarHandleChars.Array,
|
||||
VarHandleChars.FieldInstanceReadOnly,
|
||||
VarHandleChars.FieldStaticReadOnly,
|
||||
VarHandleDoubles.Array,
|
||||
VarHandleDoubles.FieldInstanceReadOnly,
|
||||
VarHandleDoubles.FieldStaticReadOnly,
|
||||
VarHandleFloats.Array,
|
||||
VarHandleFloats.FieldInstanceReadOnly,
|
||||
VarHandleFloats.FieldStaticReadOnly,
|
||||
VarHandleInts.Array,
|
||||
VarHandleInts.FieldInstanceReadOnly,
|
||||
VarHandleInts.FieldStaticReadOnly,
|
||||
VarHandleLongs.Array,
|
||||
VarHandleLongs.FieldInstanceReadOnly,
|
||||
VarHandleLongs.FieldStaticReadOnly,
|
||||
VarHandleReferences.Array,
|
||||
VarHandleReferences.FieldInstanceReadOnly,
|
||||
VarHandleReferences.FieldStaticReadOnly,
|
||||
VarHandleShorts.Array,
|
||||
VarHandleShorts.FieldInstanceReadOnly,
|
||||
VarHandleShorts.FieldStaticReadOnly {
|
||||
final VarForm vform;
|
||||
final boolean exact;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -37,7 +37,7 @@ import static java.lang.invoke.MethodHandleStatics.UNSAFE;
|
||||
|
||||
final class VarHandle$Type$s {
|
||||
|
||||
static class FieldInstanceReadOnly extends VarHandle {
|
||||
static sealed class FieldInstanceReadOnly extends VarHandle {
|
||||
final long fieldOffset;
|
||||
final Class<?> receiverType;
|
||||
#if[Object]
|
||||
@ -381,7 +381,7 @@ final class VarHandle$Type$s {
|
||||
}
|
||||
|
||||
|
||||
static class FieldStaticReadOnly extends VarHandle {
|
||||
static sealed class FieldStaticReadOnly extends VarHandle {
|
||||
final Object base;
|
||||
final long fieldOffset;
|
||||
#if[Object]
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -71,7 +71,7 @@ final class VarHandleByteArrayAs$Type$s extends VarHandleByteArrayBase {
|
||||
#end[floatingPoint]
|
||||
|
||||
|
||||
private static abstract class ByteArrayViewVarHandle extends VarHandle {
|
||||
static abstract sealed class ByteArrayViewVarHandle extends VarHandle {
|
||||
final boolean be;
|
||||
|
||||
ByteArrayViewVarHandle(VarForm form, boolean be, boolean exact) {
|
||||
|
Loading…
Reference in New Issue
Block a user