--- old/src/share/vm/ci/ciMethod.hpp 2016-11-16 09:31:43.419379661 +0000 +++ new/src/share/vm/ci/ciMethod.hpp 2016-11-16 09:31:43.293379670 +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. --- old/src/share/vm/opto/callGenerator.cpp 2016-11-16 09:31:43.879379630 +0000 +++ new/src/share/vm/opto/callGenerator.cpp 2016-11-16 09:31:43.755379638 +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 && --- old/src/share/vm/opto/graphKit.hpp 2016-11-16 09:31:44.346379598 +0000 +++ new/src/share/vm/opto/graphKit.hpp 2016-11-16 09:31:44.222379606 +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); --- old/test/compiler/jsr292/NullConstantReceiver.java 2016-11-16 09:31:44.797379567 +0000 +++ new/test/compiler/jsr292/NullConstantReceiver.java 2016-11-16 09:31:44.673379576 +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;