public static int sizeof(Object o) {
    int size;

    if (o instanceof byte[]) {
      size = BYTE_ARRAY_OVERHEAD + ((byte[]) o).length;
    } else if (o instanceof String) {
      size = STRING_OVERHEAD + ((String) o).length() * 2;
    } else {
      return 0;
    }

    return roundUpSize(size);
  }
An efficient sizer for some commonly used classes.

This will return 0 if it does not know how to size the object
geode-core/src/main/java/org/apache/geode/internal/size/WellKnownClassSizer.java