Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove JDK 1.8 specific functions from tikv-client #2761

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions tikv-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
</properties>

<dependencies>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
47 changes: 0 additions & 47 deletions tikv-client/src/main/java/com/pingcap/tikv/util/MemoryUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down