How do I get a list of JNI libraries which are loaded?

前端 未结 7 1963
半阙折子戏
半阙折子戏 2020-11-28 07:54

Just what the subject says, is there a way in Java to get a list of all the JNI native libraries which have been loaded at any given time?

7条回答
  •  北海茫月
    2020-11-28 08:09

    as of Janurary 2019, the correct answer (from jdk9+ ondwards) is: There is no way anymore to get the List of loaded libraries.

    Although the mentioned field (loadedLibraryNames) still exists in hotspot-type VMs, it does not exist in others (like openj9). Also, if you try this on jdk9 onwards, you will get a warning on your terminal, that this access will be revoked in Java 12 onwards:

    WARNING: An illegal reflective access operation has occurred
    WARNING: Illegal reflective access by  (file:) to method|constructor
    WARNING: Please consider reporting this to the maintainers of 
    WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
    WARNING: All illegal access operations will be denied in a future release
    

    That said, * this method only works on a very specific JVM. do not rely on this, as someone may use another mature VM like openj9, azul, corretto, etc. * It won't work since Java 9 officially, but will crash your JVM (or yield unexpected output) starting from Java 12.

提交回复
热议问题