How to run specific part of the SerialGC in a new thread?

Thomas Schatzl thomas.schatzl at oracle.com
Tue Jun 30 08:09:50 UTC 2020


Hi,

On 30.06.20 09:02, Ofir Gordon wrote:
> Hi,
> Sorry for the late followup, thank you for the answer.
> I looked at the WorkGang mechanism and it seems a little overkill for my 
> purposes, I only want to be able to split the task to a different thread 
> and wait for it to complete. From what I understand, in order to do this 
> with WotkGang I need to create a dedicated AbstractGangClass which will 
> need to include all methods of the scenario I'm trying to run separately..

I am not completely clear about the problem here: of course the spawned 
thread needs to include (call) the method(s) you want it to run, so 
there seems to be no difference than any other mechanism.

The original question also asked about a single ("a new thread") thread 
doing all the work, so the problem you have with WorkGang is even more 
puzzling to me.

I agree that there is some boilerplate involved with AbstractGangClass, 
but pthreads with all the manual synchronization involved seems to be 
much worse.

Maybe you want to do multiple tasks once each by multiple threads? What 
Hotspot code usually does in this case is that every worker claims a 
part of that work.

There is e.g. SubTasksDone that could help you with that, see e.g. 
G1RootProcessor or any other use for an application.

Otherwise please clarify your use case.

> Is it not possible to use pthread or similar libraries within the code? 
> Is there another way that doesn't require using WorkGang?
> 

Workgang is the simply the simplest option ;) I think managing a 
Thread/NamedThread yourselves could be fine too if you want to keep the 
rest of Hotspot working, but that (like pthreads) involves coding the 
synchronization between main and worker thread yourselves.

The reason why pthread most likely fails with trying to do existing work 
is that they want to implicitly access some members of the thread during 
processing, e.g. logging and others, but idk as I do not know the code. 
I have no idea why using pthreads breaks compilation: at least on 
Linux/BSD/lots of others it is in use already.

So if that work you are trying to move into a separate thread is 
completely independent of existing work, pthreads should work just fine.

Thanks,
   Thomas


More information about the hotspot-gc-dev mailing list