Skip to content
This repository was archived by the owner on Apr 24, 2023. It is now read-only.
/ jdk20 Public archive

Commit f771c56

Browse files
committed
8298797: Specification of some restricted methods is incorrect
Reviewed-by: jvernee, pminborg
1 parent 0ba4734 commit f771c56

File tree

6 files changed

+19
-23
lines changed

6 files changed

+19
-23
lines changed

src/java.base/share/classes/java/lang/foreign/Linker.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,7 @@ public sealed interface Linker permits AbstractLinker {
180180
*
181181
* @return a linker for the ABI associated with the OS and processor where the Java runtime is currently executing.
182182
* @throws UnsupportedOperationException if the underlying native platform is not supported.
183-
* @throws IllegalCallerException if access to this method occurs from a module {@code M} and the command line option
184-
* {@code --enable-native-access} is specified, but does not mention the module name {@code M}, or
185-
* {@code ALL-UNNAMED} in case {@code M} is an unnamed module.
183+
* @throws IllegalCallerException If the caller is in a module that does not have native access enabled.
186184
*/
187185
@CallerSensitive
188186
static Linker nativeLinker() {

src/java.base/share/classes/java/lang/foreign/MemorySegment.java

+7-10
Original file line numberDiff line numberDiff line change
@@ -1065,9 +1065,7 @@ static MemorySegment ofAddress(long address) {
10651065
* @param byteSize the size (in bytes) of the returned native segment.
10661066
* @return a zero-length native segment with the given address and size.
10671067
* @throws IllegalArgumentException if {@code byteSize < 0}.
1068-
* @throws IllegalCallerException if access to this method occurs from a module {@code M} and the command line option
1069-
* {@code --enable-native-access} is specified, but does not mention the module name {@code M}, or
1070-
* {@code ALL-UNNAMED} in case {@code M} is an unnamed module.
1068+
* @throws IllegalCallerException If the caller is in a module that does not have native access enabled.
10711069
*/
10721070
@CallerSensitive
10731071
static MemorySegment ofAddress(long address, long byteSize) {
@@ -1088,7 +1086,10 @@ static MemorySegment ofAddress(long address, long byteSize) {
10881086
* {@snippet lang = java:
10891087
* ofAddress(address, byteSize, scope, null);
10901088
*}
1091-
*
1089+
* This method is <a href="package-summary.html#restricted"><em>restricted</em></a>.
1090+
* Restricted methods are unsafe, and, if used incorrectly, their use might crash
1091+
* the JVM or, worse, silently result in memory corruption. Thus, clients should refrain from depending on
1092+
* restricted methods, and use safe and supported functionalities, where possible.
10921093
* @param address the returned segment's address.
10931094
* @param byteSize the desired size.
10941095
* @param scope the scope associated with the returned native segment.
@@ -1097,9 +1098,7 @@ static MemorySegment ofAddress(long address, long byteSize) {
10971098
* @throws IllegalStateException if {@code scope} is not {@linkplain SegmentScope#isAlive() alive}.
10981099
* @throws WrongThreadException if this method is called from a thread {@code T},
10991100
* such that {@code scope.isAccessibleBy(T) == false}.
1100-
* @throws IllegalCallerException if access to this method occurs from a module {@code M} and the command line option
1101-
* {@code --enable-native-access} is specified, but does not mention the module name {@code M}, or
1102-
* {@code ALL-UNNAMED} in case {@code M} is an unnamed module.
1101+
* @throws IllegalCallerException If the caller is in a module that does not have native access enabled.
11031102
*/
11041103
@CallerSensitive
11051104
@ForceInline
@@ -1140,9 +1139,7 @@ static MemorySegment ofAddress(long address, long byteSize, SegmentScope scope)
11401139
* @throws IllegalStateException if {@code scope} is not {@linkplain SegmentScope#isAlive() alive}.
11411140
* @throws WrongThreadException if this method is called from a thread {@code T},
11421141
* such that {@code scope.isAccessibleBy(T) == false}.
1143-
* @throws IllegalCallerException if access to this method occurs from a module {@code M} and the command line option
1144-
* {@code --enable-native-access} is specified, but does not mention the module name {@code M}, or
1145-
* {@code ALL-UNNAMED} in case {@code M} is an unnamed module.
1142+
* @throws IllegalCallerException If the caller is in a module that does not have native access enabled.
11461143
*/
11471144
@CallerSensitive
11481145
static MemorySegment ofAddress(long address, long byteSize, SegmentScope scope, Runnable cleanupAction) {

src/java.base/share/classes/java/lang/foreign/SymbolLookup.java

+2-6
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,7 @@ static SymbolLookup loaderLookup() {
189189
* @param scope the scope associated with symbols obtained from the returned lookup.
190190
* @return a new symbol lookup suitable to find symbols in a library with the given name.
191191
* @throws IllegalArgumentException if {@code name} does not identify a valid library.
192-
* @throws IllegalCallerException if access to this method occurs from a module {@code M} and the command line option
193-
* {@code --enable-native-access} is either absent, or does not mention the module name {@code M}, or
194-
* {@code ALL-UNNAMED} in case {@code M} is an unnamed module.
192+
* @throws IllegalCallerException If the caller is in a module that does not have native access enabled.
195193
*/
196194
@CallerSensitive
197195
static SymbolLookup libraryLookup(String name, SegmentScope scope) {
@@ -215,9 +213,7 @@ static SymbolLookup libraryLookup(String name, SegmentScope scope) {
215213
* @param scope the scope associated with symbols obtained from the returned lookup.
216214
* @return a new symbol lookup suitable to find symbols in a library with the given path.
217215
* @throws IllegalArgumentException if {@code path} does not point to a valid library.
218-
* @throws IllegalCallerException if access to this method occurs from a module {@code M} and the command line option
219-
* {@code --enable-native-access} is either absent, or does not mention the module name {@code M}, or
220-
* {@code ALL-UNNAMED} in case {@code M} is an unnamed module.
216+
* @throws IllegalCallerException If the caller is in a module that does not have native access enabled.
221217
*/
222218
@CallerSensitive
223219
static SymbolLookup libraryLookup(Path path, SegmentScope scope) {

src/java.base/share/classes/java/lang/foreign/VaList.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,7 @@ public sealed interface VaList permits WinVaList, SysVVaList, LinuxAArch64VaList
247247
* @throws WrongThreadException if this method is called from a thread {@code T},
248248
* such that {@code scope.isAccessibleBy(T) == false}.
249249
* @throws UnsupportedOperationException if the underlying native platform is not supported.
250-
* @throws IllegalCallerException if access to this method occurs from a module {@code M} and the command line option
251-
* {@code --enable-native-access} is specified, but does not mention the module name {@code M}, or
252-
* {@code ALL-UNNAMED} in case {@code M} is an unnamed module.
250+
* @throws IllegalCallerException If the caller is in a module that does not have native access enabled.
253251
*/
254252
@CallerSensitive
255253
static VaList ofAddress(long address, SegmentScope scope) {

src/java.base/share/classes/java/lang/foreign/ValueLayout.java

+1
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ sealed interface OfAddress extends ValueLayout permits ValueLayouts.OfAddressImp
424424
* restricted methods, and use safe and supported functionalities, where possible.
425425
*
426426
* @return an unbounded address layout with same characteristics as this layout.
427+
* @throws IllegalCallerException If the caller is in a module that does not have native access enabled.
427428
* @see #isUnbounded()
428429
*/
429430
@CallerSensitive

test/jdk/java/foreign/handles/lookup_module/handle/lookup/MethodHandleLookup.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,15 @@ static Object[][] restrictedMethods() {
5050
return new Object[][]{
5151
{ MethodHandles.lookup().findStatic(Linker.class, "nativeLinker",
5252
MethodType.methodType(Linker.class)), "Linker::nativeLinker" },
53+
{ MethodHandles.lookup().findStatic(MemorySegment.class, "ofAddress",
54+
MethodType.methodType(MemorySegment.class, long.class, long.class)),
55+
"MemorySegment::ofAddress/2" },
5356
{ MethodHandles.lookup().findStatic(MemorySegment.class, "ofAddress",
5457
MethodType.methodType(MemorySegment.class, long.class, long.class, SegmentScope.class)),
55-
"MemorySegment::ofAddressNative" },
58+
"MemorySegment::ofAddress/3" },
59+
{ MethodHandles.lookup().findStatic(MemorySegment.class, "ofAddress",
60+
MethodType.methodType(MemorySegment.class, long.class, long.class, SegmentScope.class, Runnable.class)),
61+
"MemorySegment::ofAddress/4" },
5662
{ MethodHandles.lookup().findStatic(SymbolLookup.class, "libraryLookup",
5763
MethodType.methodType(SymbolLookup.class, String.class, SegmentScope.class)),
5864
"SymbolLookup::libraryLookup(String)" },

0 commit comments

Comments
 (0)