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 {

View file

@ -27,6 +27,7 @@ package java.net;
import jdk.internal.event.SocketReadEvent;
import jdk.internal.event.SocketWriteEvent;
import jdk.internal.invoke.MhUtil;
import sun.security.util.SecurityConstants;
import java.io.InputStream;
@ -102,14 +103,10 @@ import java.util.Collections;
public class Socket implements java.io.Closeable {
private static final VarHandle STATE, IN, OUT;
static {
try {
MethodHandles.Lookup l = MethodHandles.lookup();
STATE = l.findVarHandle(Socket.class, "state", int.class);
IN = l.findVarHandle(Socket.class, "in", InputStream.class);
OUT = l.findVarHandle(Socket.class, "out", OutputStream.class);
} catch (Exception e) {
throw new InternalError(e);
}
MethodHandles.Lookup l = MethodHandles.lookup();
STATE = MhUtil.findVarHandle(l, "state", int.class);
IN = MhUtil.findVarHandle(l, "in", InputStream.class);
OUT = MhUtil.findVarHandle(l, "out", OutputStream.class);
}
// the underlying SocketImpl, may be null, may be swapped when connecting

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 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
@ -25,6 +25,8 @@
package java.nio.channels;
import jdk.internal.invoke.MhUtil;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
@ -429,15 +431,9 @@ public abstract class SelectionKey {
// -- Attachments --
private static final VarHandle ATTACHMENT;
static {
try {
MethodHandles.Lookup l = MethodHandles.lookup();
ATTACHMENT = l.findVarHandle(SelectionKey.class, "attachment", Object.class);
} catch (Exception e) {
throw new InternalError(e);
}
}
private static final VarHandle ATTACHMENT = MhUtil.findVarHandle(
MethodHandles.lookup(), "attachment", Object.class);
private volatile Object attachment;
/**

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 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
@ -30,6 +30,7 @@ import java.lang.invoke.VarHandle;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import jdk.internal.invoke.MhUtil;
import sun.nio.ch.SelectionKeyImpl;
import sun.nio.ch.SelectorImpl;
@ -46,15 +47,8 @@ import sun.nio.ch.SelectorImpl;
public abstract class AbstractSelectionKey
extends SelectionKey
{
private static final VarHandle INVALID;
static {
try {
MethodHandles.Lookup l = MethodHandles.lookup();
INVALID = l.findVarHandle(AbstractSelectionKey.class, "invalid", boolean.class);
} catch (Exception e) {
throw new InternalError(e);
}
}
private static final VarHandle INVALID = MhUtil.findVarHandle(
MethodHandles.lookup(), "invalid", boolean.class);
/**
* Initializes a new instance of this class.

View file

@ -32,6 +32,8 @@ import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.util.HashSet;
import java.util.Set;
import jdk.internal.invoke.MhUtil;
import sun.nio.ch.Interruptible;
import sun.nio.ch.SelectorImpl;
@ -72,15 +74,9 @@ import sun.nio.ch.SelectorImpl;
public abstract class AbstractSelector
extends Selector
{
private static final VarHandle CLOSED;
static {
try {
MethodHandles.Lookup l = MethodHandles.lookup();
CLOSED = l.findVarHandle(AbstractSelector.class, "closed", boolean.class);
} catch (Exception e) {
throw new InternalError(e);
}
}
private static final VarHandle CLOSED = MhUtil.findVarHandle(
MethodHandles.lookup(), "closed", boolean.class);
private volatile boolean closed;
// The provider that created this selector

View file

@ -35,6 +35,8 @@
package java.util.concurrent;
import jdk.internal.invoke.MhUtil;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import java.util.concurrent.locks.LockSupport;
@ -3079,14 +3081,10 @@ public class CompletableFuture<T> implements Future<T>, CompletionStage<T> {
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);
}
MethodHandles.Lookup l = MethodHandles.lookup();
RESULT = MhUtil.findVarHandle(l, "result", Object.class);
STACK = MhUtil.findVarHandle(l, "stack", Completion.class);
NEXT = MhUtil.findVarHandle(l, Completion.class, "next", Completion.class);
// Reduce the risk of rare disastrous classloading in first call to
// LockSupport.park: https://bugs.openjdk.org/browse/JDK-8074773

View file

@ -36,6 +36,8 @@
package java.util.concurrent;
import jdk.internal.invoke.MhUtil;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import java.util.concurrent.locks.LockSupport;
@ -530,15 +532,11 @@ public class Exchanger<V> {
private static final VarHandle ENTRY;
private static final VarHandle AA;
static {
try {
MethodHandles.Lookup l = MethodHandles.lookup();
BOUND = l.findVarHandle(Exchanger.class, "bound", int.class);
MATCH = l.findVarHandle(Node.class, "match", Object.class);
ENTRY = l.findVarHandle(Slot.class, "entry", Node.class);
AA = MethodHandles.arrayElementVarHandle(Slot[].class);
} catch (ReflectiveOperationException e) {
throw new ExceptionInInitializerError(e);
}
MethodHandles.Lookup l = MethodHandles.lookup();
BOUND = MhUtil.findVarHandle(l, "bound", int.class);
MATCH = MhUtil.findVarHandle(l, Node.class, "match", Object.class);
ENTRY = MhUtil.findVarHandle(l, Slot.class, "entry", Node.class);
AA = MethodHandles.arrayElementVarHandle(Slot[].class);
}
}

View file

@ -35,6 +35,8 @@
package java.util.concurrent;
import jdk.internal.invoke.MhUtil;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import java.util.concurrent.locks.LockSupport;
@ -582,14 +584,10 @@ public class FutureTask<V> implements RunnableFuture<V> {
private static final VarHandle RUNNER;
private static final VarHandle WAITERS;
static {
try {
MethodHandles.Lookup l = MethodHandles.lookup();
STATE = l.findVarHandle(FutureTask.class, "state", int.class);
RUNNER = l.findVarHandle(FutureTask.class, "runner", Thread.class);
WAITERS = l.findVarHandle(FutureTask.class, "waiters", WaitNode.class);
} catch (ReflectiveOperationException e) {
throw new ExceptionInInitializerError(e);
}
MethodHandles.Lookup l = MethodHandles.lookup();
STATE = MhUtil.findVarHandle(l, "state", int.class);
RUNNER = MhUtil.findVarHandle(l, "runner", Thread.class);
WAITERS = MhUtil.findVarHandle(l, "waiters", WaitNode.class);
// Reduce the risk of rare disastrous classloading in first call to
// LockSupport.park: https://bugs.openjdk.org/browse/JDK-8074773

View file

@ -35,6 +35,8 @@
package java.util.concurrent;
import jdk.internal.invoke.MhUtil;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import java.util.concurrent.atomic.AtomicReference;
@ -1137,15 +1139,9 @@ public class Phaser {
}
// VarHandle mechanics
private static final VarHandle STATE;
private static final VarHandle STATE = MhUtil.findVarHandle(
MethodHandles.lookup(), "state", long.class);
static {
try {
MethodHandles.Lookup l = MethodHandles.lookup();
STATE = l.findVarHandle(Phaser.class, "state", long.class);
} catch (ReflectiveOperationException e) {
throw new ExceptionInInitializerError(e);
}
// Reduce the risk of rare disastrous classloading in first call to
// LockSupport.park: https://bugs.openjdk.org/browse/JDK-8074773
Class<?> ensureLoaded = LockSupport.class;

View file

@ -53,6 +53,7 @@ import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Consumer;
import java.util.function.Predicate;
import jdk.internal.access.SharedSecrets;
import jdk.internal.invoke.MhUtil;
import jdk.internal.util.ArraysSupport;
/**
@ -1093,15 +1094,8 @@ public class PriorityBlockingQueue<E> extends AbstractQueue<E>
}
// VarHandle mechanics
private static final VarHandle ALLOCATIONSPINLOCK;
static {
try {
MethodHandles.Lookup l = MethodHandles.lookup();
ALLOCATIONSPINLOCK = l.findVarHandle(PriorityBlockingQueue.class,
"allocationSpinLock",
int.class);
} catch (ReflectiveOperationException e) {
throw new ExceptionInInitializerError(e);
}
}
private static final VarHandle ALLOCATIONSPINLOCK =
MhUtil.findVarHandle(
MethodHandles.lookup(), "allocationSpinLock", int.class);
}

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
@ -37,6 +37,7 @@ import java.util.function.Function;
import java.util.function.Supplier;
import jdk.internal.javac.PreviewFeature;
import jdk.internal.misc.ThreadFlock;
import jdk.internal.invoke.MhUtil;
/**
* A basic API for <em>structured concurrency</em>. {@code StructuredTaskScope} supports
@ -990,13 +991,9 @@ public class StructuredTaskScope<T> implements AutoCloseable {
private static final VarHandle FIRST_RESULT;
private static final VarHandle FIRST_EXCEPTION;
static {
try {
MethodHandles.Lookup l = MethodHandles.lookup();
FIRST_RESULT = l.findVarHandle(ShutdownOnSuccess.class, "firstResult", Object.class);
FIRST_EXCEPTION = l.findVarHandle(ShutdownOnSuccess.class, "firstException", Throwable.class);
} catch (Exception e) {
throw new ExceptionInInitializerError(e);
}
MethodHandles.Lookup l = MethodHandles.lookup();
FIRST_RESULT = MhUtil.findVarHandle(l, "firstResult", Object.class);
FIRST_EXCEPTION = MhUtil.findVarHandle(l, "firstException", Throwable.class);
}
private volatile Object firstResult;
private volatile Throwable firstException;
@ -1177,15 +1174,8 @@ public class StructuredTaskScope<T> implements AutoCloseable {
*/
@PreviewFeature(feature = PreviewFeature.Feature.STRUCTURED_CONCURRENCY)
public static final class ShutdownOnFailure extends StructuredTaskScope<Object> {
private static final VarHandle FIRST_EXCEPTION;
static {
try {
MethodHandles.Lookup l = MethodHandles.lookup();
FIRST_EXCEPTION = l.findVarHandle(ShutdownOnFailure.class, "firstException", Throwable.class);
} catch (Exception e) {
throw new ExceptionInInitializerError(e);
}
}
private static final VarHandle FIRST_EXCEPTION =
MhUtil.findVarHandle(MethodHandles.lookup(), "firstException", Throwable.class);
private volatile Throwable firstException;
/**

View file

@ -35,6 +35,8 @@
package java.util.concurrent;
import jdk.internal.invoke.MhUtil;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import java.util.ArrayList;
@ -1505,16 +1507,10 @@ public class SubmissionPublisher<T> implements Publisher<T>,
static final VarHandle QA;
static {
try {
MethodHandles.Lookup l = MethodHandles.lookup();
CTL = l.findVarHandle(BufferedSubscription.class, "ctl",
int.class);
DEMAND = l.findVarHandle(BufferedSubscription.class, "demand",
long.class);
QA = MethodHandles.arrayElementVarHandle(Object[].class);
} catch (ReflectiveOperationException e) {
throw new ExceptionInInitializerError(e);
}
MethodHandles.Lookup l = MethodHandles.lookup();
CTL = MhUtil.findVarHandle(l, "ctl", int.class);
DEMAND = MhUtil.findVarHandle(l, "demand", long.class);
QA = MethodHandles.arrayElementVarHandle(Object[].class);
// Reduce the risk of rare disastrous classloading in first call to
// LockSupport.park: https://bugs.openjdk.org/browse/JDK-8074773

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 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
@ -38,6 +38,7 @@ import java.util.stream.Stream;
import static java.util.concurrent.TimeUnit.NANOSECONDS;
import jdk.internal.access.JavaLangAccess;
import jdk.internal.access.SharedSecrets;
import jdk.internal.invoke.MhUtil;
import jdk.internal.vm.ThreadContainer;
import jdk.internal.vm.ThreadContainers;
@ -48,15 +49,8 @@ import jdk.internal.vm.ThreadContainers;
class ThreadPerTaskExecutor extends ThreadContainer implements ExecutorService {
private static final JavaLangAccess JLA = SharedSecrets.getJavaLangAccess();
private static final Permission MODIFY_THREAD = new RuntimePermission("modifyThread");
private static final VarHandle STATE;
static {
try {
MethodHandles.Lookup l = MethodHandles.lookup();
STATE = l.findVarHandle(ThreadPerTaskExecutor.class, "state", int.class);
} catch (Exception e) {
throw new ExceptionInInitializerError(e);
}
}
private static final VarHandle STATE = MhUtil.findVarHandle(
MethodHandles.lookup(), "state", int.class);
private final ThreadFactory factory;
private final Set<Thread> threads = ConcurrentHashMap.newKeySet();
@ -506,14 +500,10 @@ class ThreadPerTaskExecutor extends ThreadContainer implements ExecutorService {
private static final VarHandle EXCEPTION;
private static final VarHandle EXCEPTION_COUNT;
static {
try {
MethodHandles.Lookup l = MethodHandles.lookup();
RESULT = l.findVarHandle(AnyResultHolder.class, "result", Object.class);
EXCEPTION = l.findVarHandle(AnyResultHolder.class, "exception", Throwable.class);
EXCEPTION_COUNT = l.findVarHandle(AnyResultHolder.class, "exceptionCount", int.class);
} catch (Exception e) {
throw new InternalError(e);
}
MethodHandles.Lookup l = MethodHandles.lookup();
RESULT = MhUtil.findVarHandle(l, "result", Object.class);
EXCEPTION = MhUtil.findVarHandle(l, "exception", Throwable.class);
EXCEPTION_COUNT = MhUtil.findVarHandle(l, "exceptionCount", int.class);
}
private static final Object NULL = new Object();

View file

@ -35,6 +35,8 @@
package java.util.concurrent.atomic;
import jdk.internal.invoke.MhUtil;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
@ -50,15 +52,8 @@ import java.lang.invoke.VarHandle;
*/
public class AtomicBoolean implements java.io.Serializable {
private static final long serialVersionUID = 4654671469794556979L;
private static final VarHandle VALUE;
static {
try {
MethodHandles.Lookup l = MethodHandles.lookup();
VALUE = l.findVarHandle(AtomicBoolean.class, "value", int.class);
} catch (ReflectiveOperationException e) {
throw new ExceptionInInitializerError(e);
}
}
private static final VarHandle VALUE = MhUtil.findVarHandle(
MethodHandles.lookup(), "value", int.class);
private volatile int value;

View file

@ -35,6 +35,8 @@
package java.util.concurrent.atomic;
import jdk.internal.invoke.MhUtil;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
@ -190,16 +192,8 @@ public class AtomicMarkableReference<V> {
}
// VarHandle mechanics
private static final VarHandle PAIR;
static {
try {
MethodHandles.Lookup l = MethodHandles.lookup();
PAIR = l.findVarHandle(AtomicMarkableReference.class, "pair",
Pair.class);
} catch (ReflectiveOperationException e) {
throw new ExceptionInInitializerError(e);
}
}
private static final VarHandle PAIR = MhUtil.findVarHandle(
MethodHandles.lookup(), "pair", Pair.class);
private boolean casPair(Pair<V> cmp, Pair<V> val) {
return PAIR.compareAndSet(this, cmp, val);

View file

@ -35,6 +35,8 @@
package java.util.concurrent.atomic;
import jdk.internal.invoke.MhUtil;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import java.util.function.BinaryOperator;
@ -50,15 +52,8 @@ import java.util.function.UnaryOperator;
*/
public class AtomicReference<V> implements java.io.Serializable {
private static final long serialVersionUID = -1848883965231344442L;
private static final VarHandle VALUE;
static {
try {
MethodHandles.Lookup l = MethodHandles.lookup();
VALUE = l.findVarHandle(AtomicReference.class, "value", Object.class);
} catch (ReflectiveOperationException e) {
throw new ExceptionInInitializerError(e);
}
}
private static final VarHandle VALUE = MhUtil.findVarHandle(
MethodHandles.lookup(), "value", Object.class);
@SuppressWarnings("serial") // Conditionally serializable
private volatile V value;

View file

@ -35,6 +35,8 @@
package java.util.concurrent.atomic;
import jdk.internal.invoke.MhUtil;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
@ -190,16 +192,8 @@ public class AtomicStampedReference<V> {
}
// VarHandle mechanics
private static final VarHandle PAIR;
static {
try {
MethodHandles.Lookup l = MethodHandles.lookup();
PAIR = l.findVarHandle(AtomicStampedReference.class, "pair",
Pair.class);
} catch (ReflectiveOperationException e) {
throw new ExceptionInInitializerError(e);
}
}
private static final VarHandle PAIR = MhUtil.findVarHandle(
MethodHandles.lookup(), "pair", Pair.class);
private boolean casPair(Pair<V> cmp, Pair<V> val) {
return PAIR.compareAndSet(this, cmp, val);

View file

@ -35,6 +35,8 @@
package java.util.concurrent.atomic;
import jdk.internal.invoke.MhUtil;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import java.util.Arrays;
@ -138,15 +140,8 @@ abstract class Striped64 extends Number {
}
// VarHandle mechanics
private static final VarHandle VALUE;
static {
try {
MethodHandles.Lookup l = MethodHandles.lookup();
VALUE = l.findVarHandle(Cell.class, "value", long.class);
} catch (ReflectiveOperationException e) {
throw new ExceptionInInitializerError(e);
}
}
private static final VarHandle VALUE = MhUtil.findVarHandle(
MethodHandles.lookup(), "value", long.class);
}
/** Number of CPUS, to place bound on table size */
@ -381,14 +376,12 @@ abstract class Striped64 extends Number {
private static final VarHandle CELLSBUSY;
private static final VarHandle THREAD_PROBE;
static {
try {
MethodHandles.Lookup l1 = MethodHandles.lookup();
BASE = l1.findVarHandle(Striped64.class,
"base", long.class);
CELLSBUSY = l1.findVarHandle(Striped64.class,
"cellsBusy", int.class);
MethodHandles.Lookup l1 = MethodHandles.lookup();
BASE = MhUtil.findVarHandle(l1, "base", long.class);
CELLSBUSY = MhUtil.findVarHandle(l1, "cellsBusy", int.class);
@SuppressWarnings("removal")
MethodHandles.Lookup l2 = java.security.AccessController.doPrivileged(
MethodHandles.Lookup l2 = java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<>() {
public MethodHandles.Lookup run() {
try {
@ -397,11 +390,7 @@ abstract class Striped64 extends Number {
throw new ExceptionInInitializerError(e);
}
}});
THREAD_PROBE = l2.findVarHandle(Thread.class,
"threadLocalRandomProbe", int.class);
} catch (ReflectiveOperationException e) {
throw new ExceptionInInitializerError(e);
}
THREAD_PROBE = MhUtil.findVarHandle(l2, "threadLocalRandomProbe", int.class);
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 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
@ -24,6 +24,8 @@
*/
package java.util.stream;
import jdk.internal.invoke.MhUtil;
import java.util.Objects;
import java.util.Spliterator;
import java.util.concurrent.CountedCompleter;
@ -370,15 +372,8 @@ final class ForEachOps {
private Node<T> node;
private ForEachOrderedTask<S, T> next;
private static final VarHandle NEXT;
static {
try {
MethodHandles.Lookup l = MethodHandles.lookup();
NEXT = l.findVarHandle(ForEachOrderedTask.class, "next", ForEachOrderedTask.class);
} catch (Exception e) {
throw new InternalError(e);
}
}
private static final VarHandle NEXT = MhUtil.findVarHandle(
MethodHandles.lookup(), "next", ForEachOrderedTask.class);
protected ForEachOrderedTask(PipelineHelper<T> helper,
Spliterator<S> spliterator,

View file

@ -24,6 +24,7 @@
*/
package java.util.stream;
import jdk.internal.invoke.MhUtil;
import jdk.internal.vm.annotation.ForceInline;
import java.lang.invoke.MethodHandles;
@ -453,16 +454,8 @@ final class GathererOp<T, A, R> extends ReferencePipeline<T, R> {
private Spliterator<T> spliterator;
private Hybrid next;
private static final VarHandle NEXT;
static {
try {
MethodHandles.Lookup l = MethodHandles.lookup();
NEXT = l.findVarHandle(Hybrid.class, "next", Hybrid.class);
} catch (Exception e) {
throw new InternalError(e);
}
}
private static final VarHandle NEXT = MhUtil.findVarHandle(
MethodHandles.lookup(), "next", Hybrid.class);
protected Hybrid(Spliterator<T> spliterator) {
super(null);