RFR: 8338596: Clarify handling of restricted and caller-sensitive methods [v2]
Maurizio Cimadamore
mcimadamore at openjdk.org
Thu Sep 19 14:11:36 UTC 2024
On Thu, 19 Sep 2024 13:59:30 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
>> This PR moves the section on restricted methods from the the javadoc of `java.lang.foreign` package into a standalone static [javadoc page](https://cr.openjdk.org/~mcimadamore/jdk/restricted_javadoc_section/docs/api/java.base/java/lang/foreign/doc-files/RestrictedMethods.html).
>>
>> This is because, after [JEP 472](https://openjdk.org/jeps/472), we now have restricted methods *outside* the foreign package, namely `System::loadLibrary`, `Runtime::loadLibrary` (and related methods). And, even before, we also had a restricted method in `ModuleLayer.Controller`.
>>
>> The new static page contains some guidance of what happens when a restricted method is called when there's no Java frame on the stack (this can happen e.g. when upcalling into a restricted method from a native thread not known to the JVM) - that is, the call is treated as originating from an unnamed module.
>>
>> The static page is linked from the restricted method banner in a restricted method javadoc. Here's an [example](https://cr.openjdk.org/~mcimadamore/jdk/restricted_javadoc_section/docs/api/java.base/java/lang/foreign/Linker.html#downcallHandle(java.lang.foreign.MemorySegment,java.lang.foreign.FunctionDescriptor,java.lang.foreign.Linker.Option...)).
>
> Maurizio Cimadamore has updated the pull request incrementally with one additional commit since the last revision:
>
> Move restricted method page to `java.lang`
> Update restricted method page
src/java.base/share/classes/java/lang/doc-files/RestrictedMethods.html line 41:
> 39: done either via implementation-specific command line options or programmatically, e.g.
> 40: by calling <a href="../../ModuleLayer.Controller.html#enableNativeAccess(java.lang.Module)"><code>ModuleLayer.Controller.enableNativeAccess(java.lang.Module)</code></a>.</p>
> 41: <p>When a restricted method is invoked by <a href="../../../../specs/jni/index.html">JNI code</a>,
IMHO, having this text here is better than copy and paste a similar version of this text in 14 (!!) places. That's why we added the `@Restricted` annotation, to make sure that uniform javadoc is generated for all restricted methods.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/21067#discussion_r1766909046
More information about the core-libs-dev
mailing list