If you are a curious coder like us over here at RebelLabs, then you might have asked yourself about how memory is laid out in Java objects and classes.

Have you ever wondered, for example:

  • How much space does a class take up in memory? 
  • How much space do my objects consume in machine memory? 
  • What’s the deal with the alignment of object properties in memory? 
  • And why did Sun add the "backdoor" Unsafe class to the JVM, which lets developers directly operate memory and threads, when it is so voliate, unstable and certainly not recommended for use in production?  

For your reading pleasure, we offer you: Dangerous Code: How to be Unsafe with Java Classes & Objects in Memory

Many developers out there would like change the data or even the code within the memory, but in order to do this you need to know more about the instrumentation of classes and how they are laid out. From this you can get some specific fields from memory, or hack these fields within memory on the fly. Check out the full article to grab some interesting info on “Off-Heap Memory” and “High Performance Serialization” implementations, which are a couple of good samples based on the object memory structure.

The full article covers all this and more, complete with code and bytecode images for you uber geeks out there. Enjoy! http://zeroturnaround.com/rebellabs/dangerous-code-how-to-be-unsafe-with-java-classes-objects-in-memory/