mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8194233: Improve support for array handles
Reviewed-by: jrose, vlivanov, ahgross, rhalade
This commit is contained in:
parent
97c8fdb2dd
commit
9b54e6d766
12 changed files with 248 additions and 24 deletions
|
@ -592,6 +592,28 @@ final class VarHandle$Type$s {
|
|||
return accessMode.at.accessModeType({#if[Object]?arrayType:$type$[].class}, {#if[Object]?arrayType.getComponentType():$type$.class}, int.class);
|
||||
}
|
||||
|
||||
#if[Object]
|
||||
@ForceInline
|
||||
static Object runtimeTypeCheck(Array handle, Object[] oarray, Object value) {
|
||||
if (handle.arrayType == oarray.getClass()) {
|
||||
// Fast path: static array type same as argument array type
|
||||
return handle.componentType.cast(value);
|
||||
} else {
|
||||
// Slow path: check value against argument array component type
|
||||
return reflectiveTypeCheck(oarray, value);
|
||||
}
|
||||
}
|
||||
|
||||
@ForceInline
|
||||
static Object reflectiveTypeCheck(Object[] oarray, Object value) {
|
||||
try {
|
||||
return oarray.getClass().getComponentType().cast(value);
|
||||
} catch (ClassCastException e) {
|
||||
throw new ArrayStoreException();
|
||||
}
|
||||
}
|
||||
#end[Object]
|
||||
|
||||
@ForceInline
|
||||
static $type$ get(Array handle, Object oarray, int index) {
|
||||
#if[Object]
|
||||
|
@ -632,7 +654,7 @@ final class VarHandle$Type$s {
|
|||
#end[Object]
|
||||
UNSAFE.put$Type$Volatile(array,
|
||||
(((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
|
||||
{#if[Object]?handle.componentType.cast(value):value});
|
||||
{#if[Object]?runtimeTypeCheck(handle, array, value):value});
|
||||
}
|
||||
|
||||
@ForceInline
|
||||
|
@ -655,7 +677,7 @@ final class VarHandle$Type$s {
|
|||
#end[Object]
|
||||
UNSAFE.put$Type$Opaque(array,
|
||||
(((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
|
||||
{#if[Object]?handle.componentType.cast(value):value});
|
||||
{#if[Object]?runtimeTypeCheck(handle, array, value):value});
|
||||
}
|
||||
|
||||
@ForceInline
|
||||
|
@ -678,7 +700,7 @@ final class VarHandle$Type$s {
|
|||
#end[Object]
|
||||
UNSAFE.put$Type$Release(array,
|
||||
(((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
|
||||
{#if[Object]?handle.componentType.cast(value):value});
|
||||
{#if[Object]?runtimeTypeCheck(handle, array, value):value});
|
||||
}
|
||||
#if[CAS]
|
||||
|
||||
|
@ -692,7 +714,7 @@ final class VarHandle$Type$s {
|
|||
return UNSAFE.compareAndSet$Type$(array,
|
||||
(((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
|
||||
{#if[Object]?handle.componentType.cast(expected):expected},
|
||||
{#if[Object]?handle.componentType.cast(value):value});
|
||||
{#if[Object]?runtimeTypeCheck(handle, array, value):value});
|
||||
}
|
||||
|
||||
@ForceInline
|
||||
|
@ -705,7 +727,7 @@ final class VarHandle$Type$s {
|
|||
return UNSAFE.compareAndExchange$Type$(array,
|
||||
(((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
|
||||
{#if[Object]?handle.componentType.cast(expected):expected},
|
||||
{#if[Object]?handle.componentType.cast(value):value});
|
||||
{#if[Object]?runtimeTypeCheck(handle, array, value):value});
|
||||
}
|
||||
|
||||
@ForceInline
|
||||
|
@ -718,7 +740,7 @@ final class VarHandle$Type$s {
|
|||
return UNSAFE.compareAndExchange$Type$Acquire(array,
|
||||
(((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
|
||||
{#if[Object]?handle.componentType.cast(expected):expected},
|
||||
{#if[Object]?handle.componentType.cast(value):value});
|
||||
{#if[Object]?runtimeTypeCheck(handle, array, value):value});
|
||||
}
|
||||
|
||||
@ForceInline
|
||||
|
@ -731,7 +753,7 @@ final class VarHandle$Type$s {
|
|||
return UNSAFE.compareAndExchange$Type$Release(array,
|
||||
(((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
|
||||
{#if[Object]?handle.componentType.cast(expected):expected},
|
||||
{#if[Object]?handle.componentType.cast(value):value});
|
||||
{#if[Object]?runtimeTypeCheck(handle, array, value):value});
|
||||
}
|
||||
|
||||
@ForceInline
|
||||
|
@ -744,7 +766,7 @@ final class VarHandle$Type$s {
|
|||
return UNSAFE.weakCompareAndSet$Type$Plain(array,
|
||||
(((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
|
||||
{#if[Object]?handle.componentType.cast(expected):expected},
|
||||
{#if[Object]?handle.componentType.cast(value):value});
|
||||
{#if[Object]?runtimeTypeCheck(handle, array, value):value});
|
||||
}
|
||||
|
||||
@ForceInline
|
||||
|
@ -757,7 +779,7 @@ final class VarHandle$Type$s {
|
|||
return UNSAFE.weakCompareAndSet$Type$(array,
|
||||
(((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
|
||||
{#if[Object]?handle.componentType.cast(expected):expected},
|
||||
{#if[Object]?handle.componentType.cast(value):value});
|
||||
{#if[Object]?runtimeTypeCheck(handle, array, value):value});
|
||||
}
|
||||
|
||||
@ForceInline
|
||||
|
@ -770,7 +792,7 @@ final class VarHandle$Type$s {
|
|||
return UNSAFE.weakCompareAndSet$Type$Acquire(array,
|
||||
(((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
|
||||
{#if[Object]?handle.componentType.cast(expected):expected},
|
||||
{#if[Object]?handle.componentType.cast(value):value});
|
||||
{#if[Object]?runtimeTypeCheck(handle, array, value):value});
|
||||
}
|
||||
|
||||
@ForceInline
|
||||
|
@ -783,7 +805,7 @@ final class VarHandle$Type$s {
|
|||
return UNSAFE.weakCompareAndSet$Type$Release(array,
|
||||
(((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
|
||||
{#if[Object]?handle.componentType.cast(expected):expected},
|
||||
{#if[Object]?handle.componentType.cast(value):value});
|
||||
{#if[Object]?runtimeTypeCheck(handle, array, value):value});
|
||||
}
|
||||
|
||||
@ForceInline
|
||||
|
@ -795,7 +817,7 @@ final class VarHandle$Type$s {
|
|||
#end[Object]
|
||||
return UNSAFE.getAndSet$Type$(array,
|
||||
(((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
|
||||
{#if[Object]?handle.componentType.cast(value):value});
|
||||
{#if[Object]?runtimeTypeCheck(handle, array, value):value});
|
||||
}
|
||||
|
||||
@ForceInline
|
||||
|
@ -807,7 +829,7 @@ final class VarHandle$Type$s {
|
|||
#end[Object]
|
||||
return UNSAFE.getAndSet$Type$Acquire(array,
|
||||
(((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
|
||||
{#if[Object]?handle.componentType.cast(value):value});
|
||||
{#if[Object]?runtimeTypeCheck(handle, array, value):value});
|
||||
}
|
||||
|
||||
@ForceInline
|
||||
|
@ -819,7 +841,7 @@ final class VarHandle$Type$s {
|
|||
#end[Object]
|
||||
return UNSAFE.getAndSet$Type$Release(array,
|
||||
(((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
|
||||
{#if[Object]?handle.componentType.cast(value):value});
|
||||
{#if[Object]?runtimeTypeCheck(handle, array, value):value});
|
||||
}
|
||||
#end[CAS]
|
||||
#if[AtomicAdd]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue