RFR: 8087322: Implement a Semaphore utility class

Stefan Karlsson stefan.karlsson at oracle.com
Fri Jun 12 15:21:08 UTC 2015

Hi all,

Please review this patch to create a Semaphore utility class. I need 
this class to implementing faster GC thread synchronization [1].


Some of our platforms already implement a Semaphore class, but those 
classes are hidden inside os_<os>.cpp. I've moved the class declaration 
to semaphore.hpp, but the implementation is left in the os_<os>.hpp. I 
considered creating semaphore_<os>.cpp files, but I ended up having to 
restructure too much code and I wanted to focus on the feature in [1] 
instead. Should I create a RFE to move the semaphore implementations?

There seems to be another opportunity to cleanup the code. If we take 
os_linux.cpp, as an example, the code uses both the existing Semaphore 
class and the global ::sem_wait and ::sem_post functions. We might want 
to consider unifying that code.

Since HotSpot is built on platforms that I don't have access to and 
can't test, I've added the IMPLEMENTS_SEMAPHORE_CLASS define. So, that I 
can detect if the the current platform implements the Semaphore class, 
and choose what synchronization primitive to use by the GC.

The os_bsd.cpp file has support for "non-apple BSD", but I've only 
tested this patch with OS X.

This patch has been tested in JPRT and our nightly testing together with 
the patches in [1]. The patch also contains a few unit tests in 



More information about the hotspot-dev mailing list