--- old/src/share/vm/ci/ciMethod.hpp 2016-11-15 11:54:45.983700818 +0000 +++ new/src/share/vm/ci/ciMethod.hpp 2016-11-15 11:54:45.831700828 +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-15 11:54:46.480700784 +0000 +++ new/src/share/vm/opto/callGenerator.cpp 2016-11-15 11:54:46.323700794 +0000 @@ -1119,7 +1119,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-15 11:54:46.951700752 +0000 +++ new/src/share/vm/opto/graphKit.hpp 2016-11-15 11:54:46.820700761 +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-15 11:54:47.422700719 +0000 +++ new/test/compiler/jsr292/NullConstantReceiver.java 2016-11-15 11:54:47.285700729 +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;