Skip to content

Commit 91a44f5

Browse files
authored
HBASE-26523 + HBASE-25465 + HBASE-26855 backport to branch-2.4 (#4439)
* HBASE-26523 Upgrade hbase-thirdparty dependency to 4.0.1 (#3988) Signed-off-by: GeorryHuang <huangzhuoyue@apache.org> * HBASE-25465 Use javac --release option for supporting cross version compilation (#4164) Signed-off-by: Andrew Purtell <apurtell@apache.org> * HBASE-26855 Delete unnecessary dependency on jaxb-runtime jar (#4236) Signed-off-by: Duo Zhang <zhangduo@apache.org> * spotless apply Co-authored-by: Duo Zhang <zhangduo@apache.org> Co-authored-by: Nick Dimiduk <ndimiduk@apache.org> Signed-off-by: Andrew Purtell <apurtell@apache.org>
1 parent ee284b6 commit 91a44f5

File tree

51 files changed

+471
-573
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+471
-573
lines changed

hbase-client/src/main/java/org/apache/hadoop/hbase/filter/FuzzyRowFilter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
import org.apache.hadoop.hbase.CellComparator;
2828
import org.apache.hadoop.hbase.PrivateCellUtil;
2929
import org.apache.hadoop.hbase.exceptions.DeserializationException;
30+
import org.apache.hadoop.hbase.unsafe.HBasePlatformDependent;
3031
import org.apache.hadoop.hbase.util.Bytes;
3132
import org.apache.hadoop.hbase.util.Pair;
32-
import org.apache.hadoop.hbase.util.UnsafeAvailChecker;
3333
import org.apache.yetus.audience.InterfaceAudience;
3434

3535
import org.apache.hbase.thirdparty.com.google.protobuf.InvalidProtocolBufferException;
@@ -58,7 +58,8 @@
5858
*/
5959
@InterfaceAudience.Public
6060
public class FuzzyRowFilter extends FilterBase {
61-
private static final boolean UNSAFE_UNALIGNED = UnsafeAvailChecker.unaligned();
61+
62+
private static final boolean UNSAFE_UNALIGNED = HBasePlatformDependent.unaligned();
6263

6364
// the wildcard byte is 1 on the user side. but the filter converts it internally
6465
// in preprocessMask. This was changed in HBASE-15676 due to a bug with using 0.

hbase-common/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@
6060
<groupId>org.apache.hbase.thirdparty</groupId>
6161
<artifactId>hbase-shaded-netty</artifactId>
6262
</dependency>
63+
<dependency>
64+
<groupId>org.apache.hbase.thirdparty</groupId>
65+
<artifactId>hbase-unsafe</artifactId>
66+
</dependency>
6367
<dependency>
6468
<groupId>org.slf4j</groupId>
6569
<artifactId>slf4j-api</artifactId>

hbase-common/src/main/java/org/apache/hadoop/hbase/io/ByteBuffAllocator.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929
import org.apache.hadoop.hbase.nio.ByteBuff;
3030
import org.apache.hadoop.hbase.nio.SingleByteBuff;
3131
import org.apache.hadoop.hbase.util.ReflectionUtils;
32+
import org.apache.hadoop.hbase.util.UnsafeAccess;
3233
import org.apache.yetus.audience.InterfaceAudience;
3334
import org.slf4j.Logger;
3435
import org.slf4j.LoggerFactory;
35-
import sun.nio.ch.DirectBuffer;
3636

3737
import org.apache.hbase.thirdparty.com.google.common.collect.Sets;
3838

@@ -362,11 +362,8 @@ public ByteBuff allocate(int size) {
362362
public void clean() {
363363
while (!buffers.isEmpty()) {
364364
ByteBuffer b = buffers.poll();
365-
if (b instanceof DirectBuffer) {
366-
DirectBuffer db = (DirectBuffer) b;
367-
if (db.cleaner() != null) {
368-
db.cleaner().clean();
369-
}
365+
if (b.isDirect()) {
366+
UnsafeAccess.freeDirectBuffer(b);
370367
}
371368
}
372369
this.usedBufCount.set(0);

hbase-common/src/main/java/org/apache/hadoop/hbase/nio/SingleByteBuff.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,11 @@
2424
import java.nio.channels.FileChannel;
2525
import java.nio.channels.ReadableByteChannel;
2626
import org.apache.hadoop.hbase.io.ByteBuffAllocator.Recycler;
27+
import org.apache.hadoop.hbase.unsafe.HBasePlatformDependent;
2728
import org.apache.hadoop.hbase.util.ByteBufferUtils;
2829
import org.apache.hadoop.hbase.util.ObjectIntPair;
2930
import org.apache.hadoop.hbase.util.UnsafeAccess;
30-
import org.apache.hadoop.hbase.util.UnsafeAvailChecker;
3131
import org.apache.yetus.audience.InterfaceAudience;
32-
import sun.nio.ch.DirectBuffer;
3332

3433
/**
3534
* An implementation of ByteBuff where a single BB backs the BBI. This just acts as a wrapper over a
@@ -38,8 +37,8 @@
3837
@InterfaceAudience.Private
3938
public class SingleByteBuff extends ByteBuff {
4039

41-
private static final boolean UNSAFE_AVAIL = UnsafeAvailChecker.isAvailable();
42-
private static final boolean UNSAFE_UNALIGNED = UnsafeAvailChecker.unaligned();
40+
private static final boolean UNSAFE_AVAIL = HBasePlatformDependent.isUnsafeAvailable();
41+
private static final boolean UNSAFE_UNALIGNED = HBasePlatformDependent.unaligned();
4342

4443
// Underlying BB
4544
private final ByteBuffer buf;
@@ -63,7 +62,7 @@ public SingleByteBuff(Recycler recycler, ByteBuffer buf) {
6362
this.unsafeOffset = UnsafeAccess.BYTE_ARRAY_BASE_OFFSET + buf.arrayOffset();
6463
this.unsafeRef = buf.array();
6564
} else {
66-
this.unsafeOffset = ((DirectBuffer) buf).address();
65+
this.unsafeOffset = UnsafeAccess.directBufferAddress(buf);
6766
}
6867
}
6968

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

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,16 @@
3131
import org.apache.hadoop.hbase.io.ByteBufferWriter;
3232
import org.apache.hadoop.hbase.io.util.StreamUtils;
3333
import org.apache.hadoop.hbase.nio.ByteBuff;
34+
import org.apache.hadoop.hbase.unsafe.HBasePlatformDependent;
3435
import org.apache.hadoop.io.IOUtils;
3536
import org.apache.hadoop.io.WritableUtils;
3637
import org.apache.yetus.audience.InterfaceAudience;
37-
import sun.nio.ch.DirectBuffer;
3838

3939
/**
4040
* Utility functions for working with byte buffers, such as reading/writing variable-length long
4141
* numbers.
4242
* @deprecated This class will become IA.Private in HBase 3.0. Downstream folks shouldn't use it.
4343
*/
44-
@SuppressWarnings("restriction")
4544
@Deprecated
4645
@InterfaceAudience.Public
4746
public final class ByteBufferUtils {
@@ -50,8 +49,8 @@ public final class ByteBufferUtils {
5049
public final static int NEXT_BIT_SHIFT = 7;
5150
public final static int NEXT_BIT_MASK = 1 << 7;
5251
@InterfaceAudience.Private
53-
final static boolean UNSAFE_AVAIL = UnsafeAvailChecker.isAvailable();
54-
public final static boolean UNSAFE_UNALIGNED = UnsafeAvailChecker.unaligned();
52+
final static boolean UNSAFE_AVAIL = HBasePlatformDependent.isUnsafeAvailable();
53+
public final static boolean UNSAFE_UNALIGNED = HBasePlatformDependent.unaligned();
5554

5655
private ByteBufferUtils() {
5756
}
@@ -91,11 +90,10 @@ static class ComparerHolder {
9190

9291
static Comparer getBestComparer() {
9392
try {
94-
Class<?> theClass = Class.forName(UNSAFE_COMPARER_NAME);
93+
Class<? extends Comparer> theClass =
94+
Class.forName(UNSAFE_COMPARER_NAME).asSubclass(Comparer.class);
9595

96-
@SuppressWarnings("unchecked")
97-
Comparer comparer = (Comparer) theClass.getConstructor().newInstance();
98-
return comparer;
96+
return theClass.getConstructor().newInstance();
9997
} catch (Throwable t) { // ensure we really catch *everything*
10098
return PureJavaComparer.INSTANCE;
10199
}
@@ -152,7 +150,7 @@ public int compareTo(byte[] buf1, int o1, int l1, ByteBuffer buf2, int o2, int l
152150
long offset2Adj;
153151
Object refObj2 = null;
154152
if (buf2.isDirect()) {
155-
offset2Adj = o2 + ((DirectBuffer) buf2).address();
153+
offset2Adj = o2 + UnsafeAccess.directBufferAddress(buf2);
156154
} else {
157155
offset2Adj = o2 + buf2.arrayOffset() + UnsafeAccess.BYTE_ARRAY_BASE_OFFSET;
158156
refObj2 = buf2.array();
@@ -166,13 +164,13 @@ public int compareTo(ByteBuffer buf1, int o1, int l1, ByteBuffer buf2, int o2, i
166164
long offset1Adj, offset2Adj;
167165
Object refObj1 = null, refObj2 = null;
168166
if (buf1.isDirect()) {
169-
offset1Adj = o1 + ((DirectBuffer) buf1).address();
167+
offset1Adj = o1 + UnsafeAccess.directBufferAddress(buf1);
170168
} else {
171169
offset1Adj = o1 + buf1.arrayOffset() + UnsafeAccess.BYTE_ARRAY_BASE_OFFSET;
172170
refObj1 = buf1.array();
173171
}
174172
if (buf2.isDirect()) {
175-
offset2Adj = o2 + ((DirectBuffer) buf2).address();
173+
offset2Adj = o2 + UnsafeAccess.directBufferAddress(buf2);
176174
} else {
177175
offset2Adj = o2 + buf2.arrayOffset() + UnsafeAccess.BYTE_ARRAY_BASE_OFFSET;
178176
refObj2 = buf2.array();
@@ -189,12 +187,11 @@ static class ConverterHolder {
189187

190188
static Converter getBestConverter() {
191189
try {
192-
Class<?> theClass = Class.forName(UNSAFE_CONVERTER_NAME);
190+
Class<? extends Converter> theClass =
191+
Class.forName(UNSAFE_CONVERTER_NAME).asSubclass(Converter.class);
193192

194193
// yes, UnsafeComparer does implement Comparer<byte[]>
195-
@SuppressWarnings("unchecked")
196-
Converter converter = (Converter) theClass.getConstructor().newInstance();
197-
return converter;
194+
return theClass.getConstructor().newInstance();
198195
} catch (Throwable t) { // ensure we really catch *everything*
199196
return PureJavaConverter.INSTANCE;
200197
}
@@ -932,8 +929,8 @@ static int compareToUnsafe(Object obj1, long o1, int l1, Object obj2, long o2, i
932929
* 64-bit.
933930
*/
934931
for (i = 0; i < strideLimit; i += stride) {
935-
long lw = UnsafeAccess.theUnsafe.getLong(obj1, o1 + (long) i);
936-
long rw = UnsafeAccess.theUnsafe.getLong(obj2, o2 + (long) i);
932+
long lw = HBasePlatformDependent.getLong(obj1, o1 + (long) i);
933+
long rw = HBasePlatformDependent.getLong(obj2, o2 + (long) i);
937934
if (lw != rw) {
938935
if (!UnsafeAccess.LITTLE_ENDIAN) {
939936
return ((lw + Long.MIN_VALUE) < (rw + Long.MIN_VALUE)) ? -1 : 1;
@@ -953,8 +950,8 @@ static int compareToUnsafe(Object obj1, long o1, int l1, Object obj2, long o2, i
953950

954951
// The epilogue to cover the last (minLength % stride) elements.
955952
for (; i < minLength; i++) {
956-
int il = (UnsafeAccess.theUnsafe.getByte(obj1, o1 + i) & 0xFF);
957-
int ir = (UnsafeAccess.theUnsafe.getByte(obj2, o2 + i) & 0xFF);
953+
int il = (HBasePlatformDependent.getByte(obj1, o1 + i) & 0xFF);
954+
int ir = (HBasePlatformDependent.getByte(obj2, o2 + i) & 0xFF);
958955
if (il != ir) {
959956
return il - ir;
960957
}

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

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,20 @@
4242
import org.apache.hadoop.hbase.Cell;
4343
import org.apache.hadoop.hbase.CellComparator;
4444
import org.apache.hadoop.hbase.KeyValue;
45+
import org.apache.hadoop.hbase.unsafe.HBasePlatformDependent;
4546
import org.apache.hadoop.io.RawComparator;
4647
import org.apache.hadoop.io.WritableComparator;
4748
import org.apache.hadoop.io.WritableUtils;
4849
import org.apache.yetus.audience.InterfaceAudience;
4950
import org.slf4j.Logger;
5051
import org.slf4j.LoggerFactory;
51-
import sun.misc.Unsafe;
5252

5353
import org.apache.hbase.thirdparty.org.apache.commons.collections4.CollectionUtils;
5454

5555
/**
5656
* Utility class that handles byte arrays, conversions to/from other types, comparisons, hash code
5757
* generation, manufacturing keys for HashMaps or HashSets, and can be used as key in maps or trees.
5858
*/
59-
@SuppressWarnings("restriction")
6059
@InterfaceAudience.Public
6160
@edu.umd.cs.findbugs.annotations.SuppressWarnings(
6261
value = "EQ_CHECK_FOR_OPERAND_NOT_COMPATIBLE_WITH_THIS",
@@ -127,7 +126,7 @@ public class Bytes implements Comparable<Bytes> {
127126
public static final int ESTIMATED_HEAP_TAX = 16;
128127

129128
@InterfaceAudience.Private
130-
static final boolean UNSAFE_UNALIGNED = UnsafeAvailChecker.unaligned();
129+
static final boolean UNSAFE_UNALIGNED = HBasePlatformDependent.unaligned();
131130

132131
/**
133132
* Returns length of the byte array, returning 0 if the array is null. Useful for calculating
@@ -1428,22 +1427,18 @@ int putShort(byte[] bytes, int offset, short val) {
14281427

14291428
protected static final class UnsafeConverter extends Converter {
14301429

1431-
static final Unsafe theUnsafe;
1432-
14331430
public UnsafeConverter() {
14341431
}
14351432

14361433
static {
1437-
if (UNSAFE_UNALIGNED) {
1438-
theUnsafe = UnsafeAccess.theUnsafe;
1439-
} else {
1434+
if (!UNSAFE_UNALIGNED) {
14401435
// It doesn't matter what we throw;
14411436
// it's swallowed in getBestComparer().
14421437
throw new Error();
14431438
}
14441439

14451440
// sanity check - this should never fail
1446-
if (theUnsafe.arrayIndexScale(byte[].class) != 1) {
1441+
if (HBasePlatformDependent.arrayIndexScale(byte[].class) != 1) {
14471442
throw new AssertionError();
14481443
}
14491444
}
@@ -1482,7 +1477,7 @@ int putShort(byte[] bytes, int offset, short val) {
14821477

14831478
/**
14841479
* Provides a lexicographical comparer implementation; either a Java implementation or a faster
1485-
* implementation based on {@link Unsafe}.
1480+
* implementation based on {@code Unsafe}.
14861481
* <p>
14871482
* Uses reflection to gracefully fall back to the Java implementation if {@code Unsafe} isn't
14881483
* available.
@@ -1539,18 +1534,15 @@ public int compareTo(byte[] buffer1, int offset1, int length1, byte[] buffer2, i
15391534
enum UnsafeComparer implements Comparer<byte[]> {
15401535
INSTANCE;
15411536

1542-
static final Unsafe theUnsafe;
15431537
static {
1544-
if (UNSAFE_UNALIGNED) {
1545-
theUnsafe = UnsafeAccess.theUnsafe;
1546-
} else {
1538+
if (!UNSAFE_UNALIGNED) {
15471539
// It doesn't matter what we throw;
15481540
// it's swallowed in getBestComparer().
15491541
throw new Error();
15501542
}
15511543

15521544
// sanity check - this should never fail
1553-
if (theUnsafe.arrayIndexScale(byte[].class) != 1) {
1545+
if (HBasePlatformDependent.arrayIndexScale(byte[].class) != 1) {
15541546
throw new AssertionError();
15551547
}
15561548
}
@@ -1585,8 +1577,8 @@ public int compareTo(byte[] buffer1, int offset1, int length1, byte[] buffer2, i
15851577
* than 4 bytes even on 32-bit. On the other hand, it is substantially faster on 64-bit.
15861578
*/
15871579
for (i = 0; i < strideLimit; i += stride) {
1588-
long lw = theUnsafe.getLong(buffer1, offset1Adj + i);
1589-
long rw = theUnsafe.getLong(buffer2, offset2Adj + i);
1580+
long lw = HBasePlatformDependent.getLong(buffer1, offset1Adj + i);
1581+
long rw = HBasePlatformDependent.getLong(buffer2, offset2Adj + i);
15901582
if (lw != rw) {
15911583
if (!UnsafeAccess.LITTLE_ENDIAN) {
15921584
return ((lw + Long.MIN_VALUE) < (rw + Long.MIN_VALUE)) ? -1 : 1;

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.lang.reflect.Modifier;
2222
import java.util.concurrent.ConcurrentHashMap;
2323
import java.util.concurrent.ConcurrentSkipListMap;
24+
import org.apache.hadoop.hbase.unsafe.HBasePlatformDependent;
2425
import org.apache.yetus.audience.InterfaceAudience;
2526
import org.slf4j.Logger;
2627
import org.slf4j.LoggerFactory;
@@ -178,13 +179,19 @@ private static final class HeaderSize {
178179
private byte a;
179180
}
180181

182+
private static final int ARRAY_OBJECT_INDEX_SCALE =
183+
HBasePlatformDependent.arrayIndexScale(Object[].class);
184+
185+
private static final int ARRAY_BYTE_INDEX_SCALE =
186+
HBasePlatformDependent.arrayIndexScale(byte[].class);
187+
181188
public UnsafeLayout() {
182189
}
183190

184191
@Override
185192
int headerSize() {
186193
try {
187-
return (int) UnsafeAccess.theUnsafe
194+
return (int) HBasePlatformDependent
188195
.objectFieldOffset(HeaderSize.class.getDeclaredField("a"));
189196
} catch (NoSuchFieldException | SecurityException e) {
190197
LOG.error(e.toString(), e);
@@ -194,29 +201,30 @@ int headerSize() {
194201

195202
@Override
196203
int arrayHeaderSize() {
197-
return UnsafeAccess.theUnsafe.arrayBaseOffset(byte[].class);
204+
return HBasePlatformDependent.arrayBaseOffset(byte[].class);
198205
}
199206

200207
@Override
201-
@SuppressWarnings("static-access")
202208
int oopSize() {
203209
// Unsafe.addressSize() returns 8, even with CompressedOops. This is how many bytes each
204210
// element is allocated in an Object[].
205-
return UnsafeAccess.theUnsafe.ARRAY_OBJECT_INDEX_SCALE;
211+
return ARRAY_OBJECT_INDEX_SCALE;
206212
}
207213

208214
@Override
209-
@SuppressWarnings("static-access")
210215
long sizeOfByteArray(int len) {
211-
return align(ARRAY + len * UnsafeAccess.theUnsafe.ARRAY_BYTE_INDEX_SCALE);
216+
return align(ARRAY + len * ARRAY_BYTE_INDEX_SCALE);
212217
}
213218
}
214219

215220
private static MemoryLayout getMemoryLayout() {
216221
// Have a safeguard in case Unsafe estimate is wrong. This is static context, there is
217222
// no configuration, so we look at System property.
218223
String enabled = System.getProperty("hbase.memorylayout.use.unsafe");
219-
if (UnsafeAvailChecker.isAvailable() && (enabled == null || Boolean.parseBoolean(enabled))) {
224+
if (
225+
HBasePlatformDependent.isUnsafeAvailable()
226+
&& (enabled == null || Boolean.parseBoolean(enabled))
227+
) {
220228
LOG.debug("Using Unsafe to estimate memory layout");
221229
return new UnsafeLayout();
222230
}

0 commit comments

Comments
 (0)