Claudenw opened a new issue, #200:
URL: https://github.com/apache/datasketches-memory/issues/200
When running on Java version > 17 the NioBits method throws an exception.
This issue is noted in the `NioBits` code where indicates there are 2 methods
that in Java 18 and later take a `long` and not an `int`.
the issue is in this code block form NioBits:
```
static {
try {
isPageAligned = VirtualMachineMemory.getIsPageAligned();
maxDBBMemory = VirtualMachineMemory.getMaxDBBMemory();
NIO_BITS_CLASS = Class.forName("java.nio.Bits");
NIO_BITS_RESERVE_MEMORY_METHOD = NIO_BITS_CLASS
.getDeclaredMethod("reserveMemory", long.class, int.class); //JD16
requires (long, long)
NIO_BITS_RESERVE_MEMORY_METHOD.setAccessible(true);
NIO_BITS_UNRESERVE_MEMORY_METHOD = NIO_BITS_CLASS
.getDeclaredMethod("unreserveMemory", long.class, int.class);
//JD16 requires (long, long)
NIO_BITS_UNRESERVE_MEMORY_METHOD.setAccessible(true); final Field
countField = NIO_BITS_CLASS.getDeclaredField(NioBitsFields.COUNT_FIELD_NAME);
countField.setAccessible(true);
nioBitsCount = (AtomicLong) (countField.get(null)); final Field
reservedMemoryField =
NIO_BITS_CLASS.getDeclaredField(NioBitsFields.RESERVED_MEMORY_FIELD_NAME);
reservedMemoryField.setAccessible(true);
nioBitsReservedMemory = (AtomicLong) (reservedMemoryField.get(null));
final Field totalCapacityField =
NIO_BITS_CLASS.getDeclaredField(NioBitsFields.TOTAL_CAPACITY_FIELD_NAME);
totalCapacityField.setAccessible(true);
nioBitsTotalCapacity = (AtomicLong) (totalCapacityField.get(null));
} catch (final ClassNotFoundException | NoSuchMethodException |
IllegalAccessException
| IllegalArgumentException | SecurityException |
NoSuchFieldException e) {
throw new RuntimeException("Could not acquire java.nio.Bits class: " +
e.getClass());
}
}
```
if when `NIO_BITS_RESERVE_MEMORY_METHOD` and
`NIO_BITS_UNRESERVE_MEMORY_METHOD` were discovered we instead looked for the
function name without the parameters and accept a function definition that
takes either (long, long) or (long, int) I think this might work.
The current code base always passes an int as the second parameter so it
should work with the (long, long) version of the method as well as the (long,
int).
A solution something like:
```
static {
try {
isPageAligned = VirtualMachineMemory.getIsPageAligned();
maxDBBMemory = VirtualMachineMemory.getMaxDBBMemory();
NIO_BITS_CLASS = Class.forName("java.nio.Bits");
Method reserve = null;
Method unreserve = null;
try {
reserve = NIO_BITS_CLASS
.getDeclaredMethod("reserveMemory", long.class, long.class);
//JD16 requires (long, long)
unreserve = NIO_BITS_CLASS
.getDeclaredMethod("unreserveMemory", long.class, long.class);
//JD16 requires (long, long)
} catch (NoSuchMethodException expected) {
reserve = NIO_BITS_CLASS
.getDeclaredMethod("reserveMemory", long.class, int.class); //JD16
requires (long, long)
unreserve = NIO_BITS_CLASS
.getDeclaredMethod("unreserveMemory", long.class, int.class);
//JD16 requires (long, long)
}
NIO_BITS_RESERVE_MEMORY_METHOD = reserve;
NIO_BITS_RESERVE_MEMORY_METHOD.setAccessible(true);
NIO_BITS_UNRESERVE_MEMORY_METHOD = unreserve;
NIO_BITS_UNRESERVE_MEMORY_METHOD.setAccessible(true);
final Field countField =
NIO_BITS_CLASS.getDeclaredField(NioBitsFields.COUNT_FIELD_NAME);
countField.setAccessible(true);
nioBitsCount = (AtomicLong) (countField.get(null));
final Field reservedMemoryField =
NIO_BITS_CLASS.getDeclaredField(NioBitsFields.RESERVED_MEMORY_FIELD_NAME);
reservedMemoryField.setAccessible(true);
nioBitsReservedMemory = (AtomicLong) (reservedMemoryField.get(null));
final Field totalCapacityField =
NIO_BITS_CLASS.getDeclaredField(NioBitsFields.TOTAL_CAPACITY_FIELD_NAME);
totalCapacityField.setAccessible(true);
nioBitsTotalCapacity = (AtomicLong) (totalCapacityField.get(null));
} catch (final ClassNotFoundException | NoSuchMethodException |
IllegalAccessException
| IllegalArgumentException | SecurityException |
NoSuchFieldException e) {
throw new RuntimeException("Could not acquire java.nio.Bits class: " +
e.getClass());
}
}
```
Might work, though my quick experiment in trying to compile under Java 18
failed with a `cannot find symbol class Cleaner` error.
```
java --version
openjdk 18.0.2-ea 2022-07-19
OpenJDK Runtime Environment (build 18.0.2-ea+9-Ubuntu-222.04)
OpenJDK 64-Bit Server VM (build 18.0.2-ea+9-Ubuntu-222.04, mixed mode,
sharing)
```
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]