Results 1 to 7 of 7
  1. #1
    itsraghu is offline Member
    Join Date
    Jun 2010
    Posts
    4
    Rep Power
    0

    Default EXCEPTION_ACCESS_VIOLATION on Windows 7 64 bit OS

    Hi,
    I'm using Windows 7 64 bit OS. I'm trying to run a simple JNI program which works fine on Windows XP 32 bit OS. I get following exception in Windows 7.
    ================================================== ======================
    #
    # An unexpected error has been detected by HotSpot Virtual Machine:
    #
    # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x77e83100, pid=5472, tid=5508
    #
    # Java VM: Java HotSpot(TM) Client VM (1.5.0_11-b03 mixed mode, sharing)
    # Problematic frame:
    # C [ntdll.dll+0x33100]
    #

    --------------- T H R E A D ---------------

    Current thread (0x002e84d8): JavaThread "main" [_thread_in_native, id=5508]

    siginfo: ExceptionCode=0xc0000005, reading address 0x047b7112

    Registers:
    EAX=0x00100000, EBX=0x047f1278, ECX=0x00000000, EDX=0x000007ff
    ESP=0x000cf85c, EBP=0x000cf884, ESI=0x047b7110, EDI=0x001a0000
    EIP=0x77e83100, EFLAGS=0x00010246

    Top of Stack: (sp=0x000cf85c)
    0x000cf85c: 001a0000 047f1278 00000000 77e83af4
    0x000cf86c: 0000000a 000cf850 00000019 000cf96c
    0x000cf87c: 77ec041d 00fad29e 000cf97c 77e83407
    0x000cf88c: 001a0000 047f1278 000cf94c 00000000
    0x000cf89c: 7711e542 00000000 001a0000 047f1280
    0x000cf8ac: 047f3eb8 ffffffff 0000007f 00e30005
    0x000cf8bc: 00000005 000cf944 6d6476e0 00000001
    0x000cf8cc: 00000004 001a0000 002d2960 047f00c4

    Instructions: (pc=0x77e83100)
    0x77e830f0: f0 3b f3 74 17 8b 47 4c 8b c8 c1 e9 14 22 4f 52
    0x77e83100: 32 4e 02 f6 c1 01 0f 84 f5 10 00 00 83 7f 4c 00


    Stack: [0x00090000,0x000d0000), sp=0x000cf85c, free space=254k
    Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
    C [ntdll.dll+0x33100]
    C [ntdll.dll+0x33407]
    C [ntdll.dll+0x332f2]
    C [msvcrt.dll+0x98cd]

    Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
    j com.teamcenter.rac.cme.cmereport.JNITest.test(Ljav a/lang/String;)Z+0
    j com.teamcenter.rac.cme.cmereport.JNITest.main([Ljava/lang/String;)V+13
    v ~StubRoutines::call_stub

    --------------- P R O C E S S ---------------

    Java Threads: ( => current thread )
    0x00369f60 JavaThread "Low Memory Detector" daemon [_thread_blocked, id=5048]
    0x0039e150 JavaThread "CompilerThread0" daemon [_thread_blocked, id=2744]
    0x0036d588 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=1644]
    0x003695d8 JavaThread "Finalizer" daemon [_thread_blocked, id=6116]
    0x00368000 JavaThread "Reference Handler" daemon [_thread_blocked, id=3856]
    =>0x002e84d8 JavaThread "main" [_thread_in_native, id=5508]

    Other Threads:
    0x0035bdf0 VMThread [id=5260]
    0x0036d930 WatcherThread [id=3100]

    VM state:not at safepoint (normal execution)

    VM Mutex/Monitor currently owned by a thread: None

    Heap
    def new generation total 576K, used 109K [0x240e0000, 0x24180000, 0x245c0000)
    eden space 512K, 8% used [0x240e0000, 0x240eb450, 0x24160000)
    from space 64K, 100% used [0x24170000, 0x24180000, 0x24180000)
    to space 64K, 0% used [0x24160000, 0x24160000, 0x24170000)
    tenured generation total 1408K, used 138K [0x245c0000, 0x24720000, 0x280e0000)
    the space 1408K, 9% used [0x245c0000, 0x245e2b18, 0x245e2c00, 0x24720000)
    compacting perm gen total 8192K, used 18K [0x280e0000, 0x288e0000, 0x2c0e0000)
    the space 8192K, 0% used [0x280e0000, 0x280e4ac8, 0x280e4c00, 0x288e0000)
    ro space 8192K, 63% used [0x2c0e0000, 0x2c5ef230, 0x2c5ef400, 0x2c8e0000)
    rw space 12288K, 46% used [0x2c8e0000, 0x2ce81670, 0x2ce81800, 0x2d4e0000)

    Dynamic libraries:
    0x00400000 - 0x0040d000 C:\apps\Java\jre1.5.0_11\bin\javaw.exe
    0x77e50000 - 0x77fd0000 C:\Windows\SysWOW64\ntdll.dll
    0x76370000 - 0x76470000 C:\Windows\syswow64\kernel32.dll
    0x76500000 - 0x76546000 C:\Windows\syswow64\KERNELBASE.dll
    0x775c0000 - 0x77660000 C:\Windows\syswow64\ADVAPI32.dll
    0x771a0000 - 0x7724c000 C:\Windows\syswow64\msvcrt.dll
    0x75bb0000 - 0x75bc9000 C:\Windows\SysWOW64\sechost.dll
    0x75bd0000 - 0x75cc0000 C:\Windows\syswow64\RPCRT4.dll
    0x759c0000 - 0x75a20000 C:\Windows\syswow64\SspiCli.dll
    0x759b0000 - 0x759bc000 C:\Windows\syswow64\CRYPTBASE.dll
    0x77770000 - 0x77870000 C:\Windows\syswow64\USER32.dll
    0x76470000 - 0x76500000 C:\Windows\syswow64\GDI32.dll
    0x762f0000 - 0x762fa000 C:\Windows\syswow64\LPK.dll
    0x776a0000 - 0x7773d000 C:\Windows\syswow64\USP10.dll
    0x75d50000 - 0x75db0000 C:\Windows\system32\IMM32.DLL
    0x77950000 - 0x77a1c000 C:\Windows\syswow64\MSCTF.dll
    0x6d640000 - 0x6d7dd000 C:\apps\Java\jre1.5.0_11\bin\client\jvm.dll
    0x73480000 - 0x734b2000 C:\Windows\system32\WINMM.dll
    0x74af0000 - 0x74b3b000 C:\Windows\system32\apphelp.dll
    0x6d290000 - 0x6d298000 C:\apps\Java\jre1.5.0_11\bin\hpi.dll
    0x75db0000 - 0x75db5000 C:\Windows\syswow64\PSAPI.DLL
    0x6d610000 - 0x6d61c000 C:\apps\Java\jre1.5.0_11\bin\verify.dll
    0x6d310000 - 0x6d32d000 C:\apps\Java\jre1.5.0_11\bin\java.dll
    0x6d630000 - 0x6d63f000 C:\apps\Java\jre1.5.0_11\bin\zip.dll
    0x10000000 - 0x10006000 D:\Development\Adobe\FinalDlls\JNITest.dll
    0x74ce0000 - 0x74d7b000 C:\Windows\WinSxS\x86_microsoft.vc80.crt_1fc8b3b9a 1e18e3b_8.0.50727.4927_none_d08a205e442db5b5\MSVCR 80.dll

    VM Arguments:
    java_command: com.teamcenter.rac.cme.cmereport.JNITest
    Launcher Type: SUN_STANDARD

    Environment Variables:
    CLASSPATH=.;C:\Program Files (x86)\QuickTime\QTSystem\QTJava.zip
    PATH=C:\Windows\system32;C:\Windows;C:\Windows\Sys tem32\Wbem;C:\Windows\System32\WindowsPowerShell\v 1.0\;C:\Program Files\Dell\DW WLAN Card;C:\Program Files (x86)\QuickTime\QTSystem\;D:\Development\JTTK\bin\ lib;C:\Siemens\Tecnomatix\eMPower\;D:\Development\ Adobe\FinalDlls
    USERNAME=raghuvan
    OS=Windows_NT
    PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 23 Stepping 10, GenuineIntel



    --------------- S Y S T E M ---------------

    OS: Windows NT 6.1 Build 7600

    CPU:total 2 (cores per cpu 2, threads per core 1) family 6 model 7 stepping 10, cmov, cx8, fxsr, mmx, sse, sse2

    Memory: 4k page, physical 4181948k(2286876k free), swap 4194303k(4194303k free)

    vm_info: Java HotSpot(TM) Client VM (1.5.0_11-b03) for windows-x86, built on Dec 15 2006 01:16:12 by "java_re" with MS VC++ 6.0

    ====================================

    My Code:

    Java:
    ====
    public class JNITest
    {
    static
    {
    System.loadLibrary("JNITest");
    }

    public native boolean test(String message);

    public static void main(String[] argv)
    {
    boolean retVal = false;

    JNITest jnitest = new JNITest();
    retVal = jnitest.test("Testing JNI on Windows 7");
    System.out.println("Return value : " + retVal);
    }
    }
    --------------------------------------------------------------------------------------------------------------------------------

    C++:
    ====
    #include "JNITest.h"

    JNIEXPORT jboolean JNICALL Java_com_teamcenter_rac_cme_cmereport_JNITest_test
    (JNIEnv *env, jobject thisobject, jstring message)
    {
    printf("This is my C++ OR C code is getting invoked from JAVA\n");

    char* cMessage = _strdup(env->GetStringUTFChars(message, 0));
    env->ReleaseStringUTFChars(message, cMessage);

    bool success = false;

    printf("%s", cMessage);

    free(cMessage);
    return success;
    }

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,386
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by itsraghu View Post
    Java Code:
    	char* cMessage = _strdup(env->GetStringUTFChars(message, 0));
    	env->ReleaseStringUTFChars(message, cMessage);
    
    	bool success = false;
    
    	printf("%s", cMessage);
    
    	free(cMessage);
    	return success;
    }
    Don't do it that way; you're trying to release a copy of the C string created by the JVM and you're forgetting the original copy; do this instead:

    Java Code:
    	char* cMessage = env->GetStringUTFChars(message, 0);
    
                 if (cMessage == null)
                    return false;
    
    	printf("%s", cMessage);
    	env->ReleaseStringUTFChars(message, cMessage);
    
    	return success;
    kind regards,

    Jos

  3. #3
    itsraghu is offline Member
    Join Date
    Jun 2010
    Posts
    4
    Rep Power
    0

    Default

    Thanks Jos! It helped.

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,386
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by itsraghu View Post
    Thanks Jos! It helped.
    Good; did you get rid of the access violation?

    kind regards,

    Jos

  5. #5
    itsraghu is offline Member
    Join Date
    Jun 2010
    Posts
    4
    Rep Power
    0

    Default

    Yes, I do. But I wonder how my old approach worked fine on Windows XP 32 bit. Do you have any idea?

  6. #6
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,386
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by itsraghu View Post
    Yes, I do. But I wonder how my old approach worked fine on Windows XP 32 bit. Do you have any idea?
    Yup, on descent operating systems the ReleaseStringUTFChars( ... ) can be quite picky: it can only free what was allocated by the JVM and if you don't free it (with that method) you're leaking memory; but more important for now: you wanted it to free something it didn't allocate itself (strdup( ... ) did that). You were trying to make ReleaseStringUTFChars( ... ) free your copy (which it didn't allocate) while forgetting to free the original copy (which was allocated by the JVM). so remember ReleaseStringUTFChars( ... ) is not a general purpose substitute for C's free( ... ) or C++'s delete[].

    kind regards,

    Jos

  7. #7
    itsraghu is offline Member
    Join Date
    Jun 2010
    Posts
    4
    Rep Power
    0

Similar Threads

  1. EXCEPTION_ACCESS_VIOLATION (0xc0000005)
    By Marty in forum Eclipse
    Replies: 12
    Last Post: 03-21-2011, 12:55 PM
  2. EXCEPTION_ACCESS_VIOLATION (0xc0000005)
    By Ic e in forum Java Applets
    Replies: 2
    Last Post: 04-07-2010, 03:30 AM
  3. EXCEPTION_ACCESS_VIOLATION (0xc0000005)
    By sahumerio in forum Advanced Java
    Replies: 1
    Last Post: 03-16-2009, 02:27 PM
  4. Exception_access_violation
    By naveen.panc in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 11-15-2008, 12:27 AM
  5. EXCEPTION_ACCESS_VIOLATION (0xc0000005)
    By abhiN in forum Eclipse
    Replies: 1
    Last Post: 11-14-2008, 06:56 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •