1 /* 2 * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "precompiled.hpp" 26 #include "ci/ciCPCache.hpp" 27 #include "ci/ciCallSite.hpp" 28 #include "ci/ciMethodHandle.hpp" 29 #include "classfile/vmSymbols.hpp" 30 #include "compiler/compileLog.hpp" 31 #include "interpreter/linkResolver.hpp" 32 #include "opto/addnode.hpp" 33 #include "opto/callGenerator.hpp" 34 #include "opto/cfgnode.hpp" 35 #include "opto/mulnode.hpp" 36 #include "opto/parse.hpp" 37 #include "opto/rootnode.hpp" 38 #include "opto/runtime.hpp" 39 #include "opto/subnode.hpp" 40 #include "prims/nativeLookup.hpp" 41 #include "runtime/sharedRuntime.hpp" 42 43 #ifndef PRODUCT 44 void trace_type_profile(ciMethod *method, int depth, int bci, ciMethod *prof_method, ciKlass *prof_klass, int site_count, int receiver_count) { 45 if (TraceTypeProfile || PrintInlining || PrintOptoInlining) { 46 tty->print(" "); 47 for( int i = 0; i < depth; i++ ) tty->print(" "); 48 if (!PrintOpto) { 49 method->print_short_name(); 50 tty->print(" ->"); 51 } 52 tty->print(" @ %d ", bci); 53 prof_method->print_short_name(); 54 tty->print(" >>TypeProfile (%d/%d counts) = ", receiver_count, site_count); 55 prof_klass->name()->print_symbol(); 56 tty->print_cr(" (%d bytes)", prof_method->code_size()); 57 } 58 } 59 #endif 60 61 CallGenerator* Compile::call_generator(ciMethod* call_method, int vtable_index, bool call_is_virtual, 62 JVMState* jvms, bool allow_inline, 63 float prof_factor) { 64 CallGenerator* cg; 65 66 // Dtrace currently doesn't work unless all calls are vanilla 67 if (env()->dtrace_method_probes()) { 68 allow_inline = false; 69 } 70 71 // Note: When we get profiling during stage-1 compiles, we want to pull 72 // from more specific profile data which pertains to this inlining. 73 // Right now, ignore the information in jvms->caller(), and do method[bci]. 74 ciCallProfile profile = jvms->method()->call_profile_at_bci(jvms->bci()); 75 76 // See how many times this site has been invoked. 252 } 253 CallGenerator* miss_cg; 254 Deoptimization::DeoptReason reason = (profile.morphism() == 2) ? 255 Deoptimization::Reason_bimorphic : 256 Deoptimization::Reason_class_check; 257 if (( profile.morphism() == 1 || 258 (profile.morphism() == 2 && next_hit_cg != NULL) ) && 259 !too_many_traps(jvms->method(), jvms->bci(), reason) 260 ) { 261 // Generate uncommon trap for class check failure path 262 // in case of monomorphic or bimorphic virtual call site. 263 miss_cg = CallGenerator::for_uncommon_trap(call_method, reason, 264 Deoptimization::Action_maybe_recompile); 265 } else { 266 // Generate virtual call for class check failure path 267 // in case of polymorphic virtual call site. 268 miss_cg = CallGenerator::for_virtual_call(call_method, vtable_index); 269 } 270 if (miss_cg != NULL) { 271 if (next_hit_cg != NULL) { 272 NOT_PRODUCT(trace_type_profile(jvms->method(), jvms->depth(), jvms->bci(), next_receiver_method, profile.receiver(1), site_count, profile.receiver_count(1))); 273 // We don't need to record dependency on a receiver here and below. 274 // Whenever we inline, the dependency is added by Parse::Parse(). 275 miss_cg = CallGenerator::for_predicted_call(profile.receiver(1), miss_cg, next_hit_cg, PROB_MAX); 276 } 277 if (miss_cg != NULL) { 278 NOT_PRODUCT(trace_type_profile(jvms->method(), jvms->depth(), jvms->bci(), receiver_method, profile.receiver(0), site_count, receiver_count)); 279 cg = CallGenerator::for_predicted_call(profile.receiver(0), miss_cg, hit_cg, profile.receiver_prob(0)); 280 if (cg != NULL) return cg; 281 } 282 } 283 } 284 } 285 } 286 } 287 288 // There was no special inlining tactic, or it bailed out. 289 // Use a more generic tactic, like a simple call. 290 if (call_is_virtual) { 291 return CallGenerator::for_virtual_call(call_method, vtable_index); 292 } else { 293 // Class Hierarchy Analysis or Type Profile reveals a unique target, 294 // or it is a static or special call. 295 return CallGenerator::for_direct_call(call_method, should_delay_inlining(call_method, jvms)); 296 } 297 } 298 | 1 /* 2 * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "precompiled.hpp" 26 #include "ci/ciCPCache.hpp" 27 #include "ci/ciCallSite.hpp" 28 #include "ci/ciMethodHandle.hpp" 29 #include "classfile/vmSymbols.hpp" 30 #include "compiler/compileBroker.hpp" 31 #include "compiler/compileLog.hpp" 32 #include "interpreter/linkResolver.hpp" 33 #include "opto/addnode.hpp" 34 #include "opto/callGenerator.hpp" 35 #include "opto/cfgnode.hpp" 36 #include "opto/mulnode.hpp" 37 #include "opto/parse.hpp" 38 #include "opto/rootnode.hpp" 39 #include "opto/runtime.hpp" 40 #include "opto/subnode.hpp" 41 #include "prims/nativeLookup.hpp" 42 #include "runtime/sharedRuntime.hpp" 43 44 #ifndef PRODUCT 45 void trace_type_profile(ciMethod *method, int depth, int bci, ciMethod *prof_method, ciKlass *prof_klass, int site_count, int receiver_count) { 46 if (TraceTypeProfile || PrintInlining || PrintOptoInlining) { 47 if (!PrintInlining) { 48 if (!PrintOpto && !PrintCompilation) { 49 method->print_short_name(); 50 tty->cr(); 51 } 52 CompileTask::print_inlining(prof_method, depth, bci); 53 } 54 CompileTask::print_inline_indent(depth); 55 tty->print(" \\-> TypeProfile (%d/%d counts) = ", receiver_count, site_count); 56 prof_klass->name()->print_symbol(); 57 tty->cr(); 58 } 59 } 60 #endif 61 62 CallGenerator* Compile::call_generator(ciMethod* call_method, int vtable_index, bool call_is_virtual, 63 JVMState* jvms, bool allow_inline, 64 float prof_factor) { 65 CallGenerator* cg; 66 67 // Dtrace currently doesn't work unless all calls are vanilla 68 if (env()->dtrace_method_probes()) { 69 allow_inline = false; 70 } 71 72 // Note: When we get profiling during stage-1 compiles, we want to pull 73 // from more specific profile data which pertains to this inlining. 74 // Right now, ignore the information in jvms->caller(), and do method[bci]. 75 ciCallProfile profile = jvms->method()->call_profile_at_bci(jvms->bci()); 76 77 // See how many times this site has been invoked. 253 } 254 CallGenerator* miss_cg; 255 Deoptimization::DeoptReason reason = (profile.morphism() == 2) ? 256 Deoptimization::Reason_bimorphic : 257 Deoptimization::Reason_class_check; 258 if (( profile.morphism() == 1 || 259 (profile.morphism() == 2 && next_hit_cg != NULL) ) && 260 !too_many_traps(jvms->method(), jvms->bci(), reason) 261 ) { 262 // Generate uncommon trap for class check failure path 263 // in case of monomorphic or bimorphic virtual call site. 264 miss_cg = CallGenerator::for_uncommon_trap(call_method, reason, 265 Deoptimization::Action_maybe_recompile); 266 } else { 267 // Generate virtual call for class check failure path 268 // in case of polymorphic virtual call site. 269 miss_cg = CallGenerator::for_virtual_call(call_method, vtable_index); 270 } 271 if (miss_cg != NULL) { 272 if (next_hit_cg != NULL) { 273 NOT_PRODUCT(trace_type_profile(jvms->method(), jvms->depth() - 1, jvms->bci(), next_receiver_method, profile.receiver(1), site_count, profile.receiver_count(1))); 274 // We don't need to record dependency on a receiver here and below. 275 // Whenever we inline, the dependency is added by Parse::Parse(). 276 miss_cg = CallGenerator::for_predicted_call(profile.receiver(1), miss_cg, next_hit_cg, PROB_MAX); 277 } 278 if (miss_cg != NULL) { 279 NOT_PRODUCT(trace_type_profile(jvms->method(), jvms->depth() - 1, jvms->bci(), receiver_method, profile.receiver(0), site_count, receiver_count)); 280 cg = CallGenerator::for_predicted_call(profile.receiver(0), miss_cg, hit_cg, profile.receiver_prob(0)); 281 if (cg != NULL) return cg; 282 } 283 } 284 } 285 } 286 } 287 } 288 289 // There was no special inlining tactic, or it bailed out. 290 // Use a more generic tactic, like a simple call. 291 if (call_is_virtual) { 292 return CallGenerator::for_virtual_call(call_method, vtable_index); 293 } else { 294 // Class Hierarchy Analysis or Type Profile reveals a unique target, 295 // or it is a static or special call. 296 return CallGenerator::for_direct_call(call_method, should_delay_inlining(call_method, jvms)); 297 } 298 } 299 |