2

My understanding is that the .dlls are loaded into java.library.path by a ClassLoader but where are they stored in memory after System.loadLibrary() and System.load() is called from a non-static procedure?

JVM Internal Architecture

amadib
  • 868
  • 14
  • 33

2 Answers2

5

When the System.loadLibrary() or System.load() functions are called, the ClassLoader for the current Java class is tasked with finding the requested DLL (and its dependencies) and informing the operating system about the libraries' locations. The ClassLoader itself does not perform any loading: this operation uses the Java Native Interface (JNI) libraries to communicate with the operating system and tells it where to look for the requested libraries.

When a DLL function is called, the function is loaded into the address space of the Java VM process and is executed there. This address space is a memory block given to a process by the operating system and is separate from the Java VM altogether. So, the answer to your question is that the Java VM simply uses its given address space to load DLL functions on-demand and executes them through the Java Native Interface.

Source: http://www.webbasedprogramming.com/Tricks-of-the-Java-Programming-Gurus/ch30.htm

Adil B
  • 14,635
  • 11
  • 60
  • 78
  • @Adil, your knowledge might help solving the problem which is stated here: [SO](https://stackoverflow.com/questions/51057895/system-load-generates-a-memory-failure-memmove-avx-unaligned-erms). The question relates to this answer: memory errors occurring when loading a shared library. – Yvus Jun 27 '18 at 09:37
1

'Non-static procedure' has nothing to do with it. Neither does the Java heap, and neither does Java, or your picture. The code is mapped into the process's code space and the data is mapped into the process's data space.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • 1
    I am interested in learning more about the "process data space". Do you know of a picture representation or diagram of where the dlls are loaded? What else is loaded into this space? How are size limitations specified? – amadib Apr 03 '14 at 00:20
  • Every process in an operating system has code space and data space. Too broad to answer here. – user207421 Apr 03 '14 at 01:59