JDK-8289253 : JNI AttachCurrentThread should declare the correct parameter types
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 20
  • Priority: P4
  • Status: Resolved
  • Resolution: Withdrawn
  • Submitted: 2022-06-27
  • Updated: 2022-08-05
  • Resolved: 2022-08-05
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 20
20Resolved
Related Reports
Relates :  
Relates :  
Description
The current declaration is:

jint AttachCurrentThread(JavaVM *vm, void **p_env, void *thr_args);

but p_env must be a JNIEnv**, and thr_args must be a JavaVMAttachArgs* so we should declare them as such.

There are also number of inconsistencies in parameter naming e.g. penv vs. p_env, and vm vs p_vm, that should be made consistent across the invocation API. Some grammatical improvements in parameter descriptions can also be made e.g.

`vm`: the VM to which the current thread will be attached, must not be `NULL`.

should read:

`vm`: the VM to which the current thread will be attached. It must not be `NULL`.
Comments
It turns out that in practice we cannot make this change without breaking source compatability with existing JNI native code. While existing code of the form: JavaVMAttachArgs args; ... vm->AttachCurrentThread((void **) &env, (void *) &args); compiles without a problem (as we cast from JavaVMAttachArgs* -> void* -> JavaVMAttachArgs* which is perfectly valid); existing code of the form: vm->AttachCurrentThread((void **) &env, (void *) 0); will get a compiler error of the form: error: invalid conversion from 'void*' to 'JavaVMAttachArgs*' [-fpermissive] So this suggested improvement is being withdrawn. I will file a new issue for the argument inconsistencies and editorial changes in the description.
05-08-2022