My question is regarding mostly the standard, but input on how specific implementations deal with the issue is welcome too. So without further redo, my question is;
Also how is this usually implemented, through Java Native Interface?
Example; I'm reading a file, using java.io.FileReader. When invoking read
on this object the JVM will obviously call this function, in the correct class file, in the JCL, however will this code in the end rely on the JVM for calling, for instance the posix read
function? - or will the class file do this itself, through the use of JNI? (assuming a read
has to be done, that is the file isn't already in cache/memory)
I was hoping some real professional would answer this, preferrably someone who has actually worked on a JVM/JDK. Since so far, none of them seem to be online (or have seen your question, for that matter), I will have a go at explaining this.
The Java Class Library classes (found in the rt.jar
file of your JRE/JDK) are in fact pure java. They do contain a lot of JNI calls, though. If you look at the source of FileInputStream
for example, you will find stuff like this:
private native int readBytes(byte b[], int off, int len)
throws IOException;
public int read(byte b[])
throws IOException
{
return readBytes(b, 0, b.length);
}
So your guess was correct: the JCL does make extensive use of JNI. But who provides those native implementations? Simple: The JVM. And that is how the pieces fit together.
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