< prev index next > src/hotspot/share/gc/shenandoah/c2/shenandoahBarrierSetC2.cpp
Print this page
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
! #include "classfile/javaClasses.hpp"
#include "gc/shared/barrierSet.hpp"
#include "gc/shenandoah/c2/shenandoahBarrierSetC2.hpp"
- #include "gc/shenandoah/c2/shenandoahSupport.hpp"
#include "gc/shenandoah/heuristics/shenandoahHeuristics.hpp"
- #include "gc/shenandoah/shenandoahBarrierSet.hpp"
- #include "gc/shenandoah/shenandoahCardTable.hpp"
#include "gc/shenandoah/shenandoahForwarding.hpp"
#include "gc/shenandoah/shenandoahHeap.hpp"
#include "gc/shenandoah/shenandoahRuntime.hpp"
#include "gc/shenandoah/shenandoahThreadLocalData.hpp"
#include "opto/arraycopynode.hpp"
#include "opto/escape.hpp"
#include "opto/graphKit.hpp"
#include "opto/idealKit.hpp"
#include "opto/macro.hpp"
- #include "opto/movenode.hpp"
#include "opto/narrowptrnode.hpp"
#include "opto/rootnode.hpp"
#include "opto/runtime.hpp"
ShenandoahBarrierSetC2* ShenandoahBarrierSetC2::bsc2() {
return reinterpret_cast<ShenandoahBarrierSetC2*>(BarrierSet::barrier_set()->barrier_set_c2());
}
! ShenandoahBarrierSetC2State::ShenandoahBarrierSetC2State(Arena* comp_arena)
! : _load_reference_barriers(new (comp_arena) GrowableArray<ShenandoahLoadReferenceBarrierNode*>(comp_arena, 8, 0, nullptr)) {
}
! int ShenandoahBarrierSetC2State::load_reference_barriers_count() const {
! return _load_reference_barriers->length();
! }
-
- ShenandoahLoadReferenceBarrierNode* ShenandoahBarrierSetC2State::load_reference_barrier(int idx) const {
- return _load_reference_barriers->at(idx);
- }
-
- void ShenandoahBarrierSetC2State::add_load_reference_barrier(ShenandoahLoadReferenceBarrierNode * n) {
- assert(!_load_reference_barriers->contains(n), "duplicate entry in barrier list");
- _load_reference_barriers->append(n);
- }
-
- void ShenandoahBarrierSetC2State::remove_load_reference_barrier(ShenandoahLoadReferenceBarrierNode * n) {
- if (_load_reference_barriers->contains(n)) {
- _load_reference_barriers->remove(n);
}
- }
-
- #define __ kit->
! bool ShenandoahBarrierSetC2::satb_can_remove_pre_barrier(GraphKit* kit, PhaseGVN* phase, Node* adr,
! BasicType bt, uint adr_idx) const {
! intptr_t offset = 0;
! Node* base = AddPNode::Ideal_base_and_offset(adr, phase, offset);
! AllocateNode* alloc = AllocateNode::Ideal_allocation(base);
-
- if (offset == Type::OffsetBot) {
- return false; // cannot unalias unless there are precise offsets
- }
! if (alloc == nullptr) {
! return false; // No allocation found
}
! intptr_t size_in_bytes = type2aelembytes(bt);
-
- Node* mem = __ memory(adr_idx); // start searching here...
-
- for (int cnt = 0; cnt < 50; cnt++) {
-
- if (mem->is_Store()) {
-
- Node* st_adr = mem->in(MemNode::Address);
- intptr_t st_offset = 0;
- Node* st_base = AddPNode::Ideal_base_and_offset(st_adr, phase, st_offset);
-
- if (st_base == nullptr) {
- break; // inscrutable pointer
- }
-
- // Break we have found a store with same base and offset as ours so break
- if (st_base == base && st_offset == offset) {
- break;
- }
! if (st_offset != offset && st_offset != Type::OffsetBot) {
! const int MAX_STORE = BytesPerLong;
! if (st_offset >= offset + size_in_bytes ||
! st_offset <= offset - MAX_STORE ||
! st_offset <= offset - mem->as_Store()->memory_size()) {
! // Success: The offsets are provably independent.
! // (You may ask, why not just test st_offset != offset and be done?
! // The answer is that stores of different sizes can co-exist
- // in the same sequence of RawMem effects. We sometimes initialize
- // a whole 'tile' of array elements with a single jint or jlong.)
- mem = mem->in(MemNode::Memory);
- continue; // advance through independent store memory
- }
- }
-
- if (st_base != base
- && MemNode::detect_ptr_independence(base, alloc, st_base,
- AllocateNode::Ideal_allocation(st_base),
- phase)) {
- // Success: The bases are provably independent.
- mem = mem->in(MemNode::Memory);
- continue; // advance through independent store memory
- }
- } else if (mem->is_Proj() && mem->in(0)->is_Initialize()) {
-
- InitializeNode* st_init = mem->in(0)->as_Initialize();
- AllocateNode* st_alloc = st_init->allocation();
-
- // Make sure that we are looking at the same allocation site.
- // The alloc variable is guaranteed to not be null here from earlier check.
- if (alloc == st_alloc) {
- // Check that the initialization is storing null so that no previous store
- // has been moved up and directly write a reference
- Node* captured_store = st_init->find_captured_store(offset,
- type2aelembytes(T_OBJECT),
- phase);
- if (captured_store == nullptr || captured_store == st_init->zero_memory()) {
- return true;
- }
}
}
-
- // Unless there is an explicit 'continue', we must bail out here,
- // because 'mem' is an inscrutable memory state (e.g., a call).
- break;
}
! return false;
! }
!
! #undef __
! #define __ ideal.
!
- void ShenandoahBarrierSetC2::satb_write_barrier_pre(GraphKit* kit,
- bool do_load,
- Node* obj,
- Node* adr,
- uint alias_idx,
- Node* val,
- const TypeOopPtr* val_type,
- Node* pre_val,
- BasicType bt) const {
- // Some sanity checks
- // Note: val is unused in this routine.
-
- if (do_load) {
- // We need to generate the load of the previous value
- assert(adr != nullptr, "where are loading from?");
- assert(pre_val == nullptr, "loaded already?");
- assert(val_type != nullptr, "need a type");
-
- if (ReduceInitialCardMarks
- && satb_can_remove_pre_barrier(kit, &kit->gvn(), adr, bt, alias_idx)) {
- return;
}
-
- } else {
- // In this case both val_type and alias_idx are unused.
- assert(pre_val != nullptr, "must be loaded already");
- // Nothing to be done if pre_val is null.
- if (pre_val->bottom_type() == TypePtr::NULL_PTR) return;
- assert(pre_val->bottom_type()->basic_type() == T_OBJECT, "or we shouldn't be here");
}
- assert(bt == T_OBJECT, "or we shouldn't be here");
! IdealKit ideal(kit, true);
!
! Node* tls = __ thread(); // ThreadLocalStorage
-
- Node* no_base = __ top();
- Node* zero = __ ConI(0);
- Node* zeroX = __ ConX(0);
-
- float likely = PROB_LIKELY(0.999);
- float unlikely = PROB_UNLIKELY(0.999);
-
- // Offsets into the thread
- const int index_offset = in_bytes(ShenandoahThreadLocalData::satb_mark_queue_index_offset());
- const int buffer_offset = in_bytes(ShenandoahThreadLocalData::satb_mark_queue_buffer_offset());
-
- // Now the actual pointers into the thread
- Node* buffer_adr = __ AddP(no_base, tls, __ ConX(buffer_offset));
- Node* index_adr = __ AddP(no_base, tls, __ ConX(index_offset));
-
- // Now some of the values
- Node* marking;
- Node* gc_state = __ AddP(no_base, tls, __ ConX(in_bytes(ShenandoahThreadLocalData::gc_state_offset())));
- Node* ld = __ load(__ ctrl(), gc_state, TypeInt::BYTE, T_BYTE, Compile::AliasIdxRaw);
- marking = __ AndI(ld, __ ConI(ShenandoahHeap::MARKING));
- assert(ShenandoahBarrierC2Support::is_gc_state_load(ld), "Should match the shape");
-
- // if (!marking)
- __ if_then(marking, BoolTest::ne, zero, unlikely); {
- BasicType index_bt = TypeX_X->basic_type();
- assert(sizeof(size_t) == type2aelembytes(index_bt), "Loading Shenandoah SATBMarkQueue::_index with wrong size.");
- Node* index = __ load(__ ctrl(), index_adr, TypeX_X, index_bt, Compile::AliasIdxRaw);
-
- if (do_load) {
- // load original value
- // alias_idx correct??
- pre_val = __ load(__ ctrl(), adr, val_type, bt, alias_idx);
- }
! // if (pre_val != nullptr)
! __ if_then(pre_val, BoolTest::ne, kit->null()); {
- Node* buffer = __ load(__ ctrl(), buffer_adr, TypeRawPtr::NOTNULL, T_ADDRESS, Compile::AliasIdxRaw);
! // is the queue for this thread full?
! __ if_then(index, BoolTest::ne, zeroX, likely); {
! // decrement the index
! Node* next_index = kit->gvn().transform(new SubXNode(index, __ ConX(sizeof(intptr_t))));
! // Now get the buffer location we will log the previous value into and store it
! Node *log_addr = __ AddP(no_base, buffer, next_index);
! __ store(__ ctrl(), log_addr, pre_val, T_OBJECT, Compile::AliasIdxRaw, MemNode::unordered);
! // update the index
! __ store(__ ctrl(), index_adr, next_index, index_bt, Compile::AliasIdxRaw, MemNode::unordered);
! } __ else_(); {
! // logging buffer is full, call the runtime
! const TypeFunc *tf = ShenandoahBarrierSetC2::write_barrier_pre_Type();
! __ make_leaf_call(tf, CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_barrier_pre), "shenandoah_wb_pre", pre_val);
! } __ end_if(); // (!index)
! } __ end_if(); // (pre_val != nullptr)
- } __ end_if(); // (!marking)
! // Final sync IdealKit and GraphKit.
! kit->final_sync(ideal);
! if (ShenandoahSATBBarrier && adr != nullptr) {
! Node* c = kit->control();
! Node* call = c->in(1)->in(1)->in(1)->in(0);
! assert(is_shenandoah_wb_pre_call(call), "shenandoah_wb_pre call expected");
! call->add_req(adr);
}
- }
! bool ShenandoahBarrierSetC2::is_shenandoah_wb_pre_call(Node* call) {
- return call->is_CallLeaf() &&
- call->as_CallLeaf()->entry_point() == CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_barrier_pre);
}
! bool ShenandoahBarrierSetC2::is_shenandoah_clone_call(Node* call) {
! return call->is_CallLeaf() &&
! call->as_CallLeaf()->entry_point() == CAST_FROM_FN_PTR(address, ShenandoahRuntime::clone_barrier);
}
! bool ShenandoahBarrierSetC2::is_shenandoah_lrb_call(Node* call) {
! if (!call->is_CallLeaf()) {
! return false;
! }
-
- address entry_point = call->as_CallLeaf()->entry_point();
- return (entry_point == CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_strong)) ||
- (entry_point == CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_strong_narrow)) ||
- (entry_point == CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_weak)) ||
- (entry_point == CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_weak_narrow)) ||
- (entry_point == CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_phantom)) ||
- (entry_point == CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_phantom_narrow));
}
! bool ShenandoahBarrierSetC2::is_shenandoah_marking_if(PhaseValues* phase, Node* n) {
! if (n->Opcode() != Op_If) {
! return false;
! }
! Node* bol = n->in(1);
! assert(bol->is_Bool(), "");
! Node* cmpx = bol->in(1);
! if (bol->as_Bool()->_test._test == BoolTest::ne &&
! cmpx->is_Cmp() && cmpx->in(2) == phase->intcon(0) &&
! is_shenandoah_state_load(cmpx->in(1)->in(1)) &&
! cmpx->in(1)->in(2)->is_Con() &&
- cmpx->in(1)->in(2) == phase->intcon(ShenandoahHeap::MARKING)) {
- return true;
}
-
- return false;
}
! bool ShenandoahBarrierSetC2::is_shenandoah_state_load(Node* n) {
! if (!n->is_Load()) return false;
! const int state_offset = in_bytes(ShenandoahThreadLocalData::gc_state_offset());
! return n->in(2)->is_AddP() && n->in(2)->in(2)->Opcode() == Op_ThreadLocal
! && n->in(2)->in(3)->is_Con()
! && n->in(2)->in(3)->bottom_type()->is_intptr_t()->get_con() == state_offset;
}
! void ShenandoahBarrierSetC2::shenandoah_write_barrier_pre(GraphKit* kit,
! bool do_load,
! Node* obj,
! Node* adr,
! uint alias_idx,
! Node* val,
! const TypeOopPtr* val_type,
! Node* pre_val,
! BasicType bt) const {
! if (ShenandoahSATBBarrier) {
! IdealKit ideal(kit);
! kit->sync_kit(ideal);
!
- satb_write_barrier_pre(kit, do_load, obj, adr, alias_idx, val, val_type, pre_val, bt);
-
- ideal.sync_kit(kit);
- kit->final_sync(ideal);
}
}
! // Helper that guards and inserts a pre-barrier.
! void ShenandoahBarrierSetC2::insert_pre_barrier(GraphKit* kit, Node* base_oop, Node* offset,
! Node* pre_val, bool need_mem_bar) const {
! // We could be accessing the referent field of a reference object. If so, when Shenandoah
- // is enabled, we need to log the value in the referent field in an SATB buffer.
- // This routine performs some compile time filters and generates suitable
- // runtime filters that guard the pre-barrier code.
- // Also add memory barrier for non volatile load from the referent field
- // to prevent commoning of loads across safepoint.
-
- // Some compile time checks.
-
- // If offset is a constant, is it java_lang_ref_Reference::_reference_offset?
- const TypeX* otype = offset->find_intptr_t_type();
- if (otype != nullptr && otype->is_con() &&
- otype->get_con() != java_lang_ref_Reference::referent_offset()) {
- // Constant offset but not the reference_offset so just return
- return;
- }
! // We only need to generate the runtime guards for instances.
! const TypeOopPtr* btype = base_oop->bottom_type()->isa_oopptr();
! if (btype != nullptr) {
! if (btype->isa_aryptr()) {
- // Array type so nothing to do
- return;
- }
! const TypeInstPtr* itype = btype->isa_instptr();
! if (itype != nullptr) {
! // Can the klass of base_oop be statically determined to be
! // _not_ a sub-class of Reference and _not_ Object?
- ciKlass* klass = itype->instance_klass();
- if (klass->is_loaded() &&
- !klass->is_subtype_of(kit->env()->Reference_klass()) &&
- !kit->env()->Object_klass()->is_subtype_of(klass)) {
- return;
- }
}
- }
! // The compile time filters did not reject base_oop/offset so
! // we need to generate the following runtime filters
! //
! // if (offset == java_lang_ref_Reference::_reference_offset) {
! // if (instance_of(base, java.lang.ref.Reference)) {
! // pre_barrier(_, pre_val, ...);
! // }
! // }
!
! float likely = PROB_LIKELY( 0.999);
! float unlikely = PROB_UNLIKELY(0.999);
!
- IdealKit ideal(kit);
-
- Node* referent_off = __ ConX(java_lang_ref_Reference::referent_offset());
-
- __ if_then(offset, BoolTest::eq, referent_off, unlikely); {
- // Update graphKit memory and control from IdealKit.
- kit->sync_kit(ideal);
-
- Node* ref_klass_con = kit->makecon(TypeKlassPtr::make(kit->env()->Reference_klass()));
- Node* is_instof = kit->gen_instanceof(base_oop, ref_klass_con);
! // Update IdealKit memory and control from graphKit.
! __ sync_kit(kit);
! Node* one = __ ConI(1);
! // is_instof == 0 if base_oop == nullptr
! __ if_then(is_instof, BoolTest::eq, one, unlikely); {
! // Update graphKit from IdeakKit.
! kit->sync_kit(ideal);
! // Use the pre-barrier to record the value in the referent field
! satb_write_barrier_pre(kit, false /* do_load */,
! nullptr /* obj */, nullptr /* adr */, max_juint /* alias_idx */, nullptr /* val */, nullptr /* val_type */,
! pre_val /* pre_val */,
! T_OBJECT);
! if (need_mem_bar) {
- // Add memory barrier to prevent commoning reads from this field
- // across safepoint since GC can change its value.
- kit->insert_mem_bar(Op_MemBarCPUOrder);
}
- // Update IdealKit from graphKit.
- __ sync_kit(kit);
! } __ end_if(); // _ref_type != ref_none
! } __ end_if(); // offset == referent_offset
! // Final sync IdealKit and GraphKit.
! kit->final_sync(ideal);
}
! void ShenandoahBarrierSetC2::post_barrier(GraphKit* kit,
! Node* ctl,
! Node* oop_store,
- Node* obj,
- Node* adr,
- uint adr_idx,
- Node* val,
- BasicType bt,
- bool use_precise) const {
- assert(ShenandoahCardBarrier, "Should have been checked by caller");
-
- // No store check needed if we're storing a null.
- if (val != nullptr && val->is_Con()) {
- // must be either an oop or null
- const Type* t = val->bottom_type();
- if (t == TypePtr::NULL_PTR || t == Type::TOP)
- return;
- }
! if (ReduceInitialCardMarks && obj == kit->just_allocated_object(kit->control())) {
! // We use card marks to track old to young references in Generational Shenandoah;
! // see flag ShenandoahCardBarrier above.
! // Objects are always allocated in the young generation and initialized
- // before they are promoted. There's always a safepoint (e.g. at final mark)
- // before an object is promoted from young to old. Promotion entails dirtying of
- // the cards backing promoted objects, so they will be guaranteed to be scanned
- // at the next remembered set scan of the old generation.
- // Thus, we can safely skip card-marking of initializing stores on a
- // freshly-allocated object. If any of the assumptions above change in
- // the future, this code will need to be re-examined; see check in
- // ShenandoahCardBarrier::on_slowpath_allocation_exit().
- return;
}
! if (!use_precise) {
! // All card marks for a (non-array) instance are in one place:
! adr = obj;
}
- // (Else it's an array (or unknown), and we want more precise card marks.)
- assert(adr != nullptr, "");
-
- IdealKit ideal(kit, true);
-
- Node* tls = __ thread(); // ThreadLocalStorage
-
- // Convert the pointer to an int prior to doing math on it
- Node* cast = __ CastPX(__ ctrl(), adr);
! Node* curr_ct_holder_offset = __ ConX(in_bytes(ShenandoahThreadLocalData::card_table_offset()));
! Node* curr_ct_holder_addr = __ AddP(__ top(), tls, curr_ct_holder_offset);
- Node* curr_ct_base_addr = __ load( __ ctrl(), curr_ct_holder_addr, TypeRawPtr::NOTNULL, T_ADDRESS, Compile::AliasIdxRaw);
-
- // Divide by card size
- Node* card_offset = __ URShiftX( cast, __ ConI(CardTable::card_shift()) );
-
- // Combine card table base and card offset
- Node* card_adr = __ AddP(__ top(), curr_ct_base_addr, card_offset);
! // Get the alias_index for raw card-mark memory
! int adr_type = Compile::AliasIdxRaw;
! Node* zero = __ ConI(0); // Dirty card value
! if (UseCondCardMark) {
! // The classic GC reference write barrier is typically implemented
! // as a store into the global card mark table. Unfortunately
! // unconditional stores can result in false sharing and excessive
! // coherence traffic as well as false transactional aborts.
! // UseCondCardMark enables MP "polite" conditional card mark
! // stores. In theory we could relax the load from ctrl() to
! // no_ctrl, but that doesn't buy much latitude.
! Node* card_val = __ load( __ ctrl(), card_adr, TypeInt::BYTE, T_BYTE, adr_type);
- __ if_then(card_val, BoolTest::ne, zero);
}
! // Smash zero into card
! __ store(__ ctrl(), card_adr, zero, T_BYTE, adr_type, MemNode::unordered);
!
! if (UseCondCardMark) {
! __ end_if();
}
! // Final sync IdealKit and GraphKit.
- kit->final_sync(ideal);
- }
-
- #undef __
-
- const TypeFunc* ShenandoahBarrierSetC2::_write_barrier_pre_Type = nullptr;
- const TypeFunc* ShenandoahBarrierSetC2::_clone_barrier_Type = nullptr;
- const TypeFunc* ShenandoahBarrierSetC2::_load_reference_barrier_Type = nullptr;
-
- inline const TypeFunc* ShenandoahBarrierSetC2::write_barrier_pre_Type() {
- assert(ShenandoahBarrierSetC2::_write_barrier_pre_Type != nullptr, "should be initialized");
- return ShenandoahBarrierSetC2::_write_barrier_pre_Type;
- }
-
- inline const TypeFunc* ShenandoahBarrierSetC2::clone_barrier_Type() {
- assert(ShenandoahBarrierSetC2::_clone_barrier_Type != nullptr, "should be initialized");
- return ShenandoahBarrierSetC2::_clone_barrier_Type;
- }
-
- const TypeFunc* ShenandoahBarrierSetC2::load_reference_barrier_Type() {
- assert(ShenandoahBarrierSetC2::_load_reference_barrier_Type != nullptr, "should be initialized");
- return ShenandoahBarrierSetC2::_load_reference_barrier_Type;
}
! void ShenandoahBarrierSetC2::init() {
! ShenandoahBarrierSetC2::make_write_barrier_pre_Type();
! ShenandoahBarrierSetC2::make_clone_barrier_Type();
- ShenandoahBarrierSetC2::make_load_reference_barrier_Type();
- }
-
- void ShenandoahBarrierSetC2::make_write_barrier_pre_Type() {
- assert(ShenandoahBarrierSetC2::_write_barrier_pre_Type == nullptr, "should be");
- const Type **fields = TypeTuple::fields(1);
- fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // original field value
- const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
-
- // create result type (range)
- fields = TypeTuple::fields(0);
- const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
-
- ShenandoahBarrierSetC2::_write_barrier_pre_Type = TypeFunc::make(domain, range);
- }
-
- void ShenandoahBarrierSetC2::make_clone_barrier_Type() {
- assert(ShenandoahBarrierSetC2::_clone_barrier_Type == nullptr, "should be");
- const Type **fields = TypeTuple::fields(1);
- fields[TypeFunc::Parms+0] = TypeOopPtr::NOTNULL; // src oop
- const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
-
- // create result type (range)
- fields = TypeTuple::fields(0);
- const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
-
- ShenandoahBarrierSetC2::_clone_barrier_Type = TypeFunc::make(domain, range);
- }
-
- void ShenandoahBarrierSetC2::make_load_reference_barrier_Type() {
- assert(ShenandoahBarrierSetC2::_load_reference_barrier_Type == nullptr, "should be");
- const Type **fields = TypeTuple::fields(2);
- fields[TypeFunc::Parms+0] = TypeOopPtr::BOTTOM; // original field value
- fields[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // original load address
-
- const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
-
- // create result type (range)
- fields = TypeTuple::fields(1);
- fields[TypeFunc::Parms+0] = TypeOopPtr::BOTTOM;
- const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
-
- ShenandoahBarrierSetC2::_load_reference_barrier_Type = TypeFunc::make(domain, range);
- }
-
- Node* ShenandoahBarrierSetC2::store_at_resolved(C2Access& access, C2AccessValue& val) const {
- DecoratorSet decorators = access.decorators();
-
- const TypePtr* adr_type = access.addr().type();
- Node* adr = access.addr().node();
-
- bool no_keepalive = (decorators & AS_NO_KEEPALIVE) != 0;
-
- if (!access.is_oop()) {
- return BarrierSetC2::store_at_resolved(access, val);
}
! if (no_keepalive) {
! // No keep-alive means no need for the pre-barrier.
! return BarrierSetC2::store_at_resolved(access, val);
! }
! if (access.is_parse_access()) {
! C2ParseAccess& parse_access = static_cast<C2ParseAccess&>(access);
! GraphKit* kit = parse_access.kit();
! uint adr_idx = kit->C->get_alias_index(adr_type);
! assert(adr_idx != Compile::AliasIdxTop, "use other store_to_memory factory" );
! shenandoah_write_barrier_pre(kit, true /* do_load */, /*kit->control(),*/ access.base(), adr, adr_idx, val.node(),
! static_cast<const TypeOopPtr*>(val.type()), nullptr /* pre_val */, access.type());
! Node* result = BarrierSetC2::store_at_resolved(access, val);
! if (ShenandoahCardBarrier) {
! const bool anonymous = (decorators & ON_UNKNOWN_OOP_REF) != 0;
! const bool is_array = (decorators & IS_ARRAY) != 0;
! const bool use_precise = is_array || anonymous;
! post_barrier(kit, kit->control(), access.raw_access(), access.base(),
- adr, adr_idx, val.node(), access.type(), use_precise);
}
- return result;
- } else {
- assert(access.is_opt_access(), "only for optimization passes");
- assert(((decorators & C2_TIGHTLY_COUPLED_ALLOC) != 0 || !ShenandoahSATBBarrier) && (decorators & C2_ARRAY_COPY) != 0, "unexpected caller of this code");
- return BarrierSetC2::store_at_resolved(access, val);
}
}
! Node* ShenandoahBarrierSetC2::load_at_resolved(C2Access& access, const Type* val_type) const {
! // 1: non-reference load, no additional barrier is needed
! if (!access.is_oop()) {
! return BarrierSetC2::load_at_resolved(access, val_type);
}
! Node* load = BarrierSetC2::load_at_resolved(access, val_type);
! DecoratorSet decorators = access.decorators();
! BasicType type = access.type();
!
! // 2: apply LRB if needed
! if (ShenandoahBarrierSet::need_load_reference_barrier(decorators, type)) {
! load = new ShenandoahLoadReferenceBarrierNode(nullptr, load, decorators);
! if (access.is_parse_access()) {
! load = static_cast<C2ParseAccess &>(access).kit()->gvn().transform(load);
- } else {
- load = static_cast<C2OptAccess &>(access).gvn().transform(load);
}
! }
!
! // 3: apply keep-alive barrier for java.lang.ref.Reference if needed
! if (ShenandoahBarrierSet::need_keep_alive_barrier(decorators, type)) {
! Node* top = Compile::current()->top();
- Node* adr = access.addr().node();
- Node* offset = adr->is_AddP() ? adr->in(AddPNode::Offset) : top;
- Node* obj = access.base();
-
- bool unknown = (decorators & ON_UNKNOWN_OOP_REF) != 0;
- bool on_weak_ref = (decorators & (ON_WEAK_OOP_REF | ON_PHANTOM_OOP_REF)) != 0;
- bool keep_alive = (decorators & AS_NO_KEEPALIVE) == 0;
-
- // If we are reading the value of the referent field of a Reference
- // object (either by using Unsafe directly or through reflection)
- // then, if SATB is enabled, we need to record the referent in an
- // SATB log buffer using the pre-barrier mechanism.
- // Also we need to add memory barrier to prevent commoning reads
- // from this field across safepoint since GC can change its value.
- if (!on_weak_ref || (unknown && (offset == top || obj == top)) || !keep_alive) {
- return load;
}
! assert(access.is_parse_access(), "entry not supported at optimization time");
! C2ParseAccess& parse_access = static_cast<C2ParseAccess&>(access);
! GraphKit* kit = parse_access.kit();
- bool mismatched = (decorators & C2_MISMATCHED) != 0;
- bool is_unordered = (decorators & MO_UNORDERED) != 0;
- bool in_native = (decorators & IN_NATIVE) != 0;
- bool need_cpu_mem_bar = !is_unordered || mismatched || in_native;
-
- if (on_weak_ref) {
- // Use the pre-barrier to record the value in the referent field
- satb_write_barrier_pre(kit, false /* do_load */,
- nullptr /* obj */, nullptr /* adr */, max_juint /* alias_idx */, nullptr /* val */, nullptr /* val_type */,
- load /* pre_val */, T_OBJECT);
- // Add memory barrier to prevent commoning reads from this field
- // across safepoint since GC can change its value.
- kit->insert_mem_bar(Op_MemBarCPUOrder);
- } else if (unknown) {
- // We do not require a mem bar inside pre_barrier if need_mem_bar
- // is set: the barriers would be emitted by us.
- insert_pre_barrier(kit, obj, offset, load, !need_cpu_mem_bar);
- }
}
! return load;
}
! Node* ShenandoahBarrierSetC2::atomic_cmpxchg_val_at_resolved(C2AtomicParseAccess& access, Node* expected_val,
! Node* new_val, const Type* value_type) const {
! GraphKit* kit = access.kit();
! if (access.is_oop()) {
! shenandoah_write_barrier_pre(kit, false /* do_load */,
! nullptr, nullptr, max_juint, nullptr, nullptr,
- expected_val /* pre_val */, T_OBJECT);
-
- MemNode::MemOrd mo = access.mem_node_mo();
- Node* mem = access.memory();
- Node* adr = access.addr().node();
- const TypePtr* adr_type = access.addr().type();
- Node* load_store = nullptr;
-
- #ifdef _LP64
- if (adr->bottom_type()->is_ptr_to_narrowoop()) {
- Node *newval_enc = kit->gvn().transform(new EncodePNode(new_val, new_val->bottom_type()->make_narrowoop()));
- Node *oldval_enc = kit->gvn().transform(new EncodePNode(expected_val, expected_val->bottom_type()->make_narrowoop()));
- if (ShenandoahCASBarrier) {
- load_store = kit->gvn().transform(new ShenandoahCompareAndExchangeNNode(kit->control(), mem, adr, newval_enc, oldval_enc, adr_type, value_type->make_narrowoop(), mo));
- } else {
- load_store = kit->gvn().transform(new CompareAndExchangeNNode(kit->control(), mem, adr, newval_enc, oldval_enc, adr_type, value_type->make_narrowoop(), mo));
- }
- } else
- #endif
- {
- if (ShenandoahCASBarrier) {
- load_store = kit->gvn().transform(new ShenandoahCompareAndExchangePNode(kit->control(), mem, adr, new_val, expected_val, adr_type, value_type->is_oopptr(), mo));
- } else {
- load_store = kit->gvn().transform(new CompareAndExchangePNode(kit->control(), mem, adr, new_val, expected_val, adr_type, value_type->is_oopptr(), mo));
- }
- }
! access.set_raw_access(load_store);
! pin_atomic_op(access);
! #ifdef _LP64
! if (adr->bottom_type()->is_ptr_to_narrowoop()) {
! load_store = kit->gvn().transform(new DecodeNNode(load_store, load_store->get_ptr_type()));
}
! #endif
! load_store = kit->gvn().transform(new ShenandoahLoadReferenceBarrierNode(nullptr, load_store, access.decorators()));
! if (ShenandoahCardBarrier) {
! post_barrier(kit, kit->control(), access.raw_access(), access.base(),
- access.addr().node(), access.alias_idx(), new_val, T_OBJECT, true);
}
! return load_store;
! }
! return BarrierSetC2::atomic_cmpxchg_val_at_resolved(access, expected_val, new_val, value_type);
! }
!
! Node* ShenandoahBarrierSetC2::atomic_cmpxchg_bool_at_resolved(C2AtomicParseAccess& access, Node* expected_val,
! Node* new_val, const Type* value_type) const {
! GraphKit* kit = access.kit();
! if (access.is_oop()) {
- shenandoah_write_barrier_pre(kit, false /* do_load */,
- nullptr, nullptr, max_juint, nullptr, nullptr,
- expected_val /* pre_val */, T_OBJECT);
- DecoratorSet decorators = access.decorators();
- MemNode::MemOrd mo = access.mem_node_mo();
- Node* mem = access.memory();
- bool is_weak_cas = (decorators & C2_WEAK_CMPXCHG) != 0;
- Node* load_store = nullptr;
- Node* adr = access.addr().node();
- #ifdef _LP64
- if (adr->bottom_type()->is_ptr_to_narrowoop()) {
- Node *newval_enc = kit->gvn().transform(new EncodePNode(new_val, new_val->bottom_type()->make_narrowoop()));
- Node *oldval_enc = kit->gvn().transform(new EncodePNode(expected_val, expected_val->bottom_type()->make_narrowoop()));
- if (ShenandoahCASBarrier) {
- if (is_weak_cas) {
- load_store = kit->gvn().transform(new ShenandoahWeakCompareAndSwapNNode(kit->control(), mem, adr, newval_enc, oldval_enc, mo));
- } else {
- load_store = kit->gvn().transform(new ShenandoahCompareAndSwapNNode(kit->control(), mem, adr, newval_enc, oldval_enc, mo));
- }
- } else {
- if (is_weak_cas) {
- load_store = kit->gvn().transform(new WeakCompareAndSwapNNode(kit->control(), mem, adr, newval_enc, oldval_enc, mo));
- } else {
- load_store = kit->gvn().transform(new CompareAndSwapNNode(kit->control(), mem, adr, newval_enc, oldval_enc, mo));
- }
- }
- } else
- #endif
- {
- if (ShenandoahCASBarrier) {
- if (is_weak_cas) {
- load_store = kit->gvn().transform(new ShenandoahWeakCompareAndSwapPNode(kit->control(), mem, adr, new_val, expected_val, mo));
- } else {
- load_store = kit->gvn().transform(new ShenandoahCompareAndSwapPNode(kit->control(), mem, adr, new_val, expected_val, mo));
- }
- } else {
- if (is_weak_cas) {
- load_store = kit->gvn().transform(new WeakCompareAndSwapPNode(kit->control(), mem, adr, new_val, expected_val, mo));
- } else {
- load_store = kit->gvn().transform(new CompareAndSwapPNode(kit->control(), mem, adr, new_val, expected_val, mo));
- }
}
}
! access.set_raw_access(load_store);
! pin_atomic_op(access);
! if (ShenandoahCardBarrier) {
- post_barrier(kit, kit->control(), access.raw_access(), access.base(),
- access.addr().node(), access.alias_idx(), new_val, T_OBJECT, true);
}
- return load_store;
}
- return BarrierSetC2::atomic_cmpxchg_bool_at_resolved(access, expected_val, new_val, value_type);
- }
! Node* ShenandoahBarrierSetC2::atomic_xchg_at_resolved(C2AtomicParseAccess& access, Node* val, const Type* value_type) const {
! GraphKit* kit = access.kit();
- Node* result = BarrierSetC2::atomic_xchg_at_resolved(access, val, value_type);
- if (access.is_oop()) {
- result = kit->gvn().transform(new ShenandoahLoadReferenceBarrierNode(nullptr, result, access.decorators()));
- shenandoah_write_barrier_pre(kit, false /* do_load */,
- nullptr, nullptr, max_juint, nullptr, nullptr,
- result /* pre_val */, T_OBJECT);
- if (ShenandoahCardBarrier) {
- post_barrier(kit, kit->control(), access.raw_access(), access.base(),
- access.addr().node(), access.alias_idx(), val, T_OBJECT, true);
- }
}
- return result;
}
! bool ShenandoahBarrierSetC2::is_gc_pre_barrier_node(Node* node) const {
! return is_shenandoah_wb_pre_call(node);
- }
! bool ShenandoahBarrierSetC2::is_gc_barrier_node(Node* node) const {
! return (node->Opcode() == Op_ShenandoahLoadReferenceBarrier) ||
! is_shenandoah_lrb_call(node) ||
! is_shenandoah_wb_pre_call(node) ||
! is_shenandoah_clone_call(node);
- }
! Node* ShenandoahBarrierSetC2::step_over_gc_barrier(Node* c) const {
! if (c == nullptr) {
! return c;
! }
! if (c->Opcode() == Op_ShenandoahLoadReferenceBarrier) {
! return c->in(ShenandoahLoadReferenceBarrierNode::ValueIn);
}
- return c;
- }
! bool ShenandoahBarrierSetC2::expand_barriers(Compile* C, PhaseIterGVN& igvn) const {
! return !ShenandoahBarrierC2Support::expand(C, igvn);
}
! bool ShenandoahBarrierSetC2::optimize_loops(PhaseIdealLoop* phase, LoopOptsMode mode, VectorSet& visited, Node_Stack& nstack, Node_List& worklist) const {
! if (mode == LoopOptsShenandoahExpand) {
! assert(UseShenandoahGC, "only for shenandoah");
! ShenandoahBarrierC2Support::pin_and_expand(phase);
! return true;
! }
! return false;
}
bool ShenandoahBarrierSetC2::array_copy_requires_gc_barriers(bool tightly_coupled_alloc, BasicType type, bool is_clone, bool is_clone_instance, ArrayCopyPhase phase) const {
bool is_oop = is_reference_type(type);
if (!is_oop) {
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
! #include "classfile/javaClasses.inline.hpp"
#include "gc/shared/barrierSet.hpp"
#include "gc/shenandoah/c2/shenandoahBarrierSetC2.hpp"
#include "gc/shenandoah/heuristics/shenandoahHeuristics.hpp"
#include "gc/shenandoah/shenandoahForwarding.hpp"
#include "gc/shenandoah/shenandoahHeap.hpp"
#include "gc/shenandoah/shenandoahRuntime.hpp"
#include "gc/shenandoah/shenandoahThreadLocalData.hpp"
#include "opto/arraycopynode.hpp"
#include "opto/escape.hpp"
#include "opto/graphKit.hpp"
#include "opto/idealKit.hpp"
#include "opto/macro.hpp"
#include "opto/narrowptrnode.hpp"
+ #include "opto/output.hpp"
#include "opto/rootnode.hpp"
#include "opto/runtime.hpp"
ShenandoahBarrierSetC2* ShenandoahBarrierSetC2::bsc2() {
return reinterpret_cast<ShenandoahBarrierSetC2*>(BarrierSet::barrier_set()->barrier_set_c2());
}
! ShenandoahBarrierSetC2State::ShenandoahBarrierSetC2State(Arena* comp_arena) :
! BarrierSetC2State(comp_arena),
+ _stubs(new (comp_arena) GrowableArray<ShenandoahBarrierStubC2*>(comp_arena, 8, 0, nullptr)),
+ _trampoline_stubs_count(0),
+ _stubs_start_offset(0) {
}
! static void set_barrier_data(C2Access& access, bool load, bool store) {
! if (!access.is_oop()) {
! return;
}
! DecoratorSet decorators = access.decorators();
! bool tightly_coupled = (decorators & C2_TIGHTLY_COUPLED_ALLOC) != 0;
! bool in_heap = (decorators & IN_HEAP) != 0;
! bool on_weak = (decorators & ON_WEAK_OOP_REF) != 0;
! bool on_phantom = (decorators & ON_PHANTOM_OOP_REF) != 0;
! if (tightly_coupled) {
! access.set_barrier_data(ShenandoahBitElided);
+ return;
}
! uint8_t barrier_data = 0;
! if (load) {
! if (ShenandoahLoadRefBarrier) {
! if (on_phantom) {
! barrier_data |= ShenandoahBitPhantom;
! } else if (on_weak) {
! barrier_data |= ShenandoahBitWeak;
! } else {
! barrier_data |= ShenandoahBitStrong;
}
}
}
! if (store) {
! if (ShenandoahSATBBarrier) {
! barrier_data |= ShenandoahBitKeepAlive;
! }
! if (ShenandoahCardBarrier && in_heap) {
! barrier_data |= ShenandoahBitCardMark;
}
}
! if (!in_heap) {
! barrier_data |= ShenandoahBitNative;
! }
! access.set_barrier_data(barrier_data);
! }
! Node* ShenandoahBarrierSetC2::load_at_resolved(C2Access& access, const Type* val_type) const {
! // 1: Non-reference load, no additional barrier is needed
+ if (!access.is_oop()) {
+ return BarrierSetC2::load_at_resolved(access, val_type);
+ }
! // 2. Set barrier data for load
! set_barrier_data(access, /* load = */ true, /* store = */ false);
! // 3. Correction: If we are reading the value of the referent field of
! // a Reference object, we need to record the referent resurrection.
! DecoratorSet decorators = access.decorators();
! bool on_weak = (decorators & ON_WEAK_OOP_REF) != 0;
! bool on_phantom = (decorators & ON_PHANTOM_OOP_REF) != 0;
+ bool no_keepalive = (decorators & AS_NO_KEEPALIVE) != 0;
+ bool needs_keepalive = ((on_weak || on_phantom) && !no_keepalive);
+ if (needs_keepalive) {
+ uint8_t barriers = access.barrier_data() | (ShenandoahSATBBarrier ? ShenandoahBitKeepAlive : 0);
+ access.set_barrier_data(barriers);
+ }
! return BarrierSetC2::load_at_resolved(access, val_type);
+ }
! Node* ShenandoahBarrierSetC2::store_at_resolved(C2Access& access, C2AccessValue& val) const {
! // 1: Non-reference store, no additional barrier is needed
! if (!access.is_oop()) {
! return BarrierSetC2::store_at_resolved(access, val);
! }
! // 2. Set barrier data for store
! set_barrier_data(access, /* load = */ false, /* store = */ true);
! // 3. Correction: avoid keep-alive barriers that should not do keep-alive.
! DecoratorSet decorators = access.decorators();
! bool no_keepalive = (decorators & AS_NO_KEEPALIVE) != 0;
! if (no_keepalive) {
! access.set_barrier_data(access.barrier_data() & ~ShenandoahBitKeepAlive);
}
! return BarrierSetC2::store_at_resolved(access, val);
}
! Node* ShenandoahBarrierSetC2::atomic_cmpxchg_val_at_resolved(C2AtomicParseAccess& access, Node* expected_val,
! Node* new_val, const Type* value_type) const {
! set_barrier_data(access, /* load = */ true, /* store = */ true);
+ return BarrierSetC2::atomic_cmpxchg_val_at_resolved(access, expected_val, new_val, value_type);
}
! Node* ShenandoahBarrierSetC2::atomic_cmpxchg_bool_at_resolved(C2AtomicParseAccess& access, Node* expected_val,
! Node* new_val, const Type* value_type) const {
! set_barrier_data(access, /* load = */ true, /* store = */ true);
! return BarrierSetC2::atomic_cmpxchg_bool_at_resolved(access, expected_val, new_val, value_type);
}
! Node* ShenandoahBarrierSetC2::atomic_xchg_at_resolved(C2AtomicParseAccess& access, Node* val, const Type* value_type) const {
! set_barrier_data(access, /* load = */ true, /* store = */ true);
! return BarrierSetC2::atomic_xchg_at_resolved(access, val, value_type);
! }
! bool ShenandoahBarrierSetC2::is_Load(int opcode) {
! switch (opcode) {
! case Op_LoadN:
! case Op_LoadP:
! return true;
! default:
! return false;
}
}
! bool ShenandoahBarrierSetC2::is_Store(int opcode) {
! switch (opcode) {
! case Op_StoreN:
! case Op_StoreP:
! return true;
! default:
+ return false;
+ }
}
! bool ShenandoahBarrierSetC2::is_LoadStore(int opcode) {
! switch (opcode) {
! case Op_CompareAndExchangeN:
! case Op_CompareAndExchangeP:
! case Op_WeakCompareAndSwapN:
! case Op_WeakCompareAndSwapP:
! case Op_CompareAndSwapN:
! case Op_CompareAndSwapP:
! case Op_GetAndSetP:
! case Op_GetAndSetN:
! return true;
! default:
! return false;
}
}
! bool ShenandoahBarrierSetC2::can_remove_load_barrier(Node* root) {
! // Check if all outs feed into nodes that do not expose the oops to the rest
! // of the runtime system. In this case, we can elide the LRB barrier. We bail
! // out with false at the first sight of trouble.
! ResourceMark rm;
! VectorSet visited;
! Node_List worklist;
! worklist.push(root);
! while (worklist.size() > 0) {
! Node* n = worklist.pop();
! if (visited.test_set(n->_idx)) {
! continue;
}
! for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
! Node* out = n->fast_out(i);
! switch (out->Opcode()) {
! case Op_EncodeP:
! case Op_DecodeN:
! case Op_CastPP:
! case Op_CheckCastPP:
! case Op_AddP: {
! // Transitive node, check if any other outs are doing anything troublesome.
! worklist.push(out);
! break;
! }
! case Op_LoadRange:
! case Op_LoadKlass: {
+ // Loads of stable metadata values from the object. These are the same in all copies.
+ // Note that LoadNKlass is *not* safe: with +UCOH, it loads from mark word, which
+ // clashes with forwarding pointers.
+ break;
+ }
! case Op_CmpN: {
! if (out->in(1) == n &&
! out->in(2)->Opcode() == Op_ConN &&
+ out->in(2)->get_narrowcon() == 0) {
+ // Null check, no oop is exposed.
+ break;
+ }
+ if (out->in(2) == n &&
+ out->in(1)->Opcode() == Op_ConN &&
+ out->in(1)->get_narrowcon() == 0) {
+ // Null check, no oop is exposed.
+ break;
+ }
+ return false;
+ }
! case Op_CmpP: {
! if (out->in(1) == n &&
+ out->in(2)->Opcode() == Op_ConP &&
+ out->in(2)->get_ptr() == 0) {
+ // Null check, no oop is exposed.
+ break;
+ }
+ if (out->in(2) == n &&
+ out->in(1)->Opcode() == Op_ConP &&
+ out->in(1)->get_ptr() == 0) {
+ // Null check, no oop is exposed.
+ break;
+ }
+ return false;
+ }
! case Op_CallStaticJava: {
! if (out->as_CallStaticJava()->is_uncommon_trap()) {
! // Local feeds into uncommon trap. Deopt machinery handles barriers itself.
! break;
! }
! return false;
}
! default: {
! // Paranoidly distrust any other nodes.
+ return false;
+ }
+ }
+ }
+ }
! // Nothing troublesome found.
! return true;
}
! uint8_t ShenandoahBarrierSetC2::refine_load(Node* n, uint8_t bd) {
! assert(ShenandoahElideBarriers, "Checked by caller");
! assert(bd != 0, "Checked by caller");
! // Do not touch weak loads at all: they are responsible for shielding from
! // Reference.referent resurrection.
! if ((bd & (ShenandoahBitWeak | ShenandoahBitPhantom)) != 0) {
! return bd;
}
! if (can_remove_load_barrier(n)) {
! bd &= ~ShenandoahBitStrong;
! bd |= ShenandoahBitElided;
}
! return bd;
! }
! uint8_t ShenandoahBarrierSetC2::refine_store(Node* n, uint8_t bd) {
! assert(ShenandoahElideBarriers, "Checked by caller");
! assert(bd != 0, "Checked by caller");
+ assert(n->is_Mem() || n->is_LoadStore(), "Sanity");
! // Not an oop store? There should be no barriers.
! const Node* newval = n->in(MemNode::ValueIn);
! assert(newval != nullptr, "Should be present");
! const Type* newval_bottom = newval->bottom_type();
! if (!newval_bottom->isa_oopptr() &&
! !newval_bottom->isa_narrowoop() &&
! newval_bottom != TypePtr::NULL_PTR) {
! assert(bd == 0, "Non-oop stores should have no barrier data");
! return bd;
}
! // Type system tells us something about nullity?
! const TypePtr* newval_type = newval_bottom->make_ptr();
! assert(newval_type != nullptr, "Should have been filtered before");
! TypePtr::PTR newval_type_ptr = newval_type->ptr();
! if (newval_type_ptr == TypePtr::Null) {
+ bd &= ~ShenandoahBitNotNull;
+ // Card table barrier is not needed if we store null.
+ bd &= ~ShenandoahBitCardMark;
+ } else if (newval_type_ptr == TypePtr::NotNull) {
+ // Definitely not null.
+ bd |= ShenandoahBitNotNull;
}
! return bd;
}
! bool ShenandoahBarrierSetC2::expand_barriers(Compile* C, PhaseIterGVN& igvn) const {
! if (!ShenandoahElideBarriers) {
! return false;
}
! ResourceMark rm;
! VectorSet visited;
! Node_List worklist;
! worklist.push(C->root());
+ while (worklist.size() > 0) {
+ Node* n = worklist.pop();
+ if (visited.test_set(n->_idx)) {
+ continue;
+ }
! int opc = n->Opcode();
! bool is_load = is_Load(opc);
! bool is_store = is_Store(opc);
+ bool is_load_store = is_LoadStore(opc);
! uint8_t bd = 0;
! if (is_load_store) {
! bd = n->as_LoadStore()->barrier_data();
! } else if (is_load || is_store) {
+ bd = n->as_Mem()->barrier_data();
+ }
! if (bd != 0) {
+ if (is_load || is_load_store) {
+ bd = refine_load(n, bd);
+ }
+ if (is_store || is_load_store) {
+ bd = refine_store(n, bd);
+ }
+ if (is_load_store) {
+ n->as_LoadStore()->set_barrier_data(bd);
+ } else {
+ n->as_Mem()->set_barrier_data(bd);
+ }
+ }
! for (uint j = 0; j < n->req(); j++) {
! Node* in = n->in(j);
! if (in != nullptr) {
! worklist.push(in);
! }
}
}
+ return false;
}
! // Support for macro expanded GC barriers
! void ShenandoahBarrierSetC2::eliminate_gc_barrier_data(Node* node) const {
! if (node->is_LoadStore()) {
! LoadStoreNode* loadstore = node->as_LoadStore();
+ loadstore->set_barrier_data(0);
+ } else if (node->is_Mem()) {
+ MemNode* mem = node->as_Mem();
+ mem->set_barrier_data(0);
}
+ }
! // If there are no real barrier flags on the node, strip away additional fluff.
! // Matcher does not care about this, and we would like to avoid invoking "barrier_data() != 0"
! // rules when the only flags are the irrelevant fluff.
! void ShenandoahBarrierSetC2::strip_extra_data(const Node* n) const {
! if (n->is_LoadStore()) {
! LoadStoreNode* load_store = n->as_LoadStore();
! uint8_t barrier_data = load_store->barrier_data();
! if ((barrier_data & ShenandoahBitsReal) == 0) {
! load_store->set_barrier_data(0);
}
! } else if (n->is_Mem()) {
! MemNode* mem = n->as_Mem();
! uint8_t barrier_data = mem->barrier_data();
! if ((barrier_data & ShenandoahBitsReal) == 0) {
! mem->set_barrier_data(0);
}
+ }
+ }
! void ShenandoahBarrierSetC2::strip_extra_data(Node_List& accesses) const {
! for (uint c = 0; c < accesses.size(); c++) {
! strip_extra_data(accesses.at(c));
}
+ }
! void ShenandoahBarrierSetC2::eliminate_gc_barrier(PhaseMacroExpand* macro, Node* node) const {
+ eliminate_gc_barrier_data(node);
}
! void ShenandoahBarrierSetC2::elide_dominated_barrier(MachNode* node, MachNode* dominator) const {
! uint8_t orig_bd = node->barrier_data();
! if (orig_bd == 0) {
! // Nothing to do.
! return;
! }
! uint8_t bd = orig_bd;
! int node_opcode = node->ideal_Opcode();
! if (dominator == nullptr) {
! // Must be allocation node.
! if (is_Load(node_opcode) || is_LoadStore(node_opcode)) {
+ // Loads from recent allocations do not need LRBs.
+ bd &= ~ShenandoahBitStrong;
}
! if (is_Store(node_opcode) || is_LoadStore(node_opcode)) {
! // Stores to recent allocations do not need KA or CM.
! bd &= ~ShenandoahBitKeepAlive;
! bd &= ~ShenandoahBitCardMark;
}
! } else {
! assert(is_Load(node_opcode) || is_Store(node_opcode) || is_LoadStore(node_opcode), "Sanity");
! int dom_opcode = dominator->ideal_Opcode();
! uint8_t dom_bd = dominator->barrier_data();
!
! if (is_Load(dom_opcode) || is_LoadStore(dom_opcode)) {
! // If dominating load is set up to perform LRB fixups, no further LRB is needed.
! if ((dom_bd & ShenandoahBitStrong) != 0) {
! bd &= ~ShenandoahBitStrong;
}
}
! if (is_Store(dom_opcode)) {
! // Dominating store has stored the good ref, no LRB is needed.
! bd &= ~ShenandoahBitStrong;
}
}
! if (orig_bd != bd) {
! node->set_barrier_data(bd);
}
}
+ void ShenandoahBarrierSetC2::analyze_dominating_barriers() const {
+ if (!ShenandoahElideDominatedBarriers) {
+ return;
+ }
! ResourceMark rm;
! Node_List accesses, dominators;
! PhaseCFG* const cfg = Compile::current()->cfg();
! for (uint i = 0; i < cfg->number_of_blocks(); ++i) {
! const Block* const block = cfg->get_block(i);
! for (uint j = 0; j < block->number_of_nodes(); ++j) {
! Node* const node = block->get_node(j);
! // Everything that happens in allocations does not need barriers.
! // Record them for dominance analysis.
! if (node->is_Phi() && is_allocation(node)) {
! dominators.push(node);
! continue;
! }
+
+ if (!node->is_Mach()) {
+ continue;
+ }
+
+ MachNode* const mach = node->as_Mach();
+ int opcode = mach->ideal_Opcode();
+ if (is_Load(opcode) || is_Store(opcode) || is_LoadStore(opcode)) {
+ if ((mach->barrier_data() & ShenandoahBitsReal) != 0) {
+ accesses.push(mach);
+ dominators.push(mach);
+ }
+ }
+ }
}
! elide_dominated_barriers(accesses, dominators);
!
+ // Also clean up extra metadata. Dominance analysis likely left
+ // many non-elided barriers with extra metadata, which can be stripped away.
+ strip_extra_data(accesses);
}
! uint ShenandoahBarrierSetC2::estimated_barrier_size(const Node* node) const {
! // Barrier impact on fast-path is driven by GC state checks emitted very late.
! // These checks are tight load-test-branch sequences, with no impact on C2 graph
! // size. Limiting unrolling in presence of GC barriers might turn some loops
! // tighter than with default unrolling, which may benefit performance due to denser
! // code. Testing shows it is still counter-productive.
! // Therefore, we report zero barrier size to let C2 do its normal thing.
+ return 0;
}
bool ShenandoahBarrierSetC2::array_copy_requires_gc_barriers(bool tightly_coupled_alloc, BasicType type, bool is_clone, bool is_clone_instance, ArrayCopyPhase phase) const {
bool is_oop = is_reference_type(type);
if (!is_oop) {
return !is_clone;
}
return true;
}
! bool ShenandoahBarrierSetC2::clone_needs_barrier(Node* src, PhaseGVN& gvn) {
! const TypeOopPtr* src_type = gvn.type(src)->is_oopptr();
if (src_type->isa_instptr() != nullptr) {
ciInstanceKlass* ik = src_type->is_instptr()->instance_klass();
! if ((src_type->klass_is_exact() || !ik->has_subklass()) && !ik->has_injected_fields()) {
! if (ik->has_object_fields()) {
! return true;
! } else {
! if (!src_type->klass_is_exact()) {
! Compile::current()->dependencies()->assert_leaf_type(ik);
- }
}
! } else {
! return true;
! }
! } else if (src_type->isa_aryptr()) {
BasicType src_elem = src_type->isa_aryptr()->elem()->array_element_basic_type();
if (is_reference_type(src_elem, true)) {
! return true;
}
- } else {
- return true;
}
- return false;
- }
! void ShenandoahBarrierSetC2::clone_at_expansion(PhaseMacroExpand* phase, ArrayCopyNode* ac) const {
! Node* ctrl = ac->in(TypeFunc::Control);
- Node* mem = ac->in(TypeFunc::Memory);
- Node* src_base = ac->in(ArrayCopyNode::Src);
- Node* src_offset = ac->in(ArrayCopyNode::SrcPos);
- Node* dest_base = ac->in(ArrayCopyNode::Dest);
- Node* dest_offset = ac->in(ArrayCopyNode::DestPos);
- Node* length = ac->in(ArrayCopyNode::Length);
-
- Node* src = phase->basic_plus_adr(src_base, src_offset);
- Node* dest = phase->basic_plus_adr(dest_base, dest_offset);
-
- if (ShenandoahCloneBarrier && clone_needs_barrier(src, phase->igvn())) {
- // Check if heap is has forwarded objects. If it does, we need to call into the special
- // routine that would fix up source references before we can continue.
-
- enum { _heap_stable = 1, _heap_unstable, PATH_LIMIT };
- Node* region = new RegionNode(PATH_LIMIT);
- Node* mem_phi = new PhiNode(region, Type::MEMORY, TypeRawPtr::BOTTOM);
-
- Node* thread = phase->transform_later(new ThreadLocalNode());
- Node* offset = phase->igvn().MakeConX(in_bytes(ShenandoahThreadLocalData::gc_state_offset()));
- Node* gc_state_addr = phase->transform_later(AddPNode::make_off_heap(thread, offset));
-
- uint gc_state_idx = Compile::AliasIdxRaw;
- const TypePtr* gc_state_adr_type = nullptr; // debug-mode-only argument
- DEBUG_ONLY(gc_state_adr_type = phase->C->get_adr_type(gc_state_idx));
-
- Node* gc_state = phase->transform_later(new LoadBNode(ctrl, mem, gc_state_addr, gc_state_adr_type, TypeInt::BYTE, MemNode::unordered));
- Node* stable_and = phase->transform_later(new AndINode(gc_state, phase->igvn().intcon(ShenandoahHeap::HAS_FORWARDED)));
- Node* stable_cmp = phase->transform_later(new CmpINode(stable_and, phase->igvn().zerocon(T_INT)));
- Node* stable_test = phase->transform_later(new BoolNode(stable_cmp, BoolTest::ne));
-
- IfNode* stable_iff = phase->transform_later(new IfNode(ctrl, stable_test, PROB_UNLIKELY(0.999), COUNT_UNKNOWN))->as_If();
- Node* stable_ctrl = phase->transform_later(new IfFalseNode(stable_iff));
- Node* unstable_ctrl = phase->transform_later(new IfTrueNode(stable_iff));
-
- // Heap is stable, no need to do anything additional
- region->init_req(_heap_stable, stable_ctrl);
- mem_phi->init_req(_heap_stable, mem);
-
- // Heap is unstable, call into clone barrier stub
- Node* call = phase->make_leaf_call(unstable_ctrl, mem,
- ShenandoahBarrierSetC2::clone_barrier_Type(),
- CAST_FROM_FN_PTR(address, ShenandoahRuntime::clone_barrier),
- "shenandoah_clone",
- TypeRawPtr::BOTTOM,
- src_base);
- call = phase->transform_later(call);
-
- ctrl = phase->transform_later(new ProjNode(call, TypeFunc::Control));
- mem = phase->transform_later(new ProjNode(call, TypeFunc::Memory));
- region->init_req(_heap_unstable, ctrl);
- mem_phi->init_req(_heap_unstable, mem);
-
- // Wire up the actual arraycopy stub now
- ctrl = phase->transform_later(region);
- mem = phase->transform_later(mem_phi);
-
- const char* name = "arraycopy";
- call = phase->make_leaf_call(ctrl, mem,
- OptoRuntime::fast_arraycopy_Type(),
- phase->basictype2arraycopy(T_LONG, nullptr, nullptr, true, name, true),
- name, TypeRawPtr::BOTTOM,
- src, dest, length
- LP64_ONLY(COMMA phase->top()));
- call = phase->transform_later(call);
-
- // Hook up the whole thing into the graph
- phase->igvn().replace_node(ac, call);
- } else {
- BarrierSetC2::clone_at_expansion(phase, ac);
- }
}
! // Support for macro expanded GC barriers
! void ShenandoahBarrierSetC2::register_potential_barrier_node(Node* node) const {
! if (node->Opcode() == Op_ShenandoahLoadReferenceBarrier) {
! state()->add_load_reference_barrier((ShenandoahLoadReferenceBarrierNode*) node);
}
- }
! void ShenandoahBarrierSetC2::unregister_potential_barrier_node(Node* node) const {
! if (node->Opcode() == Op_ShenandoahLoadReferenceBarrier) {
! state()->remove_load_reference_barrier((ShenandoahLoadReferenceBarrierNode*) node);
}
- }
! void ShenandoahBarrierSetC2::eliminate_gc_barrier(PhaseMacroExpand* macro, Node* node) const {
! if (is_shenandoah_wb_pre_call(node)) {
! shenandoah_eliminate_wb_pre(node, ¯o->igvn());
! }
! if (ShenandoahCardBarrier && node->Opcode() == Op_CastP2X) {
! Node* shift = node->unique_out();
! Node* addp = shift->unique_out();
! for (DUIterator_Last jmin, j = addp->last_outs(jmin); j >= jmin; --j) {
! Node* mem = addp->last_out(j);
! if (UseCondCardMark && mem->is_Load()) {
! assert(mem->Opcode() == Op_LoadB, "unexpected code shape");
! // The load is checking if the card has been written so
! // replace it with zero to fold the test.
! macro->replace_node(mem, macro->intcon(0));
- continue;
- }
- assert(mem->is_Store(), "store required");
- macro->replace_node(mem, mem->in(MemNode::Memory));
- }
}
}
! void ShenandoahBarrierSetC2::shenandoah_eliminate_wb_pre(Node* call, PhaseIterGVN* igvn) const {
! assert(UseShenandoahGC && is_shenandoah_wb_pre_call(call), "");
! Node* c = call->as_Call()->proj_out(TypeFunc::Control);
! c = c->unique_ctrl_out();
! assert(c->is_Region() && c->req() == 3, "where's the pre barrier control flow?");
! c = c->unique_ctrl_out();
! assert(c->is_Region() && c->req() == 3, "where's the pre barrier control flow?");
! Node* iff = c->in(1)->is_IfProj() ? c->in(1)->in(0) : c->in(2)->in(0);
! assert(iff->is_If(), "expect test");
! if (!is_shenandoah_marking_if(igvn, iff)) {
! c = c->unique_ctrl_out();
! assert(c->is_Region() && c->req() == 3, "where's the pre barrier control flow?");
! iff = c->in(1)->is_IfProj() ? c->in(1)->in(0) : c->in(2)->in(0);
! assert(is_shenandoah_marking_if(igvn, iff), "expect marking test");
}
- Node* cmpx = iff->in(1)->in(1);
- igvn->replace_node(cmpx, igvn->makecon(TypeInt::CC_EQ));
- igvn->rehash_node_delayed(call);
- call->del_req(call->req()-1);
- }
! void ShenandoahBarrierSetC2::enqueue_useful_gc_barrier(PhaseIterGVN* igvn, Node* node) const {
! if (node->Opcode() == Op_AddP && ShenandoahBarrierSetC2::has_only_shenandoah_wb_pre_uses(node)) {
! igvn->add_users_to_worklist(node);
}
- }
! void ShenandoahBarrierSetC2::eliminate_useless_gc_barriers(Unique_Node_List &useful, Compile* C) const {
! for (uint i = 0; i < useful.size(); i++) {
- Node* n = useful.at(i);
- if (n->Opcode() == Op_AddP && ShenandoahBarrierSetC2::has_only_shenandoah_wb_pre_uses(n)) {
- for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
- C->record_for_igvn(n->fast_out(i));
- }
- }
- }
! for (int i = state()->load_reference_barriers_count() - 1; i >= 0; i--) {
! ShenandoahLoadReferenceBarrierNode* n = state()->load_reference_barrier(i);
! if (!useful.member(n)) {
! state()->remove_load_reference_barrier(n);
! }
! }
}
void* ShenandoahBarrierSetC2::create_barrier_state(Arena* comp_arena) const {
return new(comp_arena) ShenandoahBarrierSetC2State(comp_arena);
}
ShenandoahBarrierSetC2State* ShenandoahBarrierSetC2::state() const {
return reinterpret_cast<ShenandoahBarrierSetC2State*>(Compile::current()->barrier_set_state());
}
! // If the BarrierSetC2 state has kept macro nodes in its compilation unit state to be
! // expanded later, then now is the time to do so.
! bool ShenandoahBarrierSetC2::expand_macro_nodes(PhaseMacroExpand* macro) const { return false; }
#ifdef ASSERT
void ShenandoahBarrierSetC2::verify_gc_barriers(Compile* compile, CompilePhase phase) const {
! if (ShenandoahVerifyOptoBarriers && phase == BarrierSetC2::BeforeMacroExpand) {
! ShenandoahBarrierC2Support::verify(Compile::current()->root());
! } else if (phase == BarrierSetC2::BeforeCodeGen) {
- // Verify Shenandoah pre-barriers
- const int gc_state_offset = in_bytes(ShenandoahThreadLocalData::gc_state_offset());
-
- Unique_Node_List visited;
- Node_List worklist;
- // We're going to walk control flow backwards starting from the Root
- worklist.push(compile->root());
- while (worklist.size() > 0) {
- Node *x = worklist.pop();
- if (x == nullptr || x == compile->top()) {
- continue;
- }
! if (visited.member(x)) {
! continue;
! } else {
! visited.push(x);
}
!
! if (x->is_Region()) {
! for (uint i = 1; i < x->req(); i++) {
! worklist.push(x->in(i));
}
! } else {
! worklist.push(x->in(0));
! // We are looking for the pattern:
! // /->ThreadLocal
! // If->Bool->CmpI->LoadB->AddP->ConL(marking_offset)
- // \->ConI(0)
- // We want to verify that the If and the LoadB have the same control
- // See GraphKit::g1_write_barrier_pre()
- if (x->is_If()) {
- IfNode *iff = x->as_If();
- if (iff->in(1)->is_Bool() && iff->in(1)->in(1)->is_Cmp()) {
- CmpNode *cmp = iff->in(1)->in(1)->as_Cmp();
- if (cmp->Opcode() == Op_CmpI && cmp->in(2)->is_Con() && cmp->in(2)->bottom_type()->is_int()->get_con() == 0
- && cmp->in(1)->is_Load()) {
- LoadNode *load = cmp->in(1)->as_Load();
- if (load->Opcode() == Op_LoadB && load->in(2)->is_AddP() && load->in(2)->in(2)->Opcode() == Op_ThreadLocal
- && load->in(2)->in(3)->is_Con()
- && load->in(2)->in(3)->bottom_type()->is_intptr_t()->get_con() == gc_state_offset) {
-
- Node *if_ctrl = iff->in(0);
- Node *load_ctrl = load->in(0);
-
- if (if_ctrl != load_ctrl) {
- // Skip possible CProj->NeverBranch in infinite loops
- if ((if_ctrl->is_Proj() && if_ctrl->Opcode() == Op_CProj)
- && if_ctrl->in(0)->is_NeverBranch()) {
- if_ctrl = if_ctrl->in(0)->in(0);
- }
- }
- assert(load_ctrl != nullptr && if_ctrl == load_ctrl, "controls must match");
- }
- }
- }
}
}
}
}
}
#endif
! Node* ShenandoahBarrierSetC2::ideal_node(PhaseGVN* phase, Node* n, bool can_reshape) const {
! if (is_shenandoah_wb_pre_call(n)) {
! uint cnt = ShenandoahBarrierSetC2::write_barrier_pre_Type()->domain()->cnt();
! if (n->req() > cnt) {
! Node* addp = n->in(cnt);
! if (has_only_shenandoah_wb_pre_uses(addp)) {
! n->del_req(cnt);
! if (can_reshape) {
! phase->is_IterGVN()->_worklist.push(addp);
! }
! return n;
! }
}
}
- if (n->Opcode() == Op_CmpP) {
- Node* in1 = n->in(1);
- Node* in2 = n->in(2);
-
- // If one input is null, then step over the strong LRB barriers on the other input
- if (in1->bottom_type() == TypePtr::NULL_PTR &&
- !((in2->Opcode() == Op_ShenandoahLoadReferenceBarrier) &&
- !ShenandoahBarrierSet::is_strong_access(((ShenandoahLoadReferenceBarrierNode*)in2)->decorators()))) {
- in2 = step_over_gc_barrier(in2);
- }
- if (in2->bottom_type() == TypePtr::NULL_PTR &&
- !((in1->Opcode() == Op_ShenandoahLoadReferenceBarrier) &&
- !ShenandoahBarrierSet::is_strong_access(((ShenandoahLoadReferenceBarrierNode*)in1)->decorators()))) {
- in1 = step_over_gc_barrier(in1);
- }
! if (in1 != n->in(1)) {
! n->set_req_X(1, in1, phase);
! assert(in2 == n->in(2), "only one change");
! return n;
! }
! if (in2 != n->in(2)) {
! n->set_req_X(2, in2, phase);
! return n;
- }
- } else if (can_reshape &&
- n->Opcode() == Op_If &&
- ShenandoahBarrierC2Support::is_heap_stable_test(n) &&
- n->in(0) != nullptr &&
- n->outcnt() == 2) {
- Node* dom = n->in(0);
- Node* prev_dom = n;
- int op = n->Opcode();
- int dist = 16;
- // Search up the dominator tree for another heap stable test
- while (dom->Opcode() != op || // Not same opcode?
- !ShenandoahBarrierC2Support::is_heap_stable_test(dom) || // Not same input 1?
- prev_dom->in(0) != dom) { // One path of test does not dominate?
- if (dist < 0) return nullptr;
-
- dist--;
- prev_dom = dom;
- dom = IfNode::up_one_dom(dom);
- if (!dom) return nullptr;
- }
! // Check that we did not follow a loop back to ourselves
! if (n == dom) {
- return nullptr;
- }
! return n->as_If()->dominated_by(prev_dom, phase->is_IterGVN(), false);
}
! return nullptr;
}
! bool ShenandoahBarrierSetC2::has_only_shenandoah_wb_pre_uses(Node* n) {
! for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
- Node* u = n->fast_out(i);
- if (!is_shenandoah_wb_pre_call(u)) {
- return false;
- }
- }
- return n->outcnt() > 0;
}
! bool ShenandoahBarrierSetC2::final_graph_reshaping(Compile* compile, Node* n, uint opcode, Unique_Node_List& dead_nodes) const {
! switch (opcode) {
! case Op_CallLeaf:
! case Op_CallLeafNoFP: {
! assert (n->is_Call(), "");
! CallNode *call = n->as_Call();
! if (ShenandoahBarrierSetC2::is_shenandoah_wb_pre_call(call)) {
! uint cnt = ShenandoahBarrierSetC2::write_barrier_pre_Type()->domain()->cnt();
! if (call->req() > cnt) {
! assert(call->req() == cnt + 1, "only one extra input");
! Node *addp = call->in(cnt);
! assert(!ShenandoahBarrierSetC2::has_only_shenandoah_wb_pre_uses(addp), "useless address computation?");
! call->del_req(cnt);
! }
}
- return false;
}
- case Op_ShenandoahCompareAndSwapP:
- case Op_ShenandoahCompareAndSwapN:
- case Op_ShenandoahWeakCompareAndSwapN:
- case Op_ShenandoahWeakCompareAndSwapP:
- case Op_ShenandoahCompareAndExchangeP:
- case Op_ShenandoahCompareAndExchangeN:
- return true;
- case Op_ShenandoahLoadReferenceBarrier:
- assert(false, "should have been expanded already");
- return true;
- default:
- return false;
}
- }
! bool ShenandoahBarrierSetC2::escape_add_to_con_graph(ConnectionGraph* conn_graph, PhaseGVN* gvn, Unique_Node_List* delayed_worklist, Node* n, uint opcode) const {
! switch (opcode) {
! case Op_ShenandoahCompareAndExchangeP:
! case Op_ShenandoahCompareAndExchangeN:
! conn_graph->add_objload_to_connection_graph(n, delayed_worklist);
! // fallthrough
- case Op_ShenandoahWeakCompareAndSwapP:
- case Op_ShenandoahWeakCompareAndSwapN:
- case Op_ShenandoahCompareAndSwapP:
- case Op_ShenandoahCompareAndSwapN:
- conn_graph->add_to_congraph_unsafe_access(n, opcode, delayed_worklist);
- return true;
- case Op_StoreP: {
- Node* adr = n->in(MemNode::Address);
- const Type* adr_type = gvn->type(adr);
- // Pointer stores in Shenandoah barriers looks like unsafe access.
- // Ignore such stores to be able scalar replace non-escaping
- // allocations.
- if (adr_type->isa_rawptr() && adr->is_AddP()) {
- Node* base = conn_graph->get_addp_base(adr);
- if (base->Opcode() == Op_LoadP &&
- base->in(MemNode::Address)->is_AddP()) {
- adr = base->in(MemNode::Address);
- Node* tls = conn_graph->get_addp_base(adr);
- if (tls->Opcode() == Op_ThreadLocal) {
- int offs = (int) gvn->find_intptr_t_con(adr->in(AddPNode::Offset), Type::OffsetBot);
- const int buf_offset = in_bytes(ShenandoahThreadLocalData::satb_mark_queue_buffer_offset());
- if (offs == buf_offset) {
- return true; // Pre barrier previous oop value store.
- }
- }
- }
- }
- return false;
- }
- case Op_ShenandoahLoadReferenceBarrier:
- conn_graph->add_local_var_and_edge(n, PointsToNode::NoEscape, n->in(ShenandoahLoadReferenceBarrierNode::ValueIn), delayed_worklist);
- return true;
- default:
- // Nothing
- break;
}
! return false;
}
! bool ShenandoahBarrierSetC2::escape_add_final_edges(ConnectionGraph* conn_graph, PhaseGVN* gvn, Node* n, uint opcode) const {
! switch (opcode) {
! case Op_ShenandoahCompareAndExchangeP:
! case Op_ShenandoahCompareAndExchangeN: {
! Node *adr = n->in(MemNode::Address);
- conn_graph->add_local_var_and_edge(n, PointsToNode::NoEscape, adr, nullptr);
- // fallthrough
- }
- case Op_ShenandoahCompareAndSwapP:
- case Op_ShenandoahCompareAndSwapN:
- case Op_ShenandoahWeakCompareAndSwapP:
- case Op_ShenandoahWeakCompareAndSwapN:
- return conn_graph->add_final_edges_unsafe_access(n, opcode);
- case Op_ShenandoahLoadReferenceBarrier:
- conn_graph->add_local_var_and_edge(n, PointsToNode::NoEscape, n->in(ShenandoahLoadReferenceBarrierNode::ValueIn), nullptr);
- return true;
- default:
- // Nothing
- break;
}
- return false;
}
! bool ShenandoahBarrierSetC2::escape_has_out_with_unsafe_object(Node* n) const {
! return n->has_out_with(Op_ShenandoahCompareAndExchangeP) || n->has_out_with(Op_ShenandoahCompareAndExchangeN) ||
! n->has_out_with(Op_ShenandoahCompareAndSwapP, Op_ShenandoahCompareAndSwapN, Op_ShenandoahWeakCompareAndSwapP, Op_ShenandoahWeakCompareAndSwapN);
!
- }
! bool ShenandoahBarrierSetC2::matcher_find_shared_post_visit(Matcher* matcher, Node* n, uint opcode) const {
! switch (opcode) {
! case Op_ShenandoahCompareAndExchangeP:
! case Op_ShenandoahCompareAndExchangeN:
! case Op_ShenandoahWeakCompareAndSwapP:
! case Op_ShenandoahWeakCompareAndSwapN:
! case Op_ShenandoahCompareAndSwapP:
! case Op_ShenandoahCompareAndSwapN: { // Convert trinary to binary-tree
! Node* newval = n->in(MemNode::ValueIn);
! Node* oldval = n->in(LoadStoreConditionalNode::ExpectedIn);
! Node* pair = new BinaryNode(oldval, newval);
! n->set_req(MemNode::ValueIn,pair);
! n->del_req(LoadStoreConditionalNode::ExpectedIn);
! return true;
}
- default:
- break;
}
! return false;
}
! bool ShenandoahBarrierSetC2::matcher_is_store_load_barrier(Node* x, uint xop) const {
! return xop == Op_ShenandoahCompareAndExchangeP ||
! xop == Op_ShenandoahCompareAndExchangeN ||
! xop == Op_ShenandoahWeakCompareAndSwapP ||
! xop == Op_ShenandoahWeakCompareAndSwapN ||
! xop == Op_ShenandoahCompareAndSwapN ||
! xop == Op_ShenandoahCompareAndSwapP;
}
return !is_clone;
}
return true;
}
! bool ShenandoahBarrierSetC2::clone_needs_barrier(const TypeOopPtr* src_type, bool& is_oop_array) {
! if (!ShenandoahCloneBarrier) {
+ return false;
+ }
+
if (src_type->isa_instptr() != nullptr) {
+ // Instance: need barrier only if there is a possibility of having an oop anywhere in it.
ciInstanceKlass* ik = src_type->is_instptr()->instance_klass();
! if ((src_type->klass_is_exact() || !ik->has_subklass()) &&
! !ik->has_injected_fields() && !ik->has_object_fields()) {
! if (!src_type->klass_is_exact()) {
! // Class is *currently* the leaf in the hierarchy.
! // Record the dependency so that we deopt if this does not hold in future.
! Compile::current()->dependencies()->assert_leaf_type(ik);
}
! return false;
! }
! } else if (src_type->isa_aryptr() != nullptr) {
! // Array: need barrier only if array is oop-bearing.
BasicType src_elem = src_type->isa_aryptr()->elem()->array_element_basic_type();
if (is_reference_type(src_elem, true)) {
! is_oop_array = true;
+ } else {
+ return false;
}
}
! // Assume the worst.
! return true;
}
+ void ShenandoahBarrierSetC2::clone(GraphKit* kit, Node* src_base, Node* dst_base, Node* size, bool is_array) const {
+ const TypeOopPtr* src_type = kit->gvn().type(src_base)->is_oopptr();
! bool is_oop_array = false;
! if (!clone_needs_barrier(src_type, is_oop_array)) {
! // No barrier is needed? Just do what common BarrierSetC2 wants with it.
! BarrierSetC2::clone(kit, src_base, dst_base, size, is_array);
+ return;
}
! if (ShenandoahCloneRuntime || !is_array || !is_oop_array) {
! // Looks like an instance? Prepare the instance clone. This would either
! // be exploded into individual accesses or be left as runtime call.
+ // Common BarrierSetC2 prepares everything for both cases.
+ BarrierSetC2::clone(kit, src_base, dst_base, size, is_array);
+ return;
}
! // We are cloning the oop array. Prepare to call the normal arraycopy stub
! // after the expansion. Normal stub takes the number of actual type-sized
! // elements to copy after the base, compute the count here.
! Node* offset = kit->MakeConX(arrayOopDesc::base_offset_in_bytes(UseCompressedOops ? T_NARROWOOP : T_OBJECT));
! size = kit->gvn().transform(new SubXNode(size, offset));
! size = kit->gvn().transform(new URShiftXNode(size, kit->intcon(LogBytesPerHeapOop)));
! ArrayCopyNode* ac = ArrayCopyNode::make(kit, false, src_base, offset, dst_base, offset, size, true, false);
! ac->set_clone_array();
! Node* n = kit->gvn().transform(ac);
! if (n == ac) {
! ac->set_adr_type(TypeRawPtr::BOTTOM);
! kit->set_predefined_output_for_runtime_call(ac, ac->in(TypeFunc::Memory), TypeRawPtr::BOTTOM);
! } else {
! kit->set_all_memory(n);
}
}
! void ShenandoahBarrierSetC2::clone_at_expansion(PhaseMacroExpand* phase, ArrayCopyNode* ac) const {
! Node* const ctrl = ac->in(TypeFunc::Control);
! Node* const mem = ac->in(TypeFunc::Memory);
! Node* const src = ac->in(ArrayCopyNode::Src);
! Node* const src_offset = ac->in(ArrayCopyNode::SrcPos);
! Node* const dest = ac->in(ArrayCopyNode::Dest);
! Node* const dest_offset = ac->in(ArrayCopyNode::DestPos);
! Node* length = ac->in(ArrayCopyNode::Length);
!
! const TypeOopPtr* src_type = phase->igvn().type(src)->is_oopptr();
!
! bool is_oop_array = false;
! if (!clone_needs_barrier(src_type, is_oop_array)) {
! // No barrier is needed? Expand to normal HeapWord-sized arraycopy.
+ BarrierSetC2::clone_at_expansion(phase, ac);
+ return;
}
! if (ShenandoahCloneRuntime || !ac->is_clone_array() || !is_oop_array) {
! // Still looks like an instance? Likely a large instance or reflective
! // clone with unknown length. Go to runtime and handle it there.
+ clone_in_runtime(phase, ac, CAST_FROM_FN_PTR(address, ShenandoahRuntime::clone_addr()), "ShenandoahRuntime::clone");
+ return;
}
! // We are cloning the oop array. Call into normal oop array copy stubs.
! // Those stubs would call BarrierSetAssembler to handle GC barriers.
! // This is the full clone, so offsets should equal each other and be at array base.
! assert(src_offset == dest_offset, "should be equal");
! const jlong offset = src_offset->get_long();
! const TypeAryPtr* const ary_ptr = src->get_ptr_type()->isa_aryptr();
! BasicType bt = ary_ptr->elem()->array_element_basic_type();
! assert(offset == arrayOopDesc::base_offset_in_bytes(bt), "should match");
+
+ const char* copyfunc_name = "arraycopy";
+ const address copyfunc_addr = phase->basictype2arraycopy(T_OBJECT, nullptr, nullptr, true, copyfunc_name, true);
+
+ Node* const call = phase->make_leaf_call(ctrl, mem,
+ OptoRuntime::fast_arraycopy_Type(),
+ copyfunc_addr, copyfunc_name,
+ TypeRawPtr::BOTTOM,
+ phase->basic_plus_adr(src, src_offset),
+ phase->basic_plus_adr(dest, dest_offset),
+ length,
+ phase->top()
+ );
+ phase->transform_later(call);
+
+ phase->igvn().replace_node(ac, call);
}
void* ShenandoahBarrierSetC2::create_barrier_state(Arena* comp_arena) const {
return new(comp_arena) ShenandoahBarrierSetC2State(comp_arena);
}
ShenandoahBarrierSetC2State* ShenandoahBarrierSetC2::state() const {
return reinterpret_cast<ShenandoahBarrierSetC2State*>(Compile::current()->barrier_set_state());
}
! void ShenandoahBarrierSetC2::print_barrier_data(outputStream* os, uint8_t data) {
! os->print(" Node barriers: ");
! if ((data & ShenandoahBitStrong) != 0) {
+ data &= ~ShenandoahBitStrong;
+ os->print("strong ");
+ }
+
+ if ((data & ShenandoahBitWeak) != 0) {
+ data &= ~ShenandoahBitWeak;
+ os->print("weak ");
+ }
+
+ if ((data & ShenandoahBitPhantom) != 0) {
+ data &= ~ShenandoahBitPhantom;
+ os->print("phantom ");
+ }
+
+ if ((data & ShenandoahBitKeepAlive) != 0) {
+ data &= ~ShenandoahBitKeepAlive;
+ os->print("keepalive ");
+ }
+
+ if ((data & ShenandoahBitCardMark) != 0) {
+ data &= ~ShenandoahBitCardMark;
+ os->print("cardmark ");
+ }
+
+ if ((data & ShenandoahBitNative) != 0) {
+ data &= ~ShenandoahBitNative;
+ os->print("native ");
+ }
+
+ if ((data & ShenandoahBitNotNull) != 0) {
+ data &= ~ShenandoahBitNotNull;
+ os->print("not-null ");
+ }
+
+ if ((data & ShenandoahBitElided) != 0) {
+ data &= ~ShenandoahBitElided;
+ os->print("elided ");
+ }
+
+ os->cr();
+
+ if (data > 0) {
+ fatal("Unknown bit!");
+ }
+
+ os->print_cr(" GC configuration: %sLRB %sSATB %sCAS %sClone %sCard",
+ (ShenandoahLoadRefBarrier ? "+" : "-"),
+ (ShenandoahSATBBarrier ? "+" : "-"),
+ (ShenandoahCASBarrier ? "+" : "-"),
+ (ShenandoahCloneBarrier ? "+" : "-"),
+ (ShenandoahCardBarrier ? "+" : "-")
+ );
+ }
#ifdef ASSERT
+ void ShenandoahBarrierSetC2::verify_gc_barrier_assert(bool cond, const char* msg, uint8_t bd, Node* n) {
+ if (!cond) {
+ stringStream ss;
+ ss.print_cr("%s", msg);
+ ss.print_cr("-----------------");
+ print_barrier_data(&ss, bd);
+ ss.print_cr("-----------------");
+ n->dump_bfs(1, nullptr, "", &ss);
+ report_vm_error(__FILE__, __LINE__, ss.as_string());
+ }
+ }
+
void ShenandoahBarrierSetC2::verify_gc_barriers(Compile* compile, CompilePhase phase) const {
! if (!ShenandoahVerifyOptoBarriers) {
! return;
! }
! // Optimizations might have removed the remaining auxiliary flags, making some accesses completely blank.
! bool accept_blank = (phase == BeforeCodeGen);
! bool expect_load_barriers = !accept_blank && ShenandoahLoadRefBarrier;
! bool expect_store_barriers = !accept_blank && (ShenandoahSATBBarrier || ShenandoahCardBarrier);
+ bool expect_load_store_barriers = !accept_blank && ShenandoahCASBarrier;
+
+ Unique_Node_List wq;
+
+ wq.push(compile->root());
+ for (uint next = 0; next < wq.size(); next++) {
+ Node *n = wq.at(next);
+ int opc = n->Opcode();
+
+ uint8_t bd = 0;
+ const TypePtr* adr_type = nullptr;
+ if (is_Load(opc)) {
+ bd = n->as_Load()->barrier_data();
+ adr_type = n->as_Load()->adr_type();
+ } else if (is_Store(opc)) {
+ bd = n->as_Store()->barrier_data();
+ adr_type = n->as_Store()->adr_type();
+ } else if (is_LoadStore(opc)) {
+ bd = n->as_LoadStore()->barrier_data();
+ adr_type = n->as_LoadStore()->adr_type();
+ } else if (n->is_Mem()) {
+ bd = MemNode::barrier_data(n);
+ verify_gc_barrier_assert(bd == 0, "Other mem nodes should have no barrier data", bd, n);
+ }
+
+ bool is_weak = (bd & (ShenandoahBitWeak | ShenandoahBitPhantom)) != 0;
+ bool is_native = (bd & ShenandoahBitNative) != 0;
+
+ bool is_referent = adr_type != nullptr &&
+ adr_type->isa_instptr() &&
+ adr_type->is_instptr()->instance_klass()->is_subtype_of(Compile::current()->env()->Reference_klass()) &&
+ adr_type->is_instptr()->offset() == java_lang_ref_Reference::referent_offset();
+
+ bool is_oop_addr = (adr_type != nullptr) && (adr_type->isa_oopptr() || adr_type->isa_narrowoop());
+ bool is_raw_addr = (adr_type != nullptr) && (adr_type->isa_rawptr() || adr_type->isa_klassptr());
+
+ if (is_oop_addr) {
+ if (is_Load(opc)) {
+ verify_gc_barrier_assert(!expect_load_barriers || (bd != 0), "Oop load should have barrier data", bd, n);
+ verify_gc_barrier_assert(!is_weak || is_referent, "Weak load only for Reference.referent", bd, n);
+ } else if (is_Store(opc)) {
+ // Reference.referent stores can be without barriers.
+ verify_gc_barrier_assert(!expect_store_barriers || is_referent || (bd != 0), "Oop store should have barrier data", bd, n);
+ } else if (is_LoadStore(opc)) {
+ verify_gc_barrier_assert(!expect_load_store_barriers || (bd != 0), "Oop load-store should have barrier data", bd, n);
}
! } else if (is_raw_addr) {
! if (is_native) {
! if (is_Load(opc)) {
! verify_gc_barrier_assert(!expect_load_barriers || (bd != 0), "Native oop load should have barrier data", bd, n);
}
! if (is_Store(opc)) {
! verify_gc_barrier_assert(!expect_store_barriers || (bd != 0), "Native oop store should have barrier data", bd, n);
! }
! if (is_LoadStore(opc)) {
! verify_gc_barrier_assert(!expect_load_store_barriers || (bd != 0), "Native oop load-store should have barrier data", bd, n);
}
+ } else {
+ // Some Load/Stores are used for T_ADDRESS and/or raw stores, which are supposed not to have barriers.
+ // Some other Load/Stores are emitted for real oops, but on raw addresses via Unsafe.
+ // The distinction on this level is lost, so we cannot really verify this.
}
+ } else {
+ if (is_Load(opc) || is_Store(opc) || is_LoadStore(opc)) {
+ verify_gc_barrier_assert(false, "Unclassified access type", bd, n);
+ }
+ }
+
+ for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
+ Node* m = n->fast_out(i);
+ wq.push(m);
}
}
}
#endif
! static ShenandoahBarrierSetC2State* barrier_set_state() {
! return reinterpret_cast<ShenandoahBarrierSetC2State*>(Compile::current()->barrier_set_state());
! }
!
! int ShenandoahBarrierSetC2::estimate_stub_size() const {
! GrowableArray<ShenandoahBarrierStubC2*>* const stubs = barrier_set_state()->stubs();
! assert(stubs->is_empty(), "Lifecycle: no stubs were yet created");
! return 0;
! }
!
! void ShenandoahBarrierSetC2::emit_stubs(CodeBuffer& cb) const {
! MacroAssembler masm(&cb);
+
+ PhaseOutput* const output = Compile::current()->output();
+ assert(masm.offset() <= output->buffer_sizing_data()->_code,
+ "Stubs are assumed to be emitted directly after code and code_size is a hard limit on where it can start");
+ barrier_set_state()->set_stubs_start_offset(masm.offset());
+
+ // Stub generation counts all stubs as skipped for the sake of inlining policy.
+ // This is critical for performance, check it.
+ #ifdef ASSERT
+ int offset_before = masm.offset();
+ int skipped_before = cb.total_skipped_instructions_size();
+ #endif
+
+ GrowableArray<ShenandoahBarrierStubC2*>* const stubs = barrier_set_state()->stubs();
+ for (int i = 0; i < stubs->length(); i++) {
+ // Make sure there is enough space in the code buffer
+ if (cb.insts()->maybe_expand_to_ensure_remaining(PhaseOutput::MAX_inst_size) && cb.blob() == nullptr) {
+ ciEnv::current()->record_failure("CodeCache is full");
+ return;
}
+ stubs->at(i)->emit_code(masm);
}
! #ifdef ASSERT
! int offset_after = masm.offset();
! int skipped_after = cb.total_skipped_instructions_size();
! assert(offset_after - offset_before == skipped_after - skipped_before,
! "All stubs are counted as skipped. masm: %d - %d = %d, cb: %d - %d = %d",
! offset_after, offset_before, offset_after - offset_before,
! skipped_after, skipped_before, skipped_after - skipped_before);
! #endif
! masm.flush();
! }
! void ShenandoahBarrierStubC2::register_stub(ShenandoahBarrierStubC2* stub) {
+ if (!Compile::current()->output()->in_scratch_emit_size()) {
+ barrier_set_state()->stubs()->append(stub);
}
+ }
! ShenandoahBarrierStubC2* ShenandoahBarrierStubC2::create(const MachNode* node, Register obj, Address addr, bool narrow, bool do_load) {
+ auto* stub = new (Compile::current()->comp_arena()) ShenandoahBarrierStubC2(node, obj, addr, narrow, do_load);
+ ShenandoahBarrierStubC2::register_stub(stub);
+ return stub;
}
! bool ShenandoahBarrierStubC2::is_live_register(Register reg) {
! return preserve_set().member(OptoReg::as_OptoReg(reg->as_VMReg()));
}
! Register ShenandoahBarrierStubC2::select_temp_register(bool& selected_live, Register skip_reg1) {
! Register tmp = noreg;
! Register fallback_live = noreg;
!
! // Try to select non-live first:
! for (int i = 0; i < available_gp_registers(); i++) {
! Register r = as_Register(i);
! if (r != _obj && r != _addr.base() && r != _addr.index() &&
! r != skip_reg1 && !is_special_register(r)) {
! if (!is_live_register(r)) {
! tmp = r;
! break;
! } else if (fallback_live == noreg) {
! fallback_live = r;
}
}
}
! // If we could not find a non-live register, select the live fallback:
! if (tmp == noreg) {
! tmp = fallback_live;
! selected_live = true;
! } else {
! selected_live = false;
}
!
+ assert(tmp != noreg, "successfully selected");
+ assert_different_registers(tmp, skip_reg1);
+ assert_different_registers(tmp, _obj);
+ assert_different_registers(tmp, _addr.base());
+ assert_different_registers(tmp, _addr.index());
+ return tmp;
}
! address ShenandoahBarrierStubC2::keepalive_runtime_entry_addr() {
! if (_narrow) {
! return CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_barrier_pre_narrow);
! } else {
! return CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_barrier_pre);
}
}
! address ShenandoahBarrierStubC2::lrb_runtime_entry_addr() {
! bool is_strong = (_node->barrier_data() & ShenandoahBitStrong) != 0;
! bool is_weak = (_node->barrier_data() & ShenandoahBitWeak) != 0;
! bool is_phantom = (_node->barrier_data() & ShenandoahBitPhantom) != 0;
! if (_narrow) {
! if (is_strong) {
! return CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_strong_narrow_narrow);
! } else if (is_weak) {
! return CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_weak_narrow_narrow);
! } else if (is_phantom) {
! return CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_phantom_narrow_narrow);
! }
! } else {
! if (is_strong) {
! return CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_strong);
! } else if (is_weak) {
! return CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_weak);
! } else if (is_phantom) {
+ return CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_phantom);
}
}
!
+ ShouldNotReachHere();
+ return nullptr;
}
! bool ShenandoahBarrierSetC2State::needs_liveness_data(const MachNode* mach) const {
! // Nodes that require slow-path stubs need liveness data.
! return ShenandoahBarrierStubC2::needs_slow_barrier(mach);
! }
!
! bool ShenandoahBarrierSetC2State::needs_livein_data() const {
! return true;
}
< prev index next >