{"id":453,"date":"2011-03-25T09:36:41","date_gmt":"2011-03-25T01:36:41","guid":{"rendered":"http:\/\/coderbee.net\/?p=453"},"modified":"2013-09-10T09:38:57","modified_gmt":"2013-09-10T01:38:57","slug":"%e5%90%8c%e6%ad%a5%e6%96%b9%e6%b3%95%e4%b8%8e%e5%90%8c%e6%ad%a5%e4%bb%a3%e7%a0%81%e5%9d%97%e7%9a%84%e5%8c%ba%e5%88%ab","status":"publish","type":"post","link":"https:\/\/coderbee.net\/index.php\/java\/20110325\/453","title":{"rendered":"\u540c\u6b65\u65b9\u6cd5\u4e0e\u540c\u6b65\u4ee3\u7801\u5757\u7684\u533a\u522b"},"content":{"rendered":"<p>\u5f53JVM\u6267\u884c\u4e00\u4e2a\u65b9\u6cd5\u65f6\uff0c\u6267\u884c\u4e2d\u7684\u7ebf\u7a0b\u8bc6\u522b\u8be5\u65b9\u6cd5\u7684 <code>method_info<\/code> \u7ed3\u6784\u662f\u5426\u6709 <code>ACC_SYNCHRONIZED<\/code> \u6807\u8bb0\u8bbe\u7f6e\uff0c\u7136\u540e\u5b83\u81ea\u52a8\u83b7\u53d6\u5bf9\u8c61\u7684\u9501\uff0c\u8c03\u7528\u65b9\u6cd5\uff0c\u6700\u540e\u91ca\u653e\u9501\u3002\u5982\u679c\u6709\u5f02\u5e38\u53d1\u751f\uff0c\u7ebf\u7a0b\u81ea\u52a8\u91ca\u653e\u9501\u3002<\/p>\n<p>\u540c\u6b65\u5316\u4e00\u4e2a\u65b9\u6cd5\u5757\u4f1a\u8d85\u8fc7JVM\u5bf9\u83b7\u53d6\u5bf9\u8c61\u9501\u548c\u5f02\u5e38\u5904\u7406\u7684\u5185\u7f6e\u652f\u6301\uff0c\u8981\u6c42\u4ee5\u5b57\u8282\u4ee3\u7801\u663e\u5f0f\u5199\u5165\u529f\u80fd\u3002\u5982\u679c\u4f7f\u7528\u540c\u6b65\u65b9\u6cd5\u8bfb\u53d6\u4e00\u4e2a\u65b9\u6cd5\u7684\u5b57\u8282\u4ee3\u7801\uff0c\u5c31\u4f1a\u770b\u5230\u6709\u5341\u51e0\u4e2a\u989d\u5916\u7684\u64cd\u4f5c\u7528\u4e8e\u7ba1\u7406\u8fd9\u4e2a\u529f\u80fd\u3002<\/p>\n<pre><code class=\"java\">public class Sync {\n    private int i;\n\n    public synchronized int synchronizedMethodGet() {\n        return i;\n    }\n\n    public int synchronizedBlockGet() {\n        synchronized( this ) {\n            return i;\n        }\n    }\n\n}\n<\/code><\/pre>\n<p>\u53cd\u7f16\u8bd1\u51fa\u7684\u5b57\u8282\u7801\uff1a<\/p>\n<pre><code class=\"java\">D:\\Java\\jdk1.6.0_02\\bin&gt;javap -c Sync\nCompiled from \"Sync.java\"\n\npublic class Sync extends java.lang.Object{\npublic Sync();\n  Code:\n   0:   aload_0\n   1:   invokespecial   #1; \/\/Method java\/lang\/Object.\"&lt;init&gt;\":()V\n   4:   return\n\npublic synchronized int synchronizedMethodGet();\n  Code:\n   0:   aload_0\n   1:   getfield        #2; \/\/Field i:I\n   4:   ireturn\n\npublic int synchronizedBlockGet();\n  Code:\n   0:   aload_0\n   1:   dup\n   2:   astore_1\n   3:   monitorenter\n   4:   aload_0\n   5:   getfield        #2; \/\/Field i:I\n   8:   aload_1\n   9:   monitorexit\n   10:  ireturn\n   11:  astore_2\n   12:  aload_1\n   13:  monitorexit\n   14:  aload_2\n   15:  athrow\n  Exception table:\n   from   to  target type\n     4    10    11   any\n    11    14    11   any\n\n}\n<\/code><\/pre>\n<hr\/>\n<p>\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u5fae\u4fe1\u516c\u4f17\u53f7: <strong>coderbee\u7b14\u8bb0<\/strong>\uff0c\u53ef\u4ee5\u66f4\u53ca\u65f6\u56de\u590d\u4f60\u7684\u8ba8\u8bba\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"258\" height=\"258\" src=\"https:\/\/coderbee.net\/wp-content\/uploads\/2019\/01\/coderbee-note.jpg\" class=\"alignnone size-full wp-image-1707\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53JVM\u6267\u884c\u4e00\u4e2a\u65b9\u6cd5\u65f6\uff0c\u6267\u884c\u4e2d\u7684\u7ebf\u7a0b\u8bc6\u522b\u8be5\u65b9\u6cd5\u7684 method_info \u7ed3\u6784\u662f &hellip; <a href=\"https:\/\/coderbee.net\/index.php\/java\/20110325\/453\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"_links":{"self":[{"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/posts\/453"}],"collection":[{"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/comments?post=453"}],"version-history":[{"count":2,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/posts\/453\/revisions"}],"predecessor-version":[{"id":455,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/posts\/453\/revisions\/455"}],"wp:attachment":[{"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/media?parent=453"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/categories?post=453"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/tags?post=453"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}