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

Thomas Schatzl thomas.schatzl at oracle.com
Mon Jul 6 09:13:49 UTC 2020


Hi,

   sorry for the late answer, I started writing but then forgot to send 
the email. :(

On 30.06.20 10:27, Ofir Gordon wrote:
> 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.

WorkGang* w = new WorkGang("My Work Gang", 1, true, false);
w->initialize();

Store w in some static somewhere in MarkSweep.

[...]

void MarkSweep::new_follow_stack() {
   class MyGangTask : public AbstractGangTask {
   public:
     MyGangTask() : AbstractGangTask("My Gang Task") { }

     void work(uint worker_id) {
      // call original method, but may as well pass marking stack
      // (contents) to process to wherever you want, waiting for
      // simulator to finish etc.
       MarkSweep::follow_stack();
     }
   } cl;

   w->run_task(&cl);
}

Untested, but incidentally just today I wrote a hotspot gtest that very 
much looks like that. There are also ~70 example implementations of 
AbstractGangTask in the code, ranging from one-liners like that to more 
complicated ones for further reference.

I belive that manually setting up a pthread, implementing the logic to 
wait for work and synchronize again, tearing everything down, is a lot 
longer than that.

> 
> 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).

As mentioned, Hotspot uses the pthread library itself, so you can use it 
yourselves if you want. Please have a look at the platform dependent 
threading shim, e.g. os_linux.cpp for Linux and the os class to use them.

 From what I can see it does:# include <pthread.h>

# include <pthread.h>

and further down in that file using pthread_* methods.

Thanks,
   Thomas


More information about the hotspot-gc-dev mailing list