Mercurial > hg > graal-compiler
annotate src/share/vm/runtime/simpleThresholdPolicy.cpp @ 6231:7e5976e66c62
7182543: NMT ON: Aggregate a few NMT related bugs
Summary: 1) Fixed MemTrackWorker::generations_in_used() calculation 2) Ensured NMT not to leak memory recorders after shutdown 3) Used ThreadCritical to block safepoint safe threads
Reviewed-by: acorn, coleenp, dholmes, kvn
author | zgu |
---|---|
date | Thu, 19 Jul 2012 09:05:42 -0400 |
parents | 20334ed5ed3c |
children | da91efe96a93 |
rev | line source |
---|---|
1783 | 1 /* |
3358 | 2 * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. |
1783 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
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 | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 * | |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "compiler/compileBroker.hpp" | |
27 #include "memory/resourceArea.hpp" | |
28 #include "runtime/arguments.hpp" | |
29 #include "runtime/simpleThresholdPolicy.hpp" | |
30 #include "runtime/simpleThresholdPolicy.inline.hpp" | |
2252 | 31 #include "code/scopeDesc.hpp" |
1783 | 32 |
4116
973293defacd
7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents:
3837
diff
changeset
|
33 |
973293defacd
7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents:
3837
diff
changeset
|
34 void SimpleThresholdPolicy::print_counters(const char* prefix, methodHandle mh) { |
973293defacd
7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents:
3837
diff
changeset
|
35 int invocation_count = mh->invocation_count(); |
973293defacd
7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents:
3837
diff
changeset
|
36 int backedge_count = mh->backedge_count(); |
973293defacd
7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents:
3837
diff
changeset
|
37 methodDataHandle mdh = mh->method_data(); |
973293defacd
7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents:
3837
diff
changeset
|
38 int mdo_invocations = 0, mdo_backedges = 0; |
973293defacd
7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents:
3837
diff
changeset
|
39 int mdo_invocations_start = 0, mdo_backedges_start = 0; |
973293defacd
7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents:
3837
diff
changeset
|
40 if (mdh() != NULL) { |
973293defacd
7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents:
3837
diff
changeset
|
41 mdo_invocations = mdh->invocation_count(); |
973293defacd
7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents:
3837
diff
changeset
|
42 mdo_backedges = mdh->backedge_count(); |
973293defacd
7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents:
3837
diff
changeset
|
43 mdo_invocations_start = mdh->invocation_count_start(); |
973293defacd
7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents:
3837
diff
changeset
|
44 mdo_backedges_start = mdh->backedge_count_start(); |
973293defacd
7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents:
3837
diff
changeset
|
45 } |
973293defacd
7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents:
3837
diff
changeset
|
46 tty->print(" %stotal: %d,%d %smdo: %d(%d),%d(%d)", prefix, |
973293defacd
7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents:
3837
diff
changeset
|
47 invocation_count, backedge_count, prefix, |
973293defacd
7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents:
3837
diff
changeset
|
48 mdo_invocations, mdo_invocations_start, |
973293defacd
7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents:
3837
diff
changeset
|
49 mdo_backedges, mdo_backedges_start); |
973293defacd
7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents:
3837
diff
changeset
|
50 tty->print(" %smax levels: %d,%d", prefix, |
973293defacd
7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents:
3837
diff
changeset
|
51 mh->highest_comp_level(), mh->highest_osr_comp_level()); |
973293defacd
7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents:
3837
diff
changeset
|
52 } |
973293defacd
7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents:
3837
diff
changeset
|
53 |
1783 | 54 // Print an event. |
55 void SimpleThresholdPolicy::print_event(EventType type, methodHandle mh, methodHandle imh, | |
56 int bci, CompLevel level) { | |
57 bool inlinee_event = mh() != imh(); | |
58 | |
59 ttyLocker tty_lock; | |
60 tty->print("%lf: [", os::elapsedTime()); | |
61 | |
62 switch(type) { | |
63 case CALL: | |
64 tty->print("call"); | |
65 break; | |
66 case LOOP: | |
67 tty->print("loop"); | |
68 break; | |
69 case COMPILE: | |
70 tty->print("compile"); | |
2252 | 71 break; |
3791
2c359f27615c
7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents:
3790
diff
changeset
|
72 case REMOVE_FROM_QUEUE: |
2c359f27615c
7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents:
3790
diff
changeset
|
73 tty->print("remove-from-queue"); |
2252 | 74 break; |
3791
2c359f27615c
7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents:
3790
diff
changeset
|
75 case UPDATE_IN_QUEUE: |
2c359f27615c
7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents:
3790
diff
changeset
|
76 tty->print("update-in-queue"); |
2252 | 77 break; |
78 case REPROFILE: | |
79 tty->print("reprofile"); | |
80 break; | |
3791
2c359f27615c
7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents:
3790
diff
changeset
|
81 case MAKE_NOT_ENTRANT: |
2c359f27615c
7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents:
3790
diff
changeset
|
82 tty->print("make-not-entrant"); |
2c359f27615c
7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents:
3790
diff
changeset
|
83 break; |
2252 | 84 default: |
85 tty->print("unknown"); | |
1783 | 86 } |
87 | |
88 tty->print(" level: %d ", level); | |
89 | |
90 ResourceMark rm; | |
91 char *method_name = mh->name_and_sig_as_C_string(); | |
92 tty->print("[%s", method_name); | |
93 if (inlinee_event) { | |
94 char *inlinee_name = imh->name_and_sig_as_C_string(); | |
95 tty->print(" [%s]] ", inlinee_name); | |
96 } | |
97 else tty->print("] "); | |
98 tty->print("@%d queues: %d,%d", bci, CompileBroker::queue_size(CompLevel_full_profile), | |
99 CompileBroker::queue_size(CompLevel_full_optimization)); | |
100 | |
101 print_specific(type, mh, imh, bci, level); | |
102 | |
103 if (type != COMPILE) { | |
4116
973293defacd
7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents:
3837
diff
changeset
|
104 print_counters("", mh); |
1783 | 105 if (inlinee_event) { |
4116
973293defacd
7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents:
3837
diff
changeset
|
106 print_counters("inlinee ", imh); |
1783 | 107 } |
108 tty->print(" compilable: "); | |
109 bool need_comma = false; | |
110 if (!mh->is_not_compilable(CompLevel_full_profile)) { | |
111 tty->print("c1"); | |
112 need_comma = true; | |
113 } | |
114 if (!mh->is_not_compilable(CompLevel_full_optimization)) { | |
115 if (need_comma) tty->print(", "); | |
116 tty->print("c2"); | |
117 need_comma = true; | |
118 } | |
119 if (!mh->is_not_osr_compilable()) { | |
120 if (need_comma) tty->print(", "); | |
121 tty->print("osr"); | |
122 } | |
123 tty->print(" status:"); | |
124 if (mh->queued_for_compilation()) { | |
125 tty->print(" in queue"); | |
126 } else tty->print(" idle"); | |
127 } | |
128 tty->print_cr("]"); | |
129 } | |
130 | |
131 void SimpleThresholdPolicy::initialize() { | |
132 if (FLAG_IS_DEFAULT(CICompilerCount)) { | |
133 FLAG_SET_DEFAULT(CICompilerCount, 3); | |
134 } | |
135 int count = CICompilerCount; | |
136 if (CICompilerCountPerCPU) { | |
137 count = MAX2(log2_intptr(os::active_processor_count()), 1) * 3 / 2; | |
138 } | |
139 set_c1_count(MAX2(count / 3, 1)); | |
140 set_c2_count(MAX2(count - count / 3, 1)); | |
141 } | |
142 | |
143 void SimpleThresholdPolicy::set_carry_if_necessary(InvocationCounter *counter) { | |
144 if (!counter->carry() && counter->count() > InvocationCounter::count_limit / 2) { | |
145 counter->set_carry_flag(); | |
146 } | |
147 } | |
148 | |
149 // Set carry flags on the counters if necessary | |
150 void SimpleThresholdPolicy::handle_counter_overflow(methodOop method) { | |
151 set_carry_if_necessary(method->invocation_counter()); | |
152 set_carry_if_necessary(method->backedge_counter()); | |
153 methodDataOop mdo = method->method_data(); | |
154 if (mdo != NULL) { | |
155 set_carry_if_necessary(mdo->invocation_counter()); | |
156 set_carry_if_necessary(mdo->backedge_counter()); | |
157 } | |
158 } | |
159 | |
160 // Called with the queue locked and with at least one element | |
161 CompileTask* SimpleThresholdPolicy::select_task(CompileQueue* compile_queue) { | |
162 return compile_queue->first(); | |
163 } | |
164 | |
2252 | 165 void SimpleThresholdPolicy::reprofile(ScopeDesc* trap_scope, bool is_osr) { |
166 for (ScopeDesc* sd = trap_scope;; sd = sd->sender()) { | |
167 if (PrintTieredEvents) { | |
168 methodHandle mh(sd->method()); | |
169 print_event(REPROFILE, mh, mh, InvocationEntryBci, CompLevel_none); | |
170 } | |
171 methodDataOop mdo = sd->method()->method_data(); | |
172 if (mdo != NULL) { | |
173 mdo->reset_start_counters(); | |
174 } | |
175 if (sd->is_top()) break; | |
176 } | |
177 } | |
178 | |
1783 | 179 nmethod* SimpleThresholdPolicy::event(methodHandle method, methodHandle inlinee, |
4825
20334ed5ed3c
7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents:
4116
diff
changeset
|
180 int branch_bci, int bci, CompLevel comp_level, nmethod* nm, JavaThread* thread) { |
1783 | 181 if (comp_level == CompLevel_none && |
4825
20334ed5ed3c
7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents:
4116
diff
changeset
|
182 JvmtiExport::can_post_interpreter_events() && |
20334ed5ed3c
7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents:
4116
diff
changeset
|
183 thread->is_interp_only_mode()) { |
20334ed5ed3c
7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents:
4116
diff
changeset
|
184 return NULL; |
1783 | 185 } |
186 nmethod *osr_nm = NULL; | |
187 | |
188 handle_counter_overflow(method()); | |
189 if (method() != inlinee()) { | |
190 handle_counter_overflow(inlinee()); | |
191 } | |
192 | |
193 if (PrintTieredEvents) { | |
194 print_event(bci == InvocationEntryBci ? CALL : LOOP, method, inlinee, bci, comp_level); | |
195 } | |
196 | |
197 if (bci == InvocationEntryBci) { | |
4825
20334ed5ed3c
7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents:
4116
diff
changeset
|
198 method_invocation_event(method, inlinee, comp_level, nm, thread); |
1783 | 199 } else { |
4825
20334ed5ed3c
7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents:
4116
diff
changeset
|
200 method_back_branch_event(method, inlinee, bci, comp_level, nm, thread); |
3791
2c359f27615c
7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents:
3790
diff
changeset
|
201 // method == inlinee if the event originated in the main method |
2c359f27615c
7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents:
3790
diff
changeset
|
202 int highest_level = inlinee->highest_osr_comp_level(); |
1783 | 203 if (highest_level > comp_level) { |
3791
2c359f27615c
7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents:
3790
diff
changeset
|
204 osr_nm = inlinee->lookup_osr_nmethod_for(bci, highest_level, false); |
1783 | 205 } |
206 } | |
207 return osr_nm; | |
208 } | |
209 | |
210 // Check if the method can be compiled, change level if necessary | |
4825
20334ed5ed3c
7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents:
4116
diff
changeset
|
211 void SimpleThresholdPolicy::compile(methodHandle mh, int bci, CompLevel level, JavaThread* thread) { |
3837
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
212 assert(level <= TieredStopAtLevel, "Invalid compilation level"); |
1783 | 213 if (level == CompLevel_none) { |
214 return; | |
215 } | |
1964
22ef3370343b
7000349: Tiered reacts incorrectly to C1 compilation failures
iveresov
parents:
1783
diff
changeset
|
216 // Check if the method can be compiled. If it cannot be compiled with C1, continue profiling |
22ef3370343b
7000349: Tiered reacts incorrectly to C1 compilation failures
iveresov
parents:
1783
diff
changeset
|
217 // in the interpreter and then compile with C2 (the transition function will request that, |
22ef3370343b
7000349: Tiered reacts incorrectly to C1 compilation failures
iveresov
parents:
1783
diff
changeset
|
218 // see common() ). If the method cannot be compiled with C2 but still can with C1, compile it with |
22ef3370343b
7000349: Tiered reacts incorrectly to C1 compilation failures
iveresov
parents:
1783
diff
changeset
|
219 // pure C1. |
1783 | 220 if (!can_be_compiled(mh, level)) { |
221 if (level == CompLevel_full_optimization && can_be_compiled(mh, CompLevel_simple)) { | |
4825
20334ed5ed3c
7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents:
4116
diff
changeset
|
222 compile(mh, bci, CompLevel_simple, thread); |
1783 | 223 } |
224 return; | |
225 } | |
226 if (bci != InvocationEntryBci && mh->is_not_osr_compilable()) { | |
227 return; | |
228 } | |
229 if (!CompileBroker::compilation_is_in_queue(mh, bci)) { | |
3837
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
230 if (PrintTieredEvents) { |
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
231 print_event(COMPILE, mh, mh, bci, level); |
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
232 } |
4825
20334ed5ed3c
7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents:
4116
diff
changeset
|
233 submit_compile(mh, bci, level, thread); |
1783 | 234 } |
235 } | |
236 | |
237 // Tell the broker to compile the method | |
4825
20334ed5ed3c
7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents:
4116
diff
changeset
|
238 void SimpleThresholdPolicy::submit_compile(methodHandle mh, int bci, CompLevel level, JavaThread* thread) { |
1783 | 239 int hot_count = (bci == InvocationEntryBci) ? mh->invocation_count() : mh->backedge_count(); |
4825
20334ed5ed3c
7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents:
4116
diff
changeset
|
240 CompileBroker::compile_method(mh, bci, level, mh, hot_count, "tiered", thread); |
1783 | 241 } |
242 | |
243 // Call and loop predicates determine whether a transition to a higher | |
244 // compilation level should be performed (pointers to predicate functions | |
245 // are passed to common() transition function). | |
246 bool SimpleThresholdPolicy::loop_predicate(int i, int b, CompLevel cur_level) { | |
247 switch(cur_level) { | |
248 case CompLevel_none: | |
249 case CompLevel_limited_profile: { | |
250 return loop_predicate_helper<CompLevel_none>(i, b, 1.0); | |
251 } | |
252 case CompLevel_full_profile: { | |
253 return loop_predicate_helper<CompLevel_full_profile>(i, b, 1.0); | |
254 } | |
255 default: | |
256 return true; | |
257 } | |
258 } | |
259 | |
260 bool SimpleThresholdPolicy::call_predicate(int i, int b, CompLevel cur_level) { | |
261 switch(cur_level) { | |
262 case CompLevel_none: | |
263 case CompLevel_limited_profile: { | |
264 return call_predicate_helper<CompLevel_none>(i, b, 1.0); | |
265 } | |
266 case CompLevel_full_profile: { | |
267 return call_predicate_helper<CompLevel_full_profile>(i, b, 1.0); | |
268 } | |
269 default: | |
270 return true; | |
271 } | |
272 } | |
273 | |
274 // Determine is a method is mature. | |
275 bool SimpleThresholdPolicy::is_mature(methodOop method) { | |
276 if (is_trivial(method)) return true; | |
277 methodDataOop mdo = method->method_data(); | |
278 if (mdo != NULL) { | |
279 int i = mdo->invocation_count(); | |
280 int b = mdo->backedge_count(); | |
281 double k = ProfileMaturityPercentage / 100.0; | |
282 return call_predicate_helper<CompLevel_full_profile>(i, b, k) || | |
283 loop_predicate_helper<CompLevel_full_profile>(i, b, k); | |
284 } | |
285 return false; | |
286 } | |
287 | |
288 // Common transition function. Given a predicate determines if a method should transition to another level. | |
289 CompLevel SimpleThresholdPolicy::common(Predicate p, methodOop method, CompLevel cur_level) { | |
290 CompLevel next_level = cur_level; | |
291 int i = method->invocation_count(); | |
292 int b = method->backedge_count(); | |
293 | |
3837
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
294 if (is_trivial(method)) { |
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
295 next_level = CompLevel_simple; |
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
296 } else { |
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
297 switch(cur_level) { |
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
298 case CompLevel_none: |
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
299 // If we were at full profile level, would we switch to full opt? |
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
300 if (common(p, method, CompLevel_full_profile) == CompLevel_full_optimization) { |
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
301 next_level = CompLevel_full_optimization; |
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
302 } else if ((this->*p)(i, b, cur_level)) { |
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
303 next_level = CompLevel_full_profile; |
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
304 } |
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
305 break; |
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
306 case CompLevel_limited_profile: |
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
307 case CompLevel_full_profile: |
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
308 { |
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
309 methodDataOop mdo = method->method_data(); |
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
310 if (mdo != NULL) { |
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
311 if (mdo->would_profile()) { |
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
312 int mdo_i = mdo->invocation_count_delta(); |
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
313 int mdo_b = mdo->backedge_count_delta(); |
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
314 if ((this->*p)(mdo_i, mdo_b, cur_level)) { |
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
315 next_level = CompLevel_full_optimization; |
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
316 } |
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
317 } else { |
2252 | 318 next_level = CompLevel_full_optimization; |
319 } | |
1783 | 320 } |
321 } | |
3837
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
322 break; |
1783 | 323 } |
324 } | |
3837
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
325 return MIN2(next_level, (CompLevel)TieredStopAtLevel); |
1783 | 326 } |
327 | |
328 // Determine if a method should be compiled with a normal entry point at a different level. | |
329 CompLevel SimpleThresholdPolicy::call_event(methodOop method, CompLevel cur_level) { | |
3790
6f6e91603a45
7058689: Tiered: Reprofiling doesn't happen in presence of level 4 OSR methods
iveresov
parents:
3358
diff
changeset
|
330 CompLevel osr_level = MIN2((CompLevel) method->highest_osr_comp_level(), |
6f6e91603a45
7058689: Tiered: Reprofiling doesn't happen in presence of level 4 OSR methods
iveresov
parents:
3358
diff
changeset
|
331 common(&SimpleThresholdPolicy::loop_predicate, method, cur_level)); |
1783 | 332 CompLevel next_level = common(&SimpleThresholdPolicy::call_predicate, method, cur_level); |
333 | |
334 // If OSR method level is greater than the regular method level, the levels should be | |
335 // equalized by raising the regular method level in order to avoid OSRs during each | |
336 // invocation of the method. | |
337 if (osr_level == CompLevel_full_optimization && cur_level == CompLevel_full_profile) { | |
338 methodDataOop mdo = method->method_data(); | |
339 guarantee(mdo != NULL, "MDO should not be NULL"); | |
340 if (mdo->invocation_count() >= 1) { | |
341 next_level = CompLevel_full_optimization; | |
342 } | |
343 } else { | |
344 next_level = MAX2(osr_level, next_level); | |
345 } | |
346 | |
347 return next_level; | |
348 } | |
349 | |
350 // Determine if we should do an OSR compilation of a given method. | |
351 CompLevel SimpleThresholdPolicy::loop_event(methodOop method, CompLevel cur_level) { | |
3790
6f6e91603a45
7058689: Tiered: Reprofiling doesn't happen in presence of level 4 OSR methods
iveresov
parents:
3358
diff
changeset
|
352 CompLevel next_level = common(&SimpleThresholdPolicy::loop_predicate, method, cur_level); |
1783 | 353 if (cur_level == CompLevel_none) { |
354 // If there is a live OSR method that means that we deopted to the interpreter | |
355 // for the transition. | |
3790
6f6e91603a45
7058689: Tiered: Reprofiling doesn't happen in presence of level 4 OSR methods
iveresov
parents:
3358
diff
changeset
|
356 CompLevel osr_level = MIN2((CompLevel)method->highest_osr_comp_level(), next_level); |
1783 | 357 if (osr_level > CompLevel_none) { |
358 return osr_level; | |
359 } | |
360 } | |
3790
6f6e91603a45
7058689: Tiered: Reprofiling doesn't happen in presence of level 4 OSR methods
iveresov
parents:
3358
diff
changeset
|
361 return next_level; |
1783 | 362 } |
363 | |
364 | |
365 // Handle the invocation event. | |
366 void SimpleThresholdPolicy::method_invocation_event(methodHandle mh, methodHandle imh, | |
4825
20334ed5ed3c
7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents:
4116
diff
changeset
|
367 CompLevel level, nmethod* nm, JavaThread* thread) { |
1783 | 368 if (is_compilation_enabled() && !CompileBroker::compilation_is_in_queue(mh, InvocationEntryBci)) { |
369 CompLevel next_level = call_event(mh(), level); | |
370 if (next_level != level) { | |
4825
20334ed5ed3c
7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents:
4116
diff
changeset
|
371 compile(mh, InvocationEntryBci, next_level, thread); |
1783 | 372 } |
373 } | |
374 } | |
375 | |
376 // Handle the back branch event. Notice that we can compile the method | |
377 // with a regular entry from here. | |
378 void SimpleThresholdPolicy::method_back_branch_event(methodHandle mh, methodHandle imh, | |
4825
20334ed5ed3c
7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents:
4116
diff
changeset
|
379 int bci, CompLevel level, nmethod* nm, JavaThread* thread) { |
1783 | 380 // If the method is already compiling, quickly bail out. |
381 if (is_compilation_enabled() && !CompileBroker::compilation_is_in_queue(mh, bci)) { | |
382 // Use loop event as an opportinity to also check there's been | |
383 // enough calls. | |
384 CompLevel cur_level = comp_level(mh()); | |
385 CompLevel next_level = call_event(mh(), cur_level); | |
386 CompLevel next_osr_level = loop_event(mh(), level); | |
387 | |
388 next_level = MAX2(next_level, | |
389 next_osr_level < CompLevel_full_optimization ? next_osr_level : cur_level); | |
390 bool is_compiling = false; | |
391 if (next_level != cur_level) { | |
4825
20334ed5ed3c
7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents:
4116
diff
changeset
|
392 compile(mh, InvocationEntryBci, next_level, thread); |
1783 | 393 is_compiling = true; |
394 } | |
395 | |
396 // Do the OSR version | |
397 if (!is_compiling && next_osr_level != level) { | |
4825
20334ed5ed3c
7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents:
4116
diff
changeset
|
398 compile(mh, bci, next_osr_level, thread); |
1783 | 399 } |
400 } | |
401 } |