7090976: Eclipse/CDT causes a JVM crash while indexing C++ code

Wed, 01 Feb 2012 10:36:58 +0100

author
roland
date
Wed, 01 Feb 2012 10:36:58 +0100
changeset 3498
f067b4e0e04b
parent 3497
2f5980b127e3
child 3499
aa3d708d67c4

7090976: Eclipse/CDT causes a JVM crash while indexing C++ code
Summary: too optimistic inlining decision confuses local value numbering.
Reviewed-by: never

src/share/vm/c1/c1_GraphBuilder.cpp file | annotate | diff | comparison | revisions
src/share/vm/c1/c1_GraphBuilder.hpp file | annotate | diff | comparison | revisions
src/share/vm/c1/c1_ValueMap.cpp file | annotate | diff | comparison | revisions
test/compiler/7090976/Test7090976.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/vm/c1/c1_GraphBuilder.cpp	Tue Jan 31 09:53:46 2012 -0800
     1.2 +++ b/src/share/vm/c1/c1_GraphBuilder.cpp	Wed Feb 01 10:36:58 2012 +0100
     1.3 @@ -1592,6 +1592,7 @@
     1.4    // this happened while running the JCK invokevirtual tests under doit.  TKR
     1.5    ciMethod* cha_monomorphic_target = NULL;
     1.6    ciMethod* exact_target = NULL;
     1.7 +  Value better_receiver = NULL;
     1.8    if (UseCHA && DeoptC1 && klass->is_loaded() && target->is_loaded() &&
     1.9        !target->is_method_handle_invoke()) {
    1.10      Value receiver = NULL;
    1.11 @@ -1653,6 +1654,18 @@
    1.12        ciInstanceKlass* singleton = NULL;
    1.13        if (target->holder()->nof_implementors() == 1) {
    1.14          singleton = target->holder()->implementor(0);
    1.15 +
    1.16 +        assert(holder->is_interface(), "invokeinterface to non interface?");
    1.17 +        ciInstanceKlass* decl_interface = (ciInstanceKlass*)holder;
    1.18 +        // the number of implementors for decl_interface is less or
    1.19 +        // equal to the number of implementors for target->holder() so
    1.20 +        // if number of implementors of target->holder() == 1 then
    1.21 +        // number of implementors for decl_interface is 0 or 1. If
    1.22 +        // it's 0 then no class implements decl_interface and there's
    1.23 +        // no point in inlining.
    1.24 +        if (!holder->is_loaded() || decl_interface->nof_implementors() != 1) {
    1.25 +          singleton = NULL;
    1.26 +        }
    1.27        }
    1.28        if (singleton) {
    1.29          cha_monomorphic_target = target->find_monomorphic_target(calling_klass, target->holder(), singleton);
    1.30 @@ -1667,7 +1680,9 @@
    1.31            CheckCast* c = new CheckCast(klass, receiver, copy_state_for_exception());
    1.32            c->set_incompatible_class_change_check();
    1.33            c->set_direct_compare(klass->is_final());
    1.34 -          append_split(c);
    1.35 +          // pass the result of the checkcast so that the compiler has
    1.36 +          // more accurate type info in the inlinee
    1.37 +          better_receiver = append_split(c);
    1.38          }
    1.39        }
    1.40      }
    1.41 @@ -1709,7 +1724,7 @@
    1.42        }
    1.43        if (!success) {
    1.44          // static binding => check if callee is ok
    1.45 -        success = try_inline(inline_target, (cha_monomorphic_target != NULL) || (exact_target != NULL));
    1.46 +        success = try_inline(inline_target, (cha_monomorphic_target != NULL) || (exact_target != NULL), better_receiver);
    1.47        }
    1.48        CHECK_BAILOUT();
    1.49  
    1.50 @@ -3034,7 +3049,7 @@
    1.51  }
    1.52  
    1.53  
    1.54 -bool GraphBuilder::try_inline(ciMethod* callee, bool holder_known) {
    1.55 +bool GraphBuilder::try_inline(ciMethod* callee, bool holder_known, Value receiver) {
    1.56    // Clear out any existing inline bailout condition
    1.57    clear_inline_bailout();
    1.58  
    1.59 @@ -3056,7 +3071,7 @@
    1.60    } else if (callee->is_abstract()) {
    1.61      INLINE_BAILOUT("abstract")
    1.62    } else {
    1.63 -    return try_inline_full(callee, holder_known);
    1.64 +    return try_inline_full(callee, holder_known, NULL, receiver);
    1.65    }
    1.66  }
    1.67  
    1.68 @@ -3405,7 +3420,7 @@
    1.69  }
    1.70  
    1.71  
    1.72 -bool GraphBuilder::try_inline_full(ciMethod* callee, bool holder_known, BlockBegin* cont_block) {
    1.73 +bool GraphBuilder::try_inline_full(ciMethod* callee, bool holder_known, BlockBegin* cont_block, Value receiver) {
    1.74    assert(!callee->is_native(), "callee must not be native");
    1.75    if (CompilationPolicy::policy()->should_not_inline(compilation()->env(), callee)) {
    1.76      INLINE_BAILOUT("inlining prohibited by policy");
    1.77 @@ -3541,6 +3556,9 @@
    1.78        Value  arg = caller_state->stack_at_inc(i);
    1.79        // NOTE: take base() of arg->type() to avoid problems storing
    1.80        // constants
    1.81 +      if (receiver != NULL && par_no == 0) {
    1.82 +        arg = receiver;
    1.83 +      }
    1.84        store_local(callee_state, arg, arg->type()->base(), par_no);
    1.85      }
    1.86    }
    1.87 @@ -3720,7 +3738,7 @@
    1.88  
    1.89            // Parse first adapter
    1.90            _last = _block = one;
    1.91 -          if (!try_inline_full(mh1_adapter, /*holder_known=*/ true, end)) {
    1.92 +          if (!try_inline_full(mh1_adapter, /*holder_known=*/ true, end, NULL)) {
    1.93              restore_inline_cleanup_info();
    1.94              block()->clear_end();  // remove appended iff
    1.95              return false;
    1.96 @@ -3729,7 +3747,7 @@
    1.97            // Parse second adapter
    1.98            _last = _block = two;
    1.99            _state = state_before;
   1.100 -          if (!try_inline_full(mh2_adapter, /*holder_known=*/ true, end)) {
   1.101 +          if (!try_inline_full(mh2_adapter, /*holder_known=*/ true, end, NULL)) {
   1.102              restore_inline_cleanup_info();
   1.103              block()->clear_end();  // remove appended iff
   1.104              return false;
     2.1 --- a/src/share/vm/c1/c1_GraphBuilder.hpp	Tue Jan 31 09:53:46 2012 -0800
     2.2 +++ b/src/share/vm/c1/c1_GraphBuilder.hpp	Wed Feb 01 10:36:58 2012 +0100
     2.3 @@ -337,9 +337,9 @@
     2.4    void fill_sync_handler(Value lock, BlockBegin* sync_handler, bool default_handler = false);
     2.5  
     2.6    // inliners
     2.7 -  bool try_inline(           ciMethod* callee, bool holder_known);
     2.8 +  bool try_inline(           ciMethod* callee, bool holder_known, Value receiver = NULL);
     2.9    bool try_inline_intrinsics(ciMethod* callee);
    2.10 -  bool try_inline_full(      ciMethod* callee, bool holder_known, BlockBegin* cont_block = NULL);
    2.11 +  bool try_inline_full(      ciMethod* callee, bool holder_known, BlockBegin* cont_block, Value receiver);
    2.12    bool try_inline_jsr(int jsr_dest_bci);
    2.13  
    2.14    // JSR 292 support
     3.1 --- a/src/share/vm/c1/c1_ValueMap.cpp	Tue Jan 31 09:53:46 2012 -0800
     3.2 +++ b/src/share/vm/c1/c1_ValueMap.cpp	Wed Feb 01 10:36:58 2012 +0100
     3.3 @@ -125,6 +125,7 @@
     3.4              // otherwise it is possible that they are not evaluated
     3.5              f->pin(Instruction::PinGlobalValueNumbering);
     3.6            }
     3.7 +          assert(x->type()->tag() == f->type()->tag(), "should have same type");
     3.8  
     3.9            return f;
    3.10  
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/test/compiler/7090976/Test7090976.java	Wed Feb 01 10:36:58 2012 +0100
     4.3 @@ -0,0 +1,82 @@
     4.4 +/*
     4.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
     4.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4.7 + *
     4.8 + * This code is free software; you can redistribute it and/or modify it
     4.9 + * under the terms of the GNU General Public License version 2 only, as
    4.10 + * published by the Free Software Foundation.
    4.11 + *
    4.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    4.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    4.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    4.15 + * version 2 for more details (a copy is included in the LICENSE file that
    4.16 + * accompanied this code).
    4.17 + *
    4.18 + * You should have received a copy of the GNU General Public License version
    4.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    4.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    4.21 + *
    4.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    4.23 + * or visit www.oracle.com if you need additional information or have any
    4.24 + * questions.
    4.25 + *
    4.26 + */
    4.27 +
    4.28 +/**
    4.29 + * @test
    4.30 + * @bug 7090976
    4.31 + * @summary Eclipse/CDT causes a JVM crash while indexing C++ code
    4.32 + *
    4.33 + * @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement Test7090976
    4.34 + */
    4.35 +
    4.36 +public class Test7090976 {
    4.37 +
    4.38 +    static interface I1 {
    4.39 +        public void m1();
    4.40 +    };
    4.41 +
    4.42 +    static interface I2 {
    4.43 +        public void m2();
    4.44 +    };
    4.45 +
    4.46 +    static interface I extends I1,I2 {
    4.47 +    }
    4.48 +
    4.49 +    static class A implements I1 {
    4.50 +        int v = 0;
    4.51 +        int v2;
    4.52 +
    4.53 +        public void m1() {
    4.54 +            v2 = v;
    4.55 +        }
    4.56 +    }
    4.57 +
    4.58 +    static class B implements I2 {
    4.59 +        Object v = new Object();
    4.60 +        Object v2;
    4.61 +
    4.62 +        public void m2() {
    4.63 +            v2 = v;
    4.64 +        }
    4.65 +    }
    4.66 +
    4.67 +    private void test(A a)
    4.68 +    {
    4.69 +        if (a instanceof I) {
    4.70 +            I i = (I)a;
    4.71 +            i.m1();
    4.72 +            i.m2();
    4.73 +        }
    4.74 +    }
    4.75 +
    4.76 +    public static void main(String[] args)
    4.77 +    {
    4.78 +        Test7090976 t = new Test7090976();
    4.79 +        A a = new A();
    4.80 +        B b = new B();
    4.81 +        for (int i = 0; i < 10000; i++) {
    4.82 +            t.test(a);
    4.83 +        }
    4.84 +    }
    4.85 +}

mercurial