JNI (Java Native Interface) is the standard way Java calls into C/C++ (and vice versa).

🔹 Concrete instances where this happens:

  1. Standard Java Library internals

    • Many parts of the JDK are wrappers over OS or C libraries.
    • Example:
      • java.lang.System.loadLibrary()
      • System.arraycopy() → implemented in C
      • java.io.FileDescriptor, Socket, Thread → all rely on OS calls via JNI
  2. JVM integrations

    • GC, JIT, threading, and monitoring tools use native hooks.
    • Example: JMX or JVMTI agents.
  3. Third-party libraries

    • OpenCV (image processing), TensorFlow (ML), SQLite (databases).
    • Java code calls into native DLLs / .so libraries for performance-critical work.
  4. Custom native methods

Developers can declare:

public class NativeExample {     
	public native void doSomething();     
	static { System.loadLibrary("nativeLib"); }
}

Implemented in C:

JNIEXPORT void JNICALL Java_NativeExample_doSomething(JNIEnv *env, jobject obj) {     
	// Native logic here 
}

👉 Whenever this happens, the native library might hold references to Java objects passed into it. These references are stored in JNI global/weak handle tables, and the GC treats them as roots until released.