8325949: Create an internal utility method for creating VarHandle instances

Reviewed-by: rriggs
This commit is contained in:
Per Minborg 2024-09-23 10:57:43 +00:00
parent 67448b0eb2
commit 384deda65f
31 changed files with 232 additions and 317 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2024, 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
@ -34,6 +34,7 @@ import java.util.Objects;
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadFactory;
import jdk.internal.misc.Unsafe;
import jdk.internal.invoke.MhUtil;
import jdk.internal.vm.ContinuationSupport;
/**
@ -273,15 +274,9 @@ class ThreadBuilders {
* Base ThreadFactory implementation.
*/
private abstract static class BaseThreadFactory implements ThreadFactory {
private static final VarHandle COUNT;
static {
try {
MethodHandles.Lookup l = MethodHandles.lookup();
COUNT = l.findVarHandle(BaseThreadFactory.class, "count", long.class);
} catch (Exception e) {
throw new InternalError(e);
}
}
private static final VarHandle COUNT = MhUtil.findVarHandle(
MethodHandles.lookup(), "count", long.class);
private final String name;
private final int characteristics;
private final UncaughtExceptionHandler uhe;

View file

@ -25,6 +25,7 @@
package java.lang.invoke;
import jdk.internal.invoke.MhUtil;
import jdk.internal.vm.annotation.DontInline;
import jdk.internal.vm.annotation.ForceInline;
import jdk.internal.vm.annotation.Hidden;
@ -681,16 +682,9 @@ class Invokers {
}
private static class Lazy {
private static final MethodHandle MH_asSpreader;
static {
try {
MH_asSpreader = IMPL_LOOKUP.findVirtual(MethodHandle.class, "asSpreader",
MethodType.methodType(MethodHandle.class, Class.class, int.class));
} catch (ReflectiveOperationException ex) {
throw newInternalError(ex);
}
}
private static final MethodHandle MH_asSpreader = MhUtil.findVirtual(
IMPL_LOOKUP, MethodHandle.class, "asSpreader",
MethodType.methodType(MethodHandle.class, Class.class, int.class));
}
static {