0

I've been working with Java for a while and now I came around native methods and JNI. I think that Java without native functionality can just manage its memory (create classes and fields and pass data from one method to another, and declare primitive types), but all things like thread management, data I/O and its stuff and more similar things are done thanks to native methods.

Now I know that native methods (eg: thread start is declared as private native void start0(); which starts a new thread) have corresponding library which (I'm not sure but should) directly communicate with JVM instance or another system libraries (OpenGL communicates this way).

Is the above text true or is there something more going on? And additional question, where are these libraries (that API's native methods use) loaded? I know that you need to load a library with your custom native method. API does so or it is done by JVM automatically?

2
  • This is really too broad a topic for StackOverflow, and also borders on the "off-topic because it's a request for external resources". The best resource would be to read the JVM Specification. Commented Dec 24, 2015 at 22:10
  • Yeah, i know, but here are some people that have been maybe dealing with this longer. And i've also seen the specification. But there is explained how jvm is dealing with native methods rather than showing structure of libraries and java API Commented Dec 24, 2015 at 22:17

1 Answer 1

1

The HotSpot/OpenJDK JVM is a program written in C. As such the native methods are written in C and are loaded via shared libraries in the same manner that any other C program loads shared libraries.

In most cases, native calls to threads and IO are thin wrappers from systems calls i.e. the OS does all the real work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.