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" |
220 // Interates through invocation counters and decrements them. This |
220 // Interates through invocation counters and decrements them. This |
221 // is done at each safepoint. |
221 // is done at each safepoint. |
222 // |
222 // |
223 class CounterDecay : public AllStatic { |
223 class CounterDecay : public AllStatic { |
224 static jlong _last_timestamp; |
224 static jlong _last_timestamp; |
225 static void do_method(methodOop m) { |
225 static void do_method(Method* m) { |
226 m->invocation_counter()->decay(); |
226 m->invocation_counter()->decay(); |
227 } |
227 } |
228 public: |
228 public: |
229 static void decay(); |
229 static void decay(); |
230 static bool is_decay_needed() { |
230 static bool is_decay_needed() { |
243 assert(SafepointSynchronize::is_at_safepoint(), "can only be executed at a safepoint"); |
243 assert(SafepointSynchronize::is_at_safepoint(), "can only be executed at a safepoint"); |
244 int nclasses = SystemDictionary::number_of_classes(); |
244 int nclasses = SystemDictionary::number_of_classes(); |
245 double classes_per_tick = nclasses * (CounterDecayMinIntervalLength * 1e-3 / |
245 double classes_per_tick = nclasses * (CounterDecayMinIntervalLength * 1e-3 / |
246 CounterHalfLifeTime); |
246 CounterHalfLifeTime); |
247 for (int i = 0; i < classes_per_tick; i++) { |
247 for (int i = 0; i < classes_per_tick; i++) { |
248 klassOop k = SystemDictionary::try_get_next_class(); |
248 Klass* k = SystemDictionary::try_get_next_class(); |
249 if (k != NULL && k->klass_part()->oop_is_instance()) { |
249 if (k != NULL && k->oop_is_instance()) { |
250 instanceKlass::cast(k)->methods_do(do_method); |
250 InstanceKlass::cast(k)->methods_do(do_method); |
251 } |
251 } |
252 } |
252 } |
253 } |
253 } |
254 |
254 |
255 // Called at the end of the safepoint |
255 // Called at the end of the safepoint |
275 sd->method()->backedge_counter()->reset(); |
275 sd->method()->backedge_counter()->reset(); |
276 } |
276 } |
277 |
277 |
278 // This method can be called by any component of the runtime to notify the policy |
278 // This method can be called by any component of the runtime to notify the policy |
279 // that it's recommended to delay the complation of this method. |
279 // that it's recommended to delay the complation of this method. |
280 void NonTieredCompPolicy::delay_compilation(methodOop method) { |
280 void NonTieredCompPolicy::delay_compilation(Method* method) { |
281 method->invocation_counter()->decay(); |
281 method->invocation_counter()->decay(); |
282 method->backedge_counter()->decay(); |
282 method->backedge_counter()->decay(); |
283 } |
283 } |
284 |
284 |
285 void NonTieredCompPolicy::disable_compilation(methodOop method) { |
285 void NonTieredCompPolicy::disable_compilation(Method* method) { |
286 method->invocation_counter()->set_state(InvocationCounter::wait_for_nothing); |
286 method->invocation_counter()->set_state(InvocationCounter::wait_for_nothing); |
287 method->backedge_counter()->set_state(InvocationCounter::wait_for_nothing); |
287 method->backedge_counter()->set_state(InvocationCounter::wait_for_nothing); |
288 } |
288 } |
289 |
289 |
290 CompileTask* NonTieredCompPolicy::select_task(CompileQueue* compile_queue) { |
290 CompileTask* NonTieredCompPolicy::select_task(CompileQueue* compile_queue) { |
291 return compile_queue->first(); |
291 return compile_queue->first(); |
292 } |
292 } |
293 |
293 |
294 bool NonTieredCompPolicy::is_mature(methodOop method) { |
294 bool NonTieredCompPolicy::is_mature(Method* method) { |
295 methodDataOop mdo = method->method_data(); |
295 MethodData* mdo = method->method_data(); |
296 assert(mdo != NULL, "Should be"); |
296 assert(mdo != NULL, "Should be"); |
297 uint current = mdo->mileage_of(method); |
297 uint current = mdo->mileage_of(method); |
298 uint initial = mdo->creation_mileage(); |
298 uint initial = mdo->creation_mileage(); |
299 if (current < initial) |
299 if (current < initial) |
300 return true; // some sort of overflow |
300 return true; // some sort of overflow |
369 tty->cr(); |
369 tty->cr(); |
370 ic->print(); |
370 ic->print(); |
371 bc->print(); |
371 bc->print(); |
372 if (ProfileInterpreter) { |
372 if (ProfileInterpreter) { |
373 if (bci != InvocationEntryBci) { |
373 if (bci != InvocationEntryBci) { |
374 methodDataOop mdo = m->method_data(); |
374 MethodData* mdo = m->method_data(); |
375 if (mdo != NULL) { |
375 if (mdo != NULL) { |
376 int count = mdo->bci_to_data(branch_bci)->as_JumpData()->taken(); |
376 int count = mdo->bci_to_data(branch_bci)->as_JumpData()->taken(); |
377 tty->print_cr("back branch count = %d", count); |
377 tty->print_cr("back branch count = %d", count); |
378 } |
378 } |
379 } |
379 } |
625 |
625 |
626 const char* StackWalkCompPolicy::shouldNotInline(methodHandle m) { |
626 const char* StackWalkCompPolicy::shouldNotInline(methodHandle m) { |
627 // negative filter: should send NOT be inlined? returns NULL (--> inline) or rejection msg |
627 // negative filter: should send NOT be inlined? returns NULL (--> inline) or rejection msg |
628 if (m->is_abstract()) return (_msg = "abstract method"); |
628 if (m->is_abstract()) return (_msg = "abstract method"); |
629 // note: we allow ik->is_abstract() |
629 // note: we allow ik->is_abstract() |
630 if (!instanceKlass::cast(m->method_holder())->is_initialized()) return (_msg = "method holder not initialized"); |
630 if (!InstanceKlass::cast(m->method_holder())->is_initialized()) return (_msg = "method holder not initialized"); |
631 if (m->is_native()) return (_msg = "native method"); |
631 if (m->is_native()) return (_msg = "native method"); |
632 nmethod* m_code = m->code(); |
632 nmethod* m_code = m->code(); |
633 if (m_code != NULL && m_code->code_size() > InlineSmallCode) |
633 if (m_code != NULL && m_code->code_size() > InlineSmallCode) |
634 return (_msg = "already compiled into a big method"); |
634 return (_msg = "already compiled into a big method"); |
635 |
635 |
637 if (m->code_size() <= MaxTrivialSize) return NULL; |
637 if (m->code_size() <= MaxTrivialSize) return NULL; |
638 if (UseInterpreter) { // don't use counts with -Xcomp |
638 if (UseInterpreter) { // don't use counts with -Xcomp |
639 if ((m->code() == NULL) && m->was_never_executed()) return (_msg = "never executed"); |
639 if ((m->code() == NULL) && m->was_never_executed()) return (_msg = "never executed"); |
640 if (!m->was_executed_more_than(MIN2(MinInliningThreshold, CompileThreshold >> 1))) return (_msg = "executed < MinInliningThreshold times"); |
640 if (!m->was_executed_more_than(MIN2(MinInliningThreshold, CompileThreshold >> 1))) return (_msg = "executed < MinInliningThreshold times"); |
641 } |
641 } |
642 if (methodOopDesc::has_unloaded_classes_in_signature(m, JavaThread::current())) return (_msg = "unloaded signature classes"); |
642 if (Method::has_unloaded_classes_in_signature(m, JavaThread::current())) return (_msg = "unloaded signature classes"); |
643 |
643 |
644 return NULL; |
644 return NULL; |
645 } |
645 } |
646 |
646 |
647 |
647 |