From a5a349f289dd9b579c3026224186b6ea82dbd9b5 Mon Sep 17 00:00:00 2001 From: Yutong Xiao Date: Wed, 27 Oct 2021 22:02:59 +0800 Subject: [PATCH] HBASE-26392 Update ClassSize.BYTE_BUFFER for JDK17 (#3784) Signed-off-by: Duo Zhang --- .../apache/hadoop/hbase/util/ClassSize.java | 6 +++++- .../org/apache/hadoop/hbase/util/JVM.java | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/ClassSize.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/ClassSize.java index b983fc0f3db..4e6005637bf 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/ClassSize.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/ClassSize.java @@ -257,7 +257,11 @@ public class ClassSize { LINKEDLIST_ENTRY = align(OBJECT + (2 * REFERENCE)); //noinspection PointlessArithmeticExpression - BYTE_BUFFER = align(OBJECT + REFERENCE + + BYTE_BUFFER = JVM.getJVMSpecVersion() < 17 ? + align(OBJECT + REFERENCE + + (5 * Bytes.SIZEOF_INT) + + (3 * Bytes.SIZEOF_BOOLEAN) + Bytes.SIZEOF_LONG) + align(ARRAY) : + align(OBJECT + 2 * REFERENCE + (5 * Bytes.SIZEOF_INT) + (3 * Bytes.SIZEOF_BOOLEAN) + Bytes.SIZEOF_LONG) + align(ARRAY); diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/JVM.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/JVM.java index 6657481ed02..8bd70e486fb 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/JVM.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/JVM.java @@ -60,6 +60,21 @@ public class JVM { private static final String JVMVersion = System.getProperty("java.version"); + /** + * The raw String of java specification version. + * "1.8" for java8, "9","10"... for Java 9, 10... + */ + private static final String JVM_SPEC_VERSION_STRING = + System.getProperty("java.specification.version"); + + /** + * The Integer represent of JVM_SPEC_VERSION, for the JVM version comparison. + * Java 8, 9, 10 ... will be noted as 8, 9 10 ... + */ + private static final int JVM_SPEC_VERSION = JVM_SPEC_VERSION_STRING.contains(".") ? + (int) (Float.parseFloat(JVM_SPEC_VERSION_STRING) * 10 % 10) : + Integer.parseInt(JVM_SPEC_VERSION_STRING); + /** * Constructor. Get the running Operating System instance */ @@ -106,6 +121,10 @@ public class JVM { return ibmvendor && JVMVersion.contains("1.6.0"); } + public static int getJVMSpecVersion() { + return JVM_SPEC_VERSION; + } + /** * Load the implementation of UnixOperatingSystemMXBean for Oracle jvm * and runs the desired method.