Mercurial > hg > truffle
comparison src/share/vm/runtime/compilationPolicy.cpp @ 10408:836a62f43af9
Merge with http://hg.openjdk.java.net/hsx/hsx25/hotspot/
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Wed, 19 Jun 2013 10:45:56 +0200 |
parents | 3ce140f4f2c9 d1c9384eecb4 |
children | 36bcc10e01c0 |
comparison
equal
deleted
inserted
replaced
10086:e0fb8a213650 | 10408:836a62f43af9 |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. | 2 * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
114 (UseCompiler && AlwaysCompileLoopMethods && m->has_loops() && CompileBroker::should_compile_new_jobs()); // eagerly compile loop methods | 114 (UseCompiler && AlwaysCompileLoopMethods && m->has_loops() && CompileBroker::should_compile_new_jobs()); // eagerly compile loop methods |
115 } | 115 } |
116 | 116 |
117 // Returns true if m is allowed to be compiled | 117 // Returns true if m is allowed to be compiled |
118 bool CompilationPolicy::can_be_compiled(methodHandle m, int comp_level) { | 118 bool CompilationPolicy::can_be_compiled(methodHandle m, int comp_level) { |
119 // allow any levels for WhiteBox | |
120 assert(WhiteBoxAPI || comp_level == CompLevel_all || is_compile(comp_level), "illegal compilation level"); | |
121 | |
119 if (m->is_abstract()) return false; | 122 if (m->is_abstract()) return false; |
120 if (DontCompileHugeMethods && m->code_size() > HugeMethodLimit) return false; | 123 if (DontCompileHugeMethods && m->code_size() > HugeMethodLimit) return false; |
121 | 124 |
122 // Math intrinsics should never be compiled as this can lead to | 125 // Math intrinsics should never be compiled as this can lead to |
123 // monotonicity problems because the interpreter will prefer the | 126 // monotonicity problems because the interpreter will prefer the |
127 // modes. | 130 // modes. |
128 if (!AbstractInterpreter::can_be_compiled(m)) { | 131 if (!AbstractInterpreter::can_be_compiled(m)) { |
129 return false; | 132 return false; |
130 } | 133 } |
131 if (comp_level == CompLevel_all) { | 134 if (comp_level == CompLevel_all) { |
132 return !m->is_not_compilable(CompLevel_simple) && !m->is_not_compilable(CompLevel_full_optimization); | 135 if (TieredCompilation) { |
136 // enough to be compilable at any level for tiered | |
137 return !m->is_not_compilable(CompLevel_simple) || !m->is_not_compilable(CompLevel_full_optimization); | |
138 } else { | |
139 // must be compilable at available level for non-tiered | |
140 return !m->is_not_compilable(CompLevel_highest_tier); | |
141 } | |
133 } else if (is_compile(comp_level)) { | 142 } else if (is_compile(comp_level)) { |
134 return !m->is_not_compilable(comp_level); | 143 return !m->is_not_compilable(comp_level); |
135 } | 144 } |
136 return false; | 145 return false; |
137 } | 146 } |
203 // Make sure invocation and backedge counter doesn't overflow again right away | 212 // Make sure invocation and backedge counter doesn't overflow again right away |
204 // as would be the case for native methods. | 213 // as would be the case for native methods. |
205 | 214 |
206 // BUT also make sure the method doesn't look like it was never executed. | 215 // BUT also make sure the method doesn't look like it was never executed. |
207 // Set carry bit and reduce counter's value to min(count, CompileThreshold/2). | 216 // Set carry bit and reduce counter's value to min(count, CompileThreshold/2). |
208 m->invocation_counter()->set_carry(); | 217 MethodCounters* mcs = m->method_counters(); |
209 m->backedge_counter()->set_carry(); | 218 assert(mcs != NULL, "MethodCounters cannot be NULL for profiling"); |
219 mcs->invocation_counter()->set_carry(); | |
220 mcs->backedge_counter()->set_carry(); | |
210 | 221 |
211 assert(!m->was_never_executed(), "don't reset to 0 -- could be mistaken for never-executed"); | 222 assert(!m->was_never_executed(), "don't reset to 0 -- could be mistaken for never-executed"); |
212 } | 223 } |
213 | 224 |
214 void NonTieredCompPolicy::reset_counter_for_back_branch_event(methodHandle m) { | 225 void NonTieredCompPolicy::reset_counter_for_back_branch_event(methodHandle m) { |
215 // Delay next back-branch event but pump up invocation counter to triger | 226 // Delay next back-branch event but pump up invocation counter to triger |
216 // whole method compilation. | 227 // whole method compilation. |
217 InvocationCounter* i = m->invocation_counter(); | 228 MethodCounters* mcs = m->method_counters(); |
218 InvocationCounter* b = m->backedge_counter(); | 229 assert(mcs != NULL, "MethodCounters cannot be NULL for profiling"); |
230 InvocationCounter* i = mcs->invocation_counter(); | |
231 InvocationCounter* b = mcs->backedge_counter(); | |
219 | 232 |
220 // Don't set invocation_counter's value too low otherwise the method will | 233 // Don't set invocation_counter's value too low otherwise the method will |
221 // look like immature (ic < ~5300) which prevents the inlining based on | 234 // look like immature (ic < ~5300) which prevents the inlining based on |
222 // the type profiling. | 235 // the type profiling. |
223 i->set(i->state(), CompileThreshold); | 236 i->set(i->state(), CompileThreshold); |
232 // is done at each safepoint. | 245 // is done at each safepoint. |
233 // | 246 // |
234 class CounterDecay : public AllStatic { | 247 class CounterDecay : public AllStatic { |
235 static jlong _last_timestamp; | 248 static jlong _last_timestamp; |
236 static void do_method(Method* m) { | 249 static void do_method(Method* m) { |
237 m->invocation_counter()->decay(); | 250 MethodCounters* mcs = m->method_counters(); |
251 if (mcs != NULL) { | |
252 mcs->invocation_counter()->decay(); | |
253 } | |
238 } | 254 } |
239 public: | 255 public: |
240 static void decay(); | 256 static void decay(); |
241 static bool is_decay_needed() { | 257 static bool is_decay_needed() { |
242 return (os::javaTimeMillis() - _last_timestamp) > CounterDecayMinIntervalLength; | 258 return (os::javaTimeMillis() - _last_timestamp) > CounterDecayMinIntervalLength; |
270 } | 286 } |
271 } | 287 } |
272 | 288 |
273 void NonTieredCompPolicy::reprofile(ScopeDesc* trap_scope, bool is_osr) { | 289 void NonTieredCompPolicy::reprofile(ScopeDesc* trap_scope, bool is_osr) { |
274 ScopeDesc* sd = trap_scope; | 290 ScopeDesc* sd = trap_scope; |
291 MethodCounters* mcs; | |
292 InvocationCounter* c; | |
275 for (; !sd->is_top(); sd = sd->sender()) { | 293 for (; !sd->is_top(); sd = sd->sender()) { |
276 // Reset ICs of inlined methods, since they can trigger compilations also. | 294 mcs = sd->method()->method_counters(); |
277 sd->method()->invocation_counter()->reset(); | 295 if (mcs != NULL) { |
278 } | 296 // Reset ICs of inlined methods, since they can trigger compilations also. |
279 InvocationCounter* c = sd->method()->invocation_counter(); | 297 mcs->invocation_counter()->reset(); |
280 if (is_osr) { | 298 } |
281 // It was an OSR method, so bump the count higher. | 299 } |
282 c->set(c->state(), CompileThreshold); | 300 mcs = sd->method()->method_counters(); |
283 } else { | 301 if (mcs != NULL) { |
284 c->reset(); | 302 c = mcs->invocation_counter(); |
285 } | 303 if (is_osr) { |
286 sd->method()->backedge_counter()->reset(); | 304 // It was an OSR method, so bump the count higher. |
305 c->set(c->state(), CompileThreshold); | |
306 } else { | |
307 c->reset(); | |
308 } | |
309 mcs->backedge_counter()->reset(); | |
310 } | |
287 } | 311 } |
288 | 312 |
289 // This method can be called by any component of the runtime to notify the policy | 313 // This method can be called by any component of the runtime to notify the policy |
290 // that it's recommended to delay the complation of this method. | 314 // that it's recommended to delay the complation of this method. |
291 void NonTieredCompPolicy::delay_compilation(Method* method) { | 315 void NonTieredCompPolicy::delay_compilation(Method* method) { |
292 method->invocation_counter()->decay(); | 316 MethodCounters* mcs = method->method_counters(); |
293 method->backedge_counter()->decay(); | 317 if (mcs != NULL) { |
318 mcs->invocation_counter()->decay(); | |
319 mcs->backedge_counter()->decay(); | |
320 } | |
294 } | 321 } |
295 | 322 |
296 void NonTieredCompPolicy::disable_compilation(Method* method) { | 323 void NonTieredCompPolicy::disable_compilation(Method* method) { |
297 method->invocation_counter()->set_state(InvocationCounter::wait_for_nothing); | 324 MethodCounters* mcs = method->method_counters(); |
298 method->backedge_counter()->set_state(InvocationCounter::wait_for_nothing); | 325 if (mcs != NULL) { |
326 mcs->invocation_counter()->set_state(InvocationCounter::wait_for_nothing); | |
327 mcs->backedge_counter()->set_state(InvocationCounter::wait_for_nothing); | |
328 } | |
299 } | 329 } |
300 | 330 |
301 CompileTask* NonTieredCompPolicy::select_task(CompileQueue* compile_queue) { | 331 CompileTask* NonTieredCompPolicy::select_task(CompileQueue* compile_queue) { |
302 return compile_queue->first(); | 332 return compile_queue->first(); |
303 } | 333 } |
376 } | 406 } |
377 | 407 |
378 #ifndef PRODUCT | 408 #ifndef PRODUCT |
379 void NonTieredCompPolicy::trace_frequency_counter_overflow(methodHandle m, int branch_bci, int bci) { | 409 void NonTieredCompPolicy::trace_frequency_counter_overflow(methodHandle m, int branch_bci, int bci) { |
380 if (TraceInvocationCounterOverflow) { | 410 if (TraceInvocationCounterOverflow) { |
381 InvocationCounter* ic = m->invocation_counter(); | 411 MethodCounters* mcs = m->method_counters(); |
382 InvocationCounter* bc = m->backedge_counter(); | 412 assert(mcs != NULL, "MethodCounters cannot be NULL for profiling"); |
413 InvocationCounter* ic = mcs->invocation_counter(); | |
414 InvocationCounter* bc = mcs->backedge_counter(); | |
383 ResourceMark rm; | 415 ResourceMark rm; |
384 const char* msg = | 416 const char* msg = |
385 bci == InvocationEntryBci | 417 bci == InvocationEntryBci |
386 ? "comp-policy cntr ovfl @ %d in entry of " | 418 ? "comp-policy cntr ovfl @ %d in entry of " |
387 : "comp-policy cntr ovfl @ %d in loop of "; | 419 : "comp-policy cntr ovfl @ %d in loop of "; |
418 const int comp_level = CompLevel_highest_tier; | 450 const int comp_level = CompLevel_highest_tier; |
419 const int hot_count = m->invocation_count(); | 451 const int hot_count = m->invocation_count(); |
420 reset_counter_for_invocation_event(m); | 452 reset_counter_for_invocation_event(m); |
421 const char* comment = "count"; | 453 const char* comment = "count"; |
422 | 454 |
423 if (is_compilation_enabled() && can_be_compiled(m)) { | 455 if (is_compilation_enabled() && can_be_compiled(m, comp_level)) { |
424 nmethod* nm = m->code(); | 456 nmethod* nm = m->code(); |
425 #ifdef GRAALVM | 457 #ifdef GRAALVM |
426 if (m->queued_for_compilation()) { | 458 if (m->queued_for_compilation()) { |
427 delay_compilation(m()); | 459 delay_compilation(m()); |
428 } else | 460 } else |
436 void SimpleCompPolicy::method_back_branch_event(methodHandle m, int bci, JavaThread* thread) { | 468 void SimpleCompPolicy::method_back_branch_event(methodHandle m, int bci, JavaThread* thread) { |
437 const int comp_level = CompLevel_highest_tier; | 469 const int comp_level = CompLevel_highest_tier; |
438 const int hot_count = m->backedge_count(); | 470 const int hot_count = m->backedge_count(); |
439 const char* comment = "backedge_count"; | 471 const char* comment = "backedge_count"; |
440 | 472 |
441 if (is_compilation_enabled() && !m->is_not_osr_compilable(comp_level) && can_be_compiled(m)) { | 473 if (is_compilation_enabled() && !m->is_not_osr_compilable(comp_level) && can_be_compiled(m, comp_level)) { |
442 CompileBroker::compile_method(m, bci, comp_level, m, hot_count, comment, thread); | 474 CompileBroker::compile_method(m, bci, comp_level, m, hot_count, comment, thread); |
443 NOT_PRODUCT(trace_osr_completion(m->lookup_osr_nmethod_for(bci, comp_level, true));) | 475 NOT_PRODUCT(trace_osr_completion(m->lookup_osr_nmethod_for(bci, comp_level, true));) |
444 } | 476 } |
445 } | 477 } |
446 | 478 |
447 // GraalCompPolicy - compile current method | 479 // GraalCompPolicy - compile current method |
448 | 480 |
449 #ifdef GRAALVM | 481 #ifdef GRAALVM |
450 | 482 |
451 void GraalCompPolicy::method_invocation_event(methodHandle m, JavaThread* thread) { | 483 void GraalCompPolicy::method_invocation_event(methodHandle m, JavaThread* thread) { |
484 MethodCounters* mcs = m->method_counters(); | |
452 int hot_count = m->invocation_count(); | 485 int hot_count = m->invocation_count(); |
453 jlong hot_time = m->graal_invocation_time(); | 486 jlong hot_time = (mcs == NULL) ? 0 : mcs->graal_invocation_time(); |
454 reset_counter_for_invocation_event(m); | 487 reset_counter_for_invocation_event(m); |
455 | 488 |
456 if (is_compilation_enabled() && can_be_compiled(m)) { | 489 if (is_compilation_enabled() && can_be_compiled(m)) { |
457 nmethod* nm = m->code(); | 490 nmethod* nm = m->code(); |
458 if (nm == NULL) { | 491 if (nm == NULL) { |
459 if (hot_count > 1) { | 492 if (hot_count > 1) { |
460 jlong current_time = os::javaTimeNanos(); | 493 jlong current_time = os::javaTimeNanos(); |
461 int time_per_call = (int) ((current_time - hot_time) / hot_count); | 494 int time_per_call = (int) ((current_time - hot_time) / hot_count); |
462 m->set_graal_invocation_time(current_time); | 495 if (mcs != NULL) { |
496 mcs->set_graal_invocation_time(current_time); | |
497 } | |
463 if (UseNewCode) { | 498 if (UseNewCode) { |
464 if (m->queued_for_compilation()) { | 499 if (m->queued_for_compilation()) { |
465 if (time_per_call < (m->graal_priority() / 5)) { | 500 if (time_per_call < (m->graal_priority() / 5)) { |
466 m->set_graal_priority(time_per_call); | 501 m->set_graal_priority(time_per_call); |
467 m->clear_queued_for_compilation(); | 502 m->clear_queued_for_compilation(); |
523 const int comp_level = CompLevel_highest_tier; | 558 const int comp_level = CompLevel_highest_tier; |
524 const int hot_count = m->invocation_count(); | 559 const int hot_count = m->invocation_count(); |
525 reset_counter_for_invocation_event(m); | 560 reset_counter_for_invocation_event(m); |
526 const char* comment = "count"; | 561 const char* comment = "count"; |
527 | 562 |
528 if (is_compilation_enabled() && m->code() == NULL && can_be_compiled(m)) { | 563 if (is_compilation_enabled() && m->code() == NULL && can_be_compiled(m, comp_level)) { |
529 ResourceMark rm(thread); | 564 ResourceMark rm(thread); |
530 frame fr = thread->last_frame(); | 565 frame fr = thread->last_frame(); |
531 assert(fr.is_interpreted_frame(), "must be interpreted"); | 566 assert(fr.is_interpreted_frame(), "must be interpreted"); |
532 assert(fr.interpreter_frame_method() == m(), "bad method"); | 567 assert(fr.interpreter_frame_method() == m(), "bad method"); |
533 | 568 |
561 void StackWalkCompPolicy::method_back_branch_event(methodHandle m, int bci, JavaThread* thread) { | 596 void StackWalkCompPolicy::method_back_branch_event(methodHandle m, int bci, JavaThread* thread) { |
562 const int comp_level = CompLevel_highest_tier; | 597 const int comp_level = CompLevel_highest_tier; |
563 const int hot_count = m->backedge_count(); | 598 const int hot_count = m->backedge_count(); |
564 const char* comment = "backedge_count"; | 599 const char* comment = "backedge_count"; |
565 | 600 |
566 if (is_compilation_enabled() && !m->is_not_osr_compilable(comp_level) && can_be_compiled(m)) { | 601 if (is_compilation_enabled() && !m->is_not_osr_compilable(comp_level) && can_be_compiled(m, comp_level)) { |
567 CompileBroker::compile_method(m, bci, comp_level, m, hot_count, comment, thread); | 602 CompileBroker::compile_method(m, bci, comp_level, m, hot_count, comment, thread); |
568 NOT_PRODUCT(trace_osr_completion(m->lookup_osr_nmethod_for(bci, comp_level, true));) | 603 NOT_PRODUCT(trace_osr_completion(m->lookup_osr_nmethod_for(bci, comp_level, true));) |
569 } | 604 } |
570 } | 605 } |
571 | 606 |
656 } | 691 } |
657 | 692 |
658 | 693 |
659 // If the caller method is too big or something then we do not want to | 694 // If the caller method is too big or something then we do not want to |
660 // compile it just to inline a method | 695 // compile it just to inline a method |
661 if (!can_be_compiled(next_m)) { | 696 if (!can_be_compiled(next_m, CompLevel_any)) { |
662 msg = "caller cannot be compiled"; | 697 msg = "caller cannot be compiled"; |
663 break; | 698 break; |
664 } | 699 } |
665 | 700 |
666 if( next_m->name() == vmSymbols::class_initializer_name() ) { | 701 if( next_m->name() == vmSymbols::class_initializer_name() ) { |