I have an application which requires the allocation of multiple-millions of small objects. Through
testing and instrumentation, I've discovered that the time spent construction the objects is substantially longer than the time spent in algorithmic processing. So I've been experimenting using the
Java Unsafe API to create objects through direct memory manipulation. Although I recognize that Unsafe is, well, unsafe and may go away in Java 9, this is still an interesting investigation for me because of the unusual nature of my problem (which I described in an earlier post
Allocating large numbers of Java objects). If I could get this to work, it would mean that my code would have to take care of some of its own memory management, but that's a small price to pay to improve the run-time performance of my application.
The good news is that I am seeing a 20-fold improvement in the time to allocate objects. The bad news is that the objects seem to be unusable. Although I can set values for data primitives within the objects (ints, floats, etc.), when I try to store object references, the JVM crashes with a fatal EXCEPTION_ACCESS_VIOLATION.
Does anyone have suggestions on how to make this work or, failing that, why it doesn't work? I thought it might have something to do with memory barriers or the GC mark-and-sweep support, but haven't found an answer on the web.
Also, am running this under Java VM: Java HotSpot(TM) 64-Bit Server VM (23.25-b01 mixed mode windows-amd64 compressed oops)
A sample block of code follows.