Print this page
rev 1082 : [mq]: indy.compiler.patch
Split |
Close |
Expand all |
Collapse all |
--- old/src/share/vm/opto/callGenerator.cpp
+++ new/src/share/vm/opto/callGenerator.cpp
1 1 /*
2 - * Copyright 2000-2008 Sun Microsystems, Inc. All Rights Reserved.
2 + * Copyright 2000-2009 Sun Microsystems, Inc. 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,
17 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 18 *
19 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 21 * have any questions.
22 22 *
23 23 */
24 24
25 25 #include "incls/_precompiled.incl"
26 26 #include "incls/_callGenerator.cpp.incl"
27 27
28 28 CallGenerator::CallGenerator(ciMethod* method) {
29 29 _method = method;
30 30 }
31 31
32 32 // Utility function.
33 33 const TypeFunc* CallGenerator::tf() const {
34 34 return TypeFunc::make(method());
35 35 }
36 36
37 37 //-----------------------------ParseGenerator---------------------------------
38 38 // Internal class which handles all direct bytecode traversal.
39 39 class ParseGenerator : public InlineCallGenerator {
40 40 private:
41 41 bool _is_osr;
42 42 float _expected_uses;
43 43
44 44 public:
45 45 ParseGenerator(ciMethod* method, float expected_uses, bool is_osr = false)
46 46 : InlineCallGenerator(method)
47 47 {
48 48 _is_osr = is_osr;
49 49 _expected_uses = expected_uses;
50 50 assert(can_parse(method, is_osr), "parse must be possible");
51 51 }
52 52
53 53 // Can we build either an OSR or a regular parser for this method?
54 54 static bool can_parse(ciMethod* method, int is_osr = false);
55 55
56 56 virtual bool is_parse() const { return true; }
57 57 virtual JVMState* generate(JVMState* jvms);
58 58 int is_osr() { return _is_osr; }
59 59
60 60 };
61 61
62 62 JVMState* ParseGenerator::generate(JVMState* jvms) {
63 63 Compile* C = Compile::current();
64 64
65 65 if (is_osr()) {
66 66 // The JVMS for a OSR has a single argument (see its TypeFunc).
67 67 assert(jvms->depth() == 1, "no inline OSR");
68 68 }
69 69
70 70 if (C->failing()) {
71 71 return NULL; // bailing out of the compile; do not try to parse
72 72 }
73 73
74 74 Parse parser(jvms, method(), _expected_uses);
75 75 // Grab signature for matching/allocation
76 76 #ifdef ASSERT
77 77 if (parser.tf() != (parser.depth() == 1 ? C->tf() : tf())) {
78 78 MutexLockerEx ml(Compile_lock, Mutex::_no_safepoint_check_flag);
79 79 assert(C->env()->system_dictionary_modification_counter_changed(),
80 80 "Must invalidate if TypeFuncs differ");
81 81 }
82 82 #endif
83 83
84 84 GraphKit& exits = parser.exits();
85 85
86 86 if (C->failing()) {
87 87 while (exits.pop_exception_state() != NULL) ;
88 88 return NULL;
89 89 }
90 90
91 91 assert(exits.jvms()->same_calls_as(jvms), "sanity");
92 92
93 93 // Simply return the exit state of the parser,
94 94 // augmented by any exceptional states.
95 95 return exits.transfer_exceptions_into_jvms();
96 96 }
97 97
98 98 //---------------------------DirectCallGenerator------------------------------
99 99 // Internal class which handles all out-of-line calls w/o receiver type checks.
100 100 class DirectCallGenerator : public CallGenerator {
101 101 private:
102 102 CallStaticJavaNode* _call_node;
103 103 // Force separate memory and I/O projections for the exceptional
104 104 // paths to facilitate late inlinig.
105 105 bool _separate_io_proj;
106 106
107 107 public:
108 108 DirectCallGenerator(ciMethod* method, bool separate_io_proj)
109 109 : CallGenerator(method),
110 110 _separate_io_proj(separate_io_proj)
111 111 {
112 112 }
113 113 virtual JVMState* generate(JVMState* jvms);
114 114
115 115 CallStaticJavaNode* call_node() const { return _call_node; }
116 116 };
117 117
118 118 JVMState* DirectCallGenerator::generate(JVMState* jvms) {
119 119 GraphKit kit(jvms);
120 120 bool is_static = method()->is_static();
121 121 address target = is_static ? SharedRuntime::get_resolve_static_call_stub()
122 122 : SharedRuntime::get_resolve_opt_virtual_call_stub();
123 123
124 124 if (kit.C->log() != NULL) {
125 125 kit.C->log()->elem("direct_call bci='%d'", jvms->bci());
126 126 }
127 127
128 128 CallStaticJavaNode *call = new (kit.C, tf()->domain()->cnt()) CallStaticJavaNode(tf(), target, method(), kit.bci());
↓ open down ↓ |
116 lines elided |
↑ open up ↑ |
129 129 if (!is_static) {
130 130 // Make an explicit receiver null_check as part of this call.
131 131 // Since we share a map with the caller, his JVMS gets adjusted.
132 132 kit.null_check_receiver(method());
133 133 if (kit.stopped()) {
134 134 // And dump it back to the caller, decorated with any exceptions:
135 135 return kit.transfer_exceptions_into_jvms();
136 136 }
137 137 // Mark the call node as virtual, sort of:
138 138 call->set_optimized_virtual(true);
139 + if (method()->is_method_handle_invoke())
140 + call->set_method_handle_invoke(true);
139 141 }
140 142 kit.set_arguments_for_java_call(call);
141 143 kit.set_edges_for_java_call(call, false, _separate_io_proj);
142 144 Node* ret = kit.set_results_for_java_call(call, _separate_io_proj);
143 145 kit.push_node(method()->return_type()->basic_type(), ret);
144 146 _call_node = call; // Save the call node in case we need it later
145 147 return kit.transfer_exceptions_into_jvms();
146 148 }
147 149
150 +//---------------------------DynamicCallGenerator-----------------------------
151 +// Internal class which handles all out-of-line dynamic calls.
152 +class DynamicCallGenerator : public CallGenerator {
153 +public:
154 + DynamicCallGenerator(ciMethod* method)
155 + : CallGenerator(method)
156 + {
157 + }
158 + virtual JVMState* generate(JVMState* jvms);
159 +};
160 +
161 +JVMState* DynamicCallGenerator::generate(JVMState* jvms) {
162 + GraphKit kit(jvms);
163 +
164 + if (kit.C->log() != NULL) {
165 + kit.C->log()->elem("dynamic_call bci='%d'", jvms->bci());
166 + }
167 +
168 + // Get the constant pool cache from the caller class.
169 + ciMethod* caller_method = jvms->method();
170 + ciBytecodeStream str(caller_method);
171 + str.force_bci(jvms->bci()); // Set the stream to the invokedynamic bci.
172 + assert(str.cur_bc() == Bytecodes::_invokedynamic, "wrong place to issue a dynamic call!");
173 + ciCPCache* cpcache = str.get_cpcache();
174 +
175 + // Get the offset of the CallSite from the constant pool cache
176 + // pointer.
177 + int index = str.get_method_index();
178 + size_t call_site_offset = cpcache->get_f1_offset(index);
179 +
180 + // Load the CallSite object from the constant pool cache.
181 + const TypeOopPtr* cpcache_ptr = TypeOopPtr::make_from_constant(cpcache);
182 + Node* cpc = kit.makecon(cpcache_ptr);
183 + Node* adr = kit.basic_plus_adr(cpc, cpc, call_site_offset);
184 + Node* call_site = kit.make_load(kit.control(), adr, TypeInstPtr::BOTTOM, T_OBJECT, Compile::AliasIdxRaw);
185 +
186 + // Load the MethodHandle (target) from the CallSite object.
187 + Node* mh_adr = kit.basic_plus_adr(call_site, call_site, java_dyn_CallSite::target_offset_in_bytes());
188 + Node* mh = kit.make_load(kit.control(), mh_adr, TypeInstPtr::BOTTOM, T_OBJECT);
189 +
190 + address stub = SharedRuntime::get_resolve_opt_virtual_call_stub();
191 +
192 + CallStaticJavaNode *call = new (kit.C, tf()->domain()->cnt()) CallStaticJavaNode(tf(), stub, method(), kit.bci());
193 + // invokedynamic is treated as an optimized invokevirtual.
194 + call->set_optimized_virtual(true);
195 + // Take extra care (in the presence of argument motion) not to trash the SP:
196 + call->set_method_handle_invoke(true);
197 +
198 + // Pass the MethodHandle as first argument and shift the other
199 + // arguments.
200 + call->init_req(0 + TypeFunc::Parms, mh);
201 + uint nargs = call->method()->arg_size();
202 + for (uint i = 1; i < nargs; i++) {
203 + Node* arg = kit.argument(i - 1);
204 + call->init_req(i + TypeFunc::Parms, arg);
205 + }
206 +
207 + kit.set_edges_for_java_call(call);
208 + Node* ret = kit.set_results_for_java_call(call);
209 + kit.push_node(method()->return_type()->basic_type(), ret);
210 + return kit.transfer_exceptions_into_jvms();
211 +}
212 +
213 +//--------------------------VirtualCallGenerator------------------------------
214 +// Internal class which handles all out-of-line calls checking receiver type.
148 215 class VirtualCallGenerator : public CallGenerator {
149 216 private:
150 217 int _vtable_index;
151 218 public:
152 219 VirtualCallGenerator(ciMethod* method, int vtable_index)
153 220 : CallGenerator(method), _vtable_index(vtable_index)
154 221 {
155 222 assert(vtable_index == methodOopDesc::invalid_vtable_index ||
156 223 vtable_index >= 0, "either invalid or usable");
157 224 }
158 225 virtual bool is_virtual() const { return true; }
159 226 virtual JVMState* generate(JVMState* jvms);
160 227 };
161 228
162 -//--------------------------VirtualCallGenerator------------------------------
163 -// Internal class which handles all out-of-line calls checking receiver type.
164 229 JVMState* VirtualCallGenerator::generate(JVMState* jvms) {
165 230 GraphKit kit(jvms);
166 231 Node* receiver = kit.argument(0);
167 232
168 233 if (kit.C->log() != NULL) {
169 234 kit.C->log()->elem("virtual_call bci='%d'", jvms->bci());
170 235 }
171 236
172 237 // If the receiver is a constant null, do not torture the system
173 238 // by attempting to call through it. The compile will proceed
174 239 // correctly, but may bail out in final_graph_reshaping, because
175 240 // the call instruction will have a seemingly deficient out-count.
176 241 // (The bailout says something misleading about an "infinite loop".)
177 242 if (kit.gvn().type(receiver)->higher_equal(TypePtr::NULL_PTR)) {
178 243 kit.inc_sp(method()->arg_size()); // restore arguments
179 244 kit.uncommon_trap(Deoptimization::Reason_null_check,
180 245 Deoptimization::Action_none,
181 246 NULL, "null receiver");
182 247 return kit.transfer_exceptions_into_jvms();
183 248 }
184 249
185 250 // Ideally we would unconditionally do a null check here and let it
186 251 // be converted to an implicit check based on profile information.
187 252 // However currently the conversion to implicit null checks in
188 253 // Block::implicit_null_check() only looks for loads and stores, not calls.
189 254 ciMethod *caller = kit.method();
190 255 ciMethodData *caller_md = (caller == NULL) ? NULL : caller->method_data();
191 256 if (!UseInlineCaches || !ImplicitNullChecks ||
192 257 ((ImplicitNullCheckThreshold > 0) && caller_md &&
193 258 (caller_md->trap_count(Deoptimization::Reason_null_check)
194 259 >= (uint)ImplicitNullCheckThreshold))) {
195 260 // Make an explicit receiver null_check as part of this call.
196 261 // Since we share a map with the caller, his JVMS gets adjusted.
197 262 receiver = kit.null_check_receiver(method());
198 263 if (kit.stopped()) {
199 264 // And dump it back to the caller, decorated with any exceptions:
200 265 return kit.transfer_exceptions_into_jvms();
201 266 }
202 267 }
203 268
204 269 assert(!method()->is_static(), "virtual call must not be to static");
205 270 assert(!method()->is_final(), "virtual call should not be to final");
206 271 assert(!method()->is_private(), "virtual call should not be to private");
207 272 assert(_vtable_index == methodOopDesc::invalid_vtable_index || !UseInlineCaches,
208 273 "no vtable calls if +UseInlineCaches ");
209 274 address target = SharedRuntime::get_resolve_virtual_call_stub();
210 275 // Normal inline cache used for call
211 276 CallDynamicJavaNode *call = new (kit.C, tf()->domain()->cnt()) CallDynamicJavaNode(tf(), target, method(), _vtable_index, kit.bci());
212 277 kit.set_arguments_for_java_call(call);
213 278 kit.set_edges_for_java_call(call);
214 279 Node* ret = kit.set_results_for_java_call(call);
215 280 kit.push_node(method()->return_type()->basic_type(), ret);
216 281
217 282 // Represent the effect of an implicit receiver null_check
218 283 // as part of this call. Since we share a map with the caller,
219 284 // his JVMS gets adjusted.
220 285 kit.cast_not_null(receiver);
221 286 return kit.transfer_exceptions_into_jvms();
222 287 }
223 288
224 289 bool ParseGenerator::can_parse(ciMethod* m, int entry_bci) {
225 290 // Certain methods cannot be parsed at all:
226 291 if (!m->can_be_compiled()) return false;
227 292 if (!m->has_balanced_monitors()) return false;
228 293 if (m->get_flow_analysis()->failing()) return false;
229 294
230 295 // (Methods may bail out for other reasons, after the parser is run.
231 296 // We try to avoid this, but if forced, we must return (Node*)NULL.
232 297 // The user of the CallGenerator must check for this condition.)
233 298 return true;
234 299 }
235 300
236 301 CallGenerator* CallGenerator::for_inline(ciMethod* m, float expected_uses) {
237 302 if (!ParseGenerator::can_parse(m)) return NULL;
238 303 return new ParseGenerator(m, expected_uses);
239 304 }
240 305
241 306 // As a special case, the JVMS passed to this CallGenerator is
242 307 // for the method execution already in progress, not just the JVMS
243 308 // of the caller. Thus, this CallGenerator cannot be mixed with others!
244 309 CallGenerator* CallGenerator::for_osr(ciMethod* m, int osr_bci) {
245 310 if (!ParseGenerator::can_parse(m, true)) return NULL;
↓ open down ↓ |
72 lines elided |
↑ open up ↑ |
246 311 float past_uses = m->interpreter_invocation_count();
247 312 float expected_uses = past_uses;
248 313 return new ParseGenerator(m, expected_uses, true);
249 314 }
250 315
251 316 CallGenerator* CallGenerator::for_direct_call(ciMethod* m, bool separate_io_proj) {
252 317 assert(!m->is_abstract(), "for_direct_call mismatch");
253 318 return new DirectCallGenerator(m, separate_io_proj);
254 319 }
255 320
321 +CallGenerator* CallGenerator::for_dynamic_call(ciMethod* m) {
322 + assert(m->is_method_handle_invoke(), "for_dynamic_call mismatch");
323 + return new DynamicCallGenerator(m);
324 +}
325 +
256 326 CallGenerator* CallGenerator::for_virtual_call(ciMethod* m, int vtable_index) {
257 327 assert(!m->is_static(), "for_virtual_call mismatch");
328 + assert(!m->is_method_handle_invoke(), "should be a direct call");
258 329 return new VirtualCallGenerator(m, vtable_index);
259 330 }
260 331
261 332 // Allow inlining decisions to be delayed
262 333 class LateInlineCallGenerator : public DirectCallGenerator {
263 334 CallGenerator* _inline_cg;
264 335
265 336 public:
266 337 LateInlineCallGenerator(ciMethod* method, CallGenerator* inline_cg) :
267 338 DirectCallGenerator(method, true), _inline_cg(inline_cg) {}
268 339
269 340 virtual bool is_late_inline() const { return true; }
270 341
271 342 // Convert the CallStaticJava into an inline
272 343 virtual void do_late_inline();
273 344
274 345 JVMState* generate(JVMState* jvms) {
275 346 // Record that this call site should be revisited once the main
276 347 // parse is finished.
277 348 Compile::current()->add_late_inline(this);
278 349
279 350 // Emit the CallStaticJava and request separate projections so
280 351 // that the late inlining logic can distinguish between fall
281 352 // through and exceptional uses of the memory and io projections
282 353 // as is done for allocations and macro expansion.
283 354 return DirectCallGenerator::generate(jvms);
284 355 }
285 356
286 357 };
287 358
288 359
289 360 void LateInlineCallGenerator::do_late_inline() {
290 361 // Can't inline it
291 362 if (call_node() == NULL || call_node()->outcnt() == 0 ||
292 363 call_node()->in(0) == NULL || call_node()->in(0)->is_top())
293 364 return;
294 365
295 366 CallStaticJavaNode* call = call_node();
296 367
297 368 // Make a clone of the JVMState that appropriate to use for driving a parse
298 369 Compile* C = Compile::current();
299 370 JVMState* jvms = call->jvms()->clone_shallow(C);
300 371 uint size = call->req();
301 372 SafePointNode* map = new (C, size) SafePointNode(size, jvms);
302 373 for (uint i1 = 0; i1 < size; i1++) {
303 374 map->init_req(i1, call->in(i1));
304 375 }
305 376
306 377 // Make sure the state is a MergeMem for parsing.
307 378 if (!map->in(TypeFunc::Memory)->is_MergeMem()) {
308 379 map->set_req(TypeFunc::Memory, MergeMemNode::make(C, map->in(TypeFunc::Memory)));
309 380 }
310 381
311 382 // Make enough space for the expression stack and transfer the incoming arguments
312 383 int nargs = method()->arg_size();
313 384 jvms->set_map(map);
314 385 map->ensure_stack(jvms, jvms->method()->max_stack());
315 386 if (nargs > 0) {
316 387 for (int i1 = 0; i1 < nargs; i1++) {
317 388 map->set_req(i1 + jvms->argoff(), call->in(TypeFunc::Parms + i1));
318 389 }
319 390 }
320 391
321 392 CompileLog* log = C->log();
322 393 if (log != NULL) {
323 394 log->head("late_inline method='%d'", log->identify(method()));
324 395 JVMState* p = jvms;
325 396 while (p != NULL) {
326 397 log->elem("jvms bci='%d' method='%d'", p->bci(), log->identify(p->method()));
327 398 p = p->caller();
328 399 }
329 400 log->tail("late_inline");
330 401 }
331 402
332 403 // Setup default node notes to be picked up by the inlining
333 404 Node_Notes* old_nn = C->default_node_notes();
334 405 if (old_nn != NULL) {
335 406 Node_Notes* entry_nn = old_nn->clone(C);
336 407 entry_nn->set_jvms(jvms);
337 408 C->set_default_node_notes(entry_nn);
338 409 }
339 410
340 411 // Now perform the inling using the synthesized JVMState
341 412 JVMState* new_jvms = _inline_cg->generate(jvms);
342 413 if (new_jvms == NULL) return; // no change
343 414 if (C->failing()) return;
344 415
345 416 // Capture any exceptional control flow
346 417 GraphKit kit(new_jvms);
347 418
348 419 // Find the result object
349 420 Node* result = C->top();
350 421 int result_size = method()->return_type()->size();
351 422 if (result_size != 0 && !kit.stopped()) {
352 423 result = (result_size == 1) ? kit.pop() : kit.pop_pair();
353 424 }
354 425
355 426 kit.replace_call(call, result);
356 427 }
357 428
358 429
359 430 CallGenerator* CallGenerator::for_late_inline(ciMethod* method, CallGenerator* inline_cg) {
360 431 return new LateInlineCallGenerator(method, inline_cg);
361 432 }
362 433
363 434
364 435 //---------------------------WarmCallGenerator--------------------------------
365 436 // Internal class which handles initial deferral of inlining decisions.
366 437 class WarmCallGenerator : public CallGenerator {
367 438 WarmCallInfo* _call_info;
368 439 CallGenerator* _if_cold;
369 440 CallGenerator* _if_hot;
370 441 bool _is_virtual; // caches virtuality of if_cold
371 442 bool _is_inline; // caches inline-ness of if_hot
372 443
373 444 public:
374 445 WarmCallGenerator(WarmCallInfo* ci,
375 446 CallGenerator* if_cold,
376 447 CallGenerator* if_hot)
377 448 : CallGenerator(if_cold->method())
378 449 {
379 450 assert(method() == if_hot->method(), "consistent choices");
380 451 _call_info = ci;
381 452 _if_cold = if_cold;
382 453 _if_hot = if_hot;
383 454 _is_virtual = if_cold->is_virtual();
384 455 _is_inline = if_hot->is_inline();
385 456 }
386 457
387 458 virtual bool is_inline() const { return _is_inline; }
388 459 virtual bool is_virtual() const { return _is_virtual; }
389 460 virtual bool is_deferred() const { return true; }
390 461
391 462 virtual JVMState* generate(JVMState* jvms);
392 463 };
393 464
394 465
395 466 CallGenerator* CallGenerator::for_warm_call(WarmCallInfo* ci,
396 467 CallGenerator* if_cold,
397 468 CallGenerator* if_hot) {
398 469 return new WarmCallGenerator(ci, if_cold, if_hot);
399 470 }
400 471
401 472 JVMState* WarmCallGenerator::generate(JVMState* jvms) {
402 473 Compile* C = Compile::current();
403 474 if (C->log() != NULL) {
404 475 C->log()->elem("warm_call bci='%d'", jvms->bci());
405 476 }
406 477 jvms = _if_cold->generate(jvms);
407 478 if (jvms != NULL) {
408 479 Node* m = jvms->map()->control();
409 480 if (m->is_CatchProj()) m = m->in(0); else m = C->top();
410 481 if (m->is_Catch()) m = m->in(0); else m = C->top();
411 482 if (m->is_Proj()) m = m->in(0); else m = C->top();
412 483 if (m->is_CallJava()) {
413 484 _call_info->set_call(m->as_Call());
414 485 _call_info->set_hot_cg(_if_hot);
415 486 #ifndef PRODUCT
416 487 if (PrintOpto || PrintOptoInlining) {
417 488 tty->print_cr("Queueing for warm inlining at bci %d:", jvms->bci());
418 489 tty->print("WCI: ");
419 490 _call_info->print();
420 491 }
421 492 #endif
422 493 _call_info->set_heat(_call_info->compute_heat());
423 494 C->set_warm_calls(_call_info->insert_into(C->warm_calls()));
424 495 }
425 496 }
426 497 return jvms;
427 498 }
428 499
429 500 void WarmCallInfo::make_hot() {
430 501 Unimplemented();
431 502 }
432 503
433 504 void WarmCallInfo::make_cold() {
434 505 // No action: Just dequeue.
435 506 }
436 507
437 508
438 509 //------------------------PredictedCallGenerator------------------------------
439 510 // Internal class which handles all out-of-line calls checking receiver type.
440 511 class PredictedCallGenerator : public CallGenerator {
441 512 ciKlass* _predicted_receiver;
442 513 CallGenerator* _if_missed;
443 514 CallGenerator* _if_hit;
444 515 float _hit_prob;
445 516
446 517 public:
447 518 PredictedCallGenerator(ciKlass* predicted_receiver,
448 519 CallGenerator* if_missed,
449 520 CallGenerator* if_hit, float hit_prob)
450 521 : CallGenerator(if_missed->method())
451 522 {
452 523 // The call profile data may predict the hit_prob as extreme as 0 or 1.
453 524 // Remove the extremes values from the range.
454 525 if (hit_prob > PROB_MAX) hit_prob = PROB_MAX;
455 526 if (hit_prob < PROB_MIN) hit_prob = PROB_MIN;
456 527
457 528 _predicted_receiver = predicted_receiver;
458 529 _if_missed = if_missed;
459 530 _if_hit = if_hit;
460 531 _hit_prob = hit_prob;
461 532 }
462 533
463 534 virtual bool is_virtual() const { return true; }
464 535 virtual bool is_inline() const { return _if_hit->is_inline(); }
465 536 virtual bool is_deferred() const { return _if_hit->is_deferred(); }
466 537
467 538 virtual JVMState* generate(JVMState* jvms);
468 539 };
469 540
470 541
471 542 CallGenerator* CallGenerator::for_predicted_call(ciKlass* predicted_receiver,
472 543 CallGenerator* if_missed,
473 544 CallGenerator* if_hit,
474 545 float hit_prob) {
475 546 return new PredictedCallGenerator(predicted_receiver, if_missed, if_hit, hit_prob);
476 547 }
477 548
478 549
479 550 JVMState* PredictedCallGenerator::generate(JVMState* jvms) {
480 551 GraphKit kit(jvms);
481 552 PhaseGVN& gvn = kit.gvn();
482 553 // We need an explicit receiver null_check before checking its type.
483 554 // We share a map with the caller, so his JVMS gets adjusted.
484 555 Node* receiver = kit.argument(0);
485 556
486 557 CompileLog* log = kit.C->log();
487 558 if (log != NULL) {
488 559 log->elem("predicted_call bci='%d' klass='%d'",
489 560 jvms->bci(), log->identify(_predicted_receiver));
490 561 }
491 562
492 563 receiver = kit.null_check_receiver(method());
493 564 if (kit.stopped()) {
494 565 return kit.transfer_exceptions_into_jvms();
495 566 }
496 567
497 568 Node* exact_receiver = receiver; // will get updated in place...
498 569 Node* slow_ctl = kit.type_check_receiver(receiver,
499 570 _predicted_receiver, _hit_prob,
500 571 &exact_receiver);
501 572
502 573 SafePointNode* slow_map = NULL;
503 574 JVMState* slow_jvms;
504 575 { PreserveJVMState pjvms(&kit);
505 576 kit.set_control(slow_ctl);
506 577 if (!kit.stopped()) {
507 578 slow_jvms = _if_missed->generate(kit.sync_jvms());
508 579 assert(slow_jvms != NULL, "miss path must not fail to generate");
509 580 kit.add_exception_states_from(slow_jvms);
510 581 kit.set_map(slow_jvms->map());
511 582 if (!kit.stopped())
512 583 slow_map = kit.stop();
513 584 }
514 585 }
515 586
516 587 if (kit.stopped()) {
517 588 // Instance exactly does not matches the desired type.
518 589 kit.set_jvms(slow_jvms);
519 590 return kit.transfer_exceptions_into_jvms();
520 591 }
521 592
522 593 // fall through if the instance exactly matches the desired type
523 594 kit.replace_in_map(receiver, exact_receiver);
524 595
525 596 // Make the hot call:
526 597 JVMState* new_jvms = _if_hit->generate(kit.sync_jvms());
527 598 if (new_jvms == NULL) {
528 599 // Inline failed, so make a direct call.
529 600 assert(_if_hit->is_inline(), "must have been a failed inline");
530 601 CallGenerator* cg = CallGenerator::for_direct_call(_if_hit->method());
531 602 new_jvms = cg->generate(kit.sync_jvms());
532 603 }
533 604 kit.add_exception_states_from(new_jvms);
534 605 kit.set_jvms(new_jvms);
535 606
536 607 // Need to merge slow and fast?
537 608 if (slow_map == NULL) {
538 609 // The fast path is the only path remaining.
539 610 return kit.transfer_exceptions_into_jvms();
540 611 }
541 612
542 613 if (kit.stopped()) {
543 614 // Inlined method threw an exception, so it's just the slow path after all.
544 615 kit.set_jvms(slow_jvms);
545 616 return kit.transfer_exceptions_into_jvms();
546 617 }
547 618
548 619 // Finish the diamond.
549 620 kit.C->set_has_split_ifs(true); // Has chance for split-if optimization
550 621 RegionNode* region = new (kit.C, 3) RegionNode(3);
551 622 region->init_req(1, kit.control());
552 623 region->init_req(2, slow_map->control());
553 624 kit.set_control(gvn.transform(region));
554 625 Node* iophi = PhiNode::make(region, kit.i_o(), Type::ABIO);
555 626 iophi->set_req(2, slow_map->i_o());
556 627 kit.set_i_o(gvn.transform(iophi));
557 628 kit.merge_memory(slow_map->merged_memory(), region, 2);
558 629 uint tos = kit.jvms()->stkoff() + kit.sp();
559 630 uint limit = slow_map->req();
560 631 for (uint i = TypeFunc::Parms; i < limit; i++) {
561 632 // Skip unused stack slots; fast forward to monoff();
562 633 if (i == tos) {
563 634 i = kit.jvms()->monoff();
564 635 if( i >= limit ) break;
565 636 }
566 637 Node* m = kit.map()->in(i);
567 638 Node* n = slow_map->in(i);
568 639 if (m != n) {
569 640 const Type* t = gvn.type(m)->meet(gvn.type(n));
570 641 Node* phi = PhiNode::make(region, m, t);
571 642 phi->set_req(2, n);
572 643 kit.map()->set_req(i, gvn.transform(phi));
573 644 }
574 645 }
575 646 return kit.transfer_exceptions_into_jvms();
576 647 }
577 648
578 649
579 650 //-------------------------UncommonTrapCallGenerator-----------------------------
580 651 // Internal class which handles all out-of-line calls checking receiver type.
581 652 class UncommonTrapCallGenerator : public CallGenerator {
582 653 Deoptimization::DeoptReason _reason;
583 654 Deoptimization::DeoptAction _action;
584 655
585 656 public:
586 657 UncommonTrapCallGenerator(ciMethod* m,
587 658 Deoptimization::DeoptReason reason,
588 659 Deoptimization::DeoptAction action)
589 660 : CallGenerator(m)
590 661 {
591 662 _reason = reason;
592 663 _action = action;
593 664 }
594 665
595 666 virtual bool is_virtual() const { ShouldNotReachHere(); return false; }
596 667 virtual bool is_trap() const { return true; }
597 668
598 669 virtual JVMState* generate(JVMState* jvms);
599 670 };
600 671
601 672
602 673 CallGenerator*
603 674 CallGenerator::for_uncommon_trap(ciMethod* m,
604 675 Deoptimization::DeoptReason reason,
605 676 Deoptimization::DeoptAction action) {
606 677 return new UncommonTrapCallGenerator(m, reason, action);
607 678 }
608 679
609 680
610 681 JVMState* UncommonTrapCallGenerator::generate(JVMState* jvms) {
611 682 GraphKit kit(jvms);
612 683 // Take the trap with arguments pushed on the stack. (Cf. null_check_receiver).
613 684 int nargs = method()->arg_size();
614 685 kit.inc_sp(nargs);
615 686 assert(nargs <= kit.sp() && kit.sp() <= jvms->stk_size(), "sane sp w/ args pushed");
616 687 if (_reason == Deoptimization::Reason_class_check &&
617 688 _action == Deoptimization::Action_maybe_recompile) {
618 689 // Temp fix for 6529811
619 690 // Don't allow uncommon_trap to override our decision to recompile in the event
620 691 // of a class cast failure for a monomorphic call as it will never let us convert
621 692 // the call to either bi-morphic or megamorphic and can lead to unc-trap loops
622 693 bool keep_exact_action = true;
623 694 kit.uncommon_trap(_reason, _action, NULL, "monomorphic vcall checkcast", false, keep_exact_action);
624 695 } else {
625 696 kit.uncommon_trap(_reason, _action);
626 697 }
627 698 return kit.transfer_exceptions_into_jvms();
628 699 }
629 700
630 701 // (Note: Moved hook_up_call to GraphKit::set_edges_for_java_call.)
631 702
632 703 // (Node: Merged hook_up_exits into ParseGenerator::generate.)
633 704
634 705 #define NODES_OVERHEAD_PER_METHOD (30.0)
635 706 #define NODES_PER_BYTECODE (9.5)
636 707
637 708 void WarmCallInfo::init(JVMState* call_site, ciMethod* call_method, ciCallProfile& profile, float prof_factor) {
638 709 int call_count = profile.count();
639 710 int code_size = call_method->code_size();
640 711
641 712 // Expected execution count is based on the historical count:
642 713 _count = call_count < 0 ? 1 : call_site->method()->scale_count(call_count, prof_factor);
643 714
644 715 // Expected profit from inlining, in units of simple call-overheads.
645 716 _profit = 1.0;
646 717
647 718 // Expected work performed by the call in units of call-overheads.
648 719 // %%% need an empirical curve fit for "work" (time in call)
649 720 float bytecodes_per_call = 3;
650 721 _work = 1.0 + code_size / bytecodes_per_call;
651 722
652 723 // Expected size of compilation graph:
653 724 // -XX:+PrintParseStatistics once reported:
654 725 // Methods seen: 9184 Methods parsed: 9184 Nodes created: 1582391
655 726 // Histogram of 144298 parsed bytecodes:
656 727 // %%% Need an better predictor for graph size.
657 728 _size = NODES_OVERHEAD_PER_METHOD + (NODES_PER_BYTECODE * code_size);
658 729 }
659 730
660 731 // is_cold: Return true if the node should never be inlined.
661 732 // This is true if any of the key metrics are extreme.
662 733 bool WarmCallInfo::is_cold() const {
663 734 if (count() < WarmCallMinCount) return true;
664 735 if (profit() < WarmCallMinProfit) return true;
665 736 if (work() > WarmCallMaxWork) return true;
666 737 if (size() > WarmCallMaxSize) return true;
667 738 return false;
668 739 }
669 740
670 741 // is_hot: Return true if the node should be inlined immediately.
671 742 // This is true if any of the key metrics are extreme.
672 743 bool WarmCallInfo::is_hot() const {
673 744 assert(!is_cold(), "eliminate is_cold cases before testing is_hot");
674 745 if (count() >= HotCallCountThreshold) return true;
675 746 if (profit() >= HotCallProfitThreshold) return true;
676 747 if (work() <= HotCallTrivialWork) return true;
677 748 if (size() <= HotCallTrivialSize) return true;
678 749 return false;
679 750 }
680 751
681 752 // compute_heat:
682 753 float WarmCallInfo::compute_heat() const {
683 754 assert(!is_cold(), "compute heat only on warm nodes");
684 755 assert(!is_hot(), "compute heat only on warm nodes");
685 756 int min_size = MAX2(0, (int)HotCallTrivialSize);
686 757 int max_size = MIN2(500, (int)WarmCallMaxSize);
687 758 float method_size = (size() - min_size) / MAX2(1, max_size - min_size);
688 759 float size_factor;
689 760 if (method_size < 0.05) size_factor = 4; // 2 sigmas better than avg.
690 761 else if (method_size < 0.15) size_factor = 2; // 1 sigma better than avg.
691 762 else if (method_size < 0.5) size_factor = 1; // better than avg.
692 763 else size_factor = 0.5; // worse than avg.
693 764 return (count() * profit() * size_factor);
694 765 }
695 766
696 767 bool WarmCallInfo::warmer_than(WarmCallInfo* that) {
697 768 assert(this != that, "compare only different WCIs");
698 769 assert(this->heat() != 0 && that->heat() != 0, "call compute_heat 1st");
699 770 if (this->heat() > that->heat()) return true;
700 771 if (this->heat() < that->heat()) return false;
701 772 assert(this->heat() == that->heat(), "no NaN heat allowed");
702 773 // Equal heat. Break the tie some other way.
703 774 if (!this->call() || !that->call()) return (address)this > (address)that;
704 775 return this->call()->_idx > that->call()->_idx;
705 776 }
706 777
707 778 //#define UNINIT_NEXT ((WarmCallInfo*)badAddress)
708 779 #define UNINIT_NEXT ((WarmCallInfo*)NULL)
709 780
710 781 WarmCallInfo* WarmCallInfo::insert_into(WarmCallInfo* head) {
711 782 assert(next() == UNINIT_NEXT, "not yet on any list");
712 783 WarmCallInfo* prev_p = NULL;
713 784 WarmCallInfo* next_p = head;
714 785 while (next_p != NULL && next_p->warmer_than(this)) {
715 786 prev_p = next_p;
716 787 next_p = prev_p->next();
717 788 }
718 789 // Install this between prev_p and next_p.
719 790 this->set_next(next_p);
720 791 if (prev_p == NULL)
721 792 head = this;
722 793 else
723 794 prev_p->set_next(this);
724 795 return head;
725 796 }
726 797
727 798 WarmCallInfo* WarmCallInfo::remove_from(WarmCallInfo* head) {
728 799 WarmCallInfo* prev_p = NULL;
729 800 WarmCallInfo* next_p = head;
730 801 while (next_p != this) {
731 802 assert(next_p != NULL, "this must be in the list somewhere");
732 803 prev_p = next_p;
733 804 next_p = prev_p->next();
734 805 }
735 806 next_p = this->next();
736 807 debug_only(this->set_next(UNINIT_NEXT));
737 808 // Remove this from between prev_p and next_p.
738 809 if (prev_p == NULL)
739 810 head = next_p;
740 811 else
741 812 prev_p->set_next(next_p);
742 813 return head;
743 814 }
744 815
745 816 WarmCallInfo* WarmCallInfo::_always_hot = NULL;
746 817 WarmCallInfo* WarmCallInfo::_always_cold = NULL;
747 818
748 819 WarmCallInfo* WarmCallInfo::always_hot() {
749 820 if (_always_hot == NULL) {
750 821 static double bits[sizeof(WarmCallInfo) / sizeof(double) + 1] = {0};
751 822 WarmCallInfo* ci = (WarmCallInfo*) bits;
752 823 ci->_profit = ci->_count = MAX_VALUE();
753 824 ci->_work = ci->_size = MIN_VALUE();
754 825 _always_hot = ci;
755 826 }
756 827 assert(_always_hot->is_hot(), "must always be hot");
757 828 return _always_hot;
758 829 }
759 830
760 831 WarmCallInfo* WarmCallInfo::always_cold() {
761 832 if (_always_cold == NULL) {
762 833 static double bits[sizeof(WarmCallInfo) / sizeof(double) + 1] = {0};
763 834 WarmCallInfo* ci = (WarmCallInfo*) bits;
764 835 ci->_profit = ci->_count = MIN_VALUE();
765 836 ci->_work = ci->_size = MAX_VALUE();
766 837 _always_cold = ci;
767 838 }
768 839 assert(_always_cold->is_cold(), "must always be cold");
769 840 return _always_cold;
770 841 }
771 842
772 843
773 844 #ifndef PRODUCT
774 845
775 846 void WarmCallInfo::print() const {
776 847 tty->print("%s : C=%6.1f P=%6.1f W=%6.1f S=%6.1f H=%6.1f -> %p",
777 848 is_cold() ? "cold" : is_hot() ? "hot " : "warm",
778 849 count(), profit(), work(), size(), compute_heat(), next());
779 850 tty->cr();
780 851 if (call() != NULL) call()->dump();
781 852 }
782 853
783 854 void print_wci(WarmCallInfo* ci) {
784 855 ci->print();
785 856 }
786 857
787 858 void WarmCallInfo::print_all() const {
788 859 for (const WarmCallInfo* p = this; p != NULL; p = p->next())
789 860 p->print();
790 861 }
791 862
792 863 int WarmCallInfo::count_all() const {
793 864 int cnt = 0;
794 865 for (const WarmCallInfo* p = this; p != NULL; p = p->next())
795 866 cnt++;
796 867 return cnt;
797 868 }
798 869
799 870 #endif //PRODUCT
↓ open down ↓ |
532 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX