RFR: 8337622: IllegalArgumentException in java.lang.reflect.Field.get [v2]

Coleen Phillimore coleenp at openjdk.org
Fri Aug 9 11:53:33 UTC 2024


On Thu, 8 Aug 2024 16:49:09 GMT, Coleen Phillimore <coleenp at openjdk.org> wrote:

>> Make the object init_lock be an injected field in the mirror so that reflecting on componentType will not inadvertently return the init_lock.  The init_lock is a Java object and the VM holds it during class linking and uses it to set state during class initialization.
>> Tested with tier1-8.
>
> Coleen Phillimore has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Fix copyright lines.

Given that this field doesn't use metaspace, the answer to that is no. Because Java objects are aligned on 64 bit boundaries (for 64 bits), the extra 32 bits for the init_lock doesn't actually add to the base size of the mirror oop:

Before with printing in create_mirror:

    $ java -cp ~/work Hello
    sizeof java_lang_class 14
    sizeof java_lang_class 14
    sizeof java_lang_class 14
    ...

After with this change:

    $ java -cp ~/work Hello
    sizeof java_lang_class 14
    sizeof java_lang_class 14
    sizeof java_lang_class 14
    sizeof java_lang_class 14 ...

Remember that static fields are added to the mirror (instance of java.lang.Class) so its size varies.  These first few classes don't have static members.

If legacy applications are a concern we don't have to backport this past JDK 21.  JDK 11 and 17 don't have the exception for reflecting on the componentType field and getting the int array.  I do have a different fix to remove the init_lock again to reduce inflated monitors in our runtime locking code but that's not backport-able.

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

PR Comment: https://git.openjdk.org/jdk/pull/20498#issuecomment-2277772147


More information about the hotspot-runtime-dev mailing list