RFR: JDK-8304723: Statically allocate global mutexes

Thomas Stuefe stuefe at openjdk.org
Thu Mar 23 06:37:41 UTC 2023


On Wed, 22 Mar 2023 22:32:59 GMT, David Holmes <dholmes at openjdk.org> wrote:

> > On posix, switch from pthread_cond_init to static initialization if possible.
> 
> Some platforms have the "wrong" default which is why we don't attempt to use the pthread static initializers. But in general statically initializing our Mutex/Monitor would be very fragile IMO - as discussed in the past.

Oh, right, there was that. Wonder if that still holds true today. Wasn't that Solaris?

> 
> Doing the allocation statically is a different matter. But what does this gain? Is the startup improvement noticeable?
> 

I'd be very happy if startup would be fast enough for ~150 fewer mallocs to matter. 

A blank hello world with no args to speak of calls into malloc >10k times. ~150(?) mallocs less are a step in the right direction.

My major gripe with this change is that I don't like the SimpleLock solution and suspect this could be simplified. I don't like the changes to the call sites either. 

A simple change to keep the mutex name in-line instead of mallocing it separately would already half the number of mallocs, and that would be a really trivial patch. One step further, one could allocate the mutexes in an array, or inside a single holder object. There are probably more ways to do this.

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

PR Comment: https://git.openjdk.org/jdk/pull/13143#issuecomment-1480668404


More information about the hotspot-dev mailing list