On 19/01/2026 8:16 pm, Eirik Bjørsnøs wrote:
David,

On Sun, Jan 18, 2026 at 11:04 PM David Holmes <[email protected] <mailto:[email protected]>> wrote:

    You would lose potentially important information when reporting
    monitors
    owned by a thread.


I get that the class name may be useful for diagnostic purposes.

However, the new Object() idiom has several thousand occurrences across the JDK, while new Lock() revealed only these two (plus a few in tests).

These Lock classes seem like an easy win in the effort to trim the list of JDK class loading during startup/shutdown.

Do you feel that the diagnostic value added by using named classes for these two instances outweighs the benefit of trimming class loading during startup?

No I suppose not. Though I'm not sure trimming the class will make any observable/practical difference in the normal case.
    Also I think Valhalla is trying to dissuade/move-away-from using
    "new Object()".


Hmm.. The alternative solution cannot be to introduce custom Lock classes everywhere, right?

I couldn't recall the exact proposal, but no. From https://github.com/openjdk/valhalla-docs/blob/main/site/design-notes/state-of-valhalla/02-object-model.md

"The root class Object poses an unusual problem, in that every class must extend it directly or indirectly, but it itself is (currently) an identity class, and it is common to use new Object() as a way to obtain a new object identity for purposes of locking. If Object were to implement IdentityObject, then primitive classes could not extend Object (and therefore could not interoperate with dynamically typed libraries such as reflection). We address this problem by treating Object like we do interfaces and certain abstract classes -- they can be extended by both identity and primitive classes -- but redefine the idiom new Object() to evaluate to a fresh instance of an anonymous identity subclass of Object."

So effectively this is like declaring a single global class that all "new Object()'s" would be instances of.

So using new Object() will not be a problem.

Cheers,
David
-----


Thanks,
Eirik.

Reply via email to