/** * {@inheritDoc} */ @Override public long getPrimitiveTypesSize(int referenceCount, int booleanCount, int intCount, int floatCount, int longCount, int doubleCount) { // note that the size of the booleans must be aligned to the int size // thus 1 boolean is in 4 bytes, but are also 2, 3 and 4 booleans in an object packed to int long booleanSize = 0; if (booleanCount > 0) { booleanSize = ((booleanCount * BOOLEAN_SIZE) + INT_SIZE) - ((booleanCount * BOOLEAN_SIZE) % INT_SIZE); } return booleanSize + (referenceCount * getReferenceSize()) + (intCount * INT_SIZE) + (floatCount * FLOAT_SIZE) + (longCount * LONG_SIZE) + (doubleCount * DOUBLE_SIZE); }
/** * Returns size of the CHM object used in the high scale lib NonBlockingHashMapLong. * * @param mapSize * Size of map. * @return Size in bytes. */ private long getSizeOfHighScaleLibCHM(int mapSize) { long size = this.getSizeOfObjectHeader(); size += this.getPrimitiveTypesSize(6, 0, 0, 0, 3, 0); size = alignTo8Bytes(size); // two counters in addition size += getSizeOfHighScaleLibCounter() << 1; // min 16, or next power of two int tablesSize = (mapSize <= MAP_INITIAL_CAPACITY) ? MAP_INITIAL_CAPACITY : 1 << (32 - Integer.numberOfLeadingZeros(mapSize - 1)); // long table[] size += this.getSizeOfPrimitiveArray(tablesSize, LONG_SIZE); // object table[] size += this.getSizeOfPrimitiveArray(tablesSize, getReferenceSize()); return size; }