< prev index next >

test/compiler/types/TestPhiElimination.java

Print this page
rev 11557 : 8132919: use package in compiler tests
Reviewed-by: duke


   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  */
  24 
  25 /**
  26  * @test
  27  * @bug 8150804
  28  * @summary Tests elimination of Phi nodes without losing type information.
  29  * @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement TestPhiElimination


  30  */



  31 public class TestPhiElimination {
  32     /*
  33        A::get() is inlined into test(obj) producing the following graph:
  34 
  35                Parm (obj)
  36             TestPhiElimination
  37                    |
  38                  CastPP
  39         TestPhiElimination:NotNull
  40                    |
  41               CheckCastPP
  42                A:NotNull
  43                /       \
  44        CheckCastPP     |
  45         A:NotNull      |
  46                 \     /
  47                   Phi
  48                    A
  49                    |
  50                Safepoint


  73 
  74     static public void main(String[] args) {
  75         TestPhiElimination t = new TestPhiElimination();
  76 
  77         // Warmup
  78         B b = new B();
  79         for (int i = 0; i < 1_000; ++i) {
  80             t.test(b);
  81         }
  82 
  83         // Compile
  84         A a = new A();
  85         for (int i = 0; i < 20_000; ++i) {
  86             if (i % 2 == 0) {
  87                 a.f = null;
  88             }
  89             t.test(a);
  90         }
  91     }
  92 
  93 }
  94 
  95 class A extends TestPhiElimination {
  96     public Object f;
  97 
  98     public A create() {
  99         return new A();
 100     }
 101 
 102     public synchronized Object get() {
 103         if (f == null) {
 104             f = create();
 105         }
 106         return f;
 107     }
 108 }
 109 
 110 class B extends A {
 111 
 112 }


   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  */
  24 
  25 /**
  26  * @test
  27  * @bug 8150804
  28  * @summary Tests elimination of Phi nodes without losing type information.
  29  *
  30  * @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement
  31  *                   compiler.types.TestPhiElimination
  32  */
  33 
  34 package compiler.types;
  35 
  36 public class TestPhiElimination {
  37     /*
  38        A::get() is inlined into test(obj) producing the following graph:
  39 
  40                Parm (obj)
  41             TestPhiElimination
  42                    |
  43                  CastPP
  44         TestPhiElimination:NotNull
  45                    |
  46               CheckCastPP
  47                A:NotNull
  48                /       \
  49        CheckCastPP     |
  50         A:NotNull      |
  51                 \     /
  52                   Phi
  53                    A
  54                    |
  55                Safepoint


  78 
  79     static public void main(String[] args) {
  80         TestPhiElimination t = new TestPhiElimination();
  81 
  82         // Warmup
  83         B b = new B();
  84         for (int i = 0; i < 1_000; ++i) {
  85             t.test(b);
  86         }
  87 
  88         // Compile
  89         A a = new A();
  90         for (int i = 0; i < 20_000; ++i) {
  91             if (i % 2 == 0) {
  92                 a.f = null;
  93             }
  94             t.test(a);
  95         }
  96     }
  97 
  98     static class A extends TestPhiElimination {


  99         public Object f;
 100 
 101         public A create() {
 102             return new A();
 103         }
 104 
 105         public synchronized Object get() {
 106             if (f == null) {
 107                 f = create();
 108             }
 109             return f;
 110         }
 111     }
 112 
 113     static class B extends A { }

 114 }
< prev index next >