Path: blob/master/src/hotspot/share/gc/shared/c2/cardTableBarrierSetC2.cpp
40974 views
/*1* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "ci/ciUtilities.hpp"26#include "gc/shared/cardTable.hpp"27#include "gc/shared/cardTableBarrierSet.hpp"28#include "gc/shared/c2/cardTableBarrierSetC2.hpp"29#include "gc/shared/gc_globals.hpp"30#include "opto/arraycopynode.hpp"31#include "opto/graphKit.hpp"32#include "opto/idealKit.hpp"33#include "opto/macro.hpp"34#include "utilities/macros.hpp"3536#define __ ideal.3738Node* CardTableBarrierSetC2::byte_map_base_node(GraphKit* kit) const {39// Get base of card map40CardTable::CardValue* card_table_base = ci_card_table_address();41if (card_table_base != NULL) {42return kit->makecon(TypeRawPtr::make((address)card_table_base));43} else {44return kit->null();45}46}4748// vanilla post barrier49// Insert a write-barrier store. This is to let generational GC work; we have50// to flag all oop-stores before the next GC point.51void CardTableBarrierSetC2::post_barrier(GraphKit* kit,52Node* ctl,53Node* oop_store,54Node* obj,55Node* adr,56uint adr_idx,57Node* val,58BasicType bt,59bool use_precise) const {60// No store check needed if we're storing a NULL.61if (val != NULL && val->is_Con()) {62const Type* t = val->bottom_type();63if (t == TypePtr::NULL_PTR || t == Type::TOP) {64return;65}66}6768if (use_ReduceInitialCardMarks()69&& obj == kit->just_allocated_object(kit->control())) {70// We can skip marks on a freshly-allocated object in Eden.71// Keep this code in sync with CardTableBarrierSet::on_slowpath_allocation_exit.72// That routine informs GC to take appropriate compensating steps,73// upon a slow-path allocation, so as to make this card-mark74// elision safe.75return;76}7778if (!use_precise) {79// All card marks for a (non-array) instance are in one place:80adr = obj;81} else {82// Else it's an array (or unknown), and we want more precise card marks.83}8485assert(adr != NULL, "");8687IdealKit ideal(kit, true);8889// Convert the pointer to an int prior to doing math on it90Node* cast = __ CastPX(__ ctrl(), adr);9192// Divide by card size93Node* card_offset = __ URShiftX(cast, __ ConI(CardTable::card_shift));9495// Combine card table base and card offset96Node* card_adr = __ AddP(__ top(), byte_map_base_node(kit), card_offset);9798// Get the alias_index for raw card-mark memory99int adr_type = Compile::AliasIdxRaw;100101// Dirty card value to store102Node* dirty = __ ConI(CardTable::dirty_card_val());103104if (UseCondCardMark) {105// The classic GC reference write barrier is typically implemented106// as a store into the global card mark table. Unfortunately107// unconditional stores can result in false sharing and excessive108// coherence traffic as well as false transactional aborts.109// UseCondCardMark enables MP "polite" conditional card mark110// stores. In theory we could relax the load from ctrl() to111// no_ctrl, but that doesn't buy much latitude.112Node* card_val = __ load( __ ctrl(), card_adr, TypeInt::BYTE, T_BYTE, adr_type);113__ if_then(card_val, BoolTest::ne, dirty);114}115116// Smash dirty value into card117__ store(__ ctrl(), card_adr, dirty, T_BYTE, adr_type, MemNode::unordered);118119if (UseCondCardMark) {120__ end_if();121}122123// Final sync IdealKit and GraphKit.124kit->final_sync(ideal);125}126127void CardTableBarrierSetC2::clone(GraphKit* kit, Node* src, Node* dst, Node* size, bool is_array) const {128BarrierSetC2::clone(kit, src, dst, size, is_array);129const TypePtr* raw_adr_type = TypeRawPtr::BOTTOM;130131// If necessary, emit some card marks afterwards. (Non-arrays only.)132bool card_mark = !is_array && !use_ReduceInitialCardMarks();133if (card_mark) {134assert(!is_array, "");135// Put in store barrier for any and all oops we are sticking136// into this object. (We could avoid this if we could prove137// that the object type contains no oop fields at all.)138Node* no_particular_value = NULL;139Node* no_particular_field = NULL;140int raw_adr_idx = Compile::AliasIdxRaw;141post_barrier(kit, kit->control(),142kit->memory(raw_adr_type),143dst,144no_particular_field,145raw_adr_idx,146no_particular_value,147T_OBJECT,148false);149}150}151152bool CardTableBarrierSetC2::use_ReduceInitialCardMarks() const {153return ReduceInitialCardMarks;154}155156bool CardTableBarrierSetC2::is_gc_barrier_node(Node* node) const {157return ModRefBarrierSetC2::is_gc_barrier_node(node) || node->Opcode() == Op_StoreCM;158}159160void CardTableBarrierSetC2::eliminate_gc_barrier(PhaseMacroExpand* macro, Node* node) const {161assert(node->Opcode() == Op_CastP2X, "ConvP2XNode required");162Node *shift = node->unique_out();163Node *addp = shift->unique_out();164for (DUIterator_Last jmin, j = addp->last_outs(jmin); j >= jmin; --j) {165Node *mem = addp->last_out(j);166if (UseCondCardMark && mem->is_Load()) {167assert(mem->Opcode() == Op_LoadB, "unexpected code shape");168// The load is checking if the card has been written so169// replace it with zero to fold the test.170macro->replace_node(mem, macro->intcon(0));171continue;172}173assert(mem->is_Store(), "store required");174macro->replace_node(mem, mem->in(MemNode::Memory));175}176}177178bool CardTableBarrierSetC2::array_copy_requires_gc_barriers(bool tightly_coupled_alloc, BasicType type, bool is_clone, bool is_clone_instance, ArrayCopyPhase phase) const {179bool is_oop = is_reference_type(type);180return is_oop && (!tightly_coupled_alloc || !use_ReduceInitialCardMarks());181}182183184