Mercurial > hg > truffle
annotate src/share/vm/interpreter/invocationCounter.cpp @ 11646:8f8f6afeb97a
New caching mechanism in TruffleCache for better compilation performance. Clean up of partial evaluator phases.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Sun, 15 Sep 2013 16:27:07 +0200 |
parents | 88672775a26c |
children | 359f7e70ae7f |
rev | line source |
---|---|
0 | 1 /* |
10105
aeaca88565e6
8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents:
1972
diff
changeset
|
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
844
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
844
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
844
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "interpreter/invocationCounter.hpp" | |
27 #include "runtime/frame.hpp" | |
28 #include "runtime/handles.inline.hpp" | |
0 | 29 |
30 | |
31 // Implementation of InvocationCounter | |
32 | |
33 void InvocationCounter::init() { | |
34 _counter = 0; // reset all the bits, including the sticky carry | |
35 reset(); | |
36 } | |
37 | |
38 void InvocationCounter::reset() { | |
39 // Only reset the state and don't make the method look like it's never | |
40 // been executed | |
41 set_state(wait_for_compile); | |
42 } | |
43 | |
44 void InvocationCounter::set_carry() { | |
1783 | 45 set_carry_flag(); |
0 | 46 // The carry bit now indicates that this counter had achieved a very |
47 // large value. Now reduce the value, so that the method can be | |
48 // executed many more times before re-entering the VM. | |
49 int old_count = count(); | |
5183
e1e681a5558e
fix PriorityQueue, enable PriorityQueue and CacheGraphs
Lukas Stadler <lukas.stadler@jku.at>
parents:
5163
diff
changeset
|
50 int new_count; |
10640
88672775a26c
Compilation policy fixes and changed default compilation policy.
Christian Haeubl <haeubl@ssw.jku.at>
parents:
10408
diff
changeset
|
51 #ifdef GRAALVM |
5183
e1e681a5558e
fix PriorityQueue, enable PriorityQueue and CacheGraphs
Lukas Stadler <lukas.stadler@jku.at>
parents:
5163
diff
changeset
|
52 new_count = 1; |
10640
88672775a26c
Compilation policy fixes and changed default compilation policy.
Christian Haeubl <haeubl@ssw.jku.at>
parents:
10408
diff
changeset
|
53 #else |
5183
e1e681a5558e
fix PriorityQueue, enable PriorityQueue and CacheGraphs
Lukas Stadler <lukas.stadler@jku.at>
parents:
5163
diff
changeset
|
54 new_count = MIN2(old_count, (int) (CompileThreshold / 2)); |
10640
88672775a26c
Compilation policy fixes and changed default compilation policy.
Christian Haeubl <haeubl@ssw.jku.at>
parents:
10408
diff
changeset
|
55 #endif |
654
c664a0794f85
6805748: Assertion "don't reset to 0 -- could be mistaken for never-executed" in CompilationPolicy
coleenp
parents:
0
diff
changeset
|
56 // prevent from going to zero, to distinguish from never-executed methods |
c664a0794f85
6805748: Assertion "don't reset to 0 -- could be mistaken for never-executed" in CompilationPolicy
coleenp
parents:
0
diff
changeset
|
57 if (new_count == 0) new_count = 1; |
0 | 58 if (old_count != new_count) set(state(), new_count); |
59 } | |
60 | |
61 void InvocationCounter::set_state(State state) { | |
62 assert(0 <= state && state < number_of_states, "illegal state"); | |
63 int init = _init[state]; | |
64 // prevent from going to zero, to distinguish from never-executed methods | |
65 if (init == 0 && count() > 0) init = 1; | |
66 int carry = (_counter & carry_mask); // the carry bit is sticky | |
67 _counter = (init << number_of_noncount_bits) | carry | state; | |
68 } | |
69 | |
70 | |
71 void InvocationCounter::print() { | |
72 tty->print_cr("invocation count: up = %d, limit = %d, carry = %s, state = %s", | |
73 count(), limit(), | |
74 carry() ? "true" : "false", | |
75 state_as_string(state())); | |
76 } | |
77 | |
78 void InvocationCounter::print_short() { | |
79 tty->print(" [%d%s;%s]", count(), carry()?"+carry":"", state_as_short_string(state())); | |
80 } | |
81 | |
82 // Initialization | |
83 | |
84 int InvocationCounter::_init [InvocationCounter::number_of_states]; | |
85 InvocationCounter::Action InvocationCounter::_action[InvocationCounter::number_of_states]; | |
86 int InvocationCounter::InterpreterInvocationLimit; | |
87 int InvocationCounter::InterpreterBackwardBranchLimit; | |
88 int InvocationCounter::InterpreterProfileLimit; | |
89 | |
90 | |
91 const char* InvocationCounter::state_as_string(State state) { | |
92 switch (state) { | |
93 case wait_for_nothing : return "wait_for_nothing"; | |
94 case wait_for_compile : return "wait_for_compile"; | |
95 } | |
96 ShouldNotReachHere(); | |
97 return NULL; | |
98 } | |
99 | |
100 const char* InvocationCounter::state_as_short_string(State state) { | |
101 switch (state) { | |
102 case wait_for_nothing : return "not comp."; | |
103 case wait_for_compile : return "compileable"; | |
104 } | |
105 ShouldNotReachHere(); | |
106 return NULL; | |
107 } | |
108 | |
109 | |
110 static address do_nothing(methodHandle method, TRAPS) { | |
111 // dummy action for inactive invocation counters | |
10105
aeaca88565e6
8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents:
1972
diff
changeset
|
112 MethodCounters* mcs = method->method_counters(); |
aeaca88565e6
8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents:
1972
diff
changeset
|
113 assert(mcs != NULL, ""); |
aeaca88565e6
8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents:
1972
diff
changeset
|
114 mcs->invocation_counter()->set_carry(); |
aeaca88565e6
8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents:
1972
diff
changeset
|
115 mcs->invocation_counter()->set_state(InvocationCounter::wait_for_nothing); |
0 | 116 return NULL; |
117 } | |
118 | |
119 | |
120 static address do_decay(methodHandle method, TRAPS) { | |
121 // decay invocation counters so compilation gets delayed | |
10105
aeaca88565e6
8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents:
1972
diff
changeset
|
122 MethodCounters* mcs = method->method_counters(); |
aeaca88565e6
8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents:
1972
diff
changeset
|
123 assert(mcs != NULL, ""); |
aeaca88565e6
8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents:
1972
diff
changeset
|
124 mcs->invocation_counter()->decay(); |
0 | 125 return NULL; |
126 } | |
127 | |
128 | |
129 void InvocationCounter::def(State state, int init, Action action) { | |
130 assert(0 <= state && state < number_of_states, "illegal state"); | |
131 assert(0 <= init && init < count_limit, "initial value out of range"); | |
132 _init [state] = init; | |
133 _action[state] = action; | |
134 } | |
135 | |
136 address dummy_invocation_counter_overflow(methodHandle m, TRAPS) { | |
137 ShouldNotReachHere(); | |
138 return NULL; | |
139 } | |
140 | |
141 void InvocationCounter::reinitialize(bool delay_overflow) { | |
142 // define states | |
143 guarantee((int)number_of_states <= (int)state_limit, "adjust number_of_state_bits"); | |
144 def(wait_for_nothing, 0, do_nothing); | |
145 if (delay_overflow) { | |
146 def(wait_for_compile, 0, do_decay); | |
147 } else { | |
148 def(wait_for_compile, 0, dummy_invocation_counter_overflow); | |
149 } | |
150 | |
151 InterpreterInvocationLimit = CompileThreshold << number_of_noncount_bits; | |
152 InterpreterProfileLimit = ((CompileThreshold * InterpreterProfilePercentage) / 100)<< number_of_noncount_bits; | |
153 | |
154 // When methodData is collected, the backward branch limit is compared against a | |
155 // methodData counter, rather than an InvocationCounter. In the former case, we | |
156 // don't need the shift by number_of_noncount_bits, but we do need to adjust | |
157 // the factor by which we scale the threshold. | |
158 if (ProfileInterpreter) { | |
159 InterpreterBackwardBranchLimit = (CompileThreshold * (OnStackReplacePercentage - InterpreterProfilePercentage)) / 100; | |
160 } else { | |
161 InterpreterBackwardBranchLimit = ((CompileThreshold * OnStackReplacePercentage) / 100) << number_of_noncount_bits; | |
162 } | |
163 | |
164 assert(0 <= InterpreterBackwardBranchLimit, | |
165 "OSR threshold should be non-negative"); | |
166 assert(0 <= InterpreterProfileLimit && | |
167 InterpreterProfileLimit <= InterpreterInvocationLimit, | |
168 "profile threshold should be less than the compilation threshold " | |
169 "and non-negative"); | |
170 } | |
171 | |
172 void invocationCounter_init() { | |
173 InvocationCounter::reinitialize(DelayCompilationDuringStartup); | |
174 } |