Skip to content

move to JDK17 - #2827

Merged
karussell merged 3 commits into
masterfrom
move_to_jdk17
Oct 18, 2023
Merged

karussell merged 3 commits into
masterfrom
move_to_jdk17

Conversation

@karussell

@karussell karussell commented May 26, 2023 •

Copy link
Copy Markdown
Member

Currently we support Java down to JDK8. With this PR we move to the latest LTS JDK and make new APIs like this possible - see branch. (projects like lucene are already on JDK17)

Comment thread pom.xml Resolved
@otbutz

otbutz commented May 26, 2023

Copy link
Copy Markdown
Contributor

This could also be simplified if Java 17 is required:

public static void cleanMappedByteBuffer(final ByteBuffer buffer) {
// TODO avoid reflection on every call
try {
AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
@Override
public Object run() throws Exception {
if (jreIsMinimumJava9()) {
// >=JDK9 class sun.misc.Unsafe { void invokeCleaner(ByteBuffer buf) }
final Class<?> unsafeClass = Class.forName("sun.misc.Unsafe");
// fetch the unsafe instance and bind it to the virtual MethodHandle
final Field f = unsafeClass.getDeclaredField("theUnsafe");
f.setAccessible(true);
final Object theUnsafe = f.get(null);
final Method method = unsafeClass.getDeclaredMethod("invokeCleaner", ByteBuffer.class);
try {
method.invoke(theUnsafe, buffer);
return null;
} catch (Throwable t) {
throw new RuntimeException(t);
}
}
if (buffer.getClass().getSimpleName().equals("MappedByteBufferAdapter")) {
if (!Constants.ANDROID)
throw new RuntimeException("MappedByteBufferAdapter only supported for Android at the moment");
// For Android 4.1 call ((MappedByteBufferAdapter)buffer).free() see #914
Class<?> directByteBufferClass = Class.forName("java.nio.MappedByteBufferAdapter");
callBufferFree(buffer, directByteBufferClass);
} else {
// <=JDK8 class DirectByteBuffer { sun.misc.Cleaner cleaner(Buffer buf) }
// then call sun.misc.Cleaner.clean
final Class<?> directByteBufferClass = Class.forName("java.nio.DirectByteBuffer");
try {
final Method dbbCleanerMethod = directByteBufferClass.getMethod("cleaner");
dbbCleanerMethod.setAccessible(true);
// call: cleaner = ((DirectByteBuffer)buffer).cleaner()
final Object cleaner = dbbCleanerMethod.invoke(buffer);
if (cleaner != null) {
final Class<?> cleanerMethodReturnType = dbbCleanerMethod.getReturnType();
final Method cleanMethod = cleanerMethodReturnType.getDeclaredMethod("clean");
cleanMethod.setAccessible(true);
// call: ((sun.misc.Cleaner)cleaner).clean()
cleanMethod.invoke(cleaner);
}
} catch (NoSuchMethodException ex2) {
if (Constants.ANDROID)
// For Android 5.1.1 call ((DirectByteBuffer)buffer).free() see #933
callBufferFree(buffer, directByteBufferClass);
else
// ignore if method cleaner or clean is not available
LOGGER.warn("NoSuchMethodException | " + System.getProperty("java.version"), ex2);
}
}
return null;
}
});
} catch (PrivilegedActionException e) {
throw new RuntimeException("Unable to unmap the mapped buffer", e);
}
}

Co-authored-by: otbutz <[email protected]>
@karussell
karussell temporarily deployed to benchmarks May 26, 2023 08:46 — with GitHub Actions Inactive
@karussell
karussell temporarily deployed to benchmarks May 26, 2023 08:54 — with GitHub Actions Inactive
@otbutz

otbutz commented May 30, 2023

Copy link
Copy Markdown
Contributor

public static Set<Integer> asSet(int... values) {
Set<Integer> s = new HashSet<>();
for (int v : values) {
s.add(v);
}
return s;
}

-> Set.of(...)

@otbutz otbutz mentioned this pull request May 31, 2023
@otbutz

otbutz commented Jun 6, 2023

Copy link
Copy Markdown
Contributor

@karussell i also made some preparations in #2835 which are also viable while we still build using Java 8.

@karussell karussell added this to the 9.0 milestone Sep 7, 2023
@karussell
karussell merged commit c721fa3 into master Oct 18, 2023
@karussell
karussell deleted the move_to_jdk17 branch October 18, 2023 13:00
karussell added a commit that referenced this pull request Oct 18, 2023

This branch was previously deployed

1 inactive deployment
benchmarks — 95bc6d25 Deployed May 26, 2023 by karussell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants