This is an automated email from the ASF dual-hosted git repository.

sijie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new 90a7448   better way to estimate object size for sql (#2528)
90a7448 is described below

commit 90a7448041aca5d5189b6a0b641453a50369faad
Author: Boyang Jerry Peng <jerry.boyang.p...@gmail.com>
AuthorDate: Thu Sep 6 01:00:12 2018 -0700

     better way to estimate object size for sql (#2528)
    
    Since we mocked ClassLayout.parseClass() because we need to exclude 
org.openjdk.jol for license issues. Lets come up with another way to estimate 
class size
---
 pulsar-sql/presto-distribution/LICENSE             |  3 +++
 pulsar-sql/presto-distribution/pom.xml             | 14 ++++++++++++
 .../java/org/openjdk/jol/info/ClassLayout.java     | 26 ++++++++++++++++++----
 3 files changed, 39 insertions(+), 4 deletions(-)

diff --git a/pulsar-sql/presto-distribution/LICENSE 
b/pulsar-sql/presto-distribution/LICENSE
index 51d4923..d7f2fc8 100644
--- a/pulsar-sql/presto-distribution/LICENSE
+++ b/pulsar-sql/presto-distribution/LICENSE
@@ -359,6 +359,7 @@ The Apache Software License, Version 2.0
     - jsr305-3.0.2.jar
   * Objenesis
     - objenesis-2.1.jar
+    - objenesis-2.6.jar
   * Okio
     - okio-1.13.0.jar
   * Presto
@@ -379,6 +380,8 @@ The Apache Software License, Version 2.0
     - snappy-java-1.1.1.3.jar
   * Bean Validation API
     - validation-api-1.1.0.Final.jar
+  * Objectsize
+    - objectsize-0.0.12.jar
 
 Protocol Buffers License
  * Protocol Buffers
diff --git a/pulsar-sql/presto-distribution/pom.xml 
b/pulsar-sql/presto-distribution/pom.xml
index ab55b3d..a355777 100644
--- a/pulsar-sql/presto-distribution/pom.xml
+++ b/pulsar-sql/presto-distribution/pom.xml
@@ -30,6 +30,8 @@
     <properties>
         <presto.version>0.206</presto.version>
         <airlift.version>0.170</airlift.version>
+        <objenesis.version>2.6</objenesis.version>
+        <objectsize.version>0.0.12</objectsize.version>
         <!-- Launcher properties -->
         <main-class>com.facebook.presto.server.PrestoServer</main-class>
         <process-name>${project.artifactId}</process-name>
@@ -80,6 +82,18 @@
             <scope>provided</scope>
         </dependency>
 
+        <dependency>
+            <groupId>org.objenesis</groupId>
+            <artifactId>objenesis</artifactId>
+            <version>${objenesis.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.twitter.common</groupId>
+            <artifactId>objectsize</artifactId>
+            <version>${objectsize.version}</version>
+        </dependency>
+
     </dependencies>
 
     <build>
diff --git 
a/pulsar-sql/presto-distribution/src/main/java/org/openjdk/jol/info/ClassLayout.java
 
b/pulsar-sql/presto-distribution/src/main/java/org/openjdk/jol/info/ClassLayout.java
index 16feb29..2a8bfa3 100644
--- 
a/pulsar-sql/presto-distribution/src/main/java/org/openjdk/jol/info/ClassLayout.java
+++ 
b/pulsar-sql/presto-distribution/src/main/java/org/openjdk/jol/info/ClassLayout.java
@@ -18,18 +18,36 @@
  */
 package org.openjdk.jol.info;
 
+import com.twitter.common.objectsize.ObjectSizeCalculator;
+import io.airlift.log.Logger;
+import org.objenesis.ObjenesisStd;
+
 /**
  * Mock class avoid a dependency on OpenJDK JOL,
  * which is incompatible with the Apache License.
  */
 public class ClassLayout {
 
-    public static ClassLayout parseClass(Class<?> ignored) {
-        return new ClassLayout();
+    private static final Logger log = Logger.get(ClassLayout.class);
+
+    private int size;
+    private static final int DEFAULT_SIZE = 64;
+
+    private ClassLayout(int size) {
+        this.size = size;
+    }
+
+    public static ClassLayout parseClass(Class<?> clazz) {
+        long size = DEFAULT_SIZE;
+        try {
+            size = ObjectSizeCalculator.getObjectSize(new 
ObjenesisStd().newInstance(clazz));
+        } catch (Throwable th) {
+            log.info("Error estimating size of class %s",clazz, th);
+        }
+        return new ClassLayout(Math.toIntExact(size));
     }
 
-    // TODO find a better estimate of class size
     public int instanceSize() {
-        return 64; // random, means nothing
+        return size;
     }
 }
\ No newline at end of file

Reply via email to