I am trying to understand how JVM internally implements an array of primitive type, like int []
My question is in two parts:
1 - Does it use a ByteBuffer internally? Where can I find the source code and then perhaps change it according to my needs (to make a modified JVM of my own).
2 - Is there any way to trick javac
to not use the build-in implementation of int []
but rather use an implementation provided by a library in lets say classpath -cp
? Is this possible and how?
My motivation is to declare this int []
in a memory outside of JVM (using allocateDirect()
) and access it outside from a native JNI code. This should avoid the memory copy overhead.
-B
Instead of using a Java IntBuffer or JNI, you can use sun.misc.Unsafe to allocate and access raw shared memory. This is Dangerous, but it is the absolute fastest way to access shared memory from Java and another process.
A helpful guide to the Unsafe methods is here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With