changeset 24510:53d23b6b25cd

8158639: C2 compilation fails with SIGSEGV Summary: fixed the jvms for callsite traps based on declared signature. Reviewed-by: jcm, coleenp, vlivanov
author dbuck
date Thu, 17 Nov 2016 16:06:56 +0000
parents 1e225dabccc5
children f5ded236c413
files src/share/vm/ci/ciMethod.hpp src/share/vm/opto/callGenerator.cpp src/share/vm/opto/graphKit.hpp test/compiler/jsr292/NullConstantReceiver.java
diffstat 4 files changed, 20 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/ci/ciMethod.hpp	Mon Jul 24 09:32:40 2017 -0700
+++ b/src/share/vm/ci/ciMethod.hpp	Thu Nov 17 16:06:56 2016 +0000
@@ -243,6 +243,11 @@
 
   ciField*      get_field_at_bci( int bci, bool &will_link);
   ciMethod*     get_method_at_bci(int bci, bool &will_link, ciSignature* *declared_signature);
+  ciMethod*     get_method_at_bci(int bci) {
+    bool ignored_will_link;
+    ciSignature* ignored_declared_signature;
+    return get_method_at_bci(bci, ignored_will_link, &ignored_declared_signature);
+  }
   // Given a certain calling environment, find the monomorphic target
   // for the call.  Return NULL if the call is not monomorphic in
   // its calling environment.
--- a/src/share/vm/opto/callGenerator.cpp	Mon Jul 24 09:32:40 2017 -0700
+++ b/src/share/vm/opto/callGenerator.cpp	Thu Nov 17 16:06:56 2016 +0000
@@ -188,7 +188,10 @@
   // the call instruction will have a seemingly deficient out-count.
   // (The bailout says something misleading about an "infinite loop".)
   if (kit.gvn().type(receiver)->higher_equal(TypePtr::NULL_PTR)) {
-    kit.inc_sp(method()->arg_size());  // restore arguments
+    assert(Bytecodes::is_invoke(kit.java_bc()), err_msg("%d: %s", kit.java_bc(), Bytecodes::name(kit.java_bc())));
+    ciMethod* declared_method = kit.method()->get_method_at_bci(kit.bci());
+    int arg_size = declared_method->signature()->arg_size_for_bc(kit.java_bc());
+    kit.inc_sp(arg_size);  // restore arguments
     kit.uncommon_trap(Deoptimization::Reason_null_check,
                       Deoptimization::Action_none,
                       NULL, "null receiver");
@@ -1119,7 +1122,10 @@
 JVMState* UncommonTrapCallGenerator::generate(JVMState* jvms) {
   GraphKit kit(jvms);
   // Take the trap with arguments pushed on the stack.  (Cf. null_check_receiver).
-  int nargs = method()->arg_size();
+  // Callsite signature can be different from actual method being called (i.e _linkTo* sites).
+  // Use callsite signature always.
+  ciMethod* declared_method = kit.method()->get_method_at_bci(kit.bci());
+  int nargs = declared_method->arg_size();
   kit.inc_sp(nargs);
   assert(nargs <= kit.sp() && kit.sp() <= jvms->stk_size(), "sane sp w/ args pushed");
   if (_reason == Deoptimization::Reason_class_check &&
--- a/src/share/vm/opto/graphKit.hpp	Mon Jul 24 09:32:40 2017 -0700
+++ b/src/share/vm/opto/graphKit.hpp	Thu Nov 17 16:06:56 2016 +0000
@@ -656,7 +656,10 @@
   // callee (with all arguments still on the stack).
   Node* null_check_receiver_before_call(ciMethod* callee) {
     assert(!callee->is_static(), "must be a virtual method");
-    const int nargs = callee->arg_size();
+    // Callsite signature can be different from actual method being called (i.e _linkTo* sites).
+    // Use callsite signature always.
+    ciMethod* declared_method = method()->get_method_at_bci(bci());
+    const int nargs = declared_method->arg_size();
     inc_sp(nargs);
     Node* n = null_check_receiver();
     dec_sp(nargs);
--- a/test/compiler/jsr292/NullConstantReceiver.java	Mon Jul 24 09:32:40 2017 -0700
+++ b/test/compiler/jsr292/NullConstantReceiver.java	Thu Nov 17 16:06:56 2016 +0000
@@ -23,8 +23,10 @@
 
 /**
  * @test
- * @bug 8059556
+ * @bug 8059556 8158639
+ *
  * @run main/othervm -Xbatch NullConstantReceiver
+ * @run main/othervm -Xbatch -XX:CompileCommand=exclude,*::run NullConstantReceiver
  */
 
 import java.lang.invoke.MethodHandle;