{"id":117864,"date":"2026-10-25T18:40:25","date_gmt":"2026-10-25T10:40:25","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/117864.html"},"modified":"2026-10-25T18:40:25","modified_gmt":"2026-10-25T10:40:25","slug":"%e7%ae%a1%e7%a8%8b%e6%98%af%e6%80%8e%e4%b9%88%e5%ae%9e%e7%8e%b0%e7%9a%84%ef%bc%9a%e4%bb%8e%e6%93%8d%e4%bd%9c%e7%b3%bb%e7%bb%9f%e5%86%85%e6%a0%b8%e5%88%b0-hotspot-%e5%af%b9%e8%b1%a1%e7%9b%91%e8%a7%86","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/117864.html","title":{"rendered":"\u7ba1\u7a0b\u662f\u600e\u4e48\u5b9e\u73b0\u7684\uff1a\u4ece\u64cd\u4f5c\u7cfb\u7edf\u5185\u6838\u5230 HotSpot \u5bf9\u8c61\u76d1\u89c6\u5668"},"content":{"rendered":"<p>English version: How Monitors Are Implemented: From the OS Kernel to the HotSpot ObjectMonitor<\/p>\n<p>\u59ca\u59b9\u7bc7 \u4ece PV \u64cd\u4f5c\u3001\u7ba1\u7a0b\u5230\u73b0\u4ee3 Java \u5e76\u53d1 \u8bb2\u7684\u662f\u7ba1\u7a0b\u662f\u4ec0\u4e48&#xff1a;\u5171\u4eab\u6570\u636e &#043; \u8fc7\u7a0b &#043; \u9690\u5f0f\u4e92\u65a5 &#043; \u6761\u4ef6\u53d8\u91cf&#xff0c;\u4ee5\u53ca Hoare \/ Mesa \u4e24\u79cd\u5524\u9192\u8bed\u4e49\u3002\u672c\u6587\u53ea\u56de\u7b54\u4e0b\u4e00\u4e2a\u95ee\u9898&#xff1a;\u5b83\u662f\u600e\u4e48\u505a\u51fa\u6765\u7684\u2014\u2014\u4ece\u4e00\u6761 CPU \u539f\u5b50\u6307\u4ee4\u5f00\u59cb&#xff0c;\u7ecf\u8fc7 Linux \u5185\u6838\u7684\u7b49\u5f85\u961f\u5217\u548c futex&#xff0c;\u4e00\u76f4\u5230 HotSpot \u91cc synchronized \u80cc\u540e\u7684\u5bf9\u8c61\u5934\u548c ObjectMonitor\u3002<\/p>\n<h3>\u7f29\u5199\u5bf9\u7167\u8868<\/h3>\n<table>\n<tr>\u7f29\u5199\u82f1\u6587\u5168\u79f0\u4e2d\u6587<\/tr>\n<tbody>\n<tr>\n<td>OS<\/td>\n<td>Operating System<\/td>\n<td>\u64cd\u4f5c\u7cfb\u7edf<\/td>\n<\/tr>\n<tr>\n<td>CPU<\/td>\n<td>Central Processing Unit<\/td>\n<td>\u4e2d\u592e\u5904\u7406\u5668<\/td>\n<\/tr>\n<tr>\n<td>CAS<\/td>\n<td>Compare-And-Swap<\/td>\n<td>\u6bd4\u8f83\u5e76\u4ea4\u6362<\/td>\n<\/tr>\n<tr>\n<td>TAS<\/td>\n<td>Test-And-Set<\/td>\n<td>\u6d4b\u8bd5\u5e76\u7f6e\u4f4d<\/td>\n<\/tr>\n<tr>\n<td>LL\/SC<\/td>\n<td>Load-Linked \/ Store-Conditional<\/td>\n<td>\u94fe\u63a5\u52a0\u8f7d \/ \u6761\u4ef6\u5b58\u50a8<\/td>\n<\/tr>\n<tr>\n<td>MCS<\/td>\n<td>Mellor-Crummey and Scott&#xff08;queue lock&#xff09;<\/td>\n<td>MCS \u961f\u5217\u9501<\/td>\n<\/tr>\n<tr>\n<td>futex<\/td>\n<td>Fast Userspace muTEX<\/td>\n<td>Linux \u5feb\u901f\u7528\u6237\u6001\u4e92\u65a5\u91cf<\/td>\n<\/tr>\n<tr>\n<td>NPTL<\/td>\n<td>Native POSIX Thread Library<\/td>\n<td>glibc \u7684\u539f\u751f POSIX \u7ebf\u7a0b\u5e93<\/td>\n<\/tr>\n<tr>\n<td>POSIX<\/td>\n<td>Portable Operating System Interface<\/td>\n<td>\u53ef\u79fb\u690d\u64cd\u4f5c\u7cfb\u7edf\u63a5\u53e3<\/td>\n<\/tr>\n<tr>\n<td>JVM<\/td>\n<td>Java Virtual Machine<\/td>\n<td>Java \u865a\u62df\u673a<\/td>\n<\/tr>\n<tr>\n<td>JDK<\/td>\n<td>Java Development Kit<\/td>\n<td>Java \u5f00\u53d1\u5de5\u5177\u5305<\/td>\n<\/tr>\n<tr>\n<td>JEP<\/td>\n<td>JDK Enhancement Proposal<\/td>\n<td>JDK \u589e\u5f3a\u63d0\u6848<\/td>\n<\/tr>\n<tr>\n<td>JUC<\/td>\n<td>java.util.concurrent<\/td>\n<td>Java \u5e76\u53d1\u5de5\u5177\u5305<\/td>\n<\/tr>\n<tr>\n<td>AQS<\/td>\n<td>AbstractQueuedSynchronizer<\/td>\n<td>\u62bd\u8c61\u961f\u5217\u540c\u6b65\u5668<\/td>\n<\/tr>\n<tr>\n<td>GC<\/td>\n<td>Garbage Collection<\/td>\n<td>\u5783\u573e\u56de\u6536<\/td>\n<\/tr>\n<tr>\n<td>IPI<\/td>\n<td>Inter-Processor Interrupt<\/td>\n<td>\u5904\u7406\u5668\u95f4\u4e2d\u65ad<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>0. \u5148\u62c6\u95ee\u9898&#xff1a;\u7ba1\u7a0b\u8981\u89e3\u51b3\u7684\u4e09\u4ef6\u4e8b<\/h3>\n<p>\u4e0d\u7ba1\u5728\u54ea\u4e00\u5c42\u5b9e\u73b0&#xff0c;\u7ba1\u7a0b\u90fd\u8981\u56de\u7b54\u4e09\u4e2a\u673a\u5236\u95ee\u9898&#xff1a;<\/p>\n<li>\u4e92\u65a5&#xff1a;\u600e\u4e48\u4fdd\u8bc1\u540c\u4e00\u65f6\u523b\u53ea\u6709\u4e00\u4e2a\u7ebf\u7a0b\u5728\u7ba1\u7a0b\u91cc&#xff1f;<\/li>\n<li>\u6761\u4ef6\u7b49\u5f85&#xff1a;wait(c) \u8981&#034;\u91ca\u653e\u9501 &#043; \u7761\u7720&#034;&#xff0c;signal(c) \u8981&#034;\u5524\u9192\u4e00\u4e2a&#034;\u2014\u2014\u4e24\u6b65\u4e4b\u95f4\u5982\u679c\u88ab\u63d2\u961f&#xff0c;\u4fe1\u53f7\u5c31\u4e22\u4e86&#xff08;\u4e22\u5931\u5524\u9192&#xff0c;lost wakeup&#xff09;\u3002\u600e\u4e48\u907f\u514d&#xff1f;<\/li>\n<li>\u963b\u585e\u4e0e\u5524\u9192&#xff1a;\u62a2\u4e0d\u5230\u9501\u3001\u6761\u4ef6\u4e0d\u6210\u7acb\u65f6&#xff0c;\u7ebf\u7a0b\u600e\u4e48\u771f\u7684&#034;\u505c\u4e0b\u6765&#034;\u4e0d\u5360 CPU&#xff0c;\u53c8\u600e\u4e48\u88ab\u53eb\u9192&#xff1f;<\/li>\n<p>\u4e0b\u9762\u6bcf\u4e00\u5c42\u7684\u8bbe\u8ba1&#xff0c;\u90fd\u662f\u5bf9\u8fd9\u4e09\u4e2a\u95ee\u9898\u7684\u4e00\u79cd\u56de\u7b54\u3002<\/p>\n<p>  #mermaid-svg-ERrqDGjyT79gUrC6{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-ERrqDGjyT79gUrC6 .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-ERrqDGjyT79gUrC6 .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-ERrqDGjyT79gUrC6 .error-icon{fill:#552222;}#mermaid-svg-ERrqDGjyT79gUrC6 .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-ERrqDGjyT79gUrC6 .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-ERrqDGjyT79gUrC6 .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-ERrqDGjyT79gUrC6 .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-ERrqDGjyT79gUrC6 .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-ERrqDGjyT79gUrC6 .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-ERrqDGjyT79gUrC6 .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-ERrqDGjyT79gUrC6 .marker{fill:#333333;stroke:#333333;}#mermaid-svg-ERrqDGjyT79gUrC6 .marker.cross{stroke:#333333;}#mermaid-svg-ERrqDGjyT79gUrC6 svg{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-ERrqDGjyT79gUrC6 p{margin:0;}#mermaid-svg-ERrqDGjyT79gUrC6 .label{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;color:#333;}#mermaid-svg-ERrqDGjyT79gUrC6 .cluster-label text{fill:#333;}#mermaid-svg-ERrqDGjyT79gUrC6 .cluster-label span{color:#333;}#mermaid-svg-ERrqDGjyT79gUrC6 .cluster-label span p{background-color:transparent;}#mermaid-svg-ERrqDGjyT79gUrC6 .label text,#mermaid-svg-ERrqDGjyT79gUrC6 span{fill:#333;color:#333;}#mermaid-svg-ERrqDGjyT79gUrC6 .node rect,#mermaid-svg-ERrqDGjyT79gUrC6 .node circle,#mermaid-svg-ERrqDGjyT79gUrC6 .node ellipse,#mermaid-svg-ERrqDGjyT79gUrC6 .node polygon,#mermaid-svg-ERrqDGjyT79gUrC6 .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-ERrqDGjyT79gUrC6 .rough-node .label text,#mermaid-svg-ERrqDGjyT79gUrC6 .node .label text,#mermaid-svg-ERrqDGjyT79gUrC6 .image-shape .label,#mermaid-svg-ERrqDGjyT79gUrC6 .icon-shape .label{text-anchor:middle;}#mermaid-svg-ERrqDGjyT79gUrC6 .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-ERrqDGjyT79gUrC6 .rough-node .label,#mermaid-svg-ERrqDGjyT79gUrC6 .node .label,#mermaid-svg-ERrqDGjyT79gUrC6 .image-shape .label,#mermaid-svg-ERrqDGjyT79gUrC6 .icon-shape .label{text-align:center;}#mermaid-svg-ERrqDGjyT79gUrC6 .node.clickable{cursor:pointer;}#mermaid-svg-ERrqDGjyT79gUrC6 .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-ERrqDGjyT79gUrC6 .arrowheadPath{fill:#333333;}#mermaid-svg-ERrqDGjyT79gUrC6 .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-ERrqDGjyT79gUrC6 .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-ERrqDGjyT79gUrC6 .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-ERrqDGjyT79gUrC6 .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-ERrqDGjyT79gUrC6 .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-ERrqDGjyT79gUrC6 .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-ERrqDGjyT79gUrC6 .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-ERrqDGjyT79gUrC6 .cluster text{fill:#333;}#mermaid-svg-ERrqDGjyT79gUrC6 .cluster span{color:#333;}#mermaid-svg-ERrqDGjyT79gUrC6 div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-ERrqDGjyT79gUrC6 .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-ERrqDGjyT79gUrC6 rect.text{fill:none;stroke-width:0;}#mermaid-svg-ERrqDGjyT79gUrC6 .icon-shape,#mermaid-svg-ERrqDGjyT79gUrC6 .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-ERrqDGjyT79gUrC6 .icon-shape p,#mermaid-svg-ERrqDGjyT79gUrC6 .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-ERrqDGjyT79gUrC6 .icon-shape .label rect,#mermaid-svg-ERrqDGjyT79gUrC6 .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-ERrqDGjyT79gUrC6 .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-ERrqDGjyT79gUrC6 .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-ERrqDGjyT79gUrC6 :root{&#8211;mermaid-font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;}<\/p>\n<p>         <span class=\"edgeLabel\"><\/span><\/p>\n<p>         <span class=\"edgeLabel\"><\/span><\/p>\n<p>         <span class=\"edgeLabel\"><\/span><\/p>\n<p>         <span class=\"edgeLabel\"><\/span><\/p>\n<p>         <span class=\"nodeLabel\"><\/p>\n<p>\u8bed\u8a00\u5c42&#xff1a;\u7ba1\u7a0b\u8bed\u6cd5synchronized \/ wait \/ notify<\/p>\n<p><\/span><\/p>\n<p>         <span class=\"nodeLabel\"><\/p>\n<p>\u8fd0\u884c\u65f6\u5c42&#xff1a;HotSpotMark Word &#043; ObjectMonitor<\/p>\n<p><\/span><\/p>\n<p>         <span class=\"nodeLabel\"><\/p>\n<p>\u7528\u6237\u6001\u7ebf\u7a0b\u5e93&#xff1a;glibc NPTLpthread_mutex \/ pthread_cond<\/p>\n<p><\/span><\/p>\n<p>         <span class=\"nodeLabel\"><\/p>\n<p>\u5185\u6838&#xff1a;futex \u7cfb\u7edf\u8c03\u7528\u7b49\u5f85\u961f\u5217 &#043; \u8c03\u5ea6\u5668<\/p>\n<p><\/span><\/p>\n<p>         <span class=\"nodeLabel\"><\/p>\n<p>\u786c\u4ef6&#xff1a;\u539f\u5b50\u6307\u4ee4LOCK CMPXCHG \/ LL-SC&#043; \u5185\u5b58\u5c4f\u969c<\/p>\n<p><\/span><\/p>\n<p>\u8fd9\u5f20\u56fe\u56de\u7b54&#xff1a;\u4e00\u6b21 synchronized \u963b\u585e&#xff0c;\u4ece\u8bed\u8a00\u4e00\u8def\u843d\u5230\u54ea\u4e9b\u5c42&#xff1f;<\/p>\n<h3>\u7b2c\u4e00\u90e8\u5206&#xff1a;\u64cd\u4f5c\u7cfb\u7edf\u91cc\u7684\u7ba1\u7a0b\u662f\u600e\u4e48\u5b9e\u73b0\u7684<\/h3>\n<p>\u5148\u6f84\u6e05\u4e00\u4e2a\u5bb9\u6613\u6df7\u7684\u70b9&#xff1a;\u7ba1\u7a0b\u662f\u8bed\u8a00\u7ed3\u6784&#xff0c;\u4e0d\u662f\u5185\u6838\u5bf9\u8c61\u3002 Linux \u5185\u6838\u91cc\u6ca1\u6709\u4e00\u4e2a\u53eb monitor \u7684\u7cfb\u7edf\u8c03\u7528\u3002Hoare \u548c Brinch Hansen \u8bbe\u60f3\u7684\u662f&#xff1a;\u7f16\u8bd1\u5668\u770b\u5230 monitor \u5173\u952e\u5b57&#xff0c;\u81ea\u52a8\u5728\u6bcf\u4e2a\u8fc7\u7a0b\u5165\u53e3\u63d2\u5165\u52a0\u9501\u3001\u51fa\u53e3\u63d2\u5165\u89e3\u9501&#xff0c;\u628a wait\/signal \u7f16\u8bd1\u6210\u5bf9\u6761\u4ef6\u53d8\u91cf\u7684\u64cd\u4f5c\u3002\u6240\u4ee5&#034;OS \u91cc\u7684\u7ba1\u7a0b&#034;&#xff0c;\u5b9e\u9645\u662f\u95ee&#xff1a;OS \u63d0\u4f9b\u4e86\u4ec0\u4e48\u539f\u8bed&#xff0c;\u8ba9\u7f16\u8bd1\u5668 \/ \u8fd0\u884c\u65f6\u80fd\u628a\u7ba1\u7a0b\u62fc\u51fa\u6765&#xff1f; \u7b54\u6848\u662f\u4e24\u6837&#xff1a;\u9501\u548c\u7b49\u5f85\u961f\u5217\u3002<\/p>\n<h4>1.1 \u4e92\u65a5&#xff1a;\u4e00\u5207\u4ece\u4e00\u6761\u539f\u5b50\u6307\u4ee4\u5f00\u59cb<\/h4>\n<p>\u5355\u6838\u65f6\u4ee3&#xff1a;\u4e34\u754c\u533a\u53ea\u4f1a\u88ab\u4e2d\u65ad\u6253\u65ad&#xff0c;\u4e8e\u662f\u8fdb\u5165\u65f6\u5173\u4e2d\u65ad\u3001\u9000\u51fa\u65f6\u5f00\u4e2d\u65ad&#xff0c;\u5c31\u5f97\u5230\u4e86\u4e92\u65a5\u3002\u8fd9\u62db\u5728\u591a\u6838\u4e0a\u5931\u6548\u2014\u2014\u5173\u6389\u7684\u53ea\u662f\u672c\u6838\u7684\u4e2d\u65ad&#xff0c;\u522b\u7684\u6838\u7167\u6837\u8dd1\u3002<\/p>\n<p>\u591a\u6838&#xff1a;\u9760\u786c\u4ef6\u63d0\u4f9b&#034;\u8bfb\u2014\u6539\u2014\u5199\u4e0d\u53ef\u5206\u5272&#034;\u7684\u6307\u4ee4&#xff1a;<\/p>\n<table>\n<tr>\u6307\u4ee4\u65cf\u4ee3\u8868\u8bed\u4e49<\/tr>\n<tbody>\n<tr>\n<td>TAS \/ \u4ea4\u6362<\/td>\n<td>x86 XCHG<\/td>\n<td>\u539f\u5b50\u5730\u5199\u5165\u65b0\u503c\u5e76\u8fd4\u56de\u65e7\u503c<\/td>\n<\/tr>\n<tr>\n<td>CAS<\/td>\n<td>x86 LOCK CMPXCHG<\/td>\n<td>\u5f53\u524d\u503c\u7b49\u4e8e\u671f\u671b\u503c\u624d\u5199\u5165&#xff0c;\u8fd4\u56de\u662f\u5426\u6210\u529f<\/td>\n<\/tr>\n<tr>\n<td>LL\/SC<\/td>\n<td>ARM LDXR\/STXR&#xff08;\u6216 ARMv8.1 \u7684 CAS&#xff09;<\/td>\n<td>\u8bfb\u540e\u82e5\u671f\u95f4\u65e0\u4eba\u5199\u8fc7&#xff0c;\u624d\u5141\u8bb8\u5199\u56de<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>LOCK \u524d\u7f00\u8ba9\u8be5\u6838\u5728\u7f13\u5b58\u4e00\u81f4\u6027\u534f\u8bae\u91cc\u72ec\u5360\u8fd9\u6761\u7f13\u5b58\u884c&#xff0c;\u5176\u4ed6\u6838\u6b64\u523b\u65e0\u6cd5\u4fee\u6539\u5b83&#xff1b;\u540c\u65f6\u8fd9\u4e9b\u6307\u4ee4\u81ea\u5e26\u5185\u5b58\u5c4f\u969c\u8bed\u4e49&#xff0c;\u4fdd\u8bc1\u4e34\u754c\u533a\u5185\u7684\u8bfb\u5199\u4e0d\u4f1a\u88ab\u91cd\u6392\u5230\u9501\u5916\u3002\u6709\u4e86\u5b83&#xff0c;\u6700\u6734\u7d20\u7684\u9501\u2014\u2014\u81ea\u65cb\u9501\u2014\u2014\u53ea\u9700\u51e0\u884c&#xff1a;<\/p>\n<p><span class=\"token keyword\">void<\/span> <span class=\"token function\">spin_lock<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> <span class=\"token operator\">*<\/span>l<span class=\"token punctuation\">)<\/span>   <span class=\"token punctuation\">{<\/span> <span class=\"token keyword\">while<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token function\">xchg<\/span><span class=\"token punctuation\">(<\/span>l<span class=\"token punctuation\">,<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token function\">cpu_relax<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token punctuation\">}<\/span>  <span class=\"token comment\">\/\/ \u62a2\u4e0d\u5230\u5c31\u539f\u5730\u8f6c<\/span><br \/>\n<span class=\"token keyword\">void<\/span> <span class=\"token function\">spin_unlock<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> <span class=\"token operator\">*<\/span>l<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token function\">store_release<\/span><span class=\"token punctuation\">(<\/span>l<span class=\"token punctuation\">,<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token punctuation\">}<\/span><\/p>\n<p>\u81ea\u65cb\u9501\u89e3\u51b3\u4e86&#034;\u4e92\u65a5&#034;&#xff0c;\u4f46\u6ca1\u89e3\u51b3&#034;\u963b\u585e&#034;&#xff1a;\u62a2\u4e0d\u5230\u7684\u7ebf\u7a0b\u4e00\u76f4\u5728\u70e7 CPU\u3002\u6301\u9501\u65f6\u95f4\u77ed&#xff08;\u51e0\u5341\u7eb3\u79d2&#xff09;\u65f6\u8fd9\u53cd\u800c\u6700\u5feb&#xff1b;\u6301\u9501\u65f6\u95f4\u957f\u6216\u6301\u9501\u8005\u88ab\u8c03\u5ea6\u8d70\u65f6&#xff0c;\u5c31\u662f\u7eaf\u6d6a\u8d39\u3002\u6240\u4ee5\u9700\u8981\u7b2c\u4e8c\u6837\u4e1c\u897f\u3002<\/p>\n<h4>1.2 \u963b\u585e\u4e0e\u5524\u9192&#xff1a;\u5185\u6838\u7684\u7b49\u5f85\u961f\u5217\u548c\u8c03\u5ea6\u5668<\/h4>\n<p>\u5185\u6838\u8ba9\u4e00\u4e2a\u7ebf\u7a0b&#034;\u505c\u4e0b\u6765&#034;\u7684\u65b9\u5f0f\u662f&#xff1a;\u628a\u5b83\u7684\u72b6\u6001\u6539\u6210\u7761\u7720&#xff0c;\u4ece\u8fd0\u884c\u961f\u5217\u4e0a\u6458\u4e0b\u6765&#xff0c;\u7136\u540e\u5207\u6362\u5230\u522b\u7684\u7ebf\u7a0b\u3002Linux \u5185\u6838\u91cc\u4e00\u4e2a\u6807\u51c6\u7684&#034;\u7b49\u6761\u4ef6&#034;\u5199\u6cd5\u5982\u4e0b&#xff1a;<\/p>\n<p><span class=\"token function\">DEFINE_WAIT<\/span><span class=\"token punctuation\">(<\/span>wait<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">for<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">;<\/span><span class=\"token punctuation\">;<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token function\">prepare_to_wait<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">&amp;<\/span>wq<span class=\"token punctuation\">,<\/span> <span class=\"token operator\">&amp;<\/span>wait<span class=\"token punctuation\">,<\/span> TASK_INTERRUPTIBLE<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u2460 \u5148\u5165\u961f\u5e76\u628a\u81ea\u5df1\u6807\u6210&#034;\u7761\u7720&#034;<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>condition<span class=\"token punctuation\">)<\/span>                                   <span class=\"token comment\">\/\/ \u2461 \u518d\u68c0\u67e5\u6761\u4ef6<\/span><br \/>\n        <span class=\"token keyword\">break<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token function\">schedule<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>                                      <span class=\"token comment\">\/\/ \u2462 \u8ba9\u51fa CPU&#xff0c;\u771f\u6b63\u7761\u4e0b<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token function\">finish_wait<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">&amp;<\/span>wq<span class=\"token punctuation\">,<\/span> <span class=\"token operator\">&amp;<\/span>wait<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u5524\u9192\u65b9&#xff1a;<\/p>\n<p>condition <span class=\"token operator\">&#061;<\/span> true<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token function\">wake_up<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">&amp;<\/span>wq<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>   <span class=\"token comment\">\/\/ \u628a\u961f\u5217\u91cc\u7684\u7ebf\u7a0b\u6807\u56de TASK_RUNNING&#xff0c;\u653e\u56de\u8fd0\u884c\u961f\u5217<\/span><\/p>\n<p>\u4e22\u5931\u5524\u9192\u662f\u600e\u4e48\u907f\u514d\u7684&#xff1f; \u5173\u952e\u5728 \u2460 \u548c \u2461 \u7684\u987a\u5e8f&#xff1a;\u5148\u628a\u81ea\u5df1\u6302\u8fdb\u961f\u5217\u5e76\u6807\u6210\u7761\u7720&#xff0c;\u518d\u68c0\u67e5\u6761\u4ef6\u3002\u5982\u679c\u5524\u9192\u65b9\u6070\u597d\u5728 \u2461 \u548c \u2462 \u4e4b\u95f4\u6267\u884c\u4e86 wake_up&#xff0c;\u5b83\u4f1a\u628a\u672c\u7ebf\u7a0b\u7684\u72b6\u6001\u6539\u56de TASK_RUNNING\u2014\u2014\u4e8e\u662f \u2462 \u7684 schedule() \u53d1\u73b0\u81ea\u5df1\u662f\u53ef\u8fd0\u884c\u7684&#xff0c;\u7acb\u523b\u8fd4\u56de&#xff0c;\u4e0d\u4f1a\u7761\u6b7b\u3002\u53cd\u8fc7\u6765&#xff0c;\u5982\u679c\u5148\u68c0\u67e5\u6761\u4ef6\u518d\u5165\u961f&#xff0c;\u4e2d\u95f4\u90a3\u4e00\u77ac\u95f4\u7684\u5524\u9192\u5c31\u843d\u4e86\u7a7a\u3002<\/p>\n<p>\u6302\u8d77\u548c\u5524\u9192\u7684\u7269\u7406\u8fc7\u7a0b&#xff1a;<\/p>\n<ul>\n<li>\u6302\u8d77&#xff1a;schedule() \u628a\u5f53\u524d\u4efb\u52a1\u79fb\u51fa\u8fd0\u884c\u961f\u5217&#xff0c;context_switch() \u4fdd\u5b58\u5bc4\u5b58\u5668\u3001\u5207\u6362\u5185\u6838\u6808&#xff08;\u8de8\u8fdb\u7a0b\u65f6\u8fd8\u8981\u5207\u6362\u9875\u8868&#xff09;&#xff0c;CPU \u8f6c\u53bb\u6267\u884c\u522b\u7684\u4efb\u52a1\u3002\u8fd9\u4e2a\u7ebf\u7a0b\u4e0d\u518d\u5360\u7528\u4efb\u4f55 CPU \u65f6\u95f4\u3002<\/li>\n<li>\u5524\u9192&#xff1a;try_to_wake_up() \u628a\u4efb\u52a1\u72b6\u6001\u6539\u4e3a TASK_RUNNING&#xff0c;\u653e\u56de\u67d0\u4e2a CPU \u7684\u8fd0\u884c\u961f\u5217&#xff1b;\u5982\u679c\u76ee\u6807 CPU \u5728\u7a7a\u95f2&#xff0c;\u5c31\u53d1\u4e00\u4e2a IPI&#xff08;Inter-Processor Interrupt&#xff0c;\u5904\u7406\u5668\u95f4\u4e2d\u65ad&#xff09;\u628a\u5b83\u53eb\u9192\u3002<\/li>\n<\/ul>\n<p>\u6ce8\u610f&#xff1a;\u5524\u9192\u53ea\u662f\u8ba9\u7ebf\u7a0b\u53d8\u5f97\u53ef\u8fd0\u884c&#xff0c;\u4ec0\u4e48\u65f6\u5019\u771f\u6b63\u4e0a CPU \u7531\u8c03\u5ea6\u5668\u51b3\u5b9a\u3002\u8fd9\u6b63\u662f Mesa \u8bed\u4e49\u7684\u7269\u7406\u6765\u6e90\u2014\u2014\u88ab\u5524\u9192\u8005\u6062\u590d\u8fd0\u884c\u65f6&#xff0c;\u6761\u4ef6\u53ef\u80fd\u5df2\u7ecf\u88ab\u522b\u4eba\u6539\u6389\u4e86&#xff0c;\u6240\u4ee5\u5fc5\u987b while \u91cd\u67e5\u3002<\/p>\n<h4>1.3 \u5185\u6838\u81ea\u5df1\u7684\u7761\u7720\u9501&#xff1a;\u81ea\u65cb &#043; \u6392\u961f\u7684\u6df7\u5408\u4f53<\/h4>\n<p>\u5185\u6838\u91cc\u7684 struct mutex \u628a\u4e0a\u9762\u4e24\u6837\u7ec4\u5408\u8d77\u6765&#xff0c;\u5206\u4e09\u6bb5\u8def\u5f84&#xff1a;<\/p>\n<table>\n<tr>\u8def\u5f84\u6761\u4ef6\u505a\u6cd5<\/tr>\n<tbody>\n<tr>\n<td>\u5feb\u901f\u8def\u5f84<\/td>\n<td>\u9501\u7a7a\u95f2<\/td>\n<td>\u4e00\u6b21 cmpxchg \u628a owner \u4ece 0 \u6539\u6210\u81ea\u5df1&#xff0c;\u5b8c\u4e8b<\/td>\n<\/tr>\n<tr>\n<td>\u4e2d\u95f4\u8def\u5f84<\/td>\n<td>\u9501\u88ab\u5360&#xff0c;\u4f46\u6301\u6709\u8005\u6b63\u5728\u67d0\u4e2a CPU \u4e0a\u8fd0\u884c<\/td>\n<td>\u4e50\u89c2\u81ea\u65cb&#xff08;\u6392\u5728 MCS \u98ce\u683c\u7684\u961f\u5217\u91cc\u8f6c&#xff09;&#xff0c;\u8d4c\u5b83\u9a6c\u4e0a\u91ca\u653e<\/td>\n<\/tr>\n<tr>\n<td>\u6162\u901f\u8def\u5f84<\/td>\n<td>\u6301\u6709\u8005\u7761\u7740\u4e86&#xff0c;\u6216\u81ea\u65cb\u592a\u4e45<\/td>\n<td>\u6302\u8fdb wait_list&#xff0c;schedule() \u7761\u4e0b&#xff1b;\u89e3\u9501\u8005\u8d1f\u8d23\u5524\u9192<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u8fd9\u4e2a&#034;\u5148 CAS\u3001\u518d\u81ea\u65cb\u3001\u6700\u540e\u6392\u961f\u7761\u7720&#034;\u7684\u4e09\u6bb5\u5f0f&#xff0c;\u540e\u9762\u5728 futex\u3001glibc\u3001HotSpot \u91cc\u4f1a\u4e00\u518d\u51fa\u73b0\u3002<\/p>\n<h4>1.4 \u628a\u7ba1\u7a0b\u62fc\u51fa\u6765&#xff1a;\u7ecf\u5178\u7684&#034;\u7528\u4fe1\u53f7\u91cf\u5b9e\u73b0 Hoare \u7ba1\u7a0b&#034;<\/h4>\n<p>\u6709\u4e86\u9501\u548c\u7b49\u5f85\u961f\u5217&#xff08;\u4fe1\u53f7\u91cf\u5c31\u662f\u4e8c\u8005\u7684\u5c01\u88c5&#xff09;&#xff0c;\u7f16\u8bd1\u5668\u5c31\u80fd\u628a\u7ba1\u7a0b\u7ffb\u8bd1\u51fa\u6765\u3002\u4e0b\u9762\u662f\u6559\u6750\u91cc\u7684\u6807\u51c6\u8bd1\u6cd5&#xff0c;\u5b9e\u73b0\u7684\u662f Hoare \u8bed\u4e49&#xff08;signal \u540e\u8ba9\u88ab\u5524\u9192\u8005\u7acb\u5373\u8fd0\u884c&#xff09;&#xff1a;<\/p>\n<p>semaphore mutex &#061; 1;       \/\/ \u7ba1\u7a0b\u5165\u53e3\u9501<br \/>\nsemaphore next  &#061; 0;       \/\/ signal \u8005\u8ba9\u51fa\u540e&#xff0c;\u7761\u5728\u8fd9\u91cc<br \/>\nint next_count  &#061; 0;       \/\/ \u7761\u5728 next \u4e0a\u7684 signal \u8005\u6570\u91cf<\/p>\n<p>\u6bcf\u4e2a\u6761\u4ef6\u53d8\u91cf x&#xff1a;<br \/>\nsemaphore x_sem   &#061; 0;<br \/>\nint       x_count &#061; 0;<\/p>\n<p>\u8fc7\u7a0b\u4f53&#xff1a;<br \/>\n    P(mutex);<br \/>\n    \u2026\u8fc7\u7a0b\u4ee3\u7801\u2026<br \/>\n    if (next_count &gt; 0) V(next);   \/\/ \u4f18\u5148\u628a\u7ba1\u7a0b\u4ea4\u8fd8\u7ed9\u8ba9\u51fa\u7684 signal \u8005<br \/>\n    else                V(mutex);<\/p>\n<p>x.wait():<br \/>\n    x_count&#043;&#043;;<br \/>\n    if (next_count &gt; 0) V(next); else V(mutex);   \/\/ \u91ca\u653e\u7ba1\u7a0b<br \/>\n    P(x_sem);                                     \/\/ \u7761\u5728 x \u4e0a<br \/>\n    x_count&#8211;;<\/p>\n<p>x.signal():<br \/>\n    if (x_count &gt; 0) {<br \/>\n        next_count&#043;&#043;;<br \/>\n        V(x_sem);      \/\/ \u5524\u9192\u4e00\u4e2a x \u4e0a\u7684\u7b49\u5f85\u8005&#xff0c;\u7ba1\u7a0b\u76f4\u63a5\u4ea4\u7ed9\u5b83<br \/>\n        P(next);       \/\/ \u81ea\u5df1\u8ba9\u51fa&#xff0c;\u7761\u5230 next \u4e0a<br \/>\n        next_count&#8211;;<br \/>\n    }<\/p>\n<p>\u8bfb\u8fd9\u6bb5\u4ee3\u7801\u80fd\u770b\u6e05 Hoare \u8bed\u4e49\u7684\u4ee3\u4ef7&#xff1a;\u6bcf\u6b21 signal \u90fd\u8981\u989d\u5916\u4e00\u6b21\u7ebf\u7a0b\u5207\u6362&#xff08;signal \u8005\u7761\u4e0b\u3001\u88ab\u5524\u9192\u8005\u4e0a\u573a&#xff09;\u3002Mesa \u8bed\u4e49\u628a x.signal() \u7b80\u5316\u6210&#034;V(x_sem) \u7136\u540e\u7ee7\u7eed\u8dd1&#034;&#xff0c;\u7701\u6389\u90a3\u6b21\u5207\u6362&#xff0c;\u4ee3\u4ef7\u662f\u7b49\u5f85\u8005\u9192\u6765\u540e\u8981\u91cd\u65b0\u68c0\u67e5\u6761\u4ef6\u2014\u2014\u8fd9\u5c31\u662f pthreads \u548c Java \u90fd\u9009 Mesa \u7684\u5de5\u7a0b\u539f\u56e0\u3002<\/p>\n<h4>1.5 \u7528\u6237\u6001\u7684\u6377\u5f84&#xff1a;futex<\/h4>\n<p>\u4e0a\u9762\u7684\u5185\u6838\u673a\u5236\u6709\u4e2a\u95ee\u9898&#xff1a;\u54ea\u6015\u9501\u5b8c\u5168\u6ca1\u4eba\u62a2&#xff0c;\u6bcf\u6b21\u52a0\u9501\u4e5f\u5f97\u9677\u5165\u5185\u6838\u3002\u4e00\u6b21\u7cfb\u7edf\u8c03\u7528\u7684\u6210\u672c\u8fdc\u9ad8\u4e8e\u4e00\u6761\u539f\u5b50\u6307\u4ee4&#xff08;\u524d\u8005\u901a\u5e38\u5728\u767e\u7eb3\u79d2\u7ea7\u4ee5\u4e0a&#xff0c;\u518d\u52a0\u4e0a\u4e0b\u6587\u5207\u6362\u5c31\u662f\u5fae\u79d2\u7ea7&#xff1b;\u540e\u8005\u65e0\u7ade\u4e89\u65f6\u5728\u7eb3\u79d2\u7ea7&#xff09;\u3002futex&#xff08;Fast Userspace muTEX&#xff0c;2002 \u5e74\u8fdb\u5165 Linux 2.5&#xff09;\u7684\u601d\u8def\u662f&#xff1a;\u9501\u7684\u72b6\u6001\u653e\u5728\u7528\u6237\u5185\u5b58\u91cc&#xff0c;\u53ea\u6709\u771f\u8981\u7761\u89c9\u6216\u771f\u8981\u53eb\u9192\u4eba\u65f6\u624d\u8fdb\u5185\u6838\u3002<\/p>\n<p>futex \u53ea\u6709\u4e24\u4e2a\u6838\u5fc3\u64cd\u4f5c&#xff1a;<\/p>\n<ul>\n<li>futex_wait(addr, expected)&#xff1a;\u5185\u6838\u5728\u6301\u6709\u8be5\u5730\u5740\u5bf9\u5e94\u54c8\u5e0c\u6876\u9501\u7684\u60c5\u51b5\u4e0b\u68c0\u67e5 *addr &#061;&#061; expected&#xff0c;\u76f8\u7b49\u624d\u8ba9\u8c03\u7528\u8005\u7761\u4e0b&#xff1b;\u4e0d\u7b49\u5c31\u7acb\u5373\u8fd4\u56de EAGAIN\u3002<\/li>\n<li>futex_wake(addr, n)&#xff1a;\u5524\u9192\u6700\u591a n \u4e2a\u7761\u5728 addr \u4e0a\u7684\u7ebf\u7a0b\u3002<\/li>\n<\/ul>\n<p>&#034;\u68c0\u67e5\u503c&#034;\u548c&#034;\u5165\u961f\u7761\u7720&#034;\u5728\u5185\u6838\u91cc\u662f\u539f\u5b50\u7684\u2014\u2014\u8fd9\u4e0e 1.2 \u4e2d&#034;\u5148\u5165\u961f\u518d\u67e5\u6761\u4ef6&#034;\u662f\u540c\u4e00\u4e2a\u9632\u4e22\u5931\u5524\u9192\u7684\u6280\u5de7&#xff0c;\u53ea\u4e0d\u8fc7\u628a&#034;\u6761\u4ef6&#034;\u6362\u6210\u4e86\u4e00\u4e2a\u7528\u6237\u6001\u6574\u6570\u3002<\/p>\n<p>Ulrich Drepper \u5728 Futexes Are Tricky \u91cc\u7ed9\u51fa\u7684\u7ecf\u5178\u4e92\u65a5\u9501&#xff0c;\u7528\u4e09\u4e2a\u72b6\u6001&#xff1a;0 \u7a7a\u95f2\u30011 \u5df2\u9501\u65e0\u7b49\u5f85\u8005\u30012 \u5df2\u9501\u4e14\u53ef\u80fd\u6709\u7b49\u5f85\u8005&#xff1a;<\/p>\n<p><span class=\"token keyword\">void<\/span> <span class=\"token function\">lock<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> <span class=\"token operator\">*<\/span>f<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">int<\/span> c <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">cmpxchg<\/span><span class=\"token punctuation\">(<\/span>f<span class=\"token punctuation\">,<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>           <span class=\"token comment\">\/\/ \u5feb\u901f\u8def\u5f84&#xff1a;0 \u2192 1&#xff0c;\u7eaf\u7528\u6237\u6001<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>c <span class=\"token operator\">!&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>c <span class=\"token operator\">!&#061;<\/span> <span class=\"token number\">2<\/span><span class=\"token punctuation\">)<\/span> c <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">xchg<\/span><span class=\"token punctuation\">(<\/span>f<span class=\"token punctuation\">,<\/span> <span class=\"token number\">2<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>     <span class=\"token comment\">\/\/ \u6807\u8bb0&#034;\u6709\u4eba\u5728\u7b49&#034;<\/span><br \/>\n        <span class=\"token keyword\">while<\/span> <span class=\"token punctuation\">(<\/span>c <span class=\"token operator\">!&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n            <span class=\"token function\">futex_wait<\/span><span class=\"token punctuation\">(<\/span>f<span class=\"token punctuation\">,<\/span> <span class=\"token number\">2<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>           <span class=\"token comment\">\/\/ \u6162\u901f\u8def\u5f84&#xff1a;\u8fdb\u5185\u6838\u7761<\/span><br \/>\n            c <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">xchg<\/span><span class=\"token punctuation\">(<\/span>f<span class=\"token punctuation\">,<\/span> <span class=\"token number\">2<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token keyword\">void<\/span> <span class=\"token function\">unlock<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> <span class=\"token operator\">*<\/span>f<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token function\">atomic_dec<\/span><span class=\"token punctuation\">(<\/span>f<span class=\"token punctuation\">)<\/span> <span class=\"token operator\">!&#061;<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span>           <span class=\"token comment\">\/\/ \u539f\u6765\u662f 2&#xff1a;\u53ef\u80fd\u6709\u4eba\u5728\u7b49<\/span><br \/>\n        <span class=\"token operator\">*<\/span>f <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token function\">futex_wake<\/span><span class=\"token punctuation\">(<\/span>f<span class=\"token punctuation\">,<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>               <span class=\"token comment\">\/\/ \u8fdb\u5185\u6838\u53eb\u9192\u4e00\u4e2a<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span>                                   <span class=\"token comment\">\/\/ \u539f\u6765\u662f 1&#xff1a;\u65e0\u4eba\u7b49\u5f85&#xff0c;\u7eaf\u7528\u6237\u6001\u8fd4\u56de<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>     \u7ebf\u7a0b B<\/p>\n<p>     \u5185\u6838 futex<\/p>\n<p>     \u7528\u6237\u5185\u5b58 f<\/p>\n<p>     \u7ebf\u7a0b A<\/p>\n<p>      \u7ebf\u7a0b B<\/p>\n<p>      \u5185\u6838 futex<\/p>\n<p>      \u7528\u6237\u5185\u5b58 f<\/p>\n<p>      \u7ebf\u7a0b A<\/p>\n<p>  #mermaid-svg-mlIS5NiETSWFRIQA{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-mlIS5NiETSWFRIQA .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-mlIS5NiETSWFRIQA .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-mlIS5NiETSWFRIQA .error-icon{fill:#552222;}#mermaid-svg-mlIS5NiETSWFRIQA .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-mlIS5NiETSWFRIQA .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-mlIS5NiETSWFRIQA .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-mlIS5NiETSWFRIQA .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-mlIS5NiETSWFRIQA .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-mlIS5NiETSWFRIQA .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-mlIS5NiETSWFRIQA .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-mlIS5NiETSWFRIQA .marker{fill:#333333;stroke:#333333;}#mermaid-svg-mlIS5NiETSWFRIQA .marker.cross{stroke:#333333;}#mermaid-svg-mlIS5NiETSWFRIQA svg{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-mlIS5NiETSWFRIQA p{margin:0;}#mermaid-svg-mlIS5NiETSWFRIQA .actor{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-mlIS5NiETSWFRIQA text.actor&gt;tspan{fill:black;stroke:none;}#mermaid-svg-mlIS5NiETSWFRIQA .actor-line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);}#mermaid-svg-mlIS5NiETSWFRIQA .innerArc{stroke-width:1.5;stroke-dasharray:none;}#mermaid-svg-mlIS5NiETSWFRIQA .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333;}#mermaid-svg-mlIS5NiETSWFRIQA .messageLine1{stroke-width:1.5;stroke-dasharray:2,2;stroke:#333;}#mermaid-svg-mlIS5NiETSWFRIQA #arrowhead path{fill:#333;stroke:#333;}#mermaid-svg-mlIS5NiETSWFRIQA .sequenceNumber{fill:white;}#mermaid-svg-mlIS5NiETSWFRIQA #sequencenumber{fill:#333;}#mermaid-svg-mlIS5NiETSWFRIQA #crosshead path{fill:#333;stroke:#333;}#mermaid-svg-mlIS5NiETSWFRIQA .messageText{fill:#333;stroke:none;}#mermaid-svg-mlIS5NiETSWFRIQA .labelBox{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-mlIS5NiETSWFRIQA .labelText,#mermaid-svg-mlIS5NiETSWFRIQA .labelText&gt;tspan{fill:black;stroke:none;}#mermaid-svg-mlIS5NiETSWFRIQA .loopText,#mermaid-svg-mlIS5NiETSWFRIQA .loopText&gt;tspan{fill:black;stroke:none;}#mermaid-svg-mlIS5NiETSWFRIQA .loopLine{stroke-width:2px;stroke-dasharray:2,2;stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);}#mermaid-svg-mlIS5NiETSWFRIQA .note{stroke:#aaaa33;fill:#fff5ad;}#mermaid-svg-mlIS5NiETSWFRIQA .noteText,#mermaid-svg-mlIS5NiETSWFRIQA .noteText&gt;tspan{fill:black;stroke:none;}#mermaid-svg-mlIS5NiETSWFRIQA .activation0{fill:#f4f4f4;stroke:#666;}#mermaid-svg-mlIS5NiETSWFRIQA .activation1{fill:#f4f4f4;stroke:#666;}#mermaid-svg-mlIS5NiETSWFRIQA .activation2{fill:#f4f4f4;stroke:#666;}#mermaid-svg-mlIS5NiETSWFRIQA .actorPopupMenu{position:absolute;}#mermaid-svg-mlIS5NiETSWFRIQA .actorPopupMenuPanel{position:absolute;fill:#ECECFF;box-shadow:0px 8px 16px 0px rgba(0,0,0,0.2);filter:drop-shadow(3px 5px 2px rgb(0 0 0 \/ 0.4));}#mermaid-svg-mlIS5NiETSWFRIQA .actor-man line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-mlIS5NiETSWFRIQA .actor-man circle,#mermaid-svg-mlIS5NiETSWFRIQA line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;stroke-width:2px;}#mermaid-svg-mlIS5NiETSWFRIQA :root{&#8211;mermaid-font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;}<\/p>\n<p>   cmpxchg 0\u21921 \u6210\u529f<\/p>\n<p>   &#xff08;\u65e0\u7cfb\u7edf\u8c03\u7528&#xff09;<\/p>\n<p>   cmpxchg 0\u21921 \u5931\u8d25<\/p>\n<p>   xchg \u7f6e\u4e3a 2<\/p>\n<p>   futex_wait(f, 2)<\/p>\n<p>   \u68c0\u67e5 *f &#061;&#061; 2<\/p>\n<p>   B \u5165\u961f\u5e76\u7761\u7720<\/p>\n<p>   atomic_dec&#xff1a;2\u21921<\/p>\n<p>   \u4e0d\u662f 1&#xff0c;\u8bf4\u660e\u6709\u7b49\u5f85\u8005<\/p>\n<p>   *f &#061; 0<\/p>\n<p>   futex_wake(f, 1)<\/p>\n<p>   B \u56de\u5230\u8fd0\u884c\u961f\u5217<\/p>\n<p>   xchg \u7f6e\u4e3a 2&#xff0c;\u62ff\u5230\u9501<\/p>\n<p>\u8fd9\u5f20\u56fe\u56de\u7b54&#xff1a;futex \u9501\u5728\u4ec0\u4e48\u65f6\u5019\u624d\u8fdb\u5185\u6838&#xff1f;<\/p>\n<p>\u7ed3\u8bba&#xff1a;\u65e0\u7ade\u4e89\u65f6\u52a0\u9501\u548c\u89e3\u9501\u90fd\u4e0d\u8fdb\u5185\u6838&#xff1b;\u53ea\u6709&#034;\u771f\u8981\u7761&#034;\u548c&#034;\u771f\u8981\u53eb\u9192\u4eba&#034;\u624d\u6709\u7528\u6237\u6001\/\u5185\u6838\u6001\u5207\u6362\u3002 \u8fd9\u5c31\u662f&#034;\u9501\u672c\u8eab\u4e0d\u8d35&#xff0c;\u7ade\u4e89\u624d\u8d35&#034;\u7684\u7269\u7406\u539f\u56e0\u3002<\/p>\n<h4>1.6 \u6761\u4ef6\u53d8\u91cf&#xff1a;pthread_cond \u7684\u9aa8\u67b6<\/h4>\n<p>\u6761\u4ef6\u53d8\u91cf\u7684\u96be\u70b9\u662f wait \u5fc5\u987b\u539f\u5b50\u5730&#034;\u91ca\u653e\u4e92\u65a5\u9501 &#043; \u7761\u4e0b&#034;\u3002\u7528 futex \u53ef\u4ee5\u8fd9\u6837\u505a&#xff08;\u7b80\u5316\u7248&#xff09;&#xff1a;<\/p>\n<p><span class=\"token keyword\">void<\/span> <span class=\"token function\">cond_wait<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">cond_t<\/span> <span class=\"token operator\">*<\/span>cv<span class=\"token punctuation\">,<\/span> <span class=\"token class-name\">mutex_t<\/span> <span class=\"token operator\">*<\/span>m<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">int<\/span> seq <span class=\"token operator\">&#061;<\/span> cv<span class=\"token operator\">-&gt;<\/span>seq<span class=\"token punctuation\">;<\/span>          <span class=\"token comment\">\/\/ \u2460 \u8bb0\u4e0b\u5f53\u524d&#034;\u4fe1\u53f7\u5e8f\u53f7&#034;<\/span><br \/>\n    <span class=\"token function\">mutex_unlock<\/span><span class=\"token punctuation\">(<\/span>m<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>            <span class=\"token comment\">\/\/ \u2461 \u91ca\u653e\u4e92\u65a5\u9501<\/span><br \/>\n    <span class=\"token function\">futex_wait<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">&amp;<\/span>cv<span class=\"token operator\">-&gt;<\/span>seq<span class=\"token punctuation\">,<\/span> seq<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u2462 \u5e8f\u53f7\u6ca1\u53d8\u624d\u7761<\/span><br \/>\n    <span class=\"token function\">mutex_lock<\/span><span class=\"token punctuation\">(<\/span>m<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>              <span class=\"token comment\">\/\/ \u2463 \u9192\u6765\u540e\u91cd\u65b0\u62a2\u9501&#xff08;Mesa&#xff09;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token keyword\">void<\/span> <span class=\"token function\">cond_signal<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">cond_t<\/span> <span class=\"token operator\">*<\/span>cv<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token function\">atomic_inc<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">&amp;<\/span>cv<span class=\"token operator\">-&gt;<\/span>seq<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>       <span class=\"token comment\">\/\/ \u6539\u5e8f\u53f7<\/span><br \/>\n    <span class=\"token function\">futex_wake<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">&amp;<\/span>cv<span class=\"token operator\">-&gt;<\/span>seq<span class=\"token punctuation\">,<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>    <span class=\"token comment\">\/\/ \u53eb\u9192\u4e00\u4e2a<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u5982\u679c signal \u6070\u597d\u53d1\u751f\u5728 \u2461 \u548c \u2462 \u4e4b\u95f4&#xff0c;\u5e8f\u53f7\u5df2\u7ecf\u53d8\u4e86&#xff0c;\u2462 \u7684 futex_wait \u4f1a\u7acb\u5373\u8fd4\u56de&#xff0c;\u4fe1\u53f7\u4e0d\u4f1a\u4e22\u3002\u2463 \u4f53\u73b0\u4e86 Mesa \u8bed\u4e49&#xff1a;\u9192\u6765\u7684\u7ebf\u7a0b\u8981\u91cd\u65b0\u7ade\u4e89\u4e92\u65a5\u9501&#xff0c;\u6240\u4ee5\u8c03\u7528\u65b9\u5fc5\u987b while (!cond) pthread_cond_wait(&#8230;)\u3002<\/p>\n<p>\u771f\u5b9e\u7684 glibc \u5b9e\u73b0&#xff08;2.25 \u8d77\u7684\u65b0\u7b97\u6cd5&#xff09;\u6bd4\u8fd9\u590d\u6742\u5f97\u591a&#xff1a;\u5b83\u628a\u7b49\u5f85\u8005\u5206\u6210\u4e24\u7ec4\u6765\u4fdd\u8bc1 signal \u4e0d\u4f1a\u5524\u9192&#034;\u6bd4\u5b83\u66f4\u665a\u5f00\u59cb\u7b49\u5f85&#034;\u7684\u7ebf\u7a0b&#xff0c;\u8fd8\u8981\u5904\u7406\u5e8f\u53f7\u56de\u7ed5\u548c\u53d6\u6d88\u3002\u4f46\u9aa8\u67b6\u5c31\u662f\u4e0a\u9762\u8fd9\u56db\u6b65\u3002<\/p>\n<h3>\u7b2c\u4e8c\u90e8\u5206&#xff1a;Java \u7684\u7ba1\u7a0b\u662f\u600e\u4e48\u5b9e\u73b0\u7684<\/h3>\n<p>Java \u8bed\u8a00\u5c42\u9762&#034;\u6bcf\u4e2a\u5bf9\u8c61\u90fd\u662f\u7ba1\u7a0b&#034;&#xff0c;\u4f46\u7269\u7406\u4e0a\u5e76\u4e0d\u662f\u6bcf\u4e2a\u5bf9\u8c61\u90fd\u5e26\u7740\u4e00\u4e2a\u7ba1\u7a0b\u2014\u2014\u90a3\u6837\u5185\u5b58\u5f00\u9500\u65e0\u6cd5\u627f\u53d7\u3002HotSpot \u7684\u505a\u6cd5\u662f&#xff1a;\u9501\u72b6\u6001\u5148\u6324\u5728\u5bf9\u8c61\u5934\u7684 64 \u4f4d\u91cc&#xff0c;\u53ea\u6709\u771f\u6b63\u9700\u8981\u6392\u961f\u65f6&#xff0c;\u624d\u5206\u914d\u4e00\u4e2a ObjectMonitor \u7ed3\u6784\u3002<\/p>\n<h4>2.1 \u5b57\u8282\u7801\u5165\u53e3&#xff1a;monitorenter \/ monitorexit<\/h4>\n<p>synchronized \u4ee3\u7801\u5757\u7f16\u8bd1\u6210\u4e00\u5bf9\u5b57\u8282\u7801 monitorenter \/ monitorexit&#xff0c;\u7f16\u8bd1\u5668\u8fd8\u4f1a\u989d\u5916\u751f\u6210\u4e00\u4e2a\u5f02\u5e38\u5904\u7406\u5668&#xff0c;\u4fdd\u8bc1\u629b\u5f02\u5e38\u65f6\u4e5f\u6267\u884c monitorexit\u2014\u2014\u8fd9\u5c31\u662f&#034;\u7f16\u8bd1\u5668\u66ff\u4f60\u91ca\u653e\u9501&#034;\u7684\u5b9e\u73b0\u3002synchronized \u65b9\u6cd5\u4e0d\u751f\u6210\u8fd9\u4e24\u6761\u5b57\u8282\u7801&#xff0c;\u800c\u662f\u5728\u65b9\u6cd5\u6807\u5fd7\u4e0a\u7f6e ACC_SYNCHRONIZED&#xff0c;\u7531 JVM \u5728\u8c03\u7528\u548c\u8fd4\u56de\u65f6\u52a0\u89e3\u9501\u3002\u7ba1\u7a0b\u7406\u8bba\u91cc&#034;\u52a0\u9501\u7531\u7f16\u8bd1\u5668\u63d2\u5165&#xff0c;\u7a0b\u5e8f\u5458\u5fd8\u4e0d\u4e86&#034;&#xff0c;\u5728\u8fd9\u91cc\u4e00\u5b57\u4e0d\u5dee\u5730\u843d\u5730\u4e86\u3002<\/p>\n<h4>2.2 \u5bf9\u8c61\u5934\u7684 Mark Word<\/h4>\n<p>64 \u4f4d HotSpot \u4e2d&#xff0c;\u6bcf\u4e2a\u5bf9\u8c61\u5934\u7684\u7b2c\u4e00\u4e2a\u5b57\u662f Mark Word\u3002\u5b83\u7684\u6700\u4f4e 2 \u4f4d&#xff08;\u52a0\u4e0a\u66fe\u7ecf\u7684 1 \u4f4d\u504f\u5411\u6807\u5fd7&#xff09;\u51b3\u5b9a\u5176\u4f59\u4f4d\u7684\u542b\u4e49\u3002\u4e0b\u8868\u662f\u672a\u5f00\u542f\u7d27\u51d1\u5bf9\u8c61\u5934\u65f6\u7684\u7ecf\u5178\u5e03\u5c40&#xff1a;<\/p>\n<table>\n<tr>\u9501\u72b6\u6001\u9ad8\u4f4d\u5185\u5bb9\u504f\u5411\u4f4d\u9501\u6807\u5fd7&#xff08;\u6700\u4f4e 2 \u4f4d&#xff09;<\/tr>\n<tbody>\n<tr>\n<td>\u65e0\u9501<\/td>\n<td>25 \u4f4d\u672a\u7528 \u00b7 31 \u4f4d identity hash \u00b7 1 \u4f4d\u672a\u7528 \u00b7 4 \u4f4d GC \u5e74\u9f84<\/td>\n<td>0<\/td>\n<td>01<\/td>\n<\/tr>\n<tr>\n<td>\u504f\u5411\u9501&#xff08;\u5df2\u79fb\u9664&#xff09;<\/td>\n<td>54 \u4f4d\u6301\u6709\u7ebf\u7a0b\u6307\u9488 \u00b7 2 \u4f4d epoch \u00b7 1 \u4f4d\u672a\u7528 \u00b7 4 \u4f4d GC \u5e74\u9f84<\/td>\n<td>1<\/td>\n<td>01<\/td>\n<\/tr>\n<tr>\n<td>\u8f7b\u91cf\u7ea7\u9501&#xff08;\u65e7\u5b9e\u73b0&#xff09;<\/td>\n<td>62 \u4f4d&#xff1a;\u6307\u5411\u6808\u4e0a\u9501\u8bb0\u5f55\u7684\u6307\u9488<\/td>\n<td>\u2014<\/td>\n<td>00<\/td>\n<\/tr>\n<tr>\n<td>\u91cd\u91cf\u7ea7\u9501<\/td>\n<td>62 \u4f4d&#xff1a;\u6307\u5411 ObjectMonitor \u7684\u6307\u9488<\/td>\n<td>\u2014<\/td>\n<td>10<\/td>\n<\/tr>\n<tr>\n<td>GC \u6807\u8bb0<\/td>\n<td>GC \u4f7f\u7528<\/td>\n<td>\u2014<\/td>\n<td>11<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u4e24\u70b9\u8981\u6ce8\u610f&#xff1a;<\/p>\n<ul>\n<li>\u4e00\u4e2a\u5b57\u88ab\u53cd\u590d\u590d\u7528&#xff0c;\u610f\u5473\u7740 identity hash\u3001GC \u5e74\u9f84\u8fd9\u4e9b\u4fe1\u606f\u5728\u52a0\u9501\u65f6\u4f1a\u88ab&#034;\u6324\u8d70&#034;&#xff0c;\u5fc5\u987b\u53e6\u627e\u5730\u65b9\u6682\u5b58&#xff08;\u65e7\u8f7b\u91cf\u7ea7\u9501\u5b58\u5230\u6808\u4e0a\u7684&#034;displaced header&#034;&#xff0c;\u91cd\u91cf\u7ea7\u9501\u5b58\u5230 ObjectMonitor \u91cc&#xff09;\u3002<\/li>\n<li>\u7d27\u51d1\u5bf9\u8c61\u5934&#xff08;JEP 450 \u5728 JDK 24 \u5b9e\u9a8c\u6027\u5f15\u5165&#xff0c;JEP 519 \u5728 JDK 25 \u8f6c\u6b63&#xff09;\u628a\u5bf9\u8c61\u5934\u538b\u7f29\u5230 64 \u4f4d&#xff0c;\u5e03\u5c40\u968f\u4e4b\u6539\u53d8&#xff1b;\u5b83\u8981\u6c42\u914d\u5408\u4e0b\u9762\u63d0\u5230\u7684\u65b0\u8f7b\u91cf\u7ea7\u9501\u548c&#034;ObjectMonitor \u8868&#034;\u3002\u4e0a\u8868\u662f\u7406\u89e3\u539f\u7406\u7528\u7684\u7ecf\u5178\u7248\u672c\u3002<\/li>\n<\/ul>\n<h4>2.3 \u9501\u7684\u51e0\u79cd\u72b6\u6001\u4e0e\u5347\u7ea7\u8def\u5f84<\/h4>\n<p>  #mermaid-svg-mt1GFpg6iytSrpMw{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-mt1GFpg6iytSrpMw .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-mt1GFpg6iytSrpMw .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-mt1GFpg6iytSrpMw .error-icon{fill:#552222;}#mermaid-svg-mt1GFpg6iytSrpMw .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-mt1GFpg6iytSrpMw .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-mt1GFpg6iytSrpMw .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-mt1GFpg6iytSrpMw .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-mt1GFpg6iytSrpMw .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-mt1GFpg6iytSrpMw .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-mt1GFpg6iytSrpMw .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-mt1GFpg6iytSrpMw .marker{fill:#333333;stroke:#333333;}#mermaid-svg-mt1GFpg6iytSrpMw .marker.cross{stroke:#333333;}#mermaid-svg-mt1GFpg6iytSrpMw svg{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-mt1GFpg6iytSrpMw p{margin:0;}#mermaid-svg-mt1GFpg6iytSrpMw defs #statediagram-barbEnd{fill:#333333;stroke:#333333;}#mermaid-svg-mt1GFpg6iytSrpMw g.stateGroup text{fill:#9370DB;stroke:none;font-size:10px;}#mermaid-svg-mt1GFpg6iytSrpMw g.stateGroup text{fill:#333;stroke:none;font-size:10px;}#mermaid-svg-mt1GFpg6iytSrpMw g.stateGroup .state-title{font-weight:bolder;fill:#131300;}#mermaid-svg-mt1GFpg6iytSrpMw g.stateGroup rect{fill:#ECECFF;stroke:#9370DB;}#mermaid-svg-mt1GFpg6iytSrpMw g.stateGroup line{stroke:#333333;stroke-width:1;}#mermaid-svg-mt1GFpg6iytSrpMw .transition{stroke:#333333;stroke-width:1;fill:none;}#mermaid-svg-mt1GFpg6iytSrpMw .stateGroup .composit{fill:white;border-bottom:1px;}#mermaid-svg-mt1GFpg6iytSrpMw .stateGroup .alt-composit{fill:#e0e0e0;border-bottom:1px;}#mermaid-svg-mt1GFpg6iytSrpMw .state-note{stroke:#aaaa33;fill:#fff5ad;}#mermaid-svg-mt1GFpg6iytSrpMw .state-note text{fill:black;stroke:none;font-size:10px;}#mermaid-svg-mt1GFpg6iytSrpMw .stateLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5;}#mermaid-svg-mt1GFpg6iytSrpMw .edgeLabel .label rect{fill:#ECECFF;opacity:0.5;}#mermaid-svg-mt1GFpg6iytSrpMw .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-mt1GFpg6iytSrpMw .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-mt1GFpg6iytSrpMw .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-mt1GFpg6iytSrpMw .edgeLabel .label text{fill:#333;}#mermaid-svg-mt1GFpg6iytSrpMw .label div .edgeLabel{color:#333;}#mermaid-svg-mt1GFpg6iytSrpMw .stateLabel text{fill:#131300;font-size:10px;font-weight:bold;}#mermaid-svg-mt1GFpg6iytSrpMw .node circle.state-start{fill:#333333;stroke:#333333;}#mermaid-svg-mt1GFpg6iytSrpMw .node .fork-join{fill:#333333;stroke:#333333;}#mermaid-svg-mt1GFpg6iytSrpMw .node circle.state-end{fill:#9370DB;stroke:white;stroke-width:1.5;}#mermaid-svg-mt1GFpg6iytSrpMw .end-state-inner{fill:white;stroke-width:1.5;}#mermaid-svg-mt1GFpg6iytSrpMw .node rect{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-mt1GFpg6iytSrpMw .node polygon{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-mt1GFpg6iytSrpMw #statediagram-barbEnd{fill:#333333;}#mermaid-svg-mt1GFpg6iytSrpMw .statediagram-cluster rect{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-mt1GFpg6iytSrpMw .cluster-label,#mermaid-svg-mt1GFpg6iytSrpMw .nodeLabel{color:#131300;}#mermaid-svg-mt1GFpg6iytSrpMw .statediagram-cluster rect.outer{rx:5px;ry:5px;}#mermaid-svg-mt1GFpg6iytSrpMw .statediagram-state .divider{stroke:#9370DB;}#mermaid-svg-mt1GFpg6iytSrpMw .statediagram-state .title-state{rx:5px;ry:5px;}#mermaid-svg-mt1GFpg6iytSrpMw .statediagram-cluster.statediagram-cluster .inner{fill:white;}#mermaid-svg-mt1GFpg6iytSrpMw .statediagram-cluster.statediagram-cluster-alt .inner{fill:#f0f0f0;}#mermaid-svg-mt1GFpg6iytSrpMw .statediagram-cluster .inner{rx:0;ry:0;}#mermaid-svg-mt1GFpg6iytSrpMw .statediagram-state rect.basic{rx:5px;ry:5px;}#mermaid-svg-mt1GFpg6iytSrpMw .statediagram-state rect.divider{stroke-dasharray:10,10;fill:#f0f0f0;}#mermaid-svg-mt1GFpg6iytSrpMw .note-edge{stroke-dasharray:5;}#mermaid-svg-mt1GFpg6iytSrpMw .statediagram-note rect{fill:#fff5ad;stroke:#aaaa33;stroke-width:1px;rx:0;ry:0;}#mermaid-svg-mt1GFpg6iytSrpMw .statediagram-note rect{fill:#fff5ad;stroke:#aaaa33;stroke-width:1px;rx:0;ry:0;}#mermaid-svg-mt1GFpg6iytSrpMw .statediagram-note text{fill:black;}#mermaid-svg-mt1GFpg6iytSrpMw .statediagram-note .nodeLabel{color:black;}#mermaid-svg-mt1GFpg6iytSrpMw .statediagram .edgeLabel{color:red;}#mermaid-svg-mt1GFpg6iytSrpMw #dependencyStart,#mermaid-svg-mt1GFpg6iytSrpMw #dependencyEnd{fill:#333333;stroke:#333333;stroke-width:1;}#mermaid-svg-mt1GFpg6iytSrpMw .statediagramTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-mt1GFpg6iytSrpMw :root{&#8211;mermaid-font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;}<\/p>\n<p>         <span class=\"edgeLabel\"><\/span><\/p>\n<p>         <span class=\"edgeLabel\"><\/p>\n<p>CAS \u6539\u9501\u4f4d\u6210\u529f<\/p>\n<p><\/span><\/p>\n<p>         <span class=\"edgeLabel\"><\/p>\n<p>\u9000\u51fa\u65f6 CAS \u8fd8\u539f<\/p>\n<p><\/span><\/p>\n<p>         <span class=\"edgeLabel\"><\/p>\n<p>\u51fa\u73b0\u7ade\u4e89\u6216\u8c03\u7528 wait()<\/p>\n<p><\/span><\/p>\n<p>         <span class=\"edgeLabel\"><\/p>\n<p>\u76f4\u63a5\u7ade\u4e89\u6216\u8c03\u7528 wait()<\/p>\n<p><\/span><\/p>\n<p>         <span class=\"edgeLabel\"><\/p>\n<p>\u7a7a\u95f2\u540e\u88ab\u5f02\u6b65\u6536\u7f29&#xff08;deflation&#xff09;<\/p>\n<p><\/span><\/p>\n<p>         <span class=\"nodeLabel\"><\/p>\n<p>\u65e0\u9501<\/p>\n<p><\/span><\/p>\n<p>         <span class=\"nodeLabel\"><\/p>\n<p>\u8f7b\u91cf\u7ea7\u9501<\/p>\n<p><\/span><\/p>\n<p>         <span class=\"nodeLabel\"><\/p>\n<p>\u91cd\u91cf\u7ea7\u9501<\/p>\n<p><\/span><\/p>\n<p>\u8fd9\u5f20\u56fe\u56de\u7b54&#xff1a;\u4e00\u4e2a\u5bf9\u8c61\u7684\u9501\u72b6\u6001\u5982\u4f55\u5728\u65e0\u9501\u3001\u8f7b\u91cf\u7ea7\u3001\u91cd\u91cf\u7ea7\u4e4b\u95f4\u8fc1\u79fb&#xff1f;&#xff08;\u504f\u5411\u9501\u5df2\u79fb\u9664&#xff0c;\u672a\u753b\u51fa&#xff09;<\/p>\n<p>\u504f\u5411\u9501&#xff08;\u5386\u53f2&#xff09;\u3002 \u89c2\u5bdf\u4f9d\u636e\u662f&#xff1a;\u5927\u591a\u6570\u9501\u4ece\u5934\u5230\u5c3e\u53ea\u88ab\u4e00\u4e2a\u7ebf\u7a0b\u7528\u3002\u7b2c\u4e00\u6b21\u52a0\u9501\u65f6\u7528\u4e00\u6b21 CAS \u628a\u7ebf\u7a0b ID \u5199\u8fdb Mark Word&#xff0c;\u4ee5\u540e\u540c\u4e00\u7ebf\u7a0b\u518d\u8fdb\u5165&#xff0c;\u53ea\u9700\u6bd4\u8f83\u7ebf\u7a0b ID&#xff0c;\u8fde CAS \u90fd\u4e0d\u7528\u3002\u4ee3\u4ef7\u5728\u64a4\u9500&#xff1a;\u53e6\u4e00\u4e2a\u7ebf\u7a0b\u6765\u62a2\u65f6&#xff0c;\u5fc5\u987b\u5728\u5b89\u5168\u70b9&#xff08;safepoint&#xff09;\u6682\u505c\u6301\u6709\u8005&#xff0c;\u68c0\u67e5\u5b83\u7684\u6808\u6765\u5224\u65ad\u662f\u5426\u8fd8\u6301\u6709\u9501\u3002\u968f\u7740\u73b0\u4ee3 CPU \u4e0a\u65e0\u7ade\u4e89 CAS \u8d8a\u6765\u8d8a\u4fbf\u5b9c&#xff0c;\u800c\u64a4\u9500\u53c8\u8d35\u3001\u4ee3\u7801\u53c8\u590d\u6742&#xff0c;\u504f\u5411\u9501\u5728 JDK 15 \u88ab\u9ed8\u8ba4\u5173\u95ed\u5e76\u5e9f\u5f03&#xff08;JEP 374&#xff09;&#xff0c;JDK 18 \u4e2d\u76f8\u5173\u53c2\u6570\u88ab\u6dd8\u6c70\u3001\u5b9e\u73b0\u88ab\u79fb\u9664\u3002\u4eca\u5929\u8bb2&#034;\u504f\u5411 \u2192 \u8f7b\u91cf \u2192 \u91cd\u91cf&#034;\u4e09\u6bb5\u5347\u7ea7&#xff0c;\u662f\u5728\u8bb2 JDK 15 \u4e4b\u524d\u7684\u9ed8\u8ba4\u884c\u4e3a\u3002<\/p>\n<p>\u8f7b\u91cf\u7ea7\u9501&#xff08;\u65e7\u5b9e\u73b0&#xff0c;\u201c\u6808\u9501\u201d&#xff09;\u3002 \u7ebf\u7a0b\u5728\u5f53\u524d\u6808\u5e27\u91cc\u5206\u914d\u4e00\u4e2a\u9501\u8bb0\u5f55&#xff08;lock record&#xff09;&#xff0c;\u628a\u5bf9\u8c61\u539f\u6765\u7684 Mark Word \u590d\u5236\u8fdb\u53bb&#xff08;displaced header&#xff09;&#xff0c;\u7136\u540e CAS \u628a Mark Word \u6539\u6210\u6307\u5411\u8fd9\u4e2a\u9501\u8bb0\u5f55\u7684\u6307\u9488\u3001\u9501\u4f4d 00\u3002\u91cd\u5165\u65f6\u518d\u538b\u4e00\u4e2a displaced header \u4e3a\u7a7a\u7684\u9501\u8bb0\u5f55\u5373\u53ef\u3002\u89e3\u9501\u65f6 CAS \u628a displaced header \u6362\u56de\u53bb\u3002\u5168\u7a0b\u53ea\u6709\u7528\u6237\u6001 CAS&#xff0c;\u6ca1\u6709\u7cfb\u7edf\u8c03\u7528\u3002<\/p>\n<p>\u8f7b\u91cf\u7ea7\u9501&#xff08;\u65b0\u5b9e\u73b0&#xff0c;lock-stack&#xff09;\u3002 JDK 21 \u5f15\u5165\u3001JDK 23 \u8d77\u6210\u4e3a\u9ed8\u8ba4&#xff08;LockingMode \u9ed8\u8ba4\u503c\u6539\u4e3a lightweight&#xff09;\u3002\u6bcf\u4e2a\u7ebf\u7a0b\u6709\u4e00\u4e2a\u5c0f\u6570\u7ec4&#034;\u9501\u6808&#034;&#xff08;lock-stack&#xff09;&#xff0c;\u52a0\u9501\u65f6 CAS \u53ea\u628a Mark Word \u7684\u9501\u4f4d\u4ece 01 \u6539\u6210 00&#xff0c;\u5e76\u628a\u5bf9\u8c61\u5f15\u7528\u538b\u8fdb\u81ea\u5df1\u7684\u9501\u6808&#xff1b;Mark Word \u7684\u5176\u4f59\u4f4d&#xff08;hash\u3001\u5e74\u9f84&#xff09;\u539f\u6837\u4fdd\u7559&#xff0c;\u4e0d\u518d\u6709\u6307\u5411\u6808\u7684\u6307\u9488\u3002\u5224\u65ad&#034;\u662f\u4e0d\u662f\u6211\u6301\u6709&#034;\u53ea\u9700\u67e5\u81ea\u5df1\u7684\u9501\u6808\u3002\u8fd9\u6837\u505a\u7684\u52a8\u673a\u4e4b\u4e00&#xff0c;\u662f\u7ed9\u7d27\u51d1\u5bf9\u8c61\u5934\u548c\u865a\u62df\u7ebf\u7a0b\u8ba9\u8def\u2014\u2014\u6307\u5411\u67d0\u4e2a\u7ebf\u7a0b\u6808\u7684\u6307\u9488\u5728\u8fd9\u4e24\u79cd\u573a\u666f\u4e0b\u90fd\u5f88\u788d\u4e8b\u3002<\/p>\n<p>\u81a8\u80c0\u4e3a\u91cd\u91cf\u7ea7\u9501\u3002 \u4ee5\u4e0b\u60c5\u51b5\u4f1a\u89e6\u53d1 inflate&#xff1a;<\/p>\n<ul>\n<li>\u8f7b\u91cf\u7ea7\u52a0\u9501\u7684 CAS \u5931\u8d25&#xff08;\u6709\u7ade\u4e89&#xff09;&#xff1b;<\/li>\n<li>\u6301\u9501\u7ebf\u7a0b\u8c03\u7528\u4e86 wait()\u2014\u2014\u8f7b\u91cf\u7ea7\u9501\u6ca1\u6709 wait set&#xff0c;\u5fc5\u987b\u6709 ObjectMonitor&#xff1b;<\/li>\n<li>\u9501\u6808\u6ee1\u4e86&#xff0c;\u6216\u5176\u4ed6\u5b9e\u73b0\u4e0a\u7684\u9650\u5236\u3002<\/li>\n<\/ul>\n<p>\u81a8\u80c0\u65f6\u5206\u914d&#xff08;\u6216\u4ece\u7f13\u5b58\u53d6\u51fa&#xff09;\u4e00\u4e2a ObjectMonitor&#xff0c;\u628a Mark Word \u6539\u4e3a\u6307\u5411\u5b83\u3001\u9501\u4f4d 10\u3002JDK 24 \u8d77\u8fd8\u53ef\u4ee5\u7528 -XX:&#043;UseObjectMonitorTable \u628a&#034;\u5bf9\u8c61 \u2192 \u76d1\u89c6\u5668&#034;\u7684\u6620\u5c04\u653e\u8fdb\u4e00\u5f20\u65c1\u8def\u54c8\u5e0c\u8868&#xff0c;\u4e0d\u518d\u6539\u5199 Mark Word&#xff08;\u7d27\u51d1\u5bf9\u8c61\u5934\u9700\u8981\u8fd9\u4e2a\u80fd\u529b&#xff09;\u3002<\/p>\n<p>\u9501\u4f1a\u964d\u7ea7\u5417&#xff1f; \u5e38\u89c1\u8bf4\u6cd5\u662f&#034;\u9501\u53ea\u80fd\u5347\u7ea7\u4e0d\u80fd\u964d\u7ea7&#034;\u3002\u5bf9\u5355\u6b21\u6301\u6709\u8fc7\u7a0b\u6765\u8bf4\u5927\u4f53\u5982\u6b64&#xff0c;\u4f46 ObjectMonitor \u5e76\u4e0d\u6c38\u4e45\u7ed1\u5b9a\u5728\u5bf9\u8c61\u4e0a&#xff1a;JDK 15 \u8d77\u6709\u4e13\u95e8\u7684\u7ebf\u7a0b**\u5f02\u6b65\u6536\u7f29&#xff08;deflate&#xff09;**\u7a7a\u95f2\u7684\u76d1\u89c6\u5668&#xff0c;\u628a\u5bf9\u8c61\u6062\u590d\u4e3a\u65e0\u9501\u72b6\u6001&#xff0c;\u76d1\u89c6\u5668\u56de\u6536\u590d\u7528\u3002\u6240\u4ee5\u66f4\u51c6\u786e\u7684\u8bf4\u6cd5\u662f&#xff1a;\u5728\u6301\u6709\u671f\u95f4\u4e0d\u964d\u7ea7&#xff0c;\u7a7a\u95f2\u540e\u4f1a\u88ab\u6536\u7f29\u3002<\/p>\n<h4>2.4 ObjectMonitor&#xff1a;\u7ba1\u7a0b\u7684\u5b8c\u6574\u5f62\u6001<\/h4>\n<p>ObjectMonitor \u662f C&#043;&#043; \u5bf9\u8c61&#xff0c;\u5c31\u662f\u6559\u79d1\u4e66\u7ba1\u7a0b\u5728 HotSpot \u91cc\u7684\u5b9e\u4f53\u3002\u7ecf\u5178\u7248\u672c&#xff08;JDK 8\u201321 \u4e00\u5e26&#xff09;\u7684\u5173\u952e\u5b57\u6bb5&#xff1a;<\/p>\n<table>\n<tr>\u5b57\u6bb5\u4f5c\u7528\u5bf9\u5e94\u7ba1\u7a0b\u6982\u5ff5<\/tr>\n<tbody>\n<tr>\n<td>_owner<\/td>\n<td>\u5f53\u524d\u6301\u6709\u8005<\/td>\n<td>\u7ba1\u7a0b\u5185\u7684\u90a3\u4e2a\u7ebf\u7a0b<\/td>\n<\/tr>\n<tr>\n<td>_recursions<\/td>\n<td>\u91cd\u5165\u6b21\u6570<\/td>\n<td>\u53ef\u91cd\u5165<\/td>\n<\/tr>\n<tr>\n<td>_cxq<\/td>\n<td>\u65b0\u6765\u7ade\u4e89\u8005\u7684\u5355\u94fe\u8868&#xff0c;CAS \u5934\u63d2&#xff08;LIFO&#xff09;<\/td>\n<td>\u5165\u53e3\u961f\u5217&#xff08;\u65e0\u9501\u5165\u961f\u90e8\u5206&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>_EntryList<\/td>\n<td>\u89e3\u9501\u8005\u4ece\u4e2d\u6311\u9009\u7ee7\u4efb\u8005\u7684\u53cc\u5411\u94fe\u8868<\/td>\n<td>\u5165\u53e3\u961f\u5217<\/td>\n<\/tr>\n<tr>\n<td>_WaitSet<\/td>\n<td>\u8c03\u7528\u4e86 wait() \u7684\u7ebf\u7a0b\u7684\u73af\u5f62\u53cc\u5411\u94fe\u8868<\/td>\n<td>\u6761\u4ef6\u53d8\u91cf\u7684\u7b49\u5f85\u961f\u5217<\/td>\n<\/tr>\n<tr>\n<td>_succ<\/td>\n<td>\u5df2\u88ab\u9009\u4e3a&#034;\u5047\u5b9a\u7ee7\u4efb\u8005&#034;\u7684\u7ebf\u7a0b<\/td>\n<td>\u907f\u514d\u91cd\u590d\u5524\u9192<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u8f83\u65b0\u7684 JDK \u5bf9\u8fd9\u4e9b\u7ed3\u6784\u505a\u8fc7\u91cd\u6784&#xff08;\u4f8b\u5982\u4e3a JEP 491 \u8ba9 owner \u6539\u4e3a\u8bb0\u5f55\u7ebf\u7a0b ID \u4ee5\u652f\u6301\u865a\u62df\u7ebf\u7a0b&#xff0c;\u5165\u53e3\u961f\u5217\u4e5f\u6709\u5408\u5e76&#xff09;&#xff0c;\u5b57\u6bb5\u540d\u53ef\u80fd\u4e0d\u540c&#xff0c;\u4f46&#034;owner &#043; \u91cd\u5165\u8ba1\u6570 &#043; \u5165\u53e3\u961f\u5217 &#043; \u7b49\u5f85\u96c6\u5408&#034;\u8fd9\u4e2a\u7ed3\u6784\u6ca1\u6709\u53d8\u3002<\/p>\n<p>\u52a0\u9501&#xff08;enter&#xff09;\u7684\u8def\u5f84&#xff0c;\u53c8\u662f\u719f\u6089\u7684\u4e09\u6bb5\u5f0f&#xff1a;<\/p>\n<li>CAS \u62a2 owner&#xff1a;_owner \u4ece\u7a7a\u6539\u6210\u81ea\u5df1&#xff0c;\u6210\u529f\u5373\u8fd4\u56de&#xff1b;\u5982\u679c owner \u5df2\u7ecf\u662f\u81ea\u5df1&#xff0c;_recursions&#043;&#043;\u3002<\/li>\n<li>\u81ea\u9002\u5e94\u81ea\u65cb&#xff1a;\u6839\u636e\u8fd9\u628a\u9501\u8fc7\u53bb\u81ea\u65cb\u6210\u529f\u7684\u5386\u53f2\u51b3\u5b9a\u8f6c\u591a\u4e45&#xff0c;\u8d4c\u6301\u6709\u8005\u9a6c\u4e0a\u91ca\u653e\u3002<\/li>\n<li>\u6392\u961f\u7761\u7720&#xff1a;\u628a\u81ea\u5df1\u5305\u88c5\u6210 ObjectWaiter \u8282\u70b9&#xff0c;CAS \u5934\u63d2\u8fdb _cxq&#xff0c;\u7136\u540e\u5faa\u73af&#034;\u518d\u8bd5\u4e00\u6b21 \u2192 \u4e0d\u884c\u5c31 park&#034;\u3002<\/li>\n<p>\u89e3\u9501&#xff08;exit&#xff09;&#xff1a; _recursions \u4e0d\u4e3a 0 \u5c31\u51cf\u4e00\u8fd4\u56de&#xff1b;\u5426\u5219\u91ca\u653e owner&#xff08;\u5e26\u5185\u5b58\u5c4f\u969c&#xff09;\u3002\u5982\u679c\u6ca1\u6709\u7b49\u5f85\u8005&#xff0c;\u76f4\u63a5\u8fd4\u56de\u2014\u2014\u8fd9\u6761\u8def\u5f84\u4e0a\u4e5f\u6ca1\u6709\u7cfb\u7edf\u8c03\u7528\u3002\u5982\u679c\u6709\u7b49\u5f85\u8005&#xff0c;\u4ece _EntryList \u6311\u4e00\u4e2a\u7ee7\u4efb\u8005&#xff08;_EntryList \u7a7a\u5c31\u5148\u628a _cxq \u6574\u4f53\u642c\u8fc7\u6765&#xff09;&#xff0c;\u53ea unpark \u8fd9\u4e00\u4e2a&#xff0c;\u907f\u514d\u60ca\u7fa4\u3002<\/p>\n<p>\u6ce8\u610f\u7b2c 3 \u6b65\u9192\u6765\u540e\u662f&#034;\u518d\u8bd5\u4e00\u6b21 CAS&#034;&#xff0c;\u800c\u4e0d\u662f\u76f4\u63a5\u62ff\u5230\u9501&#xff1a;\u89e3\u9501\u8005\u53ea\u662f\u628a\u7ee7\u4efb\u8005\u53eb\u9192&#xff0c;\u9501\u672c\u8eab\u662f\u7a7a\u51fa\u6765\u8ba9\u5927\u5bb6\u62a2\u7684\u3002\u65b0\u6765\u7684\u7ebf\u7a0b\u53ef\u80fd\u5728\u7ee7\u4efb\u8005\u9192\u6765\u4e4b\u524d\u5c31 CAS \u6210\u529f&#xff08;\u63d2\u961f&#xff0c;barging&#xff09;\u3002\u8fd9\u8ba9 synchronized \u541e\u5410\u66f4\u9ad8&#xff0c;\u4f46\u5b83\u4e0d\u662f\u516c\u5e73\u9501\u2014\u2014\u60f3\u8981 FIFO&#xff0c;\u53ea\u80fd\u7528 new ReentrantLock(true)\u3002<\/p>\n<h4>2.5 wait \/ notify \u5728 ObjectMonitor \u91cc\u600e\u4e48\u8d70<\/h4>\n<p>     \u7ebf\u7a0b T2<\/p>\n<p>     ObjectMonitor<\/p>\n<p>     \u7ebf\u7a0b T1<\/p>\n<p>      \u7ebf\u7a0b T2<\/p>\n<p>      ObjectMonitor<\/p>\n<p>      \u7ebf\u7a0b T1<\/p>\n<p>  #mermaid-svg-vTbmYb9u5JBrKsOr{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-vTbmYb9u5JBrKsOr .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-vTbmYb9u5JBrKsOr .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-vTbmYb9u5JBrKsOr .error-icon{fill:#552222;}#mermaid-svg-vTbmYb9u5JBrKsOr .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-vTbmYb9u5JBrKsOr .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-vTbmYb9u5JBrKsOr .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-vTbmYb9u5JBrKsOr .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-vTbmYb9u5JBrKsOr .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-vTbmYb9u5JBrKsOr .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-vTbmYb9u5JBrKsOr .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-vTbmYb9u5JBrKsOr .marker{fill:#333333;stroke:#333333;}#mermaid-svg-vTbmYb9u5JBrKsOr .marker.cross{stroke:#333333;}#mermaid-svg-vTbmYb9u5JBrKsOr svg{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-vTbmYb9u5JBrKsOr p{margin:0;}#mermaid-svg-vTbmYb9u5JBrKsOr .actor{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-vTbmYb9u5JBrKsOr text.actor&gt;tspan{fill:black;stroke:none;}#mermaid-svg-vTbmYb9u5JBrKsOr .actor-line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);}#mermaid-svg-vTbmYb9u5JBrKsOr .innerArc{stroke-width:1.5;stroke-dasharray:none;}#mermaid-svg-vTbmYb9u5JBrKsOr .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333;}#mermaid-svg-vTbmYb9u5JBrKsOr .messageLine1{stroke-width:1.5;stroke-dasharray:2,2;stroke:#333;}#mermaid-svg-vTbmYb9u5JBrKsOr #arrowhead path{fill:#333;stroke:#333;}#mermaid-svg-vTbmYb9u5JBrKsOr .sequenceNumber{fill:white;}#mermaid-svg-vTbmYb9u5JBrKsOr #sequencenumber{fill:#333;}#mermaid-svg-vTbmYb9u5JBrKsOr #crosshead path{fill:#333;stroke:#333;}#mermaid-svg-vTbmYb9u5JBrKsOr .messageText{fill:#333;stroke:none;}#mermaid-svg-vTbmYb9u5JBrKsOr .labelBox{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-vTbmYb9u5JBrKsOr .labelText,#mermaid-svg-vTbmYb9u5JBrKsOr .labelText&gt;tspan{fill:black;stroke:none;}#mermaid-svg-vTbmYb9u5JBrKsOr .loopText,#mermaid-svg-vTbmYb9u5JBrKsOr .loopText&gt;tspan{fill:black;stroke:none;}#mermaid-svg-vTbmYb9u5JBrKsOr .loopLine{stroke-width:2px;stroke-dasharray:2,2;stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);}#mermaid-svg-vTbmYb9u5JBrKsOr .note{stroke:#aaaa33;fill:#fff5ad;}#mermaid-svg-vTbmYb9u5JBrKsOr .noteText,#mermaid-svg-vTbmYb9u5JBrKsOr .noteText&gt;tspan{fill:black;stroke:none;}#mermaid-svg-vTbmYb9u5JBrKsOr .activation0{fill:#f4f4f4;stroke:#666;}#mermaid-svg-vTbmYb9u5JBrKsOr .activation1{fill:#f4f4f4;stroke:#666;}#mermaid-svg-vTbmYb9u5JBrKsOr .activation2{fill:#f4f4f4;stroke:#666;}#mermaid-svg-vTbmYb9u5JBrKsOr .actorPopupMenu{position:absolute;}#mermaid-svg-vTbmYb9u5JBrKsOr .actorPopupMenuPanel{position:absolute;fill:#ECECFF;box-shadow:0px 8px 16px 0px rgba(0,0,0,0.2);filter:drop-shadow(3px 5px 2px rgb(0 0 0 \/ 0.4));}#mermaid-svg-vTbmYb9u5JBrKsOr .actor-man line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-vTbmYb9u5JBrKsOr .actor-man circle,#mermaid-svg-vTbmYb9u5JBrKsOr line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;stroke-width:2px;}#mermaid-svg-vTbmYb9u5JBrKsOr :root{&#8211;mermaid-font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;}<\/p>\n<p>   \u6301\u6709\u9501&#xff0c;\u8c03\u7528 wait()<\/p>\n<p>   T1 \u5165 _WaitSet<\/p>\n<p>   \u4fdd\u5b58\u91cd\u5165\u6b21\u6570&#xff0c;\u5f7b\u5e95\u91ca\u653e\u9501<\/p>\n<p>   park&#xff0c;\u7761\u7720<\/p>\n<p>   \u62a2\u5230\u9501&#xff0c;\u4fee\u6539\u72b6\u6001<\/p>\n<p>   notify()<\/p>\n<p>   T1 \u4ece _WaitSet<\/p>\n<p>   \u79fb\u5230\u5165\u53e3\u961f\u5217&#xff08;\u5c1a\u672a\u5524\u9192&#xff09;<\/p>\n<p>   \u9000\u51fa synchronized&#xff0c;\u91ca\u653e\u9501<\/p>\n<p>   \u9009\u4e2d T1 \u4e3a\u7ee7\u4efb\u8005<\/p>\n<p>   unpark<\/p>\n<p>   \u91cd\u65b0\u7ade\u4e89\u9501<\/p>\n<p>   \u6062\u590d\u91cd\u5165\u6b21\u6570<\/p>\n<p>   while \u91cd\u67e5\u6761\u4ef6<\/p>\n<p>\u8fd9\u5f20\u56fe\u56de\u7b54&#xff1a;\u4e00\u6b21 wait\/notify&#xff0c;\u7ebf\u7a0b\u5728 ObjectMonitor \u7684\u54ea\u4e9b\u961f\u5217\u4e4b\u95f4\u79fb\u52a8&#xff0c;\u4f55\u65f6\u771f\u6b63\u88ab\u5524\u9192&#xff1f;<\/p>\n<p>\u51e0\u4e2a\u4ece\u5b9e\u73b0\u91cc\u76f4\u63a5\u8bfb\u51fa\u6765\u7684\u4e8b\u5b9e&#xff1a;<\/p>\n<ul>\n<li>wait() \u5fc5\u987b\u5148\u6301\u9501&#xff1a;\u5b9e\u73b0\u7b2c\u4e00\u6b65\u5c31\u68c0\u67e5 _owner \u662f\u4e0d\u662f\u81ea\u5df1&#xff0c;\u4e0d\u662f\u5c31\u629b IllegalMonitorStateException\u3002<\/li>\n<li>wait() \u91ca\u653e\u7684\u662f&#034;\u5168\u90e8&#034;\u91cd\u5165&#xff1a;\u5148\u628a _recursions \u5b58\u8d77\u6765\u3001\u6e05\u96f6\u3001\u5f7b\u5e95\u9000\u51fa&#xff0c;\u9192\u6765\u91cd\u65b0\u62ff\u5230\u9501\u540e\u518d\u6062\u590d\u2014\u2014\u6240\u4ee5\u5728\u4e09\u5c42\u5d4c\u5957\u7684 synchronized \u91cc\u8c03\u7528 wait() \u4e5f\u4e0d\u4f1a\u6b7b\u9501\u3002<\/li>\n<li>notify() \u4e0d\u7acb\u5373\u5524\u9192\u4efb\u4f55\u4eba&#xff1a;\u5b83\u53ea\u662f\u628a\u7b49\u5f85\u8005\u4ece _WaitSet \u632a\u5230\u5165\u53e3\u961f\u5217\u3002\u88ab\u901a\u77e5\u7684\u7ebf\u7a0b\u8981\u7b49\u901a\u77e5\u8005\u9000\u51fa\u4e34\u754c\u533a\u3001\u5e76\u88ab\u9009\u4e3a\u7ee7\u4efb\u8005&#xff0c;\u624d\u4f1a\u88ab unpark\u3002\u8fd9\u5c31\u662f Mesa \u8bed\u4e49&#xff08;signal-and-continue&#xff09;\u5728\u6e90\u7801\u5c42\u9762\u7684\u6837\u5b50\u3002<\/li>\n<li>\u56e0\u4e3a\u53ea\u6709\u4e00\u4e2a _WaitSet&#xff0c;\u7b49\u4e0d\u540c\u6761\u4ef6\u7684\u7ebf\u7a0b\u6324\u5728\u4e00\u8d77&#xff0c;\u6240\u4ee5\u9ed8\u8ba4\u8981 notifyAll()&#xff1b;\u9700\u8981\u591a\u6761\u4ef6\u5c31\u7528 ReentrantLock &#043; Condition&#xff0c;\u540e\u8005\u6bcf\u4e2a Condition \u6709\u81ea\u5df1\u7684\u7b49\u5f85\u961f\u5217\u3002<\/li>\n<\/ul>\n<h4>2.6 JVM \u600e\u4e48\u8854\u63a5\u5230 OS \u539f\u8bed<\/h4>\n<p>HotSpot \u4e0d\u76f4\u63a5\u8c03\u7528 futex \u7cfb\u7edf\u8c03\u7528&#xff0c;\u800c\u662f\u901a\u8fc7\u5e73\u53f0\u5c42\u5c01\u88c5&#xff1a;<\/p>\n<table>\n<tr>Java \u5c42HotSpot \u5185\u90e8Linux \u4e0a\u843d\u5230<\/tr>\n<tbody>\n<tr>\n<td>synchronized \u7ade\u4e89 \/ wait()<\/td>\n<td>ObjectMonitor \u2192 \u6bcf\u7ebf\u7a0b\u7684 ParkEvent \u2192 os::PlatformEvent::park()<\/td>\n<td>pthread_mutex &#043; pthread_cond_wait<\/td>\n<\/tr>\n<tr>\n<td>LockSupport.park()&#xff08;AQS\u3001ReentrantLock\u3001Condition&#xff09;<\/td>\n<td>\u6bcf\u7ebf\u7a0b\u7684 Parker<\/td>\n<td>pthread_mutex &#043; pthread_cond_(timed)wait<\/td>\n<\/tr>\n<tr>\n<td>\u4e24\u8005\u5171\u540c<\/td>\n<td>glibc NPTL<\/td>\n<td>futex(FUTEX_WAIT \/ FUTEX_WAKE) \u7cfb\u7edf\u8c03\u7528<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>PlatformEvent \u81ea\u5df1\u4e5f\u5e26\u4e00\u4e2a\u5c0f\u8ba1\u6570\u5668\u4f5c\u5feb\u901f\u8def\u5f84&#xff1a;\u5982\u679c unpark \u5148\u4e8e park \u5230\u8fbe&#xff08;&#034;\u8bb8\u53ef&#034;\u5df2\u7ecf\u7ed9\u4e86&#xff09;&#xff0c;park \u76f4\u63a5\u8fd4\u56de&#xff0c;\u6839\u672c\u4e0d\u78b0 pthread\u3002\u53ea\u6709\u771f\u8981\u7761\u65f6\u624d\u8fdb\u5165 pthread_cond_wait&#xff0c;\u518d\u7531 glibc \u8d70\u5230 futex_wait&#xff0c;\u6700\u540e\u8fdb\u5165\u7b2c\u4e00\u90e8\u5206\u8bb2\u7684\u5185\u6838\u7b49\u5f85\u961f\u5217\u548c\u8c03\u5ea6\u5668\u3002\u6240\u4ee5\u5b8c\u6574\u94fe\u6761\u662f&#xff1a;<\/p>\n<p>synchronized \u7ade\u4e89<br \/>\n  \u2192 CAS \u5931\u8d25 \u2192 \u81ea\u65cb\u5931\u8d25 \u2192 ObjectMonitor \u5165\u961f<br \/>\n  \u2192 ParkEvent::park \u2192 pthread_cond_wait<br \/>\n  \u2192 futex(FUTEX_WAIT) \u7cfb\u7edf\u8c03\u7528          \u2190 \u7b2c\u4e00\u6b21\u8fdb\u5165\u5185\u6838\u6001<br \/>\n  \u2192 \u5185\u6838&#xff1a;\u5165\u54c8\u5e0c\u6876\u7b49\u5f85\u961f\u5217&#xff0c;schedule() \u5207\u8d70<br \/>\n\u2026<br \/>\n\u6301\u6709\u8005 exit \u2192 unpark \u7ee7\u4efb\u8005 \u2192 pthread_cond_signal<br \/>\n  \u2192 futex(FUTEX_WAKE)                  \u2190 \u5524\u9192\u65b9\u8fdb\u5165\u5185\u6838\u6001<br \/>\n  \u2192 try_to_wake_up() \u2192 \u7ee7\u4efb\u8005\u56de\u5230\u8fd0\u884c\u961f\u5217<\/p>\n<p>\u5728 macOS \u4e0a&#xff0c;pthread \u5e95\u5c42\u4e0d\u662f futex&#xff0c;\u800c\u662f Darwin \u5185\u6838\u7684 psynch \u7cfb\u5217\u7cfb\u7edf\u8c03\u7528&#xff0c;\u4f46\u7ed3\u6784\u76f8\u540c\u3002<\/p>\n<h4>2.7 \u865a\u62df\u7ebf\u7a0b&#xff1a;\u628a&#034;\u7761\u7720&#034;\u4ece\u5185\u6838\u632a\u5230 JVM<\/h4>\n<p>\u865a\u62df\u7ebf\u7a0b&#xff08;JEP 444&#xff0c;JDK 21&#xff09;\u5728\u963b\u585e\u65f6\u4e0d\u8d70\u4e0a\u9762\u90a3\u6761\u901a\u5f80 futex \u7684\u8def&#xff1a;\u5b83\u628a\u81ea\u5df1\u7684\u6808\u5e27\u4f5c\u4e3a continuation \u4fdd\u5b58\u5230\u5806\u4e0a&#xff0c;\u4ece\u627f\u8f7d\u5b83\u7684\u5e73\u53f0\u7ebf\u7a0b\u4e0a\u5378\u8f7d&#xff08;unmount&#xff09;&#xff0c;\u5e73\u53f0\u7ebf\u7a0b\u7ee7\u7eed\u53bb\u8dd1\u522b\u7684\u865a\u62df\u7ebf\u7a0b\u3002\u5524\u9192\u65f6\u7531 JVM \u7684\u8c03\u5ea6\u5668&#xff08;\u4e00\u4e2a ForkJoinPool&#xff09;\u628a\u5b83\u91cd\u65b0\u6302\u8f7d\u5230\u67d0\u4e2a\u5e73\u53f0\u7ebf\u7a0b\u4e0a\u3002<\/p>\n<p>JDK 21\u201323 \u4e2d&#xff0c;synchronized \u91cc\u963b\u585e\u4f1a\u628a\u627f\u8f7d\u7ebf\u7a0b\u9489\u4f4f&#xff08;pinning&#xff09;&#xff0c;\u539f\u56e0\u4e4b\u4e00\u6b63\u662f\u65e7\u5b9e\u73b0\u628a\u9501\u548c&#034;\u67d0\u4e2a\u5e73\u53f0\u7ebf\u7a0b \/ \u67d0\u4e2a\u7ebf\u7a0b\u6808&#034;\u7ed1\u5728\u4e00\u8d77&#xff1b;JEP 491&#xff08;JDK 24&#xff09;\u91cd\u5199\u4e86 ObjectMonitor \u7684 owner \u8bb0\u5f55\u65b9\u5f0f&#xff0c;\u5927\u90e8\u5206\u60c5\u51b5\u4e0b synchronized \u4e5f\u80fd\u5378\u8f7d\u4e86\u3002\u4ecd\u7136\u4f1a\u9489\u4f4f\u7684\u60c5\u51b5\u5305\u62ec&#xff1a;\u6808\u4e0a\u6709\u672c\u5730\u65b9\u6cd5\u5e27&#xff0c;\u4ee5\u53ca\u7c7b\u521d\u59cb\u5316\u671f\u95f4\u3002<\/p>\n<h3>\u7b2c\u4e09\u90e8\u5206&#xff1a;\u4e24\u5c42\u5b9e\u73b0\u5e76\u6392\u5bf9\u7167<\/h3>\n<table>\n<tr>\u673a\u5236\u95ee\u9898\u64cd\u4f5c\u7cfb\u7edf \/ \u7ebf\u7a0b\u5e93HotSpot synchronized<\/tr>\n<tbody>\n<tr>\n<td>\u4e92\u65a5\u7684\u539f\u5b50\u6027<\/td>\n<td>\u786c\u4ef6\u539f\u5b50\u6307\u4ee4&#xff08;LOCK CMPXCHG\u3001LL\/SC&#xff09;&#xff1b;\u5355\u6838\u53ef\u5173\u4e2d\u65ad<\/td>\n<td>\u540c\u6837\u7684 CAS&#xff0c;\u4f5c\u7528\u5728 Mark Word \u6216 _owner \u4e0a<\/td>\n<\/tr>\n<tr>\n<td>\u65e0\u7ade\u4e89\u5feb\u901f\u8def\u5f84<\/td>\n<td>futex \u9501&#xff1a;\u4e00\u6b21\u7528\u6237\u6001 CAS&#xff0c;\u96f6\u7cfb\u7edf\u8c03\u7528<\/td>\n<td>\u8f7b\u91cf\u7ea7\u9501&#xff1a;\u4e00\u6b21 CAS&#xff08;\u504f\u5411\u9501\u65f6\u4ee3\u8fde CAS \u90fd\u7701\u4e86&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u77ed\u6682\u7ade\u4e89<\/td>\n<td>\u5185\u6838 mutex \u4e50\u89c2\u81ea\u65cb&#xff1b;glibc \u81ea\u9002\u5e94\u81ea\u65cb\u9501\u53ef\u9009<\/td>\n<td>ObjectMonitor \u81ea\u9002\u5e94\u81ea\u65cb<\/td>\n<\/tr>\n<tr>\n<td>\u5165\u53e3\u961f\u5217<\/td>\n<td>\u5185\u6838 wait_list \/ futex \u54c8\u5e0c\u6876\u961f\u5217<\/td>\n<td>_cxq &#043; _EntryList<\/td>\n<\/tr>\n<tr>\n<td>\u6761\u4ef6\u53d8\u91cf<\/td>\n<td>pthread_cond&#xff1a;\u5e8f\u53f7 &#043; futex<\/td>\n<td>_WaitSet&#xff08;\u6bcf\u5bf9\u8c61\u4ec5\u4e00\u4e2a&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u9632\u4e22\u5931\u5524\u9192<\/td>\n<td>\u201c\u5148\u5165\u961f\/\u8bb0\u5e8f\u53f7&#xff0c;\u518d\u67e5\u6761\u4ef6&#xff0c;\u518d\u7761\u201d&#xff0c;\u5185\u6838\u5185\u539f\u5b50\u68c0\u67e5<\/td>\n<td>\u5165 _WaitSet \u540e\u624d\u91ca\u653e\u9501&#xff1b;ParkEvent \u8bb8\u53ef\u8ba1\u6570<\/td>\n<\/tr>\n<tr>\n<td>\u6302\u8d77<\/td>\n<td>\u79fb\u51fa\u8fd0\u884c\u961f\u5217 &#043; \u4e0a\u4e0b\u6587\u5207\u6362<\/td>\n<td>park \u2192 pthread_cond_wait \u2192 futex<\/td>\n<\/tr>\n<tr>\n<td>\u5524\u9192<\/td>\n<td>\u653e\u56de\u8fd0\u884c\u961f\u5217&#xff0c;\u5fc5\u8981\u65f6\u53d1 IPI<\/td>\n<td>\u9009\u4e00\u4e2a\u7ee7\u4efb\u8005 unpark \u2192 futex wake<\/td>\n<\/tr>\n<tr>\n<td>\u5524\u9192\u8bed\u4e49<\/td>\n<td>Mesa&#xff08;pthreads&#xff09;<\/td>\n<td>Mesa<\/td>\n<\/tr>\n<tr>\n<td>\u516c\u5e73\u6027<\/td>\n<td>\u4e00\u822c\u4e0d\u4fdd\u8bc1<\/td>\n<td>\u4e0d\u4fdd\u8bc1&#xff0c;\u5141\u8bb8\u63d2\u961f<\/td>\n<\/tr>\n<tr>\n<td>\u5185\u6838\u6001\u5207\u6362\u4f55\u65f6\u53d1\u751f<\/td>\n<td>\u53ea\u5728\u771f\u8981\u7761 \/ \u771f\u8981\u5524\u9192\u65f6<\/td>\n<td>\u53ea\u5728\u81a8\u80c0\u540e\u771f\u8981 park \/ unpark \u65f6<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>\u7b2c\u56db\u90e8\u5206&#xff1a;\u4e0e\u59ca\u59b9\u7bc7\u7684\u5bf9\u7167<\/h3>\n<table>\n<tr>\u4e3b\u9898\u300a\u4ece PV \u64cd\u4f5c\u3001\u7ba1\u7a0b\u5230\u73b0\u4ee3 Java \u5e76\u53d1\u300b\u672c\u6587<\/tr>\n<tbody>\n<tr>\n<td>\u7ba1\u7a0b\u5b9a\u4e49\u3001Hoare vs. Mesa<\/td>\n<td>\u5df2\u8986\u76d6<\/td>\n<td>\u8865\u5145&#xff1a;\u4e24\u79cd\u8bed\u4e49\u7684\u5b9e\u73b0\u4ee3\u4ef7&#xff08;1.4&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>synchronized \/ wait \/ notify \u7684\u7528\u6cd5\u4e0e\u89c4\u77e9<\/td>\n<td>\u5df2\u8986\u76d6<\/td>\n<td>\u8865\u5145&#xff1a;\u6bcf\u6761\u89c4\u77e9\u5728 ObjectMonitor \u6e90\u7801\u5c42\u9762\u7684\u51fa\u5904&#xff08;2.5&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>AQS\u3001Condition\u3001Semaphore<\/td>\n<td>\u5df2\u8986\u76d6<\/td>\n<td>\u53ea\u8bb2\u5b83\u4eec\u5171\u4eab\u7684 park \u843d\u5730\u8def\u5f84&#xff08;2.6&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u539f\u5b50\u6307\u4ee4\u3001\u81ea\u65cb\u9501\u3001\u5185\u6838\u7b49\u5f85\u961f\u5217\u3001\u4e22\u5931\u5524\u9192<\/td>\n<td>\u672a\u8986\u76d6<\/td>\n<td>1.1\u20131.3<\/td>\n<\/tr>\n<tr>\n<td>futex \u5feb\u6162\u8def\u5f84\u3001pthread_cond<\/td>\n<td>\u53ea\u63d0\u5230\u540d\u5b57<\/td>\n<td>1.5\u20131.6<\/td>\n<\/tr>\n<tr>\n<td>Mark Word\u3001\u9501\u5347\u7ea7\u3001\u81a8\u80c0\u4e0e\u6536\u7f29<\/td>\n<td>\u4e00\u53e5\u8bdd\u5e26\u8fc7<\/td>\n<td>2.2\u20132.3<\/td>\n<\/tr>\n<tr>\n<td>ObjectMonitor \u7ed3\u6784\u3001\u63d2\u961f\u4e0e\u516c\u5e73\u6027<\/td>\n<td>\u672a\u8986\u76d6<\/td>\n<td>2.4<\/td>\n<\/tr>\n<tr>\n<td>\u865a\u62df\u7ebf\u7a0b<\/td>\n<td>\u5df2\u8986\u76d6&#xff08;\u5378\u8f7d\u4e0e\u9489\u4f4f&#xff09;<\/td>\n<td>\u8865\u5145&#xff1a;\u9489\u4f4f\u7684\u5b9e\u73b0\u539f\u56e0&#xff08;2.7&#xff09;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u59ca\u59b9\u7bc7\u91cc\u6709\u4e24\u5904\u8bf4\u6cd5\u504f\u7b80\u5316&#xff0c;\u672c\u6b21\u5df2\u5728\u539f\u6587\u4fee\u6b63&#xff1a;<\/p>\n<li>\u201cLockSupport.park\/unpark \u2192 futex\u201d&#xff1a;HotSpot \u5e76\u4e0d\u76f4\u63a5\u8c03\u7528 futex&#xff0c;\u4e2d\u95f4\u9694\u7740 Parker \/ PlatformEvent \u548c glibc \u7684 pthread_mutex \/ pthread_cond&#xff0c;\u540e\u8005\u5728 Linux \u4e0a\u624d\u843d\u5230 futex\u3002<\/li>\n<li>\u201c\u504f\u5411\u9501\u5df2\u7531 JEP 374 \u5728 JDK 15 \u4e2d\u5e9f\u5f03\u5e76\u9ed8\u8ba4\u5173\u95ed\u201d&#xff1a;\u6ca1\u9519&#xff0c;\u4f46\u4e0d\u5b8c\u6574\u2014\u2014JDK 18 \u5df2\u6dd8\u6c70\u76f8\u5173\u53c2\u6570\u3001\u79fb\u9664\u5b9e\u73b0\u3002\u6240\u4ee5\u7f51\u4e0a\u5e38\u89c1\u7684&#034;\u504f\u5411 \u2192 \u8f7b\u91cf \u2192 \u91cd\u91cf&#034;\u4e09\u6bb5\u5347\u7ea7&#xff0c;\u53ea\u9002\u7528\u4e8e JDK 15 \u4e4b\u524d\u7684\u9ed8\u8ba4\u914d\u7f6e\u3002<\/li>\n<h3>\u7ed3\u8bba<\/h3>\n<ul>\n<li>\u7ba1\u7a0b\u4e0d\u662f\u5185\u6838\u5bf9\u8c61&#xff0c;\u800c\u662f\u7528\u9501 &#043; \u7b49\u5f85\u961f\u5217\u62fc\u51fa\u6765\u7684\u8bed\u8a00\u7ed3\u6784\u3002 OS \u63d0\u4f9b\u7684\u662f\u539f\u5b50\u6307\u4ee4\u3001futex\u3001\u7b49\u5f85\u961f\u5217\u548c\u8c03\u5ea6\u5668&#xff1b;\u7f16\u8bd1\u5668\u548c\u8fd0\u884c\u65f6\u8d1f\u8d23\u628a\u5b83\u4eec\u7ec4\u88c5\u6210&#034;\u9690\u5f0f\u4e92\u65a5 &#043; \u6761\u4ef6\u53d8\u91cf&#034;\u3002<\/li>\n<li>\u6240\u6709\u5c42\u90fd\u5728\u7528\u540c\u4e00\u4e2a\u4e09\u6bb5\u5f0f&#xff1a;\u5148 CAS&#xff08;\u7eaf\u7528\u6237\u6001&#xff09;\u2192 \u518d\u81ea\u65cb&#xff08;\u8d4c\u6301\u6709\u8005\u9a6c\u4e0a\u91ca\u653e&#xff09;\u2192 \u6700\u540e\u6392\u961f\u7761\u7720&#xff08;\u8fdb\u5185\u6838&#xff09;\u3002\u5185\u6838 mutex\u3001futex \u9501\u3001glibc\u3001HotSpot ObjectMonitor \u83ab\u4e0d\u5982\u6b64\u3002<\/li>\n<li>\u9632\u4e22\u5931\u5524\u9192\u53ea\u6709\u4e00\u4e2a\u6838\u5fc3\u6280\u5de7&#xff1a;\u5148\u767b\u8bb0\u81ea\u5df1\u8981\u7b49&#xff08;\u5165\u961f\u6216\u8bb0\u4e0b\u5e8f\u53f7&#xff09;&#xff0c;\u518d\u68c0\u67e5\u6761\u4ef6&#xff0c;\u6700\u540e\u7761&#xff1b;\u68c0\u67e5\u548c\u5165\u7761\u5728\u5185\u6838\u91cc\u539f\u5b50\u5b8c\u6210\u3002<\/li>\n<li>\u7528\u6237\u6001 \/ \u5185\u6838\u6001\u5207\u6362\u53ea\u53d1\u751f\u5728\u771f\u7ade\u4e89\u65f6\u3002 \u65e0\u7ade\u4e89\u7684 synchronized \u662f\u4e00\u6b21 CAS&#xff1b;\u53ea\u6709\u81a8\u80c0\u4e3a\u91cd\u91cf\u7ea7\u9501\u3001\u5e76\u4e14\u771f\u7684\u8981 park \/ unpark \u65f6&#xff0c;\u624d\u901a\u8fc7 pthread_cond \u8d70\u5230 futex \u7cfb\u7edf\u8c03\u7528\u3002<\/li>\n<li>Java \u7684\u7ba1\u7a0b\u662f&#034;\u6309\u9700\u5b9e\u4f53\u5316&#034;\u7684&#xff1a;\u5e73\u65f6\u53ea\u662f Mark Word \u91cc\u7684\u51e0\u4e2a\u4f4d&#xff0c;\u9700\u8981\u6392\u961f\u6216 wait() \u65f6\u624d\u81a8\u80c0\u51fa ObjectMonitor&#xff0c;\u7a7a\u95f2\u540e\u53c8\u88ab\u5f02\u6b65\u6536\u7f29\u3002\u504f\u5411\u9501\u5df2\u6210\u5386\u53f2&#xff0c;JDK 23 \u8d77\u8f7b\u91cf\u7ea7\u9501\u4e5f\u6362\u6210\u4e86 lock-stack \u5b9e\u73b0\u3002<\/li>\n<li>Mesa \u8bed\u4e49\u6709\u7269\u7406\u6839\u6e90&#xff1a;\u5185\u6838\u5524\u9192\u53ea\u662f\u8ba9\u7ebf\u7a0b\u53d8\u6210\u53ef\u8fd0\u884c&#xff0c;notify() \u53ea\u662f\u628a\u7ebf\u7a0b\u632a\u56de\u5165\u53e3\u961f\u5217\u2014\u2014\u9192\u6765\u65f6\u6761\u4ef6\u65e9\u5df2\u53ef\u80fd\u53d8\u4e86&#xff0c;\u6240\u4ee5\u6c38\u8fdc\u5199 while\u3002<\/li>\n<\/ul>\n<h3>\u53c2\u8003\u8d44\u6599<\/h3>\n<ul>\n<li>C. A. R. Hoare, \u201cMonitors: An Operating System Structuring Concept\u201d, Communications of the ACM, 1974&#xff08;\u542b\u7528\u4fe1\u53f7\u91cf\u5b9e\u73b0\u7ba1\u7a0b\u7684\u6784\u9020&#xff09;\u3002<\/li>\n<li>B. Lampson, D. Redell, \u201cExperience with Processes and Monitors in Mesa\u201d, Communications of the ACM, 1980\u3002<\/li>\n<li>A. Silberschatz \u7b49&#xff0c;Operating System Concepts&#xff0c;\u201cMonitors\u201d \u4e0e \u201cImplementing a Monitor Using Semaphores\u201d \u5c0f\u8282\u3002<\/li>\n<li>H. Franke, R. Russell, M. Kirkwood, \u201cFuss, Futexes and Furwocks: Fast Userlevel Locking in Linux\u201d, Ottawa Linux Symposium, 2002\u3002<\/li>\n<li>U. Drepper, \u201cFutexes Are Tricky\u201d, 2011\u3002<\/li>\n<li>Linux \u5185\u6838\u6587\u6863&#xff1a;Documentation\/locking\/mutex-design.rst&#xff1b;man 2 futex\u3002<\/li>\n<li>OpenJDK HotSpot \u6e90\u7801&#xff1a;src\/hotspot\/share\/runtime\/objectMonitor.{hpp,cpp}\u3001synchronizer.cpp\u3001lockStack.hpp\u3001os\/posix\/os_posix.cpp&#xff08;PlatformEvent\u3001Parker&#xff09;\u3002<\/li>\n<li>JEP 374&#xff08;\u5e9f\u5f03\u5e76\u7981\u7528\u504f\u5411\u9501&#xff09;\u3001JEP 444&#xff08;\u865a\u62df\u7ebf\u7a0b&#xff09;\u3001JEP 450 \/ JEP 519&#xff08;\u7d27\u51d1\u5bf9\u8c61\u5934&#xff09;\u3001JEP 491&#xff08;\u865a\u62df\u7ebf\u7a0b\u540c\u6b65\u4e0d\u518d\u9489\u4f4f&#xff09;\u3002<\/li>\n<li>D. Dice, \u201cBiased Locking in HotSpot\u201d&#xff1b;OpenJDK Wiki \u201cSynchronization\u201d\u3002<\/li>\n<li>\u59ca\u59b9\u7bc7&#xff1a;\u4ece PV \u64cd\u4f5c\u3001\u7ba1\u7a0b\u5230\u73b0\u4ee3 Java \u5e76\u53d1\u3002<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>English version: How Monitors Are Implemented: From the OS Kernel to the HotSpot ObjectMonitor<br \/>\n\u59ca\u59b9\u7bc7 \u4ece PV \u64cd\u4f5c\u3001\u7ba1\u7a0b\u5230\u73b0\u4ee3 Java \u5e76\u53d1 \u8bb2\u7684\u662f\u7ba1\u7a0b\u662f\u4ec0\u4e48&#xff1a;\u5171\u4eab\u6570\u636e  \u8fc7\u7a0b  \u9690\u5f0f\u4e92\u65a5  \u6761\u4ef6\u53d8\u91cf&#xff0c;\u4ee5\u53ca Hoare \/ Mesa \u4e24\u79cd\u5524\u9192\u8bed\u4e49\u3002\u672c\u6587\u53ea\u56de\u7b54\u4e0b\u4e00\u4e2a\u95ee\u9898&#xff1a;\u5b83\u662f\u600e\u4e48\u505a\u51fa\u6765\u7684\u2014\u2014\u4ece\u4e00\u6761 CPU \u539f\u5b50\u6307\u4ee4\u5f00\u59cb&#xff0c;\u7ecf<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[99],"topic":[],"class_list":["post-117864","post","type-post","status-publish","format-standard","hentry","category-server","tag-java"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u7ba1\u7a0b\u662f\u600e\u4e48\u5b9e\u73b0\u7684\uff1a\u4ece\u64cd\u4f5c\u7cfb\u7edf\u5185\u6838\u5230 HotSpot \u5bf9\u8c61\u76d1\u89c6\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/117864.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u7ba1\u7a0b\u662f\u600e\u4e48\u5b9e\u73b0\u7684\uff1a\u4ece\u64cd\u4f5c\u7cfb\u7edf\u5185\u6838\u5230 HotSpot \u5bf9\u8c61\u76d1\u89c6\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"English version: How Monitors Are Implemented: From the OS Kernel to the HotSpot ObjectMonitor \u59ca\u59b9\u7bc7 \u4ece PV \u64cd\u4f5c\u3001\u7ba1\u7a0b\u5230\u73b0\u4ee3 Java \u5e76\u53d1 \u8bb2\u7684\u662f\u7ba1\u7a0b\u662f\u4ec0\u4e48&#xff1a;\u5171\u4eab\u6570\u636e \u8fc7\u7a0b \u9690\u5f0f\u4e92\u65a5 \u6761\u4ef6\u53d8\u91cf&#xff0c;\u4ee5\u53ca Hoare \/ Mesa \u4e24\u79cd\u5524\u9192\u8bed\u4e49\u3002\u672c\u6587\u53ea\u56de\u7b54\u4e0b\u4e00\u4e2a\u95ee\u9898&#xff1a;\u5b83\u662f\u600e\u4e48\u505a\u51fa\u6765\u7684\u2014\u2014\u4ece\u4e00\u6761 CPU \u539f\u5b50\u6307\u4ee4\u5f00\u59cb&#xff0c;\u7ecf\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/117864.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-25T10:40:25+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"17 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/117864.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/117864.html\",\"name\":\"\u7ba1\u7a0b\u662f\u600e\u4e48\u5b9e\u73b0\u7684\uff1a\u4ece\u64cd\u4f5c\u7cfb\u7edf\u5185\u6838\u5230 HotSpot \u5bf9\u8c61\u76d1\u89c6\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-10-25T10:40:25+00:00\",\"dateModified\":\"2026-10-25T10:40:25+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/117864.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/117864.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/117864.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u7ba1\u7a0b\u662f\u600e\u4e48\u5b9e\u73b0\u7684\uff1a\u4ece\u64cd\u4f5c\u7cfb\u7edf\u5185\u6838\u5230 HotSpot \u5bf9\u8c61\u76d1\u89c6\u5668\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u7ba1\u7a0b\u662f\u600e\u4e48\u5b9e\u73b0\u7684\uff1a\u4ece\u64cd\u4f5c\u7cfb\u7edf\u5185\u6838\u5230 HotSpot \u5bf9\u8c61\u76d1\u89c6\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/117864.html","og_locale":"zh_CN","og_type":"article","og_title":"\u7ba1\u7a0b\u662f\u600e\u4e48\u5b9e\u73b0\u7684\uff1a\u4ece\u64cd\u4f5c\u7cfb\u7edf\u5185\u6838\u5230 HotSpot \u5bf9\u8c61\u76d1\u89c6\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"English version: How Monitors Are Implemented: From the OS Kernel to the HotSpot ObjectMonitor \u59ca\u59b9\u7bc7 \u4ece PV \u64cd\u4f5c\u3001\u7ba1\u7a0b\u5230\u73b0\u4ee3 Java \u5e76\u53d1 \u8bb2\u7684\u662f\u7ba1\u7a0b\u662f\u4ec0\u4e48&#xff1a;\u5171\u4eab\u6570\u636e \u8fc7\u7a0b \u9690\u5f0f\u4e92\u65a5 \u6761\u4ef6\u53d8\u91cf&#xff0c;\u4ee5\u53ca Hoare \/ Mesa \u4e24\u79cd\u5524\u9192\u8bed\u4e49\u3002\u672c\u6587\u53ea\u56de\u7b54\u4e0b\u4e00\u4e2a\u95ee\u9898&#xff1a;\u5b83\u662f\u600e\u4e48\u505a\u51fa\u6765\u7684\u2014\u2014\u4ece\u4e00\u6761 CPU \u539f\u5b50\u6307\u4ee4\u5f00\u59cb&#xff0c;\u7ecf","og_url":"https:\/\/www.wsisp.com\/helps\/117864.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-10-25T10:40:25+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"17 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/117864.html","url":"https:\/\/www.wsisp.com\/helps\/117864.html","name":"\u7ba1\u7a0b\u662f\u600e\u4e48\u5b9e\u73b0\u7684\uff1a\u4ece\u64cd\u4f5c\u7cfb\u7edf\u5185\u6838\u5230 HotSpot \u5bf9\u8c61\u76d1\u89c6\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-10-25T10:40:25+00:00","dateModified":"2026-10-25T10:40:25+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/117864.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/117864.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/117864.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u7ba1\u7a0b\u662f\u600e\u4e48\u5b9e\u73b0\u7684\uff1a\u4ece\u64cd\u4f5c\u7cfb\u7edf\u5185\u6838\u5230 HotSpot \u5bf9\u8c61\u76d1\u89c6\u5668"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/117864","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=117864"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/117864\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=117864"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=117864"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=117864"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=117864"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}