8020215: Different execution plan when using JIT vs interpreter

Fri, 12 Jul 2013 14:01:37 -0700

author
kvn
date
Fri, 12 Jul 2013 14:01:37 -0700
changeset 5436
c90c698831d7
parent 5384
dec841e0c9aa
child 5437
fcf521c3fbc6

8020215: Different execution plan when using JIT vs interpreter
Summary: fix bytecode analyzer
Reviewed-by: twisti

src/share/vm/ci/bcEscapeAnalyzer.cpp file | annotate | diff | comparison | revisions
src/share/vm/ci/bcEscapeAnalyzer.hpp file | annotate | diff | comparison | revisions
test/compiler/EscapeAnalysis/Test8020215.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/vm/ci/bcEscapeAnalyzer.cpp	Wed Jul 10 13:33:56 2013 -0700
     1.2 +++ b/src/share/vm/ci/bcEscapeAnalyzer.cpp	Fri Jul 12 14:01:37 2013 -0700
     1.3 @@ -138,6 +138,16 @@
     1.4    return false;
     1.5  }
     1.6  
     1.7 +// return true if all argument elements of vars are returned
     1.8 +bool BCEscapeAnalyzer::returns_all(ArgumentMap vars) {
     1.9 +  for (int i = 0; i < _arg_size; i++) {
    1.10 +    if (vars.contains(i) && !_arg_returned.test(i)) {
    1.11 +      return false;
    1.12 +    }
    1.13 +  }
    1.14 +  return true;
    1.15 +}
    1.16 +
    1.17  void BCEscapeAnalyzer::clear_bits(ArgumentMap vars, VectorSet &bm) {
    1.18    for (int i = 0; i < _arg_size; i++) {
    1.19      if (vars.contains(i)) {
    1.20 @@ -166,6 +176,11 @@
    1.21      if (vars.contains_unknown() || vars.contains_vars()) {
    1.22        _return_allocated = false;
    1.23      }
    1.24 +    if (_return_local && vars.contains_vars() && !returns_all(vars)) {
    1.25 +      // Return result should be invalidated if args in new
    1.26 +      // state are not recorded in return state.
    1.27 +      _return_local = false;
    1.28 +    }
    1.29    }
    1.30  }
    1.31  
     2.1 --- a/src/share/vm/ci/bcEscapeAnalyzer.hpp	Wed Jul 10 13:33:56 2013 -0700
     2.2 +++ b/src/share/vm/ci/bcEscapeAnalyzer.hpp	Fri Jul 12 14:01:37 2013 -0700
     2.3 @@ -80,6 +80,7 @@
     2.4    void set_returned(ArgumentMap vars);
     2.5    bool is_argument(ArgumentMap vars);
     2.6    bool is_arg_stack(ArgumentMap vars);
     2.7 +  bool returns_all(ArgumentMap vars);
     2.8    void clear_bits(ArgumentMap vars, VectorSet &bs);
     2.9    void set_method_escape(ArgumentMap vars);
    2.10    void set_global_escape(ArgumentMap vars, bool merge = false);
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/compiler/EscapeAnalysis/Test8020215.java	Fri Jul 12 14:01:37 2013 -0700
     3.3 @@ -0,0 +1,82 @@
     3.4 +/*
     3.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
     3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3.7 + *
     3.8 + * This code is free software; you can redistribute it and/or modify it
     3.9 + * under the terms of the GNU General Public License version 2 only, as
    3.10 + * published by the Free Software Foundation.
    3.11 + *
    3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    3.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    3.15 + * version 2 for more details (a copy is included in the LICENSE file that
    3.16 + * accompanied this code).
    3.17 + *
    3.18 + * You should have received a copy of the GNU General Public License version
    3.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    3.21 + *
    3.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    3.23 + * or visit www.oracle.com if you need additional information or have any
    3.24 + * questions.
    3.25 + */
    3.26 +
    3.27 +/*
    3.28 + * @test
    3.29 + * @bug 8020215
    3.30 + * @summary Different execution plan when using JIT vs interpreter
    3.31 + * @run main Test8020215
    3.32 + */
    3.33 +
    3.34 +import java.util.ArrayList;
    3.35 +import java.util.List;
    3.36 +
    3.37 +public class Test8020215 {
    3.38 +    public static class NamedObject {
    3.39 +        public int id;
    3.40 +        public String name;
    3.41 +        public NamedObject(int id, String name) {
    3.42 +            this.id = id;
    3.43 +            this.name = name;
    3.44 +        }
    3.45 +    }
    3.46 +
    3.47 +    public static class NamedObjectList {
    3.48 +        public List<NamedObject> namedObjectList = new ArrayList<NamedObject>();
    3.49 +
    3.50 +        public NamedObject getBest(int id) {
    3.51 +            NamedObject bestObject = null;
    3.52 +            for (NamedObject o : namedObjectList) {
    3.53 +                bestObject = id==o.id ? getBetter(bestObject, o) : bestObject;
    3.54 +            }
    3.55 +            return (bestObject != null) ? bestObject : null;
    3.56 +        }
    3.57 +
    3.58 +        private static NamedObject getBetter(NamedObject p1, NamedObject p2) {
    3.59 +            return (p1 == null) ? p2 : (p2 == null) ? p1 : (p2.name.compareTo(p1.name) >= 0) ? p2 : p1;
    3.60 +        }
    3.61 +    }
    3.62 +
    3.63 +    static void test(NamedObjectList b, int i) {
    3.64 +        NamedObject x = b.getBest(2);
    3.65 +        // test
    3.66 +        if (x == null) {
    3.67 +            throw new RuntimeException("x should never be null here! (i=" + i + ")");
    3.68 +        }
    3.69 +    }
    3.70 +
    3.71 +    public static void main(String[] args) {
    3.72 +        // setup
    3.73 +        NamedObjectList b = new NamedObjectList();
    3.74 +        for (int i = 0; i < 10000; i++) {
    3.75 +            b.namedObjectList.add(new NamedObject(1, "2012-12-31"));
    3.76 +        }
    3.77 +        b.namedObjectList.add(new NamedObject(2, "2013-12-31"));
    3.78 +
    3.79 +        // execution
    3.80 +        for (int i = 0; i < 12000; i++) {
    3.81 +            test(b, i);
    3.82 +        }
    3.83 +        System.out.println("PASSED");
    3.84 +    }
    3.85 +}

mercurial