我写了个JNI程序,是java程序 -> C++ dll -> C# dll,出现了问题,代码:
Java程序:
public static void main(String[] args) {
       test t = new test();   //这是load C++ dll 的那个类
       t.link();
}C++中的程序:
#include "stdafx.h"
#include "jni.h"
#include "jni_md.h"
#include "TestJNI.h"
#include "test_tJNI.h"#using "Haiguantrain.dll"using namespace Haiguantrain;JNIEXPORT jboolean JNICALL Java_test_tJNI_link
  (JNIEnv *, jobject)
{
Encrypt ^e = gcnew Encrypt();   //我做的测试,是这条语句开始出问题,是内存问题么?gcnew是不
                                                                                       用手动释放内存的吧
bool b = e->GetEncrypt();
return true;
}Haiguantrain.dll文件代码(C#写的):
using System;
using System.Collections.Generic;  
using System.Text;  
using System.Runtime.InteropServices;
using System.Data;
using System.Data.SqlClient;
using test;namespace Haiguantrain
{    [Guid("BBD82859-46C2-43ce-8C25-C7825D40F230")]
    public interface IEncrypt      
    {          
        [DispId(1)]
        bool GetEncrypt();      
    }     
[Guid("372395D6-F810-4f6f-A355-843F05470DB3"),ClassInterface(ClassInterfaceType.None)]
        public class Encrypt : IEncrypt
        {
            public Encrypt() { }
            public bool GetEncrypt()
            {
                Console.WriteLine("Haiguantrain OK");
                return true;
            }
        }
}Tomcat错误日志:#
# A fatal error has been detected by the Java Runtime Environment:
#
#  Internal Error (0xe0434f4d), pid=700, tid=5248
#
# JRE version: 6.0_20-b02
# Java VM: Java HotSpot(TM) Client VM (16.3-b01 mixed mode, sharing windows-x86 )
# Problematic frame:
# C  [kernel32.dll+0x12afb]
#
# If you would like to submit a bug report, please visit:
#   http://java.sun.com/webapps/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#---------------  T H R E A D  ---------------Current thread (0x02dd6000):  JavaThread "http-8080-1" daemon [_thread_in_native, id=5248, stack(0x03ee0000,0x03f30000)]siginfo: ExceptionCode=0xe0434f4d, ExceptionInformation=0x80070002 
Stack: [0x03ee0000,0x03f30000],  sp=0x03f2ed2c,  free space=13b03f2e8a4k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  [kernel32.dll+0x12afb]
C  [mscorwks.dll+0x127065]
C  [mscorwks.dll+0x1272d0]
C  [mscorwks.dll+0x23129e]
C  [mscorjit.dll+0xef54]
C  [mscorjit.dll+0xebc0]
C  [mscorjit.dll+0xe8db]
C  [mscorjit.dll+0xe831]
C  [mscorwks.dll+0x2776f]
C  [mscorwks.dll+0x276e5]
C  [mscorwks.dll+0x2767a]
C  [mscorwks.dll+0x27516]Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j  test.tJNI.link()Z+0  //这是Java中的方法
j  test.test.link()Z+9
j  org.apache.jsp.page_jsp._jspService(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V+309
j  org.apache.jasper.runtime.HttpJspBase.service(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V+3
j  javax.servlet.http.HttpServlet.service(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;)V+30
j  org.apache.jasper.servlet.JspServletWrapper.service(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;Z)V+320
j  org.apache.jasper.servlet.JspServlet.serviceJspFile(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;Ljava/lang/String;Ljava/lang/Throwable;Z)V+126
j  org.apache.jasper.servlet.JspServlet.service(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V+347
j  javax.servlet.http.HttpServlet.service(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;)V+30
j  org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;)V+376
j  org.apache.catalina.core.ApplicationFilterChain.doFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;)V+101
j  org.apache.catalina.core.StandardWrapperValve.invoke(Lorg/apache/catalina/connector/Request;Lorg/apache/catalina/connector/Response;)V+804
j  org.apache.catalina.core.StandardContextValve.invoke(Lorg/apache/catalina/connector/Request;Lorg/apache/catalina/connector/Response;)V+365
j  org.apache.catalina.core.StandardHostValve.invoke(Lorg/apache/catalina/connector/Request;Lorg/apache/catalina/connector/Response;)V+64
j  org.apache.catalina.valves.ErrorReportValve.invoke(Lorg/apache/catalina/connector/Request;Lorg/apache/catalina/connector/Response;)V+6
j  org.apache.catalina.core.StandardEngineValve.invoke(Lorg/apache/catalina/connector/Request;Lorg/apache/catalina/connector/Response;)V+42
j  org.apache.catalina.connector.CoyoteAdapter.service(Lorg/apache/coyote/Request;Lorg/apache/coyote/Response;)V+158
j  org.apache.coyote.http11.Http11Processor.process(Ljava/net/Socket;)V+468
j  org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Ljava/net/Socket;)Z+82
j  org.apache.tomcat.util.net.JIoEndpoint$Worker.run()V+41
j  java.lang.Thread.run()V+11
v  ~StubRoutines::call_stub---------------  P R O C E S S  ---------------Java Threads: ( => current thread )
=>0x02dd6000 JavaThread "http-8080-1" daemon [_thread_in_native, id=5248, stack(0x03ee0000,0x03f30000)]VM state:not at safepoint (normal execution)VM Mutex/Monitor currently owned by a thread: NoneDynamic libraries:
0x00400000 - 0x0040f000  D:\JAP\Tomcat 6.0\bin\tomcat6.exe
0x7c920000 - 0x7c9b6000  C:\WINDOWS\system32\ntdll.dll
0x7c800000 - 0x7c91e000  C:\WINDOWS\system32\kernel32.dll
0x77d10000 - 0x77da0000  C:\WINDOWS\system32\USER32.dll
0x77ef0000 - 0x77f39000  C:\WINDOWS\system32\GDI32.dll
0x77da0000 - 0x77e49000  C:\WINDOWS\system32\ADVAPI32.dll
0x77e50000 - 0x77ee2000  C:\WINDOWS\system32\RPCRT4.dll
0x77fc0000 - 0x77fd1000  C:\WINDOWS\system32\Secur32.dll
0x77be0000 - 0x77c38000  C:\WINDOWS\system32\MSVCRT.dll
0x7d590000 - 0x7dd84000  C:\WINDOWS\system32\SHELL32.dll
0x77f40000 - 0x77fb6000  C:\WINDOWS\system32\SHLWAPI.dll
0x76300000 - 0x7631d000  C:\WINDOWS\system32\IMM32.DLL
0x62c20000 - 0x62c29000  C:\WINDOWS\system32\LPK.DLL
0x73fa0000 - 0x7400b000  C:\WINDOWS\system32\USP10.dll
0x77180000 - 0x77283000  C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83\comctl32.dll
0x5d170000 - 0x5d20a000  C:\WINDOWS\system32\comctl32.dll
0x6d800000 - 0x6da97000  C:\Program Files\Java\jre6\bin\client\jvm.dll
0x76b10000 - 0x76b3a000  C:\WINDOWS\system32\WINMM.dll
0x7c340000 - 0x7c396000  C:\WINDOWS\system32\MSVCR71.dll
0x6d7b0000 - 0x6d7bc000  C:\Program Files\Java\jre6\bin\verify.dll
0x6d330000 - 0x6d34f000  C:\Program Files\Java\jre6\bin\java.dll
0x6d290000 - 0x6d298000  C:\Program Files\Java\jre6\bin\hpi.dll
0x76bc0000 - 0x76bcb000  C:\WINDOWS\system32\PSAPI.DLL
0x6d7f0000 - 0x6d7ff000  C:\Program Files\Java\jre6\bin\zip.dll
0x6d560000 - 0x6d569000  C:\Program Files\Java\jre6\bin\management.dll
0x6d610000 - 0x6d623000  C:\Program Files\Java\jre6\bin\net.dll
0x71a20000 - 0x71a37000  C:\WINDOWS\system32\WS2_32.dll
0x71a10000 - 0x71a18000  C:\WINDOWS\system32\WS2HELP.dll
0x719c0000 - 0x719fe000  C:\WINDOWS\system32\mswsock.dll
0x60fd0000 - 0x61025000  C:\WINDOWS\system32\hnetcfg.dll
0x71a00000 - 0x71a08000  C:\WINDOWS\System32\wshtcpip.dll
0x76ef0000 - 0x76f17000  C:\WINDOWS\system32\DNSAPI.dll
0x76f80000 - 0x76f88000  C:\WINDOWS\System32\winrnr.dll
0x76f30000 - 0x76f5c000  C:\WINDOWS\system32\WLDAP32.dll
0x76f90000 - 0x76f96000  C:\WINDOWS\system32\rasadhlp.dll
0x10000000 - 0x1000c000  C:\WINDOWS\system32\TestJNI.dll
0x79000000 - 0x79045000  C:\WINDOWS\system32\mscoree.dll
0x78130000 - 0x781cb000  C:\WINDOWS\WinSxS\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.762_x-ww_6b128700\MSVCR80.dll
0x7c4c0000 - 0x7c53d000  C:\WINDOWS\WinSxS\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.762_x-ww_6b128700\msvcm80.dll
0x76990000 - 0x76acd000  C:\WINDOWS\system32\ole32.dll
0x79e70000 - 0x7a3d1000  C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll
0x790c0000 - 0x79ba6000  C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\mscorlib\7973c6dacc45774e961387e4761b56a6\mscorlib.ni.dll
0x79060000 - 0x790b3000  C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorjit.dll
0x68000000 - 0x68036000  C:\WINDOWS\system32\rsaenh.dllVM Arguments:
jvm_args: -Dcatalina.home=D:\JAP\Tomcat 6.0 -Dcatalina.base=D:\JAP\Tomcat 6.0 -Djava.endorsed.dirs=D:\JAP\Tomcat 6.0\endorsed -Djava.io.tmpdir=D:\JAP\Tomcat 6.0\temp -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file=D:\JAP\Tomcat 6.0\conf\logging.properties vfprintf -Xms100m -Xmx300m 
java_command: <unknown>
Launcher Type: genericEnvironment Variables:
PROCESSOR_IDENTIFIER=x86 Family 15 Model 4 Stepping 9, GenuineIntel---------------  S Y S T E M  ---------------OS: Windows XP Build 2600 Service Pack 3CPU:total 1 (1 cores per cpu, 1 threads per core) family 15 model 4 stepping 9, cmov, cx8, fxsr, mmx, sse, sse2, sse3Memory: 4k page, physical 1046052k(295128k free), swap 1685416k(953816k free)vm_info: Java HotSpot(TM) Client VM (16.3-b01) for windows-x86 JRE (1.6.0_20-b02), built on Apr 12 2010 13:52:23 by "java_re" with MS VC++ 7.1 (VS2003)time: Mon Aug 23 16:37:53 2010
elapsed time: 19 seconds

解决方案 »

  1.   

    在DOS环境下运行Java程序是没有问题的,但是放在Tomcat中,运行JSP页面Tomcat服务就会自动关闭
      

  2.   

    Google 到一个类似的问题,看上去像是跟内存管理有关系,不过也看不懂它说的啥。http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6386633
      

  3.   

    我的JNI程序也遇到类似的问题,请问楼主的问题怎么解决的 ?