/** * {@inheritDoc} */ @Override public long getSizeOfNonBlockingHashMapLong(int mapSize) { long size = this.getSizeOfObjectHeader(); size += this.getPrimitiveTypesSize(5, 1, 0, 0, 1, 0); size = alignTo8Bytes(size); // we have in addition Counter, no-key Object and CHM table in the NonBlockingHashMapLong // need to add them to the size count size += this.getSizeOfObjectObject(); size += this.getSizeOfHighScaleLibCounter(); size += this.getSizeOfHighScaleLibCHM(mapSize); return size; }
/** * {@inheritDoc} */ @Override public long getSizeOf(List<?> arrayList, int initialCapacity) { if (null == arrayList) { return 0; } int capacity = getArrayCapacity(arrayList.size(), initialCapacity); long size = alignTo8Bytes(this.getSizeOfObjectHeader() + this.getPrimitiveTypesSize(1, 0, 2, 0, 0, 0)); size += this.getSizeOfArray(capacity); return alignTo8Bytes(size); }
/** * {@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); }
/** * @return Size of concurrent hash map node in java 8. */ private long getSizeOfConcurrentHashMapNode() { long size = this.getSizeOfObjectHeader() + this.getPrimitiveTypesSize(3, 0, 1, 0, 0, 0); return alignTo8Bytes(size); }
/** * {@inheritDoc} */ @Override public long getSizeOfIntegerObject() { long size = this.getSizeOfObjectHeader() + INT_SIZE; return alignTo8Bytes(size); }
/** * Returns size of the Counter object used in the high scale lib NonBlockingHashMapLong. * * @return Size in bytes. */ private long getSizeOfHighScaleLibCounter() { long size = this.getSizeOfObjectHeader(); size += this.getPrimitiveTypesSize(1, 0, 0, 0, 0, 0); size = alignTo8Bytes(size); size += this.getSizeOfHighScaleLibCAT(); return size; }
/** * {@inheritDoc} */ @Override public long getSizeOfHashMap(int hashMapSize, int initialCapacity) { long size = this.getSizeOfObjectHeader(); size += this.getPrimitiveTypesSize(4, 0, 4, 1, 0, 0); int mapCapacity = this.getMapCapacityFromSize(hashMapSize, initialCapacity); // size of the map array for the entries // in java 8 hash map table is not initialized until first element is added if (mapCapacity > 0) { size += this.getSizeOfArray(mapCapacity); } // size of the entries size += hashMapSize * this.getSizeOfHashMapEntry(); // To each hash map I add 16 bytes because keySet, entrySet and values fields, that can each // hold 16 bytes // These fields are null until these sets are requested by user. // Thus I add for one size += getSizeOfHashMapKeyEntrySet(); return alignTo8Bytes(size); }
/** * {@inheritDoc} */ @Override public long getSizeOfConcurrentHashMap(int mapSize) { long size = this.getSizeOfObjectHeader(); size += this.getPrimitiveTypesSize(8, 0, 3, 0, 1, 0); // in Java 8 map table is not initialized when empty if (mapSize > 0) { int initialCapacity = MAP_INITIAL_CAPACITY; initialCapacity = tableSizeFor(initialCapacity + (initialCapacity >>> 1) + 1); int tableSize = getConcurrentMapCapacityFromSize(mapSize, initialCapacity); // array of nodes based on tableSize size += this.getSizeOfArray(tableSize); // and for each object in the map there is the reference to the HashEntry in Segment // that we // need to add // size += mapSize * alignTo8Bytes(this.getReferenceSize()); size += mapSize * this.getSizeOfConcurrentHashMapNode(); } return alignTo8Bytes(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; }
/** * {@inheritDoc} */ @Override public long getSizeOfHashSet(int hashSetSize, int initialCapacity) { long size = this.getSizeOfObjectHeader(); size += this.getPrimitiveTypesSize(1, 0, 0, 0, 0, 0); size += this.getSizeOfHashMap(hashSetSize, initialCapacity); // One object is used as the value in the map for all entries. This object is shared between // all HashSet instances, but we have to calculate it for each instance. if (hashSetSize > 0) { size += this.getSizeOfObjectObject(); } return alignTo8Bytes(size); }
/** * Returns size of the CAT object used in the high scale lib Counter. * * @return Size in bytes. */ private long getSizeOfHighScaleLibCAT() { long size = this.getSizeOfObjectHeader(); size += this.getPrimitiveTypesSize(2, 0, 0, 0, 4, 0); size = alignTo8Bytes(size); // always has an array of 4 longs attached size += this.getSizeOfPrimitiveArray(4, LONG_SIZE); return size; }
int ourTableSize = ((AbstractObjectSizes) objectSizes).getMapCapacityFromSize(size, 16); tableCorrect = tableSize == ourTableSize;
/** * {@inheritDoc} */ @Override public long getSizeOf(List<?> arrayList) { return this.getSizeOf(arrayList, ARRAY_LIST_INITIAL_CAPACITY); }
/** * {@inheritDoc} */ @Override public long getSizeOfHashMap(int hashMapSize) { return this.getSizeOfHashMap(hashMapSize, MAP_INITIAL_CAPACITY); }
/** * {@inheritDoc} */ @Override public long getSizeOf(Sizeable sizeable) { if (null == sizeable) { return 0; } long size = sizeable.getObjectSize(this, ALLIGN_CLASS_CALCULATION); return ALLIGN_CLASS_CALCULATION ? size : alignTo8Bytes(size); }
/** * {@inheritDoc} */ @Override public long getSizeOfCustomWeakReference() { long size = this.getSizeOfObjectHeader(); size += this.getPrimitiveTypesSize(4, 0, 0, 0, 1, 0); return alignTo8Bytes(size); }
/** * {@inheritDoc} */ @Override public long getSizeOf(String str) { if (null == str) { return 0; } long size = this.getSizeOfObjectHeader(); size += this.getPrimitiveTypesSize(1, 0, 2, 0, 0, 0); size += this.getSizeOfPrimitiveArray(str.length(), CHAR_SIZE); return alignTo8Bytes(size); }
/** * {@inheritDoc} */ @Override public long getSizeOfCharacterObject() { long size = this.getSizeOfObjectHeader() + CHAR_SIZE; return alignTo8Bytes(size); }
/** * {@inheritDoc} */ @Override public long getSizeOf(String... strings) { Set<Integer> identityHashCodeSet = new HashSet<>(); long size = 0L; for (String str : strings) { if (null == str) { continue; } if (identityHashCodeSet.add(System.identityHashCode(str))) { size += getSizeOf(str); } } return size; }
/** * Returns size of HashMap's inner Key or Entry set classes. * * @return Returns size of HashMap's inner Key or Entry set classes. */ @Override public long getSizeOfHashMapKeyEntrySet() { // since these are inner classes, one reference to enclosing class is needed long size = this.getSizeOfObjectHeader() + this.getPrimitiveTypesSize(1, 0, 0, 0, 0, 0); return alignTo8Bytes(size); }