How to run specific part of the SerialGC in a new thread?
ofirg6 at gmail.com
Tue Jun 30 08:27:38 UTC 2020
I'll try to explain my end goal:
I simply want to "take out" the part that runs the marking phase in a full
collection with serial GC to run on a dedicated cpu (on a simulator).
So, I figured the simpler way to do that would be to create a new thread
which gets the "follow_stack" part as its task and bind it to the dedicated
cpu. Any aspect of performance or synchronization issues is currently not
relevant (maybe later it will be). I'm just looking for the simplest way to
split the "follow_stack" execution to a seperate thread, while the main
thread is waiting on it.
That's why I thought that creating this AbstractGangClass task is too
complicated for my purposes.
If there is a way to create the Task class for running only "follow_stack"
in a simple way I would really like to know.
Regarding the compilation failure, when I'm trying to include <thread> and
use it the build fails because it doesn't recognize it. I tried to add to
the configuration: --with-extra-cxxflags="-std=c++0x -pthread" but then the
"make images" command fails with the message "use of global operators new
and delete is not allowed in Hotspot".
Trying to use <pthread> didn't work out as well (different errors).
Any other suggestions? (:
בתאריך יום ג׳, 30 ביוני 2020 ב-11:10 מאת Thomas Schatzl <
thomas.schatzl at oracle.com>:
> 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
> 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.
More information about the hotspot-gc-dev