From 57ebd045eae8ef1bdb5ec96d5eb11d252e08e6bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Casta=C3=B1eda=20Lozano?= Date: Tue, 23 Apr 2024 04:18:23 +0000 Subject: [PATCH] 8330153: C2: dump barrier information for all Mach nodes Reviewed-by: kvn, thartmann --- src/hotspot/share/opto/machnode.cpp | 11 +-- .../compiler/lib/ir_framework/IRNode.java | 6 ++ .../examples/GCBarrierIRExample.java | 75 +++++++++++++++++++ 3 files changed, 87 insertions(+), 5 deletions(-) create mode 100644 test/hotspot/jtreg/testlibrary_tests/ir_framework/examples/GCBarrierIRExample.java diff --git a/src/hotspot/share/opto/machnode.cpp b/src/hotspot/share/opto/machnode.cpp index b2c0028b1a3..57361313f85 100644 --- a/src/hotspot/share/opto/machnode.cpp +++ b/src/hotspot/share/opto/machnode.cpp @@ -548,6 +548,11 @@ void MachNode::dump_spec(outputStream *st) const { if( C->alias_type(t)->is_volatile() ) st->print(" Volatile!"); } + if (barrier_data() != 0) { + st->print(" barrier("); + BarrierSet::barrier_set()->barrier_set_c2()->dump_barrier_data(this, st); + st->print(") "); + } } //------------------------------dump_format------------------------------------ @@ -560,16 +565,12 @@ void MachNode::dump_format(PhaseRegAlloc *ra, outputStream *st) const { //============================================================================= #ifndef PRODUCT void MachTypeNode::dump_spec(outputStream *st) const { + MachNode::dump_spec(st); if (_bottom_type != nullptr) { _bottom_type->dump_on(st); } else { st->print(" null"); } - if (barrier_data() != 0) { - st->print(" barrier("); - BarrierSet::barrier_set()->barrier_set_c2()->dump_barrier_data(this, st); - st->print(")"); - } } #endif diff --git a/test/hotspot/jtreg/compiler/lib/ir_framework/IRNode.java b/test/hotspot/jtreg/compiler/lib/ir_framework/IRNode.java index b9a6bcccf12..366b17786ad 100644 --- a/test/hotspot/jtreg/compiler/lib/ir_framework/IRNode.java +++ b/test/hotspot/jtreg/compiler/lib/ir_framework/IRNode.java @@ -2076,6 +2076,12 @@ public class IRNode { machOnly(Z_STORE_P_WITH_BARRIER_FLAG, regex); } + public static final String Z_COMPARE_AND_SWAP_P_WITH_BARRIER_FLAG = COMPOSITE_PREFIX + "Z_COMPARE_AND_SWAP_P_WITH_BARRIER_FLAG" + POSTFIX; + static { + String regex = START + "zCompareAndSwapP" + MID + "barrier\\(\\s*" + IS_REPLACED + "\\s*\\)" + END; + machOnly(Z_COMPARE_AND_SWAP_P_WITH_BARRIER_FLAG, regex); + } + public static final String Z_GET_AND_SET_P_WITH_BARRIER_FLAG = COMPOSITE_PREFIX + "Z_GET_AND_SET_P_WITH_BARRIER_FLAG" + POSTFIX; static { String regex = START + "(zXChgP)|(zGetAndSetP\\S*)" + MID + "barrier\\(\\s*" + IS_REPLACED + "\\s*\\)" + END; diff --git a/test/hotspot/jtreg/testlibrary_tests/ir_framework/examples/GCBarrierIRExample.java b/test/hotspot/jtreg/testlibrary_tests/ir_framework/examples/GCBarrierIRExample.java new file mode 100644 index 00000000000..5d714c513f1 --- /dev/null +++ b/test/hotspot/jtreg/testlibrary_tests/ir_framework/examples/GCBarrierIRExample.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package ir_framework.examples; + +import compiler.lib.ir_framework.*; +import java.lang.invoke.VarHandle; +import java.lang.invoke.MethodHandles; + +/** + * @test + * @bug 8330153 + * @summary Example test that illustrates the use of the IR test framework for + * verification of late-expanded GC barriers. + * @library /test/lib / + * @run driver ir_framework.examples.GCBarrierIRExample + */ + +public class GCBarrierIRExample { + + static class Outer { + Object f; + } + + static final VarHandle fVarHandle; + static { + MethodHandles.Lookup l = MethodHandles.lookup(); + try { + fVarHandle = l.findVarHandle(Outer.class, "f", Object.class); + } catch (Exception e) { + throw new Error(e); + } + } + static Outer o = new Outer(); + static Object oldVal = new Object(); + static Object newVal = new Object(); + + public static void main(String[] args) { + // These rules apply only to collectors that expand barriers at code + // emission, such as ZGC. Because the collector selection flags are not + // whitelisted (see IR framework's README.md file), the user (as opposed + // to jtreg) needs to set these flags here. + TestFramework.runWithFlags("-XX:+UseZGC", "-XX:+ZGenerational"); + } + + @Test + // IR rules can be used to verify collector-specific barrier info (in this + // case, that a ZGC barrier corresponds to a strong OOP reference). Barrier + // info can only be verified after matching, e.g. at the FINAL_CODE phase. + @IR(counts = {IRNode.Z_COMPARE_AND_SWAP_P_WITH_BARRIER_FLAG, "strong", "1"}, + phase = CompilePhase.FINAL_CODE) + static boolean testBarrierOfCompareAndSwap() { + return fVarHandle.compareAndSet(o, oldVal, newVal); + } +}