tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hyun...@apache.org
Subject tajo git commit: TAJO-1523 ClassSize should consider compressed oops
Date Thu, 07 May 2015 22:30:23 GMT
Repository: tajo
Updated Branches:
  refs/heads/master fab63900c -> 2b4c1610d


TAJO-1523 ClassSize should consider compressed oops

Signed-off-by: Hyunsik Choi <hyunsik@apache.org>

Closes #508


Project: http://git-wip-us.apache.org/repos/asf/tajo/repo
Commit: http://git-wip-us.apache.org/repos/asf/tajo/commit/2b4c1610
Tree: http://git-wip-us.apache.org/repos/asf/tajo/tree/2b4c1610
Diff: http://git-wip-us.apache.org/repos/asf/tajo/diff/2b4c1610

Branch: refs/heads/master
Commit: 2b4c1610d2e60dfc9c50fbfdac22e12870c17163
Parents: fab6390
Author: navis.ryu <navis@apache.org>
Authored: Sat Apr 4 16:56:05 2015 +0900
Committer: Hyunsik Choi <hyunsik@apache.org>
Committed: Thu May 7 15:30:08 2015 -0700

----------------------------------------------------------------------
 .../java/org/apache/tajo/util/ClassSize.java    | 18 ++++++++++---
 .../java/org/apache/tajo/util/UnsafeUtil.java   | 28 ++++++++++++++++++++
 2 files changed, 42 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tajo/blob/2b4c1610/tajo-common/src/main/java/org/apache/tajo/util/ClassSize.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/util/ClassSize.java b/tajo-common/src/main/java/org/apache/tajo/util/ClassSize.java
index 708eae9..ab2fdf5 100644
--- a/tajo-common/src/main/java/org/apache/tajo/util/ClassSize.java
+++ b/tajo-common/src/main/java/org/apache/tajo/util/ClassSize.java
@@ -22,6 +22,7 @@ package org.apache.tajo.util;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import sun.misc.Unsafe;
 
 import java.lang.reflect.Field;
 import java.lang.reflect.Modifier;
@@ -141,10 +142,19 @@ public class ClassSize {
    */
   static {
     //Default value is set to 8, covering the case when arcModel is unknown
-    if (is32BitJVM()) {
-      REFERENCE = 4;
-    } else {
-      REFERENCE = 8;
+    switch (UnsafeUtil.ADDRESS_MODE) {
+      case MEM_32BIT:
+        REFERENCE = 4;
+        break;
+      case MEM_64BIT:
+        REFERENCE = 8;
+        break;
+      case MEM_64BIT_COMPRESSED_OOPS:
+        REFERENCE = 4;
+        break;
+      default:
+        REFERENCE = is32BitJVM() ? 4 : 8;
+        break;
     }
 
     OBJECT = 2 * REFERENCE;

http://git-wip-us.apache.org/repos/asf/tajo/blob/2b4c1610/tajo-common/src/main/java/org/apache/tajo/util/UnsafeUtil.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/util/UnsafeUtil.java b/tajo-common/src/main/java/org/apache/tajo/util/UnsafeUtil.java
index 9d6b9b3..ff6072e 100644
--- a/tajo-common/src/main/java/org/apache/tajo/util/UnsafeUtil.java
+++ b/tajo-common/src/main/java/org/apache/tajo/util/UnsafeUtil.java
@@ -28,6 +28,21 @@ import java.nio.ByteBuffer;
 public class UnsafeUtil {
   public static final Unsafe unsafe;
 
+  // copied from
+  // http://stackoverflow.com/questions/52353/in-java-what-is-the-best-way-to-determine-the-size-of-an-object
+  public static enum AddressMode {
+    /** Unknown address mode. Size calculations may be unreliable. */
+    UNKNOWN,
+    /** 32-bit address mode using 32-bit references. */
+    MEM_32BIT,
+    /** 64-bit address mode using 64-bit references. */
+    MEM_64BIT,
+    /** 64-bit address mode using 32-bit compressed references. */
+    MEM_64BIT_COMPRESSED_OOPS
+  }
+
+  public static final AddressMode ADDRESS_MODE;
+
   // offsets
   public static final int ARRAY_BOOLEAN_BASE_OFFSET;
   public static final int ARRAY_BYTE_BASE_OFFSET;
@@ -83,6 +98,19 @@ public class UnsafeUtil {
     ARRAY_FLOAT_INDEX_SCALE = unsafe.arrayIndexScale(float[].class);
     ARRAY_DOUBLE_INDEX_SCALE = unsafe.arrayIndexScale(double[].class);
     ARRAY_OBJECT_INDEX_SCALE = unsafe.arrayIndexScale(Object[].class);
+
+    int addressSize = unsafe.addressSize();
+    int referenceSize = unsafe.arrayIndexScale(Object[].class);
+
+    if (addressSize == 4) {
+      ADDRESS_MODE = AddressMode.MEM_32BIT;
+    } else if (addressSize == 8 && referenceSize == 8) {
+      ADDRESS_MODE = AddressMode.MEM_64BIT;
+    } else if (addressSize == 8 && referenceSize == 4) {
+      ADDRESS_MODE = AddressMode.MEM_64BIT_COMPRESSED_OOPS;
+    } else {
+      ADDRESS_MODE = AddressMode.UNKNOWN;
+    }
   }
 
   public static int alignedSize(int size) {


Mime
View raw message