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. |
195 // Make sure invocation and backedge counter doesn't overflow again right away |
195 // Make sure invocation and backedge counter doesn't overflow again right away |
196 // as would be the case for native methods. |
196 // as would be the case for native methods. |
197 |
197 |
198 // BUT also make sure the method doesn't look like it was never executed. |
198 // BUT also make sure the method doesn't look like it was never executed. |
199 // Set carry bit and reduce counter's value to min(count, CompileThreshold/2). |
199 // Set carry bit and reduce counter's value to min(count, CompileThreshold/2). |
200 m->invocation_counter()->set_carry(); |
200 MethodCounters* mcs = m->method_counters(); |
201 m->backedge_counter()->set_carry(); |
201 assert(mcs != NULL, "MethodCounters cannot be NULL for profiling"); |
|
202 mcs->invocation_counter()->set_carry(); |
|
203 mcs->backedge_counter()->set_carry(); |
202 |
204 |
203 assert(!m->was_never_executed(), "don't reset to 0 -- could be mistaken for never-executed"); |
205 assert(!m->was_never_executed(), "don't reset to 0 -- could be mistaken for never-executed"); |
204 } |
206 } |
205 |
207 |
206 void NonTieredCompPolicy::reset_counter_for_back_branch_event(methodHandle m) { |
208 void NonTieredCompPolicy::reset_counter_for_back_branch_event(methodHandle m) { |
207 // Delay next back-branch event but pump up invocation counter to triger |
209 // Delay next back-branch event but pump up invocation counter to triger |
208 // whole method compilation. |
210 // whole method compilation. |
209 InvocationCounter* i = m->invocation_counter(); |
211 MethodCounters* mcs = m->method_counters(); |
210 InvocationCounter* b = m->backedge_counter(); |
212 assert(mcs != NULL, "MethodCounters cannot be NULL for profiling"); |
|
213 InvocationCounter* i = mcs->invocation_counter(); |
|
214 InvocationCounter* b = mcs->backedge_counter(); |
211 |
215 |
212 // Don't set invocation_counter's value too low otherwise the method will |
216 // Don't set invocation_counter's value too low otherwise the method will |
213 // look like immature (ic < ~5300) which prevents the inlining based on |
217 // look like immature (ic < ~5300) which prevents the inlining based on |
214 // the type profiling. |
218 // the type profiling. |
215 i->set(i->state(), CompileThreshold); |
219 i->set(i->state(), CompileThreshold); |
224 // is done at each safepoint. |
228 // is done at each safepoint. |
225 // |
229 // |
226 class CounterDecay : public AllStatic { |
230 class CounterDecay : public AllStatic { |
227 static jlong _last_timestamp; |
231 static jlong _last_timestamp; |
228 static void do_method(Method* m) { |
232 static void do_method(Method* m) { |
229 m->invocation_counter()->decay(); |
233 MethodCounters* mcs = m->method_counters(); |
|
234 if (mcs != NULL) { |
|
235 mcs->invocation_counter()->decay(); |
|
236 } |
230 } |
237 } |
231 public: |
238 public: |
232 static void decay(); |
239 static void decay(); |
233 static bool is_decay_needed() { |
240 static bool is_decay_needed() { |
234 return (os::javaTimeMillis() - _last_timestamp) > CounterDecayMinIntervalLength; |
241 return (os::javaTimeMillis() - _last_timestamp) > CounterDecayMinIntervalLength; |
262 } |
269 } |
263 } |
270 } |
264 |
271 |
265 void NonTieredCompPolicy::reprofile(ScopeDesc* trap_scope, bool is_osr) { |
272 void NonTieredCompPolicy::reprofile(ScopeDesc* trap_scope, bool is_osr) { |
266 ScopeDesc* sd = trap_scope; |
273 ScopeDesc* sd = trap_scope; |
|
274 MethodCounters* mcs; |
|
275 InvocationCounter* c; |
267 for (; !sd->is_top(); sd = sd->sender()) { |
276 for (; !sd->is_top(); sd = sd->sender()) { |
268 // Reset ICs of inlined methods, since they can trigger compilations also. |
277 mcs = sd->method()->method_counters(); |
269 sd->method()->invocation_counter()->reset(); |
278 if (mcs != NULL) { |
270 } |
279 // Reset ICs of inlined methods, since they can trigger compilations also. |
271 InvocationCounter* c = sd->method()->invocation_counter(); |
280 mcs->invocation_counter()->reset(); |
272 if (is_osr) { |
281 } |
273 // It was an OSR method, so bump the count higher. |
282 } |
274 c->set(c->state(), CompileThreshold); |
283 mcs = sd->method()->method_counters(); |
275 } else { |
284 if (mcs != NULL) { |
276 c->reset(); |
285 c = mcs->invocation_counter(); |
277 } |
286 if (is_osr) { |
278 sd->method()->backedge_counter()->reset(); |
287 // It was an OSR method, so bump the count higher. |
|
288 c->set(c->state(), CompileThreshold); |
|
289 } else { |
|
290 c->reset(); |
|
291 } |
|
292 mcs->backedge_counter()->reset(); |
|
293 } |
279 } |
294 } |
280 |
295 |
281 // This method can be called by any component of the runtime to notify the policy |
296 // This method can be called by any component of the runtime to notify the policy |
282 // that it's recommended to delay the complation of this method. |
297 // that it's recommended to delay the complation of this method. |
283 void NonTieredCompPolicy::delay_compilation(Method* method) { |
298 void NonTieredCompPolicy::delay_compilation(Method* method) { |
284 method->invocation_counter()->decay(); |
299 MethodCounters* mcs = method->method_counters(); |
285 method->backedge_counter()->decay(); |
300 assert(mcs != NULL, "MethodCounters cannot be NULL"); |
|
301 mcs->invocation_counter()->decay(); |
|
302 mcs->backedge_counter()->decay(); |
286 } |
303 } |
287 |
304 |
288 void NonTieredCompPolicy::disable_compilation(Method* method) { |
305 void NonTieredCompPolicy::disable_compilation(Method* method) { |
289 method->invocation_counter()->set_state(InvocationCounter::wait_for_nothing); |
306 MethodCounters* mcs = method->method_counters(); |
290 method->backedge_counter()->set_state(InvocationCounter::wait_for_nothing); |
307 if (mcs != NULL) { |
|
308 mcs->invocation_counter()->set_state(InvocationCounter::wait_for_nothing); |
|
309 mcs->backedge_counter()->set_state(InvocationCounter::wait_for_nothing); |
|
310 } |
291 } |
311 } |
292 |
312 |
293 CompileTask* NonTieredCompPolicy::select_task(CompileQueue* compile_queue) { |
313 CompileTask* NonTieredCompPolicy::select_task(CompileQueue* compile_queue) { |
294 return compile_queue->first(); |
314 return compile_queue->first(); |
295 } |
315 } |
368 } |
388 } |
369 |
389 |
370 #ifndef PRODUCT |
390 #ifndef PRODUCT |
371 void NonTieredCompPolicy::trace_frequency_counter_overflow(methodHandle m, int branch_bci, int bci) { |
391 void NonTieredCompPolicy::trace_frequency_counter_overflow(methodHandle m, int branch_bci, int bci) { |
372 if (TraceInvocationCounterOverflow) { |
392 if (TraceInvocationCounterOverflow) { |
373 InvocationCounter* ic = m->invocation_counter(); |
393 MethodCounters* mcs = m->method_counters(); |
374 InvocationCounter* bc = m->backedge_counter(); |
394 assert(mcs != NULL, "MethodCounters cannot be NULL for profiling"); |
|
395 InvocationCounter* ic = mcs->invocation_counter(); |
|
396 InvocationCounter* bc = mcs->backedge_counter(); |
375 ResourceMark rm; |
397 ResourceMark rm; |
376 const char* msg = |
398 const char* msg = |
377 bci == InvocationEntryBci |
399 bci == InvocationEntryBci |
378 ? "comp-policy cntr ovfl @ %d in entry of " |
400 ? "comp-policy cntr ovfl @ %d in entry of " |
379 : "comp-policy cntr ovfl @ %d in loop of "; |
401 : "comp-policy cntr ovfl @ %d in loop of "; |