Print this page
Split |
Close |
Expand all |
Collapse all |
--- old/src/share/vm/runtime/simpleThresholdPolicy.cpp
+++ new/src/share/vm/runtime/simpleThresholdPolicy.cpp
1 1 /*
2 2 * Copyright (c) 2010, 2011, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 20 * or visit www.oracle.com if you need additional information or have any
21 21 * questions.
22 22 *
23 23 */
24 24
25 25 #include "precompiled.hpp"
26 26 #include "compiler/compileBroker.hpp"
27 27 #include "memory/resourceArea.hpp"
28 28 #include "runtime/arguments.hpp"
29 29 #include "runtime/simpleThresholdPolicy.hpp"
30 30 #include "runtime/simpleThresholdPolicy.inline.hpp"
31 31 #include "code/scopeDesc.hpp"
32 32
33 33 // Print an event.
34 34 void SimpleThresholdPolicy::print_event(EventType type, methodHandle mh, methodHandle imh,
35 35 int bci, CompLevel level) {
36 36 bool inlinee_event = mh() != imh();
37 37
38 38 ttyLocker tty_lock;
39 39 tty->print("%lf: [", os::elapsedTime());
40 40
41 41 int invocation_count = mh->invocation_count();
42 42 int backedge_count = mh->backedge_count();
43 43 switch(type) {
44 44 case CALL:
45 45 tty->print("call");
46 46 break;
47 47 case LOOP:
48 48 tty->print("loop");
49 49 break;
50 50 case COMPILE:
51 51 tty->print("compile");
52 52 break;
53 53 case REMOVE_FROM_QUEUE:
54 54 tty->print("remove-from-queue");
55 55 break;
56 56 case UPDATE_IN_QUEUE:
57 57 tty->print("update-in-queue");
58 58 break;
59 59 case REPROFILE:
60 60 tty->print("reprofile");
61 61 break;
62 62 case MAKE_NOT_ENTRANT:
63 63 tty->print("make-not-entrant");
64 64 break;
65 65 default:
66 66 tty->print("unknown");
67 67 }
68 68
69 69 tty->print(" level: %d ", level);
70 70
71 71 ResourceMark rm;
72 72 char *method_name = mh->name_and_sig_as_C_string();
73 73 tty->print("[%s", method_name);
74 74 if (inlinee_event) {
75 75 char *inlinee_name = imh->name_and_sig_as_C_string();
76 76 tty->print(" [%s]] ", inlinee_name);
77 77 }
78 78 else tty->print("] ");
79 79 tty->print("@%d queues: %d,%d", bci, CompileBroker::queue_size(CompLevel_full_profile),
80 80 CompileBroker::queue_size(CompLevel_full_optimization));
81 81
82 82 print_specific(type, mh, imh, bci, level);
83 83
84 84 if (type != COMPILE) {
85 85 methodDataHandle mdh = mh->method_data();
86 86 int mdo_invocations = 0, mdo_backedges = 0;
87 87 int mdo_invocations_start = 0, mdo_backedges_start = 0;
88 88 if (mdh() != NULL) {
89 89 mdo_invocations = mdh->invocation_count();
90 90 mdo_backedges = mdh->backedge_count();
91 91 mdo_invocations_start = mdh->invocation_count_start();
92 92 mdo_backedges_start = mdh->backedge_count_start();
93 93 }
94 94 tty->print(" total: %d,%d mdo: %d(%d),%d(%d)",
95 95 invocation_count, backedge_count,
96 96 mdo_invocations, mdo_invocations_start,
97 97 mdo_backedges, mdo_backedges_start);
98 98 tty->print(" max levels: %d,%d",
99 99 mh->highest_comp_level(), mh->highest_osr_comp_level());
100 100 if (inlinee_event) {
101 101 tty->print(" inlinee max levels: %d,%d", imh->highest_comp_level(), imh->highest_osr_comp_level());
102 102 }
103 103 tty->print(" compilable: ");
104 104 bool need_comma = false;
105 105 if (!mh->is_not_compilable(CompLevel_full_profile)) {
106 106 tty->print("c1");
107 107 need_comma = true;
108 108 }
109 109 if (!mh->is_not_compilable(CompLevel_full_optimization)) {
110 110 if (need_comma) tty->print(", ");
111 111 tty->print("c2");
112 112 need_comma = true;
113 113 }
114 114 if (!mh->is_not_osr_compilable()) {
115 115 if (need_comma) tty->print(", ");
116 116 tty->print("osr");
117 117 }
118 118 tty->print(" status:");
119 119 if (mh->queued_for_compilation()) {
120 120 tty->print(" in queue");
121 121 } else tty->print(" idle");
122 122 }
123 123 tty->print_cr("]");
124 124 }
125 125
126 126 void SimpleThresholdPolicy::initialize() {
127 127 if (FLAG_IS_DEFAULT(CICompilerCount)) {
128 128 FLAG_SET_DEFAULT(CICompilerCount, 3);
129 129 }
130 130 int count = CICompilerCount;
131 131 if (CICompilerCountPerCPU) {
132 132 count = MAX2(log2_intptr(os::active_processor_count()), 1) * 3 / 2;
133 133 }
134 134 set_c1_count(MAX2(count / 3, 1));
135 135 set_c2_count(MAX2(count - count / 3, 1));
136 136 }
137 137
138 138 void SimpleThresholdPolicy::set_carry_if_necessary(InvocationCounter *counter) {
139 139 if (!counter->carry() && counter->count() > InvocationCounter::count_limit / 2) {
140 140 counter->set_carry_flag();
141 141 }
142 142 }
143 143
144 144 // Set carry flags on the counters if necessary
145 145 void SimpleThresholdPolicy::handle_counter_overflow(methodOop method) {
146 146 set_carry_if_necessary(method->invocation_counter());
147 147 set_carry_if_necessary(method->backedge_counter());
148 148 methodDataOop mdo = method->method_data();
149 149 if (mdo != NULL) {
150 150 set_carry_if_necessary(mdo->invocation_counter());
151 151 set_carry_if_necessary(mdo->backedge_counter());
152 152 }
153 153 }
154 154
155 155 // Called with the queue locked and with at least one element
156 156 CompileTask* SimpleThresholdPolicy::select_task(CompileQueue* compile_queue) {
157 157 return compile_queue->first();
158 158 }
159 159
160 160 void SimpleThresholdPolicy::reprofile(ScopeDesc* trap_scope, bool is_osr) {
161 161 for (ScopeDesc* sd = trap_scope;; sd = sd->sender()) {
162 162 if (PrintTieredEvents) {
163 163 methodHandle mh(sd->method());
164 164 print_event(REPROFILE, mh, mh, InvocationEntryBci, CompLevel_none);
165 165 }
166 166 methodDataOop mdo = sd->method()->method_data();
167 167 if (mdo != NULL) {
168 168 mdo->reset_start_counters();
169 169 }
170 170 if (sd->is_top()) break;
171 171 }
172 172 }
173 173
174 174 nmethod* SimpleThresholdPolicy::event(methodHandle method, methodHandle inlinee,
175 175 int branch_bci, int bci, CompLevel comp_level, nmethod* nm, TRAPS) {
176 176 if (comp_level == CompLevel_none &&
177 177 JvmtiExport::can_post_interpreter_events()) {
178 178 assert(THREAD->is_Java_thread(), "Should be java thread");
179 179 if (((JavaThread*)THREAD)->is_interp_only_mode()) {
180 180 return NULL;
181 181 }
182 182 }
183 183 nmethod *osr_nm = NULL;
184 184
185 185 handle_counter_overflow(method());
186 186 if (method() != inlinee()) {
187 187 handle_counter_overflow(inlinee());
188 188 }
189 189
190 190 if (PrintTieredEvents) {
191 191 print_event(bci == InvocationEntryBci ? CALL : LOOP, method, inlinee, bci, comp_level);
192 192 }
193 193
194 194 if (bci == InvocationEntryBci) {
195 195 method_invocation_event(method, inlinee, comp_level, nm, THREAD);
196 196 } else {
197 197 method_back_branch_event(method, inlinee, bci, comp_level, nm, THREAD);
198 198 // method == inlinee if the event originated in the main method
↓ open down ↓ |
198 lines elided |
↑ open up ↑ |
199 199 int highest_level = inlinee->highest_osr_comp_level();
200 200 if (highest_level > comp_level) {
201 201 osr_nm = inlinee->lookup_osr_nmethod_for(bci, highest_level, false);
202 202 }
203 203 }
204 204 return osr_nm;
205 205 }
206 206
207 207 // Check if the method can be compiled, change level if necessary
208 208 void SimpleThresholdPolicy::compile(methodHandle mh, int bci, CompLevel level, TRAPS) {
209 - // Take the given ceiling into the account.
210 - // NOTE: You can set it to 1 to get a pure C1 version.
211 - if ((CompLevel)TieredStopAtLevel < level) {
212 - level = (CompLevel)TieredStopAtLevel;
213 - }
209 + assert(level <= TieredStopAtLevel, "Invalid compilation level");
214 210 if (level == CompLevel_none) {
215 211 return;
216 212 }
217 213 // Check if the method can be compiled. If it cannot be compiled with C1, continue profiling
218 214 // in the interpreter and then compile with C2 (the transition function will request that,
219 215 // see common() ). If the method cannot be compiled with C2 but still can with C1, compile it with
220 216 // pure C1.
221 217 if (!can_be_compiled(mh, level)) {
222 218 if (level == CompLevel_full_optimization && can_be_compiled(mh, CompLevel_simple)) {
223 219 compile(mh, bci, CompLevel_simple, THREAD);
224 220 }
225 221 return;
226 222 }
227 223 if (bci != InvocationEntryBci && mh->is_not_osr_compilable()) {
228 224 return;
229 225 }
230 - if (PrintTieredEvents) {
231 - print_event(COMPILE, mh, mh, bci, level);
232 - }
233 226 if (!CompileBroker::compilation_is_in_queue(mh, bci)) {
227 + if (PrintTieredEvents) {
228 + print_event(COMPILE, mh, mh, bci, level);
229 + }
234 230 submit_compile(mh, bci, level, THREAD);
235 231 }
236 232 }
237 233
238 234 // Tell the broker to compile the method
239 235 void SimpleThresholdPolicy::submit_compile(methodHandle mh, int bci, CompLevel level, TRAPS) {
240 236 int hot_count = (bci == InvocationEntryBci) ? mh->invocation_count() : mh->backedge_count();
241 237 CompileBroker::compile_method(mh, bci, level, mh, hot_count, "tiered", THREAD);
242 238 }
243 239
244 240 // Call and loop predicates determine whether a transition to a higher
245 241 // compilation level should be performed (pointers to predicate functions
246 242 // are passed to common() transition function).
247 243 bool SimpleThresholdPolicy::loop_predicate(int i, int b, CompLevel cur_level) {
248 244 switch(cur_level) {
249 245 case CompLevel_none:
250 246 case CompLevel_limited_profile: {
251 247 return loop_predicate_helper<CompLevel_none>(i, b, 1.0);
252 248 }
253 249 case CompLevel_full_profile: {
254 250 return loop_predicate_helper<CompLevel_full_profile>(i, b, 1.0);
255 251 }
256 252 default:
257 253 return true;
258 254 }
259 255 }
260 256
261 257 bool SimpleThresholdPolicy::call_predicate(int i, int b, CompLevel cur_level) {
262 258 switch(cur_level) {
263 259 case CompLevel_none:
264 260 case CompLevel_limited_profile: {
265 261 return call_predicate_helper<CompLevel_none>(i, b, 1.0);
266 262 }
267 263 case CompLevel_full_profile: {
268 264 return call_predicate_helper<CompLevel_full_profile>(i, b, 1.0);
269 265 }
270 266 default:
271 267 return true;
272 268 }
273 269 }
274 270
275 271 // Determine is a method is mature.
276 272 bool SimpleThresholdPolicy::is_mature(methodOop method) {
277 273 if (is_trivial(method)) return true;
278 274 methodDataOop mdo = method->method_data();
279 275 if (mdo != NULL) {
280 276 int i = mdo->invocation_count();
↓ open down ↓ |
37 lines elided |
↑ open up ↑ |
281 277 int b = mdo->backedge_count();
282 278 double k = ProfileMaturityPercentage / 100.0;
283 279 return call_predicate_helper<CompLevel_full_profile>(i, b, k) ||
284 280 loop_predicate_helper<CompLevel_full_profile>(i, b, k);
285 281 }
286 282 return false;
287 283 }
288 284
289 285 // Common transition function. Given a predicate determines if a method should transition to another level.
290 286 CompLevel SimpleThresholdPolicy::common(Predicate p, methodOop method, CompLevel cur_level) {
291 - if (is_trivial(method)) return CompLevel_simple;
292 -
293 287 CompLevel next_level = cur_level;
294 288 int i = method->invocation_count();
295 289 int b = method->backedge_count();
296 290
297 - switch(cur_level) {
298 - case CompLevel_none:
299 - // If we were at full profile level, would we switch to full opt?
300 - if (common(p, method, CompLevel_full_profile) == CompLevel_full_optimization) {
301 - next_level = CompLevel_full_optimization;
302 - } else if ((this->*p)(i, b, cur_level)) {
303 - next_level = CompLevel_full_profile;
304 - }
305 - break;
306 - case CompLevel_limited_profile:
307 - case CompLevel_full_profile:
308 - {
309 - methodDataOop mdo = method->method_data();
310 - if (mdo != NULL) {
311 - if (mdo->would_profile()) {
312 - int mdo_i = mdo->invocation_count_delta();
313 - int mdo_b = mdo->backedge_count_delta();
314 - if ((this->*p)(mdo_i, mdo_b, cur_level)) {
291 + if (is_trivial(method)) {
292 + next_level = CompLevel_simple;
293 + } else {
294 + switch(cur_level) {
295 + case CompLevel_none:
296 + // If we were at full profile level, would we switch to full opt?
297 + if (common(p, method, CompLevel_full_profile) == CompLevel_full_optimization) {
298 + next_level = CompLevel_full_optimization;
299 + } else if ((this->*p)(i, b, cur_level)) {
300 + next_level = CompLevel_full_profile;
301 + }
302 + break;
303 + case CompLevel_limited_profile:
304 + case CompLevel_full_profile:
305 + {
306 + methodDataOop mdo = method->method_data();
307 + if (mdo != NULL) {
308 + if (mdo->would_profile()) {
309 + int mdo_i = mdo->invocation_count_delta();
310 + int mdo_b = mdo->backedge_count_delta();
311 + if ((this->*p)(mdo_i, mdo_b, cur_level)) {
312 + next_level = CompLevel_full_optimization;
313 + }
314 + } else {
315 315 next_level = CompLevel_full_optimization;
316 316 }
317 - } else {
318 - next_level = CompLevel_full_optimization;
319 317 }
320 318 }
319 + break;
321 320 }
322 - break;
323 321 }
324 - return next_level;
322 + return MIN2(next_level, (CompLevel)TieredStopAtLevel);
325 323 }
326 324
327 325 // Determine if a method should be compiled with a normal entry point at a different level.
328 326 CompLevel SimpleThresholdPolicy::call_event(methodOop method, CompLevel cur_level) {
329 327 CompLevel osr_level = MIN2((CompLevel) method->highest_osr_comp_level(),
330 328 common(&SimpleThresholdPolicy::loop_predicate, method, cur_level));
331 329 CompLevel next_level = common(&SimpleThresholdPolicy::call_predicate, method, cur_level);
332 330
333 331 // If OSR method level is greater than the regular method level, the levels should be
334 332 // equalized by raising the regular method level in order to avoid OSRs during each
335 333 // invocation of the method.
336 334 if (osr_level == CompLevel_full_optimization && cur_level == CompLevel_full_profile) {
337 335 methodDataOop mdo = method->method_data();
338 336 guarantee(mdo != NULL, "MDO should not be NULL");
339 337 if (mdo->invocation_count() >= 1) {
340 338 next_level = CompLevel_full_optimization;
341 339 }
342 340 } else {
343 341 next_level = MAX2(osr_level, next_level);
344 342 }
345 343
346 344 return next_level;
347 345 }
348 346
349 347 // Determine if we should do an OSR compilation of a given method.
350 348 CompLevel SimpleThresholdPolicy::loop_event(methodOop method, CompLevel cur_level) {
351 349 CompLevel next_level = common(&SimpleThresholdPolicy::loop_predicate, method, cur_level);
352 350 if (cur_level == CompLevel_none) {
353 351 // If there is a live OSR method that means that we deopted to the interpreter
354 352 // for the transition.
355 353 CompLevel osr_level = MIN2((CompLevel)method->highest_osr_comp_level(), next_level);
356 354 if (osr_level > CompLevel_none) {
357 355 return osr_level;
358 356 }
359 357 }
360 358 return next_level;
361 359 }
362 360
363 361
364 362 // Handle the invocation event.
365 363 void SimpleThresholdPolicy::method_invocation_event(methodHandle mh, methodHandle imh,
366 364 CompLevel level, nmethod* nm, TRAPS) {
367 365 if (is_compilation_enabled() && !CompileBroker::compilation_is_in_queue(mh, InvocationEntryBci)) {
368 366 CompLevel next_level = call_event(mh(), level);
369 367 if (next_level != level) {
370 368 compile(mh, InvocationEntryBci, next_level, THREAD);
371 369 }
372 370 }
373 371 }
374 372
375 373 // Handle the back branch event. Notice that we can compile the method
376 374 // with a regular entry from here.
377 375 void SimpleThresholdPolicy::method_back_branch_event(methodHandle mh, methodHandle imh,
378 376 int bci, CompLevel level, nmethod* nm, TRAPS) {
379 377 // If the method is already compiling, quickly bail out.
380 378 if (is_compilation_enabled() && !CompileBroker::compilation_is_in_queue(mh, bci)) {
381 379 // Use loop event as an opportinity to also check there's been
382 380 // enough calls.
383 381 CompLevel cur_level = comp_level(mh());
384 382 CompLevel next_level = call_event(mh(), cur_level);
385 383 CompLevel next_osr_level = loop_event(mh(), level);
386 384
387 385 next_level = MAX2(next_level,
388 386 next_osr_level < CompLevel_full_optimization ? next_osr_level : cur_level);
389 387 bool is_compiling = false;
390 388 if (next_level != cur_level) {
391 389 compile(mh, InvocationEntryBci, next_level, THREAD);
392 390 is_compiling = true;
393 391 }
394 392
395 393 // Do the OSR version
396 394 if (!is_compiling && next_osr_level != level) {
397 395 compile(mh, bci, next_osr_level, THREAD);
398 396 }
399 397 }
400 398 }
↓ open down ↓ |
66 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX