Not sure if this at all is what people, hmm Cas and others, have been thinking about. But I had some spare time this week and sat down trying to do a solution to the problem of mapping java object fields to memory. I found a "solution" consisting of part DirectByteBuffers or sun.misc.Unsafe hacking and javassisst bytecode manipulation library. This is just a first attempt and I'm releasing it now with the hope of getting enough input to settle if its worth continue working on!
The files can be found here
http://www.lysator.liu.se/~dahlberg/storedobjects.zip beware of lousy programming

and very sparse documentation (even though javadoc is included, it's quality is actually worse than sun's java.nio docs - unbelivable!

Best way to understand what I'm trying to achieve is probably to sit down and play around with the code. To wet your appetite here is a sample:
private static List<? extends Point> unsafeNoRefsStoredPoints =
StoredObjectFactory.createStoredObjectList("se.liu.lysator.dahlberg.storedobject.example.UnsafePoint",
SIZE, new NoRefsUnsafeStoragePolicy<UnsafePoint>());
private static List<? extends Point> bufferNoRefsStoredPoints =
StoredObjectFactory.createStoredObjectList("se.liu.lysator.dahlberg.storedobject.example.BufferPoint",
SIZE, new NoRefsBufferStoragePolicy<BufferPoint>());
// ...
private static void checkPerformance(List<? extends Point> points, String name) {
int total = 0;
for (int nr = 0; nr < points.size(); nr++) {
Point point = points.get(nr);
// int-field:
int y = point.getIntField();
point.setIntField(nr);
int squareOfY = point.squareOfIntField();
y = point.getIntField();
total += y + squareOfY;
// ...
public class BufferPoint extends BufferObject implements Point {
private int y;
//...
public int squareOfIntField() {
return y*y;
}
// ....
It's probably easier to understand if you load the files available in the zip above in your favourite editor/IDE and start hacking. If you're only interested in some results you can run the jar-file provided with java -jar storedobjects.jar (provided you have extracted javassisst.jar in the same directory).
Running with the above shown StoragePolicies yields Unsafe approx. 25-50% slower than a regular populated arraylist, whereas DirectByteBufffers suffer a bit more and is roughly 3-4 times slower than the arraylist. NoRefs...StoragePolicy implies that all data is accessed through a single ...Point object (only the Point's internal base offset/address is changed depending on which elementet that is accessed - should work fine if you're only interested in looping through the elements and doing some simple calculations etc).
P.S. Don't bother with trying to understand why the data classes are called ...Point - they used to be just that but evolved
