/** * {@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 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); }
/** * {@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); }