/** * {@inheritDoc} */ @Override public long getSizeOf(Timestamp timestamp) { if (null == timestamp) { return 0; } // 72 is the number of bytes for instance of GregorianCalendar // inside Timestamp. However, I can not check if this is null or not. // In our objects I never found it to be instantiated, so I don't include it. long size = this.getSizeOfObjectHeader(); // java.sql.Timestamp size += this.getPrimitiveTypesSize(0, 0, 1, 0, 0, 0); // java.util.Date size += this.getPrimitiveTypesSize(1, 0, 0, 0, 1, 0); return alignTo8Bytes(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); }
/** * @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 getSizeOfCustomWeakReference() { long size = this.getSizeOfObjectHeader(); size += this.getPrimitiveTypesSize(4, 0, 0, 0, 1, 0); return alignTo8Bytes(size); }
/** * Returns the size of a HashMap entry. Not that the key and value objects are not in this size. * If HashSet is used the HashMapEntry value object will be a simple Object, thus this size has * to be added to the HashSet. * * @return Returns the size of a HashMap entry. Not that the key and value objects are not in * this size. If HashSet is used the HashMapEntry value object will be a simple Object, * thus this size has to be added to the HashSet. */ private long getSizeOfHashMapEntry() { long size = this.getSizeOfObjectHeader(); size += this.getPrimitiveTypesSize(3, 0, 1, 0, 0, 0); return alignTo8Bytes(size); }
/** * Calculates the size of the array with out objects in the array - <b> Can only be used on * non-primitive arrays </b>. * * @param arraySize * Size of array (length). * @return Size in bytes. */ @Override public long getSizeOfArray(int arraySize) { long size = this.getSizeOfObjectHeader(); size += this.getPrimitiveTypesSize(arraySize, 0, 1, 0, 0, 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); }
/** * 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; }
/** * 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; }
/** * {@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 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); }
/** * {@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; }
/** * 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 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); }