Mercurial > hg > truffle
annotate src/share/vm/runtime/simpleThresholdPolicy.cpp @ 21195:a4b60873851b
LIRKind: add #merge().
author | Josef Eisl <josef.eisl@jku.at> |
---|---|
date | Thu, 23 Apr 2015 11:30:06 +0200 |
parents | 7848fc12602b |
children |
rev | line source |
---|---|
1783 | 1 /* |
10105
aeaca88565e6
8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents:
6800
diff
changeset
|
2 * Copyright (c) 2010, 2013, 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(); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4825
diff
changeset
|
37 MethodData* mdh = mh->method_data(); |
4116
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; |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4825
diff
changeset
|
40 if (mdh != NULL) { |
4116
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 } |
6800
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
46 tty->print(" %stotal=%d,%d %smdo=%d(%d),%d(%d)", prefix, |
4116
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); |
6800
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
50 tty->print(" %smax levels=%d,%d", prefix, |
4116
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 | |
6800
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
88 tty->print(" level=%d ", level); |
1783 | 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("] "); | |
6800
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
98 tty->print("@%d queues=%d,%d", bci, CompileBroker::queue_size(CompLevel_full_profile), |
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
99 CompileBroker::queue_size(CompLevel_full_optimization)); |
1783 | 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 } |
6800
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
108 tty->print(" compilable="); |
1783 | 109 bool need_comma = false; |
110 if (!mh->is_not_compilable(CompLevel_full_profile)) { | |
111 tty->print("c1"); | |
112 need_comma = true; | |
113 } | |
6800
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
114 if (!mh->is_not_osr_compilable(CompLevel_full_profile)) { |
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
115 if (need_comma) tty->print(","); |
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
116 tty->print("c1-osr"); |
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
117 need_comma = true; |
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
118 } |
1783 | 119 if (!mh->is_not_compilable(CompLevel_full_optimization)) { |
6800
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
120 if (need_comma) tty->print(","); |
1783 | 121 tty->print("c2"); |
122 need_comma = true; | |
123 } | |
6800
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
124 if (!mh->is_not_osr_compilable(CompLevel_full_optimization)) { |
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
125 if (need_comma) tty->print(","); |
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
126 tty->print("c2-osr"); |
1783 | 127 } |
6800
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
128 tty->print(" status="); |
1783 | 129 if (mh->queued_for_compilation()) { |
6800
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
130 tty->print("in-queue"); |
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
131 } else tty->print("idle"); |
1783 | 132 } |
133 tty->print_cr("]"); | |
134 } | |
135 | |
136 void SimpleThresholdPolicy::initialize() { | |
137 if (FLAG_IS_DEFAULT(CICompilerCount)) { | |
138 FLAG_SET_DEFAULT(CICompilerCount, 3); | |
139 } | |
140 int count = CICompilerCount; | |
141 if (CICompilerCountPerCPU) { | |
142 count = MAX2(log2_intptr(os::active_processor_count()), 1) * 3 / 2; | |
143 } | |
144 set_c1_count(MAX2(count / 3, 1)); | |
17906
7150b16fda52
8029436: CICompilerCount is not updated when the number of compiler threads is adjusted to the number of CPUs
anoll
parents:
10204
diff
changeset
|
145 set_c2_count(MAX2(count - c1_count(), 1)); |
7150b16fda52
8029436: CICompilerCount is not updated when the number of compiler threads is adjusted to the number of CPUs
anoll
parents:
10204
diff
changeset
|
146 FLAG_SET_ERGO(intx, CICompilerCount, c1_count() + c2_count()); |
1783 | 147 } |
148 | |
149 void SimpleThresholdPolicy::set_carry_if_necessary(InvocationCounter *counter) { | |
150 if (!counter->carry() && counter->count() > InvocationCounter::count_limit / 2) { | |
151 counter->set_carry_flag(); | |
152 } | |
153 } | |
154 | |
155 // Set carry flags on the counters if necessary | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4825
diff
changeset
|
156 void SimpleThresholdPolicy::handle_counter_overflow(Method* method) { |
10105
aeaca88565e6
8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents:
6800
diff
changeset
|
157 MethodCounters *mcs = method->method_counters(); |
10204
487d442ef257
8013036: vm/runtime/simpleThresholdPolicy.cpp: assert(mcs != NULL).
jiangli
parents:
10105
diff
changeset
|
158 if (mcs != NULL) { |
487d442ef257
8013036: vm/runtime/simpleThresholdPolicy.cpp: assert(mcs != NULL).
jiangli
parents:
10105
diff
changeset
|
159 set_carry_if_necessary(mcs->invocation_counter()); |
487d442ef257
8013036: vm/runtime/simpleThresholdPolicy.cpp: assert(mcs != NULL).
jiangli
parents:
10105
diff
changeset
|
160 set_carry_if_necessary(mcs->backedge_counter()); |
487d442ef257
8013036: vm/runtime/simpleThresholdPolicy.cpp: assert(mcs != NULL).
jiangli
parents:
10105
diff
changeset
|
161 } |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4825
diff
changeset
|
162 MethodData* mdo = method->method_data(); |
1783 | 163 if (mdo != NULL) { |
164 set_carry_if_necessary(mdo->invocation_counter()); | |
165 set_carry_if_necessary(mdo->backedge_counter()); | |
166 } | |
167 } | |
168 | |
169 // Called with the queue locked and with at least one element | |
170 CompileTask* SimpleThresholdPolicy::select_task(CompileQueue* compile_queue) { | |
171 return compile_queue->first(); | |
172 } | |
173 | |
2252 | 174 void SimpleThresholdPolicy::reprofile(ScopeDesc* trap_scope, bool is_osr) { |
175 for (ScopeDesc* sd = trap_scope;; sd = sd->sender()) { | |
176 if (PrintTieredEvents) { | |
177 methodHandle mh(sd->method()); | |
178 print_event(REPROFILE, mh, mh, InvocationEntryBci, CompLevel_none); | |
179 } | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4825
diff
changeset
|
180 MethodData* mdo = sd->method()->method_data(); |
2252 | 181 if (mdo != NULL) { |
182 mdo->reset_start_counters(); | |
183 } | |
184 if (sd->is_top()) break; | |
185 } | |
186 } | |
187 | |
1783 | 188 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
|
189 int branch_bci, int bci, CompLevel comp_level, nmethod* nm, JavaThread* thread) { |
1783 | 190 if (comp_level == CompLevel_none && |
4825
20334ed5ed3c
7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents:
4116
diff
changeset
|
191 JvmtiExport::can_post_interpreter_events() && |
20334ed5ed3c
7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents:
4116
diff
changeset
|
192 thread->is_interp_only_mode()) { |
20334ed5ed3c
7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents:
4116
diff
changeset
|
193 return NULL; |
1783 | 194 } |
17912
653e11c86c5a
8041959: Skip replay parsing errors with ReplayIgnoreInitErrors
kvn
parents:
17906
diff
changeset
|
195 if (CompileTheWorld || ReplayCompiles) { |
653e11c86c5a
8041959: Skip replay parsing errors with ReplayIgnoreInitErrors
kvn
parents:
17906
diff
changeset
|
196 // Don't trigger other compiles in testing mode |
653e11c86c5a
8041959: Skip replay parsing errors with ReplayIgnoreInitErrors
kvn
parents:
17906
diff
changeset
|
197 return NULL; |
653e11c86c5a
8041959: Skip replay parsing errors with ReplayIgnoreInitErrors
kvn
parents:
17906
diff
changeset
|
198 } |
1783 | 199 |
200 handle_counter_overflow(method()); | |
201 if (method() != inlinee()) { | |
202 handle_counter_overflow(inlinee()); | |
203 } | |
204 | |
205 if (PrintTieredEvents) { | |
206 print_event(bci == InvocationEntryBci ? CALL : LOOP, method, inlinee, bci, comp_level); | |
207 } | |
208 | |
209 if (bci == InvocationEntryBci) { | |
4825
20334ed5ed3c
7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents:
4116
diff
changeset
|
210 method_invocation_event(method, inlinee, comp_level, nm, thread); |
1783 | 211 } else { |
20609
468850e35e48
8062169: Multiple OSR compilations issued for same bci
thartmann
parents:
20588
diff
changeset
|
212 // method == inlinee if the event originated in the main method |
4825
20334ed5ed3c
7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents:
4116
diff
changeset
|
213 method_back_branch_event(method, inlinee, bci, comp_level, nm, thread); |
20609
468850e35e48
8062169: Multiple OSR compilations issued for same bci
thartmann
parents:
20588
diff
changeset
|
214 // Check if event led to a higher level OSR compilation |
468850e35e48
8062169: Multiple OSR compilations issued for same bci
thartmann
parents:
20588
diff
changeset
|
215 nmethod* osr_nm = inlinee->lookup_osr_nmethod_for(bci, comp_level, false); |
468850e35e48
8062169: Multiple OSR compilations issued for same bci
thartmann
parents:
20588
diff
changeset
|
216 if (osr_nm != NULL && osr_nm->comp_level() > comp_level) { |
468850e35e48
8062169: Multiple OSR compilations issued for same bci
thartmann
parents:
20588
diff
changeset
|
217 // Perform OSR with new nmethod |
468850e35e48
8062169: Multiple OSR compilations issued for same bci
thartmann
parents:
20588
diff
changeset
|
218 return osr_nm; |
1783 | 219 } |
220 } | |
20609
468850e35e48
8062169: Multiple OSR compilations issued for same bci
thartmann
parents:
20588
diff
changeset
|
221 return NULL; |
1783 | 222 } |
223 | |
224 // 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
|
225 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
|
226 assert(level <= TieredStopAtLevel, "Invalid compilation level"); |
1783 | 227 if (level == CompLevel_none) { |
228 return; | |
229 } | |
1964
22ef3370343b
7000349: Tiered reacts incorrectly to C1 compilation failures
iveresov
parents:
1783
diff
changeset
|
230 // 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
|
231 // 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
|
232 // 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
|
233 // pure C1. |
1783 | 234 if (!can_be_compiled(mh, level)) { |
235 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
|
236 compile(mh, bci, CompLevel_simple, thread); |
1783 | 237 } |
238 return; | |
239 } | |
6800
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
240 if (bci != InvocationEntryBci && mh->is_not_osr_compilable(level)) { |
1783 | 241 return; |
242 } | |
20588
41dcdd636080
8040798: compiler/startup/SmallCodeCacheStartup.java timed out in RT_Baseline
anoll
parents:
17912
diff
changeset
|
243 if (!CompileBroker::compilation_is_in_queue(mh)) { |
3837
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
244 if (PrintTieredEvents) { |
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
245 print_event(COMPILE, mh, mh, bci, level); |
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
246 } |
4825
20334ed5ed3c
7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents:
4116
diff
changeset
|
247 submit_compile(mh, bci, level, thread); |
1783 | 248 } |
249 } | |
250 | |
251 // 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
|
252 void SimpleThresholdPolicy::submit_compile(methodHandle mh, int bci, CompLevel level, JavaThread* thread) { |
1783 | 253 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
|
254 CompileBroker::compile_method(mh, bci, level, mh, hot_count, "tiered", thread); |
1783 | 255 } |
256 | |
257 // Call and loop predicates determine whether a transition to a higher | |
258 // compilation level should be performed (pointers to predicate functions | |
259 // are passed to common() transition function). | |
260 bool SimpleThresholdPolicy::loop_predicate(int i, int b, CompLevel cur_level) { | |
261 switch(cur_level) { | |
262 case CompLevel_none: | |
263 case CompLevel_limited_profile: { | |
264 return loop_predicate_helper<CompLevel_none>(i, b, 1.0); | |
265 } | |
266 case CompLevel_full_profile: { | |
267 return loop_predicate_helper<CompLevel_full_profile>(i, b, 1.0); | |
268 } | |
269 default: | |
270 return true; | |
271 } | |
272 } | |
273 | |
274 bool SimpleThresholdPolicy::call_predicate(int i, int b, CompLevel cur_level) { | |
275 switch(cur_level) { | |
276 case CompLevel_none: | |
277 case CompLevel_limited_profile: { | |
278 return call_predicate_helper<CompLevel_none>(i, b, 1.0); | |
279 } | |
280 case CompLevel_full_profile: { | |
281 return call_predicate_helper<CompLevel_full_profile>(i, b, 1.0); | |
282 } | |
283 default: | |
284 return true; | |
285 } | |
286 } | |
287 | |
288 // Determine is a method is mature. | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4825
diff
changeset
|
289 bool SimpleThresholdPolicy::is_mature(Method* method) { |
1783 | 290 if (is_trivial(method)) return true; |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4825
diff
changeset
|
291 MethodData* mdo = method->method_data(); |
1783 | 292 if (mdo != NULL) { |
293 int i = mdo->invocation_count(); | |
294 int b = mdo->backedge_count(); | |
295 double k = ProfileMaturityPercentage / 100.0; | |
296 return call_predicate_helper<CompLevel_full_profile>(i, b, k) || | |
297 loop_predicate_helper<CompLevel_full_profile>(i, b, k); | |
298 } | |
299 return false; | |
300 } | |
301 | |
302 // Common transition function. Given a predicate determines if a method should transition to another level. | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4825
diff
changeset
|
303 CompLevel SimpleThresholdPolicy::common(Predicate p, Method* method, CompLevel cur_level) { |
1783 | 304 CompLevel next_level = cur_level; |
305 int i = method->invocation_count(); | |
306 int b = method->backedge_count(); | |
307 | |
3837
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
308 if (is_trivial(method)) { |
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
309 next_level = CompLevel_simple; |
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
310 } else { |
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
311 switch(cur_level) { |
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
312 case CompLevel_none: |
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
313 // 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
|
314 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
|
315 next_level = CompLevel_full_optimization; |
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
316 } else if ((this->*p)(i, b, cur_level)) { |
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
317 next_level = CompLevel_full_profile; |
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
318 } |
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
319 break; |
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
320 case CompLevel_limited_profile: |
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
321 case CompLevel_full_profile: |
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
322 { |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4825
diff
changeset
|
323 MethodData* mdo = method->method_data(); |
3837
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
324 if (mdo != NULL) { |
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
325 if (mdo->would_profile()) { |
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
326 int mdo_i = mdo->invocation_count_delta(); |
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
327 int mdo_b = mdo->backedge_count_delta(); |
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
328 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
|
329 next_level = CompLevel_full_optimization; |
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
330 } |
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
331 } else { |
2252 | 332 next_level = CompLevel_full_optimization; |
333 } | |
1783 | 334 } |
335 } | |
3837
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
336 break; |
1783 | 337 } |
338 } | |
3837
43f9d800f276
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
3791
diff
changeset
|
339 return MIN2(next_level, (CompLevel)TieredStopAtLevel); |
1783 | 340 } |
341 | |
342 // Determine if a method should be compiled with a normal entry point at a different level. | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4825
diff
changeset
|
343 CompLevel SimpleThresholdPolicy::call_event(Method* method, CompLevel cur_level) { |
3790
6f6e91603a45
7058689: Tiered: Reprofiling doesn't happen in presence of level 4 OSR methods
iveresov
parents:
3358
diff
changeset
|
344 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
|
345 common(&SimpleThresholdPolicy::loop_predicate, method, cur_level)); |
1783 | 346 CompLevel next_level = common(&SimpleThresholdPolicy::call_predicate, method, cur_level); |
347 | |
348 // If OSR method level is greater than the regular method level, the levels should be | |
349 // equalized by raising the regular method level in order to avoid OSRs during each | |
350 // invocation of the method. | |
351 if (osr_level == CompLevel_full_optimization && cur_level == CompLevel_full_profile) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4825
diff
changeset
|
352 MethodData* mdo = method->method_data(); |
1783 | 353 guarantee(mdo != NULL, "MDO should not be NULL"); |
354 if (mdo->invocation_count() >= 1) { | |
355 next_level = CompLevel_full_optimization; | |
356 } | |
357 } else { | |
358 next_level = MAX2(osr_level, next_level); | |
359 } | |
360 | |
361 return next_level; | |
362 } | |
363 | |
364 // Determine if we should do an OSR compilation of a given method. | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4825
diff
changeset
|
365 CompLevel SimpleThresholdPolicy::loop_event(Method* method, CompLevel cur_level) { |
3790
6f6e91603a45
7058689: Tiered: Reprofiling doesn't happen in presence of level 4 OSR methods
iveresov
parents:
3358
diff
changeset
|
366 CompLevel next_level = common(&SimpleThresholdPolicy::loop_predicate, method, cur_level); |
1783 | 367 if (cur_level == CompLevel_none) { |
368 // If there is a live OSR method that means that we deopted to the interpreter | |
369 // for the transition. | |
3790
6f6e91603a45
7058689: Tiered: Reprofiling doesn't happen in presence of level 4 OSR methods
iveresov
parents:
3358
diff
changeset
|
370 CompLevel osr_level = MIN2((CompLevel)method->highest_osr_comp_level(), next_level); |
1783 | 371 if (osr_level > CompLevel_none) { |
372 return osr_level; | |
373 } | |
374 } | |
3790
6f6e91603a45
7058689: Tiered: Reprofiling doesn't happen in presence of level 4 OSR methods
iveresov
parents:
3358
diff
changeset
|
375 return next_level; |
1783 | 376 } |
377 | |
378 | |
379 // Handle the invocation event. | |
380 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
|
381 CompLevel level, nmethod* nm, JavaThread* thread) { |
20588
41dcdd636080
8040798: compiler/startup/SmallCodeCacheStartup.java timed out in RT_Baseline
anoll
parents:
17912
diff
changeset
|
382 if (is_compilation_enabled() && !CompileBroker::compilation_is_in_queue(mh)) { |
1783 | 383 CompLevel next_level = call_event(mh(), level); |
384 if (next_level != level) { | |
4825
20334ed5ed3c
7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents:
4116
diff
changeset
|
385 compile(mh, InvocationEntryBci, next_level, thread); |
1783 | 386 } |
387 } | |
388 } | |
389 | |
390 // Handle the back branch event. Notice that we can compile the method | |
391 // with a regular entry from here. | |
392 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
|
393 int bci, CompLevel level, nmethod* nm, JavaThread* thread) { |
1783 | 394 // If the method is already compiling, quickly bail out. |
20588
41dcdd636080
8040798: compiler/startup/SmallCodeCacheStartup.java timed out in RT_Baseline
anoll
parents:
17912
diff
changeset
|
395 if (is_compilation_enabled() && !CompileBroker::compilation_is_in_queue(mh)) { |
41dcdd636080
8040798: compiler/startup/SmallCodeCacheStartup.java timed out in RT_Baseline
anoll
parents:
17912
diff
changeset
|
396 // Use loop event as an opportunity to also check there's been |
1783 | 397 // enough calls. |
398 CompLevel cur_level = comp_level(mh()); | |
399 CompLevel next_level = call_event(mh(), cur_level); | |
400 CompLevel next_osr_level = loop_event(mh(), level); | |
401 | |
402 next_level = MAX2(next_level, | |
403 next_osr_level < CompLevel_full_optimization ? next_osr_level : cur_level); | |
404 bool is_compiling = false; | |
405 if (next_level != cur_level) { | |
4825
20334ed5ed3c
7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents:
4116
diff
changeset
|
406 compile(mh, InvocationEntryBci, next_level, thread); |
1783 | 407 is_compiling = true; |
408 } | |
409 | |
410 // Do the OSR version | |
411 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
|
412 compile(mh, bci, next_osr_level, thread); |
1783 | 413 } |
414 } | |
415 } |