On Thu, 10 Apr 2008 22:36:54 -0700, "Chris Thomasson"
said :
>If thread A allocates 256 bytes, and thread B races in and concurrently
>attempts to allocate 128 bytes... Which thread is going to win?
If all threads share a common heap, new code would have to be
synchronised. If you have that synchronisation, you could use a
single global counter to use to generate a hashCode. Keep in mind we
are talking assembler here. This is the very guts of the JVM. You can
take advantage of an assembler atomic memory increment instruction for
very low overhead synchronisation.
You could invent a JVM where each thread has its own mini-heap for
freshly created objects. Then it would not need to synchronise to
allocate an object. Long lived objects could be moved to a common
synchronised heap.
JVMs have extreme latitude to do things any way they please so long
as the virtual machine behaves in a consistent way.
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com