-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8355022: Implement JEP 506: Scoped Values #24923
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
ffa3b0f
b4d7767
00ded12
d3f2ff1
877f393
8f62661
a80b034
2988802
8354bcb
7d35439
460d82b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| /* | ||
| * Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved. | ||
| * Copyright (c) 2020, 2022, Red Hat Inc. | ||
| * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved. | ||
| * Copyright (c) 2020, 2025, Red Hat Inc. | ||
| * 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,7 +34,6 @@ | |
| import java.util.function.Supplier; | ||
| import jdk.internal.access.JavaUtilConcurrentTLRAccess; | ||
| import jdk.internal.access.SharedSecrets; | ||
| import jdk.internal.javac.PreviewFeature; | ||
| import jdk.internal.vm.annotation.ForceInline; | ||
| import jdk.internal.vm.annotation.Hidden; | ||
| import jdk.internal.vm.ScopedValueContainer; | ||
|
|
@@ -236,9 +235,8 @@ | |
| * have to be regenerated after a blocking operation. | ||
| * | ||
| * @param <T> the type of the value | ||
| * @since 21 | ||
| * @since 25 | ||
| */ | ||
| @PreviewFeature(feature = PreviewFeature.Feature.SCOPED_VALUES) | ||
| public final class ScopedValue<T> { | ||
| private final int hash; | ||
|
|
||
|
|
@@ -309,9 +307,8 @@ Object find(ScopedValue<?> key) { | |
| * <p> Unless otherwise specified, passing a {@code null} argument to a method in | ||
| * this class will cause a {@link NullPointerException} to be thrown. | ||
| * | ||
| * @since 21 | ||
| * @since 25 | ||
| */ | ||
| @PreviewFeature(feature = PreviewFeature.Feature.SCOPED_VALUES) | ||
theRealAph marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| public static final class Carrier { | ||
| // Bit masks: a 1 in position n indicates that this set of bound values | ||
| // hits that slot in the cache. | ||
|
|
@@ -412,7 +409,7 @@ public <T> T get(ScopedValue<T> key) { | |
| * @return the result | ||
| * @throws StructureViolationException if a structure violation is detected | ||
| * @throws X if {@code op} completes with an exception | ||
| * @since 23 | ||
| * @since 25 | ||
|
||
| */ | ||
| public <R, X extends Throwable> R call(CallableOp<? extends R, X> op) throws X { | ||
| Objects.requireNonNull(op); | ||
|
|
@@ -496,9 +493,8 @@ private void runWith(Snapshot newSnapshot, Runnable op) { | |
| * | ||
| * @param <T> result type of the operation | ||
| * @param <X> type of the exception thrown by the operation | ||
| * @since 23 | ||
| * @since 25 | ||
| */ | ||
| @PreviewFeature(feature = PreviewFeature.Feature.SCOPED_VALUES) | ||
| @FunctionalInterface | ||
| public interface CallableOp<T, X extends Throwable> { | ||
| /** | ||
|
|
@@ -611,10 +607,11 @@ private Object findBinding() { | |
| * Returns the value of this scoped value if bound in the current thread, otherwise | ||
| * returns {@code other}. | ||
| * | ||
| * @param other the value to return if not bound, can be {@code null} | ||
| * @param other the value to return if not bound | ||
| * @return the value of the scoped value if bound, otherwise {@code other} | ||
| */ | ||
| public T orElse(T other) { | ||
| Objects.requireNonNull(other); | ||
theRealAph marked this conversation as resolved.
Show resolved
Hide resolved
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't the NPE be specified in the Javadoc?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the class specification, right above the API notes: |
||
| Object obj = findBinding(); | ||
| if (obj != Snapshot.NIL) { | ||
| @SuppressWarnings("unchecked") | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It occurred to me that
ScopedValue.NEW_THREAD_BINDINGScan be made package‑private and used inThread, removing duplication inThread.NEW_THREAD_BINDINGS.This was done this way back when
ScopedValuelived under thejdk.incubator.*package tree.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better not change that in this PR, as this PR is about making the feature permanent.