RFR: 8265842: G1: Introduce API to run multiple separate tasks in a single gangtask

Stefan Johansson sjohanss at openjdk.java.net
Tue Apr 27 09:26:36 UTC 2021


On Fri, 23 Apr 2021 13:33:51 GMT, Thomas Schatzl <tschatzl at openjdk.org> wrote:

> This makes use a bit more clumsy that expected, see the `G1CollectedHeap::post_evacuate_cleanup_1/2` methods:
> 
> ```
> void G1CollectedHeap::post_evacuate_cleanup_1(G1ParScanThreadStateSet* per_thread_states,
>                                           G1RedirtyCardsQueueSet* rdcqs) {
>   Ticks start = Ticks::now();
>   {
>     G1PostEvacuateCollectionSetCleanupTask1 cl(per_thread_states, rdcqs);
>     uint num_threads = MAX2(1u, MIN2(cl.num_busy_workers(), workers()->active_workers()));
>     cl.set_max_workers(num_threads);
>     workers()->run_task(&cl, num_threads);
>    }
>    [...]
>  }
> ```
> 
> i.e. since the constructor is used for setup, there is some small code duplication necessary to time execution of such a `G1BatchedGangTask`. @walulyai suggested (similar to other hotspot code) to introduce a `setup` method, but no `teardown`.
> 
> There is no reason for me to not to, any concerns or other ideas?

I'm not sure I exactly understand how `setup()` would be used, but a `run_batched_task(...)` might help some of the duplication:

void G1CollectedHeap::run_batched_task(G1BatchedGangTask* task) {
  uint num_threads = MAX2(1u, MIN2(cl.num_busy_workers(), workers()->active_workers()));
  task.set_max_workers(num_threads);
  workers()->run_task(task);
}

I assume the work in the constructor and destructor should be measured, since it is in the example, otherwise the timing could be added to the helper as well.

Basically the only other question/concern I have after looking at the patch is if we can some how get rid or change `num_busy_workers()`. I guess we might need some way to estimate the needed number of workers but does it have to return a `double`. To me it is strange that something can require a fraction of a worker. I understand that certain task are very small and for those we could consider returning 0. Or would that cause other problems?

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

PR: https://git.openjdk.java.net/jdk/pull/3653



More information about the hotspot-gc-dev mailing list