<tfoot id='CxbLn'></tfoot><legend id='CxbLn'><style id='CxbLn'><dir id='CxbLn'><q id='CxbLn'></q></dir></style></legend>

    1. <i id='CxbLn'><tr id='CxbLn'><dt id='CxbLn'><q id='CxbLn'><span id='CxbLn'><b id='CxbLn'><form id='CxbLn'><ins id='CxbLn'></ins><ul id='CxbLn'></ul><sub id='CxbLn'></sub></form><legend id='CxbLn'></legend><bdo id='CxbLn'><pre id='CxbLn'><center id='CxbLn'></center></pre></bdo></b><th id='CxbLn'></th></span></q></dt></tr></i><div id='CxbLn'><tfoot id='CxbLn'></tfoot><dl id='CxbLn'><fieldset id='CxbLn'></fieldset></dl></div>

      <small id='CxbLn'></small><noframes id='CxbLn'>

        <bdo id='CxbLn'></bdo><ul id='CxbLn'></ul>

    2. 在未捕获的异常上生成 Java 堆转储

      Generate Java Heap Dump on uncaught Exception(在未捕获的异常上生成 Java 堆转储)
    3. <legend id='4Csiw'><style id='4Csiw'><dir id='4Csiw'><q id='4Csiw'></q></dir></style></legend>

          <tfoot id='4Csiw'></tfoot>
          <i id='4Csiw'><tr id='4Csiw'><dt id='4Csiw'><q id='4Csiw'><span id='4Csiw'><b id='4Csiw'><form id='4Csiw'><ins id='4Csiw'></ins><ul id='4Csiw'></ul><sub id='4Csiw'></sub></form><legend id='4Csiw'></legend><bdo id='4Csiw'><pre id='4Csiw'><center id='4Csiw'></center></pre></bdo></b><th id='4Csiw'></th></span></q></dt></tr></i><div id='4Csiw'><tfoot id='4Csiw'></tfoot><dl id='4Csiw'><fieldset id='4Csiw'></fieldset></dl></div>
            <tbody id='4Csiw'></tbody>

              <bdo id='4Csiw'></bdo><ul id='4Csiw'></ul>
              1. <small id='4Csiw'></small><noframes id='4Csiw'>

                本文介绍了在未捕获的异常上生成 Java 堆转储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                当触发未捕获的异常时,我尝试生成堆转储.我尝试使用 jmap,但是因为当异常发生时进程已经完成,所以这是不可能的.

                I try to generate a Heap Dump when a uncaught exception is fired. I tried using jmap, but because the process is finished when the exception happens this is not possible.

                使用 UncaughtExceptionHandler 也不是选项,因为我只有被执行程序的二进制文件.

                Using a UncaughtExceptionHandler is no option either, because I only have the binaries of the programs that is executed.

                谁能帮帮我?

                通过命令行或类似方法可以使用该技术很重要,因为我需要将其自动化.使用 GUI 是不行的

                It is important that the technique is available through a command line or similar, because I need to automated this. Using a GUI is no option

                推荐答案

                这可以通过 JVMTI 代理将监听 VMDeath 事件,然后使用 JMM 接口 启动堆转储.

                This can be achieved with JVMTI agent that will listen to VMDeath event and then use JMM interface to initiate Heap Dump.

                以下是此类 JVMTI 代理的示例源代码:

                Here is a sample source code of such JVMTI agent:

                #include <jvmti.h>
                #include <string.h>
                #include <stdio.h>
                #include "jmm.h"
                
                JNIEXPORT void* JNICALL JVM_GetManagement(jint version);
                
                void JNICALL VMDeath(jvmtiEnv* jvmti, JNIEnv* jni) {
                    JmmInterface* jmm = (JmmInterface*) JVM_GetManagement(JMM_VERSION_1_0);
                    if (jmm == NULL) {
                        printf("Sorry, JMM is not supported
                ");
                    } else {
                        jstring path = (*jni)->NewStringUTF(jni, "dump.hprof");
                        jmm->DumpHeap0(jni, path, JNI_TRUE);
                        printf("Heap dumped
                ");
                    }
                }
                
                JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM* vm, char* options, void* reserved) {
                    jvmtiEnv* jvmti;
                    (*vm)->GetEnv(vm, (void**)&jvmti, JVMTI_VERSION_1_0);
                
                    jvmtiEventCallbacks callbacks;
                    memset(&callbacks, 0, sizeof(callbacks));
                    callbacks.VMDeath = VMDeath;
                    (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks));
                    (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, JVMTI_EVENT_VM_DEATH, NULL);
                
                    return 0;
                }
                

                将其编译到共享库 (libdump.so) 后,使用 -agentpath 选项运行 Java:

                After you've compiled it into the shared library (libdump.so) run Java with -agentpath option:

                java -agentpath:/path/to/libdump.so MainClass
                

                如果您希望处理未捕获的异常而不是等待 VMDeath,您可以使用类似的技术为异常事件安装回调.查看此处的示例.

                If you wish to handle uncaught exceptions instead of waiting for VMDeath, you may use similar technique to install callback for Exception event. Look here for an example.

                这篇关于在未捕获的异常上生成 Java 堆转储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Bytecode features not available in the Java language(Java 语言中不可用的字节码功能)
                ClassCastException because of classloaders?(ClassCastException 因为类加载器?)
                How can I add a Javaagent to a JVM without stopping the JVM?(如何在不停止 JVM 的情况下将 Javaagent 添加到 JVM?)
                Cannot load 64-bit SWT libraries on 32-bit JVM ( replacing SWT file )(无法在 32 位 JVM 上加载 64 位 SWT 库(替换 SWT 文件))
                Encourage the JVM to GC rather than grow the heap?(鼓励 JVM 进行 GC 而不是增加堆?)
                Why a sawtooth shaped graph?(为什么是锯齿形图形?)
                  • <bdo id='3tzTc'></bdo><ul id='3tzTc'></ul>
                    <legend id='3tzTc'><style id='3tzTc'><dir id='3tzTc'><q id='3tzTc'></q></dir></style></legend>
                        <i id='3tzTc'><tr id='3tzTc'><dt id='3tzTc'><q id='3tzTc'><span id='3tzTc'><b id='3tzTc'><form id='3tzTc'><ins id='3tzTc'></ins><ul id='3tzTc'></ul><sub id='3tzTc'></sub></form><legend id='3tzTc'></legend><bdo id='3tzTc'><pre id='3tzTc'><center id='3tzTc'></center></pre></bdo></b><th id='3tzTc'></th></span></q></dt></tr></i><div id='3tzTc'><tfoot id='3tzTc'></tfoot><dl id='3tzTc'><fieldset id='3tzTc'></fieldset></dl></div>

                      • <tfoot id='3tzTc'></tfoot>

                        <small id='3tzTc'></small><noframes id='3tzTc'>

                            <tbody id='3tzTc'></tbody>