问题
Background: V8 announced a feature called pointer compression (What's happening in V8? - Benedikt Meurer), which is intended to reduce the memory overhead of pointers for 64-bit processes. Java JVM's had a feature called CompressedOops since 2010 (since 6u23). At a first glance, it looks similar but then I realized it is not quite the same.
Question: What are the main differences between the pointer compression techniques (V8 vs JVM)?
The V8 implementation seems to be still not finalized, but I found at least some references:
JVM implementation:
- Trick behind JVM's compressed Oops
V8 implementation
- Design document
- Discussion about memory savings vs performance
回答1:
I think the links you provided already contain the answer? In short:
JVM's "compressed Oops" save 3 bits via shifting and thereby make it possible to address 2³ * 4 GB using 32-bit pointers at 8-byte granularity. (At least that's what your link says; I know nothing about the JVM so I cannot confirm or deny that this is accurate information.)
V8's "compressed pointers" pick a base address somewhere in the 64 (well, 48 really) bit address space and then store all heap pointers as 32-bit offsets from that base address, so the maximum heap size that can be addressed in this mode is 4GB.
I would guess that the JVM also needs to employ some variant of a base address, otherwise the shifted pointers would be limited to a very small and fixed subset of the full address space. V8's approach leaves the bits around that the JVM shifts away, which is nice for V8's purposes because it uses those bits to store other information (its pointers are tagged, and the tags are in those bits).
来源:https://stackoverflow.com/questions/59276104/how-does-the-compressed-pointer-implementation-in-v8-differ-from-jvms-compresse