Print this page
Split |
Close |
Expand all |
Collapse all |
--- old/src/share/vm/opto/callGenerator.cpp
+++ new/src/share/vm/opto/callGenerator.cpp
1 1 /*
2 2 * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 4 *
5 5 * This code is free software; you can redistribute it and/or modify it
6 6 * under the terms of the GNU General Public License version 2 only, as
7 7 * published by the Free Software Foundation.
8 8 *
9 9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 12 * version 2 for more details (a copy is included in the LICENSE file that
13 13 * accompanied this code).
14 14 *
15 15 * You should have received a copy of the GNU General Public License version
16 16 * 2 along with this work; if not, write to the Free Software Foundation,
↓ open down ↓ |
16 lines elided |
↑ open up ↑ |
17 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 18 *
19 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 20 * or visit www.oracle.com if you need additional information or have any
21 21 * questions.
22 22 *
23 23 */
24 24
25 25 #include "precompiled.hpp"
26 26 #include "ci/bcEscapeAnalyzer.hpp"
27 +#include "ci/ciCallSite.hpp"
27 28 #include "ci/ciCPCache.hpp"
28 29 #include "ci/ciMethodHandle.hpp"
29 30 #include "classfile/javaClasses.hpp"
30 31 #include "compiler/compileLog.hpp"
31 32 #include "opto/addnode.hpp"
32 33 #include "opto/callGenerator.hpp"
33 34 #include "opto/callnode.hpp"
34 35 #include "opto/cfgnode.hpp"
35 36 #include "opto/connode.hpp"
36 37 #include "opto/parse.hpp"
37 38 #include "opto/rootnode.hpp"
38 39 #include "opto/runtime.hpp"
39 40 #include "opto/subnode.hpp"
40 41
41 42 CallGenerator::CallGenerator(ciMethod* method) {
42 43 _method = method;
43 44 }
44 45
45 46 // Utility function.
46 47 const TypeFunc* CallGenerator::tf() const {
47 48 return TypeFunc::make(method());
48 49 }
49 50
50 51 //-----------------------------ParseGenerator---------------------------------
51 52 // Internal class which handles all direct bytecode traversal.
52 53 class ParseGenerator : public InlineCallGenerator {
53 54 private:
54 55 bool _is_osr;
55 56 float _expected_uses;
56 57
57 58 public:
58 59 ParseGenerator(ciMethod* method, float expected_uses, bool is_osr = false)
59 60 : InlineCallGenerator(method)
60 61 {
61 62 _is_osr = is_osr;
62 63 _expected_uses = expected_uses;
63 64 assert(can_parse(method, is_osr), "parse must be possible");
64 65 }
65 66
66 67 // Can we build either an OSR or a regular parser for this method?
67 68 static bool can_parse(ciMethod* method, int is_osr = false);
68 69
69 70 virtual bool is_parse() const { return true; }
70 71 virtual JVMState* generate(JVMState* jvms);
71 72 int is_osr() { return _is_osr; }
72 73
73 74 };
74 75
75 76 JVMState* ParseGenerator::generate(JVMState* jvms) {
76 77 Compile* C = Compile::current();
77 78
78 79 if (is_osr()) {
79 80 // The JVMS for a OSR has a single argument (see its TypeFunc).
80 81 assert(jvms->depth() == 1, "no inline OSR");
81 82 }
82 83
83 84 if (C->failing()) {
84 85 return NULL; // bailing out of the compile; do not try to parse
85 86 }
86 87
87 88 Parse parser(jvms, method(), _expected_uses);
88 89 // Grab signature for matching/allocation
89 90 #ifdef ASSERT
90 91 if (parser.tf() != (parser.depth() == 1 ? C->tf() : tf())) {
91 92 MutexLockerEx ml(Compile_lock, Mutex::_no_safepoint_check_flag);
92 93 assert(C->env()->system_dictionary_modification_counter_changed(),
93 94 "Must invalidate if TypeFuncs differ");
94 95 }
95 96 #endif
96 97
97 98 GraphKit& exits = parser.exits();
98 99
99 100 if (C->failing()) {
100 101 while (exits.pop_exception_state() != NULL) ;
101 102 return NULL;
102 103 }
103 104
104 105 assert(exits.jvms()->same_calls_as(jvms), "sanity");
105 106
106 107 // Simply return the exit state of the parser,
107 108 // augmented by any exceptional states.
108 109 return exits.transfer_exceptions_into_jvms();
109 110 }
110 111
111 112 //---------------------------DirectCallGenerator------------------------------
112 113 // Internal class which handles all out-of-line calls w/o receiver type checks.
113 114 class DirectCallGenerator : public CallGenerator {
114 115 private:
115 116 CallStaticJavaNode* _call_node;
116 117 // Force separate memory and I/O projections for the exceptional
117 118 // paths to facilitate late inlinig.
118 119 bool _separate_io_proj;
119 120
120 121 public:
121 122 DirectCallGenerator(ciMethod* method, bool separate_io_proj)
122 123 : CallGenerator(method),
123 124 _separate_io_proj(separate_io_proj)
124 125 {
125 126 }
126 127 virtual JVMState* generate(JVMState* jvms);
127 128
128 129 CallStaticJavaNode* call_node() const { return _call_node; }
129 130 };
130 131
131 132 JVMState* DirectCallGenerator::generate(JVMState* jvms) {
132 133 GraphKit kit(jvms);
133 134 bool is_static = method()->is_static();
134 135 address target = is_static ? SharedRuntime::get_resolve_static_call_stub()
135 136 : SharedRuntime::get_resolve_opt_virtual_call_stub();
136 137
137 138 if (kit.C->log() != NULL) {
138 139 kit.C->log()->elem("direct_call bci='%d'", jvms->bci());
139 140 }
140 141
141 142 CallStaticJavaNode *call = new (kit.C, tf()->domain()->cnt()) CallStaticJavaNode(tf(), target, method(), kit.bci());
142 143 if (!is_static) {
143 144 // Make an explicit receiver null_check as part of this call.
144 145 // Since we share a map with the caller, his JVMS gets adjusted.
145 146 kit.null_check_receiver(method());
146 147 if (kit.stopped()) {
147 148 // And dump it back to the caller, decorated with any exceptions:
148 149 return kit.transfer_exceptions_into_jvms();
149 150 }
150 151 // Mark the call node as virtual, sort of:
151 152 call->set_optimized_virtual(true);
152 153 if (method()->is_method_handle_invoke()) {
153 154 call->set_method_handle_invoke(true);
154 155 kit.C->set_has_method_handle_invokes(true);
155 156 }
156 157 }
157 158 kit.set_arguments_for_java_call(call);
158 159 kit.set_edges_for_java_call(call, false, _separate_io_proj);
159 160 Node* ret = kit.set_results_for_java_call(call, _separate_io_proj);
160 161 kit.push_node(method()->return_type()->basic_type(), ret);
161 162 _call_node = call; // Save the call node in case we need it later
162 163 return kit.transfer_exceptions_into_jvms();
163 164 }
164 165
165 166 //---------------------------DynamicCallGenerator-----------------------------
166 167 // Internal class which handles all out-of-line invokedynamic calls.
167 168 class DynamicCallGenerator : public CallGenerator {
168 169 public:
169 170 DynamicCallGenerator(ciMethod* method)
170 171 : CallGenerator(method)
171 172 {
172 173 }
173 174 virtual JVMState* generate(JVMState* jvms);
174 175 };
175 176
176 177 JVMState* DynamicCallGenerator::generate(JVMState* jvms) {
177 178 GraphKit kit(jvms);
178 179
179 180 if (kit.C->log() != NULL) {
180 181 kit.C->log()->elem("dynamic_call bci='%d'", jvms->bci());
181 182 }
182 183
183 184 // Get the constant pool cache from the caller class.
184 185 ciMethod* caller_method = jvms->method();
185 186 ciBytecodeStream str(caller_method);
186 187 str.force_bci(jvms->bci()); // Set the stream to the invokedynamic bci.
187 188 assert(str.cur_bc() == Bytecodes::_invokedynamic, "wrong place to issue a dynamic call!");
188 189 ciCPCache* cpcache = str.get_cpcache();
189 190
190 191 // Get the offset of the CallSite from the constant pool cache
191 192 // pointer.
192 193 int index = str.get_method_index();
193 194 size_t call_site_offset = cpcache->get_f1_offset(index);
194 195
195 196 // Load the CallSite object from the constant pool cache.
196 197 const TypeOopPtr* cpcache_ptr = TypeOopPtr::make_from_constant(cpcache);
197 198 Node* cpcache_adr = kit.makecon(cpcache_ptr);
198 199 Node* call_site_adr = kit.basic_plus_adr(cpcache_adr, cpcache_adr, call_site_offset);
199 200 Node* call_site = kit.make_load(kit.control(), call_site_adr, TypeInstPtr::BOTTOM, T_OBJECT, Compile::AliasIdxRaw);
200 201
201 202 // Load the target MethodHandle from the CallSite object.
202 203 Node* target_mh_adr = kit.basic_plus_adr(call_site, call_site, java_lang_invoke_CallSite::target_offset_in_bytes());
203 204 Node* target_mh = kit.make_load(kit.control(), target_mh_adr, TypeInstPtr::BOTTOM, T_OBJECT);
204 205
205 206 address resolve_stub = SharedRuntime::get_resolve_opt_virtual_call_stub();
206 207
207 208 CallStaticJavaNode *call = new (kit.C, tf()->domain()->cnt()) CallStaticJavaNode(tf(), resolve_stub, method(), kit.bci());
208 209 // invokedynamic is treated as an optimized invokevirtual.
209 210 call->set_optimized_virtual(true);
210 211 // Take extra care (in the presence of argument motion) not to trash the SP:
211 212 call->set_method_handle_invoke(true);
212 213 kit.C->set_has_method_handle_invokes(true);
213 214
214 215 // Pass the target MethodHandle as first argument and shift the
215 216 // other arguments.
216 217 call->init_req(0 + TypeFunc::Parms, target_mh);
217 218 uint nargs = call->method()->arg_size();
218 219 for (uint i = 1; i < nargs; i++) {
219 220 Node* arg = kit.argument(i - 1);
220 221 call->init_req(i + TypeFunc::Parms, arg);
221 222 }
222 223
223 224 kit.set_edges_for_java_call(call);
224 225 Node* ret = kit.set_results_for_java_call(call);
225 226 kit.push_node(method()->return_type()->basic_type(), ret);
226 227 return kit.transfer_exceptions_into_jvms();
227 228 }
228 229
229 230 //--------------------------VirtualCallGenerator------------------------------
230 231 // Internal class which handles all out-of-line calls checking receiver type.
231 232 class VirtualCallGenerator : public CallGenerator {
232 233 private:
233 234 int _vtable_index;
234 235 public:
235 236 VirtualCallGenerator(ciMethod* method, int vtable_index)
236 237 : CallGenerator(method), _vtable_index(vtable_index)
237 238 {
238 239 assert(vtable_index == methodOopDesc::invalid_vtable_index ||
239 240 vtable_index >= 0, "either invalid or usable");
240 241 }
241 242 virtual bool is_virtual() const { return true; }
242 243 virtual JVMState* generate(JVMState* jvms);
243 244 };
244 245
245 246 JVMState* VirtualCallGenerator::generate(JVMState* jvms) {
246 247 GraphKit kit(jvms);
247 248 Node* receiver = kit.argument(0);
248 249
249 250 if (kit.C->log() != NULL) {
250 251 kit.C->log()->elem("virtual_call bci='%d'", jvms->bci());
251 252 }
252 253
253 254 // If the receiver is a constant null, do not torture the system
254 255 // by attempting to call through it. The compile will proceed
255 256 // correctly, but may bail out in final_graph_reshaping, because
256 257 // the call instruction will have a seemingly deficient out-count.
257 258 // (The bailout says something misleading about an "infinite loop".)
258 259 if (kit.gvn().type(receiver)->higher_equal(TypePtr::NULL_PTR)) {
259 260 kit.inc_sp(method()->arg_size()); // restore arguments
260 261 kit.uncommon_trap(Deoptimization::Reason_null_check,
261 262 Deoptimization::Action_none,
262 263 NULL, "null receiver");
263 264 return kit.transfer_exceptions_into_jvms();
264 265 }
265 266
266 267 // Ideally we would unconditionally do a null check here and let it
267 268 // be converted to an implicit check based on profile information.
268 269 // However currently the conversion to implicit null checks in
269 270 // Block::implicit_null_check() only looks for loads and stores, not calls.
270 271 ciMethod *caller = kit.method();
271 272 ciMethodData *caller_md = (caller == NULL) ? NULL : caller->method_data();
272 273 if (!UseInlineCaches || !ImplicitNullChecks ||
273 274 ((ImplicitNullCheckThreshold > 0) && caller_md &&
274 275 (caller_md->trap_count(Deoptimization::Reason_null_check)
275 276 >= (uint)ImplicitNullCheckThreshold))) {
276 277 // Make an explicit receiver null_check as part of this call.
277 278 // Since we share a map with the caller, his JVMS gets adjusted.
278 279 receiver = kit.null_check_receiver(method());
279 280 if (kit.stopped()) {
280 281 // And dump it back to the caller, decorated with any exceptions:
281 282 return kit.transfer_exceptions_into_jvms();
282 283 }
283 284 }
284 285
285 286 assert(!method()->is_static(), "virtual call must not be to static");
286 287 assert(!method()->is_final(), "virtual call should not be to final");
287 288 assert(!method()->is_private(), "virtual call should not be to private");
288 289 assert(_vtable_index == methodOopDesc::invalid_vtable_index || !UseInlineCaches,
289 290 "no vtable calls if +UseInlineCaches ");
290 291 address target = SharedRuntime::get_resolve_virtual_call_stub();
291 292 // Normal inline cache used for call
292 293 CallDynamicJavaNode *call = new (kit.C, tf()->domain()->cnt()) CallDynamicJavaNode(tf(), target, method(), _vtable_index, kit.bci());
293 294 kit.set_arguments_for_java_call(call);
294 295 kit.set_edges_for_java_call(call);
295 296 Node* ret = kit.set_results_for_java_call(call);
296 297 kit.push_node(method()->return_type()->basic_type(), ret);
297 298
298 299 // Represent the effect of an implicit receiver null_check
299 300 // as part of this call. Since we share a map with the caller,
300 301 // his JVMS gets adjusted.
301 302 kit.cast_not_null(receiver);
302 303 return kit.transfer_exceptions_into_jvms();
303 304 }
304 305
305 306 bool ParseGenerator::can_parse(ciMethod* m, int entry_bci) {
306 307 // Certain methods cannot be parsed at all:
307 308 if (!m->can_be_compiled()) return false;
308 309 if (!m->has_balanced_monitors()) return false;
309 310 if (m->get_flow_analysis()->failing()) return false;
310 311
311 312 // (Methods may bail out for other reasons, after the parser is run.
312 313 // We try to avoid this, but if forced, we must return (Node*)NULL.
313 314 // The user of the CallGenerator must check for this condition.)
314 315 return true;
315 316 }
316 317
317 318 CallGenerator* CallGenerator::for_inline(ciMethod* m, float expected_uses) {
318 319 if (!ParseGenerator::can_parse(m)) return NULL;
319 320 return new ParseGenerator(m, expected_uses);
320 321 }
321 322
322 323 // As a special case, the JVMS passed to this CallGenerator is
323 324 // for the method execution already in progress, not just the JVMS
324 325 // of the caller. Thus, this CallGenerator cannot be mixed with others!
325 326 CallGenerator* CallGenerator::for_osr(ciMethod* m, int osr_bci) {
326 327 if (!ParseGenerator::can_parse(m, true)) return NULL;
327 328 float past_uses = m->interpreter_invocation_count();
328 329 float expected_uses = past_uses;
329 330 return new ParseGenerator(m, expected_uses, true);
330 331 }
331 332
332 333 CallGenerator* CallGenerator::for_direct_call(ciMethod* m, bool separate_io_proj) {
333 334 assert(!m->is_abstract(), "for_direct_call mismatch");
334 335 return new DirectCallGenerator(m, separate_io_proj);
335 336 }
336 337
337 338 CallGenerator* CallGenerator::for_dynamic_call(ciMethod* m) {
338 339 assert(m->is_method_handle_invoke(), "for_dynamic_call mismatch");
339 340 return new DynamicCallGenerator(m);
340 341 }
341 342
342 343 CallGenerator* CallGenerator::for_virtual_call(ciMethod* m, int vtable_index) {
343 344 assert(!m->is_static(), "for_virtual_call mismatch");
344 345 assert(!m->is_method_handle_invoke(), "should be a direct call");
345 346 return new VirtualCallGenerator(m, vtable_index);
346 347 }
347 348
348 349 // Allow inlining decisions to be delayed
349 350 class LateInlineCallGenerator : public DirectCallGenerator {
350 351 CallGenerator* _inline_cg;
351 352
352 353 public:
353 354 LateInlineCallGenerator(ciMethod* method, CallGenerator* inline_cg) :
354 355 DirectCallGenerator(method, true), _inline_cg(inline_cg) {}
355 356
356 357 virtual bool is_late_inline() const { return true; }
357 358
358 359 // Convert the CallStaticJava into an inline
359 360 virtual void do_late_inline();
360 361
361 362 JVMState* generate(JVMState* jvms) {
362 363 // Record that this call site should be revisited once the main
363 364 // parse is finished.
364 365 Compile::current()->add_late_inline(this);
365 366
366 367 // Emit the CallStaticJava and request separate projections so
367 368 // that the late inlining logic can distinguish between fall
368 369 // through and exceptional uses of the memory and io projections
369 370 // as is done for allocations and macro expansion.
370 371 return DirectCallGenerator::generate(jvms);
371 372 }
372 373
373 374 };
374 375
375 376
376 377 void LateInlineCallGenerator::do_late_inline() {
377 378 // Can't inline it
378 379 if (call_node() == NULL || call_node()->outcnt() == 0 ||
379 380 call_node()->in(0) == NULL || call_node()->in(0)->is_top())
380 381 return;
381 382
382 383 CallStaticJavaNode* call = call_node();
383 384
384 385 // Make a clone of the JVMState that appropriate to use for driving a parse
385 386 Compile* C = Compile::current();
386 387 JVMState* jvms = call->jvms()->clone_shallow(C);
387 388 uint size = call->req();
388 389 SafePointNode* map = new (C, size) SafePointNode(size, jvms);
389 390 for (uint i1 = 0; i1 < size; i1++) {
390 391 map->init_req(i1, call->in(i1));
391 392 }
392 393
393 394 // Make sure the state is a MergeMem for parsing.
394 395 if (!map->in(TypeFunc::Memory)->is_MergeMem()) {
395 396 map->set_req(TypeFunc::Memory, MergeMemNode::make(C, map->in(TypeFunc::Memory)));
396 397 }
397 398
398 399 // Make enough space for the expression stack and transfer the incoming arguments
399 400 int nargs = method()->arg_size();
400 401 jvms->set_map(map);
401 402 map->ensure_stack(jvms, jvms->method()->max_stack());
402 403 if (nargs > 0) {
403 404 for (int i1 = 0; i1 < nargs; i1++) {
404 405 map->set_req(i1 + jvms->argoff(), call->in(TypeFunc::Parms + i1));
405 406 }
406 407 }
407 408
408 409 CompileLog* log = C->log();
409 410 if (log != NULL) {
410 411 log->head("late_inline method='%d'", log->identify(method()));
411 412 JVMState* p = jvms;
412 413 while (p != NULL) {
413 414 log->elem("jvms bci='%d' method='%d'", p->bci(), log->identify(p->method()));
414 415 p = p->caller();
415 416 }
416 417 log->tail("late_inline");
417 418 }
418 419
419 420 // Setup default node notes to be picked up by the inlining
420 421 Node_Notes* old_nn = C->default_node_notes();
421 422 if (old_nn != NULL) {
422 423 Node_Notes* entry_nn = old_nn->clone(C);
423 424 entry_nn->set_jvms(jvms);
424 425 C->set_default_node_notes(entry_nn);
425 426 }
426 427
427 428 // Now perform the inling using the synthesized JVMState
428 429 JVMState* new_jvms = _inline_cg->generate(jvms);
429 430 if (new_jvms == NULL) return; // no change
430 431 if (C->failing()) return;
431 432
432 433 // Capture any exceptional control flow
433 434 GraphKit kit(new_jvms);
434 435
435 436 // Find the result object
436 437 Node* result = C->top();
437 438 int result_size = method()->return_type()->size();
438 439 if (result_size != 0 && !kit.stopped()) {
439 440 result = (result_size == 1) ? kit.pop() : kit.pop_pair();
440 441 }
441 442
442 443 kit.replace_call(call, result);
443 444 }
444 445
445 446
446 447 CallGenerator* CallGenerator::for_late_inline(ciMethod* method, CallGenerator* inline_cg) {
447 448 return new LateInlineCallGenerator(method, inline_cg);
448 449 }
449 450
450 451
451 452 //---------------------------WarmCallGenerator--------------------------------
452 453 // Internal class which handles initial deferral of inlining decisions.
453 454 class WarmCallGenerator : public CallGenerator {
454 455 WarmCallInfo* _call_info;
455 456 CallGenerator* _if_cold;
456 457 CallGenerator* _if_hot;
457 458 bool _is_virtual; // caches virtuality of if_cold
458 459 bool _is_inline; // caches inline-ness of if_hot
459 460
460 461 public:
461 462 WarmCallGenerator(WarmCallInfo* ci,
462 463 CallGenerator* if_cold,
463 464 CallGenerator* if_hot)
464 465 : CallGenerator(if_cold->method())
465 466 {
466 467 assert(method() == if_hot->method(), "consistent choices");
467 468 _call_info = ci;
468 469 _if_cold = if_cold;
469 470 _if_hot = if_hot;
470 471 _is_virtual = if_cold->is_virtual();
471 472 _is_inline = if_hot->is_inline();
472 473 }
473 474
474 475 virtual bool is_inline() const { return _is_inline; }
475 476 virtual bool is_virtual() const { return _is_virtual; }
476 477 virtual bool is_deferred() const { return true; }
477 478
478 479 virtual JVMState* generate(JVMState* jvms);
479 480 };
480 481
481 482
482 483 CallGenerator* CallGenerator::for_warm_call(WarmCallInfo* ci,
483 484 CallGenerator* if_cold,
484 485 CallGenerator* if_hot) {
485 486 return new WarmCallGenerator(ci, if_cold, if_hot);
486 487 }
487 488
488 489 JVMState* WarmCallGenerator::generate(JVMState* jvms) {
489 490 Compile* C = Compile::current();
490 491 if (C->log() != NULL) {
491 492 C->log()->elem("warm_call bci='%d'", jvms->bci());
492 493 }
493 494 jvms = _if_cold->generate(jvms);
494 495 if (jvms != NULL) {
495 496 Node* m = jvms->map()->control();
496 497 if (m->is_CatchProj()) m = m->in(0); else m = C->top();
497 498 if (m->is_Catch()) m = m->in(0); else m = C->top();
498 499 if (m->is_Proj()) m = m->in(0); else m = C->top();
499 500 if (m->is_CallJava()) {
500 501 _call_info->set_call(m->as_Call());
501 502 _call_info->set_hot_cg(_if_hot);
502 503 #ifndef PRODUCT
503 504 if (PrintOpto || PrintOptoInlining) {
504 505 tty->print_cr("Queueing for warm inlining at bci %d:", jvms->bci());
505 506 tty->print("WCI: ");
506 507 _call_info->print();
507 508 }
508 509 #endif
509 510 _call_info->set_heat(_call_info->compute_heat());
510 511 C->set_warm_calls(_call_info->insert_into(C->warm_calls()));
511 512 }
512 513 }
513 514 return jvms;
514 515 }
515 516
516 517 void WarmCallInfo::make_hot() {
517 518 Unimplemented();
518 519 }
519 520
520 521 void WarmCallInfo::make_cold() {
521 522 // No action: Just dequeue.
522 523 }
523 524
524 525
525 526 //------------------------PredictedCallGenerator------------------------------
526 527 // Internal class which handles all out-of-line calls checking receiver type.
527 528 class PredictedCallGenerator : public CallGenerator {
528 529 ciKlass* _predicted_receiver;
529 530 CallGenerator* _if_missed;
530 531 CallGenerator* _if_hit;
531 532 float _hit_prob;
532 533
533 534 public:
534 535 PredictedCallGenerator(ciKlass* predicted_receiver,
535 536 CallGenerator* if_missed,
536 537 CallGenerator* if_hit, float hit_prob)
537 538 : CallGenerator(if_missed->method())
538 539 {
539 540 // The call profile data may predict the hit_prob as extreme as 0 or 1.
540 541 // Remove the extremes values from the range.
541 542 if (hit_prob > PROB_MAX) hit_prob = PROB_MAX;
542 543 if (hit_prob < PROB_MIN) hit_prob = PROB_MIN;
543 544
544 545 _predicted_receiver = predicted_receiver;
545 546 _if_missed = if_missed;
546 547 _if_hit = if_hit;
547 548 _hit_prob = hit_prob;
548 549 }
549 550
550 551 virtual bool is_virtual() const { return true; }
551 552 virtual bool is_inline() const { return _if_hit->is_inline(); }
552 553 virtual bool is_deferred() const { return _if_hit->is_deferred(); }
553 554
554 555 virtual JVMState* generate(JVMState* jvms);
555 556 };
556 557
557 558
558 559 CallGenerator* CallGenerator::for_predicted_call(ciKlass* predicted_receiver,
559 560 CallGenerator* if_missed,
560 561 CallGenerator* if_hit,
561 562 float hit_prob) {
562 563 return new PredictedCallGenerator(predicted_receiver, if_missed, if_hit, hit_prob);
563 564 }
564 565
565 566
566 567 JVMState* PredictedCallGenerator::generate(JVMState* jvms) {
567 568 GraphKit kit(jvms);
568 569 PhaseGVN& gvn = kit.gvn();
569 570 // We need an explicit receiver null_check before checking its type.
570 571 // We share a map with the caller, so his JVMS gets adjusted.
571 572 Node* receiver = kit.argument(0);
572 573
573 574 CompileLog* log = kit.C->log();
574 575 if (log != NULL) {
575 576 log->elem("predicted_call bci='%d' klass='%d'",
576 577 jvms->bci(), log->identify(_predicted_receiver));
577 578 }
578 579
579 580 receiver = kit.null_check_receiver(method());
580 581 if (kit.stopped()) {
581 582 return kit.transfer_exceptions_into_jvms();
582 583 }
583 584
584 585 Node* exact_receiver = receiver; // will get updated in place...
585 586 Node* slow_ctl = kit.type_check_receiver(receiver,
586 587 _predicted_receiver, _hit_prob,
587 588 &exact_receiver);
588 589
589 590 SafePointNode* slow_map = NULL;
590 591 JVMState* slow_jvms;
591 592 { PreserveJVMState pjvms(&kit);
592 593 kit.set_control(slow_ctl);
593 594 if (!kit.stopped()) {
594 595 slow_jvms = _if_missed->generate(kit.sync_jvms());
595 596 assert(slow_jvms != NULL, "miss path must not fail to generate");
596 597 kit.add_exception_states_from(slow_jvms);
597 598 kit.set_map(slow_jvms->map());
598 599 if (!kit.stopped())
599 600 slow_map = kit.stop();
600 601 }
601 602 }
602 603
603 604 if (kit.stopped()) {
604 605 // Instance exactly does not matches the desired type.
605 606 kit.set_jvms(slow_jvms);
606 607 return kit.transfer_exceptions_into_jvms();
607 608 }
608 609
609 610 // fall through if the instance exactly matches the desired type
610 611 kit.replace_in_map(receiver, exact_receiver);
611 612
612 613 // Make the hot call:
613 614 JVMState* new_jvms = _if_hit->generate(kit.sync_jvms());
614 615 if (new_jvms == NULL) {
615 616 // Inline failed, so make a direct call.
616 617 assert(_if_hit->is_inline(), "must have been a failed inline");
617 618 CallGenerator* cg = CallGenerator::for_direct_call(_if_hit->method());
618 619 new_jvms = cg->generate(kit.sync_jvms());
619 620 }
620 621 kit.add_exception_states_from(new_jvms);
621 622 kit.set_jvms(new_jvms);
622 623
623 624 // Need to merge slow and fast?
624 625 if (slow_map == NULL) {
625 626 // The fast path is the only path remaining.
626 627 return kit.transfer_exceptions_into_jvms();
627 628 }
628 629
629 630 if (kit.stopped()) {
630 631 // Inlined method threw an exception, so it's just the slow path after all.
631 632 kit.set_jvms(slow_jvms);
632 633 return kit.transfer_exceptions_into_jvms();
633 634 }
634 635
635 636 // Finish the diamond.
636 637 kit.C->set_has_split_ifs(true); // Has chance for split-if optimization
637 638 RegionNode* region = new (kit.C, 3) RegionNode(3);
638 639 region->init_req(1, kit.control());
639 640 region->init_req(2, slow_map->control());
640 641 kit.set_control(gvn.transform(region));
641 642 Node* iophi = PhiNode::make(region, kit.i_o(), Type::ABIO);
642 643 iophi->set_req(2, slow_map->i_o());
643 644 kit.set_i_o(gvn.transform(iophi));
644 645 kit.merge_memory(slow_map->merged_memory(), region, 2);
645 646 uint tos = kit.jvms()->stkoff() + kit.sp();
646 647 uint limit = slow_map->req();
647 648 for (uint i = TypeFunc::Parms; i < limit; i++) {
648 649 // Skip unused stack slots; fast forward to monoff();
649 650 if (i == tos) {
650 651 i = kit.jvms()->monoff();
651 652 if( i >= limit ) break;
652 653 }
653 654 Node* m = kit.map()->in(i);
654 655 Node* n = slow_map->in(i);
655 656 if (m != n) {
656 657 const Type* t = gvn.type(m)->meet(gvn.type(n));
657 658 Node* phi = PhiNode::make(region, m, t);
658 659 phi->set_req(2, n);
659 660 kit.map()->set_req(i, gvn.transform(phi));
660 661 }
661 662 }
662 663 return kit.transfer_exceptions_into_jvms();
663 664 }
664 665
665 666
666 667 //------------------------PredictedDynamicCallGenerator-----------------------
667 668 // Internal class which handles all out-of-line calls checking receiver type.
668 669 class PredictedDynamicCallGenerator : public CallGenerator {
669 670 ciMethodHandle* _predicted_method_handle;
670 671 CallGenerator* _if_missed;
671 672 CallGenerator* _if_hit;
672 673 float _hit_prob;
673 674
674 675 public:
675 676 PredictedDynamicCallGenerator(ciMethodHandle* predicted_method_handle,
676 677 CallGenerator* if_missed,
677 678 CallGenerator* if_hit,
678 679 float hit_prob)
679 680 : CallGenerator(if_missed->method()),
680 681 _predicted_method_handle(predicted_method_handle),
681 682 _if_missed(if_missed),
682 683 _if_hit(if_hit),
683 684 _hit_prob(hit_prob)
684 685 {}
685 686
686 687 virtual bool is_inline() const { return _if_hit->is_inline(); }
687 688 virtual bool is_deferred() const { return _if_hit->is_deferred(); }
688 689
689 690 virtual JVMState* generate(JVMState* jvms);
690 691 };
691 692
692 693
693 694 CallGenerator* CallGenerator::for_predicted_dynamic_call(ciMethodHandle* predicted_method_handle,
694 695 CallGenerator* if_missed,
695 696 CallGenerator* if_hit,
696 697 float hit_prob) {
697 698 return new PredictedDynamicCallGenerator(predicted_method_handle, if_missed, if_hit, hit_prob);
698 699 }
699 700
700 701
701 702 CallGenerator* CallGenerator::for_method_handle_inline(Node* method_handle, JVMState* jvms,
702 703 ciMethod* caller, ciMethod* callee, ciCallProfile profile) {
703 704 if (method_handle->Opcode() == Op_ConP) {
704 705 const TypeOopPtr* oop_ptr = method_handle->bottom_type()->is_oopptr();
705 706 ciObject* const_oop = oop_ptr->const_oop();
706 707 ciMethodHandle* method_handle = const_oop->as_method_handle();
707 708
708 709 // Set the callee to have access to the class and signature in
709 710 // the MethodHandleCompiler.
710 711 method_handle->set_callee(callee);
711 712 method_handle->set_caller(caller);
712 713 method_handle->set_call_profile(profile);
713 714
714 715 // Get an adapter for the MethodHandle.
715 716 ciMethod* target_method = method_handle->get_method_handle_adapter();
716 717 if (target_method != NULL) {
717 718 CallGenerator* hit_cg = Compile::current()->call_generator(target_method, -1, false, jvms, true, 1);
718 719 if (hit_cg != NULL && hit_cg->is_inline())
719 720 return hit_cg;
720 721 }
721 722 } else if (method_handle->Opcode() == Op_Phi && method_handle->req() == 3 &&
722 723 method_handle->in(1)->Opcode() == Op_ConP && method_handle->in(2)->Opcode() == Op_ConP) {
723 724 // selectAlternative idiom merging two constant MethodHandles.
724 725 // Generate a guard so that each can be inlined. We might want to
725 726 // do more inputs at later point but this gets the most common
726 727 // case.
727 728 const TypeOopPtr* oop_ptr = method_handle->in(1)->bottom_type()->is_oopptr();
728 729 ciObject* const_oop = oop_ptr->const_oop();
729 730 ciMethodHandle* mh = const_oop->as_method_handle();
730 731
↓ open down ↓ |
694 lines elided |
↑ open up ↑ |
731 732 CallGenerator* cg1 = for_method_handle_inline(method_handle->in(1), jvms, caller, callee, profile);
732 733 CallGenerator* cg2 = for_method_handle_inline(method_handle->in(2), jvms, caller, callee, profile);
733 734 if (cg1 != NULL && cg2 != NULL) {
734 735 return new PredictedDynamicCallGenerator(mh, cg2, cg1, PROB_FAIR);
735 736 }
736 737 }
737 738 return NULL;
738 739 }
739 740
740 741
742 +CallGenerator* CallGenerator::for_invokedynamic_inline(ciCallSite* call_site, JVMState* jvms,
743 + ciMethod* caller, ciMethod* callee, ciCallProfile profile) {
744 + assert(call_site->is_constant_call_site() || call_site->is_mutable_call_site(), "must be");
745 + ciMethodHandle* method_handle = call_site->get_target();
746 +
747 + // Set the callee to have access to the class and signature in the
748 + // MethodHandleCompiler.
749 + method_handle->set_callee(callee);
750 + method_handle->set_caller(caller);
751 + method_handle->set_call_profile(profile);
752 +
753 + // Get an adapter for the MethodHandle.
754 + ciMethod* target_method = method_handle->get_invokedynamic_adapter();
755 + if (target_method != NULL) {
756 + Compile *C = Compile::current();
757 + CallGenerator* hit_cg = C->call_generator(target_method, -1, false, jvms, true, PROB_ALWAYS);
758 + if (hit_cg != NULL && hit_cg->is_inline()) {
759 + // Add a dependence for invalidation of the optimization.
760 + if (call_site->is_mutable_call_site()) {
761 + C->dependencies()->assert_call_site_target_value(C->env()->CallSite_klass(), call_site, method_handle);
762 + }
763 + return hit_cg;
764 + }
765 + }
766 + return NULL;
767 +}
768 +
769 +
741 770 JVMState* PredictedDynamicCallGenerator::generate(JVMState* jvms) {
742 771 GraphKit kit(jvms);
743 772 PhaseGVN& gvn = kit.gvn();
744 773
745 774 CompileLog* log = kit.C->log();
746 775 if (log != NULL) {
747 776 log->elem("predicted_dynamic_call bci='%d'", jvms->bci());
748 777 }
749 778
750 779 const TypeOopPtr* predicted_mh_ptr = TypeOopPtr::make_from_constant(_predicted_method_handle, true);
751 780 Node* predicted_mh = kit.makecon(predicted_mh_ptr);
752 781
753 782 Node* bol = NULL;
754 783 int bc = jvms->method()->java_code_at_bci(jvms->bci());
755 784 if (bc == Bytecodes::_invokespecial) {
756 785 // This is the selectAlternative idiom for guardWithTest
757 786 Node* receiver = kit.argument(0);
758 787
759 788 // Check if the MethodHandle is the expected one
760 789 Node* cmp = gvn.transform(new(kit.C, 3) CmpPNode(receiver, predicted_mh));
761 790 bol = gvn.transform(new(kit.C, 2) BoolNode(cmp, BoolTest::eq) );
762 791 } else {
763 792 assert(bc == Bytecodes::_invokedynamic, "must be");
764 793 // Get the constant pool cache from the caller class.
765 794 ciMethod* caller_method = jvms->method();
766 795 ciBytecodeStream str(caller_method);
767 796 str.force_bci(jvms->bci()); // Set the stream to the invokedynamic bci.
768 797 ciCPCache* cpcache = str.get_cpcache();
769 798
770 799 // Get the offset of the CallSite from the constant pool cache
771 800 // pointer.
772 801 int index = str.get_method_index();
773 802 size_t call_site_offset = cpcache->get_f1_offset(index);
774 803
775 804 // Load the CallSite object from the constant pool cache.
776 805 const TypeOopPtr* cpcache_ptr = TypeOopPtr::make_from_constant(cpcache);
777 806 Node* cpcache_adr = kit.makecon(cpcache_ptr);
778 807 Node* call_site_adr = kit.basic_plus_adr(cpcache_adr, cpcache_adr, call_site_offset);
779 808 Node* call_site = kit.make_load(kit.control(), call_site_adr, TypeInstPtr::BOTTOM, T_OBJECT, Compile::AliasIdxRaw);
780 809
781 810 // Load the target MethodHandle from the CallSite object.
782 811 Node* target_adr = kit.basic_plus_adr(call_site, call_site, java_lang_invoke_CallSite::target_offset_in_bytes());
783 812 Node* target_mh = kit.make_load(kit.control(), target_adr, TypeInstPtr::BOTTOM, T_OBJECT);
784 813
785 814 // Check if the MethodHandle is still the same.
786 815 Node* cmp = gvn.transform(new(kit.C, 3) CmpPNode(target_mh, predicted_mh));
787 816 bol = gvn.transform(new(kit.C, 2) BoolNode(cmp, BoolTest::eq) );
788 817 }
789 818 IfNode* iff = kit.create_and_xform_if(kit.control(), bol, _hit_prob, COUNT_UNKNOWN);
790 819 kit.set_control( gvn.transform(new(kit.C, 1) IfTrueNode (iff)));
791 820 Node* slow_ctl = gvn.transform(new(kit.C, 1) IfFalseNode(iff));
792 821
793 822 SafePointNode* slow_map = NULL;
794 823 JVMState* slow_jvms;
795 824 { PreserveJVMState pjvms(&kit);
796 825 kit.set_control(slow_ctl);
797 826 if (!kit.stopped()) {
798 827 slow_jvms = _if_missed->generate(kit.sync_jvms());
799 828 assert(slow_jvms != NULL, "miss path must not fail to generate");
800 829 kit.add_exception_states_from(slow_jvms);
801 830 kit.set_map(slow_jvms->map());
802 831 if (!kit.stopped())
803 832 slow_map = kit.stop();
804 833 }
805 834 }
806 835
807 836 if (kit.stopped()) {
808 837 // Instance exactly does not matches the desired type.
809 838 kit.set_jvms(slow_jvms);
810 839 return kit.transfer_exceptions_into_jvms();
811 840 }
812 841
813 842 // Make the hot call:
814 843 JVMState* new_jvms = _if_hit->generate(kit.sync_jvms());
815 844 if (new_jvms == NULL) {
816 845 // Inline failed, so make a direct call.
817 846 assert(_if_hit->is_inline(), "must have been a failed inline");
818 847 CallGenerator* cg = CallGenerator::for_direct_call(_if_hit->method());
819 848 new_jvms = cg->generate(kit.sync_jvms());
820 849 }
821 850 kit.add_exception_states_from(new_jvms);
822 851 kit.set_jvms(new_jvms);
823 852
824 853 // Need to merge slow and fast?
825 854 if (slow_map == NULL) {
826 855 // The fast path is the only path remaining.
827 856 return kit.transfer_exceptions_into_jvms();
828 857 }
829 858
830 859 if (kit.stopped()) {
831 860 // Inlined method threw an exception, so it's just the slow path after all.
832 861 kit.set_jvms(slow_jvms);
833 862 return kit.transfer_exceptions_into_jvms();
834 863 }
835 864
836 865 // Finish the diamond.
837 866 kit.C->set_has_split_ifs(true); // Has chance for split-if optimization
838 867 RegionNode* region = new (kit.C, 3) RegionNode(3);
839 868 region->init_req(1, kit.control());
840 869 region->init_req(2, slow_map->control());
841 870 kit.set_control(gvn.transform(region));
842 871 Node* iophi = PhiNode::make(region, kit.i_o(), Type::ABIO);
843 872 iophi->set_req(2, slow_map->i_o());
844 873 kit.set_i_o(gvn.transform(iophi));
845 874 kit.merge_memory(slow_map->merged_memory(), region, 2);
846 875 uint tos = kit.jvms()->stkoff() + kit.sp();
847 876 uint limit = slow_map->req();
848 877 for (uint i = TypeFunc::Parms; i < limit; i++) {
849 878 // Skip unused stack slots; fast forward to monoff();
850 879 if (i == tos) {
851 880 i = kit.jvms()->monoff();
852 881 if( i >= limit ) break;
853 882 }
854 883 Node* m = kit.map()->in(i);
855 884 Node* n = slow_map->in(i);
856 885 if (m != n) {
857 886 const Type* t = gvn.type(m)->meet(gvn.type(n));
858 887 Node* phi = PhiNode::make(region, m, t);
859 888 phi->set_req(2, n);
860 889 kit.map()->set_req(i, gvn.transform(phi));
861 890 }
862 891 }
863 892 return kit.transfer_exceptions_into_jvms();
864 893 }
865 894
866 895
867 896 //-------------------------UncommonTrapCallGenerator-----------------------------
868 897 // Internal class which handles all out-of-line calls checking receiver type.
869 898 class UncommonTrapCallGenerator : public CallGenerator {
870 899 Deoptimization::DeoptReason _reason;
871 900 Deoptimization::DeoptAction _action;
872 901
873 902 public:
874 903 UncommonTrapCallGenerator(ciMethod* m,
875 904 Deoptimization::DeoptReason reason,
876 905 Deoptimization::DeoptAction action)
877 906 : CallGenerator(m)
878 907 {
879 908 _reason = reason;
880 909 _action = action;
881 910 }
882 911
883 912 virtual bool is_virtual() const { ShouldNotReachHere(); return false; }
884 913 virtual bool is_trap() const { return true; }
885 914
886 915 virtual JVMState* generate(JVMState* jvms);
887 916 };
888 917
889 918
890 919 CallGenerator*
891 920 CallGenerator::for_uncommon_trap(ciMethod* m,
892 921 Deoptimization::DeoptReason reason,
893 922 Deoptimization::DeoptAction action) {
894 923 return new UncommonTrapCallGenerator(m, reason, action);
895 924 }
896 925
897 926
898 927 JVMState* UncommonTrapCallGenerator::generate(JVMState* jvms) {
899 928 GraphKit kit(jvms);
900 929 // Take the trap with arguments pushed on the stack. (Cf. null_check_receiver).
901 930 int nargs = method()->arg_size();
902 931 kit.inc_sp(nargs);
903 932 assert(nargs <= kit.sp() && kit.sp() <= jvms->stk_size(), "sane sp w/ args pushed");
904 933 if (_reason == Deoptimization::Reason_class_check &&
905 934 _action == Deoptimization::Action_maybe_recompile) {
906 935 // Temp fix for 6529811
907 936 // Don't allow uncommon_trap to override our decision to recompile in the event
908 937 // of a class cast failure for a monomorphic call as it will never let us convert
909 938 // the call to either bi-morphic or megamorphic and can lead to unc-trap loops
910 939 bool keep_exact_action = true;
911 940 kit.uncommon_trap(_reason, _action, NULL, "monomorphic vcall checkcast", false, keep_exact_action);
912 941 } else {
913 942 kit.uncommon_trap(_reason, _action);
914 943 }
915 944 return kit.transfer_exceptions_into_jvms();
916 945 }
917 946
918 947 // (Note: Moved hook_up_call to GraphKit::set_edges_for_java_call.)
919 948
920 949 // (Node: Merged hook_up_exits into ParseGenerator::generate.)
921 950
922 951 #define NODES_OVERHEAD_PER_METHOD (30.0)
923 952 #define NODES_PER_BYTECODE (9.5)
924 953
925 954 void WarmCallInfo::init(JVMState* call_site, ciMethod* call_method, ciCallProfile& profile, float prof_factor) {
926 955 int call_count = profile.count();
927 956 int code_size = call_method->code_size();
928 957
929 958 // Expected execution count is based on the historical count:
930 959 _count = call_count < 0 ? 1 : call_site->method()->scale_count(call_count, prof_factor);
931 960
932 961 // Expected profit from inlining, in units of simple call-overheads.
933 962 _profit = 1.0;
934 963
935 964 // Expected work performed by the call in units of call-overheads.
936 965 // %%% need an empirical curve fit for "work" (time in call)
937 966 float bytecodes_per_call = 3;
938 967 _work = 1.0 + code_size / bytecodes_per_call;
939 968
940 969 // Expected size of compilation graph:
941 970 // -XX:+PrintParseStatistics once reported:
942 971 // Methods seen: 9184 Methods parsed: 9184 Nodes created: 1582391
943 972 // Histogram of 144298 parsed bytecodes:
944 973 // %%% Need an better predictor for graph size.
945 974 _size = NODES_OVERHEAD_PER_METHOD + (NODES_PER_BYTECODE * code_size);
946 975 }
947 976
948 977 // is_cold: Return true if the node should never be inlined.
949 978 // This is true if any of the key metrics are extreme.
950 979 bool WarmCallInfo::is_cold() const {
951 980 if (count() < WarmCallMinCount) return true;
952 981 if (profit() < WarmCallMinProfit) return true;
953 982 if (work() > WarmCallMaxWork) return true;
954 983 if (size() > WarmCallMaxSize) return true;
955 984 return false;
956 985 }
957 986
958 987 // is_hot: Return true if the node should be inlined immediately.
959 988 // This is true if any of the key metrics are extreme.
960 989 bool WarmCallInfo::is_hot() const {
961 990 assert(!is_cold(), "eliminate is_cold cases before testing is_hot");
962 991 if (count() >= HotCallCountThreshold) return true;
963 992 if (profit() >= HotCallProfitThreshold) return true;
964 993 if (work() <= HotCallTrivialWork) return true;
965 994 if (size() <= HotCallTrivialSize) return true;
966 995 return false;
967 996 }
968 997
969 998 // compute_heat:
970 999 float WarmCallInfo::compute_heat() const {
971 1000 assert(!is_cold(), "compute heat only on warm nodes");
972 1001 assert(!is_hot(), "compute heat only on warm nodes");
973 1002 int min_size = MAX2(0, (int)HotCallTrivialSize);
974 1003 int max_size = MIN2(500, (int)WarmCallMaxSize);
975 1004 float method_size = (size() - min_size) / MAX2(1, max_size - min_size);
976 1005 float size_factor;
977 1006 if (method_size < 0.05) size_factor = 4; // 2 sigmas better than avg.
978 1007 else if (method_size < 0.15) size_factor = 2; // 1 sigma better than avg.
979 1008 else if (method_size < 0.5) size_factor = 1; // better than avg.
980 1009 else size_factor = 0.5; // worse than avg.
981 1010 return (count() * profit() * size_factor);
982 1011 }
983 1012
984 1013 bool WarmCallInfo::warmer_than(WarmCallInfo* that) {
985 1014 assert(this != that, "compare only different WCIs");
986 1015 assert(this->heat() != 0 && that->heat() != 0, "call compute_heat 1st");
987 1016 if (this->heat() > that->heat()) return true;
988 1017 if (this->heat() < that->heat()) return false;
989 1018 assert(this->heat() == that->heat(), "no NaN heat allowed");
990 1019 // Equal heat. Break the tie some other way.
991 1020 if (!this->call() || !that->call()) return (address)this > (address)that;
992 1021 return this->call()->_idx > that->call()->_idx;
993 1022 }
994 1023
995 1024 //#define UNINIT_NEXT ((WarmCallInfo*)badAddress)
996 1025 #define UNINIT_NEXT ((WarmCallInfo*)NULL)
997 1026
998 1027 WarmCallInfo* WarmCallInfo::insert_into(WarmCallInfo* head) {
999 1028 assert(next() == UNINIT_NEXT, "not yet on any list");
1000 1029 WarmCallInfo* prev_p = NULL;
1001 1030 WarmCallInfo* next_p = head;
1002 1031 while (next_p != NULL && next_p->warmer_than(this)) {
1003 1032 prev_p = next_p;
1004 1033 next_p = prev_p->next();
1005 1034 }
1006 1035 // Install this between prev_p and next_p.
1007 1036 this->set_next(next_p);
1008 1037 if (prev_p == NULL)
1009 1038 head = this;
1010 1039 else
1011 1040 prev_p->set_next(this);
1012 1041 return head;
1013 1042 }
1014 1043
1015 1044 WarmCallInfo* WarmCallInfo::remove_from(WarmCallInfo* head) {
1016 1045 WarmCallInfo* prev_p = NULL;
1017 1046 WarmCallInfo* next_p = head;
1018 1047 while (next_p != this) {
1019 1048 assert(next_p != NULL, "this must be in the list somewhere");
1020 1049 prev_p = next_p;
1021 1050 next_p = prev_p->next();
1022 1051 }
1023 1052 next_p = this->next();
1024 1053 debug_only(this->set_next(UNINIT_NEXT));
1025 1054 // Remove this from between prev_p and next_p.
1026 1055 if (prev_p == NULL)
1027 1056 head = next_p;
1028 1057 else
1029 1058 prev_p->set_next(next_p);
1030 1059 return head;
1031 1060 }
1032 1061
1033 1062 WarmCallInfo WarmCallInfo::_always_hot(WarmCallInfo::MAX_VALUE(), WarmCallInfo::MAX_VALUE(),
1034 1063 WarmCallInfo::MIN_VALUE(), WarmCallInfo::MIN_VALUE());
1035 1064 WarmCallInfo WarmCallInfo::_always_cold(WarmCallInfo::MIN_VALUE(), WarmCallInfo::MIN_VALUE(),
1036 1065 WarmCallInfo::MAX_VALUE(), WarmCallInfo::MAX_VALUE());
1037 1066
1038 1067 WarmCallInfo* WarmCallInfo::always_hot() {
1039 1068 assert(_always_hot.is_hot(), "must always be hot");
1040 1069 return &_always_hot;
1041 1070 }
1042 1071
1043 1072 WarmCallInfo* WarmCallInfo::always_cold() {
1044 1073 assert(_always_cold.is_cold(), "must always be cold");
1045 1074 return &_always_cold;
1046 1075 }
1047 1076
1048 1077
1049 1078 #ifndef PRODUCT
1050 1079
1051 1080 void WarmCallInfo::print() const {
1052 1081 tty->print("%s : C=%6.1f P=%6.1f W=%6.1f S=%6.1f H=%6.1f -> %p",
1053 1082 is_cold() ? "cold" : is_hot() ? "hot " : "warm",
1054 1083 count(), profit(), work(), size(), compute_heat(), next());
1055 1084 tty->cr();
1056 1085 if (call() != NULL) call()->dump();
1057 1086 }
1058 1087
1059 1088 void print_wci(WarmCallInfo* ci) {
1060 1089 ci->print();
1061 1090 }
1062 1091
1063 1092 void WarmCallInfo::print_all() const {
1064 1093 for (const WarmCallInfo* p = this; p != NULL; p = p->next())
1065 1094 p->print();
1066 1095 }
1067 1096
1068 1097 int WarmCallInfo::count_all() const {
1069 1098 int cnt = 0;
1070 1099 for (const WarmCallInfo* p = this; p != NULL; p = p->next())
1071 1100 cnt++;
1072 1101 return cnt;
1073 1102 }
1074 1103
1075 1104 #endif //PRODUCT
↓ open down ↓ |
325 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX