davisusanibar commented on code in PR #13200:
URL: https://github.com/apache/arrow/pull/13200#discussion_r878351528
##########
java/dataset/src/main/java/org/apache/arrow/dataset/jni/DirectReservationListener.java:
##########
@@ -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
+ */
+ 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) {
Review Comment:
Deleted
##########
java/dataset/src/main/java/org/apache/arrow/dataset/jni/DirectReservationListener.java:
##########
@@ -87,11 +87,40 @@ 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;
+ Field fBaseOnJDKVersion;
Review Comment:
Changed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]