RFR: 8282191: Implementation of Foreign Function & Memory API (Preview) [v37]

Maurizio Cimadamore mcimadamore at openjdk.java.net
Wed May 4 23:32:49 UTC 2022


On Wed, 4 May 2022 23:20:21 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> src/java.base/share/classes/java/lang/foreign/SymbolLookup.java line 153:
>> 
>>> 151:     static SymbolLookup loaderLookup() {
>>> 152:         Class<?> caller = Reflection.getCallerClass();
>>> 153:         ClassLoader loader = Objects.requireNonNull(caller.getClassLoader());
>> 
>> Shouldn’t this be changed to throw `IllegalCallerException` instead of throwing `NullPointerException` when the `caller`’s `ClassLoader` is `null`[^1] or when `caller` itself is `null`[^2]?
>> 
>> [^1]: This happens when `caller` is on the bootstrap classpath.
>> [^2]: This happens when `SymbolLookup.loaderLookup()` is called by native code and no **Java** code is on the call stack.
>
> Good points. Regarding `ClassLoader` being null, I think we can still return something using the `BootLoader`'s `NativeLibraries` object - that would allow this method to be called internally. @mlchung Can you please confirm?
> 
> As for the caller sensitive having no real caller (e.g. because method is called directly from native code), I think we should add a check in `Reflection::ensureNativeAccess`. Few weeks ago I verified that adding such a check does not compromise upcall stub created via the Linker interface (e.g. a Java upcall might require to perform restricted operations - but those operation always happen inside the upcall MH, which is always associated with some class).

Another option would be to treat calls to `ensureNativeAccess` with `null` caller class as coming from unnamed module.

-------------

PR: https://git.openjdk.java.net/jdk/pull/7888



More information about the build-dev mailing list