You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@flink.apache.org by "hd zhou (Jira)" <ji...@apache.org> on 2022/03/17 10:53:00 UTC

[jira] [Created] (FLINK-26705) use threadlocal to decrease ObjectSizeCalculator memory use

hd zhou created FLINK-26705:
-------------------------------

             Summary: use threadlocal to decrease ObjectSizeCalculator memory use
                 Key: FLINK-26705
                 URL: https://issues.apache.org/jira/browse/FLINK-26705
             Project: Flink
          Issue Type: Improvement
            Reporter: hd zhou


in class ObjectSizeCalculator

everytime call static function getObjectSize will new ObjectSizeCalculator, cost much memory, Gc busy. use threadlocal will decrease memory use

 
{code:java}

/**
 * Given an object, returns the total allocated size, in bytes, of the object and all other objects reachable from it.
 * Attempts to to detect the current JVM memory layout, but may fail with {@link UnsupportedOperationException};
 *
 * @param obj the object; can be null. Passing in a {@link java.lang.Class} object doesn't do anything special, it
 *        measures the size of all objects reachable through it (which will include its class loader, and by
 *        extension, all other Class objects loaded by the same loader, and all the parent class loaders). It doesn't
 *        provide the size of the static fields in the JVM class that the Class object represents.
 * @return the total allocated size of the object and all other objects it retains.
 * @throws UnsupportedOperationException if the current vm memory layout cannot be detected.
 */
public static long getObjectSize(Object obj) throws UnsupportedOperationException {
  return obj == null ? 0 : new ObjectSizeCalculator(CurrentLayout.SPEC).calculateObjectSize(obj);
} {code}



--
This message was sent by Atlassian Jira
(v8.20.1#820001)