8043354: OptimizePtrCompare too aggressive when allocations are present

Wed, 21 May 2014 10:54:59 -0700

author
rasbold
date
Wed, 21 May 2014 10:54:59 -0700
changeset 6702
42d9a5f06728
parent 6701
41daa2e6e52d
child 6703
cdf27f6a6d01

8043354: OptimizePtrCompare too aggressive when allocations are present
Summary: In bcEscapeAnalyzer update the _allocated_escapes flag if a var escapes the method.
Reviewed-by: kvn

src/share/vm/ci/bcEscapeAnalyzer.cpp file | annotate | diff | comparison | revisions
test/compiler/EscapeAnalysis/TestAllocatedEscapesPtrComparison.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/vm/ci/bcEscapeAnalyzer.cpp	Fri May 30 13:30:07 2014 -0700
     1.2 +++ b/src/share/vm/ci/bcEscapeAnalyzer.cpp	Wed May 21 10:54:59 2014 -0700
     1.3 @@ -158,6 +158,9 @@
     1.4  
     1.5  void BCEscapeAnalyzer::set_method_escape(ArgumentMap vars) {
     1.6    clear_bits(vars, _arg_local);
     1.7 +  if (vars.contains_allocated()) {
     1.8 +    _allocated_escapes = true;
     1.9 +  }
    1.10  }
    1.11  
    1.12  void BCEscapeAnalyzer::set_global_escape(ArgumentMap vars, bool merge) {
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/compiler/EscapeAnalysis/TestAllocatedEscapesPtrComparison.java	Wed May 21 10:54:59 2014 -0700
     2.3 @@ -0,0 +1,107 @@
     2.4 +/*
     2.5 + * Copyright 2014 Google, Inc.  All Rights Reserved.
     2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.7 + *
     2.8 + * This code is free software; you can redistribute it and/or modify it
     2.9 + * under the terms of the GNU General Public License version 2 only, as
    2.10 + * published by the Free Software Foundation.
    2.11 + *
    2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    2.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    2.15 + * version 2 for more details (a copy is included in the LICENSE file that
    2.16 + * accompanied this code).
    2.17 + *
    2.18 + * You should have received a copy of the GNU General Public License version
    2.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    2.21 + *
    2.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    2.23 + * or visit www.oracle.com if you need additional information or have any
    2.24 + * questions.
    2.25 + */
    2.26 +
    2.27 +/*
    2.28 + * @test
    2.29 + * @bug 8043354
    2.30 + * @summary  bcEscapeAnalyzer allocated_escapes not conservative enough
    2.31 + * @run main/othervm -XX:CompileOnly=.visitAndPop TestAllocatedEscapesPtrComparison
    2.32 + * @author Chuck Rasbold rasbold@google.com
    2.33 + */
    2.34 +
    2.35 +/*
    2.36 + * Test always passes with -XX:-OptmimizePtrCompare
    2.37 + */
    2.38 +
    2.39 +import java.util.ArrayList;
    2.40 +import java.util.List;
    2.41 +
    2.42 +public class TestAllocatedEscapesPtrComparison {
    2.43 +
    2.44 +  static TestAllocatedEscapesPtrComparison dummy;
    2.45 +
    2.46 +  class Marker {
    2.47 +  }
    2.48 +
    2.49 +  List<Marker> markerList = new ArrayList<>();
    2.50 +
    2.51 +  // Suppress compilation of this method, it must be processed
    2.52 +  // by the bytecode escape analyzer.
    2.53 +
    2.54 +  // Make a new marker and put it on the List
    2.55 +  Marker getMarker() {
    2.56 +    // result escapes through markerList
    2.57 +    final Marker result = new Marker();
    2.58 +    markerList.add(result);
    2.59 +    return result;
    2.60 +  }
    2.61 +
    2.62 +  void visit(int depth) {
    2.63 +    // Make a new marker
    2.64 +    getMarker();
    2.65 +
    2.66 +    // Call visitAndPop every once in a while
    2.67 +    // Cap the depth of our recursive visits
    2.68 +    if (depth % 10 == 2) {
    2.69 +      visitAndPop(depth + 1);
    2.70 +    } else if (depth < 15) {
    2.71 +      visit(depth + 1);
    2.72 +    }
    2.73 +  }
    2.74 +
    2.75 +   void visitAndPop(int depth) {
    2.76 +    // Random dummy allocation to force EscapeAnalysis to process this method
    2.77 +    dummy = new TestAllocatedEscapesPtrComparison();
    2.78 +
    2.79 +    // Make a new marker
    2.80 +    Marker marker = getMarker();
    2.81 +
    2.82 +    visit(depth + 1);
    2.83 +
    2.84 +    // Walk and pop the marker list up to the current marker
    2.85 +    boolean found = false;
    2.86 +    for (int i = markerList.size() - 1; i >= 0; i--) {
    2.87 +      Marker removed = markerList.remove(i);
    2.88 +
    2.89 +      // In the failure, EA mistakenly converts this comparison to false
    2.90 +      if (removed == marker) {
    2.91 +        found = true;
    2.92 +        break;
    2.93 +      }
    2.94 +    }
    2.95 +
    2.96 +    if (!found) {
    2.97 +      throw new RuntimeException("test fails");
    2.98 +    }
    2.99 +  }
   2.100 +
   2.101 +
   2.102 +  public static void main(String args[]) {
   2.103 +    TestAllocatedEscapesPtrComparison tc = new TestAllocatedEscapesPtrComparison();
   2.104 +
   2.105 +    // Warmup and run enough times
   2.106 +    for (int i = 0; i < 20000; i++) {
   2.107 +      tc.visit(0);
   2.108 +    }
   2.109 +  }
   2.110 +}

mercurial