Skip to content

Commit 82fe021

Browse files
YutSeanApache9
authored andcommitted
HBASE-26392 Update ClassSize.BYTE_BUFFER for JDK17 (#3784)
Signed-off-by: Duo Zhang <zhangduo@apache.org>
1 parent b417757 commit 82fe021

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

hbase-common/src/main/java/org/apache/hadoop/hbase/util/ClassSize.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,11 @@ public static boolean useUnsafeLayout() {
256256
LINKEDLIST_ENTRY = align(OBJECT + (2 * REFERENCE));
257257

258258
//noinspection PointlessArithmeticExpression
259-
BYTE_BUFFER = align(OBJECT + REFERENCE +
259+
BYTE_BUFFER = JVM.getJVMSpecVersion() < 17 ?
260+
align(OBJECT + REFERENCE +
261+
(5 * Bytes.SIZEOF_INT) +
262+
(3 * Bytes.SIZEOF_BOOLEAN) + Bytes.SIZEOF_LONG) + align(ARRAY) :
263+
align(OBJECT + 2 * REFERENCE +
260264
(5 * Bytes.SIZEOF_INT) +
261265
(3 * Bytes.SIZEOF_BOOLEAN) + Bytes.SIZEOF_LONG) + align(ARRAY);
262266

hbase-common/src/main/java/org/apache/hadoop/hbase/util/JVM.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,21 @@ public class JVM {
6060

6161
private static final String JVMVersion = System.getProperty("java.version");
6262

63+
/**
64+
* The raw String of java specification version.
65+
* "1.8" for java8, "9","10"... for Java 9, 10...
66+
*/
67+
private static final String JVM_SPEC_VERSION_STRING =
68+
System.getProperty("java.specification.version");
69+
70+
/**
71+
* The Integer represent of JVM_SPEC_VERSION, for the JVM version comparison.
72+
* Java 8, 9, 10 ... will be noted as 8, 9 10 ...
73+
*/
74+
private static final int JVM_SPEC_VERSION = JVM_SPEC_VERSION_STRING.contains(".") ?
75+
(int) (Float.parseFloat(JVM_SPEC_VERSION_STRING) * 10 % 10) :
76+
Integer.parseInt(JVM_SPEC_VERSION_STRING);
77+
6378
/**
6479
* Constructor. Get the running Operating System instance
6580
*/
@@ -106,6 +121,10 @@ public static boolean isGZIPOutputStreamFinishBroken() {
106121
return ibmvendor && JVMVersion.contains("1.6.0");
107122
}
108123

124+
public static int getJVMSpecVersion() {
125+
return JVM_SPEC_VERSION;
126+
}
127+
109128
/**
110129
* Load the implementation of UnixOperatingSystemMXBean for Oracle jvm
111130
* and runs the desired method.

0 commit comments

Comments
 (0)