annotate src/hotspot/share/gc/shared/c2/cardTableBarrierSetC2.cpp @ 50764:ffa644980dff

8202377: Modularize C2 GC barriers Reviewed-by: neliasso, roland
author eosterlund
date Fri, 18 May 2018 14:51:06 +0200
parents
children 2ef304ee001d
rev   line source
eosterlund@50764 1 /*
eosterlund@50764 2 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
eosterlund@50764 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
eosterlund@50764 4 *
eosterlund@50764 5 * This code is free software; you can redistribute it and/or modify it
eosterlund@50764 6 * under the terms of the GNU General Public License version 2 only, as
eosterlund@50764 7 * published by the Free Software Foundation.
eosterlund@50764 8 *
eosterlund@50764 9 * This code is distributed in the hope that it will be useful, but WITHOUT
eosterlund@50764 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
eosterlund@50764 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
eosterlund@50764 12 * version 2 for more details (a copy is included in the LICENSE file that
eosterlund@50764 13 * accompanied this code).
eosterlund@50764 14 *
eosterlund@50764 15 * You should have received a copy of the GNU General Public License version
eosterlund@50764 16 * 2 along with this work; if not, write to the Free Software Foundation,
eosterlund@50764 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
eosterlund@50764 18 *
eosterlund@50764 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
eosterlund@50764 20 * or visit www.oracle.com if you need additional information or have any
eosterlund@50764 21 * questions.
eosterlund@50764 22 *
eosterlund@50764 23 */
eosterlund@50764 24
eosterlund@50764 25 #include "precompiled.hpp"
eosterlund@50764 26 #include "ci/ciUtilities.hpp"
eosterlund@50764 27 #include "gc/shared/cardTable.hpp"
eosterlund@50764 28 #include "gc/shared/cardTableBarrierSet.hpp"
eosterlund@50764 29 #include "gc/shared/c2/cardTableBarrierSetC2.hpp"
eosterlund@50764 30 #include "opto/arraycopynode.hpp"
eosterlund@50764 31 #include "opto/graphKit.hpp"
eosterlund@50764 32 #include "opto/idealKit.hpp"
eosterlund@50764 33 #include "opto/macro.hpp"
eosterlund@50764 34 #include "utilities/macros.hpp"
eosterlund@50764 35
eosterlund@50764 36 #define __ ideal.
eosterlund@50764 37
eosterlund@50764 38 Node* CardTableBarrierSetC2::byte_map_base_node(GraphKit* kit) const {
eosterlund@50764 39 // Get base of card map
eosterlund@50764 40 jbyte* card_table_base = ci_card_table_address();
eosterlund@50764 41 if (card_table_base != NULL) {
eosterlund@50764 42 return kit->makecon(TypeRawPtr::make((address)card_table_base));
eosterlund@50764 43 } else {
eosterlund@50764 44 return kit->null();
eosterlund@50764 45 }
eosterlund@50764 46 }
eosterlund@50764 47
eosterlund@50764 48 // vanilla/CMS post barrier
eosterlund@50764 49 // Insert a write-barrier store. This is to let generational GC work; we have
eosterlund@50764 50 // to flag all oop-stores before the next GC point.
eosterlund@50764 51 void CardTableBarrierSetC2::post_barrier(GraphKit* kit,
eosterlund@50764 52 Node* ctl,
eosterlund@50764 53 Node* oop_store,
eosterlund@50764 54 Node* obj,
eosterlund@50764 55 Node* adr,
eosterlund@50764 56 uint adr_idx,
eosterlund@50764 57 Node* val,
eosterlund@50764 58 BasicType bt,
eosterlund@50764 59 bool use_precise) const {
eosterlund@50764 60 CardTableBarrierSet* ctbs = barrier_set_cast<CardTableBarrierSet>(BarrierSet::barrier_set());
eosterlund@50764 61 CardTable* ct = ctbs->card_table();
eosterlund@50764 62 // No store check needed if we're storing a NULL or an old object
eosterlund@50764 63 // (latter case is probably a string constant). The concurrent
eosterlund@50764 64 // mark sweep garbage collector, however, needs to have all nonNull
eosterlund@50764 65 // oop updates flagged via card-marks.
eosterlund@50764 66 if (val != NULL && val->is_Con()) {
eosterlund@50764 67 // must be either an oop or NULL
eosterlund@50764 68 const Type* t = val->bottom_type();
eosterlund@50764 69 if (t == TypePtr::NULL_PTR || t == Type::TOP)
eosterlund@50764 70 // stores of null never (?) need barriers
eosterlund@50764 71 return;
eosterlund@50764 72 }
eosterlund@50764 73
eosterlund@50764 74 if (use_ReduceInitialCardMarks()
eosterlund@50764 75 && obj == kit->just_allocated_object(kit->control())) {
eosterlund@50764 76 // We can skip marks on a freshly-allocated object in Eden.
eosterlund@50764 77 // Keep this code in sync with new_deferred_store_barrier() in runtime.cpp.
eosterlund@50764 78 // That routine informs GC to take appropriate compensating steps,
eosterlund@50764 79 // upon a slow-path allocation, so as to make this card-mark
eosterlund@50764 80 // elision safe.
eosterlund@50764 81 return;
eosterlund@50764 82 }
eosterlund@50764 83
eosterlund@50764 84 if (!use_precise) {
eosterlund@50764 85 // All card marks for a (non-array) instance are in one place:
eosterlund@50764 86 adr = obj;
eosterlund@50764 87 }
eosterlund@50764 88 // (Else it's an array (or unknown), and we want more precise card marks.)
eosterlund@50764 89 assert(adr != NULL, "");
eosterlund@50764 90
eosterlund@50764 91 IdealKit ideal(kit, true);
eosterlund@50764 92
eosterlund@50764 93 // Convert the pointer to an int prior to doing math on it
eosterlund@50764 94 Node* cast = __ CastPX(__ ctrl(), adr);
eosterlund@50764 95
eosterlund@50764 96 // Divide by card size
eosterlund@50764 97 Node* card_offset = __ URShiftX( cast, __ ConI(CardTable::card_shift) );
eosterlund@50764 98
eosterlund@50764 99 // Combine card table base and card offset
eosterlund@50764 100 Node* card_adr = __ AddP(__ top(), byte_map_base_node(kit), card_offset );
eosterlund@50764 101
eosterlund@50764 102 // Get the alias_index for raw card-mark memory
eosterlund@50764 103 int adr_type = Compile::AliasIdxRaw;
eosterlund@50764 104 Node* zero = __ ConI(0); // Dirty card value
eosterlund@50764 105
eosterlund@50764 106 if (UseCondCardMark) {
eosterlund@50764 107 if (ct->scanned_concurrently()) {
eosterlund@50764 108 kit->insert_mem_bar(Op_MemBarVolatile, oop_store);
eosterlund@50764 109 __ sync_kit(kit);
eosterlund@50764 110 }
eosterlund@50764 111 // The classic GC reference write barrier is typically implemented
eosterlund@50764 112 // as a store into the global card mark table. Unfortunately
eosterlund@50764 113 // unconditional stores can result in false sharing and excessive
eosterlund@50764 114 // coherence traffic as well as false transactional aborts.
eosterlund@50764 115 // UseCondCardMark enables MP "polite" conditional card mark
eosterlund@50764 116 // stores. In theory we could relax the load from ctrl() to
eosterlund@50764 117 // no_ctrl, but that doesn't buy much latitude.
eosterlund@50764 118 Node* card_val = __ load( __ ctrl(), card_adr, TypeInt::BYTE, T_BYTE, adr_type);
eosterlund@50764 119 __ if_then(card_val, BoolTest::ne, zero);
eosterlund@50764 120 }
eosterlund@50764 121
eosterlund@50764 122 // Smash zero into card
eosterlund@50764 123 if(!ct->scanned_concurrently()) {
eosterlund@50764 124 __ store(__ ctrl(), card_adr, zero, T_BYTE, adr_type, MemNode::unordered);
eosterlund@50764 125 } else {
eosterlund@50764 126 // Specialized path for CM store barrier
eosterlund@50764 127 __ storeCM(__ ctrl(), card_adr, zero, oop_store, adr_idx, T_BYTE, adr_type);
eosterlund@50764 128 }
eosterlund@50764 129
eosterlund@50764 130 if (UseCondCardMark) {
eosterlund@50764 131 __ end_if();
eosterlund@50764 132 }
eosterlund@50764 133
eosterlund@50764 134 // Final sync IdealKit and GraphKit.
eosterlund@50764 135 kit->final_sync(ideal);
eosterlund@50764 136 }
eosterlund@50764 137
eosterlund@50764 138 void CardTableBarrierSetC2::clone(GraphKit* kit, Node* src, Node* dst, Node* size, bool is_array) const {
eosterlund@50764 139 BarrierSetC2::clone(kit, src, dst, size, is_array);
eosterlund@50764 140 const TypePtr* raw_adr_type = TypeRawPtr::BOTTOM;
eosterlund@50764 141
eosterlund@50764 142 // If necessary, emit some card marks afterwards. (Non-arrays only.)
eosterlund@50764 143 bool card_mark = !is_array && !use_ReduceInitialCardMarks();
eosterlund@50764 144 if (card_mark) {
eosterlund@50764 145 assert(!is_array, "");
eosterlund@50764 146 // Put in store barrier for any and all oops we are sticking
eosterlund@50764 147 // into this object. (We could avoid this if we could prove
eosterlund@50764 148 // that the object type contains no oop fields at all.)
eosterlund@50764 149 Node* no_particular_value = NULL;
eosterlund@50764 150 Node* no_particular_field = NULL;
eosterlund@50764 151 int raw_adr_idx = Compile::AliasIdxRaw;
eosterlund@50764 152 post_barrier(kit, kit->control(),
eosterlund@50764 153 kit->memory(raw_adr_type),
eosterlund@50764 154 dst,
eosterlund@50764 155 no_particular_field,
eosterlund@50764 156 raw_adr_idx,
eosterlund@50764 157 no_particular_value,
eosterlund@50764 158 T_OBJECT,
eosterlund@50764 159 false);
eosterlund@50764 160 }
eosterlund@50764 161 }
eosterlund@50764 162
eosterlund@50764 163 bool CardTableBarrierSetC2::use_ReduceInitialCardMarks() const {
eosterlund@50764 164 return ReduceInitialCardMarks;
eosterlund@50764 165 }
eosterlund@50764 166
eosterlund@50764 167 bool CardTableBarrierSetC2::is_gc_barrier_node(Node* node) const {
eosterlund@50764 168 return ModRefBarrierSetC2::is_gc_barrier_node(node) || node->Opcode() == Op_StoreCM;
eosterlund@50764 169 }
eosterlund@50764 170
eosterlund@50764 171 void CardTableBarrierSetC2::eliminate_gc_barrier(PhaseMacroExpand* macro, Node* node) const {
eosterlund@50764 172 assert(node->Opcode() == Op_CastP2X, "ConvP2XNode required");
eosterlund@50764 173 Node *shift = node->unique_out();
eosterlund@50764 174 Node *addp = shift->unique_out();
eosterlund@50764 175 for (DUIterator_Last jmin, j = addp->last_outs(jmin); j >= jmin; --j) {
eosterlund@50764 176 Node *mem = addp->last_out(j);
eosterlund@50764 177 if (UseCondCardMark && mem->is_Load()) {
eosterlund@50764 178 assert(mem->Opcode() == Op_LoadB, "unexpected code shape");
eosterlund@50764 179 // The load is checking if the card has been written so
eosterlund@50764 180 // replace it with zero to fold the test.
eosterlund@50764 181 macro->replace_node(mem, macro->intcon(0));
eosterlund@50764 182 continue;
eosterlund@50764 183 }
eosterlund@50764 184 assert(mem->is_Store(), "store required");
eosterlund@50764 185 macro->replace_node(mem, mem->in(MemNode::Memory));
eosterlund@50764 186 }
eosterlund@50764 187 }
eosterlund@50764 188
eosterlund@50764 189 bool CardTableBarrierSetC2::array_copy_requires_gc_barriers(BasicType type) const {
eosterlund@50764 190 return !use_ReduceInitialCardMarks();
eosterlund@50764 191 }