Skip to content

Commit adc3604

Browse files
committed
8325148: Enable restricted javac warning in java.base
Reviewed-by: erikj, jvernee, mcimadamore, pminborg, ihse
1 parent 1ae8513 commit adc3604

File tree

9 files changed

+28
-18
lines changed

9 files changed

+28
-18
lines changed

make/modules/java.base/Java.gmk

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
33
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
#
55
# This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@
2323
# questions.
2424
#
2525

26-
DISABLED_WARNINGS_java += this-escape restricted
26+
DISABLED_WARNINGS_java += this-escape
2727

2828
DOCLINT += -Xdoclint:all/protected \
2929
'-Xdoclint/package:java.*,javax.*'

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

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -205,6 +205,7 @@ default SymbolLookup or(SymbolLookup other) {
205205
* @see System#loadLibrary(String)
206206
*/
207207
@CallerSensitive
208+
@SuppressWarnings("restricted")
208209
static SymbolLookup loaderLookup() {
209210
Class<?> caller = Reflection.getCallerClass();
210211
// If there's no caller class, fallback to system loader
@@ -227,7 +228,7 @@ static SymbolLookup loaderLookup() {
227228
return addr == 0L ?
228229
Optional.empty() :
229230
Optional.of(MemorySegment.ofAddress(addr)
230-
.reinterpret(loaderArena, null));
231+
.reinterpret(loaderArena, null)); // restricted
231232
};
232233
}
233234

@@ -300,6 +301,7 @@ static SymbolLookup libraryLookup(Path path, Arena arena) {
300301
return libraryLookup(path, RawNativeLibraries::load, arena);
301302
}
302303

304+
@SuppressWarnings("restricted")
303305
private static <Z>
304306
SymbolLookup libraryLookup(Z libDesc,
305307
BiFunction<RawNativeLibraries, Z, NativeLibrary> loadLibraryFunc,
@@ -327,7 +329,7 @@ public void cleanup() {
327329
return addr == 0L ?
328330
Optional.empty() :
329331
Optional.of(MemorySegment.ofAddress(addr)
330-
.reinterpret(libArena, null));
332+
.reinterpret(libArena, null)); // restricted
331333
};
332334
}
333335
}

src/java.base/share/classes/jdk/internal/foreign/SystemLookup.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -101,6 +101,7 @@ public Boolean run() {
101101
SymbolLookup fallbackLibLookup =
102102
libLookup(libs -> libs.load(jdkLibraryPath("syslookup")));
103103

104+
@SuppressWarnings("restricted")
104105
MemorySegment funcs = fallbackLibLookup.find("funcs").orElseThrow()
105106
.reinterpret(WindowsFallbackSymbols.LAYOUT.byteSize());
106107

src/java.base/share/classes/jdk/internal/foreign/abi/AbstractLinker.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -256,6 +256,7 @@ private void checkHasNaturalAlignment(MemoryLayout layout) {
256256
}
257257
}
258258

259+
@SuppressWarnings("restricted")
259260
private static MemoryLayout stripNames(MemoryLayout ml) {
260261
// we don't care about transferring alignment and byte order here
261262
// since the linker already restricts those such that they will always be the same
@@ -264,7 +265,7 @@ private static MemoryLayout stripNames(MemoryLayout ml) {
264265
case UnionLayout ul -> MemoryLayout.unionLayout(stripNames(ul.memberLayouts()));
265266
case SequenceLayout sl -> MemoryLayout.sequenceLayout(sl.elementCount(), stripNames(sl.elementLayout()));
266267
case AddressLayout al -> al.targetLayout()
267-
.map(tl -> al.withoutName().withTargetLayout(stripNames(tl)))
268+
.map(tl -> al.withoutName().withTargetLayout(stripNames(tl))) // restricted
268269
.orElseGet(al::withoutName);
269270
default -> ml.withoutName(); // ValueLayout and PaddingLayout
270271
};

src/java.base/share/classes/jdk/internal/foreign/abi/Binding.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -749,11 +749,12 @@ public void verify(Deque<Class<?>> stack) {
749749
}
750750

751751
@Override
752+
@SuppressWarnings("restricted")
752753
public void interpret(Deque<Object> stack, StoreFunc storeFunc,
753754
LoadFunc loadFunc, SegmentAllocator allocator) {
754755
MemorySegment segment = Utils.longToAddress((long) stack.pop(), size, align);
755756
if (needsScope) {
756-
segment = segment.reinterpret((Arena) allocator, null);
757+
segment = segment.reinterpret((Arena) allocator, null); // restricted
757758
}
758759
stack.push(segment);
759760
}

src/java.base/share/classes/jdk/internal/foreign/abi/SharedUtils.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -81,6 +81,7 @@ private SharedUtils() {
8181
public static final MethodHandle MH_CHECK_SYMBOL;
8282
private static final MethodHandle MH_CHECK_CAPTURE_SEGMENT;
8383

84+
@SuppressWarnings("restricted")
8485
public static final AddressLayout C_POINTER = ADDRESS
8586
.withTargetLayout(MemoryLayout.sequenceLayout(Long.MAX_VALUE, JAVA_BYTE));
8687

src/java.base/share/classes/jdk/internal/foreign/abi/UpcallStubs.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -51,13 +51,14 @@ private static void freeUpcallStub(long stubAddress) {
5151
registerNatives();
5252
}
5353

54+
@SuppressWarnings("restricted")
5455
static MemorySegment makeUpcall(long entry, Arena arena) {
5556
MemorySessionImpl.toMemorySession(arena).addOrCleanupIfFail(new MemorySessionImpl.ResourceList.ResourceCleanup() {
5657
@Override
5758
public void cleanup() {
5859
freeUpcallStub(entry);
5960
}
6061
});
61-
return MemorySegment.ofAddress(entry).reinterpret(arena, null);
62+
return MemorySegment.ofAddress(entry).reinterpret(arena, null); // restricted
6263
}
6364
}

src/java.base/share/classes/jdk/internal/foreign/abi/fallback/FallbackLinker.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -218,21 +218,22 @@ private static Object doDowncall(SegmentAllocator returnAllocator, Object[] args
218218
// note that cif is not used, but we store it here to keep it alive
219219
private record UpcallData(MemoryLayout returnLayout, List<MemoryLayout> argLayouts, MemorySegment cif) {}
220220

221+
@SuppressWarnings("restricted")
221222
private static void doUpcall(MethodHandle target, MemorySegment retPtr, MemorySegment argPtrs, UpcallData data) throws Throwable {
222223
List<MemoryLayout> argLayouts = data.argLayouts();
223224
int numArgs = argLayouts.size();
224225
MemoryLayout retLayout = data.returnLayout();
225226
try (Arena upcallArena = Arena.ofConfined()) {
226227
MemorySegment argsSeg = argPtrs.reinterpret(numArgs * ADDRESS.byteSize(), upcallArena, null);
227228
MemorySegment retSeg = retLayout != null
228-
? retPtr.reinterpret(retLayout.byteSize(), upcallArena, null)
229+
? retPtr.reinterpret(retLayout.byteSize(), upcallArena, null) // restricted
229230
: null;
230231

231232
Object[] args = new Object[numArgs];
232233
for (int i = 0; i < numArgs; i++) {
233234
MemoryLayout argLayout = argLayouts.get(i);
234235
MemorySegment argPtr = argsSeg.getAtIndex(ADDRESS, i)
235-
.reinterpret(argLayout.byteSize(), upcallArena, null);
236+
.reinterpret(argLayout.byteSize(), upcallArena, null); // restricted
236237
args[i] = readValue(argPtr, argLayout);
237238
}
238239

src/java.base/share/classes/jdk/internal/foreign/abi/fallback/LibFallback.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -160,6 +160,7 @@ static MemorySegment prepCifVar(MemorySegment returnType, int numFixedArgs, int
160160
* @throws IllegalStateException if the call to {@code ffi_prep_closure_loc} returns a non-zero status code
161161
* @throws IllegalArgumentException if {@code target} does not have the right type
162162
*/
163+
@SuppressWarnings("restricted")
163164
static MemorySegment createClosure(MemorySegment cif, MethodHandle target, Arena arena)
164165
throws IllegalStateException, IllegalArgumentException {
165166
if (target.type() != UPCALL_TARGET_TYPE) {
@@ -172,7 +173,8 @@ static MemorySegment createClosure(MemorySegment cif, MethodHandle target, Arena
172173
long execPtr = ptrs[1];
173174
long globalTarget = ptrs[2];
174175

175-
return MemorySegment.ofAddress(execPtr).reinterpret(arena, unused -> freeClosure(closurePtr, globalTarget));
176+
return MemorySegment.ofAddress(execPtr)
177+
.reinterpret(arena, unused -> freeClosure(closurePtr, globalTarget)); // restricted
176178
}
177179

178180
// the target function for a closure call

0 commit comments

Comments
 (0)