On Wed, 11 Dec 2024 18:15:57 GMT, Dan Heidinga <heidi...@openjdk.org> wrote:

>> The Class.getModifiers() method is implemented as a native method in 
>> java.lang.Class to access a field that we've calculated when creating the 
>> mirror.  The field is final after that point. The VM doesn't need it 
>> anymore, so there's no real need for the jdk code to call into the VM to get 
>> it.  This moves the field to Java and removes the intrinsic code.  I 
>> promoted the compute_modifiers() functions to return int since that's how 
>> java.lang.Class uses the value.  It should really be an unsigned short 
>> though.
>> 
>> There's a couple of JMH benchmarks added with this change.  One does show 
>> that for array classes for non-bootstrap class loader, this results in one 
>> extra load which in a long loop of just that, is observable.  I don't think 
>> this is real life code. The other benchmarks added show no regression.
>> 
>> Tested with tier1-8.
>
> src/java.base/share/classes/java/lang/Class.java line 244:
> 
>> 242:         classLoader = loader;
>> 243:         componentType = arrayComponentType;
>> 244:         modifiers = 0;
> 
> The comment above about assigning a parameter to the field to prevent the JIT 
> from assuming an incorrect default also should apply to the new `modifiers` 
> field.  I think the constructor, which is never called, should also pass in a 
> `dummyModifiers` value rather than using 0 directly

Yes, definitely, didn't see that this is the right way to do this.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/22652#discussion_r1887157349

Reply via email to