Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Java int[ ] array is implemented inside JVM?

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

like image 992
Bibrak Avatar asked Nov 24 '22 02:11

Bibrak


1 Answers

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.

like image 185
Bryce Avatar answered Nov 25 '22 15:11

Bryce