简体   繁体   English

在Java JNA调用的dll中分配内存错误

[英]Allocate memory error in dll called by Java JNA

I try to integrate DLL using JNA in Java. 我尝试在Java中使用JNA集成DLL。 DLL allocates a lot of memory (~600MB). DLL分配大量内存(〜600MB)。 Library is compiled to 32 bit version, so I need to use 32 bit JVM. 库被编译为32位版本,因此我需要使用32位JVM。

I've got fatal error from JVM 我有来自JVM的致命错误

 EXCEPTION_UNCAUGHT_CXX_EXCEPTION (0xe06d7363) at pc=0x772bd928, pid=7976, tid=2444

with detailed information 详细信息

siginfo: ExceptionCode=0xe06d7363, ExceptionInformation=0x19930520 0x02dce184 0x6a3853d8 

and stack 并堆叠

Stack: [0x023d0000,0x02dd0000],  sp=0x02dce0d0,  free space=10232k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  [KERNELBASE.dll+0xbd928]
C  [MSVCR120D.dll+0x120b86]
C  [MSVCR120D.dll+0x12c2a1]
C  [face_analysis_libD.dll+0x1157dc]  operator new[]+0xc
C  [face_analysis_libD.dll+0xea995]  Mat<float>::setSize+0xa5
C  [face_analysis_libD.dll+0xe904e]  Recognizer::initialize+0x9e
C  [face_analysis_libD.dll+0xb2bf9]  Analyser::initializeAnalyser+0x1c9

Application is started with params 应用程序以参数开始

-Xmx1300m -Xms1300m -Xss10m -XX:MaxDirectMemorySize=3g -XX:+PrintHeapAtGC

Probably the problem is with some memory limits on JVM (library works great with C#). 问题可能出在JVM的某些内存限制上(库在C#上很好用)。 Maybe someone has similar problem and can help mi find solution how to run this library in 32 bit JVM. 也许有人遇到类似的问题,可以帮助我找到如何在32位JVM中运行该库的解决方案。

32bit applications are generally restricted to 2GB of virtual address space. 通常将32位应用程序限制为2 GB的虚拟地址空间。 Assuming you're on a 64bit windows this can be extended to 4GB if the binary has been built with the largeaddressaware flag. 假设您使用的是64位Windows,那么如果二进制文件是使用largeaddressaware标志构建的,则可以将其扩展到4GB。 I think 32bit java.exe has not, although I haven't tested it myself. 我认为32bit java.exe还没有,尽管我自己还没有测试过。

So if the JVM is already eating 1.3G for the heap, additional memory for thread stacks and other non-heap data structures then there is fairly little room left for the dll to make allocations. 因此,如果JVM已经为堆占用了1.3G内存,为线程堆栈和其他非堆数据结构提供了额外的内存,则dll几乎没有余地进行分配。 If it then needs to make a large contiguous allocation this is probably going to fail and throw a C++ exception. 如果然后需要进行大的连续分配,则可能会失败并抛出C ++异常。

Your options likely are: 您的选择可能是:

  • reduce heap size 减少堆大小
  • get a 64bit version of that library instead 获取该库的64位版本
  • see if marking the binary as largeaddressaware helps, there are tools to do that 看看将二进制文件标记为largeaddressaware是否有帮助,有一些工具可以做到这一点

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

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