--- openjdk/hotspot/src/share/vm/opto/doCall.cpp 2016-07-22 11:32:42.953343258 +0200 +++ openjdk/hotspot/src/share/vm/opto/doCall.cpp 2016-07-22 11:32:39.209369543 +0200 @@ -209,16 +209,22 @@ int morphism = profile.morphism(); if (speculative_receiver_type != NULL) { - // We have a speculative type, we should be able to resolve - // the call. We do that before looking at the profiling at - // this invoke because it may lead to bimorphic inlining which - // a speculative type should help us avoid. - receiver_method = callee->resolve_invoke(jvms->method()->holder(), - speculative_receiver_type); - if (receiver_method == NULL) { - speculative_receiver_type = NULL; + if (!too_many_traps(caller, bci, Deoptimization::Reason_speculate_class_check)) { + // We have a speculative type, we should be able to resolve + // the call. We do that before looking at the profiling at + // this invoke because it may lead to bimorphic inlining which + // a speculative type should help us avoid. + receiver_method = callee->resolve_invoke(jvms->method()->holder(), + speculative_receiver_type); + if (receiver_method == NULL) { + speculative_receiver_type = NULL; + } else { + morphism = 1; + } } else { - morphism = 1; + // speculation failed before. Use profiling at the call + // (could allow bimorphic inlining for instance). + speculative_receiver_type = NULL; } } if (receiver_method == NULL && @@ -255,7 +261,7 @@ Deoptimization::Reason_bimorphic : (speculative_receiver_type == NULL ? Deoptimization::Reason_class_check : Deoptimization::Reason_speculate_class_check); if ((morphism == 1 || (morphism == 2 && next_hit_cg != NULL)) && - !too_many_traps(jvms->method(), jvms->bci(), reason) + !too_many_traps(caller, bci, reason) ) { // Generate uncommon trap for class check failure path // in case of monomorphic or bimorphic virtual call site.