opendjk jvm 异常执行分析

openjdk 异常处理流程

{

oop except_oop = STACK_OBJECT(-1); //从栈中弹出异常的引用

CHECK_NULL(except_oop); //检查异常引用是否为空

THREAD->set_pending_exception(except_oop, NULL, 0);
goto handle_exception; //处理异常执行代码

}

处理异常的代码handle_exception

{

Handle except_oop(THREAD, THREAD->pending_exception());

CALL_VM(continuation_bci = (intptr_t)InterpreterRuntime::exception_handler_for_exception(THREAD, except_oop()), handle_exception); //此为查找异常表,也就是执行InterpreterRuntime::exception_handler_for_exception,如果在执行的过程中还抛出异常,回到handle_exception开始地方,继续执行

except_oop = (oop) THREAD->vm_result();
THREAD->set_vm_result(NULL);
if (continuation_bci >= 0) { //查找异常表exception_handler_for_exception
SET_STACK_OBJECT(except_oop(), 0);
MORE_STACK(1);
pc = METHOD->code_base() + continuation_bci; //pc指针

............

goto run ; //转到解释器处理循环
}

THREAD->set_pending_exception(except_oop(), NULL, 0);
goto handle_return; //本方法没有找到相应的异常处理,继续往上抛出

}

查找异常表的代码

InterpreterRuntime::exception_handler_for_exception(JavaThread* thread, oopDesc* exception)

{

.............

if (thread->do_not_unlock_if_synchronized()) {

return Interpreter::remove_activation_entry();

}

do {

KlassHandle h_klass(THREAD, h_exception->klass());
handler_bci = h_method->fast_exception_handler_bci_for(h_klass, current_bci, THREAD);
if (HAS_PENDING_EXCEPTION) { //需要处理异常
h_exception = Handle(THREAD, PENDING_EXCEPTION);
CLEAR_PENDING_EXCEPTION;
if (handler_bci >= 0) {
current_bci = handler_bci;
should_repeat = true;
}
}

}while (should_repeat == true);

address continuation = NULL;

if (handler_bci < 0 || !thread->reguard_stack((address) &continuation)) {

continuation = Interpreter::remove_activation_entry();

h_method->interpreter_throwout_increment();

}else{

handler_pc = h_method->code_base() + handler_bci;

set_bcp_and_mdp(handler_pc, thread);
continuation = Interpreter::dispatch_table(vtos)[*handler_pc];

}

thread->set_vm_result(h_exception());
return continuation;

}


handle_return:
{

if (THREAD->do_not_unlock()) { //对方法中监视器的处理

}else{

}

if (illegal_state_oop() != NULL || original_exception() != NULL) {
istate->set_msg(throwing_exception);
if (illegal_state_oop() != NULL)
THREAD->set_pending_exception(illegal_state_oop(), NULL, 0);
else
THREAD->set_pending_exception(original_exception(), NULL, 0);
istate->set_return_kind((Bytecodes::Code)opcode);
UPDATE_PC_AND_RETURN(0);


generate_normal_entry中

__ pushptr(return_from_native_method.addr());调用前的返回地址(这就是上面return返回后的地址)

__ jmp(rax); 调用

*/
}

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值