From 7a4b659470dd0915a484ed3b7fb00381716fc60d Mon Sep 17 00:00:00 2001 From: Fred Wulff Date: Sun, 20 Aug 2023 13:54:35 -0700 Subject: [PATCH] Remove JDK 1.8 specific functions from tikv-client --- tikv-client/pom.xml | 5 ++ .../tikv/columnar/TiBlockColumnVector.java | 11 ----- .../datatypes/AutoGrowByteBuffer.java | 4 -- .../com/pingcap/tikv/util/MemoryUtil.java | 47 ------------------- 4 files changed, 5 insertions(+), 62 deletions(-) diff --git a/tikv-client/pom.xml b/tikv-client/pom.xml index 1a60634658..93c0605f64 100644 --- a/tikv-client/pom.xml +++ b/tikv-client/pom.xml @@ -37,6 +37,11 @@ + + javax.annotation + javax.annotation-api + 1.3.2 + org.antlr antlr4-runtime diff --git a/tikv-client/src/main/java/com/pingcap/tikv/columnar/TiBlockColumnVector.java b/tikv-client/src/main/java/com/pingcap/tikv/columnar/TiBlockColumnVector.java index 6c60683fbb..abf0b8b9dd 100644 --- a/tikv-client/src/main/java/com/pingcap/tikv/columnar/TiBlockColumnVector.java +++ b/tikv-client/src/main/java/com/pingcap/tikv/columnar/TiBlockColumnVector.java @@ -101,17 +101,6 @@ private void fillEmptyOffsets() { */ @Override public void close() { - if (dataAddr != 0) { - MemoryUtil.free(data); - } - - if (offsetsAddr != 0) { - MemoryUtil.free(offsets); - } - - if (nullMapAddr != 0) { - MemoryUtil.free(nullMap); - } dataAddr = 0; offsetsAddr = 0; nullMapAddr = 0; diff --git a/tikv-client/src/main/java/com/pingcap/tikv/columnar/datatypes/AutoGrowByteBuffer.java b/tikv-client/src/main/java/com/pingcap/tikv/columnar/datatypes/AutoGrowByteBuffer.java index c6a372de58..0578f1ee19 100644 --- a/tikv-client/src/main/java/com/pingcap/tikv/columnar/datatypes/AutoGrowByteBuffer.java +++ b/tikv-client/src/main/java/com/pingcap/tikv/columnar/datatypes/AutoGrowByteBuffer.java @@ -51,10 +51,6 @@ private void beforeIncrease(int inc) { MemoryUtil.getAddress(buf), MemoryUtil.getAddress(newBuf), buf.position()); newBuf.position(buf.position()); - if (buf != initBuf) { - MemoryUtil.free(buf); - } - buf = newBuf; } } diff --git a/tikv-client/src/main/java/com/pingcap/tikv/util/MemoryUtil.java b/tikv-client/src/main/java/com/pingcap/tikv/util/MemoryUtil.java index 0226f8d21a..7628f97484 100644 --- a/tikv-client/src/main/java/com/pingcap/tikv/util/MemoryUtil.java +++ b/tikv-client/src/main/java/com/pingcap/tikv/util/MemoryUtil.java @@ -29,7 +29,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.tikv.shade.com.google.common.primitives.UnsignedLong; -import sun.misc.Cleaner; import sun.misc.Unsafe; import sun.nio.ch.DirectBuffer; @@ -173,16 +172,6 @@ public static void free(long addr) { unsafe.freeMemory(addr); } - /** Good manner to free a buffer before forget it. */ - public static void free(ByteBuffer buffer) { - if (buffer.isDirect()) { - Cleaner cleaner = ((DirectBuffer) buffer).cleaner(); - if (cleaner != null) { - cleaner.clean(); - } - } - } - public static void setByte(long address, byte b) { unsafe.putByte(address, b); } @@ -300,38 +289,6 @@ public static double getDouble(long address) { return unsafe.getDouble(address); } - public static ByteBuffer getByteBuffer(long address, int length, boolean autoFree) { - ByteBuffer instance = getHollowDirectByteBuffer(); - if (autoFree) { - Cleaner cleaner = Cleaner.create(instance, new Deallocator(address)); - setByteBuffer(instance, address, length, cleaner); - } else { - setByteBuffer(instance, address, length, null); - } - instance.order(ByteOrder.nativeOrder()); - return instance; - } - - public static ByteBuffer getHollowDirectByteBuffer() { - ByteBuffer instance; - try { - instance = (ByteBuffer) unsafe.allocateInstance(DIRECT_BYTE_BUFFER_CLASS); - } catch (InstantiationException e) { - throw new AssertionError(e); - } - instance.order(ByteOrder.nativeOrder()); - return instance; - } - - public static void setByteBuffer(ByteBuffer instance, long address, int length, Cleaner cleaner) { - unsafe.putLong(instance, DIRECT_BYTE_BUFFER_ADDRESS_OFFSET, address); - unsafe.putInt(instance, DIRECT_BYTE_BUFFER_CAPACITY_OFFSET, length); - unsafe.putInt(instance, DIRECT_BYTE_BUFFER_LIMIT_OFFSET, length); - if (cleaner != null) { - unsafe.putObject(instance, DIRECT_BYTE_BUFFER_CLEANER, cleaner); - } - } - public static Object getAttachment(ByteBuffer instance) { assert instance.getClass() == DIRECT_BYTE_BUFFER_CLASS; return unsafe.getObject(instance, DIRECT_BYTE_BUFFER_ATTACHMENT_OFFSET); @@ -363,10 +320,6 @@ public static ByteBuffer duplicateDirectByteBuffer(ByteBuffer source, ByteBuffer return hollowBuffer; } - public static ByteBuffer duplicateDirectByteBuffer(ByteBuffer source) { - return duplicateDirectByteBuffer(source, getHollowDirectByteBuffer()); - } - public static long getLongByByte(long address) { if (BIG_ENDIAN) { return (((long) unsafe.getByte(address)) << 56)