On Fri, 27 Mar 2026 13:28:23 GMT, Stefan Karlsson <[email protected]> wrote:

>> If the markword logic is going away then sure. I have to query why we 
>> have/had two ways of querying this though? Optimization?
>
> My understanding is that this was implemented as optimizations, but things 
> get complicated because of object monitors and displaced mark words, and the 
> optimizations bring conditional branches. I've looked through the C++ code 
> and can't see anything where these optimizations seems to be necessary 
> compared to the overhead of the surrounding code. C2 still uses these mark 
> word bits for creating optimized code.
> 
> My wish is to make it so that the `oopDesc::is_` functions call into 
> `obj->klass()->is_` functions. If we ever find a place in the C++ code where 
> we get noticeably penalized for decoding the klass pointer, then we place a 
> localized mark-word check optimization there. And then we evaluate if that 
> optimization really gives us the sought after performance benefit that we 
> hoped to get.

IIRC, the `flat_array_bits` in the markword is there to help minimizing the 
performance hit on code using good old Java arrays (non-flat). Because of array 
covariance, a runtime check is needed to test if the array is flat or not when 
the static type of the array is `Object[]`, an array of interfaces, or an array 
of an abstract value class. In some situations, JITs are able to collect more 
information about the array real type, and can skip this check, but in many 
cases, this check cannot be elided. It was important to have a very fast check 
to minimize the impact, especially on legacy code not using value types.
The problem with having a bit in the markword, as explain by Stefan, is that 
the bit is not always present. The other ways the check can be performed are 1) 
to check the `_kind` field of the ArrayKlass by calling 
`klass()->is_flatArray_klass()` or 2) check the layout helper with 
`layout_helper_is_flatArray(klass()->layout_helper())`.

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

PR Review Comment: 
https://git.openjdk.org/valhalla/pull/2261#discussion_r3001084016

Reply via email to