RFR: 8180450: secondary_super_cache does not scale well [v14]
Vladimir Ivanov
vlivanov at openjdk.org
Fri Apr 12 17:36:46 UTC 2024
On Fri, 12 Apr 2024 15:10:19 GMT, Andrew Haley <aph at openjdk.org> wrote:
>> This PR is a redesign of subtype checking.
>>
>> The implementation of subtype checking in the HotSpot JVM is now twenty years old. There have been some performance-related bugs reported, and the only way to fix them is a redesign of the way it works.
>>
>> So what's changed, so that the old design should be replaced?
>>
>> Firstly, the computers of today aren't the computers of twenty years ago. It's not merely a matter of speed: the systems are much more parallel, both in the sense of having more cores and each core can run many instructions in parallel. Because of this, the speed ratio between memory accesses and the rate at which we can execute instructions has become wider and wider.
>>
>> The most severe reported problem is to do with the "secondary supers cache". This is a 1-element per-class cache for interfaces (and arrays of interfaces). Unfortunately, if two threads repeatedly update this cache, the result is that a cache line ping-pongs between cores, causing a severe slowdown.
>>
>> Also, the linear search for an interface that is absent means that the entire list of interfaces has to be scanned. This plays badly with newer language features such as JEP 406, pattern matching for switch.
>>
>> However, the computers of today can help us. The very high instruction-per-cycle rate of a Great Big Out-Of-Order (GBOOO) processor allows us to execute many of the instructions of a hash table lookup in parallel, as long as we avoid dependencies between instructions.
>>
>> The solution
>> ------------
>>
>> We use a hashed lookup of secondary supers. This is a 64-way hash table, with linear probing for collisions. The table is compressed, in that null entries are removed, and the resulting hash table fits into the same secondary supers array as today's unsorted array of secondary supers. This means that existing code in HotSpot that simply does a linear scan of the secondary supers array does not need to be altered.
>>
>> We add a bitmap field to each Klass object. This bitmap contains an occupancy bit corresponding to each element of the hash table, with a 1 indicating element presence. As well as allowing the hash table to be decompressed, this bimap is used as a simple kind of Bloom Filter. To determine whether a superclass is present, we simply have to check a single bit in the bitmap. If the bit is clear, we know that the superclass is not present. If the bit is set, we have to do a little arithmetic and then consult the hash table.
>>
>> It works like th...
>
> Andrew Haley has updated the pull request incrementally with one additional commit since the last revision:
>
> JDK-8180450: secondary_super_cache does not scale well
>> At some point in the hopefully-not-very-distant future I'd like to kill secondary_super_cache altogether, and then everyone will use the stubs. But I can move the call to the code that generates the stubs for now, if you like?
> Done.
Thank you.
As the code looks now, I have some doubts the stubs can be reused outside C2.
First of all, they are targeted at constant superclass case and don't yet support non-constant/reflective case. Moreover, from previous experiments I learned that it's far from trivial to rely on stubs across the whole VM. Subtype checks are performed by template interpreter and other stubs (e.g., arraycopy), so the stubs they rely on should be ready by the time they are generated. And there's not much benefit from not inlining the whole slow path code for secondary super lookup there.
C1 may benefit from the stubs, but slow path there is already represented as a stub. So, I don't expect much benefit from reusing C2 stubs there as well.
Overall, as of now, it looks premature to optimize for future use cases. As part of work supporting remaining cases (template interpreter, stubs, C1, non-constant case in C2) it'll become clear what's the best representation. So, focusing on C2 use case and optimizing for it looks reasonable.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/18309#issuecomment-2052189683
More information about the hotspot-dev
mailing list