< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/gc/shared/CardTableBarrierSet.java

Print this page




   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  */
  24 
  25 
  26 package org.graalvm.compiler.hotspot.gc.shared;
  27 
  28 import org.graalvm.compiler.debug.GraalError;

  29 import org.graalvm.compiler.nodes.StructuredGraph;
  30 import org.graalvm.compiler.nodes.ValueNode;
  31 import org.graalvm.compiler.nodes.extended.ArrayRangeWrite;
  32 import org.graalvm.compiler.nodes.java.AbstractCompareAndSwapNode;
  33 import org.graalvm.compiler.nodes.java.LoweredAtomicReadAndWriteNode;
  34 import org.graalvm.compiler.nodes.memory.FixedAccessNode;
  35 import org.graalvm.compiler.nodes.memory.HeapAccess;
  36 import org.graalvm.compiler.nodes.memory.ReadNode;
  37 import org.graalvm.compiler.nodes.memory.WriteNode;
  38 import org.graalvm.compiler.nodes.memory.address.AddressNode;
  39 import org.graalvm.compiler.nodes.type.StampTool;
  40 
  41 public class CardTableBarrierSet extends BarrierSet {
  42 




  43     @Override
  44     public void addReadNodeBarriers(ReadNode node, StructuredGraph graph) {
  45         assert node.getBarrierType() == HeapAccess.BarrierType.NONE : "Non precise read barrier has been attached to read node.";
  46     }
  47 
  48     @Override
  49     public void addWriteNodeBarriers(WriteNode node, StructuredGraph graph) {
  50         HeapAccess.BarrierType barrierType = node.getBarrierType();
  51         switch (barrierType) {
  52             case NONE:
  53                 // nothing to do
  54                 break;
  55             case IMPRECISE:
  56             case PRECISE:
  57                 boolean precise = barrierType == HeapAccess.BarrierType.PRECISE;
  58                 addSerialPostWriteBarrier(node, node.getAddress(), node.value(), precise, graph);




  59                 break;
  60             default:
  61                 throw new GraalError("unexpected barrier type: " + barrierType);
  62         }
  63     }
  64 
  65     @Override
  66     public void addAtomicReadWriteNodeBarriers(LoweredAtomicReadAndWriteNode node, StructuredGraph graph) {
  67         HeapAccess.BarrierType barrierType = node.getBarrierType();
  68         switch (barrierType) {
  69             case NONE:
  70                 // nothing to do
  71                 break;
  72             case IMPRECISE:
  73             case PRECISE:
  74                 boolean precise = barrierType == HeapAccess.BarrierType.PRECISE;

  75                 addSerialPostWriteBarrier(node, node.getAddress(), node.getNewValue(), precise, graph);
  76                 break;
  77             default:
  78                 throw new GraalError("unexpected barrier type: " + barrierType);
  79         }
  80     }
  81 
  82     @Override
  83     public void addCASBarriers(AbstractCompareAndSwapNode node, StructuredGraph graph) {
  84         HeapAccess.BarrierType barrierType = node.getBarrierType();
  85         switch (barrierType) {
  86             case NONE:
  87                 // nothing to do
  88                 break;
  89             case IMPRECISE:
  90             case PRECISE:
  91                 boolean precise = barrierType == HeapAccess.BarrierType.PRECISE;

  92                 addSerialPostWriteBarrier(node, node.getAddress(), node.getNewValue(), precise, graph);
  93                 break;
  94             default:
  95                 throw new GraalError("unexpected barrier type: " + barrierType);
  96         }
  97     }
  98 
  99     @Override
 100     public void addArrayRangeBarriers(ArrayRangeWrite write, StructuredGraph graph) {
 101         SerialArrayRangeWriteBarrier serialArrayRangeWriteBarrier = graph.add(new SerialArrayRangeWriteBarrier(write.getAddress(), write.getLength(), write.getElementStride()));
 102         graph.addAfterFixed(write.asNode(), serialArrayRangeWriteBarrier);
 103     }
 104 
 105     protected void addSerialPostWriteBarrier(FixedAccessNode node, AddressNode address, ValueNode value, boolean precise, StructuredGraph graph) {
 106         final boolean alwaysNull = StampTool.isPointerAlwaysNull(value);
 107         if (alwaysNull) {
 108             // Serial barrier isn't needed for null value
 109             return;
 110         }
 111         graph.addAfterFixed(node, graph.add(new SerialWriteBarrier(address, precise)));


   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  */
  24 
  25 
  26 package org.graalvm.compiler.hotspot.gc.shared;
  27 
  28 import org.graalvm.compiler.debug.GraalError;
  29 import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig;
  30 import org.graalvm.compiler.nodes.StructuredGraph;
  31 import org.graalvm.compiler.nodes.ValueNode;
  32 import org.graalvm.compiler.nodes.extended.ArrayRangeWrite;
  33 import org.graalvm.compiler.nodes.java.AbstractCompareAndSwapNode;
  34 import org.graalvm.compiler.nodes.java.LoweredAtomicReadAndWriteNode;
  35 import org.graalvm.compiler.nodes.memory.FixedAccessNode;
  36 import org.graalvm.compiler.nodes.memory.HeapAccess;
  37 import org.graalvm.compiler.nodes.memory.ReadNode;
  38 import org.graalvm.compiler.nodes.memory.WriteNode;
  39 import org.graalvm.compiler.nodes.memory.address.AddressNode;
  40 import org.graalvm.compiler.nodes.type.StampTool;
  41 
  42 public class CardTableBarrierSet extends BarrierSet {
  43 
  44     public CardTableBarrierSet(GraalHotSpotVMConfig vmConfig) {
  45         super(vmConfig);
  46     }
  47 
  48     @Override
  49     public void addReadNodeBarriers(ReadNode node, StructuredGraph graph) {
  50         // Nothing to do here.
  51     }
  52 
  53     @Override
  54     public void addWriteNodeBarriers(WriteNode node, StructuredGraph graph) {
  55         HeapAccess.BarrierType barrierType = node.getBarrierType();
  56         switch (barrierType) {
  57             case NONE:
  58                 // nothing to do
  59                 break;
  60             case FIELD:
  61             case ARRAY:
  62             case UNKNOWN:
  63                 boolean precise = barrierType != HeapAccess.BarrierType.FIELD;
  64                 boolean init = node.getLocationIdentity().isInit();
  65                 if (!init || !getVMConfig().useDeferredInitBarriers) {
  66                     addSerialPostWriteBarrier(node, node.getAddress(), node.value(), precise, graph);
  67                 }
  68                 break;
  69             default:
  70                 throw new GraalError("unexpected barrier type: " + barrierType);
  71         }
  72     }
  73 
  74     @Override
  75     public void addAtomicReadWriteNodeBarriers(LoweredAtomicReadAndWriteNode node, StructuredGraph graph) {
  76         HeapAccess.BarrierType barrierType = node.getBarrierType();
  77         switch (barrierType) {
  78             case NONE:
  79                 // nothing to do
  80                 break;
  81             case FIELD:
  82             case ARRAY:
  83             case UNKNOWN:
  84                 boolean precise = barrierType != HeapAccess.BarrierType.FIELD;
  85                 addSerialPostWriteBarrier(node, node.getAddress(), node.getNewValue(), precise, graph);
  86                 break;
  87             default:
  88                 throw new GraalError("unexpected barrier type: " + barrierType);
  89         }
  90     }
  91 
  92     @Override
  93     public void addCASBarriers(AbstractCompareAndSwapNode node, StructuredGraph graph) {
  94         HeapAccess.BarrierType barrierType = node.getBarrierType();
  95         switch (barrierType) {
  96             case NONE:
  97                 // nothing to do
  98                 break;
  99             case FIELD:
 100             case ARRAY:
 101             case UNKNOWN:
 102                 boolean precise = barrierType != HeapAccess.BarrierType.FIELD;
 103                 addSerialPostWriteBarrier(node, node.getAddress(), node.getNewValue(), precise, graph);
 104                 break;
 105             default:
 106                 throw new GraalError("unexpected barrier type: " + barrierType);
 107         }
 108     }
 109 
 110     @Override
 111     public void addArrayRangeBarriers(ArrayRangeWrite write, StructuredGraph graph) {
 112         SerialArrayRangeWriteBarrier serialArrayRangeWriteBarrier = graph.add(new SerialArrayRangeWriteBarrier(write.getAddress(), write.getLength(), write.getElementStride()));
 113         graph.addAfterFixed(write.asNode(), serialArrayRangeWriteBarrier);
 114     }
 115 
 116     protected void addSerialPostWriteBarrier(FixedAccessNode node, AddressNode address, ValueNode value, boolean precise, StructuredGraph graph) {
 117         final boolean alwaysNull = StampTool.isPointerAlwaysNull(value);
 118         if (alwaysNull) {
 119             // Serial barrier isn't needed for null value
 120             return;
 121         }
 122         graph.addAfterFixed(node, graph.add(new SerialWriteBarrier(address, precise)));
< prev index next >