Skip to content

Commit a5a349f

Browse files
authored
HBASE-26392 Update ClassSize.BYTE_BUFFER for JDK17 (#3784)
Signed-off-by: Duo Zhang <[email protected]>
1 parent 8e7f78c commit a5a349f

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
@@ -257,7 +257,11 @@ public static boolean useUnsafeLayout() {
257257
LINKEDLIST_ENTRY = align(OBJECT + (2 * REFERENCE));
258258

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

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)