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

IGNITE-19652 Adapt to DirectByteBuffer ctor changes in JDK 21 #10764

Merged
merged 1 commit into from
Jun 15, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ public abstract class GridUnsafe {
/** {@link java.nio.Buffer#address} field offset. */
private static final long DIRECT_BUF_ADDR_OFF = bufferAddressOffset();

/** Whether to use newDirectByteBuffer(long, long) constructor */
private static final boolean IS_DIRECT_BUF_LONG_CAP = majorJavaVersion(jdkVersion()) >= 21;

/** Cleaner code for direct {@code java.nio.ByteBuffer}. */
private static final DirectBufferCleaner DIRECT_BUF_CLEANER =
majorJavaVersion(jdkVersion()) < 9
Expand Down Expand Up @@ -1641,7 +1644,8 @@ private static Method newDirectBufferMethod(Object nioAccessObj) {
try {
Class<?> cls = nioAccessObj.getClass();

Method mtd = cls.getMethod("newDirectByteBuffer", long.class, int.class, Object.class);
Method mtd = IS_DIRECT_BUF_LONG_CAP ? cls.getMethod("newDirectByteBuffer", long.class, long.class, Object.class) :
cls.getMethod("newDirectByteBuffer", long.class, int.class, Object.class);

mtd.setAccessible(true);

Expand All @@ -1660,7 +1664,6 @@ private static Method newDirectBufferMethod(Object nioAccessObj) {
return javaVer < 9 ? "sun" : "jdk.internal";
}


/**
* Creates and tests contructor for Direct ByteBuffer. Test is wrapping one-byte unsafe memory into a buffer.
*
Expand Down Expand Up @@ -1696,7 +1699,8 @@ private static Constructor<?> createNewDirectBufferCtor() {
try {
ByteBuffer buf = ByteBuffer.allocateDirect(1).order(NATIVE_BYTE_ORDER);

Constructor<?> ctor = buf.getClass().getDeclaredConstructor(long.class, int.class);
Constructor<?> ctor = IS_DIRECT_BUF_LONG_CAP ? buf.getClass().getDeclaredConstructor(long.class, long.class) :
buf.getClass().getDeclaredConstructor(long.class, int.class);

ctor.setAccessible(true);

Expand Down