You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by ha...@apache.org on 2016/05/21 01:15:23 UTC
hive git commit: HIVE-13699: Make JavaDataModel#get thread safe for
parallel compilation (Peter Slawski via Ashutosh Chauhan)
Repository: hive
Updated Branches:
refs/heads/master f68cbcbfb -> 2c3ebf8f2
HIVE-13699: Make JavaDataModel#get thread safe for parallel compilation (Peter Slawski via Ashutosh Chauhan)
Signed-off-by: Ashutosh Chauhan <ha...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/2c3ebf8f
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/2c3ebf8f
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/2c3ebf8f
Branch: refs/heads/master
Commit: 2c3ebf8f2259a46d102b598df3512f7226b6522a
Parents: f68cbcb
Author: Peter Slawski <pe...@amazon.com>
Authored: Tue Apr 5 14:21:55 2016 -0700
Committer: Ashutosh Chauhan <ha...@apache.org>
Committed: Fri May 20 18:04:14 2016 -0700
----------------------------------------------------------------------
.../hadoop/hive/ql/util/JavaDataModel.java | 34 +++++++----
.../hadoop/hive/ql/util/JavaDataModelTest.java | 59 ++++++++++++++++++++
2 files changed, 82 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hive/blob/2c3ebf8f/storage-api/src/java/org/apache/hadoop/hive/ql/util/JavaDataModel.java
----------------------------------------------------------------------
diff --git a/storage-api/src/java/org/apache/hadoop/hive/ql/util/JavaDataModel.java b/storage-api/src/java/org/apache/hadoop/hive/ql/util/JavaDataModel.java
index 151f30d..33b70c2 100644
--- a/storage-api/src/java/org/apache/hadoop/hive/ql/util/JavaDataModel.java
+++ b/storage-api/src/java/org/apache/hadoop/hive/ql/util/JavaDataModel.java
@@ -18,6 +18,11 @@
package org.apache.hadoop.hive.ql.util;
+import com.google.common.annotations.VisibleForTesting;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
/**
* Estimation of memory footprint of object
*/
@@ -229,6 +234,8 @@ public enum JavaDataModel {
return (value + align - 1) & ~(align - 1);
}
+ private static final Logger LOG = LoggerFactory.getLogger(JavaDataModel.class);
+
public static final int JAVA32_META = 12;
public static final int JAVA32_ARRAY_META = 16;
public static final int JAVA32_REF = 4;
@@ -246,22 +253,27 @@ public enum JavaDataModel {
public static final int PRIMITIVE_BYTE = 1; // byte
- private static JavaDataModel current;
+ private static final class LazyHolder {
+ private static final JavaDataModel MODEL_FOR_SYSTEM = getModelForSystem();
+ }
- public static JavaDataModel get() {
- if (current != null) {
- return current;
- }
+ @VisibleForTesting
+ static JavaDataModel getModelForSystem() {
+ String props = null;
try {
- String props = System.getProperty("sun.arch.data.model");
- if ("32".equals(props)) {
- return current = JAVA32;
- }
+ props = System.getProperty("sun.arch.data.model");
} catch (Exception e) {
- // ignore
+ LOG.warn("Failed to determine java data model, defaulting to 64", e);
+ }
+ if ("32".equals(props)) {
+ return JAVA32;
}
// TODO: separate model is needed for compressedOops, which can be guessed from memory size.
- return current = JAVA64;
+ return JAVA64;
+ }
+
+ public static JavaDataModel get() {
+ return LazyHolder.MODEL_FOR_SYSTEM;
}
public static int round(int size) {
http://git-wip-us.apache.org/repos/asf/hive/blob/2c3ebf8f/storage-api/src/test/org/apache/hadoop/hive/ql/util/JavaDataModelTest.java
----------------------------------------------------------------------
diff --git a/storage-api/src/test/org/apache/hadoop/hive/ql/util/JavaDataModelTest.java b/storage-api/src/test/org/apache/hadoop/hive/ql/util/JavaDataModelTest.java
new file mode 100644
index 0000000..35976cc
--- /dev/null
+++ b/storage-api/src/test/org/apache/hadoop/hive/ql/util/JavaDataModelTest.java
@@ -0,0 +1,59 @@
+package org.apache.hadoop.hive.ql.util;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
+
+public final class JavaDataModelTest {
+
+ private static final String DATA_MODEL_PROPERTY = "sun.arch.data.model";
+
+ private String previousModelSetting;
+
+ @Before
+ public void setUp() throws Exception {
+ previousModelSetting = System.getProperty(DATA_MODEL_PROPERTY);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ if (previousModelSetting != null) {
+ System.setProperty(DATA_MODEL_PROPERTY, previousModelSetting);
+ } else {
+ System.clearProperty(DATA_MODEL_PROPERTY);
+ }
+ }
+
+ @Test
+ public void testGetDoesNotReturnNull() throws Exception {
+ JavaDataModel model = JavaDataModel.get();
+ assertNotNull(model);
+ }
+
+ @Test
+ public void testGetModelForSystemWhenSetTo32() throws Exception {
+ System.setProperty(DATA_MODEL_PROPERTY, "32");
+ assertSame(JavaDataModel.JAVA32, JavaDataModel.getModelForSystem());
+ }
+
+ @Test
+ public void testGetModelForSystemWhenSetTo64() throws Exception {
+ System.setProperty(DATA_MODEL_PROPERTY, "64");
+ assertSame(JavaDataModel.JAVA64, JavaDataModel.getModelForSystem());
+ }
+
+ @Test
+ public void testGetModelForSystemWhenSetToUnknown() throws Exception {
+ System.setProperty(DATA_MODEL_PROPERTY, "unknown");
+ assertSame(JavaDataModel.JAVA64, JavaDataModel.getModelForSystem());
+ }
+
+ @Test
+ public void testGetModelForSystemWhenUndefined() throws Exception {
+ System.clearProperty(DATA_MODEL_PROPERTY);
+ assertSame(JavaDataModel.JAVA64, JavaDataModel.getModelForSystem());
+ }
+}
\ No newline at end of file