相濡以沫

鱼遇于池,池涸,相濡以沫,相鞠以湿,不若相忘于海。(爱技术、爱时尚)

用户操作
[即时聊天] [发私信] [加为好友]
挨踢老人ID:onlyzhangqin
3130990次访问,排名1,好友286人,关注者1065人。
大便的离去是马桶的招唤,还是肛门的不挽留?
onlyzhangqin的文章
原创 672 篇
翻译 11 篇
转载 18940 篇
评论 268 篇
挨踢老人的公告
点我聊QQ


最近评论
jianwei824:上大一的时候我也写过这样的一个程序,通过这个才真正开始对编程着迷,但编了好多年又迷了!
feiniao2008:学习
mynote:30岁而已,当了总统还是最年轻的总统呢。
jerry_yn:我想知道你的无线模块有中继功能吗?
huangkui800:好 嘿嘿
文章分类
收藏
相册
超女里不多的美女
都是美女
好看好玩
著名的照片
技术
Cisco网络技术(Net130.Com)
CSS在线编辑
DotNet男孩社区
IP查询
Sunmoonfire's artistic matrix
UML软件工程组织
一个好博客(RSS)
中国协议分析网
中国项目管理网
微软帮助和支持
朋友
又一个好博客(RSS)
小人鱼的秘密
我的站长天下
其它
AC MILAN官网
Badged
deshow 在线制作服务
E书下载
IT公司速查手册
msn在线留言
Slide
Webfetti
东方资源
中华电脑书库
博客网址价值评估工具
我爱e书
我的下载Blog
存档
订阅我的博客
XML聚合  FeedSky
订阅到鲜果
订阅到Google
订阅到抓虾
订阅到BlogLines
订阅到Yahoo
订阅到GouGou
订阅到飞鸽
订阅到Rojo
订阅到newsgator
订阅到netvibes

转载 athrow程序执行代码。收藏

新一篇: GooD.GD 又一方便的网络硬盘服务。 | 旧一篇: C#使用BerkeleyDB操作简介。

 



淘宝书店http://shop35357269.taobao.com

       看看openjdk中的athrow处理流程

    {

             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) {   //一般都是大于0,详见查找异常表exception_handler_for_exception的操作的说明

                       SET_STACK_OBJECT(except_oop(), 0);
                       MORE_STACK(1);
                       pc = METHOD->code_base() + continuation_bci; //pc指针

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

                       goto run ; //转到解释器处理循环,如果到这,不会执行if以后的代码

             }

             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) { //这个地方有点看不明白,大于0应该是表示找到了catch里面对应的异常处理,怎么还继续循环?
                                          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代码,handle_return处理的应该是本方法没有处理异常,也就是应该由上层方法处理。

    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);

/*注意,这个地方采用的是return,也就是说它会跳出解释器的while(1)循环,从而结束javaCalls:call方法,这个就返回了上一个方法的处理流程中,具体得看InterpreterGenerator::generate_normal_entry,这个地方有些难于看懂,是怎么从调用的方法中返回,然后进行下一句的执行的。

      在generate_normal_entry中注意下面的两句

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

      __ jmp(rax); 调用真正的方法

*/
            }

     }


搜索是最好的老师,要善用搜索!!!

Google

我的非技术博客:http://wholdman.blogcn.com

发表于 @ 2008年10月10日 17:29:00|评论(loading...)|收藏

新一篇: GooD.GD 又一方便的网络硬盘服务。 | 旧一篇: C#使用BerkeleyDB操作简介。

评论:没有评论。

发表评论  


当前用户设置只有注册用户才能发表评论。如果你没有登录,请点击登录
Csdn Blog version 3.1a
Copyright © 挨踢老人