What is actually memory overhead in java?

I read what-is-the-memory-consumption-of-an-object-in-java and what-is-the-memory-overhead-of-an-object-in-java .

But still, I'm confused.

  • What is memory overhead? is it padding ?
  • What is a Compressed Pointer JVM ? is this reference ??
  • If a 32-bit JVM , will the overhead be less? Of course yes. But is it due to filling?
  • So is it always better to use the 32-bit JVM for memory efficiency or for performance?

Below is the image of this link (page number 26)

In this image, at startup, they were displayed as 16 byte JVM overhead, why is this?

enter image description here

+5
source share
1 answer

What is memory overhead?

When more memory is used than the fields you created.

is this an addition?

Some are indents that can appear anywhere in the object, with the exception of the header, which is always at the beginning. The header usually has a length of 8-12 bytes.

What is a Compressed Pointer JVM?

A way to use 32-bit pointers in a 64-bit JVM to save memory.

this is a link?

References can use this technique, but therefore can point to class information for an object.

If a 32-bit JVM is used, will the overhead be less?

Perhaps, although this is the same as using compressed pointers for references and classes.

But is it due to filling?

This is because 64-bit pointers use more space than a 32-bit pointer.

So is it better to use a 32-bit JVM for memory efficiency or performance?

No, the 32-bit processor model has 32-bit registers, where, since the 64-bit model has twice as many registers whose size is doubled (64-bit), much more can be stored in the fastest memory, registers. 64-bit computing tends to be faster, as well as with a 64-bit processing model.

In general, I would recommend that you always use a 64-bit JVM if you are not a) unable or b) to have a very small amount of memory.

In this image, at startup, they were displayed as 16 byte JVM overhead, why is this?

This is not entirely correct. This assumes that you have a reference to an uncompressed class, so the header has 12 bytes, however by default the objects are 8 bytes by default, which means there will be 4 bytes of padding at the end (which is 16 bytes, but that’s not all at first )

Frequently Asked Questions: Why is the 32-bit compressed OOP address more than 4 GB

The object must be set to 8 bytes by default. This makes memory management easier, but sometimes delays debugging. A side effect is that the address of each object will have 000 for the lower three bits (it must be a multiple of 8). These bits do not need to be stored. This allows compressed oops to address 8 * 4 GB or 32 GB.

When aligned by 16 bytes, the JVM can access 64 GB with a 32-bit link (however, the overhead is more expensive and may not be worth it)

IFAQ: why is it slower by about 28-32 GB

While the link can be multiplied by 8, the heap does not start at the beginning of memory. It usually starts at about 4 GB. This means that if you want to use 32 GB, you must add this offset, which has a small overhead.

Heap Sizes:

  • <4 GB - address of the zero address
  • 4 - 28 GB - multiply by 8 or << 3 note: x64 has instructions for supporting double[] and long[]
  • 28 - 32 GB - a few by 8 and add a register containing the offset. A bit slower, but usually this is not a problem.
+7
source

Source: https://habr.com/ru/post/1258068/


All Articles