test/hotspot/jtreg/compiler/escapeAnalysis/TestAllocatedEscapesPtrComparison.java
changeset 47216 71c04702a3d5
parent 40059 c2304140ed64
equal deleted inserted replaced
47215:4ebc2e2fb97c 47216:71c04702a3d5
       
     1 /*
       
     2  * Copyright 2014 Google, Inc.  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 8043354
       
    27  * @summary bcEscapeAnalyzer allocated_escapes not conservative enough
       
    28  *
       
    29  * @run main/othervm
       
    30  *      -XX:CompileCommand=compileonly,compiler.escapeAnalysis.TestAllocatedEscapesPtrComparison::visitAndPop
       
    31  *      compiler.escapeAnalysis.TestAllocatedEscapesPtrComparison
       
    32  * @author Chuck Rasbold rasbold@google.com
       
    33  */
       
    34 
       
    35 package compiler.escapeAnalysis;
       
    36 
       
    37 /*
       
    38  * Test always passes with -XX:-OptmimizePtrCompare
       
    39  */
       
    40 
       
    41 import java.util.ArrayList;
       
    42 import java.util.List;
       
    43 
       
    44 public class TestAllocatedEscapesPtrComparison {
       
    45 
       
    46   static TestAllocatedEscapesPtrComparison dummy;
       
    47 
       
    48   class Marker {
       
    49   }
       
    50 
       
    51   List<Marker> markerList = new ArrayList<>();
       
    52 
       
    53   // Suppress compilation of this method, it must be processed
       
    54   // by the bytecode escape analyzer.
       
    55 
       
    56   // Make a new marker and put it on the List
       
    57   Marker getMarker() {
       
    58     // result escapes through markerList
       
    59     final Marker result = new Marker();
       
    60     markerList.add(result);
       
    61     return result;
       
    62   }
       
    63 
       
    64   void visit(int depth) {
       
    65     // Make a new marker
       
    66     getMarker();
       
    67 
       
    68     // Call visitAndPop every once in a while
       
    69     // Cap the depth of our recursive visits
       
    70     if (depth % 10 == 2) {
       
    71       visitAndPop(depth + 1);
       
    72     } else if (depth < 15) {
       
    73       visit(depth + 1);
       
    74     }
       
    75   }
       
    76 
       
    77    void visitAndPop(int depth) {
       
    78     // Random dummy allocation to force EscapeAnalysis to process this method
       
    79     dummy = new TestAllocatedEscapesPtrComparison();
       
    80 
       
    81     // Make a new marker
       
    82     Marker marker = getMarker();
       
    83 
       
    84     visit(depth + 1);
       
    85 
       
    86     // Walk and pop the marker list up to the current marker
       
    87     boolean found = false;
       
    88     for (int i = markerList.size() - 1; i >= 0; i--) {
       
    89       Marker removed = markerList.remove(i);
       
    90 
       
    91       // In the failure, EA mistakenly converts this comparison to false
       
    92       if (removed == marker) {
       
    93         found = true;
       
    94         break;
       
    95       }
       
    96     }
       
    97 
       
    98     if (!found) {
       
    99       throw new RuntimeException("test fails");
       
   100     }
       
   101   }
       
   102 
       
   103 
       
   104   public static void main(String args[]) {
       
   105     TestAllocatedEscapesPtrComparison tc = new TestAllocatedEscapesPtrComparison();
       
   106 
       
   107     // Warmup and run enough times
       
   108     for (int i = 0; i < 20000; i++) {
       
   109       tc.visit(0);
       
   110     }
       
   111   }
       
   112 }