2011 1114 sakai keiichikochitech ac jp http www

  • Slides: 16
Download presentation
コンパイラ 2011年 11月14日 酒居敬一@A468(sakai. keiichi@kochi-tech. ac. jp) http: //www. info. kochi-tech. ac. jp/k 1

コンパイラ 2011年 11月14日 酒居敬一@A468(sakai. [email protected] ac. jp) http: //www. info. kochi-tech. ac. jp/k 1 sakai/Lecture/COMP/2011/index. html 1

例外処理の例(110ページ) 1. class Example { 2. public static void main(String[] args){ 3. try{ 4.

例外処理の例(110ページ) 1. class Example { 2. public static void main(String[] args){ 3. try{ 4. method 1(args); 5. System. out. println("This Line is not executed. "); 6. } 7. catch(Exception e){ // Exception (かその派生クラス)に関する例外ハンドラ 8. System. out. println(e. get. Message()); 9. } 10. } 11. static void method 1(Object o){ 12. synchronized(o){ 13. method 2(); 14. System. out. println("This Line is not executed. "); 15. } 16. } 17. staic void method 2(){ 18. throw (new Exception("Jump To Handler. ")); // 例外発生源 19. } 20. } 4

10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23.

10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. void Example 8_main(Exec. Env *ee, void *args){ Example 8_method 1(ee, args); if(exception. Occured(ee)){ goto CATCH; } println(ee, System. out, "This Line is not executed. "); if(exception. Occured(ee)){ goto CATCH; } NORMAL_EXIT: return; CATCH: { void *object = ee->exception; if(is_instance_of(object, Exception, ee)){ exception. Clear(ee); println(ee, System. out, get. Message(ee, object)); if(exception. Occured(ee)){ goto EXCEPION_EXIT; } goto NORMAL_EXIT; } } EXCEPTION_EXIT: return; } 10

37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50.

37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. void Example 8_method 1(Exec. Env *ee, void *o){ Enter. Synchronized. Block(o); if(exception. Occured(ee)){ goto EXCEPTION_EXIT; } Example_method 2(ee); if(exception. Occured(ee)){ goto SYNCHRONIZED_BLOCK_EXCEPTION_EXIT; } println(ee, System. out, "This Line is not executed. "); if(exception. Occured(ee)){ goto SYNCHRONIZED_BLOCK_EXCEPTION_EXIT; } Exit. Synchronized. Block(o); if(exception. Occured(ee)){ 61. void Example 8_method 2(Exec. Env *ee){ goto EXCEPTION_EXIT; 62. void *object = new. Instance(ee, Exception); } 63. if(exception. Occured(ee)){ return; 64. goto EXCEPTION_EXIT; SYNCHRONIZED_BLOCK_EXCEPTION_EXIT; 65. } Exit. Synchronized. Block(o); 66. Exception_init(ee, object, "Jump to Handler. "); EXCEPTION_EXIT: 67. if(exception. Occured(ee)){ return; 68. goto EXCEPTION_EXIT; } 69. } 70. exception. Throw(ee, object); 71. EXCEPTION_EXIT: 72. return; 73. } 11

プログラム中のどこから来たか? という情報よりも どこへ戻るのか? という情報を使う。 呼ばれた関数の スタックフレーム 戻り番地 それは、戻り番地は暗黙的に渡されているため、 特別に処理しなくても獲得できる情報だから。 ee args 1. 2. 3.

プログラム中のどこから来たか? という情報よりも どこへ戻るのか? という情報を使う。 呼ばれた関数の スタックフレーム 戻り番地 それは、戻り番地は暗黙的に渡されているため、 特別に処理しなくても獲得できる情報だから。 ee args 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. void Example 8_main(Exec. Env *ee, void *args){ Example 8_method 1(ee, args); println(ee, System. out, "This Line is not executed. "); NORMAL_EXIT: return; CATCH: { void *object = ee->exception; if(is_instance_of(object, Exception, ee)){ exception. Clear(ee); println(ee, System. out, get. Message(ee, object)); goto NORMAL_EXIT; } } EXCEPTION_EXIT: goto (look. Up. Return. Address. In. Exception(return. Address()); } 呼んだ関数の スタックフレーム 13 ← TOS

19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32.

19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. void Example 8_method 1(Exec. Env *ee, void *o){ Enter. Synchronized. Block(o); Example_method 2(ee); println(ee, System. out, "This Line is not executed. "); Exit. Synchronized. Block(o); return; SYNCHRONIZED_BLOCK_EXCEPTION_EXIT; Exit. Synchronized. Block(o); EXCEPTION_EXIT: goto (look. Up. Return. Address. In. Exception(return. Address()); } void Example 8_method 2(Exec. Env *ee){ void *object = new. Instance(ee, Exception); Exception_init(ee, object, "Jump to Handler. "); exception. Throw(ee, object); EXCEPTION_EXIT: goto (look. Up. Return. Address. In. Exception(return. Address()); } 14