author | zgu |
Fri, 25 Jan 2013 10:04:08 -0500 | |
changeset 15432 | 9d976ca484d8 |
parent 13891 | 35dabd293e56 |
child 17000 | 11bf92e571a2 |
permissions | -rw-r--r-- |
6453 | 1 |
/* |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
11572
diff
changeset
|
2 |
* Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved. |
6453 | 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 |
||
7397 | 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" |
|
8322 | 31 |
#include "code/scopeDesc.hpp" |
6453 | 32 |
|
11192
ff37c2093a0d
7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents:
10250
diff
changeset
|
33 |
|
ff37c2093a0d
7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents:
10250
diff
changeset
|
34 |
void SimpleThresholdPolicy::print_counters(const char* prefix, methodHandle mh) { |
ff37c2093a0d
7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents:
10250
diff
changeset
|
35 |
int invocation_count = mh->invocation_count(); |
ff37c2093a0d
7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents:
10250
diff
changeset
|
36 |
int backedge_count = mh->backedge_count(); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
11572
diff
changeset
|
37 |
MethodData* mdh = mh->method_data(); |
11192
ff37c2093a0d
7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents:
10250
diff
changeset
|
38 |
int mdo_invocations = 0, mdo_backedges = 0; |
ff37c2093a0d
7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents:
10250
diff
changeset
|
39 |
int mdo_invocations_start = 0, mdo_backedges_start = 0; |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
11572
diff
changeset
|
40 |
if (mdh != NULL) { |
11192
ff37c2093a0d
7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents:
10250
diff
changeset
|
41 |
mdo_invocations = mdh->invocation_count(); |
ff37c2093a0d
7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents:
10250
diff
changeset
|
42 |
mdo_backedges = mdh->backedge_count(); |
ff37c2093a0d
7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents:
10250
diff
changeset
|
43 |
mdo_invocations_start = mdh->invocation_count_start(); |
ff37c2093a0d
7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents:
10250
diff
changeset
|
44 |
mdo_backedges_start = mdh->backedge_count_start(); |
ff37c2093a0d
7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents:
10250
diff
changeset
|
45 |
} |
13891
35dabd293e56
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
13728
diff
changeset
|
46 |
tty->print(" %stotal=%d,%d %smdo=%d(%d),%d(%d)", prefix, |
11192
ff37c2093a0d
7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents:
10250
diff
changeset
|
47 |
invocation_count, backedge_count, prefix, |
ff37c2093a0d
7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents:
10250
diff
changeset
|
48 |
mdo_invocations, mdo_invocations_start, |
ff37c2093a0d
7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents:
10250
diff
changeset
|
49 |
mdo_backedges, mdo_backedges_start); |
13891
35dabd293e56
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
13728
diff
changeset
|
50 |
tty->print(" %smax levels=%d,%d", prefix, |
11192
ff37c2093a0d
7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents:
10250
diff
changeset
|
51 |
mh->highest_comp_level(), mh->highest_osr_comp_level()); |
ff37c2093a0d
7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents:
10250
diff
changeset
|
52 |
} |
ff37c2093a0d
7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents:
10250
diff
changeset
|
53 |
|
6453 | 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"); |
|
8322 | 71 |
break; |
10014
a5c2141ee857
7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents:
10013
diff
changeset
|
72 |
case REMOVE_FROM_QUEUE: |
a5c2141ee857
7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents:
10013
diff
changeset
|
73 |
tty->print("remove-from-queue"); |
8322 | 74 |
break; |
10014
a5c2141ee857
7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents:
10013
diff
changeset
|
75 |
case UPDATE_IN_QUEUE: |
a5c2141ee857
7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents:
10013
diff
changeset
|
76 |
tty->print("update-in-queue"); |
8322 | 77 |
break; |
78 |
case REPROFILE: |
|
79 |
tty->print("reprofile"); |
|
80 |
break; |
|
10014
a5c2141ee857
7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents:
10013
diff
changeset
|
81 |
case MAKE_NOT_ENTRANT: |
a5c2141ee857
7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents:
10013
diff
changeset
|
82 |
tty->print("make-not-entrant"); |
a5c2141ee857
7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents:
10013
diff
changeset
|
83 |
break; |
8322 | 84 |
default: |
85 |
tty->print("unknown"); |
|
6453 | 86 |
} |
87 |
||
13891
35dabd293e56
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
13728
diff
changeset
|
88 |
tty->print(" level=%d ", level); |
6453 | 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("] "); |
|
13891
35dabd293e56
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
13728
diff
changeset
|
98 |
tty->print("@%d queues=%d,%d", bci, CompileBroker::queue_size(CompLevel_full_profile), |
35dabd293e56
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
13728
diff
changeset
|
99 |
CompileBroker::queue_size(CompLevel_full_optimization)); |
6453 | 100 |
|
101 |
print_specific(type, mh, imh, bci, level); |
|
102 |
||
103 |
if (type != COMPILE) { |
|
11192
ff37c2093a0d
7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents:
10250
diff
changeset
|
104 |
print_counters("", mh); |
6453 | 105 |
if (inlinee_event) { |
11192
ff37c2093a0d
7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents:
10250
diff
changeset
|
106 |
print_counters("inlinee ", imh); |
6453 | 107 |
} |
13891
35dabd293e56
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
13728
diff
changeset
|
108 |
tty->print(" compilable="); |
6453 | 109 |
bool need_comma = false; |
110 |
if (!mh->is_not_compilable(CompLevel_full_profile)) { |
|
111 |
tty->print("c1"); |
|
112 |
need_comma = true; |
|
113 |
} |
|
13891
35dabd293e56
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
13728
diff
changeset
|
114 |
if (!mh->is_not_osr_compilable(CompLevel_full_profile)) { |
35dabd293e56
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
13728
diff
changeset
|
115 |
if (need_comma) tty->print(","); |
35dabd293e56
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
13728
diff
changeset
|
116 |
tty->print("c1-osr"); |
35dabd293e56
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
13728
diff
changeset
|
117 |
need_comma = true; |
35dabd293e56
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
13728
diff
changeset
|
118 |
} |
6453 | 119 |
if (!mh->is_not_compilable(CompLevel_full_optimization)) { |
13891
35dabd293e56
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
13728
diff
changeset
|
120 |
if (need_comma) tty->print(","); |
6453 | 121 |
tty->print("c2"); |
122 |
need_comma = true; |
|
123 |
} |
|
13891
35dabd293e56
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
13728
diff
changeset
|
124 |
if (!mh->is_not_osr_compilable(CompLevel_full_optimization)) { |
35dabd293e56
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
13728
diff
changeset
|
125 |
if (need_comma) tty->print(","); |
35dabd293e56
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
13728
diff
changeset
|
126 |
tty->print("c2-osr"); |
6453 | 127 |
} |
13891
35dabd293e56
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
13728
diff
changeset
|
128 |
tty->print(" status="); |
6453 | 129 |
if (mh->queued_for_compilation()) { |
13891
35dabd293e56
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
13728
diff
changeset
|
130 |
tty->print("in-queue"); |
35dabd293e56
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
13728
diff
changeset
|
131 |
} else tty->print("idle"); |
6453 | 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)); |
|
145 |
set_c2_count(MAX2(count - count / 3, 1)); |
|
146 |
} |
|
147 |
||
148 |
void SimpleThresholdPolicy::set_carry_if_necessary(InvocationCounter *counter) { |
|
149 |
if (!counter->carry() && counter->count() > InvocationCounter::count_limit / 2) { |
|
150 |
counter->set_carry_flag(); |
|
151 |
} |
|
152 |
} |
|
153 |
||
154 |
// Set carry flags on the counters if necessary |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
11572
diff
changeset
|
155 |
void SimpleThresholdPolicy::handle_counter_overflow(Method* method) { |
6453 | 156 |
set_carry_if_necessary(method->invocation_counter()); |
157 |
set_carry_if_necessary(method->backedge_counter()); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
11572
diff
changeset
|
158 |
MethodData* mdo = method->method_data(); |
6453 | 159 |
if (mdo != NULL) { |
160 |
set_carry_if_necessary(mdo->invocation_counter()); |
|
161 |
set_carry_if_necessary(mdo->backedge_counter()); |
|
162 |
} |
|
163 |
} |
|
164 |
||
165 |
// Called with the queue locked and with at least one element |
|
166 |
CompileTask* SimpleThresholdPolicy::select_task(CompileQueue* compile_queue) { |
|
167 |
return compile_queue->first(); |
|
168 |
} |
|
169 |
||
8322 | 170 |
void SimpleThresholdPolicy::reprofile(ScopeDesc* trap_scope, bool is_osr) { |
171 |
for (ScopeDesc* sd = trap_scope;; sd = sd->sender()) { |
|
172 |
if (PrintTieredEvents) { |
|
173 |
methodHandle mh(sd->method()); |
|
174 |
print_event(REPROFILE, mh, mh, InvocationEntryBci, CompLevel_none); |
|
175 |
} |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
11572
diff
changeset
|
176 |
MethodData* mdo = sd->method()->method_data(); |
8322 | 177 |
if (mdo != NULL) { |
178 |
mdo->reset_start_counters(); |
|
179 |
} |
|
180 |
if (sd->is_top()) break; |
|
181 |
} |
|
182 |
} |
|
183 |
||
6453 | 184 |
nmethod* SimpleThresholdPolicy::event(methodHandle method, methodHandle inlinee, |
11572
84afef481892
7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents:
11192
diff
changeset
|
185 |
int branch_bci, int bci, CompLevel comp_level, nmethod* nm, JavaThread* thread) { |
6453 | 186 |
if (comp_level == CompLevel_none && |
11572
84afef481892
7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents:
11192
diff
changeset
|
187 |
JvmtiExport::can_post_interpreter_events() && |
84afef481892
7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents:
11192
diff
changeset
|
188 |
thread->is_interp_only_mode()) { |
84afef481892
7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents:
11192
diff
changeset
|
189 |
return NULL; |
6453 | 190 |
} |
191 |
nmethod *osr_nm = NULL; |
|
192 |
||
193 |
handle_counter_overflow(method()); |
|
194 |
if (method() != inlinee()) { |
|
195 |
handle_counter_overflow(inlinee()); |
|
196 |
} |
|
197 |
||
198 |
if (PrintTieredEvents) { |
|
199 |
print_event(bci == InvocationEntryBci ? CALL : LOOP, method, inlinee, bci, comp_level); |
|
200 |
} |
|
201 |
||
202 |
if (bci == InvocationEntryBci) { |
|
11572
84afef481892
7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents:
11192
diff
changeset
|
203 |
method_invocation_event(method, inlinee, comp_level, nm, thread); |
6453 | 204 |
} else { |
11572
84afef481892
7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents:
11192
diff
changeset
|
205 |
method_back_branch_event(method, inlinee, bci, comp_level, nm, thread); |
10014
a5c2141ee857
7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents:
10013
diff
changeset
|
206 |
// method == inlinee if the event originated in the main method |
a5c2141ee857
7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents:
10013
diff
changeset
|
207 |
int highest_level = inlinee->highest_osr_comp_level(); |
6453 | 208 |
if (highest_level > comp_level) { |
10014
a5c2141ee857
7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents:
10013
diff
changeset
|
209 |
osr_nm = inlinee->lookup_osr_nmethod_for(bci, highest_level, false); |
6453 | 210 |
} |
211 |
} |
|
212 |
return osr_nm; |
|
213 |
} |
|
214 |
||
215 |
// Check if the method can be compiled, change level if necessary |
|
11572
84afef481892
7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents:
11192
diff
changeset
|
216 |
void SimpleThresholdPolicy::compile(methodHandle mh, int bci, CompLevel level, JavaThread* thread) { |
10250
0794cd144834
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
10014
diff
changeset
|
217 |
assert(level <= TieredStopAtLevel, "Invalid compilation level"); |
6453 | 218 |
if (level == CompLevel_none) { |
219 |
return; |
|
220 |
} |
|
7389
93110864f81e
7000349: Tiered reacts incorrectly to C1 compilation failures
iveresov
parents:
6453
diff
changeset
|
221 |
// Check if the method can be compiled. If it cannot be compiled with C1, continue profiling |
93110864f81e
7000349: Tiered reacts incorrectly to C1 compilation failures
iveresov
parents:
6453
diff
changeset
|
222 |
// in the interpreter and then compile with C2 (the transition function will request that, |
93110864f81e
7000349: Tiered reacts incorrectly to C1 compilation failures
iveresov
parents:
6453
diff
changeset
|
223 |
// see common() ). If the method cannot be compiled with C2 but still can with C1, compile it with |
93110864f81e
7000349: Tiered reacts incorrectly to C1 compilation failures
iveresov
parents:
6453
diff
changeset
|
224 |
// pure C1. |
6453 | 225 |
if (!can_be_compiled(mh, level)) { |
226 |
if (level == CompLevel_full_optimization && can_be_compiled(mh, CompLevel_simple)) { |
|
11572
84afef481892
7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents:
11192
diff
changeset
|
227 |
compile(mh, bci, CompLevel_simple, thread); |
6453 | 228 |
} |
229 |
return; |
|
230 |
} |
|
13891
35dabd293e56
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
13728
diff
changeset
|
231 |
if (bci != InvocationEntryBci && mh->is_not_osr_compilable(level)) { |
6453 | 232 |
return; |
233 |
} |
|
234 |
if (!CompileBroker::compilation_is_in_queue(mh, bci)) { |
|
10250
0794cd144834
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
10014
diff
changeset
|
235 |
if (PrintTieredEvents) { |
0794cd144834
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
10014
diff
changeset
|
236 |
print_event(COMPILE, mh, mh, bci, level); |
0794cd144834
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
10014
diff
changeset
|
237 |
} |
11572
84afef481892
7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents:
11192
diff
changeset
|
238 |
submit_compile(mh, bci, level, thread); |
6453 | 239 |
} |
240 |
} |
|
241 |
||
242 |
// Tell the broker to compile the method |
|
11572
84afef481892
7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents:
11192
diff
changeset
|
243 |
void SimpleThresholdPolicy::submit_compile(methodHandle mh, int bci, CompLevel level, JavaThread* thread) { |
6453 | 244 |
int hot_count = (bci == InvocationEntryBci) ? mh->invocation_count() : mh->backedge_count(); |
11572
84afef481892
7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents:
11192
diff
changeset
|
245 |
CompileBroker::compile_method(mh, bci, level, mh, hot_count, "tiered", thread); |
6453 | 246 |
} |
247 |
||
248 |
// Call and loop predicates determine whether a transition to a higher |
|
249 |
// compilation level should be performed (pointers to predicate functions |
|
250 |
// are passed to common() transition function). |
|
251 |
bool SimpleThresholdPolicy::loop_predicate(int i, int b, CompLevel cur_level) { |
|
252 |
switch(cur_level) { |
|
253 |
case CompLevel_none: |
|
254 |
case CompLevel_limited_profile: { |
|
255 |
return loop_predicate_helper<CompLevel_none>(i, b, 1.0); |
|
256 |
} |
|
257 |
case CompLevel_full_profile: { |
|
258 |
return loop_predicate_helper<CompLevel_full_profile>(i, b, 1.0); |
|
259 |
} |
|
260 |
default: |
|
261 |
return true; |
|
262 |
} |
|
263 |
} |
|
264 |
||
265 |
bool SimpleThresholdPolicy::call_predicate(int i, int b, CompLevel cur_level) { |
|
266 |
switch(cur_level) { |
|
267 |
case CompLevel_none: |
|
268 |
case CompLevel_limited_profile: { |
|
269 |
return call_predicate_helper<CompLevel_none>(i, b, 1.0); |
|
270 |
} |
|
271 |
case CompLevel_full_profile: { |
|
272 |
return call_predicate_helper<CompLevel_full_profile>(i, b, 1.0); |
|
273 |
} |
|
274 |
default: |
|
275 |
return true; |
|
276 |
} |
|
277 |
} |
|
278 |
||
279 |
// Determine is a method is mature. |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
11572
diff
changeset
|
280 |
bool SimpleThresholdPolicy::is_mature(Method* method) { |
6453 | 281 |
if (is_trivial(method)) return true; |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
11572
diff
changeset
|
282 |
MethodData* mdo = method->method_data(); |
6453 | 283 |
if (mdo != NULL) { |
284 |
int i = mdo->invocation_count(); |
|
285 |
int b = mdo->backedge_count(); |
|
286 |
double k = ProfileMaturityPercentage / 100.0; |
|
287 |
return call_predicate_helper<CompLevel_full_profile>(i, b, k) || |
|
288 |
loop_predicate_helper<CompLevel_full_profile>(i, b, k); |
|
289 |
} |
|
290 |
return false; |
|
291 |
} |
|
292 |
||
293 |
// Common transition function. Given a predicate determines if a method should transition to another level. |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
11572
diff
changeset
|
294 |
CompLevel SimpleThresholdPolicy::common(Predicate p, Method* method, CompLevel cur_level) { |
6453 | 295 |
CompLevel next_level = cur_level; |
296 |
int i = method->invocation_count(); |
|
297 |
int b = method->backedge_count(); |
|
298 |
||
10250
0794cd144834
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
10014
diff
changeset
|
299 |
if (is_trivial(method)) { |
0794cd144834
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
10014
diff
changeset
|
300 |
next_level = CompLevel_simple; |
0794cd144834
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
10014
diff
changeset
|
301 |
} else { |
0794cd144834
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
10014
diff
changeset
|
302 |
switch(cur_level) { |
0794cd144834
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
10014
diff
changeset
|
303 |
case CompLevel_none: |
0794cd144834
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
10014
diff
changeset
|
304 |
// If we were at full profile level, would we switch to full opt? |
0794cd144834
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
10014
diff
changeset
|
305 |
if (common(p, method, CompLevel_full_profile) == CompLevel_full_optimization) { |
0794cd144834
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
10014
diff
changeset
|
306 |
next_level = CompLevel_full_optimization; |
0794cd144834
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
10014
diff
changeset
|
307 |
} else if ((this->*p)(i, b, cur_level)) { |
0794cd144834
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
10014
diff
changeset
|
308 |
next_level = CompLevel_full_profile; |
0794cd144834
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
10014
diff
changeset
|
309 |
} |
0794cd144834
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
10014
diff
changeset
|
310 |
break; |
0794cd144834
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
10014
diff
changeset
|
311 |
case CompLevel_limited_profile: |
0794cd144834
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
10014
diff
changeset
|
312 |
case CompLevel_full_profile: |
0794cd144834
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
10014
diff
changeset
|
313 |
{ |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
11572
diff
changeset
|
314 |
MethodData* mdo = method->method_data(); |
10250
0794cd144834
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
10014
diff
changeset
|
315 |
if (mdo != NULL) { |
0794cd144834
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
10014
diff
changeset
|
316 |
if (mdo->would_profile()) { |
0794cd144834
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
10014
diff
changeset
|
317 |
int mdo_i = mdo->invocation_count_delta(); |
0794cd144834
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
10014
diff
changeset
|
318 |
int mdo_b = mdo->backedge_count_delta(); |
0794cd144834
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
10014
diff
changeset
|
319 |
if ((this->*p)(mdo_i, mdo_b, cur_level)) { |
0794cd144834
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
10014
diff
changeset
|
320 |
next_level = CompLevel_full_optimization; |
0794cd144834
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
10014
diff
changeset
|
321 |
} |
0794cd144834
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
10014
diff
changeset
|
322 |
} else { |
8322 | 323 |
next_level = CompLevel_full_optimization; |
324 |
} |
|
6453 | 325 |
} |
326 |
} |
|
10250
0794cd144834
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
10014
diff
changeset
|
327 |
break; |
6453 | 328 |
} |
329 |
} |
|
10250
0794cd144834
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
10014
diff
changeset
|
330 |
return MIN2(next_level, (CompLevel)TieredStopAtLevel); |
6453 | 331 |
} |
332 |
||
333 |
// Determine if a method should be compiled with a normal entry point at a different level. |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
11572
diff
changeset
|
334 |
CompLevel SimpleThresholdPolicy::call_event(Method* method, CompLevel cur_level) { |
10013
714ad59b56cb
7058689: Tiered: Reprofiling doesn't happen in presence of level 4 OSR methods
iveresov
parents:
9625
diff
changeset
|
335 |
CompLevel osr_level = MIN2((CompLevel) method->highest_osr_comp_level(), |
714ad59b56cb
7058689: Tiered: Reprofiling doesn't happen in presence of level 4 OSR methods
iveresov
parents:
9625
diff
changeset
|
336 |
common(&SimpleThresholdPolicy::loop_predicate, method, cur_level)); |
6453 | 337 |
CompLevel next_level = common(&SimpleThresholdPolicy::call_predicate, method, cur_level); |
338 |
||
339 |
// If OSR method level is greater than the regular method level, the levels should be |
|
340 |
// equalized by raising the regular method level in order to avoid OSRs during each |
|
341 |
// invocation of the method. |
|
342 |
if (osr_level == CompLevel_full_optimization && cur_level == CompLevel_full_profile) { |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
11572
diff
changeset
|
343 |
MethodData* mdo = method->method_data(); |
6453 | 344 |
guarantee(mdo != NULL, "MDO should not be NULL"); |
345 |
if (mdo->invocation_count() >= 1) { |
|
346 |
next_level = CompLevel_full_optimization; |
|
347 |
} |
|
348 |
} else { |
|
349 |
next_level = MAX2(osr_level, next_level); |
|
350 |
} |
|
351 |
||
352 |
return next_level; |
|
353 |
} |
|
354 |
||
355 |
// Determine if we should do an OSR compilation of a given method. |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
11572
diff
changeset
|
356 |
CompLevel SimpleThresholdPolicy::loop_event(Method* method, CompLevel cur_level) { |
10013
714ad59b56cb
7058689: Tiered: Reprofiling doesn't happen in presence of level 4 OSR methods
iveresov
parents:
9625
diff
changeset
|
357 |
CompLevel next_level = common(&SimpleThresholdPolicy::loop_predicate, method, cur_level); |
6453 | 358 |
if (cur_level == CompLevel_none) { |
359 |
// If there is a live OSR method that means that we deopted to the interpreter |
|
360 |
// for the transition. |
|
10013
714ad59b56cb
7058689: Tiered: Reprofiling doesn't happen in presence of level 4 OSR methods
iveresov
parents:
9625
diff
changeset
|
361 |
CompLevel osr_level = MIN2((CompLevel)method->highest_osr_comp_level(), next_level); |
6453 | 362 |
if (osr_level > CompLevel_none) { |
363 |
return osr_level; |
|
364 |
} |
|
365 |
} |
|
10013
714ad59b56cb
7058689: Tiered: Reprofiling doesn't happen in presence of level 4 OSR methods
iveresov
parents:
9625
diff
changeset
|
366 |
return next_level; |
6453 | 367 |
} |
368 |
||
369 |
||
370 |
// Handle the invocation event. |
|
371 |
void SimpleThresholdPolicy::method_invocation_event(methodHandle mh, methodHandle imh, |
|
11572
84afef481892
7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents:
11192
diff
changeset
|
372 |
CompLevel level, nmethod* nm, JavaThread* thread) { |
6453 | 373 |
if (is_compilation_enabled() && !CompileBroker::compilation_is_in_queue(mh, InvocationEntryBci)) { |
374 |
CompLevel next_level = call_event(mh(), level); |
|
375 |
if (next_level != level) { |
|
11572
84afef481892
7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents:
11192
diff
changeset
|
376 |
compile(mh, InvocationEntryBci, next_level, thread); |
6453 | 377 |
} |
378 |
} |
|
379 |
} |
|
380 |
||
381 |
// Handle the back branch event. Notice that we can compile the method |
|
382 |
// with a regular entry from here. |
|
383 |
void SimpleThresholdPolicy::method_back_branch_event(methodHandle mh, methodHandle imh, |
|
11572
84afef481892
7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents:
11192
diff
changeset
|
384 |
int bci, CompLevel level, nmethod* nm, JavaThread* thread) { |
6453 | 385 |
// If the method is already compiling, quickly bail out. |
386 |
if (is_compilation_enabled() && !CompileBroker::compilation_is_in_queue(mh, bci)) { |
|
387 |
// Use loop event as an opportinity to also check there's been |
|
388 |
// enough calls. |
|
389 |
CompLevel cur_level = comp_level(mh()); |
|
390 |
CompLevel next_level = call_event(mh(), cur_level); |
|
391 |
CompLevel next_osr_level = loop_event(mh(), level); |
|
392 |
||
393 |
next_level = MAX2(next_level, |
|
394 |
next_osr_level < CompLevel_full_optimization ? next_osr_level : cur_level); |
|
395 |
bool is_compiling = false; |
|
396 |
if (next_level != cur_level) { |
|
11572
84afef481892
7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents:
11192
diff
changeset
|
397 |
compile(mh, InvocationEntryBci, next_level, thread); |
6453 | 398 |
is_compiling = true; |
399 |
} |
|
400 |
||
401 |
// Do the OSR version |
|
402 |
if (!is_compiling && next_osr_level != level) { |
|
11572
84afef481892
7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents:
11192
diff
changeset
|
403 |
compile(mh, bci, next_osr_level, thread); |
6453 | 404 |
} |
405 |
} |
|
406 |
} |