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

ARROW-16537: [Java] Patch dataset module testing failure with JSE11+ #13200

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
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 @@ -35,9 +35,9 @@ public class DirectReservationListener implements ReservationListener {
private DirectReservationListener() {
try {
final Class<?> classBits = Class.forName("java.nio.Bits");
methodReserve = classBits.getDeclaredMethod("reserveMemory", long.class, int.class);
methodReserve = this.getDeclaredMethodBaseOnJDKVersion(classBits, "reserveMemory");
methodReserve.setAccessible(true);
methodUnreserve = classBits.getDeclaredMethod("unreserveMemory", long.class, int.class);
methodUnreserve = this.getDeclaredMethodBaseOnJDKVersion(classBits, "unreserveMemory");
methodUnreserve.setAccessible(true);
} catch (Exception e) {
throw new RuntimeException(e);
Expand Down Expand Up @@ -87,11 +87,47 @@ public void unreserve(long size) {
public long getCurrentDirectMemReservation() {
try {
final Class<?> classBits = Class.forName("java.nio.Bits");
final Field f = classBits.getDeclaredField("reservedMemory");
final Field f = this.getDeclaredFieldBaseOnJDKVersion(classBits, "reservedMemory");
f.setAccessible(true);
return ((AtomicLong) f.get(null)).get();
} catch (Exception e) {
throw new RuntimeException(e);
}
}

/**
* To evaluate method on a class base on JDK version.
* @param classBits Object associated with the class with the given string name
* @param name Method needed to evaluate
* @return
davisusanibar marked this conversation as resolved.
Show resolved Hide resolved
*/
private Method getDeclaredMethodBaseOnJDKVersion(Class<?> classBits, String name) {
try {
return classBits.getDeclaredMethod(name, long.class, int.class);
} catch (NoSuchMethodException e) {
try {
return classBits.getDeclaredMethod(name, long.class, long.class);
} catch (NoSuchMethodException ex) {
throw new AssertionError(ex);
}
}
}

/**
* To evaluate field on a class base on JDK version.
* @param classBits Object associated with the class with the given string name
* @param name Field needed to evaluate
* @return
*/
private Field getDeclaredFieldBaseOnJDKVersion(Class<?> classBits, String name) {
lidavidm marked this conversation as resolved.
Show resolved Hide resolved
try {
return classBits.getDeclaredField(name);
} catch (NoSuchFieldException e) {
try {
return classBits.getDeclaredField("RESERVED_MEMORY");
} catch (NoSuchFieldException ex) {
throw new AssertionError(ex);
}
}
}
}