comparison src/share/vm/runtime/compilationPolicy.cpp @ 6948:e522a00b91aa

Merge with http://hg.openjdk.java.net/hsx/hsx25/hotspot/ after NPG - C++ build works
author Doug Simon <doug.simon@oracle.com>
date Mon, 12 Nov 2012 23:14:12 +0100
parents fd71ca8c5f88 18fb7da42534
children 2cb439954abf
comparison
equal deleted inserted replaced
6711:ae13cc658b80 6948:e522a00b91aa
1 /* 1 /*
2 * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 2000, 2012, 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.
26 #include "code/compiledIC.hpp" 26 #include "code/compiledIC.hpp"
27 #include "code/nmethod.hpp" 27 #include "code/nmethod.hpp"
28 #include "code/scopeDesc.hpp" 28 #include "code/scopeDesc.hpp"
29 #include "compiler/compilerOracle.hpp" 29 #include "compiler/compilerOracle.hpp"
30 #include "interpreter/interpreter.hpp" 30 #include "interpreter/interpreter.hpp"
31 #include "oops/methodDataOop.hpp" 31 #include "oops/methodData.hpp"
32 #include "oops/methodOop.hpp" 32 #include "oops/method.hpp"
33 #include "oops/oop.inline.hpp" 33 #include "oops/oop.inline.hpp"
34 #include "prims/nativeLookup.hpp" 34 #include "prims/nativeLookup.hpp"
35 #include "runtime/advancedThresholdPolicy.hpp" 35 #include "runtime/advancedThresholdPolicy.hpp"
36 #include "runtime/compilationPolicy.hpp" 36 #include "runtime/compilationPolicy.hpp"
37 #include "runtime/frame.hpp" 37 #include "runtime/frame.hpp"
228 // Interates through invocation counters and decrements them. This 228 // Interates through invocation counters and decrements them. This
229 // is done at each safepoint. 229 // is done at each safepoint.
230 // 230 //
231 class CounterDecay : public AllStatic { 231 class CounterDecay : public AllStatic {
232 static jlong _last_timestamp; 232 static jlong _last_timestamp;
233 static void do_method(methodOop m) { 233 static void do_method(Method* m) {
234 m->invocation_counter()->decay(); 234 m->invocation_counter()->decay();
235 } 235 }
236 public: 236 public:
237 static void decay(); 237 static void decay();
238 static bool is_decay_needed() { 238 static bool is_decay_needed() {
251 assert(SafepointSynchronize::is_at_safepoint(), "can only be executed at a safepoint"); 251 assert(SafepointSynchronize::is_at_safepoint(), "can only be executed at a safepoint");
252 int nclasses = SystemDictionary::number_of_classes(); 252 int nclasses = SystemDictionary::number_of_classes();
253 double classes_per_tick = nclasses * (CounterDecayMinIntervalLength * 1e-3 / 253 double classes_per_tick = nclasses * (CounterDecayMinIntervalLength * 1e-3 /
254 CounterHalfLifeTime); 254 CounterHalfLifeTime);
255 for (int i = 0; i < classes_per_tick; i++) { 255 for (int i = 0; i < classes_per_tick; i++) {
256 klassOop k = SystemDictionary::try_get_next_class(); 256 Klass* k = SystemDictionary::try_get_next_class();
257 if (k != NULL && k->klass_part()->oop_is_instance()) { 257 if (k != NULL && k->oop_is_instance()) {
258 instanceKlass::cast(k)->methods_do(do_method); 258 InstanceKlass::cast(k)->methods_do(do_method);
259 } 259 }
260 } 260 }
261 } 261 }
262 262
263 // Called at the end of the safepoint 263 // Called at the end of the safepoint
283 sd->method()->backedge_counter()->reset(); 283 sd->method()->backedge_counter()->reset();
284 } 284 }
285 285
286 // This method can be called by any component of the runtime to notify the policy 286 // This method can be called by any component of the runtime to notify the policy
287 // that it's recommended to delay the complation of this method. 287 // that it's recommended to delay the complation of this method.
288 void NonTieredCompPolicy::delay_compilation(methodOop method) { 288 void NonTieredCompPolicy::delay_compilation(Method* method) {
289 method->invocation_counter()->decay(); 289 method->invocation_counter()->decay();
290 method->backedge_counter()->decay(); 290 method->backedge_counter()->decay();
291 } 291 }
292 292
293 void NonTieredCompPolicy::disable_compilation(methodOop method) { 293 void NonTieredCompPolicy::disable_compilation(Method* method) {
294 method->invocation_counter()->set_state(InvocationCounter::wait_for_nothing); 294 method->invocation_counter()->set_state(InvocationCounter::wait_for_nothing);
295 method->backedge_counter()->set_state(InvocationCounter::wait_for_nothing); 295 method->backedge_counter()->set_state(InvocationCounter::wait_for_nothing);
296 } 296 }
297 297
298 CompileTask* NonTieredCompPolicy::select_task(CompileQueue* compile_queue) { 298 CompileTask* NonTieredCompPolicy::select_task(CompileQueue* compile_queue) {
299 return compile_queue->first(); 299 return compile_queue->first();
300 } 300 }
301 301
302 bool NonTieredCompPolicy::is_mature(methodOop method) { 302 bool NonTieredCompPolicy::is_mature(Method* method) {
303 methodDataOop mdo = method->method_data(); 303 MethodData* mdo = method->method_data();
304 assert(mdo != NULL, "Should be"); 304 assert(mdo != NULL, "Should be");
305 uint current = mdo->mileage_of(method); 305 uint current = mdo->mileage_of(method);
306 uint initial = mdo->creation_mileage(); 306 uint initial = mdo->creation_mileage();
307 if (current < initial) 307 if (current < initial)
308 return true; // some sort of overflow 308 return true; // some sort of overflow
377 tty->cr(); 377 tty->cr();
378 ic->print(); 378 ic->print();
379 bc->print(); 379 bc->print();
380 if (ProfileInterpreter) { 380 if (ProfileInterpreter) {
381 if (bci != InvocationEntryBci) { 381 if (bci != InvocationEntryBci) {
382 methodDataOop mdo = m->method_data(); 382 MethodData* mdo = m->method_data();
383 if (mdo != NULL) { 383 if (mdo != NULL) {
384 int count = mdo->bci_to_data(branch_bci)->as_JumpData()->taken(); 384 int count = mdo->bci_to_data(branch_bci)->as_JumpData()->taken();
385 tty->print_cr("back branch count = %d", count); 385 tty->print_cr("back branch count = %d", count);
386 } 386 }
387 } 387 }
400 #endif // !PRODUCT 400 #endif // !PRODUCT
401 401
402 // SimpleCompPolicy - compile current method 402 // SimpleCompPolicy - compile current method
403 403
404 void SimpleCompPolicy::method_invocation_event(methodHandle m, JavaThread* thread) { 404 void SimpleCompPolicy::method_invocation_event(methodHandle m, JavaThread* thread) {
405 int hot_count = m->invocation_count(); 405 const int comp_level = CompLevel_highest_tier;
406 const int hot_count = m->invocation_count();
406 reset_counter_for_invocation_event(m); 407 reset_counter_for_invocation_event(m);
407 const char* comment = "count"; 408 const char* comment = "count";
408 409
409 if (is_compilation_enabled() && can_be_compiled(m)) { 410 if (is_compilation_enabled() && can_be_compiled(m)) {
410 nmethod* nm = m->code(); 411 nmethod* nm = m->code();
411 if (nm == NULL ) { 412 if (nm == NULL ) {
412 const char* comment = "count"; 413 CompileBroker::compile_method(m, InvocationEntryBci, comp_level, m, hot_count, comment, thread);
413 CompileBroker::compile_method(m, InvocationEntryBci, CompLevel_highest_tier,
414 m, hot_count, comment, thread);
415 } 414 }
416 } 415 }
417 } 416 }
418 417
419 void SimpleCompPolicy::method_back_branch_event(methodHandle m, int bci, JavaThread* thread) { 418 void SimpleCompPolicy::method_back_branch_event(methodHandle m, int bci, JavaThread* thread) {
420 int hot_count = m->backedge_count(); 419 const int comp_level = CompLevel_highest_tier;
420 const int hot_count = m->backedge_count();
421 const char* comment = "backedge_count"; 421 const char* comment = "backedge_count";
422 422
423 if (is_compilation_enabled() && !m->is_not_osr_compilable() && can_be_compiled(m)) { 423 if (is_compilation_enabled() && !m->is_not_osr_compilable(comp_level) && can_be_compiled(m)) {
424 CompileBroker::compile_method(m, bci, CompLevel_highest_tier, 424 CompileBroker::compile_method(m, bci, comp_level, m, hot_count, comment, thread);
425 m, hot_count, comment, thread); 425 NOT_PRODUCT(trace_osr_completion(m->lookup_osr_nmethod_for(bci, comp_level, true));)
426 NOT_PRODUCT(trace_osr_completion(m->lookup_osr_nmethod_for(bci, CompLevel_highest_tier, true));)
427 } 426 }
428 } 427 }
429 428
430 // GraalCompPolicy - compile current method 429 // GraalCompPolicy - compile current method
431 430
487 const char* StackWalkCompPolicy::_msg = NULL; 486 const char* StackWalkCompPolicy::_msg = NULL;
488 487
489 488
490 // Consider m for compilation 489 // Consider m for compilation
491 void StackWalkCompPolicy::method_invocation_event(methodHandle m, JavaThread* thread) { 490 void StackWalkCompPolicy::method_invocation_event(methodHandle m, JavaThread* thread) {
492 int hot_count = m->invocation_count(); 491 const int comp_level = CompLevel_highest_tier;
492 const int hot_count = m->invocation_count();
493 reset_counter_for_invocation_event(m); 493 reset_counter_for_invocation_event(m);
494 const char* comment = "count"; 494 const char* comment = "count";
495 495
496 if (is_compilation_enabled() && m->code() == NULL && can_be_compiled(m)) { 496 if (is_compilation_enabled() && m->code() == NULL && can_be_compiled(m)) {
497 ResourceMark rm(thread); 497 ResourceMark rm(thread);
518 stack->push(first); 518 stack->push(first);
519 RFrame* top = findTopInlinableFrame(stack); 519 RFrame* top = findTopInlinableFrame(stack);
520 if (TimeCompilationPolicy) accumulated_time()->stop(); 520 if (TimeCompilationPolicy) accumulated_time()->stop();
521 assert(top != NULL, "findTopInlinableFrame returned null"); 521 assert(top != NULL, "findTopInlinableFrame returned null");
522 if (TraceCompilationPolicy) top->print(); 522 if (TraceCompilationPolicy) top->print();
523 CompileBroker::compile_method(top->top_method(), InvocationEntryBci, CompLevel_highest_tier, 523 CompileBroker::compile_method(top->top_method(), InvocationEntryBci, comp_level,
524 m, hot_count, comment, thread); 524 m, hot_count, comment, thread);
525 } 525 }
526 } 526 }
527 } 527 }
528 528
529 void StackWalkCompPolicy::method_back_branch_event(methodHandle m, int bci, JavaThread* thread) { 529 void StackWalkCompPolicy::method_back_branch_event(methodHandle m, int bci, JavaThread* thread) {
530 int hot_count = m->backedge_count(); 530 const int comp_level = CompLevel_highest_tier;
531 const int hot_count = m->backedge_count();
531 const char* comment = "backedge_count"; 532 const char* comment = "backedge_count";
532 533
533 if (is_compilation_enabled() && !m->is_not_osr_compilable() && can_be_compiled(m)) { 534 if (is_compilation_enabled() && !m->is_not_osr_compilable(comp_level) && can_be_compiled(m)) {
534 CompileBroker::compile_method(m, bci, CompLevel_highest_tier, m, hot_count, comment, thread); 535 CompileBroker::compile_method(m, bci, comp_level, m, hot_count, comment, thread);
535 536 NOT_PRODUCT(trace_osr_completion(m->lookup_osr_nmethod_for(bci, comp_level, true));)
536 NOT_PRODUCT(trace_osr_completion(m->lookup_osr_nmethod_for(bci, CompLevel_highest_tier, true));)
537 } 537 }
538 } 538 }
539 539
540 RFrame* StackWalkCompPolicy::findTopInlinableFrame(GrowableArray<RFrame*>* stack) { 540 RFrame* StackWalkCompPolicy::findTopInlinableFrame(GrowableArray<RFrame*>* stack) {
541 // go up the stack until finding a frame that (probably) won't be inlined 541 // go up the stack until finding a frame that (probably) won't be inlined
688 688
689 const char* StackWalkCompPolicy::shouldNotInline(methodHandle m) { 689 const char* StackWalkCompPolicy::shouldNotInline(methodHandle m) {
690 // negative filter: should send NOT be inlined? returns NULL (--> inline) or rejection msg 690 // negative filter: should send NOT be inlined? returns NULL (--> inline) or rejection msg
691 if (m->is_abstract()) return (_msg = "abstract method"); 691 if (m->is_abstract()) return (_msg = "abstract method");
692 // note: we allow ik->is_abstract() 692 // note: we allow ik->is_abstract()
693 if (!instanceKlass::cast(m->method_holder())->is_initialized()) return (_msg = "method holder not initialized"); 693 if (!m->method_holder()->is_initialized()) return (_msg = "method holder not initialized");
694 if (m->is_native()) return (_msg = "native method"); 694 if (m->is_native()) return (_msg = "native method");
695 nmethod* m_code = m->code(); 695 nmethod* m_code = m->code();
696 if (m_code != NULL && m_code->code_size() > InlineSmallCode) 696 if (m_code != NULL && m_code->code_size() > InlineSmallCode)
697 return (_msg = "already compiled into a big method"); 697 return (_msg = "already compiled into a big method");
698 698
700 if (m->code_size() <= MaxTrivialSize) return NULL; 700 if (m->code_size() <= MaxTrivialSize) return NULL;
701 if (UseInterpreter) { // don't use counts with -Xcomp 701 if (UseInterpreter) { // don't use counts with -Xcomp
702 if ((m->code() == NULL) && m->was_never_executed()) return (_msg = "never executed"); 702 if ((m->code() == NULL) && m->was_never_executed()) return (_msg = "never executed");
703 if (!m->was_executed_more_than(MIN2(MinInliningThreshold, CompileThreshold >> 1))) return (_msg = "executed < MinInliningThreshold times"); 703 if (!m->was_executed_more_than(MIN2(MinInliningThreshold, CompileThreshold >> 1))) return (_msg = "executed < MinInliningThreshold times");
704 } 704 }
705 if (methodOopDesc::has_unloaded_classes_in_signature(m, JavaThread::current())) return (_msg = "unloaded signature classes"); 705 if (Method::has_unloaded_classes_in_signature(m, JavaThread::current())) return (_msg = "unloaded signature classes");
706 706
707 return NULL; 707 return NULL;
708 } 708 }
709 709
710 710