Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mcimadamore committed May 17, 2024
1 parent 3a0db27 commit 789bdf4
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 20 deletions.
6 changes: 5 additions & 1 deletion src/java.base/share/classes/java/lang/ClassLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -2442,8 +2442,12 @@ static NativeLibrary loadLibrary(Class<?> fromClass, String name) {
" in java.library.path: " + StaticProperty.javaLibraryPath());
}

/*
/**
* Invoked in the VM class linking code.
* @param loader the class loader used to look up the native library symbol
* @param clazz the class in which the native method is declared
* @param entryName the native method's mangled name (this is the name used for the native lookup)
* @param javaName the native method's declared name
*/
static long findNative(ClassLoader loader, Class<?> clazz, String entryName, String javaName) {
long addr = findNativeInternal(loader, entryName);
Expand Down
4 changes: 2 additions & 2 deletions src/java.base/share/classes/java/lang/Module.java
Original file line number Diff line number Diff line change
Expand Up @@ -329,14 +329,14 @@ void ensureNativeAccess(Class<?> owner, String methodName, Class<?> currentClass
String modflag = isNamed() ? getName() : "ALL-UNNAMED";
String caller = currentClass != null ? currentClass.getName() : "code";
if (jni) {
System.err.printf("""
VM.initialErr().printf("""
WARNING: A native method in %s has been bound
WARNING: %s is declared in %s
WARNING: Use --enable-native-access=%s to avoid a warning for native methods declared in this module
WARNING: Restricted methods will be blocked in a future release unless native access is enabled
%n""", cls, mtd, mod, modflag);
} else {
System.err.printf("""
VM.initialErr().printf("""
WARNING: A restricted method in %s has been called
WARNING: %s has been called by %s in %s
WARNING: Use --enable-native-access=%s to avoid a warning for callers in this module
Expand Down
6 changes: 3 additions & 3 deletions src/java.base/share/classes/java/lang/Runtime.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1995, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1995, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, Azul Systems, Inc. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -829,7 +829,7 @@ public void runFinalization() {
* a native library image by the host system.
* @throws NullPointerException if {@code filename} is
* {@code null}
* @throws IllegalCallerException If the caller is in a module that
* @throws IllegalCallerException if the caller is in a module that
* does not have native access enabled.
* @spec jni/index.html Java Native Interface Specification
* @see java.lang.Runtime#getRuntime()
Expand Down Expand Up @@ -900,7 +900,7 @@ void load0(Class<?> fromClass, String filename) {
* native library image by the host system.
* @throws NullPointerException if {@code libname} is
* {@code null}
* @throws IllegalCallerException If the caller is in a module that
* @throws IllegalCallerException if the caller is in a module that
* does not have native access enabled.
* @spec jni/index.html Java Native Interface Specification
* @see java.lang.SecurityException
Expand Down
4 changes: 2 additions & 2 deletions src/java.base/share/classes/java/lang/System.java
Original file line number Diff line number Diff line change
Expand Up @@ -2019,7 +2019,7 @@ public static void runFinalization() {
* linked with the VM, or the library cannot be mapped to
* a native library image by the host system.
* @throws NullPointerException if {@code filename} is {@code null}
* @throws IllegalCallerException If the caller is in a module that
* @throws IllegalCallerException if the caller is in a module that
* does not have native access enabled.
*
* @spec jni/index.html Java Native Interface Specification
Expand Down Expand Up @@ -2062,7 +2062,7 @@ public static void load(String filename) {
* linked with the VM, or the library cannot be mapped to a
* native library image by the host system.
* @throws NullPointerException if {@code libname} is {@code null}
* @throws IllegalCallerException If the caller is in a module that
* @throws IllegalCallerException if the caller is in a module that
* does not have native access enabled.
*
* @spec jni/index.html Java Native Interface Specification
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public sealed interface AddressLayout extends ValueLayout permits ValueLayouts.O
* @param layout the target layout
* @return an address layout with same characteristics as this layout, but with the
* provided target layout
* @throws IllegalCallerException If the caller is in a module that does not have
* @throws IllegalCallerException if the caller is in a module that does not have
* native access enabled
* @see #targetLayout()
*/
Expand Down
6 changes: 3 additions & 3 deletions src/java.base/share/classes/java/lang/foreign/Linker.java
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ static Linker nativeLinker() {
* {@code address.equals(MemorySegment.NULL)}
* @throws IllegalArgumentException if an invalid combination of linker options
* is given
* @throws IllegalCallerException If the caller is in a module that does not have
* @throws IllegalCallerException if the caller is in a module that does not have
* native access enabled
*
* @see SymbolLookup
Expand Down Expand Up @@ -684,7 +684,7 @@ MethodHandle downcallHandle(MemorySegment address,
* supported by this linker
* @throws IllegalArgumentException if an invalid combination of linker options
* is given
* @throws IllegalCallerException If the caller is in a module that does not have
* @throws IllegalCallerException if the caller is in a module that does not have
* native access enabled
*/
@CallerSensitive
Expand Down Expand Up @@ -733,7 +733,7 @@ MethodHandle downcallHandle(MemorySegment address,
* @throws IllegalStateException if {@code arena.scope().isAlive() == false}
* @throws WrongThreadException if {@code arena} is a confined arena, and this method
* is called from a thread {@code T}, other than the arena's owner thread
* @throws IllegalCallerException If the caller is in a module that does not have
* @throws IllegalCallerException if the caller is in a module that does not have
* native access enabled
*/
@CallerSensitive
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ static SymbolLookup loaderLookup() {
* @throws WrongThreadException if {@code arena} is a confined arena, and this method
* is called from a thread {@code T}, other than the arena's owner thread
* @throws IllegalArgumentException if {@code name} does not identify a valid library
* @throws IllegalCallerException If the caller is in a module that does not have
* @throws IllegalCallerException if the caller is in a module that does not have
* native access enabled
*/
@CallerSensitive
Expand Down Expand Up @@ -319,7 +319,7 @@ static SymbolLookup libraryLookup(String name, Arena arena) {
* is called from a thread {@code T}, other than the arena's owner thread
* @throws IllegalArgumentException if {@code path} does not point to a valid library
* in the default file system
* @throws IllegalCallerException If the caller is in a module that does not have
* @throws IllegalCallerException if the caller is in a module that does not have
* native access enabled
*/
@CallerSensitive
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
* where {@code M1}, {@code M2}, {@code ... Mn} are module names (for the unnamed module,
* the special value {@code ALL-UNNAMED} can be used). Access to restricted methods
* from modules not listed by that option is deemed <em>illegal</em>. Clients can
* control how illegal access to restricted method is handled, using the command line
* control how access to restricted methods is handled, using the command line
* option {@code --illegal-native-access}. If this option is not specified,
* illegal access to restricted methods will result in runtime warnings.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,12 @@ public interface JavaLangAccess {
void addEnableNativeAccessToAllUnnamed();

/**
* Ensure that the given module has native access. If not, warn or
* throw exception depending on the configuration.
* Ensure that the given module has native access. If not, warn or throw exception depending on the configuration.
* @param m the module in which native access occurred
* @param owner the owner of the restricted method being called (or the JNI method being bound)
* @param methodName the name of the restricted method being called (or the JNI method being bound)
* @param currentClass the class calling the restricted method (for JNI, this is the same as {@code owner})
* @param jni {@code true}, if this event is related to a JNI method being bound
*/
void ensureNativeAccess(Module m, Class<?> owner, String methodName, Class<?> currentClass, boolean jni);

Expand Down
4 changes: 1 addition & 3 deletions src/java.base/share/man/java.1
Original file line number Diff line number Diff line change
Expand Up @@ -582,9 +582,7 @@ module.
This mode is the default for the current JDK but will change in a future
release.
.IP \[bu] 2
\f[V]deny\f[R]: This mode disables all illegal native access except for
those modules enabled by the \f[V]--enable-native-access\f[R]
command-line option.
\f[V]deny\f[R]: This mode disables illegal native access.
That is, any illegal native access causes an
\f[V]IllegalCallerException\f[R].
This mode will become the default in a future release.
Expand Down

0 comments on commit 789bdf4

Please sign in to comment.