Skip to content

Commit c248521

Browse files
authored
HBASE-25465 Use javac --release option for supporting cross version compilation (#4164)
Signed-off-by: Andrew Purtell <apurtell@apache.org>
1 parent f4866a4 commit c248521

File tree

14 files changed

+187
-389
lines changed

14 files changed

+187
-389
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,20 @@
2323
import java.util.List;
2424
import java.util.Objects;
2525
import java.util.PriorityQueue;
26-
2726
import org.apache.hadoop.hbase.Cell;
2827
import org.apache.hadoop.hbase.CellComparator;
2928
import org.apache.hadoop.hbase.PrivateCellUtil;
30-
import org.apache.yetus.audience.InterfaceAudience;
3129
import org.apache.hadoop.hbase.exceptions.DeserializationException;
30+
import org.apache.hadoop.hbase.unsafe.HBasePlatformDependent;
31+
import org.apache.hadoop.hbase.util.Bytes;
32+
import org.apache.hadoop.hbase.util.Pair;
33+
import org.apache.yetus.audience.InterfaceAudience;
34+
3235
import org.apache.hbase.thirdparty.com.google.protobuf.InvalidProtocolBufferException;
3336
import org.apache.hbase.thirdparty.com.google.protobuf.UnsafeByteOperations;
37+
3438
import org.apache.hadoop.hbase.shaded.protobuf.generated.FilterProtos;
3539
import org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.BytesBytesPair;
36-
import org.apache.hadoop.hbase.util.Bytes;
37-
import org.apache.hadoop.hbase.util.Pair;
38-
import org.apache.hadoop.hbase.util.UnsafeAvailChecker;
3940

4041
/**
4142
* This is optimized version of a standard FuzzyRowFilter Filters data based on fuzzy row key.
@@ -57,7 +58,7 @@
5758
*/
5859
@InterfaceAudience.Public
5960
public class FuzzyRowFilter extends FilterBase {
60-
private static final boolean UNSAFE_UNALIGNED = UnsafeAvailChecker.unaligned();
61+
private static final boolean UNSAFE_UNALIGNED = HBasePlatformDependent.unaligned();
6162
private List<Pair<byte[], byte[]>> fuzzyKeysData;
6263
private boolean done = false;
6364

hbase-common/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@
167167
<groupId>org.apache.hbase.thirdparty</groupId>
168168
<artifactId>hbase-shaded-netty</artifactId>
169169
</dependency>
170+
<dependency>
171+
<groupId>org.apache.hbase.thirdparty</groupId>
172+
<artifactId>hbase-unsafe</artifactId>
173+
</dependency>
170174
<dependency>
171175
<groupId>org.slf4j</groupId>
172176
<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
@@ -30,10 +30,10 @@
3030
import org.apache.hadoop.hbase.nio.ByteBuff;
3131
import org.apache.hadoop.hbase.nio.SingleByteBuff;
3232
import org.apache.hadoop.hbase.util.ReflectionUtils;
33+
import org.apache.hadoop.hbase.util.UnsafeAccess;
3334
import org.apache.yetus.audience.InterfaceAudience;
3435
import org.slf4j.Logger;
3536
import org.slf4j.LoggerFactory;
36-
import sun.nio.ch.DirectBuffer;
3737

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

@@ -335,11 +335,8 @@ public ByteBuff allocate(int size) {
335335
public void clean() {
336336
while (!buffers.isEmpty()) {
337337
ByteBuffer b = buffers.poll();
338-
if (b instanceof DirectBuffer) {
339-
DirectBuffer db = (DirectBuffer) b;
340-
if (db.cleaner() != null) {
341-
db.cleaner().clean();
342-
}
338+
if (b.isDirect()) {
339+
UnsafeAccess.freeDirectBuffer(b);
343340
}
344341
}
345342
this.usedBufCount.set(0);

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,22 @@
2323
import java.nio.ByteBuffer;
2424
import java.nio.channels.FileChannel;
2525
import java.nio.channels.ReadableByteChannel;
26-
2726
import org.apache.hadoop.hbase.io.ByteBuffAllocator.Recycler;
27+
import org.apache.hadoop.hbase.unsafe.HBasePlatformDependent;
2828
import org.apache.hadoop.hbase.util.ByteBufferUtils;
2929
import org.apache.hadoop.hbase.util.ObjectIntPair;
3030
import org.apache.hadoop.hbase.util.UnsafeAccess;
31-
import org.apache.hadoop.hbase.util.UnsafeAvailChecker;
3231
import org.apache.yetus.audience.InterfaceAudience;
3332

34-
import sun.nio.ch.DirectBuffer;
35-
3633
/**
3734
* An implementation of ByteBuff where a single BB backs the BBI. This just acts as a wrapper over a
3835
* normal BB - offheap or onheap
3936
*/
4037
@InterfaceAudience.Private
4138
public class SingleByteBuff extends ByteBuff {
4239

43-
private static final boolean UNSAFE_AVAIL = UnsafeAvailChecker.isAvailable();
44-
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();
4542

4643
// Underlying BB
4744
private final ByteBuffer buf;
@@ -65,7 +62,7 @@ public SingleByteBuff(Recycler recycler, ByteBuffer buf) {
6562
this.unsafeOffset = UnsafeAccess.BYTE_ARRAY_BASE_OFFSET + buf.arrayOffset();
6663
this.unsafeRef = buf.array();
6764
} else {
68-
this.unsafeOffset = ((DirectBuffer) buf).address();
65+
this.unsafeOffset = UnsafeAccess.directBufferAddress(buf);
6966
}
7067
}
7168

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
@@ -30,24 +30,23 @@
3030
import org.apache.hadoop.hbase.io.ByteBufferWriter;
3131
import org.apache.hadoop.hbase.io.util.StreamUtils;
3232
import org.apache.hadoop.hbase.nio.ByteBuff;
33+
import org.apache.hadoop.hbase.unsafe.HBasePlatformDependent;
3334
import org.apache.hadoop.io.IOUtils;
3435
import org.apache.hadoop.io.WritableUtils;
3536
import org.apache.yetus.audience.InterfaceAudience;
36-
import sun.nio.ch.DirectBuffer;
3737

3838
/**
3939
* Utility functions for working with byte buffers, such as reading/writing
4040
* variable-length long numbers.
4141
*/
42-
@SuppressWarnings("restriction")
4342
@InterfaceAudience.Private
4443
public final class ByteBufferUtils {
4544
// "Compressed integer" serialization helper constants.
4645
public final static int VALUE_MASK = 0x7f;
4746
public final static int NEXT_BIT_SHIFT = 7;
4847
public final static int NEXT_BIT_MASK = 1 << 7;
49-
final static boolean UNSAFE_AVAIL = UnsafeAvailChecker.isAvailable();
50-
public final static boolean UNSAFE_UNALIGNED = UnsafeAvailChecker.unaligned();
48+
final static boolean UNSAFE_AVAIL = HBasePlatformDependent.isUnsafeAvailable();
49+
public final static boolean UNSAFE_UNALIGNED = HBasePlatformDependent.unaligned();
5150

5251
private ByteBufferUtils() {
5352
}
@@ -78,11 +77,10 @@ static class ComparerHolder {
7877

7978
static Comparer getBestComparer() {
8079
try {
81-
Class<?> theClass = Class.forName(UNSAFE_COMPARER_NAME);
80+
Class<? extends Comparer> theClass =
81+
Class.forName(UNSAFE_COMPARER_NAME).asSubclass(Comparer.class);
8282

83-
@SuppressWarnings("unchecked")
84-
Comparer comparer = (Comparer) theClass.getConstructor().newInstance();
85-
return comparer;
83+
return theClass.getConstructor().newInstance();
8684
} catch (Throwable t) { // ensure we really catch *everything*
8785
return PureJavaComparer.INSTANCE;
8886
}
@@ -137,7 +135,7 @@ public int compareTo(byte[] buf1, int o1, int l1, ByteBuffer buf2, int o2, int l
137135
long offset2Adj;
138136
Object refObj2 = null;
139137
if (buf2.isDirect()) {
140-
offset2Adj = o2 + ((DirectBuffer)buf2).address();
138+
offset2Adj = o2 + UnsafeAccess.directBufferAddress(buf2);
141139
} else {
142140
offset2Adj = o2 + buf2.arrayOffset() + UnsafeAccess.BYTE_ARRAY_BASE_OFFSET;
143141
refObj2 = buf2.array();
@@ -151,13 +149,13 @@ public int compareTo(ByteBuffer buf1, int o1, int l1, ByteBuffer buf2, int o2, i
151149
long offset1Adj, offset2Adj;
152150
Object refObj1 = null, refObj2 = null;
153151
if (buf1.isDirect()) {
154-
offset1Adj = o1 + ((DirectBuffer) buf1).address();
152+
offset1Adj = o1 + UnsafeAccess.directBufferAddress(buf1);
155153
} else {
156154
offset1Adj = o1 + buf1.arrayOffset() + UnsafeAccess.BYTE_ARRAY_BASE_OFFSET;
157155
refObj1 = buf1.array();
158156
}
159157
if (buf2.isDirect()) {
160-
offset2Adj = o2 + ((DirectBuffer) buf2).address();
158+
offset2Adj = o2 + UnsafeAccess.directBufferAddress(buf2);
161159
} else {
162160
offset2Adj = o2 + buf2.arrayOffset() + UnsafeAccess.BYTE_ARRAY_BASE_OFFSET;
163161
refObj2 = buf2.array();
@@ -175,12 +173,11 @@ static class ConverterHolder {
175173

176174
static Converter getBestConverter() {
177175
try {
178-
Class<?> theClass = Class.forName(UNSAFE_CONVERTER_NAME);
176+
Class<? extends Converter> theClass =
177+
Class.forName(UNSAFE_CONVERTER_NAME).asSubclass(Converter.class);
179178

180179
// yes, UnsafeComparer does implement Comparer<byte[]>
181-
@SuppressWarnings("unchecked")
182-
Converter converter = (Converter) theClass.getConstructor().newInstance();
183-
return converter;
180+
return theClass.getConstructor().newInstance();
184181
} catch (Throwable t) { // ensure we really catch *everything*
185182
return PureJavaConverter.INSTANCE;
186183
}
@@ -922,8 +919,8 @@ static int compareToUnsafe(Object obj1, long o1, int l1, Object obj2, long o2, i
922919
* 64-bit.
923920
*/
924921
for (i = 0; i < strideLimit; i += stride) {
925-
long lw = UnsafeAccess.theUnsafe.getLong(obj1, o1 + (long) i);
926-
long rw = UnsafeAccess.theUnsafe.getLong(obj2, o2 + (long) i);
922+
long lw = HBasePlatformDependent.getLong(obj1, o1 + (long) i);
923+
long rw = HBasePlatformDependent.getLong(obj2, o2 + (long) i);
927924
if (lw != rw) {
928925
if (!UnsafeAccess.LITTLE_ENDIAN) {
929926
return ((lw + Long.MIN_VALUE) < (rw + Long.MIN_VALUE)) ? -1 : 1;
@@ -944,8 +941,8 @@ static int compareToUnsafe(Object obj1, long o1, int l1, Object obj2, long o2, i
944941

945942
// The epilogue to cover the last (minLength % stride) elements.
946943
for (; i < minLength; i++) {
947-
int il = (UnsafeAccess.theUnsafe.getByte(obj1, o1 + i) & 0xFF);
948-
int ir = (UnsafeAccess.theUnsafe.getByte(obj2, o2 + i) & 0xFF);
944+
int il = (HBasePlatformDependent.getByte(obj1, o1 + i) & 0xFF);
945+
int ir = (HBasePlatformDependent.getByte(obj2, o2 + i) & 0xFF);
949946
if (il != ir) {
950947
return il - ir;
951948
}

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
@@ -41,13 +41,13 @@
4141

4242
import org.apache.hadoop.hbase.Cell;
4343
import org.apache.hadoop.hbase.CellComparator;
44+
import org.apache.hadoop.hbase.unsafe.HBasePlatformDependent;
4445
import org.apache.hadoop.io.RawComparator;
4546
import org.apache.hadoop.io.WritableComparator;
4647
import org.apache.hadoop.io.WritableUtils;
4748
import org.apache.yetus.audience.InterfaceAudience;
4849
import org.slf4j.Logger;
4950
import org.slf4j.LoggerFactory;
50-
import sun.misc.Unsafe;
5151

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

@@ -56,7 +56,6 @@
5656
* comparisons, hash code generation, manufacturing keys for HashMaps or
5757
* 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",
@@ -126,7 +125,7 @@ public class Bytes implements Comparable<Bytes> {
126125
// SizeOf which uses java.lang.instrument says 24 bytes. (3 longs?)
127126
public static final int ESTIMATED_HEAP_TAX = 16;
128127

129-
static final boolean UNSAFE_UNALIGNED = UnsafeAvailChecker.unaligned();
128+
static final boolean UNSAFE_UNALIGNED = HBasePlatformDependent.unaligned();
130129

131130
/**
132131
* Returns length of the byte array, returning 0 if the array is null.
@@ -1359,21 +1358,17 @@ int putShort(byte[] bytes, int offset, short val) {
13591358

13601359
protected static final class UnsafeConverter extends Converter {
13611360

1362-
static final Unsafe theUnsafe;
1363-
13641361
public UnsafeConverter() {}
13651362

13661363
static {
1367-
if (UNSAFE_UNALIGNED) {
1368-
theUnsafe = UnsafeAccess.theUnsafe;
1369-
} else {
1364+
if (!UNSAFE_UNALIGNED) {
13701365
// It doesn't matter what we throw;
13711366
// it's swallowed in getBestComparer().
13721367
throw new Error();
13731368
}
13741369

13751370
// sanity check - this should never fail
1376-
if (theUnsafe.arrayIndexScale(byte[].class) != 1) {
1371+
if (HBasePlatformDependent.arrayIndexScale(byte[].class) != 1) {
13771372
throw new AssertionError();
13781373
}
13791374
}
@@ -1412,7 +1407,7 @@ int putShort(byte[] bytes, int offset, short val) {
14121407

14131408
/**
14141409
* Provides a lexicographical comparer implementation; either a Java
1415-
* implementation or a faster implementation based on {@link Unsafe}.
1410+
* implementation or a faster implementation based on {@code Unsafe}.
14161411
*
14171412
* <p>Uses reflection to gracefully fall back to the Java implementation if
14181413
* {@code Unsafe} isn't available.
@@ -1469,18 +1464,15 @@ public int compareTo(byte[] buffer1, int offset1, int length1,
14691464
enum UnsafeComparer implements Comparer<byte[]> {
14701465
INSTANCE;
14711466

1472-
static final Unsafe theUnsafe;
14731467
static {
1474-
if (UNSAFE_UNALIGNED) {
1475-
theUnsafe = UnsafeAccess.theUnsafe;
1476-
} else {
1468+
if (!UNSAFE_UNALIGNED) {
14771469
// It doesn't matter what we throw;
14781470
// it's swallowed in getBestComparer().
14791471
throw new Error();
14801472
}
14811473

14821474
// sanity check - this should never fail
1483-
if (theUnsafe.arrayIndexScale(byte[].class) != 1) {
1475+
if (HBasePlatformDependent.arrayIndexScale(byte[].class) != 1) {
14841476
throw new AssertionError();
14851477
}
14861478
}
@@ -1518,8 +1510,8 @@ public int compareTo(byte[] buffer1, int offset1, int length1,
15181510
* than 4 bytes even on 32-bit. On the other hand, it is substantially faster on 64-bit.
15191511
*/
15201512
for (i = 0; i < strideLimit; i += stride) {
1521-
long lw = theUnsafe.getLong(buffer1, offset1Adj + i);
1522-
long rw = theUnsafe.getLong(buffer2, offset2Adj + i);
1513+
long lw = HBasePlatformDependent.getLong(buffer1, offset1Adj + i);
1514+
long rw = HBasePlatformDependent.getLong(buffer2, offset2Adj + i);
15231515
if (lw != rw) {
15241516
if(!UnsafeAccess.LITTLE_ENDIAN) {
15251517
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: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import java.lang.reflect.Modifier;
2525
import java.util.concurrent.ConcurrentHashMap;
2626
import java.util.concurrent.ConcurrentSkipListMap;
27-
27+
import org.apache.hadoop.hbase.unsafe.HBasePlatformDependent;
2828
import org.apache.yetus.audience.InterfaceAudience;
2929
import org.slf4j.Logger;
3030
import org.slf4j.LoggerFactory;
@@ -186,13 +186,19 @@ private static final class HeaderSize {
186186
private byte a;
187187
}
188188

189+
private static final int ARRAY_OBJECT_INDEX_SCALE =
190+
HBasePlatformDependent.arrayIndexScale(Object[].class);
191+
192+
private static final int ARRAY_BYTE_INDEX_SCALE =
193+
HBasePlatformDependent.arrayIndexScale(byte[].class);
194+
189195
public UnsafeLayout() {
190196
}
191197

192198
@Override
193199
int headerSize() {
194200
try {
195-
return (int) UnsafeAccess.theUnsafe.objectFieldOffset(
201+
return (int) HBasePlatformDependent.objectFieldOffset(
196202
HeaderSize.class.getDeclaredField("a"));
197203
} catch (NoSuchFieldException | SecurityException e) {
198204
LOG.error(e.toString(), e);
@@ -202,29 +208,28 @@ int headerSize() {
202208

203209
@Override
204210
int arrayHeaderSize() {
205-
return UnsafeAccess.theUnsafe.arrayBaseOffset(byte[].class);
211+
return HBasePlatformDependent.arrayBaseOffset(byte[].class);
206212
}
207213

208214
@Override
209-
@SuppressWarnings("static-access")
210215
int oopSize() {
211216
// Unsafe.addressSize() returns 8, even with CompressedOops. This is how many bytes each
212217
// element is allocated in an Object[].
213-
return UnsafeAccess.theUnsafe.ARRAY_OBJECT_INDEX_SCALE;
218+
return ARRAY_OBJECT_INDEX_SCALE;
214219
}
215220

216221
@Override
217-
@SuppressWarnings("static-access")
218222
long sizeOfByteArray(int len) {
219-
return align(ARRAY + len * UnsafeAccess.theUnsafe.ARRAY_BYTE_INDEX_SCALE);
223+
return align(ARRAY + len * ARRAY_BYTE_INDEX_SCALE);
220224
}
221225
}
222226

223227
private static MemoryLayout getMemoryLayout() {
224228
// Have a safeguard in case Unsafe estimate is wrong. This is static context, there is
225229
// no configuration, so we look at System property.
226230
String enabled = System.getProperty("hbase.memorylayout.use.unsafe");
227-
if (UnsafeAvailChecker.isAvailable() && (enabled == null || Boolean.parseBoolean(enabled))) {
231+
if (HBasePlatformDependent.isUnsafeAvailable() &&
232+
(enabled == null || Boolean.parseBoolean(enabled))) {
228233
LOG.debug("Using Unsafe to estimate memory layout");
229234
return new UnsafeLayout();
230235
}

0 commit comments

Comments
 (0)