# HG changeset patch # User Tom Rodriguez # Date 1401913206 25200 # Node ID 6a62ccbd1658954895d8b4187ce287c121fd1a87 # Parent 8d8c6a40d8e23bfa3856e4be5d0ec2d4e7ba7527 add support for new G1 marking behavior diff -r 8d8c6a40d8e2 -r 6a62ccbd1658 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotVMConfig.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotVMConfig.java Wed Jun 04 19:17:22 2014 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotVMConfig.java Wed Jun 04 13:20:06 2014 -0700 @@ -1180,6 +1180,9 @@ @HotSpotVMField(name = "CardTableModRefBS::byte_map_base", type = "jbyte*", get = HotSpotVMField.Type.OFFSET) @Stable private int cardTableModRefBSByteMapBaseOffset; @HotSpotVMConstant(name = "CardTableModRefBS::card_shift") @Stable public int cardTableModRefBSCardShift; + @HotSpotVMValue(expression = "(jbyte)CardTableModRefBS::dirty_card_val()") @Stable public byte dirtyCardValue; + @HotSpotVMValue(expression = "(jbyte)G1SATBCardTableModRefBS::g1_young_card_val()") @Stable public byte g1YoungCardValue; + public long cardtableStartAddress() { final long barrierSetAddress = unsafe.getAddress(universeCollectedHeap + collectedHeapBarrierSetOffset); final int kind = unsafe.getInt(barrierSetAddress + barrierSetKindOffset); diff -r 8d8c6a40d8e2 -r 6a62ccbd1658 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/HotSpotReplacementsUtil.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/HotSpotReplacementsUtil.java Wed Jun 04 19:17:22 2014 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/HotSpotReplacementsUtil.java Wed Jun 04 13:20:06 2014 -0700 @@ -207,7 +207,7 @@ /** * Reads the pending deoptimization value for the given thread. - * + * * @return {@code true} if there was a pending deoptimization */ public static int readPendingDeoptimization(Word thread) { @@ -416,6 +416,16 @@ } @Fold + public static byte dirtyCardValue() { + return config().dirtyCardValue; + } + + @Fold + public static byte g1YoungCardValue() { + return config().g1YoungCardValue; + } + + @Fold public static int cardTableShift() { return config().cardtableShift(); } diff -r 8d8c6a40d8e2 -r 6a62ccbd1658 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/WriteBarrierSnippets.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/WriteBarrierSnippets.java Wed Jun 04 19:17:22 2014 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/WriteBarrierSnippets.java Wed Jun 04 13:20:06 2014 -0700 @@ -22,6 +22,7 @@ */ package com.oracle.graal.hotspot.replacements; +import static com.oracle.graal.api.code.MemoryBarriers.*; import static com.oracle.graal.compiler.common.GraalOptions.*; import static com.oracle.graal.hotspot.replacements.HotSpotReplacementsUtil.*; import static com.oracle.graal.nodes.extended.BranchProbabilityNode.*; @@ -213,22 +214,26 @@ g1EffectiveAfterNullPostWriteBarrierCounter.inc(); // If the card is already dirty, (hence already enqueued) skip the insertion. - if (probability(NOT_FREQUENT_PROBABILITY, cardByte != (byte) 0)) { - log(trace, "[%d] G1-Post Thread: %p Card: %p \n", gcCycle, thread.rawValue(), Word.unsigned(cardByte).rawValue()); - cardAddress.writeByte(0, (byte) 0, GC_CARD_LOCATION); - g1ExecutedPostWriteBarrierCounter.inc(); + if (probability(NOT_FREQUENT_PROBABILITY, cardByte != g1YoungCardValue())) { + MembarNode.memoryBarrier(STORE_LOAD); + byte cardByteReload = cardAddress.readByte(0); + if (probability(NOT_FREQUENT_PROBABILITY, cardByteReload != dirtyCardValue())) { + log(trace, "[%d] G1-Post Thread: %p Card: %p \n", gcCycle, thread.rawValue(), Word.unsigned(cardByte).rawValue()); + cardAddress.writeByte(0, (byte) 0, GC_CARD_LOCATION); + g1ExecutedPostWriteBarrierCounter.inc(); - // If the thread local card queue is full, issue a native call which will - // initialize a new one and add the card entry. - if (probability(FREQUENT_PROBABILITY, indexValue.notEqual(0))) { - Word nextIndex = indexValue.subtract(wordSize()); - Word logAddress = bufferAddress.add(nextIndex); - // Log the object to be scanned as well as update - // the card queue's next index. - logAddress.writeWord(0, cardAddress, GC_LOG_LOCATION); - indexAddress.writeWord(0, nextIndex, GC_INDEX_LOCATION); - } else { - g1PostBarrierStub(G1WBPOSTCALL, cardAddress); + // If the thread local card queue is full, issue a native call which will + // initialize a new one and add the card entry. + if (probability(FREQUENT_PROBABILITY, indexValue.notEqual(0))) { + Word nextIndex = indexValue.subtract(wordSize()); + Word logAddress = bufferAddress.add(nextIndex); + // Log the object to be scanned as well as update + // the card queue's next index. + logAddress.writeWord(0, cardAddress, GC_LOG_LOCATION); + indexAddress.writeWord(0, nextIndex, GC_INDEX_LOCATION); + } else { + g1PostBarrierStub(G1WBPOSTCALL, cardAddress); + } } } } @@ -293,19 +298,23 @@ Word cardAddress = Word.unsigned((start + cardStart) + count); byte cardByte = cardAddress.readByte(0); // If the card is already dirty, (hence already enqueued) skip the insertion. - if (cardByte != (byte) 0) { - cardAddress.writeByte(0, (byte) 0, GC_CARD_LOCATION); - // If the thread local card queue is full, issue a native call which will - // initialize a new one and add the card entry. - if (indexValue != 0) { - indexValue = indexValue - wordSize(); - Word logAddress = bufferAddress.add(Word.unsigned(indexValue)); - // Log the object to be scanned as well as update - // the card queue's next index. - logAddress.writeWord(0, cardAddress, GC_LOG_LOCATION); - indexAddress.writeWord(0, Word.unsigned(indexValue), GC_INDEX_LOCATION); - } else { - g1PostBarrierStub(G1WBPOSTCALL, cardAddress); + if (probability(NOT_FREQUENT_PROBABILITY, cardByte != g1YoungCardValue())) { + MembarNode.memoryBarrier(STORE_LOAD); + byte cardByteReload = cardAddress.readByte(0); + if (probability(NOT_FREQUENT_PROBABILITY, cardByteReload != dirtyCardValue())) { + cardAddress.writeByte(0, (byte) 0, GC_CARD_LOCATION); + // If the thread local card queue is full, issue a native call which will + // initialize a new one and add the card entry. + if (indexValue != 0) { + indexValue = indexValue - wordSize(); + Word logAddress = bufferAddress.add(Word.unsigned(indexValue)); + // Log the object to be scanned as well as update + // the card queue's next index. + logAddress.writeWord(0, cardAddress, GC_LOG_LOCATION); + indexAddress.writeWord(0, Word.unsigned(indexValue), GC_INDEX_LOCATION); + } else { + g1PostBarrierStub(G1WBPOSTCALL, cardAddress); + } } } } diff -r 8d8c6a40d8e2 -r 6a62ccbd1658 graal/com.oracle.graal.hotspotvmconfig/src/com/oracle/graal/hotspotvmconfig/HotSpotVMConfigProcessor.java --- a/graal/com.oracle.graal.hotspotvmconfig/src/com/oracle/graal/hotspotvmconfig/HotSpotVMConfigProcessor.java Wed Jun 04 19:17:22 2014 +0200 +++ b/graal/com.oracle.graal.hotspotvmconfig/src/com/oracle/graal/hotspotvmconfig/HotSpotVMConfigProcessor.java Wed Jun 04 13:20:06 2014 -0700 @@ -127,6 +127,8 @@ "}", "", "#define set_boolean(name, value) vmconfig_oop->bool_field_put(fs.offset(), value)", + "#define set_byte(name, value) vmconfig_oop->byte_field_put(fs.offset(), (jbyte)value)", + "#define set_short(name, value) vmconfig_oop->short_field_put(fs.offset(), (jshort)value)", "#define set_int(name, value) vmconfig_oop->int_field_put(fs.offset(), (int)value)", "#define set_long(name, value) vmconfig_oop->long_field_put(fs.offset(), value)", "#define set_address(name, value) do { set_long(name, (jlong) value); } while (0)",