8325148: Enable restricted javac warning in java.base

Reviewed-by: erikj, jvernee, mcimadamore, pminborg, ihse
This commit is contained in:
Joe Darcy 2024-02-02 17:47:28 +00:00
parent 1ae851387f
commit adc3604027
9 changed files with 28 additions and 18 deletions

View File

@ -1,5 +1,5 @@
#
# Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2020, 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
@ -23,7 +23,7 @@
# questions.
#
DISABLED_WARNINGS_java += this-escape restricted
DISABLED_WARNINGS_java += this-escape
DOCLINT += -Xdoclint:all/protected \
'-Xdoclint/package:java.*,javax.*'

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 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
@ -205,6 +205,7 @@ public interface SymbolLookup {
* @see System#loadLibrary(String)
*/
@CallerSensitive
@SuppressWarnings("restricted")
static SymbolLookup loaderLookup() {
Class<?> caller = Reflection.getCallerClass();
// If there's no caller class, fallback to system loader
@ -227,7 +228,7 @@ public interface SymbolLookup {
return addr == 0L ?
Optional.empty() :
Optional.of(MemorySegment.ofAddress(addr)
.reinterpret(loaderArena, null));
.reinterpret(loaderArena, null)); // restricted
};
}
@ -300,6 +301,7 @@ public interface SymbolLookup {
return libraryLookup(path, RawNativeLibraries::load, arena);
}
@SuppressWarnings("restricted")
private static <Z>
SymbolLookup libraryLookup(Z libDesc,
BiFunction<RawNativeLibraries, Z, NativeLibrary> loadLibraryFunc,
@ -327,7 +329,7 @@ public interface SymbolLookup {
return addr == 0L ?
Optional.empty() :
Optional.of(MemorySegment.ofAddress(addr)
.reinterpret(libArena, null));
.reinterpret(libArena, null)); // restricted
};
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 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
@ -101,6 +101,7 @@ public final class SystemLookup implements SymbolLookup {
SymbolLookup fallbackLibLookup =
libLookup(libs -> libs.load(jdkLibraryPath("syslookup")));
@SuppressWarnings("restricted")
MemorySegment funcs = fallbackLibLookup.find("funcs").orElseThrow()
.reinterpret(WindowsFallbackSymbols.LAYOUT.byteSize());

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 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
@ -256,6 +256,7 @@ public abstract sealed class AbstractLinker implements Linker permits LinuxAArch
}
}
@SuppressWarnings("restricted")
private static MemoryLayout stripNames(MemoryLayout ml) {
// we don't care about transferring alignment and byte order here
// since the linker already restricts those such that they will always be the same
@ -264,7 +265,7 @@ public abstract sealed class AbstractLinker implements Linker permits LinuxAArch
case UnionLayout ul -> MemoryLayout.unionLayout(stripNames(ul.memberLayouts()));
case SequenceLayout sl -> MemoryLayout.sequenceLayout(sl.elementCount(), stripNames(sl.elementLayout()));
case AddressLayout al -> al.targetLayout()
.map(tl -> al.withoutName().withTargetLayout(stripNames(tl)))
.map(tl -> al.withoutName().withTargetLayout(stripNames(tl))) // restricted
.orElseGet(al::withoutName);
default -> ml.withoutName(); // ValueLayout and PaddingLayout
};

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 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
@ -749,11 +749,12 @@ public sealed interface Binding {
}
@Override
@SuppressWarnings("restricted")
public void interpret(Deque<Object> stack, StoreFunc storeFunc,
LoadFunc loadFunc, SegmentAllocator allocator) {
MemorySegment segment = Utils.longToAddress((long) stack.pop(), size, align);
if (needsScope) {
segment = segment.reinterpret((Arena) allocator, null);
segment = segment.reinterpret((Arena) allocator, null); // restricted
}
stack.push(segment);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 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
@ -81,6 +81,7 @@ public final class SharedUtils {
public static final MethodHandle MH_CHECK_SYMBOL;
private static final MethodHandle MH_CHECK_CAPTURE_SEGMENT;
@SuppressWarnings("restricted")
public static final AddressLayout C_POINTER = ADDRESS
.withTargetLayout(MemoryLayout.sequenceLayout(Long.MAX_VALUE, JAVA_BYTE));

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 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
@ -51,6 +51,7 @@ public final class UpcallStubs {
registerNatives();
}
@SuppressWarnings("restricted")
static MemorySegment makeUpcall(long entry, Arena arena) {
MemorySessionImpl.toMemorySession(arena).addOrCleanupIfFail(new MemorySessionImpl.ResourceList.ResourceCleanup() {
@Override
@ -58,6 +59,6 @@ public final class UpcallStubs {
freeUpcallStub(entry);
}
});
return MemorySegment.ofAddress(entry).reinterpret(arena, null);
return MemorySegment.ofAddress(entry).reinterpret(arena, null); // restricted
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 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
@ -218,6 +218,7 @@ public final class FallbackLinker extends AbstractLinker {
// note that cif is not used, but we store it here to keep it alive
private record UpcallData(MemoryLayout returnLayout, List<MemoryLayout> argLayouts, MemorySegment cif) {}
@SuppressWarnings("restricted")
private static void doUpcall(MethodHandle target, MemorySegment retPtr, MemorySegment argPtrs, UpcallData data) throws Throwable {
List<MemoryLayout> argLayouts = data.argLayouts();
int numArgs = argLayouts.size();
@ -225,14 +226,14 @@ public final class FallbackLinker extends AbstractLinker {
try (Arena upcallArena = Arena.ofConfined()) {
MemorySegment argsSeg = argPtrs.reinterpret(numArgs * ADDRESS.byteSize(), upcallArena, null);
MemorySegment retSeg = retLayout != null
? retPtr.reinterpret(retLayout.byteSize(), upcallArena, null)
? retPtr.reinterpret(retLayout.byteSize(), upcallArena, null) // restricted
: null;
Object[] args = new Object[numArgs];
for (int i = 0; i < numArgs; i++) {
MemoryLayout argLayout = argLayouts.get(i);
MemorySegment argPtr = argsSeg.getAtIndex(ADDRESS, i)
.reinterpret(argLayout.byteSize(), upcallArena, null);
.reinterpret(argLayout.byteSize(), upcallArena, null); // restricted
args[i] = readValue(argPtr, argLayout);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 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
@ -160,6 +160,7 @@ final class LibFallback {
* @throws IllegalStateException if the call to {@code ffi_prep_closure_loc} returns a non-zero status code
* @throws IllegalArgumentException if {@code target} does not have the right type
*/
@SuppressWarnings("restricted")
static MemorySegment createClosure(MemorySegment cif, MethodHandle target, Arena arena)
throws IllegalStateException, IllegalArgumentException {
if (target.type() != UPCALL_TARGET_TYPE) {
@ -172,7 +173,8 @@ final class LibFallback {
long execPtr = ptrs[1];
long globalTarget = ptrs[2];
return MemorySegment.ofAddress(execPtr).reinterpret(arena, unused -> freeClosure(closurePtr, globalTarget));
return MemorySegment.ofAddress(execPtr)
.reinterpret(arena, unused -> freeClosure(closurePtr, globalTarget)); // restricted
}
// the target function for a closure call