test/compiler/EscapeAnalysis/TestAllocatedEscapesPtrComparison.java

changeset 0
f90c822e73f8
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/compiler/EscapeAnalysis/TestAllocatedEscapesPtrComparison.java	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,107 @@
     1.4 +/*
     1.5 + * Copyright 2014 Google, Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + */
    1.26 +
    1.27 +/*
    1.28 + * @test
    1.29 + * @bug 8043354
    1.30 + * @summary  bcEscapeAnalyzer allocated_escapes not conservative enough
    1.31 + * @run main/othervm -XX:CompileOnly=.visitAndPop TestAllocatedEscapesPtrComparison
    1.32 + * @author Chuck Rasbold rasbold@google.com
    1.33 + */
    1.34 +
    1.35 +/*
    1.36 + * Test always passes with -XX:-OptmimizePtrCompare
    1.37 + */
    1.38 +
    1.39 +import java.util.ArrayList;
    1.40 +import java.util.List;
    1.41 +
    1.42 +public class TestAllocatedEscapesPtrComparison {
    1.43 +
    1.44 +  static TestAllocatedEscapesPtrComparison dummy;
    1.45 +
    1.46 +  class Marker {
    1.47 +  }
    1.48 +
    1.49 +  List<Marker> markerList = new ArrayList<>();
    1.50 +
    1.51 +  // Suppress compilation of this method, it must be processed
    1.52 +  // by the bytecode escape analyzer.
    1.53 +
    1.54 +  // Make a new marker and put it on the List
    1.55 +  Marker getMarker() {
    1.56 +    // result escapes through markerList
    1.57 +    final Marker result = new Marker();
    1.58 +    markerList.add(result);
    1.59 +    return result;
    1.60 +  }
    1.61 +
    1.62 +  void visit(int depth) {
    1.63 +    // Make a new marker
    1.64 +    getMarker();
    1.65 +
    1.66 +    // Call visitAndPop every once in a while
    1.67 +    // Cap the depth of our recursive visits
    1.68 +    if (depth % 10 == 2) {
    1.69 +      visitAndPop(depth + 1);
    1.70 +    } else if (depth < 15) {
    1.71 +      visit(depth + 1);
    1.72 +    }
    1.73 +  }
    1.74 +
    1.75 +   void visitAndPop(int depth) {
    1.76 +    // Random dummy allocation to force EscapeAnalysis to process this method
    1.77 +    dummy = new TestAllocatedEscapesPtrComparison();
    1.78 +
    1.79 +    // Make a new marker
    1.80 +    Marker marker = getMarker();
    1.81 +
    1.82 +    visit(depth + 1);
    1.83 +
    1.84 +    // Walk and pop the marker list up to the current marker
    1.85 +    boolean found = false;
    1.86 +    for (int i = markerList.size() - 1; i >= 0; i--) {
    1.87 +      Marker removed = markerList.remove(i);
    1.88 +
    1.89 +      // In the failure, EA mistakenly converts this comparison to false
    1.90 +      if (removed == marker) {
    1.91 +        found = true;
    1.92 +        break;
    1.93 +      }
    1.94 +    }
    1.95 +
    1.96 +    if (!found) {
    1.97 +      throw new RuntimeException("test fails");
    1.98 +    }
    1.99 +  }
   1.100 +
   1.101 +
   1.102 +  public static void main(String args[]) {
   1.103 +    TestAllocatedEscapesPtrComparison tc = new TestAllocatedEscapesPtrComparison();
   1.104 +
   1.105 +    // Warmup and run enough times
   1.106 +    for (int i = 0; i < 20000; i++) {
   1.107 +      tc.visit(0);
   1.108 +    }
   1.109 +  }
   1.110 +}

mercurial