Query regarding ordering in G1 post-write barrier

Andrew Dinn adinn at redhat.com
Mon Jul 20 13:22:28 UTC 2015


$SUBJECT is in relation to the following code in method
GraphKit::g1_mark_card()

  . . .
  __ storeCM(__ ctrl(), card_adr, zero, oop_store, oop_alias_idx,
card_bt, Compile::AliasIdxRaw);

  //  Now do the queue work
  __ if_then(index, BoolTest::ne, zeroX); {

    Node* next_index = _gvn.transform(new SubXNode(index, __
ConX(sizeof(intptr_t))));
    Node* log_addr = __ AddP(no_base, buffer, next_index);

    // Order, see storeCM.
    __ store(__ ctrl(), log_addr, card_adr, T_ADDRESS,
Compile::AliasIdxRaw, MemNode::unordered);
    __ store(__ ctrl(), index_adr, next_index, TypeX_X->basic_type(),
Compile::AliasIdxRaw, MemNode::unordered);

  } __ else_(); {
    __ make_leaf_call(tf, CAST_FROM_FN_PTR(address,
SharedRuntime::g1_wb_post), "g1_wb_post", card_adr, __ thread());
  } __ end_if();
  . . .

The 3 stores StoreCM -> StoreP -> StoreX which mark the card and then
push the card address into the dirty queue appear to end up being
emitted in that order -- I assume by virtue of the memory links between
them (output of StoreCM is the mem input of StoreP, output of StoreP is
the mem input of StoreX). That order makes sense if the queue were to be
observed concurrently i.e. mark card to ensure write is flagged before
it is performed, write value, then decrement index to make value write
visible. So, that's ok on x86 where TCO means this is also the order of
visibility.

The StoreCM is 'ordered' i.e. it is flagged with mem ordering type =
mo_release. However, the latter pair of instructions are 'unordered'. I
looked at the G1 code which processes dirty queues and could not make
head nor tail (oops, apologies for any undercurrent of a pun) of when it
gets run.

So, the question is this: does dirty queue processing only happen in GC
threads when mutators cannot be writing them? or is there a need on
non-TCO architectures to maintain some sort of consistency in the queue
update via by serializing these writes?

Hmm, ok that seems to be two questions. Let's make that a starter for 10
and a bonus for whoever buzzes fastest.

regards,


Andrew Dinn
-----------
Senior Principal Software Engineer
Red Hat UK Ltd
Registered in UK and Wales under Company Registration No. 3798903
Directors: Michael Cunningham (USA), Matt Parson (USA), Charlie Peters
(USA), Michael O'Neill (Ireland)



More information about the hotspot-gc-dev mailing list