Menu

vm crash with multiple threads

Help
rr
2010-05-31
2013-04-29
  • rr

    rr - 2010-05-31

    Hi, I get the following vm crash if I use ghost4j in a multi threaded environment.

    #
    # An unexpected error has been detected by Java Runtime Environment:
    #
    #  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x10059fc5, pid=2372, tid=5208
    #
    # Java VM: Java HotSpot(TM) Client VM (11.0-b16 mixed mode, sharing windows-x86)
    # Problematic frame:
    # C 
    #
    # 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 (0x00396800):  JavaThread "main"

    siginfo: ExceptionCode=0xc0000005, reading address 0x00000000

    Registers:
    EAX=0x00000000, EBX=0x02df40a8, ECX=0x00000003, EDX=0x00000000
    ESP=0x003fee84, EBP=0x0000000b, ESI=0x00000000, EDI=0x102330e8
    EIP=0x10059fc5, EFLAGS=0x00010246

    Top of Stack: (sp=0x003fee84)
    0x003fee84:   003ff8b0 00396800 003ff7a8 00000010
    0x003fee94:   00000000 00000000 02db4d20 00000001
    0x003feea4:   10058700 02df40a8 02db4d24 0000000c
    0x003feeb4:   00000000 53235cb9 00000004 003ff008
    0x003feec4:   6d8618d5 003ff5f0 003feef4 6d861c98
    0x003feed4:   003ff5f0 003feef4 003feef4 02e5ce33
    0x003feee4:   00000010 003ff424 003ff5f0 000b0009
    0x003feef4:   6176616a 6e616c2f 74532f67 676e6972

    Instructions: (pc=0x10059fc5)
    0x10059fb5:   04 af bf e8 30 23 10 8b f0 b9 03 00 00 00 33 d2
    0x10059fc5:   f3 a6 0f 84 6b ff ff ff bf e0 30 23 10 8b f0 b9

    Stack: ,  sp=0x003fee84,  free space=315k
    Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)

    Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
    j  com.sun.jna.Function.invokeInt(I[Ljava/lang/Object;)I+0
    j  com.sun.jna.Function.invoke([Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object;+309
    j  com.sun.jna.Function.invoke(Ljava/lang/Class;[Ljava/lang/Object;Ljava/util/Map;)Ljava/lang/Object;+194
    j  com.sun.jna.Library$Handler.invoke(Ljava/lang/Object;Ljava/lang/reflect/Method;[Ljava/lang/Object;)Ljava/lang/Object;+344
    j  $Proxy0.gsapi_init_with_args(Lcom/sun/jna/Pointer;I[Ljava/lang/String;)I+27
    j  net.sf.ghost4j.Ghostscript.initialize([Ljava/lang/String;)V+219
    j  com.odc.pdf.renderer.ghost4j.Ghost4JRendererImpl.getPages([B)Ljava/util/Collection;+78
    j  com.odc.pdf.Main.main([Ljava/lang/String;)V+23
    v  ~StubRoutines::call_stub

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

    Java Threads: ( => current thread )
      0x02a61c00 JavaThread "Low Memory Detector" daemon
      0x02a5b400 JavaThread "CompilerThread0" daemon
      0x02a59c00 JavaThread "Attach Listener" daemon
      0x02a58c00 JavaThread "Signal Dispatcher" daemon
      0x02a53c00 JavaThread "Finalizer" daemon
      0x02a4f000 JavaThread "Reference Handler" daemon
    =>0x00396800 JavaThread "main"

    Other Threads:
      0x02a4d800 VMThread 
      0x02a63400 WatcherThread 

    VM state:not at safepoint (normal execution)

    VM Mutex/Monitor currently owned by a thread: None

    Heap
    def new generation   total 960K, used 370K [0x22970000, 0x22a70000, 0x22e50000)
      eden space 896K,  36% used [0x22970000, 0x229c20c0, 0x22a50000)
      from space 64K,  66% used [0x22a50000, 0x22a5aa88, 0x22a60000)
      to   space 64K,   0% used [0x22a60000, 0x22a60000, 0x22a70000)
    tenured generation   total 4096K, used 703K [0x22e50000, 0x23250000, 0x26970000)
       the space 4096K,  17% used [0x22e50000, 0x22efffa8, 0x22f00000, 0x23250000)
    compacting perm gen  total 12288K, used 569K [0x26970000, 0x27570000, 0x2a970000)
       the space 12288K,   4% used [0x26970000, 0x269fe698, 0x269fe800, 0x27570000)
        ro space 8192K,  67% used [0x2a970000, 0x2aed2d98, 0x2aed2e00, 0x2b170000)
        rw space 12288K,  53% used [0x2b170000, 0x2b7e0640, 0x2b7e0800, 0x2bd70000)

    VM Arguments:
    java_command: com.odc.pdf.Main
    Launcher Type: SUN_STANDARD

    Environment Variables:
    PATH=F:\Programme\Java\jdk1.6.0_20\jre6\bin\client;F:\Programme\Java\jdk1.6.0_20\jre6\bin;F:\Development\PHP_5.2\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;F:\DB\MySQL5.0\bin;C:\Programme\Gemeinsame Dateien\DivX Shared\;F:\Eigene Programme\Net\OpenVPN\bin
    USERNAME=Administrator
    OS=Windows_NT
    PROCESSOR_IDENTIFIER=x86 Family 6 Model 23 Stepping 6, GenuineIntel

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

    OS: Windows XP Build 2600 Service Pack 2

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

    Memory: 4k page, physical 1963484k(458452k free), swap 3902164k(1452628k free)

    vm_info: Java HotSpot(TM) Client VM (11.0-b16) for windows-x86 JRE (1.6.0_11-b03), built on Nov 10 2008 02:15:12 by "java_re" with MS VC++ 7.1

    time: Thu May 27 12:58:36 2010
    elapsed time: 0 seconds

    Here is the related part of my code which is invoked by multiple threads:
                //get Ghostscript instance
                Ghostscript gs = Ghostscript.getInstance();
               
    final File pdfTmpFile = File.createTempFile("ghost", ".tmp");
    FileUtils.writeByteArrayToFile(pdfTmpFile, pdfData);

            //prepare Ghostscript interpreter parameters with display device
            ArrayList<String> gsArgs = new ArrayList<String>() {
    private static final long serialVersionUID = -1501509042654572939L;

    {
            add("-dQUIET");
            add("-dNOPAUSE");
            add("-dBATCH");
            add("-dSAFER");
           
            add("-dGraphicsAlphaBits=4"); //Antialiasing settings, these make your output look the best. Use them.
            add("-dTextAlphaBits=4");
            add("-dDOINTERPOLATE");
           
            add("-r57×58"); //Resolution of output images
           
            add("-sDEVICE=display"); //to display
            add("-dDisplayHandle=0");
            add("-dDisplayFormat=16#804");

            add("-f"); //read from file
            add(pdfTmpFile.getAbsolutePath());
            }
            };

            //create display callback (capture display output pages as images)
            ImageWriterDisplayCallback displayCallback = new ImageWriterDisplayCallback();

            //set display callback
            gs.setDisplayCallback(displayCallback);
           
           
                gs.initialize(gsArgs.toArray(new String));
                gs.exit();
               
                //delete the temp pdf file.
                pdfTmpFile.delete();

     
  • zippy1978

    zippy1978 - 2010-05-31

    This is because Ghostscript API cannot run more than one instance per process.

    At the moment, the only way to solve this issue is to put your code in a synchronized block.

    However, I am currently working on release 0.4 that provides a multi-thread support (with a JVM fork mechanism) to handle multiple parallel GS API instances.

     
  • rr

    rr - 2010-06-01

    Ok, thank's for the fast answer. I will take a look at the next release.

     

Log in to post a comment.