RFR: 8336468: Reflection and MethodHandles should use more precise initializer checks [v4]

Chen Liang liach at openjdk.org
Wed Sep 25 15:35:36 UTC 2024


On Wed, 25 Sep 2024 15:22:38 GMT, Aleksey Shipilev <shade at openjdk.org> wrote:

>> src/hotspot/share/prims/jni.cpp line 450:
>> 
>>> 448:     reflection_method = Reflection::new_constructor(m, CHECK_NULL);
>>> 449:   } else {
>>> 450:     assert(!m->is_static_initializer(), "Cannot be static initializer");
>> 
>> This looks like a behavioral change; otherwise reflection and method handle changes look good. Per JNI https://docs.oracle.com/en/java/javase/23/docs/specs/jni/functions.html#toreflectedmethod it seems to just return if the method id is valid.
>
> You mean the _assert_ is excessive, or something else? I think it is within the spec to return method for `clinit`-s, since clinits are logically not constructors.

Then this assert seems excessive. If JNI users get the method slot (presumably through some hacks) for a `<clinit>` then JNI has to return the `<clinit>` and this assert doesn't stand.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/20192#discussion_r1775461239


More information about the hotspot-dev mailing list