JDK-8224624 : Inefficiencies in CodeStrings::add_comment cause timeouts
Type:Bug
Component:hotspot
Sub-Component:compiler
Affected Version:11,12,13,14
Priority:P4
Status:Resolved
Resolution:Fixed
Submitted:2019-05-22
Updated:2024-11-08
Resolved:2019-08-22
The Version table provides details related to the release that this issue/RFE will be addressed.
Unresolved : Release in which this issue/RFE will be addressed. Resolved: Release in which this issue/RFE has been resolved. Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.
Test
compiler/c1/TestLinearScanOrderMain.java
time out intemittently.
Comments
[jdk11u-fix-request] Approval Request from sendaoYan
Clean backport to improves C1 compiled time and fix the test imtermittent timeout. Jtreg tests(include tier1/2/3 etc.) passed on linux x64 and linux aarch64.
15-10-2024
A pull request was submitted for review.
Branch: master
URL: https://git.openjdk.org/jdk11u-dev/pull/2951
Date: 2024-10-15 02:49:09 +0000
You might want to check "outliers" in CI using query like this
https://mach5.us.oracle.com/mdash/testHistory?search=name%3Acompiler%2Fc1%2FTestLinearScanOrderMain.java%20%20AND%20executionSystem.pipelineId%3Ajdk-jdk*%20AND%20%20executionSystem.jobId%3A*tier1*%20AND%20durationMillis%3A%5B240000%20TO%20100000000%5D
Sometimes this test take 4-5 min to complete in tier1.
Thanks Leonid. I had another look and found the root cause:
The test that was added with the fix for JDK-8207355 [1] forces C1 to generate hundreds of exception handlers. If CommentedAssembly is enabled, LIR_Assembler::emit_exception_entries adds comments to the assembly code that is generated for these exception adapter blocks [2]. To add the comments to the right offset, CodeStrings::add_comment searches through *all* _code_strings in the CodeBuffer until it finds the last comment with that offset. This is extremely slow with a large amount of code strings (see compile times for the single test method [3]) and is repeated for every new comment that is added.
I've fixed this by changing CodeStrings to a doubly-linked-list and searching for the comment with the right offset in reverse (because especially for these exception handlers, we add comments with increasing offset). In addition, the code now maintains the invariant that comments in the linked list a sorted by increasing offset. When reverse-searching the list, we can therefore bail out if we encounter a comment with offset <= the offset we are searching for. This improves C1 compiled time of the test method dramatically from 92s to 1,8s [4].
[1] https://mail.openjdk.java.net/pipermail/hotspot-compiler-dev/2018-August/029973.html
[2] Commented assembly code for exception adapter blocks:
[...]
;; Exception adapter block
0x00007f2aed9885de: mov 0x248(%rsp),%rsi
;; branch [AL] [B61]
0x00007f2aed9885e6: jmpq 0x00007f2aed974f0c
;; Exception adapter block
0x00007f2aed9885eb: mov 0x240(%rsp),%rsi
;; branch [AL] [B63]
0x00007f2aed9885f3: jmpq 0x00007f2aed974f94
;; Exception adapter block
[...]
[3] Compile times without patch:
Individual compiler times (for compiled methods only)
------------------------------------------------
C1 {speed: 0 bytes/s; standard: 0,000 s, 0 bytes, 0 methods; osr: 0,000 s, 0 bytes, 0 methods; nmethods_size: 0 bytes; nmethods_code_size: 0 bytes}
C1 Compile Time: 92,966 s
Setup time: 0,000 s
Build HIR: 1,651 s
Parse: 0,039 s
Optimize blocks: 1,558 s
GVN: 0,034 s
Null checks elim: 0,002 s
Range checks elim: 0,000 s
Other: 0,019 s
Emit LIR: 0,237 s
LIR Gen: 0,002 s
Linear Scan: 0,235 s
Other: 0,000 s
Code Emission: 91,078 s
Code Installation: 0,000 s
Other: 0,000 s
JVMCI code install time: 0,000 s
[4] Compile times with patch:
Individual compiler times (for compiled methods only)
------------------------------------------------
C1 {speed: 0 bytes/s; standard: 0,000 s, 0 bytes, 0 methods; osr: 0,000 s, 0 bytes, 0 methods; nmethods_size: 0 bytes; nmethods_code_size: 0 bytes}
C1 Compile Time: 1,849 s
Setup time: 0,000 s
Build HIR: 1,575 s
Parse: 0,038 s
Optimize blocks: 1,483 s
GVN: 0,033 s
Null checks elim: 0,002 s
Range checks elim: 0,000 s
Other: 0,019 s
Emit LIR: 0,228 s
LIR Gen: 0,002 s
Linear Scan: 0,226 s
Other: 0,000 s
Code Emission: 0,047 s
Code Installation: 0,000 s
Other: 0,000 s
JVMCI code install time: 0,000 s
20-08-2019
ILW = Test times out, very intermittent with single test on tier1 (only happened once), no workaround (but increase timeout) = MLH = P4