How do I debug Segfaults occurring in the JVM when it runs my code?

后端 未结 5 1008
青春惊慌失措
青春惊慌失措 2020-12-14 02:46

My Java application has started to crash regularly with a SIGSEGV and a dump of stack data and a load of information in a text file.

I have debugged C programs in gd

相关标签:
5条回答
  • 2020-12-14 03:21

    I found a good list at http://www.oracle.com/technetwork/java/javase/crashes-137240.html. As I'm getting the crashes during GC, I'll try switching between garbage collectors.

    I tried switching between the serial and the parallel GC (the latter being the default on a 64-bit Linux server), this only changed the error message accordingly.

    Reducing the max heap size from 16G to 10G after a fresh analysis in the profiler (which gave me a heap usage flattening out at 8G) did lead to a significantly lower "Virtual Memory" footprint (16G instead of 60), but I don't even know what that means, and The Internet says, it doesn't matter.

    Currently, the JVM is running in client mode (using the -client startup option thus overriding the default of -server). So far, there's no crash, but the performance impact seems rather large.

    0 讨论(0)
  • 2020-12-14 03:33

    I'm assuming I'm not looking at a JVM bug here. Other Java programs run just fine, and the JVM from Sun is probably more stable than my code.

    I don't think you should make that assumption. Without using JNI, you should not be able to write Java code that causes a SIGSEGV (although we know it happens). My point is, when it happens, it is either a bug in the JVM (not unheard of) or a bug in some JNI code. If you don't have any JNI in your own code, that doesn't mean that you aren't using some library that is, so look for that. When I have seen this kind of problem before, it was in an image manipulation library. If the culprit isn't in your own JNI code, you probably won't be able to 'fix' the bug, but you may still be able to work around it.

    First, you should get an alternate JVM on the same platform and try to reproduce it. You can try one of these alternatives.

    If you cannot reproduce it, it likely is a JVM bug. From that, you can either mandate a particular JVM or search the bug database, using what you know about how to reproduce it, and maybe get suggested workarounds. (Even if you can reproduce it, many JVM implementations are just tweaks on Oracle's Hotspot implementation, so it might still be a JVM bug.)

    If you can reproduce it with an alternative JVM, the fault might be that you have some JNI bug. Look at what libraries you are using and what native calls they might be making. Sometimes there are alternative "pure Java" configurations or jar files for the same library or alternative libraries that do almost the same thing.

    Good luck!

    0 讨论(0)
  • 2020-12-14 03:37

    If you have a corefile you could try running jstack on it, which would give you something a little more comprehensible - see http://download.oracle.com/javase/6/docs/technotes/tools/share/jstack.html, although if it's a bug in the gc thread it may not be all that helpful.

    0 讨论(0)
  • 2020-12-14 03:38

    Try to check whether c program carsh which have caused java crash.use valgrind to know invalid and also cross check stack size.

    0 讨论(0)
  • 2020-12-14 03:44

    The following will almost certainly be useless unless you have native code. However, here goes.

    1. Start java program in java debugger, with breakpoint well before possible sigsegv.
    2. Use the ps command to obtain the processid of java.
    3. gdb /usr/lib/jvm/sun-java6/bin/java processid
    4. make sure that the gdb 'handle' command is set to stop on SIGSEGV
    5. continue in the java debugger from the breakpoint.
    6. wait for explosion.
    7. Use gdb to investigate

    If you've really managed to make the JVM take a sigsegv without any native code of your own, you are very unlikely to make any sense of what you will see next, and the best you can do is push a test case onto a bug report.

    0 讨论(0)
提交回复
热议问题