▲ | PaulHoule 5 days ago | ||||||||||||||||
Today Java has pointer compression where you use a 32 bit reference but shift it a few places to the left to make a 64-bit address which saves space on pointers but wastes it on alignment | |||||||||||||||||
▲ | xxs 3 days ago | parent | next [-] | ||||||||||||||||
All allocated objects would have the three least significant bits as 0. Any java object cannot be 'too small' as they all have object headers (more if you need a fully blown synchronized/mutex). So with compressed pointers (up to 32GB Heaps) all objects are aligned but then again, each pointer is 4 bytes only (instead of 8). Overall it's a massive win. | |||||||||||||||||
| |||||||||||||||||
▲ | o11c 3 days ago | parent | prev | next [-] | ||||||||||||||||
It's not wasted on alignment, since that alignment is already required (unless you need a very large heap). Remember that Java's GC heap is only used to allocate Objects, not raw bytes. There are ways to allocate memory outside of the heap and if you're dealing with that much raw data you should probably be using them. | |||||||||||||||||
▲ | layer8 2 days ago | parent | prev [-] | ||||||||||||||||
Alignment is required anyway to prevent word tearing, for the atomicity guarantees. |