test/compiler/EscapeAnalysis/TestAllocatedEscapesPtrComparison.java

Wed, 21 Jan 2015 12:38:11 +0100

author
goetz
date
Wed, 21 Jan 2015 12:38:11 +0100
changeset 7574
a51071796915
parent 0
f90c822e73f8
permissions
-rw-r--r--

8068013: [TESTBUG] Aix support in hotspot jtreg tests
Reviewed-by: ctornqvi, fzhinkin, farvidsson

     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  */
    24 /*
    25  * @test
    26  * @bug 8043354
    27  * @summary  bcEscapeAnalyzer allocated_escapes not conservative enough
    28  * @run main/othervm -XX:CompileOnly=.visitAndPop TestAllocatedEscapesPtrComparison
    29  * @author Chuck Rasbold rasbold@google.com
    30  */
    32 /*
    33  * Test always passes with -XX:-OptmimizePtrCompare
    34  */
    36 import java.util.ArrayList;
    37 import java.util.List;
    39 public class TestAllocatedEscapesPtrComparison {
    41   static TestAllocatedEscapesPtrComparison dummy;
    43   class Marker {
    44   }
    46   List<Marker> markerList = new ArrayList<>();
    48   // Suppress compilation of this method, it must be processed
    49   // by the bytecode escape analyzer.
    51   // Make a new marker and put it on the List
    52   Marker getMarker() {
    53     // result escapes through markerList
    54     final Marker result = new Marker();
    55     markerList.add(result);
    56     return result;
    57   }
    59   void visit(int depth) {
    60     // Make a new marker
    61     getMarker();
    63     // Call visitAndPop every once in a while
    64     // Cap the depth of our recursive visits
    65     if (depth % 10 == 2) {
    66       visitAndPop(depth + 1);
    67     } else if (depth < 15) {
    68       visit(depth + 1);
    69     }
    70   }
    72    void visitAndPop(int depth) {
    73     // Random dummy allocation to force EscapeAnalysis to process this method
    74     dummy = new TestAllocatedEscapesPtrComparison();
    76     // Make a new marker
    77     Marker marker = getMarker();
    79     visit(depth + 1);
    81     // Walk and pop the marker list up to the current marker
    82     boolean found = false;
    83     for (int i = markerList.size() - 1; i >= 0; i--) {
    84       Marker removed = markerList.remove(i);
    86       // In the failure, EA mistakenly converts this comparison to false
    87       if (removed == marker) {
    88         found = true;
    89         break;
    90       }
    91     }
    93     if (!found) {
    94       throw new RuntimeException("test fails");
    95     }
    96   }
    99   public static void main(String args[]) {
   100     TestAllocatedEscapesPtrComparison tc = new TestAllocatedEscapesPtrComparison();
   102     // Warmup and run enough times
   103     for (int i = 0; i < 20000; i++) {
   104       tc.visit(0);
   105     }
   106   }
   107 }

mercurial