-
Enhancement
-
Resolution: Fixed
-
P5
-
24
-
b17
In over 70 cases in the JDK, we obtain a static VarHandle for some variables and need to go through tedious static initialization blocks. It would be better to provide a utility method that captures any exceptions and wraps them into an Error.
Old:
private static final VarHandle STATE;
static {
try {
MethodHandles.Lookup l = MethodHandles.lookup();
STATE = l.findVarHandle(Phaser.class, "state", long.class);
} catch (ReflectiveOperationException e) {
throw new ExceptionInInitializerError(e);
}
New:
private static final VarHandle STATE =
XUtil.findVarHandleOrThrow(MethodHandles.lookup(), Phaser.class, "state", long.class);
Old:
private static final VarHandle RESULT;
private static final VarHandle STACK;
private static final VarHandle NEXT;
static {
try {
MethodHandles.Lookup l = MethodHandles.lookup();
RESULT = l.findVarHandle(CompletableFuture.class, "result", Object.class);
STACK = l.findVarHandle(CompletableFuture.class, "stack", Completion.class);
NEXT = l.findVarHandle(Completion.class, "next", Completion.class);
} catch (ReflectiveOperationException e) {
throw new ExceptionInInitializerError(e);
}
}
New:
private static final VarHandle RESULT;
private static final VarHandle STACK;
private static final VarHandle NEXT;
static {
MethodHandles.Lookup l = MethodHandles.lookup();
RESULT = XUtil.findVarHandleOrThrow(l, CompletableFuture.class, "result", Object.class);
STACK = XUtil.findVarHandleOrThrow(l, CompletableFuture.class, "stack", Completion.class);
NEXT = XUtil.findVarHandleOrThrow(l, Completion.class, "next", Completion.class);
}
The use of these handles is covered extensively by existing tests so I've marked this issue "noreg-other".
Old:
private static final VarHandle STATE;
static {
try {
MethodHandles.Lookup l = MethodHandles.lookup();
STATE = l.findVarHandle(Phaser.class, "state", long.class);
} catch (ReflectiveOperationException e) {
throw new ExceptionInInitializerError(e);
}
New:
private static final VarHandle STATE =
XUtil.findVarHandleOrThrow(MethodHandles.lookup(), Phaser.class, "state", long.class);
Old:
private static final VarHandle RESULT;
private static final VarHandle STACK;
private static final VarHandle NEXT;
static {
try {
MethodHandles.Lookup l = MethodHandles.lookup();
RESULT = l.findVarHandle(CompletableFuture.class, "result", Object.class);
STACK = l.findVarHandle(CompletableFuture.class, "stack", Completion.class);
NEXT = l.findVarHandle(Completion.class, "next", Completion.class);
} catch (ReflectiveOperationException e) {
throw new ExceptionInInitializerError(e);
}
}
New:
private static final VarHandle RESULT;
private static final VarHandle STACK;
private static final VarHandle NEXT;
static {
MethodHandles.Lookup l = MethodHandles.lookup();
RESULT = XUtil.findVarHandleOrThrow(l, CompletableFuture.class, "result", Object.class);
STACK = XUtil.findVarHandleOrThrow(l, CompletableFuture.class, "stack", Completion.class);
NEXT = XUtil.findVarHandleOrThrow(l, Completion.class, "next", Completion.class);
}
The use of these handles is covered extensively by existing tests so I've marked this issue "noreg-other".
- links to
-
Commit(master) openjdk/jdk/384deda6
-
Review(master) openjdk/jdk/20972