RFR: 8317809: Insertion of free code blobs into code cache can be very slow during class unloading [v5]

Albert Mingkun Yang ayang at openjdk.org
Mon Dec 4 09:11:47 UTC 2023


On Mon, 4 Dec 2023 07:56:04 GMT, Thomas Schatzl <tschatzl at openjdk.org> wrote:

>> Insert code blobs in a sorted fashion to exploit the finger-optimization when adding, making this procedure O(n) instead of O(n^2)
>> 
>> Introduces a globally available ClassUnloadingContext that contains common methods pertaining to class and code unloading. GCs may use it to efficiently manage unlinked class loader datas and nmethods to allow use of common methods (unlink/merge).
>> 
>> The steps typically are registering a new to be unlinked CLD/nmethod, and then purge its memory later. STW collectors perform this work in one big chunk taking the CodeCache_lock, for the entire duration, while concurrent collectors lock/unlock for every insertion to allow for concurrent users for the lock to progress.
>> 
>> Some care has been taken to stay consistent with an "unloading = unlinking + purge" scheme; however particularly the existing CLD handling API (still) mixes unlinking and purging in its CLD::unload() call. To simplify this change that is mostly geared towards separating nmethod unlinking from purging, to make code blob freeing O(n) instead of O(n^2).
>> 
>> Upcoming changes will
>> * separate nmethod unregistering from nmethod purging to allow doing that in bulk (for the STW collectors); that can significantly reduce code purging time for the STW collectors.
>> * better name the second stage of unlinking (called "cleaning" throughout, e.g. the work done in `G1CollectedHeap::complete_cleaning`)
>> * untangle CLD unlinking and what's called "cleaning" now to allow moving more stuff into the second unlinking stage for better parallelism
>> * G1: move some significant tasks from the remark pause to concurrent (unregistering nmethods, freeing code blobs and cld/metaspace purging)
>> * Maybe move Serial/Parallel GC metaspace purging closer to other unlinking/purging code to keep things local and allow easier logging.
>> 
>> Please also first looking into the (small) PR this depends on.
>> 
>> The crash on linux-x86 is fixed by PR#16766 which I split out for quicker reviews.
>> 
>> Testing: tier1-7
>> 
>> Thanks,
>>   Thomas
>
> Thomas Schatzl has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains ten commits:
> 
>  - Merge branch 'master' into 8317809-sorted-insertion-of-free-blobs
>  - remove trailing whitespace
>  - fix indentation after recent commit
>  - Address ayang/iwalulya review comments, remove inheritance in ClassUnloadingContext for now as unnecessary for this change, use iterators, other review comments
>  - Merge branch 'master' into mergeme
>  - iwalulya review, naming
>  - 8317809 Insert code blobs in a sorted fashion to exploit the finger-optimization when adding, making this procedure O(n) instead of O(n^2)
>    
>    Introduce a globally available ClassUnloadingContext that contains common methods pertaining to class and code unloading.
>    GCs may use it to efficiently manage unlinked class loader datas and nmethods to allow use of common methods (unlink/merge).
>    
>    The steps typically are registering a new to be unlinked CLD/nmethod, and then purge its memory later. STW collectors perform
>    this work in one big chunk taking the CodeCache_lock, for the entire duration, while concurrent collectors lock/unlock for every
>    insertion to allow for concurrent users for the lock to progress.
>    
>    Some care has been taken to stay consistent with an "unloading = unlinking + purge" scheme; however particularly the existing
>    CLD handling API (still) mixes unlinking and purging in its CLD::unload() call. To simplify this change that is mostly geared
>    towards separating nmethod unlinking from purging, to make code blob freeing O(n) instead of O(n^2).
>    
>    Upcoming changes will
>    * separate nmethod unregistering from nmethod purging to allow doing that in bulk (for the STW collectors); that can significantly
>      reduce code purging time for the STW collectors.
>    * better name the second stage of unlinking (called "cleaning" throughout, e.g. the work done in `G1CollectedHeap::complete_cleaning`)
>    * untangle CLD unlinking and what's called "cleaning" now to allow moving more stuff into the second unlinking stage for better
>      parallelism
>    * G1: move some signifcant tasks from the remark pause to concurrent (unregistering nmethods, freeing code blobs and cld/metaspace purging)
>    * Maybe move Serial/Parallel GC metaspace purging closer to other unlinking/purging code to keep things local and allow easier logging.
>  - Only run test case on debug VMs, sufficient
>  - 8320331 g1 full gc "during" verification accesses half-unloa...

src/hotspot/share/gc/shared/classUnloadingContext.hpp line 38:

> 36:   static ClassUnloadingContext* _context;
> 37: 
> 38:   ClassLoaderData* volatile _cld_head;

I don't get why `ClassLoaderData* volatile _cld_head;` needs to be inside `ClassUnloadingContext`. What's the motivation for the change to files in `src/hotspot/share/classfile/`? Seems that they have nothing to do with other fields inside this class, which are for sort-before-free of nmethods.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/16759#discussion_r1413566268


More information about the hotspot-gc-dev mailing list