1 class LoadSelfIntoField {
 2     // Test that PEA handles loading self into a field correctly.
 3     // This test is a smaller reproducer of Test6843752.
 4     static class Item {
 5         public Item    next;
 6         public Item    prev;
 7     }
 8     Item list = null;
 9 
10     private Item test(boolean cond) {
11         Item item = new Item();
12         Item head = list;
13         if (cond) {
14             item.next = item;
15             item.prev = item;
16             list = item;
17             // Confirm we correctly materialize setting object's field to self.
18             assert item == item.next;
19             assert item == item.prev;
20         } else {
21             item.next = head;
22             item.prev = head.prev;
23             head.prev.next = item;
24             head.prev = item;
25         }
26         return item;
27     }
28 
29     public static void main(String[] args)  {
30         LoadSelfIntoField obj = new LoadSelfIntoField();
31         long iterations = 0;
32         while (iterations <= 20000) {
33             obj.test(0 == (iterations & 0xf));
34             iterations++;
35         }
36     }
37 }