mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 14:24:46 +02:00
8325949: Create an internal utility method for creating VarHandle instances
Reviewed-by: rriggs
This commit is contained in:
parent
67448b0eb2
commit
384deda65f
31 changed files with 232 additions and 317 deletions
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue