test/hotspot/jtreg/compiler/escapeAnalysis/Test6689060.java
changeset 47216 71c04702a3d5
parent 40059 c2304140ed64
child 49483 d374b1634589
equal deleted inserted replaced
47215:4ebc2e2fb97c 47216:71c04702a3d5
       
     1 /*
       
     2  * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     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 
       
    24 /*
       
    25  * @test
       
    26  * @bug 6689060
       
    27  * @summary Escape Analysis does not work with Compressed Oops
       
    28  *
       
    29  * @run main/othervm -Xbatch -XX:+AggressiveOpts
       
    30  *      -XX:CompileCommand=exclude,compiler.escapeAnalysis.Test6689060::dummy
       
    31  *      compiler.escapeAnalysis.Test6689060
       
    32  */
       
    33 
       
    34 package compiler.escapeAnalysis;
       
    35 
       
    36 import java.lang.reflect.Array;
       
    37 
       
    38 public class Test6689060 {
       
    39     static class Point {
       
    40         int x;
       
    41         int y;
       
    42         Point next;
       
    43         int ax[];
       
    44         int ay[];
       
    45         Point pax[];
       
    46         Point pay[];
       
    47 
       
    48         public Point getNext() {
       
    49             return next;
       
    50         }
       
    51     }
       
    52 
       
    53     void dummy() {
       
    54         // Empty method to verify correctness of DebugInfo.
       
    55         // Use -XX:CompileCommand=exclude,Test.dummy
       
    56     }
       
    57 
       
    58     int ival(int i) {
       
    59         return i * 2;
       
    60     }
       
    61 
       
    62     int test80(int y, int l, int i) {
       
    63         Point p = new Point();
       
    64         p.ax = new int[2];
       
    65         p.ay = new int[2];
       
    66         int x = 3;
       
    67         p.ax[0] = x;
       
    68         p.ay[1] = 3 * x + y;
       
    69         dummy();
       
    70         return p.ax[0] * p.ay[1];
       
    71     }
       
    72 
       
    73     int test81(int y, int l, int i) {
       
    74         Point p = new Point();
       
    75         p.ax = new int[2];
       
    76         p.ay = new int[2];
       
    77         int x = 3;
       
    78         p.ax[0] = x;
       
    79         p.ay[1] = 3 * x + y;
       
    80         dummy();
       
    81         return p.ax[0] * p.ay[1];
       
    82     }
       
    83 
       
    84 
       
    85     int test44(int y) {
       
    86         Point p1 = new Point();
       
    87         p1.x = ival(3);
       
    88         dummy();
       
    89         p1.y = 3 * p1.x + y;
       
    90         return p1.y;
       
    91     }
       
    92 
       
    93     int test43(int y) {
       
    94         Point p1 = new Point();
       
    95         if ((y & 1) == 1) {
       
    96             p1.x = ival(3);
       
    97         } else {
       
    98             p1.x = ival(5);
       
    99         }
       
   100         dummy();
       
   101         p1.y = 3 * p1.x + y;
       
   102         return p1.y;
       
   103     }
       
   104 
       
   105     int test42(int y) {
       
   106         Point p1 = new Point();
       
   107         p1.x = 3;
       
   108         for (int i = 0; i < y; i++) {
       
   109             if ((i & 1) == 1) {
       
   110                 p1.x += 4;
       
   111             }
       
   112         }
       
   113         p1.y = 3 * y + p1.x;
       
   114         return p1.y;
       
   115     }
       
   116 
       
   117     int test40(int y) {
       
   118         Point p1 = new Point();
       
   119         if ((y & 1) == 1) {
       
   120             p1.x = 3;
       
   121         } else {
       
   122             p1.x = 5;
       
   123         }
       
   124         p1.y = 3 * p1.x + y;
       
   125         return p1.y;
       
   126     }
       
   127 
       
   128     int test41(int y) {
       
   129         Point p1 = new Point();
       
   130         if ((y & 1) == 1) {
       
   131             p1.x += 4;
       
   132         } else {
       
   133             p1.x += 5;
       
   134         }
       
   135         p1.y = 3 * p1.x + y;
       
   136         return p1.y;
       
   137     }
       
   138 
       
   139     Point test00(int y) {
       
   140         int x = 3;
       
   141         Point p = new Point();
       
   142         p.x = x;
       
   143         p.y = 3 * x + y;
       
   144         return p;
       
   145     }
       
   146 
       
   147     Point test01(int y) {
       
   148         int x = 3;
       
   149         Point p = new Point();
       
   150         p.x = x;
       
   151         p.y = 3 * x + y;
       
   152         dummy();
       
   153         return p;
       
   154     }
       
   155 
       
   156     Point test02(int y) {
       
   157         int x = 3;
       
   158         Point p1 = null;
       
   159         for (int i = 0; i < y; i++) {
       
   160             Point p2 = new Point();
       
   161             p2.x = x;
       
   162             p2.y = 3 * y + x;
       
   163             p2.next = p1;
       
   164             p1 = p2;
       
   165         }
       
   166         return p1;
       
   167     }
       
   168 
       
   169     Point test03(int y) {
       
   170         int x = 3;
       
   171         Point p1 = null;
       
   172         for (int i = 0; i < y; i++) {
       
   173             Point p2 = new Point();
       
   174             p2.x = x;
       
   175             p2.y = 3 * y + x;
       
   176             p2.next = p1;
       
   177             p1 = p2;
       
   178         }
       
   179         dummy();
       
   180         return p1;
       
   181     }
       
   182 
       
   183     Point test04(int y) {
       
   184         int x = 3;
       
   185         Point p1 = null;
       
   186         for (int i = 0; i < y; i++) {
       
   187             Point p2 = new Point();
       
   188             p2.x = x;
       
   189             p2.y = 3 * y + x;
       
   190             p2.next = p1;
       
   191             dummy();
       
   192             p1 = p2;
       
   193         }
       
   194         return p1;
       
   195     }
       
   196 
       
   197     int test05(int y) {
       
   198         int x = 3;
       
   199         Point p1 = new Point();
       
   200         for (int i = 0; i < y; i++) {
       
   201             Point p2 = new Point();
       
   202             p2.x = x;
       
   203             p2.y = 3 * y + x;
       
   204             p1.next = p2;
       
   205             p1 = p2;
       
   206         }
       
   207         return p1.y;
       
   208     }
       
   209 
       
   210     int test0(int y) {
       
   211         int x = 3;
       
   212         Point p = new Point();
       
   213         p.x = x;
       
   214         p.y = 3 * x + y;
       
   215         dummy();
       
   216         return p.x * p.y;
       
   217     }
       
   218 
       
   219     int test1(int y) {
       
   220         Point p = new Point();
       
   221         if ((y & 1) == 1) {
       
   222             p = new Point(); // Kill previous
       
   223         }
       
   224         int x = 3;
       
   225         p.x = x;
       
   226         p.y = 3 * x + y;
       
   227         dummy();
       
   228         return p.x * p.y;
       
   229     }
       
   230 
       
   231     int test2(int y) {
       
   232         Point p1 = new Point();
       
   233         Point p2 = new Point();
       
   234         p1.x = 3;
       
   235         p2.x = 4;
       
   236         p1.y = 3 * p2.x + y;
       
   237         p2.y = 3 * p1.x + y;
       
   238         dummy();
       
   239         return p1.y * p2.y;
       
   240     }
       
   241 
       
   242     int test3(int y, Point p1) {
       
   243         Point p2 = new Point();
       
   244         p1.x = 3;
       
   245         p2.x = 4;
       
   246         p1.y = 3 * p2.x + y;
       
   247         p2.y = 3 * p1.x + y;
       
   248         dummy();
       
   249         return p1.y * p2.y;
       
   250     }
       
   251 
       
   252     int test4(int y) {
       
   253         Point p1 = new Point();
       
   254         Point p2 = new Point();
       
   255         if ((y & 1) == 1) {
       
   256             p1.x = 3;
       
   257             p2.x = 4;
       
   258         } else {
       
   259             p1.x = 5;
       
   260             p2.x = 6;
       
   261         }
       
   262         p1.y = 3 * p2.x + y;
       
   263         p2.y = 3 * p1.x + y;
       
   264         dummy();
       
   265         return p1.y * p2.y;
       
   266     }
       
   267 
       
   268     int test5(int y, Point p1) {
       
   269         Point p2 = new Point();
       
   270         if ((y & 1) == 1) {
       
   271             p1.x = 3;
       
   272             p2.x = 4;
       
   273         } else {
       
   274             p1.x = 5;
       
   275             p2.x = 6;
       
   276         }
       
   277         p1.y = 3 * p2.x + y;
       
   278         p2.y = 3 * p1.x + y;
       
   279         dummy();
       
   280         return p1.y * p2.y;
       
   281     }
       
   282 
       
   283     int test6(int y) {
       
   284         Point p1 = new Point();
       
   285         Point p2 = new Point();
       
   286         p1.next = p2;
       
   287         if ((y & 1) == 1) {
       
   288             p1.x = 3;
       
   289             p1.getNext().x = 4;
       
   290         } else {
       
   291             p1.x = 5;
       
   292             p1.getNext().x = 6;
       
   293         }
       
   294         p1.y = 3 * p2.x + y;
       
   295         p2.y = 3 * p1.x + y;
       
   296         dummy();
       
   297         return p1.y * p2.y;
       
   298     }
       
   299 
       
   300     int test7(int y, Point p1) {
       
   301         Point p2 = new Point();
       
   302         p1.next = p2;
       
   303         if ((y & 1) == 1) {
       
   304             p1.x = 3;
       
   305             p1.getNext().x = 4;
       
   306         } else {
       
   307             p1.x = 5;
       
   308             p1.getNext().x = 6;
       
   309         }
       
   310         p1.y = 3 * p2.x + y;
       
   311         p2.y = 3 * p1.x + y;
       
   312         dummy();
       
   313         return p1.y * p2.y;
       
   314     }
       
   315 
       
   316     int test8(int y, int l, int i) {
       
   317         Point p = new Point();
       
   318         p.ax = new int[l];
       
   319         p.ay = new int[l];
       
   320         int x = 3;
       
   321         p.ax[i] = x;
       
   322         p.ay[i] = 3 * x + y;
       
   323         dummy();
       
   324         return p.ax[i] * p.ay[i];
       
   325     }
       
   326 
       
   327     int test9(int y, int l, int i) {
       
   328         Point p = new Point();
       
   329         p.pax = new Point[l];
       
   330         p.pay = new Point[l];
       
   331         p.pax[i] = new Point();
       
   332         p.pay[i] = new Point();
       
   333         p.pax[i].x = 3;
       
   334         p.pay[i].x = 4;
       
   335         p.pax[i].y = 3 * p.pay[i].x + y;
       
   336         p.pay[i].y = 3 * p.pax[i].x + y;
       
   337         dummy();
       
   338         return p.pax[i].y * p.pay[i].y;
       
   339     }
       
   340 
       
   341     int test10(int y, int l, int i, Class cls) {
       
   342         Point p = new Point();
       
   343         try {
       
   344             p.pax = (Point[]) Array.newInstance(cls, l);
       
   345             p.pax[i] = (Point) cls.newInstance();
       
   346         } catch (java.lang.InstantiationException ex) {
       
   347             return 0;
       
   348         } catch (java.lang.IllegalAccessException ex) {
       
   349             return 0;
       
   350         }
       
   351         p.pax[i].x = 3;
       
   352         p.pax[i].y = 3 * p.pax[i].x + y;
       
   353         dummy();
       
   354         return p.pax[i].x * p.pax[i].y;
       
   355     }
       
   356 
       
   357     int test11(int y) {
       
   358         Point p1 = new Point();
       
   359         Point p2 = new Point();
       
   360         p1.next = p2;
       
   361         if ((y & 1) == 1) {
       
   362             p1.x = 3;
       
   363             p1.next.x = 4;
       
   364         } else {
       
   365             p1.x = 5;
       
   366             p1.next.x = 6;
       
   367         }
       
   368         p1.y = 3 * p1.next.x + y;
       
   369         p1.next.y = 3 * p1.x + y;
       
   370         dummy();
       
   371         return p1.y * p1.next.y;
       
   372     }
       
   373 
       
   374     int test12(int y) {
       
   375         Point p1 = new Point();
       
   376         p1.next = p1;
       
   377         if ((y & 1) == 1) {
       
   378             p1.x = 3;
       
   379             p1.next.x = 4;
       
   380         } else {
       
   381             p1.x = 5;
       
   382             p1.next.x = 6;
       
   383         }
       
   384         p1.y = 3 * p1.next.x + y;
       
   385         p1.next.y = 3 * p1.x + y;
       
   386         dummy();
       
   387         return p1.y * p1.next.y;
       
   388     }
       
   389 
       
   390 
       
   391     public static void main(String args[]) {
       
   392         Test6689060 tsr = new Test6689060();
       
   393         Point p = new Point();
       
   394         Point ptmp = p;
       
   395         Class cls = Point.class;
       
   396         int y = 0;
       
   397         for (int i = 0; i < 10000; i++) {
       
   398             ptmp.next = tsr.test00(1);
       
   399             ptmp.next = tsr.test01(1);
       
   400             ptmp.next = tsr.test02(1);
       
   401             ptmp.next = tsr.test03(1);
       
   402             ptmp.next = tsr.test04(1);
       
   403 
       
   404             y = tsr.test05(1);
       
   405 
       
   406             y = tsr.test80(y, 1, 0);
       
   407             y = tsr.test81(y, 1, 0);
       
   408 
       
   409             y = tsr.test44(y);
       
   410             y = tsr.test43(y);
       
   411             y = tsr.test42(y);
       
   412             y = tsr.test40(y);
       
   413             y = tsr.test41(y);
       
   414 
       
   415             y = tsr.test0(y);
       
   416             y = tsr.test1(y);
       
   417             y = tsr.test2(y);
       
   418             y = tsr.test3(y, p);
       
   419             y = tsr.test4(y);
       
   420             y = tsr.test5(y, p);
       
   421             y = tsr.test6(y);
       
   422             y = tsr.test7(y, p);
       
   423             y = tsr.test8(y, 1, 0);
       
   424             y = tsr.test9(y, 1, 0);
       
   425             y = tsr.test10(y, 1, 0, cls);
       
   426             y = tsr.test11(y);
       
   427             y = tsr.test12(y);
       
   428         }
       
   429         for (int i = 0; i < 10000; i++) {
       
   430             ptmp.next = tsr.test00(1);
       
   431             ptmp.next = tsr.test01(1);
       
   432             ptmp.next = tsr.test02(1);
       
   433             ptmp.next = tsr.test03(1);
       
   434             ptmp.next = tsr.test04(1);
       
   435 
       
   436             y = tsr.test05(1);
       
   437 
       
   438             y = tsr.test80(y, 1, 0);
       
   439             y = tsr.test81(y, 1, 0);
       
   440 
       
   441             y = tsr.test44(y);
       
   442             y = tsr.test43(y);
       
   443             y = tsr.test42(y);
       
   444             y = tsr.test40(y);
       
   445             y = tsr.test41(y);
       
   446 
       
   447             y = tsr.test0(y);
       
   448             y = tsr.test1(y);
       
   449             y = tsr.test2(y);
       
   450             y = tsr.test3(y, p);
       
   451             y = tsr.test4(y);
       
   452             y = tsr.test5(y, p);
       
   453             y = tsr.test6(y);
       
   454             y = tsr.test7(y, p);
       
   455             y = tsr.test8(y, 1, 0);
       
   456             y = tsr.test9(y, 1, 0);
       
   457             y = tsr.test10(y, 1, 0, cls);
       
   458             y = tsr.test11(y);
       
   459             y = tsr.test12(y);
       
   460         }
       
   461         for (int i = 0; i < 10000; i++) {
       
   462             ptmp.next = tsr.test00(1);
       
   463             ptmp.next = tsr.test01(1);
       
   464             ptmp.next = tsr.test02(1);
       
   465             ptmp.next = tsr.test03(1);
       
   466             ptmp.next = tsr.test04(1);
       
   467 
       
   468             y = tsr.test05(1);
       
   469 
       
   470             y = tsr.test80(y, 1, 0);
       
   471             y = tsr.test81(y, 1, 0);
       
   472 
       
   473             y = tsr.test44(y);
       
   474             y = tsr.test43(y);
       
   475             y = tsr.test42(y);
       
   476             y = tsr.test40(y);
       
   477             y = tsr.test41(y);
       
   478 
       
   479             y = tsr.test0(y);
       
   480             y = tsr.test1(y);
       
   481             y = tsr.test2(y);
       
   482             y = tsr.test3(y, p);
       
   483             y = tsr.test4(y);
       
   484             y = tsr.test5(y, p);
       
   485             y = tsr.test6(y);
       
   486             y = tsr.test7(y, p);
       
   487             y = tsr.test8(y, 1, 0);
       
   488             y = tsr.test9(y, 1, 0);
       
   489             y = tsr.test10(y, 1, 0, cls);
       
   490             y = tsr.test11(y);
       
   491             y = tsr.test12(y);
       
   492         }
       
   493 
       
   494         int z = 0;
       
   495         y = tsr.test80(0, 1, 0);
       
   496         z += y;
       
   497         System.out.println("After 'test80' y=" + y);
       
   498         y = tsr.test81(0, 1, 0);
       
   499         z += y;
       
   500         System.out.println("After 'test81' y=" + y);
       
   501 
       
   502         y = tsr.test44(0);
       
   503         z += y;
       
   504         System.out.println("After 'test44' y=" + y);
       
   505         y = tsr.test43(0);
       
   506         z += y;
       
   507         System.out.println("After 'test43' y=" + y);
       
   508         y = tsr.test42(0);
       
   509         z += y;
       
   510         System.out.println("After 'test42' y=" + y);
       
   511         y = tsr.test40(0);
       
   512         z += y;
       
   513         System.out.println("After 'test40' y=" + y);
       
   514         y = tsr.test41(0);
       
   515         z += y;
       
   516         System.out.println("After 'test41' y=" + y);
       
   517 
       
   518         ptmp.next = tsr.test00(1);
       
   519         z += y;
       
   520         System.out.println("After 'test00' p.y=" + ptmp.next.y);
       
   521         ptmp.next = tsr.test01(1);
       
   522         z += y;
       
   523         System.out.println("After 'test01' p.y=" + ptmp.next.y);
       
   524         ptmp.next = tsr.test02(1);
       
   525         z += y;
       
   526         System.out.println("After 'test02' p.y=" + ptmp.next.y);
       
   527         ptmp.next = tsr.test03(1);
       
   528         z += y;
       
   529         System.out.println("After 'test03' p.y=" + ptmp.next.y);
       
   530         ptmp.next = tsr.test04(1);
       
   531         z += y;
       
   532         System.out.println("After 'test04' p.y=" + ptmp.next.y);
       
   533 
       
   534         y = tsr.test05(1);
       
   535         z += y;
       
   536         System.out.println("After 'test05' y=" + y);
       
   537 
       
   538         y = tsr.test0(0);
       
   539         z += y;
       
   540         System.out.println("After 'test0' y=" + y);
       
   541         y = tsr.test1(0);
       
   542         z += y;
       
   543         System.out.println("After 'test1' y=" + y);
       
   544         y = tsr.test2(0);
       
   545         z += y;
       
   546         System.out.println("After 'test2' y=" + y);
       
   547         y = tsr.test3(0, new Point());
       
   548         z += y;
       
   549         System.out.println("After 'test3' y=" + y);
       
   550         y = tsr.test4(0);
       
   551         z += y;
       
   552         System.out.println("After 'test4' y=" + y);
       
   553         y = tsr.test5(0, new Point());
       
   554         z += y;
       
   555         System.out.println("After 'test5' y=" + y);
       
   556         y = tsr.test6(0);
       
   557         z += y;
       
   558         System.out.println("After 'test6' y=" + y);
       
   559         y = tsr.test7(0, new Point());
       
   560         z += y;
       
   561         System.out.println("After 'test7' y=" + y);
       
   562         y = tsr.test8(0, 1, 0);
       
   563         z += y;
       
   564         System.out.println("After 'test8' y=" + y);
       
   565         y = tsr.test9(0, 1, 0);
       
   566         z += y;
       
   567         System.out.println("After 'test9' y=" + y);
       
   568         y = tsr.test10(0, 1, 0, cls);
       
   569         z += y;
       
   570         System.out.println("After 'test10' y=" + y);
       
   571         y = tsr.test11(0);
       
   572         z += y;
       
   573         System.out.println("After 'test11' y=" + y);
       
   574         y = tsr.test12(0);
       
   575         z += y;
       
   576         System.out.println("After 'test12' y=" + y);
       
   577         System.out.println("Sum of y =" + z);
       
   578     }
       
   579 }