src/share/vm/opto/callGenerator.cpp

Thu, 05 Feb 2009 11:42:10 -0800

author
never
date
Thu, 05 Feb 2009 11:42:10 -0800
changeset 979
82a980778b92
parent 772
9ee9cf798b59
child 1515
7c57aead6d3e
permissions
-rw-r--r--

6793828: G1: invariant: queues are empty when activated
Reviewed-by: jrose, kvn

duke@435 1 /*
xdono@772 2 * Copyright 2000-2008 Sun Microsystems, Inc. All Rights Reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 #include "incls/_precompiled.incl"
duke@435 26 #include "incls/_callGenerator.cpp.incl"
duke@435 27
duke@435 28 CallGenerator::CallGenerator(ciMethod* method) {
duke@435 29 _method = method;
duke@435 30 }
duke@435 31
duke@435 32 // Utility function.
duke@435 33 const TypeFunc* CallGenerator::tf() const {
duke@435 34 return TypeFunc::make(method());
duke@435 35 }
duke@435 36
duke@435 37 //-----------------------------ParseGenerator---------------------------------
duke@435 38 // Internal class which handles all direct bytecode traversal.
duke@435 39 class ParseGenerator : public InlineCallGenerator {
duke@435 40 private:
duke@435 41 bool _is_osr;
duke@435 42 float _expected_uses;
duke@435 43
duke@435 44 public:
duke@435 45 ParseGenerator(ciMethod* method, float expected_uses, bool is_osr = false)
duke@435 46 : InlineCallGenerator(method)
duke@435 47 {
duke@435 48 _is_osr = is_osr;
duke@435 49 _expected_uses = expected_uses;
duke@435 50 assert(can_parse(method, is_osr), "parse must be possible");
duke@435 51 }
duke@435 52
duke@435 53 // Can we build either an OSR or a regular parser for this method?
duke@435 54 static bool can_parse(ciMethod* method, int is_osr = false);
duke@435 55
duke@435 56 virtual bool is_parse() const { return true; }
duke@435 57 virtual JVMState* generate(JVMState* jvms);
duke@435 58 int is_osr() { return _is_osr; }
duke@435 59
duke@435 60 };
duke@435 61
duke@435 62 JVMState* ParseGenerator::generate(JVMState* jvms) {
duke@435 63 Compile* C = Compile::current();
duke@435 64
duke@435 65 if (is_osr()) {
duke@435 66 // The JVMS for a OSR has a single argument (see its TypeFunc).
duke@435 67 assert(jvms->depth() == 1, "no inline OSR");
duke@435 68 }
duke@435 69
duke@435 70 if (C->failing()) {
duke@435 71 return NULL; // bailing out of the compile; do not try to parse
duke@435 72 }
duke@435 73
duke@435 74 Parse parser(jvms, method(), _expected_uses);
duke@435 75 // Grab signature for matching/allocation
duke@435 76 #ifdef ASSERT
duke@435 77 if (parser.tf() != (parser.depth() == 1 ? C->tf() : tf())) {
duke@435 78 MutexLockerEx ml(Compile_lock, Mutex::_no_safepoint_check_flag);
duke@435 79 assert(C->env()->system_dictionary_modification_counter_changed(),
duke@435 80 "Must invalidate if TypeFuncs differ");
duke@435 81 }
duke@435 82 #endif
duke@435 83
duke@435 84 GraphKit& exits = parser.exits();
duke@435 85
duke@435 86 if (C->failing()) {
duke@435 87 while (exits.pop_exception_state() != NULL) ;
duke@435 88 return NULL;
duke@435 89 }
duke@435 90
duke@435 91 assert(exits.jvms()->same_calls_as(jvms), "sanity");
duke@435 92
duke@435 93 // Simply return the exit state of the parser,
duke@435 94 // augmented by any exceptional states.
duke@435 95 return exits.transfer_exceptions_into_jvms();
duke@435 96 }
duke@435 97
duke@435 98 //---------------------------DirectCallGenerator------------------------------
duke@435 99 // Internal class which handles all out-of-line calls w/o receiver type checks.
duke@435 100 class DirectCallGenerator : public CallGenerator {
duke@435 101 public:
duke@435 102 DirectCallGenerator(ciMethod* method)
duke@435 103 : CallGenerator(method)
duke@435 104 {
duke@435 105 }
duke@435 106 virtual JVMState* generate(JVMState* jvms);
duke@435 107 };
duke@435 108
duke@435 109 JVMState* DirectCallGenerator::generate(JVMState* jvms) {
duke@435 110 GraphKit kit(jvms);
duke@435 111 bool is_static = method()->is_static();
duke@435 112 address target = is_static ? SharedRuntime::get_resolve_static_call_stub()
duke@435 113 : SharedRuntime::get_resolve_opt_virtual_call_stub();
duke@435 114
duke@435 115 if (kit.C->log() != NULL) {
duke@435 116 kit.C->log()->elem("direct_call bci='%d'", jvms->bci());
duke@435 117 }
duke@435 118
duke@435 119 CallStaticJavaNode *call = new (kit.C, tf()->domain()->cnt()) CallStaticJavaNode(tf(), target, method(), kit.bci());
duke@435 120 if (!is_static) {
duke@435 121 // Make an explicit receiver null_check as part of this call.
duke@435 122 // Since we share a map with the caller, his JVMS gets adjusted.
duke@435 123 kit.null_check_receiver(method());
duke@435 124 if (kit.stopped()) {
duke@435 125 // And dump it back to the caller, decorated with any exceptions:
duke@435 126 return kit.transfer_exceptions_into_jvms();
duke@435 127 }
duke@435 128 // Mark the call node as virtual, sort of:
duke@435 129 call->set_optimized_virtual(true);
duke@435 130 }
duke@435 131 kit.set_arguments_for_java_call(call);
duke@435 132 kit.set_edges_for_java_call(call);
duke@435 133 Node* ret = kit.set_results_for_java_call(call);
duke@435 134 kit.push_node(method()->return_type()->basic_type(), ret);
duke@435 135 return kit.transfer_exceptions_into_jvms();
duke@435 136 }
duke@435 137
duke@435 138 class VirtualCallGenerator : public CallGenerator {
duke@435 139 private:
duke@435 140 int _vtable_index;
duke@435 141 public:
duke@435 142 VirtualCallGenerator(ciMethod* method, int vtable_index)
duke@435 143 : CallGenerator(method), _vtable_index(vtable_index)
duke@435 144 {
duke@435 145 assert(vtable_index == methodOopDesc::invalid_vtable_index ||
duke@435 146 vtable_index >= 0, "either invalid or usable");
duke@435 147 }
duke@435 148 virtual bool is_virtual() const { return true; }
duke@435 149 virtual JVMState* generate(JVMState* jvms);
duke@435 150 };
duke@435 151
duke@435 152 //--------------------------VirtualCallGenerator------------------------------
duke@435 153 // Internal class which handles all out-of-line calls checking receiver type.
duke@435 154 JVMState* VirtualCallGenerator::generate(JVMState* jvms) {
duke@435 155 GraphKit kit(jvms);
duke@435 156 Node* receiver = kit.argument(0);
duke@435 157
duke@435 158 if (kit.C->log() != NULL) {
duke@435 159 kit.C->log()->elem("virtual_call bci='%d'", jvms->bci());
duke@435 160 }
duke@435 161
duke@435 162 // If the receiver is a constant null, do not torture the system
duke@435 163 // by attempting to call through it. The compile will proceed
duke@435 164 // correctly, but may bail out in final_graph_reshaping, because
duke@435 165 // the call instruction will have a seemingly deficient out-count.
duke@435 166 // (The bailout says something misleading about an "infinite loop".)
duke@435 167 if (kit.gvn().type(receiver)->higher_equal(TypePtr::NULL_PTR)) {
duke@435 168 kit.inc_sp(method()->arg_size()); // restore arguments
duke@435 169 kit.uncommon_trap(Deoptimization::Reason_null_check,
duke@435 170 Deoptimization::Action_none,
duke@435 171 NULL, "null receiver");
duke@435 172 return kit.transfer_exceptions_into_jvms();
duke@435 173 }
duke@435 174
duke@435 175 // Ideally we would unconditionally do a null check here and let it
duke@435 176 // be converted to an implicit check based on profile information.
duke@435 177 // However currently the conversion to implicit null checks in
duke@435 178 // Block::implicit_null_check() only looks for loads and stores, not calls.
duke@435 179 ciMethod *caller = kit.method();
duke@435 180 ciMethodData *caller_md = (caller == NULL) ? NULL : caller->method_data();
duke@435 181 if (!UseInlineCaches || !ImplicitNullChecks ||
duke@435 182 ((ImplicitNullCheckThreshold > 0) && caller_md &&
duke@435 183 (caller_md->trap_count(Deoptimization::Reason_null_check)
duke@435 184 >= (uint)ImplicitNullCheckThreshold))) {
duke@435 185 // Make an explicit receiver null_check as part of this call.
duke@435 186 // Since we share a map with the caller, his JVMS gets adjusted.
duke@435 187 receiver = kit.null_check_receiver(method());
duke@435 188 if (kit.stopped()) {
duke@435 189 // And dump it back to the caller, decorated with any exceptions:
duke@435 190 return kit.transfer_exceptions_into_jvms();
duke@435 191 }
duke@435 192 }
duke@435 193
duke@435 194 assert(!method()->is_static(), "virtual call must not be to static");
duke@435 195 assert(!method()->is_final(), "virtual call should not be to final");
duke@435 196 assert(!method()->is_private(), "virtual call should not be to private");
duke@435 197 assert(_vtable_index == methodOopDesc::invalid_vtable_index || !UseInlineCaches,
duke@435 198 "no vtable calls if +UseInlineCaches ");
duke@435 199 address target = SharedRuntime::get_resolve_virtual_call_stub();
duke@435 200 // Normal inline cache used for call
duke@435 201 CallDynamicJavaNode *call = new (kit.C, tf()->domain()->cnt()) CallDynamicJavaNode(tf(), target, method(), _vtable_index, kit.bci());
duke@435 202 kit.set_arguments_for_java_call(call);
duke@435 203 kit.set_edges_for_java_call(call);
duke@435 204 Node* ret = kit.set_results_for_java_call(call);
duke@435 205 kit.push_node(method()->return_type()->basic_type(), ret);
duke@435 206
duke@435 207 // Represent the effect of an implicit receiver null_check
duke@435 208 // as part of this call. Since we share a map with the caller,
duke@435 209 // his JVMS gets adjusted.
duke@435 210 kit.cast_not_null(receiver);
duke@435 211 return kit.transfer_exceptions_into_jvms();
duke@435 212 }
duke@435 213
duke@435 214 bool ParseGenerator::can_parse(ciMethod* m, int entry_bci) {
duke@435 215 // Certain methods cannot be parsed at all:
duke@435 216 if (!m->can_be_compiled()) return false;
duke@435 217 if (!m->has_balanced_monitors()) return false;
duke@435 218 if (m->get_flow_analysis()->failing()) return false;
duke@435 219
duke@435 220 // (Methods may bail out for other reasons, after the parser is run.
duke@435 221 // We try to avoid this, but if forced, we must return (Node*)NULL.
duke@435 222 // The user of the CallGenerator must check for this condition.)
duke@435 223 return true;
duke@435 224 }
duke@435 225
duke@435 226 CallGenerator* CallGenerator::for_inline(ciMethod* m, float expected_uses) {
duke@435 227 if (!ParseGenerator::can_parse(m)) return NULL;
duke@435 228 return new ParseGenerator(m, expected_uses);
duke@435 229 }
duke@435 230
duke@435 231 // As a special case, the JVMS passed to this CallGenerator is
duke@435 232 // for the method execution already in progress, not just the JVMS
duke@435 233 // of the caller. Thus, this CallGenerator cannot be mixed with others!
duke@435 234 CallGenerator* CallGenerator::for_osr(ciMethod* m, int osr_bci) {
duke@435 235 if (!ParseGenerator::can_parse(m, true)) return NULL;
duke@435 236 float past_uses = m->interpreter_invocation_count();
duke@435 237 float expected_uses = past_uses;
duke@435 238 return new ParseGenerator(m, expected_uses, true);
duke@435 239 }
duke@435 240
duke@435 241 CallGenerator* CallGenerator::for_direct_call(ciMethod* m) {
duke@435 242 assert(!m->is_abstract(), "for_direct_call mismatch");
duke@435 243 return new DirectCallGenerator(m);
duke@435 244 }
duke@435 245
duke@435 246 CallGenerator* CallGenerator::for_virtual_call(ciMethod* m, int vtable_index) {
duke@435 247 assert(!m->is_static(), "for_virtual_call mismatch");
duke@435 248 return new VirtualCallGenerator(m, vtable_index);
duke@435 249 }
duke@435 250
duke@435 251
duke@435 252 //---------------------------WarmCallGenerator--------------------------------
duke@435 253 // Internal class which handles initial deferral of inlining decisions.
duke@435 254 class WarmCallGenerator : public CallGenerator {
duke@435 255 WarmCallInfo* _call_info;
duke@435 256 CallGenerator* _if_cold;
duke@435 257 CallGenerator* _if_hot;
duke@435 258 bool _is_virtual; // caches virtuality of if_cold
duke@435 259 bool _is_inline; // caches inline-ness of if_hot
duke@435 260
duke@435 261 public:
duke@435 262 WarmCallGenerator(WarmCallInfo* ci,
duke@435 263 CallGenerator* if_cold,
duke@435 264 CallGenerator* if_hot)
duke@435 265 : CallGenerator(if_cold->method())
duke@435 266 {
duke@435 267 assert(method() == if_hot->method(), "consistent choices");
duke@435 268 _call_info = ci;
duke@435 269 _if_cold = if_cold;
duke@435 270 _if_hot = if_hot;
duke@435 271 _is_virtual = if_cold->is_virtual();
duke@435 272 _is_inline = if_hot->is_inline();
duke@435 273 }
duke@435 274
duke@435 275 virtual bool is_inline() const { return _is_inline; }
duke@435 276 virtual bool is_virtual() const { return _is_virtual; }
duke@435 277 virtual bool is_deferred() const { return true; }
duke@435 278
duke@435 279 virtual JVMState* generate(JVMState* jvms);
duke@435 280 };
duke@435 281
duke@435 282
duke@435 283 CallGenerator* CallGenerator::for_warm_call(WarmCallInfo* ci,
duke@435 284 CallGenerator* if_cold,
duke@435 285 CallGenerator* if_hot) {
duke@435 286 return new WarmCallGenerator(ci, if_cold, if_hot);
duke@435 287 }
duke@435 288
duke@435 289 JVMState* WarmCallGenerator::generate(JVMState* jvms) {
duke@435 290 Compile* C = Compile::current();
duke@435 291 if (C->log() != NULL) {
duke@435 292 C->log()->elem("warm_call bci='%d'", jvms->bci());
duke@435 293 }
duke@435 294 jvms = _if_cold->generate(jvms);
duke@435 295 if (jvms != NULL) {
duke@435 296 Node* m = jvms->map()->control();
duke@435 297 if (m->is_CatchProj()) m = m->in(0); else m = C->top();
duke@435 298 if (m->is_Catch()) m = m->in(0); else m = C->top();
duke@435 299 if (m->is_Proj()) m = m->in(0); else m = C->top();
duke@435 300 if (m->is_CallJava()) {
duke@435 301 _call_info->set_call(m->as_Call());
duke@435 302 _call_info->set_hot_cg(_if_hot);
duke@435 303 #ifndef PRODUCT
duke@435 304 if (PrintOpto || PrintOptoInlining) {
duke@435 305 tty->print_cr("Queueing for warm inlining at bci %d:", jvms->bci());
duke@435 306 tty->print("WCI: ");
duke@435 307 _call_info->print();
duke@435 308 }
duke@435 309 #endif
duke@435 310 _call_info->set_heat(_call_info->compute_heat());
duke@435 311 C->set_warm_calls(_call_info->insert_into(C->warm_calls()));
duke@435 312 }
duke@435 313 }
duke@435 314 return jvms;
duke@435 315 }
duke@435 316
duke@435 317 void WarmCallInfo::make_hot() {
duke@435 318 Compile* C = Compile::current();
duke@435 319 // Replace the callnode with something better.
duke@435 320 CallJavaNode* call = this->call()->as_CallJava();
duke@435 321 ciMethod* method = call->method();
duke@435 322 int nargs = method->arg_size();
duke@435 323 JVMState* jvms = call->jvms()->clone_shallow(C);
duke@435 324 uint size = TypeFunc::Parms + MAX2(2, nargs);
duke@435 325 SafePointNode* map = new (C, size) SafePointNode(size, jvms);
duke@435 326 for (uint i1 = 0; i1 < (uint)(TypeFunc::Parms + nargs); i1++) {
duke@435 327 map->init_req(i1, call->in(i1));
duke@435 328 }
duke@435 329 jvms->set_map(map);
duke@435 330 jvms->set_offsets(map->req());
duke@435 331 jvms->set_locoff(TypeFunc::Parms);
duke@435 332 jvms->set_stkoff(TypeFunc::Parms);
duke@435 333 GraphKit kit(jvms);
duke@435 334
duke@435 335 JVMState* new_jvms = _hot_cg->generate(kit.jvms());
duke@435 336 if (new_jvms == NULL) return; // no change
duke@435 337 if (C->failing()) return;
duke@435 338
duke@435 339 kit.set_jvms(new_jvms);
duke@435 340 Node* res = C->top();
duke@435 341 int res_size = method->return_type()->size();
duke@435 342 if (res_size != 0) {
duke@435 343 kit.inc_sp(-res_size);
duke@435 344 res = kit.argument(0);
duke@435 345 }
duke@435 346 GraphKit ekit(kit.combine_and_pop_all_exception_states()->jvms());
duke@435 347
duke@435 348 // Replace the call:
duke@435 349 for (DUIterator i = call->outs(); call->has_out(i); i++) {
duke@435 350 Node* n = call->out(i);
duke@435 351 Node* nn = NULL; // replacement
duke@435 352 if (n->is_Proj()) {
duke@435 353 ProjNode* nproj = n->as_Proj();
duke@435 354 assert(nproj->_con < (uint)(TypeFunc::Parms + (res_size ? 1 : 0)), "sane proj");
duke@435 355 if (nproj->_con == TypeFunc::Parms) {
duke@435 356 nn = res;
duke@435 357 } else {
duke@435 358 nn = kit.map()->in(nproj->_con);
duke@435 359 }
duke@435 360 if (nproj->_con == TypeFunc::I_O) {
duke@435 361 for (DUIterator j = nproj->outs(); nproj->has_out(j); j++) {
duke@435 362 Node* e = nproj->out(j);
duke@435 363 if (e->Opcode() == Op_CreateEx) {
duke@435 364 e->replace_by(ekit.argument(0));
duke@435 365 } else if (e->Opcode() == Op_Catch) {
duke@435 366 for (DUIterator k = e->outs(); e->has_out(k); k++) {
duke@435 367 CatchProjNode* p = e->out(j)->as_CatchProj();
duke@435 368 if (p->is_handler_proj()) {
duke@435 369 p->replace_by(ekit.control());
duke@435 370 } else {
duke@435 371 p->replace_by(kit.control());
duke@435 372 }
duke@435 373 }
duke@435 374 }
duke@435 375 }
duke@435 376 }
duke@435 377 }
duke@435 378 NOT_PRODUCT(if (!nn) n->dump(2));
duke@435 379 assert(nn != NULL, "don't know what to do with this user");
duke@435 380 n->replace_by(nn);
duke@435 381 }
duke@435 382 }
duke@435 383
duke@435 384 void WarmCallInfo::make_cold() {
duke@435 385 // No action: Just dequeue.
duke@435 386 }
duke@435 387
duke@435 388
duke@435 389 //------------------------PredictedCallGenerator------------------------------
duke@435 390 // Internal class which handles all out-of-line calls checking receiver type.
duke@435 391 class PredictedCallGenerator : public CallGenerator {
duke@435 392 ciKlass* _predicted_receiver;
duke@435 393 CallGenerator* _if_missed;
duke@435 394 CallGenerator* _if_hit;
duke@435 395 float _hit_prob;
duke@435 396
duke@435 397 public:
duke@435 398 PredictedCallGenerator(ciKlass* predicted_receiver,
duke@435 399 CallGenerator* if_missed,
duke@435 400 CallGenerator* if_hit, float hit_prob)
duke@435 401 : CallGenerator(if_missed->method())
duke@435 402 {
duke@435 403 // The call profile data may predict the hit_prob as extreme as 0 or 1.
duke@435 404 // Remove the extremes values from the range.
duke@435 405 if (hit_prob > PROB_MAX) hit_prob = PROB_MAX;
duke@435 406 if (hit_prob < PROB_MIN) hit_prob = PROB_MIN;
duke@435 407
duke@435 408 _predicted_receiver = predicted_receiver;
duke@435 409 _if_missed = if_missed;
duke@435 410 _if_hit = if_hit;
duke@435 411 _hit_prob = hit_prob;
duke@435 412 }
duke@435 413
duke@435 414 virtual bool is_virtual() const { return true; }
duke@435 415 virtual bool is_inline() const { return _if_hit->is_inline(); }
duke@435 416 virtual bool is_deferred() const { return _if_hit->is_deferred(); }
duke@435 417
duke@435 418 virtual JVMState* generate(JVMState* jvms);
duke@435 419 };
duke@435 420
duke@435 421
duke@435 422 CallGenerator* CallGenerator::for_predicted_call(ciKlass* predicted_receiver,
duke@435 423 CallGenerator* if_missed,
duke@435 424 CallGenerator* if_hit,
duke@435 425 float hit_prob) {
duke@435 426 return new PredictedCallGenerator(predicted_receiver, if_missed, if_hit, hit_prob);
duke@435 427 }
duke@435 428
duke@435 429
duke@435 430 JVMState* PredictedCallGenerator::generate(JVMState* jvms) {
duke@435 431 GraphKit kit(jvms);
duke@435 432 PhaseGVN& gvn = kit.gvn();
duke@435 433 // We need an explicit receiver null_check before checking its type.
duke@435 434 // We share a map with the caller, so his JVMS gets adjusted.
duke@435 435 Node* receiver = kit.argument(0);
duke@435 436
duke@435 437 CompileLog* log = kit.C->log();
duke@435 438 if (log != NULL) {
duke@435 439 log->elem("predicted_call bci='%d' klass='%d'",
duke@435 440 jvms->bci(), log->identify(_predicted_receiver));
duke@435 441 }
duke@435 442
duke@435 443 receiver = kit.null_check_receiver(method());
duke@435 444 if (kit.stopped()) {
duke@435 445 return kit.transfer_exceptions_into_jvms();
duke@435 446 }
duke@435 447
duke@435 448 Node* exact_receiver = receiver; // will get updated in place...
duke@435 449 Node* slow_ctl = kit.type_check_receiver(receiver,
duke@435 450 _predicted_receiver, _hit_prob,
duke@435 451 &exact_receiver);
duke@435 452
duke@435 453 SafePointNode* slow_map = NULL;
duke@435 454 JVMState* slow_jvms;
duke@435 455 { PreserveJVMState pjvms(&kit);
duke@435 456 kit.set_control(slow_ctl);
duke@435 457 if (!kit.stopped()) {
duke@435 458 slow_jvms = _if_missed->generate(kit.sync_jvms());
duke@435 459 assert(slow_jvms != NULL, "miss path must not fail to generate");
duke@435 460 kit.add_exception_states_from(slow_jvms);
duke@435 461 kit.set_map(slow_jvms->map());
duke@435 462 if (!kit.stopped())
duke@435 463 slow_map = kit.stop();
duke@435 464 }
duke@435 465 }
duke@435 466
kvn@728 467 if (kit.stopped()) {
kvn@728 468 // Instance exactly does not matches the desired type.
kvn@728 469 kit.set_jvms(slow_jvms);
kvn@728 470 return kit.transfer_exceptions_into_jvms();
kvn@728 471 }
kvn@728 472
duke@435 473 // fall through if the instance exactly matches the desired type
duke@435 474 kit.replace_in_map(receiver, exact_receiver);
duke@435 475
duke@435 476 // Make the hot call:
duke@435 477 JVMState* new_jvms = _if_hit->generate(kit.sync_jvms());
duke@435 478 if (new_jvms == NULL) {
duke@435 479 // Inline failed, so make a direct call.
duke@435 480 assert(_if_hit->is_inline(), "must have been a failed inline");
duke@435 481 CallGenerator* cg = CallGenerator::for_direct_call(_if_hit->method());
duke@435 482 new_jvms = cg->generate(kit.sync_jvms());
duke@435 483 }
duke@435 484 kit.add_exception_states_from(new_jvms);
duke@435 485 kit.set_jvms(new_jvms);
duke@435 486
duke@435 487 // Need to merge slow and fast?
duke@435 488 if (slow_map == NULL) {
duke@435 489 // The fast path is the only path remaining.
duke@435 490 return kit.transfer_exceptions_into_jvms();
duke@435 491 }
duke@435 492
duke@435 493 if (kit.stopped()) {
duke@435 494 // Inlined method threw an exception, so it's just the slow path after all.
duke@435 495 kit.set_jvms(slow_jvms);
duke@435 496 return kit.transfer_exceptions_into_jvms();
duke@435 497 }
duke@435 498
duke@435 499 // Finish the diamond.
duke@435 500 kit.C->set_has_split_ifs(true); // Has chance for split-if optimization
duke@435 501 RegionNode* region = new (kit.C, 3) RegionNode(3);
duke@435 502 region->init_req(1, kit.control());
duke@435 503 region->init_req(2, slow_map->control());
duke@435 504 kit.set_control(gvn.transform(region));
duke@435 505 Node* iophi = PhiNode::make(region, kit.i_o(), Type::ABIO);
duke@435 506 iophi->set_req(2, slow_map->i_o());
duke@435 507 kit.set_i_o(gvn.transform(iophi));
duke@435 508 kit.merge_memory(slow_map->merged_memory(), region, 2);
duke@435 509 uint tos = kit.jvms()->stkoff() + kit.sp();
duke@435 510 uint limit = slow_map->req();
duke@435 511 for (uint i = TypeFunc::Parms; i < limit; i++) {
duke@435 512 // Skip unused stack slots; fast forward to monoff();
duke@435 513 if (i == tos) {
duke@435 514 i = kit.jvms()->monoff();
duke@435 515 if( i >= limit ) break;
duke@435 516 }
duke@435 517 Node* m = kit.map()->in(i);
duke@435 518 Node* n = slow_map->in(i);
duke@435 519 if (m != n) {
duke@435 520 const Type* t = gvn.type(m)->meet(gvn.type(n));
duke@435 521 Node* phi = PhiNode::make(region, m, t);
duke@435 522 phi->set_req(2, n);
duke@435 523 kit.map()->set_req(i, gvn.transform(phi));
duke@435 524 }
duke@435 525 }
duke@435 526 return kit.transfer_exceptions_into_jvms();
duke@435 527 }
duke@435 528
duke@435 529
duke@435 530 //-------------------------UncommonTrapCallGenerator-----------------------------
duke@435 531 // Internal class which handles all out-of-line calls checking receiver type.
duke@435 532 class UncommonTrapCallGenerator : public CallGenerator {
duke@435 533 Deoptimization::DeoptReason _reason;
duke@435 534 Deoptimization::DeoptAction _action;
duke@435 535
duke@435 536 public:
duke@435 537 UncommonTrapCallGenerator(ciMethod* m,
duke@435 538 Deoptimization::DeoptReason reason,
duke@435 539 Deoptimization::DeoptAction action)
duke@435 540 : CallGenerator(m)
duke@435 541 {
duke@435 542 _reason = reason;
duke@435 543 _action = action;
duke@435 544 }
duke@435 545
duke@435 546 virtual bool is_virtual() const { ShouldNotReachHere(); return false; }
duke@435 547 virtual bool is_trap() const { return true; }
duke@435 548
duke@435 549 virtual JVMState* generate(JVMState* jvms);
duke@435 550 };
duke@435 551
duke@435 552
duke@435 553 CallGenerator*
duke@435 554 CallGenerator::for_uncommon_trap(ciMethod* m,
duke@435 555 Deoptimization::DeoptReason reason,
duke@435 556 Deoptimization::DeoptAction action) {
duke@435 557 return new UncommonTrapCallGenerator(m, reason, action);
duke@435 558 }
duke@435 559
duke@435 560
duke@435 561 JVMState* UncommonTrapCallGenerator::generate(JVMState* jvms) {
duke@435 562 GraphKit kit(jvms);
duke@435 563 // Take the trap with arguments pushed on the stack. (Cf. null_check_receiver).
duke@435 564 int nargs = method()->arg_size();
duke@435 565 kit.inc_sp(nargs);
duke@435 566 assert(nargs <= kit.sp() && kit.sp() <= jvms->stk_size(), "sane sp w/ args pushed");
duke@435 567 if (_reason == Deoptimization::Reason_class_check &&
duke@435 568 _action == Deoptimization::Action_maybe_recompile) {
duke@435 569 // Temp fix for 6529811
duke@435 570 // Don't allow uncommon_trap to override our decision to recompile in the event
duke@435 571 // of a class cast failure for a monomorphic call as it will never let us convert
duke@435 572 // the call to either bi-morphic or megamorphic and can lead to unc-trap loops
duke@435 573 bool keep_exact_action = true;
duke@435 574 kit.uncommon_trap(_reason, _action, NULL, "monomorphic vcall checkcast", false, keep_exact_action);
duke@435 575 } else {
duke@435 576 kit.uncommon_trap(_reason, _action);
duke@435 577 }
duke@435 578 return kit.transfer_exceptions_into_jvms();
duke@435 579 }
duke@435 580
duke@435 581 // (Note: Moved hook_up_call to GraphKit::set_edges_for_java_call.)
duke@435 582
duke@435 583 // (Node: Merged hook_up_exits into ParseGenerator::generate.)
duke@435 584
duke@435 585 #define NODES_OVERHEAD_PER_METHOD (30.0)
duke@435 586 #define NODES_PER_BYTECODE (9.5)
duke@435 587
duke@435 588 void WarmCallInfo::init(JVMState* call_site, ciMethod* call_method, ciCallProfile& profile, float prof_factor) {
duke@435 589 int call_count = profile.count();
duke@435 590 int code_size = call_method->code_size();
duke@435 591
duke@435 592 // Expected execution count is based on the historical count:
duke@435 593 _count = call_count < 0 ? 1 : call_site->method()->scale_count(call_count, prof_factor);
duke@435 594
duke@435 595 // Expected profit from inlining, in units of simple call-overheads.
duke@435 596 _profit = 1.0;
duke@435 597
duke@435 598 // Expected work performed by the call in units of call-overheads.
duke@435 599 // %%% need an empirical curve fit for "work" (time in call)
duke@435 600 float bytecodes_per_call = 3;
duke@435 601 _work = 1.0 + code_size / bytecodes_per_call;
duke@435 602
duke@435 603 // Expected size of compilation graph:
duke@435 604 // -XX:+PrintParseStatistics once reported:
duke@435 605 // Methods seen: 9184 Methods parsed: 9184 Nodes created: 1582391
duke@435 606 // Histogram of 144298 parsed bytecodes:
duke@435 607 // %%% Need an better predictor for graph size.
duke@435 608 _size = NODES_OVERHEAD_PER_METHOD + (NODES_PER_BYTECODE * code_size);
duke@435 609 }
duke@435 610
duke@435 611 // is_cold: Return true if the node should never be inlined.
duke@435 612 // This is true if any of the key metrics are extreme.
duke@435 613 bool WarmCallInfo::is_cold() const {
duke@435 614 if (count() < WarmCallMinCount) return true;
duke@435 615 if (profit() < WarmCallMinProfit) return true;
duke@435 616 if (work() > WarmCallMaxWork) return true;
duke@435 617 if (size() > WarmCallMaxSize) return true;
duke@435 618 return false;
duke@435 619 }
duke@435 620
duke@435 621 // is_hot: Return true if the node should be inlined immediately.
duke@435 622 // This is true if any of the key metrics are extreme.
duke@435 623 bool WarmCallInfo::is_hot() const {
duke@435 624 assert(!is_cold(), "eliminate is_cold cases before testing is_hot");
duke@435 625 if (count() >= HotCallCountThreshold) return true;
duke@435 626 if (profit() >= HotCallProfitThreshold) return true;
duke@435 627 if (work() <= HotCallTrivialWork) return true;
duke@435 628 if (size() <= HotCallTrivialSize) return true;
duke@435 629 return false;
duke@435 630 }
duke@435 631
duke@435 632 // compute_heat:
duke@435 633 float WarmCallInfo::compute_heat() const {
duke@435 634 assert(!is_cold(), "compute heat only on warm nodes");
duke@435 635 assert(!is_hot(), "compute heat only on warm nodes");
duke@435 636 int min_size = MAX2(0, (int)HotCallTrivialSize);
duke@435 637 int max_size = MIN2(500, (int)WarmCallMaxSize);
duke@435 638 float method_size = (size() - min_size) / MAX2(1, max_size - min_size);
duke@435 639 float size_factor;
duke@435 640 if (method_size < 0.05) size_factor = 4; // 2 sigmas better than avg.
duke@435 641 else if (method_size < 0.15) size_factor = 2; // 1 sigma better than avg.
duke@435 642 else if (method_size < 0.5) size_factor = 1; // better than avg.
duke@435 643 else size_factor = 0.5; // worse than avg.
duke@435 644 return (count() * profit() * size_factor);
duke@435 645 }
duke@435 646
duke@435 647 bool WarmCallInfo::warmer_than(WarmCallInfo* that) {
duke@435 648 assert(this != that, "compare only different WCIs");
duke@435 649 assert(this->heat() != 0 && that->heat() != 0, "call compute_heat 1st");
duke@435 650 if (this->heat() > that->heat()) return true;
duke@435 651 if (this->heat() < that->heat()) return false;
duke@435 652 assert(this->heat() == that->heat(), "no NaN heat allowed");
duke@435 653 // Equal heat. Break the tie some other way.
duke@435 654 if (!this->call() || !that->call()) return (address)this > (address)that;
duke@435 655 return this->call()->_idx > that->call()->_idx;
duke@435 656 }
duke@435 657
duke@435 658 //#define UNINIT_NEXT ((WarmCallInfo*)badAddress)
duke@435 659 #define UNINIT_NEXT ((WarmCallInfo*)NULL)
duke@435 660
duke@435 661 WarmCallInfo* WarmCallInfo::insert_into(WarmCallInfo* head) {
duke@435 662 assert(next() == UNINIT_NEXT, "not yet on any list");
duke@435 663 WarmCallInfo* prev_p = NULL;
duke@435 664 WarmCallInfo* next_p = head;
duke@435 665 while (next_p != NULL && next_p->warmer_than(this)) {
duke@435 666 prev_p = next_p;
duke@435 667 next_p = prev_p->next();
duke@435 668 }
duke@435 669 // Install this between prev_p and next_p.
duke@435 670 this->set_next(next_p);
duke@435 671 if (prev_p == NULL)
duke@435 672 head = this;
duke@435 673 else
duke@435 674 prev_p->set_next(this);
duke@435 675 return head;
duke@435 676 }
duke@435 677
duke@435 678 WarmCallInfo* WarmCallInfo::remove_from(WarmCallInfo* head) {
duke@435 679 WarmCallInfo* prev_p = NULL;
duke@435 680 WarmCallInfo* next_p = head;
duke@435 681 while (next_p != this) {
duke@435 682 assert(next_p != NULL, "this must be in the list somewhere");
duke@435 683 prev_p = next_p;
duke@435 684 next_p = prev_p->next();
duke@435 685 }
duke@435 686 next_p = this->next();
duke@435 687 debug_only(this->set_next(UNINIT_NEXT));
duke@435 688 // Remove this from between prev_p and next_p.
duke@435 689 if (prev_p == NULL)
duke@435 690 head = next_p;
duke@435 691 else
duke@435 692 prev_p->set_next(next_p);
duke@435 693 return head;
duke@435 694 }
duke@435 695
duke@435 696 WarmCallInfo* WarmCallInfo::_always_hot = NULL;
duke@435 697 WarmCallInfo* WarmCallInfo::_always_cold = NULL;
duke@435 698
duke@435 699 WarmCallInfo* WarmCallInfo::always_hot() {
duke@435 700 if (_always_hot == NULL) {
duke@435 701 static double bits[sizeof(WarmCallInfo) / sizeof(double) + 1] = {0};
duke@435 702 WarmCallInfo* ci = (WarmCallInfo*) bits;
duke@435 703 ci->_profit = ci->_count = MAX_VALUE();
duke@435 704 ci->_work = ci->_size = MIN_VALUE();
duke@435 705 _always_hot = ci;
duke@435 706 }
duke@435 707 assert(_always_hot->is_hot(), "must always be hot");
duke@435 708 return _always_hot;
duke@435 709 }
duke@435 710
duke@435 711 WarmCallInfo* WarmCallInfo::always_cold() {
duke@435 712 if (_always_cold == NULL) {
duke@435 713 static double bits[sizeof(WarmCallInfo) / sizeof(double) + 1] = {0};
duke@435 714 WarmCallInfo* ci = (WarmCallInfo*) bits;
duke@435 715 ci->_profit = ci->_count = MIN_VALUE();
duke@435 716 ci->_work = ci->_size = MAX_VALUE();
duke@435 717 _always_cold = ci;
duke@435 718 }
duke@435 719 assert(_always_cold->is_cold(), "must always be cold");
duke@435 720 return _always_cold;
duke@435 721 }
duke@435 722
duke@435 723
duke@435 724 #ifndef PRODUCT
duke@435 725
duke@435 726 void WarmCallInfo::print() const {
duke@435 727 tty->print("%s : C=%6.1f P=%6.1f W=%6.1f S=%6.1f H=%6.1f -> %p",
duke@435 728 is_cold() ? "cold" : is_hot() ? "hot " : "warm",
duke@435 729 count(), profit(), work(), size(), compute_heat(), next());
duke@435 730 tty->cr();
duke@435 731 if (call() != NULL) call()->dump();
duke@435 732 }
duke@435 733
duke@435 734 void print_wci(WarmCallInfo* ci) {
duke@435 735 ci->print();
duke@435 736 }
duke@435 737
duke@435 738 void WarmCallInfo::print_all() const {
duke@435 739 for (const WarmCallInfo* p = this; p != NULL; p = p->next())
duke@435 740 p->print();
duke@435 741 }
duke@435 742
duke@435 743 int WarmCallInfo::count_all() const {
duke@435 744 int cnt = 0;
duke@435 745 for (const WarmCallInfo* p = this; p != NULL; p = p->next())
duke@435 746 cnt++;
duke@435 747 return cnt;
duke@435 748 }
duke@435 749
duke@435 750 #endif //PRODUCT

mercurial