-
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
Closed
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ffa3b0f
Implement JEP 506: Scoped Values
b4d7767
8355720: Implement JEP 506: Scoped Values
00ded12
ScopedValue::orElse() does not accept null as an argument.
d3f2ff1
Since when?
877f393
Remove unnecessary @enablePreview in some tests
8f62661
Remove unnecessary @since 25
a80b034
ScopedValue::orElse() does not accept null as an argument.
2988802
Merge from https://github.com/openjdk/jdk
8354bcb
Fix merge
7d35439
Fix merge
460d82b
Merge from JDK head
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| /* | ||
| * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved. | ||
| * Copyright (c) 2020, 2022, Red Hat Inc. | ||
| * 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; | ||
|
|
@@ -237,9 +236,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; | ||
|
|
||
|
|
@@ -310,9 +308,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. | ||
|
|
@@ -413,7 +410,6 @@ 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 | ||
| */ | ||
| public <R, X extends Throwable> R call(CallableOp<? extends R, X> op) throws X { | ||
| Objects.requireNonNull(op); | ||
|
|
@@ -497,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> { | ||
| /** | ||
|
|
@@ -612,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") | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.