简体   繁体   English

通过JNI监视使用Java调用的C DLL的内存使用情况?

[英]Monitoring memory usage for a C DLL called with Java via JNI?

How can I monitor the memory being used by a native C DLL that is being called from Java via JNI? 如何监视通过JNI从Java调用的本机C DLL使用的内存? Using standard Java monitoring tools and options I can see the Java memory space, but I cannot view any memory used by the C DLL. 使用标准的Java监视工具和选项我可以看到Java内存空间,但我无法查看C DLL使用的任何内存。 Java is using ~70MB, but the task in the Task Manager shows 200Mb+, and I'd like to see what's in that 130MB extra if possible. Java正在使用~70MB,但任务管理器中的任务显示200Mb +,如果可能的话,我想看看130MB的额外内容。

You can monitor the native heap with counters in the performance montitor. 您可以使用性能监视器中的计数器监视本机堆。 (perfmon32) however it wont break it down for you on a per DLL basis, even jvm.dll will be included here. (perfmon32)然而,它不会在每个DLL的基础上为你分解,甚至jvm.dll将包含在这里。

Most profiling tools out there can attach to a process and capture and track memory allocations and deallocations. 大多数分析工具可以附加到进程并捕获和跟踪内存分配和释放。 This allows them to speculate where leaks are. 这允许他们推测泄漏的位置。 One pretty good one i found when recently trying to track down memory leaks in native code which was called from Java is Memory Validator 我最近在尝试跟踪从Java调用的本机代码中的内存泄漏时发现的一个非常好的内存是Memory Validator

Have you tried using Process Viewer to dig deeper. 您是否尝试过使用Process Viewer深入挖掘。

If you have the source to the DLL you could rebuild with debug libraries and possibly a mem allocation tracker - and debug using visual C++ debugger (you'll need to tell it to use the java application). 如果您有DLL的源代码,您可以使用调试库和可能的内存分配跟踪器进行重建 - 并使用Visual C ++调试器进行调试(您需要告诉它使用java应用程序)。

If you haven't got the source - then the options are limited. 如果您还没有来源 - 则选项有限。

I believe even doing this inside the C DLL would not be very easy. 我相信即使在C DLL中执行此操作也不是很容易。

As far as I understand the Standard Java Monitoring tools gather information by querying the Virtual Machine, thus even though that memory is in the same process unless the virtual machine knows how to inspect your dynamically linked library, it won't be able to see anything. 据我所知,标准Java监控工具通过查询虚拟机来收集信息,因此即使该内存处于同一进程中,除非虚拟机知道如何检查动态链接库,否则它将无法看到任何内容。 I believe you would need to use an external tool or make somewhat massive modifications to the DLL in order to track its memory usage. 我相信您需要使用外部工具或对DLL进行一些大量修改才能跟踪其内存使用情况。

Well, since the DLL isn't really part of the Java heap, I think the most accurate reading would be to write a small profiling program (either a small a Java/JNI program or C++/C#, etc) to import and use the DLL in a similar way to your application and do NOTHING ELSE - just use the DLL as you do - the resulting memory profile of this profiling app should be a good approximation to the memory profile of the DLL. 好吧,既然DLL实际上不是Java堆的一部分,我认为最准确的解读是编写一个小的分析程序(小型Java / JNI程序或C ++ / C#等)来导入和使用DLL与您的应用程序的方式类似,并且不做任何操作 - 只需像您一样使用DLL - 此配置文件应用程序的结果内存配置文件应该是DLL的内存配置文件的良好近似值。

You should also test to see if there's a static or dynamic memory shape of the DLL - take memory measurments directly before and after the DLL is loaded to see if there's a one-time hit of ~130MB, or if the memory slowly goes up over time. 您还应该测试是否存在DLL的静态动态内存形状 - 在加载DLL之前和之后直接进行内存测量,以查看是否存在~130MB的一次性命中,或者内存是否缓慢上升时间。

On Solaris / Linux, I've heard that the Sun Studio Collector / Analyzer is a good tool for this, but you're stuck in DLL-land (or DLL hell, as it were) 在Solaris / Linux上,我听说Sun Studio Collector / Analyzer是一个很好的工具,但是你被困在DLL-land(或DLL地狱,就像它)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM