src/share/vm/opto/callGenerator.cpp

Thu, 24 May 2018 19:26:50 +0800

author
aoqi
date
Thu, 24 May 2018 19:26:50 +0800
changeset 8862
fd13a567f179
parent 8856
ac27a9c85bea
permissions
-rw-r--r--

#7046 C2 supports long branch
Contributed-by: fujie

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #include "precompiled.hpp"
aoqi@0 26 #include "ci/bcEscapeAnalyzer.hpp"
aoqi@0 27 #include "ci/ciCallSite.hpp"
aoqi@0 28 #include "ci/ciObjArray.hpp"
aoqi@0 29 #include "ci/ciMemberName.hpp"
aoqi@0 30 #include "ci/ciMethodHandle.hpp"
aoqi@0 31 #include "classfile/javaClasses.hpp"
aoqi@0 32 #include "compiler/compileLog.hpp"
aoqi@0 33 #include "opto/addnode.hpp"
aoqi@0 34 #include "opto/callGenerator.hpp"
aoqi@0 35 #include "opto/callnode.hpp"
aoqi@0 36 #include "opto/cfgnode.hpp"
aoqi@0 37 #include "opto/connode.hpp"
aoqi@0 38 #include "opto/parse.hpp"
aoqi@0 39 #include "opto/rootnode.hpp"
aoqi@0 40 #include "opto/runtime.hpp"
aoqi@0 41 #include "opto/subnode.hpp"
aoqi@0 42
aoqi@0 43
aoqi@0 44 // Utility function.
aoqi@0 45 const TypeFunc* CallGenerator::tf() const {
aoqi@0 46 return TypeFunc::make(method());
aoqi@0 47 }
aoqi@0 48
aoqi@0 49 //-----------------------------ParseGenerator---------------------------------
aoqi@0 50 // Internal class which handles all direct bytecode traversal.
aoqi@0 51 class ParseGenerator : public InlineCallGenerator {
aoqi@0 52 private:
aoqi@0 53 bool _is_osr;
aoqi@0 54 float _expected_uses;
aoqi@0 55
aoqi@0 56 public:
aoqi@0 57 ParseGenerator(ciMethod* method, float expected_uses, bool is_osr = false)
aoqi@0 58 : InlineCallGenerator(method)
aoqi@0 59 {
aoqi@0 60 _is_osr = is_osr;
aoqi@0 61 _expected_uses = expected_uses;
aoqi@0 62 assert(InlineTree::check_can_parse(method) == NULL, "parse must be possible");
aoqi@0 63 }
aoqi@0 64
aoqi@0 65 virtual bool is_parse() const { return true; }
roland@7041 66 virtual JVMState* generate(JVMState* jvms);
aoqi@0 67 int is_osr() { return _is_osr; }
aoqi@0 68
aoqi@0 69 };
aoqi@0 70
roland@7041 71 JVMState* ParseGenerator::generate(JVMState* jvms) {
aoqi@0 72 Compile* C = Compile::current();
aoqi@0 73
aoqi@0 74 if (is_osr()) {
aoqi@0 75 // The JVMS for a OSR has a single argument (see its TypeFunc).
aoqi@0 76 assert(jvms->depth() == 1, "no inline OSR");
aoqi@0 77 }
aoqi@0 78
aoqi@0 79 if (C->failing()) {
aoqi@0 80 return NULL; // bailing out of the compile; do not try to parse
aoqi@0 81 }
aoqi@0 82
roland@7041 83 Parse parser(jvms, method(), _expected_uses);
aoqi@0 84 // Grab signature for matching/allocation
aoqi@0 85 #ifdef ASSERT
aoqi@0 86 if (parser.tf() != (parser.depth() == 1 ? C->tf() : tf())) {
aoqi@0 87 MutexLockerEx ml(Compile_lock, Mutex::_no_safepoint_check_flag);
aoqi@0 88 assert(C->env()->system_dictionary_modification_counter_changed(),
aoqi@0 89 "Must invalidate if TypeFuncs differ");
aoqi@0 90 }
aoqi@0 91 #endif
aoqi@0 92
aoqi@0 93 GraphKit& exits = parser.exits();
aoqi@0 94
aoqi@0 95 if (C->failing()) {
aoqi@0 96 while (exits.pop_exception_state() != NULL) ;
aoqi@0 97 return NULL;
aoqi@0 98 }
aoqi@0 99
aoqi@0 100 assert(exits.jvms()->same_calls_as(jvms), "sanity");
aoqi@0 101
aoqi@0 102 // Simply return the exit state of the parser,
aoqi@0 103 // augmented by any exceptional states.
aoqi@0 104 return exits.transfer_exceptions_into_jvms();
aoqi@0 105 }
aoqi@0 106
aoqi@0 107 //---------------------------DirectCallGenerator------------------------------
aoqi@0 108 // Internal class which handles all out-of-line calls w/o receiver type checks.
aoqi@0 109 class DirectCallGenerator : public CallGenerator {
aoqi@0 110 private:
aoqi@0 111 CallStaticJavaNode* _call_node;
aoqi@0 112 // Force separate memory and I/O projections for the exceptional
aoqi@0 113 // paths to facilitate late inlinig.
aoqi@0 114 bool _separate_io_proj;
aoqi@0 115
aoqi@0 116 public:
aoqi@0 117 DirectCallGenerator(ciMethod* method, bool separate_io_proj)
aoqi@0 118 : CallGenerator(method),
aoqi@0 119 _separate_io_proj(separate_io_proj)
aoqi@0 120 {
aoqi@0 121 }
roland@7041 122 virtual JVMState* generate(JVMState* jvms);
aoqi@0 123
aoqi@0 124 CallStaticJavaNode* call_node() const { return _call_node; }
aoqi@0 125 };
aoqi@0 126
roland@7041 127 JVMState* DirectCallGenerator::generate(JVMState* jvms) {
aoqi@0 128 GraphKit kit(jvms);
aoqi@0 129 bool is_static = method()->is_static();
aoqi@0 130 address target = is_static ? SharedRuntime::get_resolve_static_call_stub()
aoqi@0 131 : SharedRuntime::get_resolve_opt_virtual_call_stub();
aoqi@0 132
aoqi@0 133 if (kit.C->log() != NULL) {
aoqi@0 134 kit.C->log()->elem("direct_call bci='%d'", jvms->bci());
aoqi@0 135 }
aoqi@0 136
aoqi@0 137 CallStaticJavaNode *call = new (kit.C) CallStaticJavaNode(kit.C, tf(), target, method(), kit.bci());
aoqi@0 138 _call_node = call; // Save the call node in case we need it later
aoqi@0 139 if (!is_static) {
aoqi@0 140 // Make an explicit receiver null_check as part of this call.
aoqi@0 141 // Since we share a map with the caller, his JVMS gets adjusted.
aoqi@0 142 kit.null_check_receiver_before_call(method());
aoqi@0 143 if (kit.stopped()) {
aoqi@0 144 // And dump it back to the caller, decorated with any exceptions:
aoqi@0 145 return kit.transfer_exceptions_into_jvms();
aoqi@0 146 }
aoqi@0 147 // Mark the call node as virtual, sort of:
aoqi@0 148 call->set_optimized_virtual(true);
aoqi@0 149 if (method()->is_method_handle_intrinsic() ||
aoqi@0 150 method()->is_compiled_lambda_form()) {
aoqi@0 151 call->set_method_handle_invoke(true);
aoqi@0 152 }
aoqi@0 153 }
aoqi@0 154 kit.set_arguments_for_java_call(call);
aoqi@0 155 kit.set_edges_for_java_call(call, false, _separate_io_proj);
aoqi@0 156 Node* ret = kit.set_results_for_java_call(call, _separate_io_proj);
aoqi@0 157 kit.push_node(method()->return_type()->basic_type(), ret);
aoqi@0 158 return kit.transfer_exceptions_into_jvms();
aoqi@0 159 }
aoqi@0 160
aoqi@0 161 //--------------------------VirtualCallGenerator------------------------------
aoqi@0 162 // Internal class which handles all out-of-line calls checking receiver type.
aoqi@0 163 class VirtualCallGenerator : public CallGenerator {
aoqi@0 164 private:
aoqi@0 165 int _vtable_index;
aoqi@0 166 public:
aoqi@0 167 VirtualCallGenerator(ciMethod* method, int vtable_index)
aoqi@0 168 : CallGenerator(method), _vtable_index(vtable_index)
aoqi@0 169 {
aoqi@0 170 assert(vtable_index == Method::invalid_vtable_index ||
aoqi@0 171 vtable_index >= 0, "either invalid or usable");
aoqi@0 172 }
aoqi@0 173 virtual bool is_virtual() const { return true; }
roland@7041 174 virtual JVMState* generate(JVMState* jvms);
aoqi@0 175 };
aoqi@0 176
roland@7041 177 JVMState* VirtualCallGenerator::generate(JVMState* jvms) {
aoqi@0 178 GraphKit kit(jvms);
aoqi@0 179 Node* receiver = kit.argument(0);
aoqi@0 180
aoqi@0 181 if (kit.C->log() != NULL) {
aoqi@0 182 kit.C->log()->elem("virtual_call bci='%d'", jvms->bci());
aoqi@0 183 }
aoqi@0 184
aoqi@0 185 // If the receiver is a constant null, do not torture the system
aoqi@0 186 // by attempting to call through it. The compile will proceed
aoqi@0 187 // correctly, but may bail out in final_graph_reshaping, because
aoqi@0 188 // the call instruction will have a seemingly deficient out-count.
aoqi@0 189 // (The bailout says something misleading about an "infinite loop".)
aoqi@0 190 if (kit.gvn().type(receiver)->higher_equal(TypePtr::NULL_PTR)) {
dbuck@8651 191 assert(Bytecodes::is_invoke(kit.java_bc()), err_msg("%d: %s", kit.java_bc(), Bytecodes::name(kit.java_bc())));
dbuck@8651 192 ciMethod* declared_method = kit.method()->get_method_at_bci(kit.bci());
dbuck@8651 193 int arg_size = declared_method->signature()->arg_size_for_bc(kit.java_bc());
dbuck@8651 194 kit.inc_sp(arg_size); // restore arguments
aoqi@0 195 kit.uncommon_trap(Deoptimization::Reason_null_check,
aoqi@0 196 Deoptimization::Action_none,
aoqi@0 197 NULL, "null receiver");
aoqi@0 198 return kit.transfer_exceptions_into_jvms();
aoqi@0 199 }
aoqi@0 200
aoqi@0 201 // Ideally we would unconditionally do a null check here and let it
aoqi@0 202 // be converted to an implicit check based on profile information.
aoqi@0 203 // However currently the conversion to implicit null checks in
aoqi@0 204 // Block::implicit_null_check() only looks for loads and stores, not calls.
aoqi@0 205 ciMethod *caller = kit.method();
aoqi@0 206 ciMethodData *caller_md = (caller == NULL) ? NULL : caller->method_data();
aoqi@0 207 if (!UseInlineCaches || !ImplicitNullChecks || !os::zero_page_read_protected() ||
aoqi@0 208 ((ImplicitNullCheckThreshold > 0) && caller_md &&
aoqi@0 209 (caller_md->trap_count(Deoptimization::Reason_null_check)
aoqi@0 210 >= (uint)ImplicitNullCheckThreshold))) {
aoqi@0 211 // Make an explicit receiver null_check as part of this call.
aoqi@0 212 // Since we share a map with the caller, his JVMS gets adjusted.
aoqi@0 213 receiver = kit.null_check_receiver_before_call(method());
aoqi@0 214 if (kit.stopped()) {
aoqi@0 215 // And dump it back to the caller, decorated with any exceptions:
aoqi@0 216 return kit.transfer_exceptions_into_jvms();
aoqi@0 217 }
aoqi@0 218 }
aoqi@0 219
aoqi@0 220 assert(!method()->is_static(), "virtual call must not be to static");
aoqi@0 221 assert(!method()->is_final(), "virtual call should not be to final");
aoqi@0 222 assert(!method()->is_private(), "virtual call should not be to private");
aoqi@0 223 assert(_vtable_index == Method::invalid_vtable_index || !UseInlineCaches,
aoqi@0 224 "no vtable calls if +UseInlineCaches ");
aoqi@0 225 address target = SharedRuntime::get_resolve_virtual_call_stub();
aoqi@0 226 // Normal inline cache used for call
aoqi@0 227 CallDynamicJavaNode *call = new (kit.C) CallDynamicJavaNode(tf(), target, method(), _vtable_index, kit.bci());
aoqi@0 228 kit.set_arguments_for_java_call(call);
aoqi@0 229 kit.set_edges_for_java_call(call);
aoqi@0 230 Node* ret = kit.set_results_for_java_call(call);
aoqi@0 231 kit.push_node(method()->return_type()->basic_type(), ret);
aoqi@0 232
aoqi@0 233 // Represent the effect of an implicit receiver null_check
aoqi@0 234 // as part of this call. Since we share a map with the caller,
aoqi@0 235 // his JVMS gets adjusted.
aoqi@0 236 kit.cast_not_null(receiver);
aoqi@0 237 return kit.transfer_exceptions_into_jvms();
aoqi@0 238 }
aoqi@0 239
aoqi@0 240 CallGenerator* CallGenerator::for_inline(ciMethod* m, float expected_uses) {
aoqi@0 241 if (InlineTree::check_can_parse(m) != NULL) return NULL;
aoqi@0 242 return new ParseGenerator(m, expected_uses);
aoqi@0 243 }
aoqi@0 244
aoqi@0 245 // As a special case, the JVMS passed to this CallGenerator is
aoqi@0 246 // for the method execution already in progress, not just the JVMS
aoqi@0 247 // of the caller. Thus, this CallGenerator cannot be mixed with others!
aoqi@0 248 CallGenerator* CallGenerator::for_osr(ciMethod* m, int osr_bci) {
aoqi@0 249 if (InlineTree::check_can_parse(m) != NULL) return NULL;
aoqi@0 250 float past_uses = m->interpreter_invocation_count();
aoqi@0 251 float expected_uses = past_uses;
aoqi@0 252 return new ParseGenerator(m, expected_uses, true);
aoqi@0 253 }
aoqi@0 254
aoqi@0 255 CallGenerator* CallGenerator::for_direct_call(ciMethod* m, bool separate_io_proj) {
aoqi@0 256 assert(!m->is_abstract(), "for_direct_call mismatch");
aoqi@0 257 return new DirectCallGenerator(m, separate_io_proj);
aoqi@0 258 }
aoqi@0 259
aoqi@0 260 CallGenerator* CallGenerator::for_virtual_call(ciMethod* m, int vtable_index) {
aoqi@0 261 assert(!m->is_static(), "for_virtual_call mismatch");
aoqi@0 262 assert(!m->is_method_handle_intrinsic(), "should be a direct call");
aoqi@0 263 return new VirtualCallGenerator(m, vtable_index);
aoqi@0 264 }
aoqi@0 265
aoqi@0 266 // Allow inlining decisions to be delayed
aoqi@0 267 class LateInlineCallGenerator : public DirectCallGenerator {
aoqi@0 268 protected:
aoqi@0 269 CallGenerator* _inline_cg;
aoqi@0 270
aoqi@0 271 virtual bool do_late_inline_check(JVMState* jvms) { return true; }
aoqi@0 272
aoqi@0 273 public:
aoqi@0 274 LateInlineCallGenerator(ciMethod* method, CallGenerator* inline_cg) :
aoqi@0 275 DirectCallGenerator(method, true), _inline_cg(inline_cg) {}
aoqi@0 276
aoqi@0 277 virtual bool is_late_inline() const { return true; }
aoqi@0 278
aoqi@0 279 // Convert the CallStaticJava into an inline
aoqi@0 280 virtual void do_late_inline();
aoqi@0 281
roland@7041 282 virtual JVMState* generate(JVMState* jvms) {
aoqi@0 283 Compile *C = Compile::current();
aoqi@0 284 C->print_inlining_skip(this);
aoqi@0 285
aoqi@0 286 // Record that this call site should be revisited once the main
aoqi@0 287 // parse is finished.
aoqi@0 288 if (!is_mh_late_inline()) {
aoqi@0 289 C->add_late_inline(this);
aoqi@0 290 }
aoqi@0 291
aoqi@0 292 // Emit the CallStaticJava and request separate projections so
aoqi@0 293 // that the late inlining logic can distinguish between fall
aoqi@0 294 // through and exceptional uses of the memory and io projections
aoqi@0 295 // as is done for allocations and macro expansion.
roland@7041 296 return DirectCallGenerator::generate(jvms);
aoqi@0 297 }
aoqi@0 298
aoqi@0 299 virtual void print_inlining_late(const char* msg) {
aoqi@0 300 CallNode* call = call_node();
aoqi@0 301 Compile* C = Compile::current();
aoqi@0 302 C->print_inlining_insert(this);
aoqi@0 303 C->print_inlining(method(), call->jvms()->depth()-1, call->jvms()->bci(), msg);
aoqi@0 304 }
aoqi@0 305
aoqi@0 306 };
aoqi@0 307
aoqi@0 308 void LateInlineCallGenerator::do_late_inline() {
aoqi@0 309 // Can't inline it
aoqi@0 310 CallStaticJavaNode* call = call_node();
aoqi@0 311 if (call == NULL || call->outcnt() == 0 ||
aoqi@0 312 call->in(0) == NULL || call->in(0)->is_top()) {
aoqi@0 313 return;
aoqi@0 314 }
aoqi@0 315
aoqi@0 316 const TypeTuple *r = call->tf()->domain();
aoqi@0 317 for (int i1 = 0; i1 < method()->arg_size(); i1++) {
aoqi@0 318 if (call->in(TypeFunc::Parms + i1)->is_top() && r->field_at(TypeFunc::Parms + i1) != Type::HALF) {
aoqi@0 319 assert(Compile::current()->inlining_incrementally(), "shouldn't happen during parsing");
aoqi@0 320 return;
aoqi@0 321 }
aoqi@0 322 }
aoqi@0 323
aoqi@0 324 if (call->in(TypeFunc::Memory)->is_top()) {
aoqi@0 325 assert(Compile::current()->inlining_incrementally(), "shouldn't happen during parsing");
aoqi@0 326 return;
aoqi@0 327 }
aoqi@0 328
aoqi@0 329 Compile* C = Compile::current();
aoqi@0 330 // Remove inlined methods from Compiler's lists.
aoqi@0 331 if (call->is_macro()) {
aoqi@0 332 C->remove_macro_node(call);
aoqi@0 333 }
aoqi@0 334
aoqi@0 335 // Make a clone of the JVMState that appropriate to use for driving a parse
aoqi@0 336 JVMState* old_jvms = call->jvms();
aoqi@0 337 JVMState* jvms = old_jvms->clone_shallow(C);
aoqi@0 338 uint size = call->req();
aoqi@0 339 SafePointNode* map = new (C) SafePointNode(size, jvms);
aoqi@0 340 for (uint i1 = 0; i1 < size; i1++) {
aoqi@0 341 map->init_req(i1, call->in(i1));
aoqi@0 342 }
aoqi@0 343
aoqi@0 344 // Make sure the state is a MergeMem for parsing.
aoqi@0 345 if (!map->in(TypeFunc::Memory)->is_MergeMem()) {
aoqi@0 346 Node* mem = MergeMemNode::make(C, map->in(TypeFunc::Memory));
aoqi@0 347 C->initial_gvn()->set_type_bottom(mem);
aoqi@0 348 map->set_req(TypeFunc::Memory, mem);
aoqi@0 349 }
aoqi@0 350
aoqi@0 351 uint nargs = method()->arg_size();
aoqi@0 352 // blow away old call arguments
aoqi@0 353 Node* top = C->top();
aoqi@0 354 for (uint i1 = 0; i1 < nargs; i1++) {
aoqi@0 355 map->set_req(TypeFunc::Parms + i1, top);
aoqi@0 356 }
aoqi@0 357 jvms->set_map(map);
aoqi@0 358
aoqi@0 359 // Make enough space in the expression stack to transfer
aoqi@0 360 // the incoming arguments and return value.
aoqi@0 361 map->ensure_stack(jvms, jvms->method()->max_stack());
aoqi@0 362 for (uint i1 = 0; i1 < nargs; i1++) {
aoqi@0 363 map->set_argument(jvms, i1, call->in(TypeFunc::Parms + i1));
aoqi@0 364 }
aoqi@0 365
aoqi@0 366 // This check is done here because for_method_handle_inline() method
aoqi@0 367 // needs jvms for inlined state.
aoqi@0 368 if (!do_late_inline_check(jvms)) {
aoqi@0 369 map->disconnect_inputs(NULL, C);
aoqi@0 370 return;
aoqi@0 371 }
aoqi@0 372
aoqi@0 373 C->print_inlining_insert(this);
aoqi@0 374
aoqi@0 375 CompileLog* log = C->log();
aoqi@0 376 if (log != NULL) {
aoqi@0 377 log->head("late_inline method='%d'", log->identify(method()));
aoqi@0 378 JVMState* p = jvms;
aoqi@0 379 while (p != NULL) {
aoqi@0 380 log->elem("jvms bci='%d' method='%d'", p->bci(), log->identify(p->method()));
aoqi@0 381 p = p->caller();
aoqi@0 382 }
aoqi@0 383 log->tail("late_inline");
aoqi@0 384 }
aoqi@0 385
aoqi@0 386 // Setup default node notes to be picked up by the inlining
aoqi@0 387 Node_Notes* old_nn = C->node_notes_at(call->_idx);
aoqi@0 388 if (old_nn != NULL) {
aoqi@0 389 Node_Notes* entry_nn = old_nn->clone(C);
aoqi@0 390 entry_nn->set_jvms(jvms);
aoqi@0 391 C->set_default_node_notes(entry_nn);
aoqi@0 392 }
aoqi@0 393
aoqi@0 394 // Now perform the inling using the synthesized JVMState
roland@7041 395 JVMState* new_jvms = _inline_cg->generate(jvms);
aoqi@0 396 if (new_jvms == NULL) return; // no change
aoqi@0 397 if (C->failing()) return;
aoqi@0 398
aoqi@0 399 // Capture any exceptional control flow
aoqi@0 400 GraphKit kit(new_jvms);
aoqi@0 401
aoqi@0 402 // Find the result object
aoqi@0 403 Node* result = C->top();
aoqi@0 404 int result_size = method()->return_type()->size();
aoqi@0 405 if (result_size != 0 && !kit.stopped()) {
aoqi@0 406 result = (result_size == 1) ? kit.pop() : kit.pop_pair();
aoqi@0 407 }
aoqi@0 408
aoqi@0 409 C->set_has_loops(C->has_loops() || _inline_cg->method()->has_loops());
aoqi@0 410 C->env()->notice_inlined_method(_inline_cg->method());
aoqi@0 411 C->set_inlining_progress(true);
aoqi@0 412
roland@7041 413 kit.replace_call(call, result, true);
aoqi@0 414 }
aoqi@0 415
aoqi@0 416
aoqi@0 417 CallGenerator* CallGenerator::for_late_inline(ciMethod* method, CallGenerator* inline_cg) {
aoqi@0 418 return new LateInlineCallGenerator(method, inline_cg);
aoqi@0 419 }
aoqi@0 420
aoqi@0 421 class LateInlineMHCallGenerator : public LateInlineCallGenerator {
aoqi@0 422 ciMethod* _caller;
aoqi@0 423 int _attempt;
aoqi@0 424 bool _input_not_const;
aoqi@0 425
aoqi@0 426 virtual bool do_late_inline_check(JVMState* jvms);
aoqi@0 427 virtual bool already_attempted() const { return _attempt > 0; }
aoqi@0 428
aoqi@0 429 public:
aoqi@0 430 LateInlineMHCallGenerator(ciMethod* caller, ciMethod* callee, bool input_not_const) :
aoqi@0 431 LateInlineCallGenerator(callee, NULL), _caller(caller), _attempt(0), _input_not_const(input_not_const) {}
aoqi@0 432
aoqi@0 433 virtual bool is_mh_late_inline() const { return true; }
aoqi@0 434
roland@7041 435 virtual JVMState* generate(JVMState* jvms) {
roland@7041 436 JVMState* new_jvms = LateInlineCallGenerator::generate(jvms);
aoqi@0 437 if (_input_not_const) {
aoqi@0 438 // inlining won't be possible so no need to enqueue right now.
aoqi@0 439 call_node()->set_generator(this);
aoqi@0 440 } else {
aoqi@0 441 Compile::current()->add_late_inline(this);
aoqi@0 442 }
aoqi@0 443 return new_jvms;
aoqi@0 444 }
aoqi@0 445
aoqi@0 446 virtual void print_inlining_late(const char* msg) {
aoqi@0 447 if (!_input_not_const) return;
aoqi@0 448 LateInlineCallGenerator::print_inlining_late(msg);
aoqi@0 449 }
aoqi@0 450 };
aoqi@0 451
aoqi@0 452 bool LateInlineMHCallGenerator::do_late_inline_check(JVMState* jvms) {
aoqi@0 453
aoqi@0 454 CallGenerator* cg = for_method_handle_inline(jvms, _caller, method(), _input_not_const);
aoqi@0 455
aoqi@0 456 if (!_input_not_const) {
aoqi@0 457 _attempt++;
aoqi@0 458 }
aoqi@0 459
aoqi@0 460 if (cg != NULL) {
aoqi@0 461 assert(!cg->is_late_inline() && cg->is_inline(), "we're doing late inlining");
aoqi@0 462 _inline_cg = cg;
aoqi@0 463 Compile::current()->dec_number_of_mh_late_inlines();
aoqi@0 464 return true;
aoqi@0 465 }
aoqi@0 466
aoqi@0 467 call_node()->set_generator(this);
aoqi@0 468 return false;
aoqi@0 469 }
aoqi@0 470
aoqi@0 471 CallGenerator* CallGenerator::for_mh_late_inline(ciMethod* caller, ciMethod* callee, bool input_not_const) {
aoqi@0 472 Compile::current()->inc_number_of_mh_late_inlines();
aoqi@0 473 CallGenerator* cg = new LateInlineMHCallGenerator(caller, callee, input_not_const);
aoqi@0 474 return cg;
aoqi@0 475 }
aoqi@0 476
aoqi@0 477 class LateInlineStringCallGenerator : public LateInlineCallGenerator {
aoqi@0 478
aoqi@0 479 public:
aoqi@0 480 LateInlineStringCallGenerator(ciMethod* method, CallGenerator* inline_cg) :
aoqi@0 481 LateInlineCallGenerator(method, inline_cg) {}
aoqi@0 482
roland@7041 483 virtual JVMState* generate(JVMState* jvms) {
aoqi@0 484 Compile *C = Compile::current();
aoqi@0 485 C->print_inlining_skip(this);
aoqi@0 486
aoqi@0 487 C->add_string_late_inline(this);
aoqi@0 488
roland@7041 489 JVMState* new_jvms = DirectCallGenerator::generate(jvms);
aoqi@0 490 return new_jvms;
aoqi@0 491 }
aoqi@0 492
aoqi@0 493 virtual bool is_string_late_inline() const { return true; }
aoqi@0 494 };
aoqi@0 495
aoqi@0 496 CallGenerator* CallGenerator::for_string_late_inline(ciMethod* method, CallGenerator* inline_cg) {
aoqi@0 497 return new LateInlineStringCallGenerator(method, inline_cg);
aoqi@0 498 }
aoqi@0 499
aoqi@0 500 class LateInlineBoxingCallGenerator : public LateInlineCallGenerator {
aoqi@0 501
aoqi@0 502 public:
aoqi@0 503 LateInlineBoxingCallGenerator(ciMethod* method, CallGenerator* inline_cg) :
aoqi@0 504 LateInlineCallGenerator(method, inline_cg) {}
aoqi@0 505
roland@7041 506 virtual JVMState* generate(JVMState* jvms) {
aoqi@0 507 Compile *C = Compile::current();
aoqi@0 508 C->print_inlining_skip(this);
aoqi@0 509
aoqi@0 510 C->add_boxing_late_inline(this);
aoqi@0 511
roland@7041 512 JVMState* new_jvms = DirectCallGenerator::generate(jvms);
aoqi@0 513 return new_jvms;
aoqi@0 514 }
aoqi@0 515 };
aoqi@0 516
aoqi@0 517 CallGenerator* CallGenerator::for_boxing_late_inline(ciMethod* method, CallGenerator* inline_cg) {
aoqi@0 518 return new LateInlineBoxingCallGenerator(method, inline_cg);
aoqi@0 519 }
aoqi@0 520
aoqi@0 521 //---------------------------WarmCallGenerator--------------------------------
aoqi@0 522 // Internal class which handles initial deferral of inlining decisions.
aoqi@0 523 class WarmCallGenerator : public CallGenerator {
aoqi@0 524 WarmCallInfo* _call_info;
aoqi@0 525 CallGenerator* _if_cold;
aoqi@0 526 CallGenerator* _if_hot;
aoqi@0 527 bool _is_virtual; // caches virtuality of if_cold
aoqi@0 528 bool _is_inline; // caches inline-ness of if_hot
aoqi@0 529
aoqi@0 530 public:
aoqi@0 531 WarmCallGenerator(WarmCallInfo* ci,
aoqi@0 532 CallGenerator* if_cold,
aoqi@0 533 CallGenerator* if_hot)
aoqi@0 534 : CallGenerator(if_cold->method())
aoqi@0 535 {
aoqi@0 536 assert(method() == if_hot->method(), "consistent choices");
aoqi@0 537 _call_info = ci;
aoqi@0 538 _if_cold = if_cold;
aoqi@0 539 _if_hot = if_hot;
aoqi@0 540 _is_virtual = if_cold->is_virtual();
aoqi@0 541 _is_inline = if_hot->is_inline();
aoqi@0 542 }
aoqi@0 543
aoqi@0 544 virtual bool is_inline() const { return _is_inline; }
aoqi@0 545 virtual bool is_virtual() const { return _is_virtual; }
aoqi@0 546 virtual bool is_deferred() const { return true; }
aoqi@0 547
roland@7041 548 virtual JVMState* generate(JVMState* jvms);
aoqi@0 549 };
aoqi@0 550
aoqi@0 551
aoqi@0 552 CallGenerator* CallGenerator::for_warm_call(WarmCallInfo* ci,
aoqi@0 553 CallGenerator* if_cold,
aoqi@0 554 CallGenerator* if_hot) {
aoqi@0 555 return new WarmCallGenerator(ci, if_cold, if_hot);
aoqi@0 556 }
aoqi@0 557
roland@7041 558 JVMState* WarmCallGenerator::generate(JVMState* jvms) {
aoqi@0 559 Compile* C = Compile::current();
aoqi@0 560 if (C->log() != NULL) {
aoqi@0 561 C->log()->elem("warm_call bci='%d'", jvms->bci());
aoqi@0 562 }
roland@7041 563 jvms = _if_cold->generate(jvms);
aoqi@0 564 if (jvms != NULL) {
aoqi@0 565 Node* m = jvms->map()->control();
aoqi@0 566 if (m->is_CatchProj()) m = m->in(0); else m = C->top();
aoqi@0 567 if (m->is_Catch()) m = m->in(0); else m = C->top();
aoqi@0 568 if (m->is_Proj()) m = m->in(0); else m = C->top();
aoqi@0 569 if (m->is_CallJava()) {
aoqi@0 570 _call_info->set_call(m->as_Call());
aoqi@0 571 _call_info->set_hot_cg(_if_hot);
aoqi@0 572 #ifndef PRODUCT
aoqi@0 573 if (PrintOpto || PrintOptoInlining) {
aoqi@0 574 tty->print_cr("Queueing for warm inlining at bci %d:", jvms->bci());
aoqi@0 575 tty->print("WCI: ");
aoqi@0 576 _call_info->print();
aoqi@0 577 }
aoqi@0 578 #endif
aoqi@0 579 _call_info->set_heat(_call_info->compute_heat());
aoqi@0 580 C->set_warm_calls(_call_info->insert_into(C->warm_calls()));
aoqi@0 581 }
aoqi@0 582 }
aoqi@0 583 return jvms;
aoqi@0 584 }
aoqi@0 585
aoqi@0 586 void WarmCallInfo::make_hot() {
aoqi@0 587 Unimplemented();
aoqi@0 588 }
aoqi@0 589
aoqi@0 590 void WarmCallInfo::make_cold() {
aoqi@0 591 // No action: Just dequeue.
aoqi@0 592 }
aoqi@0 593
aoqi@0 594
aoqi@0 595 //------------------------PredictedCallGenerator------------------------------
aoqi@0 596 // Internal class which handles all out-of-line calls checking receiver type.
aoqi@0 597 class PredictedCallGenerator : public CallGenerator {
aoqi@0 598 ciKlass* _predicted_receiver;
aoqi@0 599 CallGenerator* _if_missed;
aoqi@0 600 CallGenerator* _if_hit;
aoqi@0 601 float _hit_prob;
aoqi@0 602
aoqi@0 603 public:
aoqi@0 604 PredictedCallGenerator(ciKlass* predicted_receiver,
aoqi@0 605 CallGenerator* if_missed,
aoqi@0 606 CallGenerator* if_hit, float hit_prob)
aoqi@0 607 : CallGenerator(if_missed->method())
aoqi@0 608 {
aoqi@0 609 // The call profile data may predict the hit_prob as extreme as 0 or 1.
aoqi@0 610 // Remove the extremes values from the range.
aoqi@0 611 if (hit_prob > PROB_MAX) hit_prob = PROB_MAX;
aoqi@0 612 if (hit_prob < PROB_MIN) hit_prob = PROB_MIN;
aoqi@0 613
aoqi@0 614 _predicted_receiver = predicted_receiver;
aoqi@0 615 _if_missed = if_missed;
aoqi@0 616 _if_hit = if_hit;
aoqi@0 617 _hit_prob = hit_prob;
aoqi@0 618 }
aoqi@0 619
aoqi@0 620 virtual bool is_virtual() const { return true; }
aoqi@0 621 virtual bool is_inline() const { return _if_hit->is_inline(); }
aoqi@0 622 virtual bool is_deferred() const { return _if_hit->is_deferred(); }
aoqi@0 623
roland@7041 624 virtual JVMState* generate(JVMState* jvms);
aoqi@0 625 };
aoqi@0 626
aoqi@0 627
aoqi@0 628 CallGenerator* CallGenerator::for_predicted_call(ciKlass* predicted_receiver,
aoqi@0 629 CallGenerator* if_missed,
aoqi@0 630 CallGenerator* if_hit,
aoqi@0 631 float hit_prob) {
aoqi@0 632 return new PredictedCallGenerator(predicted_receiver, if_missed, if_hit, hit_prob);
aoqi@0 633 }
aoqi@0 634
aoqi@0 635
roland@7041 636 JVMState* PredictedCallGenerator::generate(JVMState* jvms) {
aoqi@0 637 GraphKit kit(jvms);
aoqi@0 638 PhaseGVN& gvn = kit.gvn();
aoqi@0 639 // We need an explicit receiver null_check before checking its type.
aoqi@0 640 // We share a map with the caller, so his JVMS gets adjusted.
aoqi@0 641 Node* receiver = kit.argument(0);
aoqi@0 642
aoqi@0 643 CompileLog* log = kit.C->log();
aoqi@0 644 if (log != NULL) {
aoqi@0 645 log->elem("predicted_call bci='%d' klass='%d'",
aoqi@0 646 jvms->bci(), log->identify(_predicted_receiver));
aoqi@0 647 }
aoqi@0 648
aoqi@0 649 receiver = kit.null_check_receiver_before_call(method());
aoqi@0 650 if (kit.stopped()) {
aoqi@0 651 return kit.transfer_exceptions_into_jvms();
aoqi@0 652 }
aoqi@0 653
roland@7041 654 // Make a copy of the replaced nodes in case we need to restore them
roland@7041 655 ReplacedNodes replaced_nodes = kit.map()->replaced_nodes();
roland@7041 656 replaced_nodes.clone();
roland@7041 657
aoqi@0 658 Node* exact_receiver = receiver; // will get updated in place...
aoqi@0 659 Node* slow_ctl = kit.type_check_receiver(receiver,
aoqi@0 660 _predicted_receiver, _hit_prob,
aoqi@0 661 &exact_receiver);
aoqi@0 662
aoqi@0 663 SafePointNode* slow_map = NULL;
csahu@8316 664 JVMState* slow_jvms = NULL;
aoqi@0 665 { PreserveJVMState pjvms(&kit);
aoqi@0 666 kit.set_control(slow_ctl);
aoqi@0 667 if (!kit.stopped()) {
roland@7041 668 slow_jvms = _if_missed->generate(kit.sync_jvms());
aoqi@0 669 if (kit.failing())
aoqi@0 670 return NULL; // might happen because of NodeCountInliningCutoff
aoqi@0 671 assert(slow_jvms != NULL, "must be");
aoqi@0 672 kit.add_exception_states_from(slow_jvms);
aoqi@0 673 kit.set_map(slow_jvms->map());
aoqi@0 674 if (!kit.stopped())
aoqi@0 675 slow_map = kit.stop();
aoqi@0 676 }
aoqi@0 677 }
aoqi@0 678
aoqi@0 679 if (kit.stopped()) {
aoqi@0 680 // Instance exactly does not matches the desired type.
aoqi@0 681 kit.set_jvms(slow_jvms);
aoqi@0 682 return kit.transfer_exceptions_into_jvms();
aoqi@0 683 }
aoqi@0 684
aoqi@0 685 // fall through if the instance exactly matches the desired type
aoqi@0 686 kit.replace_in_map(receiver, exact_receiver);
aoqi@0 687
aoqi@0 688 // Make the hot call:
roland@7041 689 JVMState* new_jvms = _if_hit->generate(kit.sync_jvms());
aoqi@0 690 if (new_jvms == NULL) {
aoqi@0 691 // Inline failed, so make a direct call.
aoqi@0 692 assert(_if_hit->is_inline(), "must have been a failed inline");
aoqi@0 693 CallGenerator* cg = CallGenerator::for_direct_call(_if_hit->method());
roland@7041 694 new_jvms = cg->generate(kit.sync_jvms());
aoqi@0 695 }
aoqi@0 696 kit.add_exception_states_from(new_jvms);
aoqi@0 697 kit.set_jvms(new_jvms);
aoqi@0 698
aoqi@0 699 // Need to merge slow and fast?
aoqi@0 700 if (slow_map == NULL) {
aoqi@0 701 // The fast path is the only path remaining.
aoqi@0 702 return kit.transfer_exceptions_into_jvms();
aoqi@0 703 }
aoqi@0 704
aoqi@0 705 if (kit.stopped()) {
aoqi@0 706 // Inlined method threw an exception, so it's just the slow path after all.
aoqi@0 707 kit.set_jvms(slow_jvms);
aoqi@0 708 return kit.transfer_exceptions_into_jvms();
aoqi@0 709 }
aoqi@0 710
roland@7041 711 // There are 2 branches and the replaced nodes are only valid on
roland@7041 712 // one: restore the replaced nodes to what they were before the
roland@7041 713 // branch.
roland@7041 714 kit.map()->set_replaced_nodes(replaced_nodes);
roland@7041 715
aoqi@0 716 // Finish the diamond.
aoqi@0 717 kit.C->set_has_split_ifs(true); // Has chance for split-if optimization
aoqi@0 718 RegionNode* region = new (kit.C) RegionNode(3);
aoqi@0 719 region->init_req(1, kit.control());
aoqi@0 720 region->init_req(2, slow_map->control());
aoqi@0 721 kit.set_control(gvn.transform(region));
aoqi@0 722 Node* iophi = PhiNode::make(region, kit.i_o(), Type::ABIO);
aoqi@0 723 iophi->set_req(2, slow_map->i_o());
aoqi@0 724 kit.set_i_o(gvn.transform(iophi));
kvn@7026 725 // Merge memory
aoqi@0 726 kit.merge_memory(slow_map->merged_memory(), region, 2);
kvn@7026 727 // Transform new memory Phis.
kvn@7026 728 for (MergeMemStream mms(kit.merged_memory()); mms.next_non_empty();) {
kvn@7026 729 Node* phi = mms.memory();
kvn@7026 730 if (phi->is_Phi() && phi->in(0) == region) {
kvn@7026 731 mms.set_memory(gvn.transform(phi));
kvn@7026 732 }
kvn@7026 733 }
aoqi@0 734 uint tos = kit.jvms()->stkoff() + kit.sp();
aoqi@0 735 uint limit = slow_map->req();
aoqi@0 736 for (uint i = TypeFunc::Parms; i < limit; i++) {
aoqi@0 737 // Skip unused stack slots; fast forward to monoff();
aoqi@0 738 if (i == tos) {
aoqi@0 739 i = kit.jvms()->monoff();
aoqi@0 740 if( i >= limit ) break;
aoqi@0 741 }
aoqi@0 742 Node* m = kit.map()->in(i);
aoqi@0 743 Node* n = slow_map->in(i);
aoqi@0 744 if (m != n) {
aoqi@0 745 const Type* t = gvn.type(m)->meet_speculative(gvn.type(n));
aoqi@0 746 Node* phi = PhiNode::make(region, m, t);
aoqi@0 747 phi->set_req(2, n);
aoqi@0 748 kit.map()->set_req(i, gvn.transform(phi));
aoqi@0 749 }
aoqi@0 750 }
aoqi@0 751 return kit.transfer_exceptions_into_jvms();
aoqi@0 752 }
aoqi@0 753
aoqi@0 754
aoqi@0 755 CallGenerator* CallGenerator::for_method_handle_call(JVMState* jvms, ciMethod* caller, ciMethod* callee, bool delayed_forbidden) {
aoqi@0 756 assert(callee->is_method_handle_intrinsic() ||
aoqi@0 757 callee->is_compiled_lambda_form(), "for_method_handle_call mismatch");
aoqi@0 758 bool input_not_const;
aoqi@0 759 CallGenerator* cg = CallGenerator::for_method_handle_inline(jvms, caller, callee, input_not_const);
aoqi@0 760 Compile* C = Compile::current();
aoqi@0 761 if (cg != NULL) {
aoqi@0 762 if (!delayed_forbidden && AlwaysIncrementalInline) {
aoqi@0 763 return CallGenerator::for_late_inline(callee, cg);
aoqi@0 764 } else {
aoqi@0 765 return cg;
aoqi@0 766 }
aoqi@0 767 }
aoqi@0 768 int bci = jvms->bci();
aoqi@0 769 ciCallProfile profile = caller->call_profile_at_bci(bci);
aoqi@0 770 int call_site_count = caller->scale_count(profile.count());
aoqi@0 771
aoqi@0 772 if (IncrementalInline && call_site_count > 0 &&
aoqi@0 773 (input_not_const || !C->inlining_incrementally() || C->over_inlining_cutoff())) {
aoqi@0 774 return CallGenerator::for_mh_late_inline(caller, callee, input_not_const);
aoqi@0 775 } else {
aoqi@0 776 // Out-of-line call.
aoqi@0 777 return CallGenerator::for_direct_call(callee);
aoqi@0 778 }
aoqi@0 779 }
aoqi@0 780
aoqi@0 781 CallGenerator* CallGenerator::for_method_handle_inline(JVMState* jvms, ciMethod* caller, ciMethod* callee, bool& input_not_const) {
aoqi@0 782 GraphKit kit(jvms);
aoqi@0 783 PhaseGVN& gvn = kit.gvn();
aoqi@0 784 Compile* C = kit.C;
aoqi@0 785 vmIntrinsics::ID iid = callee->intrinsic_id();
aoqi@0 786 input_not_const = true;
aoqi@0 787 switch (iid) {
aoqi@0 788 case vmIntrinsics::_invokeBasic:
aoqi@0 789 {
aoqi@0 790 // Get MethodHandle receiver:
aoqi@0 791 Node* receiver = kit.argument(0);
aoqi@0 792 if (receiver->Opcode() == Op_ConP) {
aoqi@0 793 input_not_const = false;
aoqi@0 794 const TypeOopPtr* oop_ptr = receiver->bottom_type()->is_oopptr();
aoqi@0 795 ciMethod* target = oop_ptr->const_oop()->as_method_handle()->get_vmtarget();
aoqi@0 796 guarantee(!target->is_method_handle_intrinsic(), "should not happen"); // XXX remove
aoqi@0 797 const int vtable_index = Method::invalid_vtable_index;
aoqi@0 798 CallGenerator* cg = C->call_generator(target, vtable_index, false, jvms, true, PROB_ALWAYS, NULL, true, true);
aoqi@0 799 assert(cg == NULL || !cg->is_late_inline() || cg->is_mh_late_inline(), "no late inline here");
aoqi@0 800 if (cg != NULL && cg->is_inline())
aoqi@0 801 return cg;
aoqi@0 802 }
aoqi@0 803 }
aoqi@0 804 break;
aoqi@0 805
aoqi@0 806 case vmIntrinsics::_linkToVirtual:
aoqi@0 807 case vmIntrinsics::_linkToStatic:
aoqi@0 808 case vmIntrinsics::_linkToSpecial:
aoqi@0 809 case vmIntrinsics::_linkToInterface:
aoqi@0 810 {
aoqi@0 811 // Get MemberName argument:
aoqi@0 812 Node* member_name = kit.argument(callee->arg_size() - 1);
aoqi@0 813 if (member_name->Opcode() == Op_ConP) {
aoqi@0 814 input_not_const = false;
aoqi@0 815 const TypeOopPtr* oop_ptr = member_name->bottom_type()->is_oopptr();
aoqi@0 816 ciMethod* target = oop_ptr->const_oop()->as_member_name()->get_vmtarget();
aoqi@0 817
aoqi@0 818 // In lamda forms we erase signature types to avoid resolving issues
aoqi@0 819 // involving class loaders. When we optimize a method handle invoke
aoqi@0 820 // to a direct call we must cast the receiver and arguments to its
aoqi@0 821 // actual types.
aoqi@0 822 ciSignature* signature = target->signature();
aoqi@0 823 const int receiver_skip = target->is_static() ? 0 : 1;
aoqi@0 824 // Cast receiver to its type.
aoqi@0 825 if (!target->is_static()) {
aoqi@0 826 Node* arg = kit.argument(0);
aoqi@0 827 const TypeOopPtr* arg_type = arg->bottom_type()->isa_oopptr();
aoqi@0 828 const Type* sig_type = TypeOopPtr::make_from_klass(signature->accessing_klass());
aoqi@0 829 if (arg_type != NULL && !arg_type->higher_equal(sig_type)) {
aoqi@0 830 Node* cast_obj = gvn.transform(new (C) CheckCastPPNode(kit.control(), arg, sig_type));
aoqi@0 831 kit.set_argument(0, cast_obj);
aoqi@0 832 }
aoqi@0 833 }
aoqi@0 834 // Cast reference arguments to its type.
thartmann@8304 835 for (int i = 0, j = 0; i < signature->count(); i++) {
aoqi@0 836 ciType* t = signature->type_at(i);
aoqi@0 837 if (t->is_klass()) {
thartmann@8304 838 Node* arg = kit.argument(receiver_skip + j);
aoqi@0 839 const TypeOopPtr* arg_type = arg->bottom_type()->isa_oopptr();
aoqi@0 840 const Type* sig_type = TypeOopPtr::make_from_klass(t->as_klass());
aoqi@0 841 if (arg_type != NULL && !arg_type->higher_equal(sig_type)) {
aoqi@0 842 Node* cast_obj = gvn.transform(new (C) CheckCastPPNode(kit.control(), arg, sig_type));
thartmann@8304 843 kit.set_argument(receiver_skip + j, cast_obj);
aoqi@0 844 }
aoqi@0 845 }
thartmann@8304 846 j += t->size(); // long and double take two slots
aoqi@0 847 }
aoqi@0 848
aoqi@0 849 // Try to get the most accurate receiver type
aoqi@0 850 const bool is_virtual = (iid == vmIntrinsics::_linkToVirtual);
aoqi@0 851 const bool is_virtual_or_interface = (is_virtual || iid == vmIntrinsics::_linkToInterface);
aoqi@0 852 int vtable_index = Method::invalid_vtable_index;
aoqi@0 853 bool call_does_dispatch = false;
aoqi@0 854
aoqi@0 855 ciKlass* speculative_receiver_type = NULL;
aoqi@0 856 if (is_virtual_or_interface) {
aoqi@0 857 ciInstanceKlass* klass = target->holder();
aoqi@0 858 Node* receiver_node = kit.argument(0);
aoqi@0 859 const TypeOopPtr* receiver_type = gvn.type(receiver_node)->isa_oopptr();
aoqi@0 860 // call_does_dispatch and vtable_index are out-parameters. They might be changed.
aoqi@0 861 // optimize_virtual_call() takes 2 different holder
aoqi@0 862 // arguments for a corner case that doesn't apply here (see
aoqi@0 863 // Parse::do_call())
aoqi@0 864 target = C->optimize_virtual_call(caller, jvms->bci(), klass, klass,
aoqi@0 865 target, receiver_type, is_virtual,
vlivanov@7792 866 call_does_dispatch, vtable_index, // out-parameters
vlivanov@7792 867 /*check_access=*/false);
aoqi@0 868 // We lack profiling at this call but type speculation may
aoqi@0 869 // provide us with a type
vlivanov@7287 870 speculative_receiver_type = (receiver_type != NULL) ? receiver_type->speculative_type() : NULL;
aoqi@0 871 }
aoqi@0 872
aoqi@0 873 CallGenerator* cg = C->call_generator(target, vtable_index, call_does_dispatch, jvms, true, PROB_ALWAYS, speculative_receiver_type, true, true);
aoqi@0 874 assert(cg == NULL || !cg->is_late_inline() || cg->is_mh_late_inline(), "no late inline here");
aoqi@0 875 if (cg != NULL && cg->is_inline())
aoqi@0 876 return cg;
aoqi@0 877 }
aoqi@0 878 }
aoqi@0 879 break;
aoqi@0 880
aoqi@0 881 default:
aoqi@0 882 fatal(err_msg_res("unexpected intrinsic %d: %s", iid, vmIntrinsics::name_at(iid)));
aoqi@0 883 break;
aoqi@0 884 }
aoqi@0 885 return NULL;
aoqi@0 886 }
aoqi@0 887
aoqi@0 888
kvn@7026 889 //------------------------PredicatedIntrinsicGenerator------------------------------
kvn@7026 890 // Internal class which handles all predicated Intrinsic calls.
kvn@7026 891 class PredicatedIntrinsicGenerator : public CallGenerator {
aoqi@0 892 CallGenerator* _intrinsic;
aoqi@0 893 CallGenerator* _cg;
aoqi@0 894
aoqi@0 895 public:
kvn@7026 896 PredicatedIntrinsicGenerator(CallGenerator* intrinsic,
kvn@7026 897 CallGenerator* cg)
aoqi@0 898 : CallGenerator(cg->method())
aoqi@0 899 {
aoqi@0 900 _intrinsic = intrinsic;
aoqi@0 901 _cg = cg;
aoqi@0 902 }
aoqi@0 903
aoqi@0 904 virtual bool is_virtual() const { return true; }
aoqi@0 905 virtual bool is_inlined() const { return true; }
aoqi@0 906 virtual bool is_intrinsic() const { return true; }
aoqi@0 907
roland@7041 908 virtual JVMState* generate(JVMState* jvms);
aoqi@0 909 };
aoqi@0 910
aoqi@0 911
kvn@7026 912 CallGenerator* CallGenerator::for_predicated_intrinsic(CallGenerator* intrinsic,
kvn@7026 913 CallGenerator* cg) {
kvn@7026 914 return new PredicatedIntrinsicGenerator(intrinsic, cg);
aoqi@0 915 }
aoqi@0 916
aoqi@0 917
roland@7041 918 JVMState* PredicatedIntrinsicGenerator::generate(JVMState* jvms) {
kvn@7026 919 // The code we want to generate here is:
kvn@7026 920 // if (receiver == NULL)
kvn@7026 921 // uncommon_Trap
kvn@7026 922 // if (predicate(0))
kvn@7026 923 // do_intrinsic(0)
kvn@7026 924 // else
kvn@7026 925 // if (predicate(1))
kvn@7026 926 // do_intrinsic(1)
kvn@7026 927 // ...
kvn@7026 928 // else
kvn@7026 929 // do_java_comp
kvn@7026 930
aoqi@0 931 GraphKit kit(jvms);
aoqi@0 932 PhaseGVN& gvn = kit.gvn();
aoqi@0 933
aoqi@0 934 CompileLog* log = kit.C->log();
aoqi@0 935 if (log != NULL) {
kvn@7026 936 log->elem("predicated_intrinsic bci='%d' method='%d'",
aoqi@0 937 jvms->bci(), log->identify(method()));
aoqi@0 938 }
aoqi@0 939
kvn@7026 940 if (!method()->is_static()) {
kvn@7026 941 // We need an explicit receiver null_check before checking its type in predicate.
kvn@7026 942 // We share a map with the caller, so his JVMS gets adjusted.
kvn@7026 943 Node* receiver = kit.null_check_receiver_before_call(method());
kvn@7026 944 if (kit.stopped()) {
kvn@7026 945 return kit.transfer_exceptions_into_jvms();
aoqi@0 946 }
aoqi@0 947 }
aoqi@0 948
kvn@7026 949 int n_predicates = _intrinsic->predicates_count();
kvn@7026 950 assert(n_predicates > 0, "sanity");
kvn@7026 951
kvn@7026 952 JVMState** result_jvms = NEW_RESOURCE_ARRAY(JVMState*, (n_predicates+1));
kvn@7026 953
kvn@7026 954 // Region for normal compilation code if intrinsic failed.
kvn@7026 955 Node* slow_region = new (kit.C) RegionNode(1);
kvn@7026 956
kvn@7026 957 int results = 0;
kvn@7026 958 for (int predicate = 0; (predicate < n_predicates) && !kit.stopped(); predicate++) {
kvn@7026 959 #ifdef ASSERT
kvn@7026 960 JVMState* old_jvms = kit.jvms();
kvn@7026 961 SafePointNode* old_map = kit.map();
kvn@7026 962 Node* old_io = old_map->i_o();
kvn@7026 963 Node* old_mem = old_map->memory();
kvn@7026 964 Node* old_exc = old_map->next_exception();
kvn@7026 965 #endif
kvn@7026 966 Node* else_ctrl = _intrinsic->generate_predicate(kit.sync_jvms(), predicate);
kvn@7026 967 #ifdef ASSERT
kvn@7026 968 // Assert(no_new_memory && no_new_io && no_new_exceptions) after generate_predicate.
kvn@7026 969 assert(old_jvms == kit.jvms(), "generate_predicate should not change jvm state");
kvn@7026 970 SafePointNode* new_map = kit.map();
kvn@7026 971 assert(old_io == new_map->i_o(), "generate_predicate should not change i_o");
kvn@7026 972 assert(old_mem == new_map->memory(), "generate_predicate should not change memory");
kvn@7026 973 assert(old_exc == new_map->next_exception(), "generate_predicate should not add exceptions");
kvn@7026 974 #endif
kvn@7026 975 if (!kit.stopped()) {
kvn@7026 976 PreserveJVMState pjvms(&kit);
kvn@7026 977 // Generate intrinsic code:
roland@7041 978 JVMState* new_jvms = _intrinsic->generate(kit.sync_jvms());
kvn@7026 979 if (new_jvms == NULL) {
kvn@7026 980 // Intrinsic failed, use normal compilation path for this predicate.
kvn@7026 981 slow_region->add_req(kit.control());
kvn@7026 982 } else {
kvn@7026 983 kit.add_exception_states_from(new_jvms);
kvn@7026 984 kit.set_jvms(new_jvms);
kvn@7026 985 if (!kit.stopped()) {
kvn@7026 986 result_jvms[results++] = kit.jvms();
kvn@7026 987 }
kvn@7026 988 }
kvn@7026 989 }
kvn@7026 990 if (else_ctrl == NULL) {
kvn@7026 991 else_ctrl = kit.C->top();
kvn@7026 992 }
kvn@7026 993 kit.set_control(else_ctrl);
kvn@7026 994 }
kvn@7026 995 if (!kit.stopped()) {
kvn@7026 996 // Final 'else' after predicates.
kvn@7026 997 slow_region->add_req(kit.control());
kvn@7026 998 }
kvn@7026 999 if (slow_region->req() > 1) {
kvn@7026 1000 PreserveJVMState pjvms(&kit);
kvn@7026 1001 // Generate normal compilation code:
kvn@7026 1002 kit.set_control(gvn.transform(slow_region));
roland@7041 1003 JVMState* new_jvms = _cg->generate(kit.sync_jvms());
kvn@7026 1004 if (kit.failing())
kvn@7026 1005 return NULL; // might happen because of NodeCountInliningCutoff
kvn@7026 1006 assert(new_jvms != NULL, "must be");
kvn@7026 1007 kit.add_exception_states_from(new_jvms);
kvn@7026 1008 kit.set_jvms(new_jvms);
kvn@7026 1009 if (!kit.stopped()) {
kvn@7026 1010 result_jvms[results++] = kit.jvms();
kvn@7026 1011 }
kvn@7026 1012 }
kvn@7026 1013
kvn@7026 1014 if (results == 0) {
kvn@7026 1015 // All paths ended in uncommon traps.
kvn@7026 1016 (void) kit.stop();
aoqi@0 1017 return kit.transfer_exceptions_into_jvms();
aoqi@0 1018 }
aoqi@0 1019
kvn@7026 1020 if (results == 1) { // Only one path
kvn@7026 1021 kit.set_jvms(result_jvms[0]);
aoqi@0 1022 return kit.transfer_exceptions_into_jvms();
aoqi@0 1023 }
aoqi@0 1024
kvn@7026 1025 // Merge all paths.
kvn@7026 1026 kit.C->set_has_split_ifs(true); // Has chance for split-if optimization
kvn@7026 1027 RegionNode* region = new (kit.C) RegionNode(results + 1);
kvn@7026 1028 Node* iophi = PhiNode::make(region, kit.i_o(), Type::ABIO);
kvn@7026 1029 for (int i = 0; i < results; i++) {
kvn@7026 1030 JVMState* jvms = result_jvms[i];
kvn@7026 1031 int path = i + 1;
kvn@7026 1032 SafePointNode* map = jvms->map();
kvn@7026 1033 region->init_req(path, map->control());
kvn@7026 1034 iophi->set_req(path, map->i_o());
kvn@7026 1035 if (i == 0) {
kvn@7026 1036 kit.set_jvms(jvms);
kvn@7026 1037 } else {
kvn@7026 1038 kit.merge_memory(map->merged_memory(), region, path);
kvn@7026 1039 }
kvn@7026 1040 }
kvn@7026 1041 kit.set_control(gvn.transform(region));
kvn@7026 1042 kit.set_i_o(gvn.transform(iophi));
kvn@7026 1043 // Transform new memory Phis.
kvn@7026 1044 for (MergeMemStream mms(kit.merged_memory()); mms.next_non_empty();) {
kvn@7026 1045 Node* phi = mms.memory();
kvn@7026 1046 if (phi->is_Phi() && phi->in(0) == region) {
kvn@7026 1047 mms.set_memory(gvn.transform(phi));
kvn@7026 1048 }
aoqi@0 1049 }
aoqi@0 1050
kvn@7026 1051 // Merge debug info.
kvn@7026 1052 Node** ins = NEW_RESOURCE_ARRAY(Node*, results);
aoqi@0 1053 uint tos = kit.jvms()->stkoff() + kit.sp();
kvn@7026 1054 Node* map = kit.map();
kvn@7026 1055 uint limit = map->req();
aoqi@0 1056 for (uint i = TypeFunc::Parms; i < limit; i++) {
aoqi@0 1057 // Skip unused stack slots; fast forward to monoff();
aoqi@0 1058 if (i == tos) {
aoqi@0 1059 i = kit.jvms()->monoff();
aoqi@0 1060 if( i >= limit ) break;
aoqi@0 1061 }
kvn@7026 1062 Node* n = map->in(i);
kvn@7026 1063 ins[0] = n;
kvn@7026 1064 const Type* t = gvn.type(n);
kvn@7026 1065 bool needs_phi = false;
kvn@7026 1066 for (int j = 1; j < results; j++) {
kvn@7026 1067 JVMState* jvms = result_jvms[j];
kvn@7026 1068 Node* jmap = jvms->map();
kvn@7026 1069 Node* m = NULL;
kvn@7026 1070 if (jmap->req() > i) {
kvn@7026 1071 m = jmap->in(i);
kvn@7026 1072 if (m != n) {
kvn@7026 1073 needs_phi = true;
kvn@7026 1074 t = t->meet_speculative(gvn.type(m));
kvn@7026 1075 }
kvn@7026 1076 }
kvn@7026 1077 ins[j] = m;
kvn@7026 1078 }
kvn@7026 1079 if (needs_phi) {
kvn@7026 1080 Node* phi = PhiNode::make(region, n, t);
kvn@7026 1081 for (int j = 1; j < results; j++) {
kvn@7026 1082 phi->set_req(j + 1, ins[j]);
kvn@7026 1083 }
kvn@7026 1084 map->set_req(i, gvn.transform(phi));
aoqi@0 1085 }
aoqi@0 1086 }
kvn@7026 1087
aoqi@0 1088 return kit.transfer_exceptions_into_jvms();
aoqi@0 1089 }
aoqi@0 1090
aoqi@0 1091 //-------------------------UncommonTrapCallGenerator-----------------------------
aoqi@0 1092 // Internal class which handles all out-of-line calls checking receiver type.
aoqi@0 1093 class UncommonTrapCallGenerator : public CallGenerator {
aoqi@0 1094 Deoptimization::DeoptReason _reason;
aoqi@0 1095 Deoptimization::DeoptAction _action;
aoqi@0 1096
aoqi@0 1097 public:
aoqi@0 1098 UncommonTrapCallGenerator(ciMethod* m,
aoqi@0 1099 Deoptimization::DeoptReason reason,
aoqi@0 1100 Deoptimization::DeoptAction action)
aoqi@0 1101 : CallGenerator(m)
aoqi@0 1102 {
aoqi@0 1103 _reason = reason;
aoqi@0 1104 _action = action;
aoqi@0 1105 }
aoqi@0 1106
aoqi@0 1107 virtual bool is_virtual() const { ShouldNotReachHere(); return false; }
aoqi@0 1108 virtual bool is_trap() const { return true; }
aoqi@0 1109
roland@7041 1110 virtual JVMState* generate(JVMState* jvms);
aoqi@0 1111 };
aoqi@0 1112
aoqi@0 1113
aoqi@0 1114 CallGenerator*
aoqi@0 1115 CallGenerator::for_uncommon_trap(ciMethod* m,
aoqi@0 1116 Deoptimization::DeoptReason reason,
aoqi@0 1117 Deoptimization::DeoptAction action) {
aoqi@0 1118 return new UncommonTrapCallGenerator(m, reason, action);
aoqi@0 1119 }
aoqi@0 1120
aoqi@0 1121
roland@7041 1122 JVMState* UncommonTrapCallGenerator::generate(JVMState* jvms) {
aoqi@0 1123 GraphKit kit(jvms);
aoqi@0 1124 // Take the trap with arguments pushed on the stack. (Cf. null_check_receiver).
dbuck@8651 1125 // Callsite signature can be different from actual method being called (i.e _linkTo* sites).
dbuck@8651 1126 // Use callsite signature always.
dbuck@8651 1127 ciMethod* declared_method = kit.method()->get_method_at_bci(kit.bci());
dbuck@8651 1128 int nargs = declared_method->arg_size();
aoqi@0 1129 kit.inc_sp(nargs);
aoqi@0 1130 assert(nargs <= kit.sp() && kit.sp() <= jvms->stk_size(), "sane sp w/ args pushed");
aoqi@0 1131 if (_reason == Deoptimization::Reason_class_check &&
aoqi@0 1132 _action == Deoptimization::Action_maybe_recompile) {
aoqi@0 1133 // Temp fix for 6529811
aoqi@0 1134 // Don't allow uncommon_trap to override our decision to recompile in the event
aoqi@0 1135 // of a class cast failure for a monomorphic call as it will never let us convert
aoqi@0 1136 // the call to either bi-morphic or megamorphic and can lead to unc-trap loops
aoqi@0 1137 bool keep_exact_action = true;
aoqi@0 1138 kit.uncommon_trap(_reason, _action, NULL, "monomorphic vcall checkcast", false, keep_exact_action);
aoqi@0 1139 } else {
aoqi@0 1140 kit.uncommon_trap(_reason, _action);
aoqi@0 1141 }
aoqi@0 1142 return kit.transfer_exceptions_into_jvms();
aoqi@0 1143 }
aoqi@0 1144
aoqi@0 1145 // (Note: Moved hook_up_call to GraphKit::set_edges_for_java_call.)
aoqi@0 1146
aoqi@0 1147 // (Node: Merged hook_up_exits into ParseGenerator::generate.)
aoqi@0 1148
aoqi@0 1149 #define NODES_OVERHEAD_PER_METHOD (30.0)
aoqi@0 1150 #define NODES_PER_BYTECODE (9.5)
aoqi@0 1151
aoqi@0 1152 void WarmCallInfo::init(JVMState* call_site, ciMethod* call_method, ciCallProfile& profile, float prof_factor) {
aoqi@0 1153 int call_count = profile.count();
aoqi@0 1154 int code_size = call_method->code_size();
aoqi@0 1155
aoqi@0 1156 // Expected execution count is based on the historical count:
aoqi@0 1157 _count = call_count < 0 ? 1 : call_site->method()->scale_count(call_count, prof_factor);
aoqi@0 1158
aoqi@0 1159 // Expected profit from inlining, in units of simple call-overheads.
aoqi@0 1160 _profit = 1.0;
aoqi@0 1161
aoqi@0 1162 // Expected work performed by the call in units of call-overheads.
aoqi@0 1163 // %%% need an empirical curve fit for "work" (time in call)
aoqi@0 1164 float bytecodes_per_call = 3;
aoqi@0 1165 _work = 1.0 + code_size / bytecodes_per_call;
aoqi@0 1166
aoqi@0 1167 // Expected size of compilation graph:
aoqi@0 1168 // -XX:+PrintParseStatistics once reported:
aoqi@0 1169 // Methods seen: 9184 Methods parsed: 9184 Nodes created: 1582391
aoqi@0 1170 // Histogram of 144298 parsed bytecodes:
aoqi@0 1171 // %%% Need an better predictor for graph size.
aoqi@0 1172 _size = NODES_OVERHEAD_PER_METHOD + (NODES_PER_BYTECODE * code_size);
aoqi@0 1173 }
aoqi@0 1174
aoqi@0 1175 // is_cold: Return true if the node should never be inlined.
aoqi@0 1176 // This is true if any of the key metrics are extreme.
aoqi@0 1177 bool WarmCallInfo::is_cold() const {
aoqi@0 1178 if (count() < WarmCallMinCount) return true;
aoqi@0 1179 if (profit() < WarmCallMinProfit) return true;
aoqi@0 1180 if (work() > WarmCallMaxWork) return true;
aoqi@0 1181 if (size() > WarmCallMaxSize) return true;
aoqi@0 1182 return false;
aoqi@0 1183 }
aoqi@0 1184
aoqi@0 1185 // is_hot: Return true if the node should be inlined immediately.
aoqi@0 1186 // This is true if any of the key metrics are extreme.
aoqi@0 1187 bool WarmCallInfo::is_hot() const {
aoqi@0 1188 assert(!is_cold(), "eliminate is_cold cases before testing is_hot");
aoqi@0 1189 if (count() >= HotCallCountThreshold) return true;
aoqi@0 1190 if (profit() >= HotCallProfitThreshold) return true;
aoqi@0 1191 if (work() <= HotCallTrivialWork) return true;
aoqi@0 1192 if (size() <= HotCallTrivialSize) return true;
aoqi@0 1193 return false;
aoqi@0 1194 }
aoqi@0 1195
aoqi@0 1196 // compute_heat:
aoqi@0 1197 float WarmCallInfo::compute_heat() const {
aoqi@0 1198 assert(!is_cold(), "compute heat only on warm nodes");
aoqi@0 1199 assert(!is_hot(), "compute heat only on warm nodes");
aoqi@0 1200 int min_size = MAX2(0, (int)HotCallTrivialSize);
aoqi@0 1201 int max_size = MIN2(500, (int)WarmCallMaxSize);
aoqi@0 1202 float method_size = (size() - min_size) / MAX2(1, max_size - min_size);
aoqi@0 1203 float size_factor;
aoqi@0 1204 if (method_size < 0.05) size_factor = 4; // 2 sigmas better than avg.
aoqi@0 1205 else if (method_size < 0.15) size_factor = 2; // 1 sigma better than avg.
aoqi@0 1206 else if (method_size < 0.5) size_factor = 1; // better than avg.
aoqi@0 1207 else size_factor = 0.5; // worse than avg.
aoqi@0 1208 return (count() * profit() * size_factor);
aoqi@0 1209 }
aoqi@0 1210
aoqi@0 1211 bool WarmCallInfo::warmer_than(WarmCallInfo* that) {
aoqi@0 1212 assert(this != that, "compare only different WCIs");
aoqi@0 1213 assert(this->heat() != 0 && that->heat() != 0, "call compute_heat 1st");
aoqi@0 1214 if (this->heat() > that->heat()) return true;
aoqi@0 1215 if (this->heat() < that->heat()) return false;
aoqi@0 1216 assert(this->heat() == that->heat(), "no NaN heat allowed");
aoqi@0 1217 // Equal heat. Break the tie some other way.
aoqi@0 1218 if (!this->call() || !that->call()) return (address)this > (address)that;
aoqi@0 1219 return this->call()->_idx > that->call()->_idx;
aoqi@0 1220 }
aoqi@0 1221
aoqi@0 1222 //#define UNINIT_NEXT ((WarmCallInfo*)badAddress)
aoqi@0 1223 #define UNINIT_NEXT ((WarmCallInfo*)NULL)
aoqi@0 1224
aoqi@0 1225 WarmCallInfo* WarmCallInfo::insert_into(WarmCallInfo* head) {
aoqi@0 1226 assert(next() == UNINIT_NEXT, "not yet on any list");
aoqi@0 1227 WarmCallInfo* prev_p = NULL;
aoqi@0 1228 WarmCallInfo* next_p = head;
aoqi@0 1229 while (next_p != NULL && next_p->warmer_than(this)) {
aoqi@0 1230 prev_p = next_p;
aoqi@0 1231 next_p = prev_p->next();
aoqi@0 1232 }
aoqi@0 1233 // Install this between prev_p and next_p.
aoqi@0 1234 this->set_next(next_p);
aoqi@0 1235 if (prev_p == NULL)
aoqi@0 1236 head = this;
aoqi@0 1237 else
aoqi@0 1238 prev_p->set_next(this);
aoqi@0 1239 return head;
aoqi@0 1240 }
aoqi@0 1241
aoqi@0 1242 WarmCallInfo* WarmCallInfo::remove_from(WarmCallInfo* head) {
aoqi@0 1243 WarmCallInfo* prev_p = NULL;
aoqi@0 1244 WarmCallInfo* next_p = head;
aoqi@0 1245 while (next_p != this) {
aoqi@0 1246 assert(next_p != NULL, "this must be in the list somewhere");
aoqi@0 1247 prev_p = next_p;
aoqi@0 1248 next_p = prev_p->next();
aoqi@0 1249 }
aoqi@0 1250 next_p = this->next();
aoqi@0 1251 debug_only(this->set_next(UNINIT_NEXT));
aoqi@0 1252 // Remove this from between prev_p and next_p.
aoqi@0 1253 if (prev_p == NULL)
aoqi@0 1254 head = next_p;
aoqi@0 1255 else
aoqi@0 1256 prev_p->set_next(next_p);
aoqi@0 1257 return head;
aoqi@0 1258 }
aoqi@0 1259
aoqi@0 1260 WarmCallInfo WarmCallInfo::_always_hot(WarmCallInfo::MAX_VALUE(), WarmCallInfo::MAX_VALUE(),
aoqi@0 1261 WarmCallInfo::MIN_VALUE(), WarmCallInfo::MIN_VALUE());
aoqi@0 1262 WarmCallInfo WarmCallInfo::_always_cold(WarmCallInfo::MIN_VALUE(), WarmCallInfo::MIN_VALUE(),
aoqi@0 1263 WarmCallInfo::MAX_VALUE(), WarmCallInfo::MAX_VALUE());
aoqi@0 1264
aoqi@0 1265 WarmCallInfo* WarmCallInfo::always_hot() {
aoqi@0 1266 assert(_always_hot.is_hot(), "must always be hot");
aoqi@0 1267 return &_always_hot;
aoqi@0 1268 }
aoqi@0 1269
aoqi@0 1270 WarmCallInfo* WarmCallInfo::always_cold() {
aoqi@0 1271 assert(_always_cold.is_cold(), "must always be cold");
aoqi@0 1272 return &_always_cold;
aoqi@0 1273 }
aoqi@0 1274
aoqi@0 1275
aoqi@0 1276 #ifndef PRODUCT
aoqi@0 1277
aoqi@0 1278 void WarmCallInfo::print() const {
aoqi@0 1279 tty->print("%s : C=%6.1f P=%6.1f W=%6.1f S=%6.1f H=%6.1f -> %p",
aoqi@0 1280 is_cold() ? "cold" : is_hot() ? "hot " : "warm",
aoqi@0 1281 count(), profit(), work(), size(), compute_heat(), next());
aoqi@0 1282 tty->cr();
aoqi@0 1283 if (call() != NULL) call()->dump();
aoqi@0 1284 }
aoqi@0 1285
aoqi@0 1286 void print_wci(WarmCallInfo* ci) {
aoqi@0 1287 ci->print();
aoqi@0 1288 }
aoqi@0 1289
aoqi@0 1290 void WarmCallInfo::print_all() const {
aoqi@0 1291 for (const WarmCallInfo* p = this; p != NULL; p = p->next())
aoqi@0 1292 p->print();
aoqi@0 1293 }
aoqi@0 1294
aoqi@0 1295 int WarmCallInfo::count_all() const {
aoqi@0 1296 int cnt = 0;
aoqi@0 1297 for (const WarmCallInfo* p = this; p != NULL; p = p->next())
aoqi@0 1298 cnt++;
aoqi@0 1299 return cnt;
aoqi@0 1300 }
aoqi@0 1301
aoqi@0 1302 #endif //PRODUCT

mercurial