Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the value returned by arrayIndexScale refer to?

Tags:

java

I would like to know what is the usage of sun.misc.unsafe.arrayIndexScale, in the javadoc it is said that:

Report the scale factor for addressing elements in the storage allocation of a given array class. However, arrays of "narrow" types will generally not work properly with accessors like getByte(java.lang.Object,int), so the scale factor for such classes is reported as zero.

This method returns an int, but I am not sure what the value means.

like image 376
Bionix1441 Avatar asked Apr 27 '15 14:04

Bionix1441


1 Answers

The method gives you Java object memory layout information.

This is used to determine the amount of memory that the given array is occupying. Scale Factor is a term that represents how much a given quantity, in this case memory, is being multiplied by to represent the total. You should not use the method that you are trying to use; it's UNSAFE.

However, there are safer versions that you can use: staticFieldBase or staticFieldOffset.

like image 72
Evan Bechtol Avatar answered Nov 15 '22 00:11

Evan Bechtol