rents
rents

Reputation: 848

How is a compressed ooP implemented in JVM?

A quick google search results in surprisingly nothing.

My question is as follows:

For 32-bit architecture - 2^32 bytes would be the memory space = 4GB So for a Java heap of 4 GB, we need a pointer of size 32 bits = 4 bytes.

However, by the concept of compressed oop, the JVM can still use the 4 byte pointer upto a heap size of 32 GB.

Thinking about it, 32 GB = 4 GB * 2^3. It means we actually need 3 more bits but somehow these bits are getting encoded/decoded by JVM during the storage/access.

I found these pages inaccessible : http://wikis.sun.com/display/HotSpotInternals/CompressedOops https://wikis.oracle.com/display/HotSpotInternals/CompressedOops

Can someone explain me the wizardry that is going on behind the scenes?

To Mods: I found an existing question, but that points to https://wikis.oracle.com/display/HotSpotInternals/CompressedOops. This wiki doesn't exist anymore, can you please allow this question so long that someone points me to an alternate in-depth link. Please.

Edit:

@Markus Mikkolainen response is the simplest and easiest explanation I have found : they are offsets and they are used to index 8 byte blocks and not one byte blocks since objects are 8 byte aligned.

Upvotes: 0

Views: 822

Answers (1)

Markus Mikkolainen
Markus Mikkolainen

Reputation: 3497

http://docs.oracle.com/javase/7/docs/technotes/guides/vm/performance-enhancements-7.html#compressedOop

does this answer your question, they are offsets and they are used to index 8 byte blocks and not one byte blocks since objects are 8 byte aligned.

Upvotes: 2

Related Questions