/*
Returns the JVM-specific size of a primitive type.
545219
private static int sizeofPrimitiveType(final Class type) {
        if (type == int.class) {
            return INT_FIELD_SIZE;
        } else if (type == long.class) {
            return LONG_FIELD_SIZE;
        } else if (type == short.class) {
            return SHORT_FIELD_SIZE;
        } else if (type == byte.class) {
            return BYTE_FIELD_SIZE;
        } else if (type == boolean.class) {
            return BOOLEAN_FIELD_SIZE;
        } else if (type == char.class) {
            return CHAR_FIELD_SIZE;
        } else if (type == double.class) {
            return DOUBLE_FIELD_SIZE;
        } else if (type == float.class) {
            return FLOAT_FIELD_SIZE;
        } else {
            throw new IllegalArgumentException("not primitive: " + type);
        }
    }
126408
public static int maxSize(Type type) {
		return type.isFixedSize() ? type.maxSize() : ByteHelper.INT_SIZE + type.maxSize();
	}
860502
public static long sizeOnHeapOf(ByteBuffer buffer)
    {
        if (buffer.isDirect())
            return BUFFER_EMPTY_SIZE;
        // if we're only referencing a sub-portion of the ByteBuffer, don't count the array overhead (assume it's slab
        // allocated, so amortized over all the allocations the overhead is negligible and better to undercount than over)
        if (buffer.capacity() > buffer.remaining())
            return buffer.remaining();
        return BUFFER_EMPTY_SIZE + sizeOfArray(buffer.capacity(), 1);
    }
1253161
@Deprecated public static int size (Object[] list)
    {
        if (list == null) {
            return 0;
        }
        int llength = list.length;
        for (int ii = 0; ii < llength; ii++) {
            if (list[ii] == null) {
                return ii;
            }
        }
        return llength;
    }
190088
@Override
	public int size() {

		if (allElementsInCache) {
			return orderedCache.size();
		} else {
			int count = 0;
			try (final RocksBytesIterator iterator = orderedBytesIterator()) {
				while (iterator.hasNext()) {
					iterator.next();
					++count;
				}
			}
			return count;
		}
	}
1024159
public int getSizeOfSurroundingTryBlock(String vmNameOfExceptionClass, int pc) {
        if (code == null) {
            throw new IllegalStateException("Not visiting Code");
        }
        return Util.getSizeOfSurroundingTryBlock(constantPool, code, vmNameOfExceptionClass, pc);
    }
138396
@Override
    public int size() {
	final Segment<K, V>[] segments = this.segments;
	long sum = 0;
	long check = 0;
	int[] mc = new int[segments.length];
	// Try a few times to get accurate count. On failure due to
	// continuous async changes in table, resort to locking.
	for (int k = 0; k < RETRIES_BEFORE_LOCK; ++k) {
	    check = 0;
	    sum = 0;
	    int mcsum = 0;
	    for (int i = 0; i < segments.length; ++i) {
		sum += segments[i].count;
		mcsum += mc[i] = segments[i].modCount;
	    }
	    if (mcsum != 0) {
		for (int i = 0; i < segments.length; ++i) {
		    check += segments[i].count;
		    if (mc[i] != segments[i].modCount) {
			check = -1; // force retry
			break;
		    }
		}
	    }
	    if (check == sum) break;
	}
	if (check != sum) { // Resort to locking all segments
	    sum = 0;
	    for (int i = 0; i < segments.length; ++i)
		segments[i].lock();
	    for (int i = 0; i < segments.length; ++i)
		sum += segments[i].count;
	    for (int i = 0; i < segments.length; ++i)
		segments[i].unlock();
	}
	if (sum > Integer.MAX_VALUE) return Integer.MAX_VALUE;
	return (int) sum;
    }
1322050
def get_memory_size(self):
        """"""
        n = sys.getsizeof(self)
        n += sys.getsizeof(self.padding)
        n += total_size(self.start_addr)
        n += total_size(self._buf)
        n += sys.getsizeof(self._offset)
        return n
281987
public static int readSizeT(Pointer ptr) {
    // TODO(scottb): make not public.
    if (SIZE_T_CLASS == SizeT4.class) {
      int result;
      result = ptr.getInt(0);
      assert result >= 0;
      return result;
    } else {
      long result = ptr.getLong(0);
      assert result >= 0;
      assert result < Integer.MAX_VALUE;
      return (int) result;
    }
  }
484895
private static @Nullable Pair<Integer, Integer> getVP8LDimension(final InputStream is)
      throws IOException {
    // Skip 4 bytes
    getInt(is);
    //We have a check here
    final byte check = getByte(is);
    if (check != 0x2F) {
      return null;
    }
    int data1 = ((byte) is.read()) & 0xFF;
    int data2 = ((byte) is.read()) & 0xFF;
    int data3 = ((byte) is.read()) & 0xFF;
    int data4 = ((byte) is.read()) & 0xFF;
    // In this case the bits for size are 14!!! The sizes are -1!!!
    final int width = ((data2 & 0x3F) << 8 | data1) + 1;
    final int height = ((data4 & 0x0F) << 10 | data3 << 2 | (data2 & 0xC0) >> 6) + 1;
    return new Pair<>(width, height);
  }
1129976
public int getSize() {
        int ret = 0;
        MethodState state = firstPointer;
        while (state != null) {
            ret++;
            state = state.getNext();
        }
        return ret;
    }
744926
function sizeOfType(t) {
	switch (t) {
		case NUMTYPE.UINT8:
		case NUMTYPE.INT8:
			return 1;
		case NUMTYPE.UINT16:
		case NUMTYPE.INT16:
			return 2;
		case NUMTYPE.UINT32:
		case NUMTYPE.INT32:
		case NUMTYPE.FLOAT32:
			return 4;
		case NUMTYPE.FLOAT64:
			return 8;
	}
	return 255;
}
970171
public static long sizeof(final Object obj) {
        if (null == obj || isSharedFlyweight(obj)) {
            return 0;
        }

        final IdentityHashMap visited = new IdentityHashMap(80000);

        try {
            return computeSizeof(obj, visited, CLASS_METADATA_CACHE);
        } catch (RuntimeException re) {
            // re.printStackTrace();//DEBUG
            return -1;
        } catch (NoClassDefFoundError ncdfe) {
            // BUG: throws "java.lang.NoClassDefFoundError: org.eclipse.core.resources.IWorkspaceRoot" when run in WSAD
            // 5
            // see
            // http://www.javaworld.com/javaforums/showflat.php?Cat=&Board=958763&Number=15235&page=0&view=collapsed&sb=5&o=
            // System.err.println(ncdfe);//DEBUG
            return -1;
        }
    }
177285
public static int sizeOf(Class<?> clz) throws IllegalArgumentException {
    switch (clz.getName()) {
    case "int":
      return Integer.BYTES;
    case "short":
      return Short.BYTES;
    case "long":
      return Long.BYTES;
    case "double":
      return Double.BYTES;
    case "float":
      return Float.BYTES;
    case "boolean":
      return 1;
    case "char":
      return Character.BYTES;
    case "byte":
      return 1;
    default:
      throw new IllegalArgumentException("Not a primitive type.");
    }
  }
94932
public static int computeSize(int order, Object o, FieldType type, boolean list, boolean debug, File path) {
        int size = 0;
        if (o == null) {
            return size;
        }

        if (type == FieldType.OBJECT) {
            Class cls = o.getClass();
            Codec target = ProtobufProxy.create(cls);
            try {
                size = target.size(o);
                size = size + CodedOutputStream.computeRawVarint32Size(size);
                return size + CodedOutputStream.computeTagSize(order);
            } catch (IOException e) {
                throw new RuntimeException(e.getMessage(), e);
            }
        }

        if (type == FieldType.STRING) {
            size = CodedOutputStream.computeStringSizeNoTag(String.valueOf(o));
        } else if (type == FieldType.BOOL) {
            size = CodedOutputStream.computeBoolSizeNoTag(Boolean.valueOf(String.valueOf(o)));
        } else if (type == FieldType.BYTES) {
            byte[] bb = (byte[]) o;
            size = CodedOutputStream.computeBytesSizeNoTag(ByteString.copyFrom(bb));
        } else if (type == FieldType.DOUBLE) {
            size = CodedOutputStream.computeDoubleSizeNoTag(Double.valueOf(o.toString()));
        } else if (type == FieldType.FIXED32 || type == FieldType.INT32 || type == FieldType.SFIXED32
                || type == FieldType.SINT32 || type == FieldType.UINT32) {
            size = CodedOutputStream.computeInt32SizeNoTag(Integer.valueOf(o.toString()));
        } else if (type == FieldType.FIXED64 || type == FieldType.INT64 || type == FieldType.SFIXED64
                || type == FieldType.SINT64 || type == FieldType.UINT64) {
            size = CodedOutputStream.computeInt64SizeNoTag(Long.valueOf(o.toString()));
        } else if (type == FieldType.FLOAT) {
            size = CodedOutputStream.computeFloatSizeNoTag(Float.valueOf(o.toString()));
        } else if (type == FieldType.ENUM) {
            if (o instanceof EnumReadable) {
                size = CodedOutputStream.computeInt32SizeNoTag(((EnumReadable) o).value());
            } else if (o instanceof Enum) {
                size = CodedOutputStream.computeInt32SizeNoTag(((Enum) o).ordinal());
            }
        }

        return size;
    }
190281
public static int getArraySize(final Object object, final Class<?> componentType) {

        ArgUtils.notNull(componentType, "componentType");

        if(object == null) {
            return 0;
        }

        if(!object.getClass().isArray()) {
            throw new IllegalArgumentException(String.format("args0 is not arrays : %s.", object.getClass().getName()));
        }

        if(!componentType.isPrimitive()) {
            return ((Object[])object).length;
        }

        if(componentType.equals(boolean.class)) {
            return ((boolean[]) object).length;

        } else if(componentType.equals(char.class)) {
            return ((char[]) object).length;

        } else if(componentType.equals(byte.class)) {
            return ((byte[]) object).length;

        } else if(componentType.equals(short.class)) {
            return ((short[]) object).length;

        } else if(componentType.equals(int.class)) {
            return ((int[]) object).length;

        } else if(componentType.equals(long.class)) {
            return ((long[]) object).length;

        } else if(componentType.equals(float.class)) {
            return ((byte[]) object).length;

        } else if(componentType.equals(double.class)) {
            return ((byte[]) object).length;

        }

        throw new IllegalArgumentException(String.format("not support primitive type : %s.", componentType.getName()));
    }
432958
public static int calculateFixLengthPartSize(InternalType type) {
		if (type.equals(InternalTypes.BOOLEAN)) {
			return 1;
		} else if (type.equals(InternalTypes.BYTE)) {
			return 1;
		} else if (type.equals(InternalTypes.SHORT)) {
			return 2;
		} else if (type.equals(InternalTypes.INT)) {
			return 4;
		} else if (type.equals(InternalTypes.FLOAT)) {
			return 4;
		} else if (type.equals(InternalTypes.CHAR)) {
			return 2;
		} else if (type.equals(InternalTypes.DATE)) {
			return 4;
		} else if (type.equals(InternalTypes.TIME)) {
			return 4;
		} else {
			// long, double is 8 bytes.
			// It store the length and offset of variable-length part when type is string, map, etc.
			return 8;
		}
	}