性能问答>Instrumentation.redefineClasses热更代码导致jvm crash>
2回复
4年前

Instrumentation.redefineClasses热更代码导致jvm crash



通过Instrumentation.redefineClasses更新字节码导致进程crash,三个class,其他两个成功了,有一个直接导致crash。
具体原因不确定,看了jvm源码,逻辑极简单,所以无法确认问题点

void MemberNameTable::adjust_method_entries(Method** old_methods, Method** new_methods,
                                            int methods_length, bool *trace_name_printed) {
  assert(SafepointSynchronize::is_at_safepoint(), "only called at safepoint");
  // search the MemberNameTable for uses of either obsolete or EMCP methods
  for (int j = 0; j < methods_length; j++) {
    Method* old_method = old_methods[j];
    Method* new_method = new_methods[j];
    oop mem_name = find_member_name_by_method(old_method);
    if (mem_name != NULL) {
      java_lang_invoke_MemberName::adjust_vmtarget(mem_name, new_method);

      if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
        if (!(*trace_name_printed)) {
          // RC_TRACE_MESG macro has an embedded ResourceMark
          RC_TRACE_MESG(("adjust: name=%s",
                         old_method->method_holder()->external_name()));
          *trace_name_printed = true;
        }
        // RC_TRACE macro has an embedded ResourceMark
        RC_TRACE(0x00400000, ("MemberName method update: %s(%s)",
                              new_method->name()->as_C_string(),
                              new_method->signature()->as_C_string()));
      }
    }
  }
}

官网上找到的类似redefine问题https://bugs.java.com/bugdatabase/view_bug.do?bug_id=8076110

crash日志如下

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007fc6c666b321, pid=4831, tid=0x00007fc6837b0700
#
# JRE version: Java(TM) SE Runtime Environment (8.0_101-b13) (build 1.8.0_101-b13)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.101-b13 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# V  [libjvm.so+0x8c5321]  MemberNameTable::adjust_method_entries(InstanceKlass*, bool*)+0x91
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
#

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

Current thread (0x00007fc6c00ee000):  VMThread [stack: 0x00007fc6836b0000,0x00007fc6837b1000] [id=4844]

siginfo: si_signo: 11 (SIGSEGV), si_code: 128 (SI_KERNEL), si_addr: 0x0000000000000000

Registers:
RAX=0x0a09090a0909640a, RBX=0x00000000b34481a0, RCX=0x00000001003b7c28, RDX=0x00007fc6837af828
RSP=0x00007fc6837af5d0, RBP=0x00007fc6837af670, RSI=0x00000001003b7c28, RDI=0x00000001003b7c28
R8 =0x0000000000000003, R9 =0x0000000000000001, R10=0x0000000000000000, R11=0x0000000000000002
R12=0x00007fc68072bfe8, R13=0x0000000000000000, R14=0x0000000000000000, R15=0x00007fc5d405b500
RIP=0x00007fc6c666b321, EFLAGS=0x0000000000010202, CSGSFS=0x0000000000000033, ERR=0x0000000000000000
  TRAPNO=0x000000000000000d

Top of Stack: (sp=0x00007fc6837af5d0)
0x00007fc6837af5d0:   00007fc6741b01f0 00007fc6837af828
0x00007fc6837af5e0:   00000001003b7c28 00007fc6c00ee350
0x00007fc6837af5f0:   00007fc683ddb0b8 00007fc6c00ee000
0x00007fc6837af600:   00007fc6c00ee478 0000000000000006
0x00007fc6837af610:   00007fc6837af650 0000000100000028
0x00007fc6837af620:   00007fc6837af810 00007fc6c009d210
0x00007fc6837af630:   0000000000000001 00007fc6c00ee000
0x00007fc6837af640:   00007fc6837af670 0000000000000000
0x00007fc6837af650:   0000000000000000 0000000000000000
0x00007fc6837af660:   0000000000000001 00007fc6c00ee000
0x00007fc6837af670:   00007fc6837af860 00007fc6c6555039
0x00007fc6837af680:   00007fc6c6643780 0000000000000020
0x00007fc6837af690:   00007fc6837af7b0 00007fc6837af828
0x00007fc6837af6a0:   00007fc6837af740 00007fc6837af7e0
0x00007fc6837af6b0:   00007fc6837af780 00007fc6c00ee000
0x00007fc6837af6c0:   0000000100f5bbd8 00007fc59d7be310
0x00007fc6837af6d0:   00000000aa98ee28 00000001003b7c28
0x00007fc6837af6e0:   0000000000007fd8 00007fc6741b0150
0x00007fc6837af6f0:   000000079ea54c28 00007fc6741b0090
0x00007fc6837af700:   00007fc6837af7b0 0000000000000001
0x00007fc6837af710:   00007fc6837af730 00007fc6c665312a
0x00007fc6837af720:   00000001002b0a70 00007fc59b41d070
0x00007fc6837af730:   0000000000000007 00007fc6c668dea4
0x00007fc6837af740:   00007fc6c00ee000 00007fc6c00ee350
0x00007fc6837af750:   00007fc6c00ee390 00007fc6c00ee3a0
0x00007fc6837af760:   00007fc6c00ee478 00000000000000d8
0x00007fc6837af770:   00007fc6837af880 00007fc5d901ffff
0x00007fc6837af780:   0000000000000000 00007fc6b7d61500
0x00007fc6837af790:   0000000000000000 00007fc6b7d61500
0x00007fc6837af7a0:   00007fc6741b0190 0000000000000007
0x00007fc6837af7b0:   00007fc6c6d0b5b0 00007fc6837af740
0x00007fc6837af7c0:   0000000000000000 0000000000000c00 

Instructions: (pc=0x00007fc6c666b321)
0x00007fc6c666b301:   49 89 c4 74 ca 8b 40 20 a9 00 00 01 00 74 c0 66
0x00007fc6c666b311:   85 c0 78 bb 49 8b 44 24 08 48 8b bd 70 ff ff ff
0x00007fc6c666b321:   0f b7 70 2e e8 56 85 d7 ff 48 89 df 48 89 c6 48
0x00007fc6c666b331:   89 85 78 ff ff ff e8 f4 09 dd ff 48 8b 05 c5 b0 

Register to memory mapping:

RAX=0x0a09090a0909640a is an unknown value
RBX=0x00000000b34481a0 is an oop
java.lang.invoke.MemberName 
 - klass: 'java/lang/invoke/MemberName'
RCX=0x00000001003b7c28 is pointing into metadata
RDX=0x00007fc6837af828 is an unknown value
RSP=0x00007fc6837af5d0 is an unknown value
RBP=0x00007fc6837af670 is an unknown value
RSI=0x00000001003b7c28 is pointing into metadata
RDI=0x00000001003b7c28 is pointing into metadata
R8 =0x0000000000000003 is an unknown value
R9 =0x0000000000000001 is an unknown value
R10=0x0000000000000000 is an unknown value
R11=0x0000000000000002 is an unknown value
R12=0x00007fc68072bfe8 is pointing into metadata
R13=0x0000000000000000 is an unknown value
R14=0x0000000000000000 is an unknown value
R15=0x00007fc5d405b500 is an unknown value


Stack: [0x00007fc6836b0000,0x00007fc6837b1000],  sp=0x00007fc6837af5d0,  free space=1021k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V  [libjvm.so+0x8c5321]  MemberNameTable::adjust_method_entries(InstanceKlass*, bool*)+0x91
V  [libjvm.so+0x7af039]  VM_RedefineClasses::redefine_single_class(_jclass*, Klass*, Thread*)+0x949
V  [libjvm.so+0x7af54b]  VM_RedefineClasses::doit()+0xab
V  [libjvm.so+0xacd405]  VM_Operation::evaluate()+0x55
V  [libjvm.so+0xacb7da]  VMThread::evaluate_operation(VM_Operation*)+0xba
V  [libjvm.so+0xacbb5e]  VMThread::loop()+0x1ce
V  [libjvm.so+0xacbfd0]  VMThread::run()+0x70
V  [libjvm.so+0x924698]  java_start(Thread*)+0x108

VM_Operation (0x00007fc59d7be310): RedefineClasses, mode: safepoint, requested by thread 0x00007fc664001800

。。。
。。。
Events (10 events):
Event: 72628.683 Thread 0x00007fc608019000 Thread exited: 0x00007fc608019000
Event: 72629.248 Executing VM operation: RevokeBias
Event: 72629.248 Executing VM operation: RevokeBias done
Event: 72630.807 Executing VM operation: RedefineClasses
Event: 72631.004 Executing VM operation: RedefineClasses done
Event: 72631.010 Executing VM operation: RedefineClasses
Event: 72631.191 Executing VM operation: RedefineClasses done
Event: 72631.196 Executing VM operation: RedefineClasses
Event: 72631.387 Executing VM operation: RedefineClasses done
Event: 72631.389 Executing VM operation: RedefineClasses
4222 阅读
请先登录,查看2条精彩评论吧
快去登录吧,你将获得
  • 浏览更多精彩评论
  • 和开发者讨论交流,共同进步