From 9bb6db965fab9bfbd87d9617de2a1c5afbeca2b5 Mon Sep 17 00:00:00 2001 From: "lusou.zq" Date: Fri, 5 Jan 2024 15:54:03 +0800 Subject: [PATCH 1/2] [Backport] 8225776: Optimize branch frequency of G1's write post-barrier in C2 Summary: Optimize branch frequency of G1's write post-barrier in C2 to be unlikely. Testing: test/hotspot/jtreg/compiler/c2/aarch64/TestVolatilesG1.java Reviewers: kuaiwei.kw, maoliang.ml Issue: https://github.com/dragonwell-project/dragonwell11/issues/766 --- src/hotspot/share/gc/g1/c2/g1BarrierSetC2.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/hotspot/share/gc/g1/c2/g1BarrierSetC2.cpp b/src/hotspot/share/gc/g1/c2/g1BarrierSetC2.cpp index d6f7afb3278..c54f41efd6e 100644 --- a/src/hotspot/share/gc/g1/c2/g1BarrierSetC2.cpp +++ b/src/hotspot/share/gc/g1/c2/g1BarrierSetC2.cpp @@ -414,7 +414,8 @@ void G1BarrierSetC2::post_barrier(GraphKit* kit, Node* tls = __ thread(); // ThreadLocalStorage Node* no_base = __ top(); - float unlikely = PROB_UNLIKELY(0.999); + float likely = PROB_LIKELY_MAG(3); + float unlikely = PROB_UNLIKELY_MAG(3); Node* young_card = __ ConI((jint)G1CardTable::g1_young_card_val()); Node* dirty_card = __ ConI((jint)G1CardTable::dirty_card_val()); Node* zeroX = __ ConX(0); @@ -457,17 +458,17 @@ void G1BarrierSetC2::post_barrier(GraphKit* kit, Node* xor_res = __ URShiftX ( __ XorX( cast, __ CastPX(__ ctrl(), val)), __ ConI(HeapRegion::LogOfHRGrainBytes)); // if (xor_res == 0) same region so skip - __ if_then(xor_res, BoolTest::ne, zeroX); { + __ if_then(xor_res, BoolTest::ne, zeroX, likely); { // No barrier if we are storing a NULL - __ if_then(val, BoolTest::ne, kit->null(), unlikely); { + __ if_then(val, BoolTest::ne, kit->null(), likely); { // Ok must mark the card if not already dirty // load the original value of the card Node* card_val = __ load(__ ctrl(), card_adr, TypeInt::INT, T_BYTE, Compile::AliasIdxRaw); - __ if_then(card_val, BoolTest::ne, young_card); { + __ if_then(card_val, BoolTest::ne, young_card, unlikely); { kit->sync_kit(ideal); kit->insert_mem_bar(Op_MemBarVolatile, oop_store); __ sync_kit(kit); From 00cf3e20c73582b6bdb1f7b614c6bc35b2529933 Mon Sep 17 00:00:00 2001 From: "lusou.zq" Date: Fri, 5 Jan 2024 15:54:44 +0800 Subject: [PATCH 2/2] [Backport] 8232828: AArch64: compiler/c2/aarch64/TestVolatilesG1.java fails after JDK-8225776 Summary: Fix falied test case TestVolatilesG1.java Testing: test/hotspot/jtreg/compiler/c2/aarch64/TestVolatilesG1.java Reviewers: kuaiwei.kw, maoliang.ml Issue: https://github.com/dragonwell-project/dragonwell11/issues/766 --- .../compiler/c2/aarch64/TestVolatiles.java | 84 +++++++++++++------ 1 file changed, 58 insertions(+), 26 deletions(-) diff --git a/test/hotspot/jtreg/compiler/c2/aarch64/TestVolatiles.java b/test/hotspot/jtreg/compiler/c2/aarch64/TestVolatiles.java index c9028c5fa65..3a291f03f8d 100644 --- a/test/hotspot/jtreg/compiler/c2/aarch64/TestVolatiles.java +++ b/test/hotspot/jtreg/compiler/c2/aarch64/TestVolatiles.java @@ -331,14 +331,18 @@ private void checkstore(OutputAnalyzer output, String testType, boolean useBarri case "G1": // a card mark volatile barrier should be generated // before the card mark strb + // + // following the fix for 8225776 the G1 barrier is now + // scheduled out of line after the membar volatile and + // and subsequent return matches = new String[] { "membar_release \\(elided\\)", useCompressedOops ? "stlrw?" : "stlr", + "membar_volatile \\(elided\\)", + "ret", "membar_volatile", "dmb ish", - "strb", - "membar_volatile \\(elided\\)", - "ret" + "strb" }; break; case "CMSCondMark": @@ -399,16 +403,20 @@ private void checkstore(OutputAnalyzer output, String testType, boolean useBarri case "G1": // a card mark volatile barrier should be generated // before the card mark strb + // + // following the fix for 8225776 the G1 barrier is now + // scheduled out of line after the membar volatile and + // and subsequent return matches = new String[] { "membar_release", "dmb ish", useCompressedOops ? "strw?" : "str", "membar_volatile", "dmb ish", - "strb", + "ret", "membar_volatile", "dmb ish", - "ret" + "strb" }; break; case "CMSCondMark": @@ -522,14 +530,18 @@ private void checkcas(OutputAnalyzer output, String testType, boolean useBarrier case "G1": // a card mark volatile barrier should be generated // before the card mark strb + // + // following the fix for 8225776 the G1 barrier is now + // scheduled out of line after the membar acquire and + // and subsequent return matches = new String[] { "membar_release \\(elided\\)", useCompressedOops ? "cmpxchgw?_acq" : "cmpxchg_acq", + "membar_acquire \\(elided\\)", + "ret", "membar_volatile", "dmb ish", - "strb", - "membar_acquire \\(elided\\)", - "ret" + "strb" }; break; case "CMSCondMark": @@ -589,16 +601,20 @@ private void checkcas(OutputAnalyzer output, String testType, boolean useBarrier case "G1": // a card mark volatile barrier should be generated // before the card mark strb + // + // following the fix for 8225776 the G1 barrier is now + // scheduled out of line after the membar acquire and + // and subsequent return matches = new String[] { "membar_release", "dmb ish", useCompressedOops ? "cmpxchgw? " : "cmpxchg ", - "membar_volatile", - "dmb ish", - "strb", "membar_acquire", "dmb ish", - "ret" + "ret", + "membar_volatile", + "dmb ish", + "strb" }; break; case "CMSCondMark": @@ -725,14 +741,18 @@ private void checkcae(OutputAnalyzer output, String testType, boolean useBarrier case "G1": // a card mark volatile barrier should be generated // before the card mark strb + // + // following the fix for 8225776 the G1 barrier is now + // scheduled out of line after the membar acquire and + // and subsequent return matches = new String[] { "membar_release \\(elided\\)", useCompressedOops ? "cmpxchgw?_acq" : "cmpxchg_acq", + "membar_acquire \\(elided\\)", + "ret", "membar_volatile", "dmb ish", - "strb", - "membar_acquire \\(elided\\)", - "ret" + "strb" }; break; case "CMSCondMark": @@ -781,16 +801,20 @@ private void checkcae(OutputAnalyzer output, String testType, boolean useBarrier case "G1": // a card mark volatile barrier should be generated // before the card mark strb + // + // following the fix for 8225776 the G1 barrier is now + // scheduled out of line after the membar acquire and + // and subsequent return matches = new String[] { "membar_release", "dmb ish", useCompressedOops ? "cmpxchgw? " : "cmpxchg ", - "membar_volatile", - "dmb ish", - "strb", "membar_acquire", "dmb ish", - "ret" + "ret", + "membar_volatile", + "dmb ish", + "strb" }; break; case "CMSCondMark": @@ -899,14 +923,18 @@ private void checkgas(OutputAnalyzer output, String testType, boolean useBarrier case "G1": // a card mark volatile barrier should be generated // before the card mark strb + // + // following the fix for 8225776 the G1 barrier is now + // scheduled out of line after the membar acquire and + // and subsequent return matches = new String[] { "membar_release \\(elided\\)", useCompressedOops ? "atomic_xchgw?_acq" : "atomic_xchg_acq", + "membar_acquire \\(elided\\)", + "ret", "membar_volatile", "dmb ish", - "strb", - "membar_acquire \\(elided\\)", - "ret" + "strb" }; break; case "CMSCondMark": @@ -955,16 +983,20 @@ private void checkgas(OutputAnalyzer output, String testType, boolean useBarrier case "G1": // a card mark volatile barrier should be generated // before the card mark strb + // + // following the fix for 8225776 the G1 barrier is now + // scheduled out of line after the membar acquire and + // and subsequent return matches = new String[] { "membar_release", "dmb ish", useCompressedOops ? "atomic_xchgw? " : "atomic_xchg ", - "membar_volatile", - "dmb ish", - "strb", "membar_acquire", "dmb ish", - "ret" + "ret", + "membar_volatile", + "dmb ish", + "strb" }; break; case "CMSCondMark":