src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/WriteBarrierVerificationTest.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/WriteBarrierVerificationTest.java

Print this page




   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package org.graalvm.compiler.hotspot.test;
  24 
  25 import java.util.List;
  26 import java.util.Map;
  27 
  28 import org.junit.Assert;
  29 import org.junit.Test;
  30 
  31 import org.graalvm.compiler.core.common.LocationIdentity;
  32 import org.graalvm.compiler.debug.Debug;
  33 import org.graalvm.compiler.debug.Debug.Scope;
  34 import org.graalvm.compiler.debug.DebugConfig;
  35 import org.graalvm.compiler.debug.DebugConfigScope;
  36 import org.graalvm.compiler.debug.DebugDumpScope;
  37 import org.graalvm.compiler.debug.internal.DebugScope;
  38 import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig;
  39 import org.graalvm.compiler.hotspot.nodes.G1ArrayRangePostWriteBarrier;
  40 import org.graalvm.compiler.hotspot.nodes.G1ArrayRangePreWriteBarrier;
  41 import org.graalvm.compiler.hotspot.nodes.G1PostWriteBarrier;
  42 import org.graalvm.compiler.hotspot.nodes.G1PreWriteBarrier;
  43 import org.graalvm.compiler.hotspot.nodes.SerialArrayRangeWriteBarrier;
  44 import org.graalvm.compiler.hotspot.nodes.SerialWriteBarrier;
  45 import org.graalvm.compiler.hotspot.phases.WriteBarrierAdditionPhase;
  46 import org.graalvm.compiler.hotspot.phases.WriteBarrierVerificationPhase;
  47 import org.graalvm.compiler.hotspot.replacements.arraycopy.UnsafeArrayCopyNode;


  49 import org.graalvm.compiler.nodes.AbstractMergeNode;
  50 import org.graalvm.compiler.nodes.FieldLocationIdentity;
  51 import org.graalvm.compiler.nodes.FixedNode;
  52 import org.graalvm.compiler.nodes.FixedWithNextNode;
  53 import org.graalvm.compiler.nodes.LoopBeginNode;
  54 import org.graalvm.compiler.nodes.LoopExitNode;
  55 import org.graalvm.compiler.nodes.StructuredGraph;
  56 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
  57 import org.graalvm.compiler.nodes.memory.WriteNode;
  58 import org.graalvm.compiler.nodes.spi.LoweringTool;
  59 import org.graalvm.compiler.phases.OptimisticOptimizations;
  60 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
  61 import org.graalvm.compiler.phases.common.GuardLoweringPhase;
  62 import org.graalvm.compiler.phases.common.LoopSafepointInsertionPhase;
  63 import org.graalvm.compiler.phases.common.LoweringPhase;
  64 import org.graalvm.compiler.phases.common.inlining.InliningPhase;
  65 import org.graalvm.compiler.phases.graph.ReentrantNodeIterator;
  66 import org.graalvm.compiler.phases.graph.ReentrantNodeIterator.NodeIteratorClosure;
  67 import org.graalvm.compiler.phases.tiers.HighTierContext;
  68 import org.graalvm.compiler.phases.tiers.MidTierContext;

  69 
  70 import jdk.vm.ci.meta.ResolvedJavaField;
  71 
  72 /**
  73  * The following tests validate the write barrier verification phase. For every tested snippet, an
  74  * array of write barrier indices and the total write barrier number are passed as parameters. The
  75  * indices denote the barriers that will be manually removed. The write barrier verification phase
  76  * runs after the write barrier removal and depending on the result an assertion might be generated.
  77  * The tests anticipate the presence or not of an assertion generated by the verification phase.
  78  */
  79 public class WriteBarrierVerificationTest extends HotSpotGraalCompilerTest {
  80 
  81     public static int barrierIndex;
  82 
  83     private final GraalHotSpotVMConfig config = runtime().getVMConfig();
  84 
  85     public static class Container {
  86 
  87         public Container a;
  88         public Container b;


 289             main.b = temp1.a.a;
 290         } else {
 291             barrierIndex = 4;
 292             main.a = temp2;
 293             barrierIndex = 5;
 294             main.b = temp2.a.a;
 295         }
 296         safepoint();
 297     }
 298 
 299     @Test(expected = AssertionError.class)
 300     public void test21() {
 301         test("test6Snippet", 5, new int[]{1});
 302     }
 303 
 304     @Test(expected = AssertionError.class)
 305     public void test22() {
 306         test("test6Snippet", 5, new int[]{1, 2});
 307     }
 308 
 309     @Test(expected = AssertionError.class)
 310     public void test23() {
 311         test("test6Snippet", 5, new int[]{3});
 312     }
 313 
 314     @Test
 315     public void test24() {
 316         test("test6Snippet", 5, new int[]{4});
 317     }
 318 
 319     public static void test7Snippet(Container main, boolean test) {
 320         Container temp1 = new Container();
 321         Container temp2 = new Container();
 322         safepoint();
 323         barrierIndex = 1;
 324         main.a = temp1;
 325         if (test) {
 326             barrierIndex = 2;
 327             main.a = temp1;
 328         }
 329         barrierIndex = 3;


 695                     } else if (node instanceof SerialWriteBarrier || node instanceof G1PostWriteBarrier) {
 696                         // Remove flagged write barriers.
 697                         if (currentState) {
 698                             graph.removeFixed(((FixedWithNextNode) node));
 699                             return false;
 700                         }
 701                     }
 702                     return currentState;
 703                 }
 704 
 705                 private boolean eliminateBarrier(int index, int[] map) {
 706                     for (int i = 0; i < map.length; i++) {
 707                         if (map[i] == index) {
 708                             return true;
 709                         }
 710                     }
 711                     return false;
 712                 }
 713 
 714                 @Override
 715                 protected Map<LoopExitNode, Boolean> processLoop(LoopBeginNode loop, Boolean initialState) {
 716                     return ReentrantNodeIterator.processLoop(this, loop, initialState).exitStates;
 717                 }
 718 
 719                 @Override
 720                 protected Boolean merge(AbstractMergeNode merge, List<Boolean> states) {
 721                     return false;
 722                 }
 723 
 724                 @Override
 725                 protected Boolean afterSplit(AbstractBeginNode node, Boolean oldState) {
 726                     return false;
 727                 }
 728             };
 729 
 730             DebugConfig debugConfig = DebugScope.getConfig();
 731             DebugConfig fixedConfig = debugConfig == null ? null
 732                             : Debug.fixedConfig(0, 0, false, false, false, false, false, debugConfig.dumpHandlers(), debugConfig.verifyHandlers(), debugConfig.output());
 733             try (DebugConfigScope s = Debug.setConfig(fixedConfig)) {
 734                 ReentrantNodeIterator.apply(closure, graph.start(), false);
 735                 new WriteBarrierVerificationPhase(config).apply(graph);
 736             } catch (AssertionError error) {
 737                 /*
 738                  * Catch assertion, test for expected one and re-throw in order to validate unit
 739                  * test.
 740                  */
 741                 Assert.assertTrue(error.getMessage().contains("Write barrier must be present"));
 742                 throw error;
 743             }
 744         } catch (Throwable e) {
 745             throw Debug.handle(e);
 746         }
 747     }
 748 }


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


  26 import org.junit.Assert;
  27 import org.junit.Test;
  28 
  29 import org.graalvm.compiler.core.common.LocationIdentity;
  30 import org.graalvm.compiler.debug.Debug;
  31 import org.graalvm.compiler.debug.Debug.Scope;
  32 import org.graalvm.compiler.debug.DebugConfig;
  33 import org.graalvm.compiler.debug.DebugConfigScope;
  34 import org.graalvm.compiler.debug.DebugDumpScope;
  35 import org.graalvm.compiler.debug.internal.DebugScope;
  36 import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig;
  37 import org.graalvm.compiler.hotspot.nodes.G1ArrayRangePostWriteBarrier;
  38 import org.graalvm.compiler.hotspot.nodes.G1ArrayRangePreWriteBarrier;
  39 import org.graalvm.compiler.hotspot.nodes.G1PostWriteBarrier;
  40 import org.graalvm.compiler.hotspot.nodes.G1PreWriteBarrier;
  41 import org.graalvm.compiler.hotspot.nodes.SerialArrayRangeWriteBarrier;
  42 import org.graalvm.compiler.hotspot.nodes.SerialWriteBarrier;
  43 import org.graalvm.compiler.hotspot.phases.WriteBarrierAdditionPhase;
  44 import org.graalvm.compiler.hotspot.phases.WriteBarrierVerificationPhase;
  45 import org.graalvm.compiler.hotspot.replacements.arraycopy.UnsafeArrayCopyNode;


  47 import org.graalvm.compiler.nodes.AbstractMergeNode;
  48 import org.graalvm.compiler.nodes.FieldLocationIdentity;
  49 import org.graalvm.compiler.nodes.FixedNode;
  50 import org.graalvm.compiler.nodes.FixedWithNextNode;
  51 import org.graalvm.compiler.nodes.LoopBeginNode;
  52 import org.graalvm.compiler.nodes.LoopExitNode;
  53 import org.graalvm.compiler.nodes.StructuredGraph;
  54 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
  55 import org.graalvm.compiler.nodes.memory.WriteNode;
  56 import org.graalvm.compiler.nodes.spi.LoweringTool;
  57 import org.graalvm.compiler.phases.OptimisticOptimizations;
  58 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
  59 import org.graalvm.compiler.phases.common.GuardLoweringPhase;
  60 import org.graalvm.compiler.phases.common.LoopSafepointInsertionPhase;
  61 import org.graalvm.compiler.phases.common.LoweringPhase;
  62 import org.graalvm.compiler.phases.common.inlining.InliningPhase;
  63 import org.graalvm.compiler.phases.graph.ReentrantNodeIterator;
  64 import org.graalvm.compiler.phases.graph.ReentrantNodeIterator.NodeIteratorClosure;
  65 import org.graalvm.compiler.phases.tiers.HighTierContext;
  66 import org.graalvm.compiler.phases.tiers.MidTierContext;
  67 import org.graalvm.util.EconomicMap;
  68 
  69 import jdk.vm.ci.meta.ResolvedJavaField;
  70 
  71 /**
  72  * The following tests validate the write barrier verification phase. For every tested snippet, an
  73  * array of write barrier indices and the total write barrier number are passed as parameters. The
  74  * indices denote the barriers that will be manually removed. The write barrier verification phase
  75  * runs after the write barrier removal and depending on the result an assertion might be generated.
  76  * The tests anticipate the presence or not of an assertion generated by the verification phase.
  77  */
  78 public class WriteBarrierVerificationTest extends HotSpotGraalCompilerTest {
  79 
  80     public static int barrierIndex;
  81 
  82     private final GraalHotSpotVMConfig config = runtime().getVMConfig();
  83 
  84     public static class Container {
  85 
  86         public Container a;
  87         public Container b;


 288             main.b = temp1.a.a;
 289         } else {
 290             barrierIndex = 4;
 291             main.a = temp2;
 292             barrierIndex = 5;
 293             main.b = temp2.a.a;
 294         }
 295         safepoint();
 296     }
 297 
 298     @Test(expected = AssertionError.class)
 299     public void test21() {
 300         test("test6Snippet", 5, new int[]{1});
 301     }
 302 
 303     @Test(expected = AssertionError.class)
 304     public void test22() {
 305         test("test6Snippet", 5, new int[]{1, 2});
 306     }
 307 
 308     @Test
 309     public void test23() {
 310         test("test6Snippet", 5, new int[]{3});
 311     }
 312 
 313     @Test
 314     public void test24() {
 315         test("test6Snippet", 5, new int[]{4});
 316     }
 317 
 318     public static void test7Snippet(Container main, boolean test) {
 319         Container temp1 = new Container();
 320         Container temp2 = new Container();
 321         safepoint();
 322         barrierIndex = 1;
 323         main.a = temp1;
 324         if (test) {
 325             barrierIndex = 2;
 326             main.a = temp1;
 327         }
 328         barrierIndex = 3;


 694                     } else if (node instanceof SerialWriteBarrier || node instanceof G1PostWriteBarrier) {
 695                         // Remove flagged write barriers.
 696                         if (currentState) {
 697                             graph.removeFixed(((FixedWithNextNode) node));
 698                             return false;
 699                         }
 700                     }
 701                     return currentState;
 702                 }
 703 
 704                 private boolean eliminateBarrier(int index, int[] map) {
 705                     for (int i = 0; i < map.length; i++) {
 706                         if (map[i] == index) {
 707                             return true;
 708                         }
 709                     }
 710                     return false;
 711                 }
 712 
 713                 @Override
 714                 protected EconomicMap<LoopExitNode, Boolean> processLoop(LoopBeginNode loop, Boolean initialState) {
 715                     return ReentrantNodeIterator.processLoop(this, loop, initialState).exitStates;
 716                 }
 717 
 718                 @Override
 719                 protected Boolean merge(AbstractMergeNode merge, List<Boolean> states) {
 720                     return false;
 721                 }
 722 
 723                 @Override
 724                 protected Boolean afterSplit(AbstractBeginNode node, Boolean oldState) {
 725                     return false;
 726                 }
 727             };
 728 
 729             DebugConfig debugConfig = DebugScope.getConfig();
 730             DebugConfig fixedConfig = debugConfig == null ? null
 731                             : Debug.fixedConfig(debugConfig.getOptions(), 0, 0, false, false, false, false, false, debugConfig.dumpHandlers(), debugConfig.verifyHandlers(), debugConfig.output());
 732             try (DebugConfigScope s = Debug.setConfig(fixedConfig)) {
 733                 ReentrantNodeIterator.apply(closure, graph.start(), false);
 734                 new WriteBarrierVerificationPhase(config).apply(graph);
 735             } catch (AssertionError error) {
 736                 /*
 737                  * Catch assertion, test for expected one and re-throw in order to validate unit
 738                  * test.
 739                  */
 740                 Assert.assertTrue(error.getMessage().contains("Write barrier must be present"));
 741                 throw error;
 742             }
 743         } catch (Throwable e) {
 744             throw Debug.handle(e);
 745         }
 746     }
 747 }
src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/WriteBarrierVerificationTest.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File