Skip to content

Commit 9e1de13

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

File tree

14 files changed

+188
-390
lines changed

14 files changed

+188
-390
lines changed

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

Lines changed: 8 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,8 @@
5758
*/
5859
@InterfaceAudience.Public
5960
public class FuzzyRowFilter extends FilterBase {
60-
private static final boolean UNSAFE_UNALIGNED = UnsafeAvailChecker.unaligned();
61+
62+
private static final boolean UNSAFE_UNALIGNED = HBasePlatformDependent.unaligned();
6163

6264
// the wildcard byte is 1 on the user side. but the filter converts it internally
6365
// 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
@@ -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

@@ -339,11 +339,8 @@ public ByteBuff allocate(int size) {
339339
public void clean() {
340340
while (!buffers.isEmpty()) {
341341
ByteBuffer b = buffers.poll();
342-
if (b instanceof DirectBuffer) {
343-
DirectBuffer db = (DirectBuffer) b;
344-
if (db.cleaner() != null) {
345-
db.cleaner().clean();
346-
}
342+
if (b.isDirect()) {
343+
UnsafeAccess.freeDirectBuffer(b);
347344
}
348345
}
349346
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 & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +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;
3738

38-
import sun.nio.ch.DirectBuffer;
39-
4039
/**
4140
* Utility functions for working with byte buffers, such as reading/writing
4241
* variable-length long numbers.
4342
* @deprecated This class will become IA.Private in HBase 3.0. Downstream folks shouldn't use it.
4443
*/
45-
@SuppressWarnings("restriction")
4644
@Deprecated
4745
@InterfaceAudience.Public
4846
public final class ByteBufferUtils {
@@ -51,8 +49,8 @@ public final class ByteBufferUtils {
5149
public final static int NEXT_BIT_SHIFT = 7;
5250
public final static int NEXT_BIT_MASK = 1 << 7;
5351
@InterfaceAudience.Private
54-
final static boolean UNSAFE_AVAIL = UnsafeAvailChecker.isAvailable();
55-
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();
5654

5755
private ByteBufferUtils() {
5856
}
@@ -83,11 +81,10 @@ static class ComparerHolder {
8381

8482
static Comparer getBestComparer() {
8583
try {
86-
Class<?> theClass = Class.forName(UNSAFE_COMPARER_NAME);
84+
Class<? extends Comparer> theClass =
85+
Class.forName(UNSAFE_COMPARER_NAME).asSubclass(Comparer.class);
8786

88-
@SuppressWarnings("unchecked")
89-
Comparer comparer = (Comparer) theClass.getConstructor().newInstance();
90-
return comparer;
87+
return theClass.getConstructor().newInstance();
9188
} catch (Throwable t) { // ensure we really catch *everything*
9289
return PureJavaComparer.INSTANCE;
9390
}
@@ -142,7 +139,7 @@ public int compareTo(byte[] buf1, int o1, int l1, ByteBuffer buf2, int o2, int l
142139
long offset2Adj;
143140
Object refObj2 = null;
144141
if (buf2.isDirect()) {
145-
offset2Adj = o2 + ((DirectBuffer)buf2).address();
142+
offset2Adj = o2 + UnsafeAccess.directBufferAddress(buf2);
146143
} else {
147144
offset2Adj = o2 + buf2.arrayOffset() + UnsafeAccess.BYTE_ARRAY_BASE_OFFSET;
148145
refObj2 = buf2.array();
@@ -156,13 +153,13 @@ public int compareTo(ByteBuffer buf1, int o1, int l1, ByteBuffer buf2, int o2, i
156153
long offset1Adj, offset2Adj;
157154
Object refObj1 = null, refObj2 = null;
158155
if (buf1.isDirect()) {
159-
offset1Adj = o1 + ((DirectBuffer) buf1).address();
156+
offset1Adj = o1 + UnsafeAccess.directBufferAddress(buf1);
160157
} else {
161158
offset1Adj = o1 + buf1.arrayOffset() + UnsafeAccess.BYTE_ARRAY_BASE_OFFSET;
162159
refObj1 = buf1.array();
163160
}
164161
if (buf2.isDirect()) {
165-
offset2Adj = o2 + ((DirectBuffer) buf2).address();
162+
offset2Adj = o2 + UnsafeAccess.directBufferAddress(buf2);
166163
} else {
167164
offset2Adj = o2 + buf2.arrayOffset() + UnsafeAccess.BYTE_ARRAY_BASE_OFFSET;
168165
refObj2 = buf2.array();
@@ -180,12 +177,11 @@ static class ConverterHolder {
180177

181178
static Converter getBestConverter() {
182179
try {
183-
Class<?> theClass = Class.forName(UNSAFE_CONVERTER_NAME);
180+
Class<? extends Converter> theClass =
181+
Class.forName(UNSAFE_CONVERTER_NAME).asSubclass(Converter.class);
184182

185183
// yes, UnsafeComparer does implement Comparer<byte[]>
186-
@SuppressWarnings("unchecked")
187-
Converter converter = (Converter) theClass.getConstructor().newInstance();
188-
return converter;
184+
return theClass.getConstructor().newInstance();
189185
} catch (Throwable t) { // ensure we really catch *everything*
190186
return PureJavaConverter.INSTANCE;
191187
}
@@ -949,8 +945,8 @@ static int compareToUnsafe(Object obj1, long o1, int l1, Object obj2, long o2, i
949945
* 64-bit.
950946
*/
951947
for (i = 0; i < strideLimit; i += stride) {
952-
long lw = UnsafeAccess.theUnsafe.getLong(obj1, o1 + (long) i);
953-
long rw = UnsafeAccess.theUnsafe.getLong(obj2, o2 + (long) i);
948+
long lw = HBasePlatformDependent.getLong(obj1, o1 + (long) i);
949+
long rw = HBasePlatformDependent.getLong(obj2, o2 + (long) i);
954950
if (lw != rw) {
955951
if (!UnsafeAccess.LITTLE_ENDIAN) {
956952
return ((lw + Long.MIN_VALUE) < (rw + Long.MIN_VALUE)) ? -1 : 1;
@@ -971,8 +967,8 @@ static int compareToUnsafe(Object obj1, long o1, int l1, Object obj2, long o2, i
971967

972968
// The epilogue to cover the last (minLength % stride) elements.
973969
for (; i < minLength; i++) {
974-
int il = (UnsafeAccess.theUnsafe.getByte(obj1, o1 + i) & 0xFF);
975-
int ir = (UnsafeAccess.theUnsafe.getByte(obj2, o2 + i) & 0xFF);
970+
int il = (HBasePlatformDependent.getByte(obj1, o1 + i) & 0xFF);
971+
int ir = (HBasePlatformDependent.getByte(obj2, o2 + i) & 0xFF);
976972
if (il != ir) {
977973
return il - ir;
978974
}

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
@@ -43,13 +43,13 @@
4343
import org.apache.hadoop.hbase.Cell;
4444
import org.apache.hadoop.hbase.CellComparator;
4545
import org.apache.hadoop.hbase.KeyValue;
46+
import org.apache.hadoop.hbase.unsafe.HBasePlatformDependent;
4647
import org.apache.hadoop.io.RawComparator;
4748
import org.apache.hadoop.io.WritableComparator;
4849
import org.apache.hadoop.io.WritableUtils;
4950
import org.apache.yetus.audience.InterfaceAudience;
5051
import org.slf4j.Logger;
5152
import org.slf4j.LoggerFactory;
52-
import sun.misc.Unsafe;
5353

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

@@ -58,7 +58,6 @@
5858
* comparisons, hash code generation, manufacturing keys for HashMaps or
5959
* HashSets, and can be used as key in maps or trees.
6060
*/
61-
@SuppressWarnings("restriction")
6261
@InterfaceAudience.Public
6362
@edu.umd.cs.findbugs.annotations.SuppressWarnings(
6463
value="EQ_CHECK_FOR_OPERAND_NOT_COMPATIBLE_WITH_THIS",
@@ -129,7 +128,7 @@ public class Bytes implements Comparable<Bytes> {
129128
public static final int ESTIMATED_HEAP_TAX = 16;
130129

131130
@InterfaceAudience.Private
132-
static final boolean UNSAFE_UNALIGNED = UnsafeAvailChecker.unaligned();
131+
static final boolean UNSAFE_UNALIGNED = HBasePlatformDependent.unaligned();
133132

134133
/**
135134
* Returns length of the byte array, returning 0 if the array is null.
@@ -1487,21 +1486,17 @@ int putShort(byte[] bytes, int offset, short val) {
14871486

14881487
protected static final class UnsafeConverter extends Converter {
14891488

1490-
static final Unsafe theUnsafe;
1491-
14921489
public UnsafeConverter() {}
14931490

14941491
static {
1495-
if (UNSAFE_UNALIGNED) {
1496-
theUnsafe = UnsafeAccess.theUnsafe;
1497-
} else {
1492+
if (!UNSAFE_UNALIGNED) {
14981493
// It doesn't matter what we throw;
14991494
// it's swallowed in getBestComparer().
15001495
throw new Error();
15011496
}
15021497

15031498
// sanity check - this should never fail
1504-
if (theUnsafe.arrayIndexScale(byte[].class) != 1) {
1499+
if (HBasePlatformDependent.arrayIndexScale(byte[].class) != 1) {
15051500
throw new AssertionError();
15061501
}
15071502
}
@@ -1540,7 +1535,7 @@ int putShort(byte[] bytes, int offset, short val) {
15401535

15411536
/**
15421537
* Provides a lexicographical comparer implementation; either a Java
1543-
* implementation or a faster implementation based on {@link Unsafe}.
1538+
* implementation or a faster implementation based on {@code Unsafe}.
15441539
*
15451540
* <p>Uses reflection to gracefully fall back to the Java implementation if
15461541
* {@code Unsafe} isn't available.
@@ -1599,18 +1594,15 @@ public int compareTo(byte[] buffer1, int offset1, int length1,
15991594
enum UnsafeComparer implements Comparer<byte[]> {
16001595
INSTANCE;
16011596

1602-
static final Unsafe theUnsafe;
16031597
static {
1604-
if (UNSAFE_UNALIGNED) {
1605-
theUnsafe = UnsafeAccess.theUnsafe;
1606-
} else {
1598+
if (!UNSAFE_UNALIGNED) {
16071599
// It doesn't matter what we throw;
16081600
// it's swallowed in getBestComparer().
16091601
throw new Error();
16101602
}
16111603

16121604
// sanity check - this should never fail
1613-
if (theUnsafe.arrayIndexScale(byte[].class) != 1) {
1605+
if (HBasePlatformDependent.arrayIndexScale(byte[].class) != 1) {
16141606
throw new AssertionError();
16151607
}
16161608
}
@@ -1648,8 +1640,8 @@ public int compareTo(byte[] buffer1, int offset1, int length1,
16481640
* than 4 bytes even on 32-bit. On the other hand, it is substantially faster on 64-bit.
16491641
*/
16501642
for (i = 0; i < strideLimit; i += stride) {
1651-
long lw = theUnsafe.getLong(buffer1, offset1Adj + i);
1652-
long rw = theUnsafe.getLong(buffer2, offset2Adj + i);
1643+
long lw = HBasePlatformDependent.getLong(buffer1, offset1Adj + i);
1644+
long rw = HBasePlatformDependent.getLong(buffer2, offset2Adj + i);
16531645
if (lw != rw) {
16541646
if(!UnsafeAccess.LITTLE_ENDIAN) {
16551647
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;
@@ -185,13 +185,19 @@ private static final class HeaderSize {
185185
private byte a;
186186
}
187187

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

191197
@Override
192198
int headerSize() {
193199
try {
194-
return (int) UnsafeAccess.theUnsafe.objectFieldOffset(
200+
return (int) HBasePlatformDependent.objectFieldOffset(
195201
HeaderSize.class.getDeclaredField("a"));
196202
} catch (NoSuchFieldException | SecurityException e) {
197203
LOG.error(e.toString(), e);
@@ -201,29 +207,28 @@ int headerSize() {
201207

202208
@Override
203209
int arrayHeaderSize() {
204-
return UnsafeAccess.theUnsafe.arrayBaseOffset(byte[].class);
210+
return HBasePlatformDependent.arrayBaseOffset(byte[].class);
205211
}
206212

207213
@Override
208-
@SuppressWarnings("static-access")
209214
int oopSize() {
210215
// Unsafe.addressSize() returns 8, even with CompressedOops. This is how many bytes each
211216
// element is allocated in an Object[].
212-
return UnsafeAccess.theUnsafe.ARRAY_OBJECT_INDEX_SCALE;
217+
return ARRAY_OBJECT_INDEX_SCALE;
213218
}
214219

215220
@Override
216-
@SuppressWarnings("static-access")
217221
long sizeOfByteArray(int len) {
218-
return align(ARRAY + len * UnsafeAccess.theUnsafe.ARRAY_BYTE_INDEX_SCALE);
222+
return align(ARRAY + len * ARRAY_BYTE_INDEX_SCALE);
219223
}
220224
}
221225

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

0 commit comments

Comments
 (0)