annotate src/share/vm/interpreter/invocationCounter.cpp @ 9126:bc26f978b0ce

HotSpotResolvedObjectType: implement hasFinalizeSubclass() correctly don't use the (wrong) cached value, but ask the runtime on each request. Fixes regression on xml.* benchmarks @ specjvm2008. The problem was: After the constructor of Object was deoptimized due to an assumption violation, it was recompiled again after some time. However, on recompilation, the value of hasFinalizeSubclass for the class was not updated and it was compiled again with a, now wrong, assumption, which then triggers deoptimization again. This was repeated until it hit the recompilation limit (defined by PerMethodRecompilationCutoff), and therefore only executed by the interpreter from now on, causing the performance regression.
author Bernhard Urban <bernhard.urban@jku.at>
date Mon, 15 Apr 2013 19:54:58 +0200
parents e1e681a5558e
children 836a62f43af9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1783
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1783
diff changeset
25 #include "precompiled.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1783
diff changeset
26 #include "interpreter/invocationCounter.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1783
diff changeset
27 #include "runtime/frame.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1783
diff changeset
28 #include "runtime/handles.inline.hpp"
0
a61af66fc99e Initial load
duke
parents:
diff changeset
29
a61af66fc99e Initial load
duke
parents:
diff changeset
30
a61af66fc99e Initial load
duke
parents:
diff changeset
31 // Implementation of InvocationCounter
a61af66fc99e Initial load
duke
parents:
diff changeset
32
a61af66fc99e Initial load
duke
parents:
diff changeset
33 void InvocationCounter::init() {
a61af66fc99e Initial load
duke
parents:
diff changeset
34 _counter = 0; // reset all the bits, including the sticky carry
a61af66fc99e Initial load
duke
parents:
diff changeset
35 reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
36 }
a61af66fc99e Initial load
duke
parents:
diff changeset
37
a61af66fc99e Initial load
duke
parents:
diff changeset
38 void InvocationCounter::reset() {
a61af66fc99e Initial load
duke
parents:
diff changeset
39 // Only reset the state and don't make the method look like it's never
a61af66fc99e Initial load
duke
parents:
diff changeset
40 // been executed
a61af66fc99e Initial load
duke
parents:
diff changeset
41 set_state(wait_for_compile);
a61af66fc99e Initial load
duke
parents:
diff changeset
42 }
a61af66fc99e Initial load
duke
parents:
diff changeset
43
a61af66fc99e Initial load
duke
parents:
diff changeset
44 void InvocationCounter::set_carry() {
1783
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
45 set_carry_flag();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
46 // The carry bit now indicates that this counter had achieved a very
a61af66fc99e Initial load
duke
parents:
diff changeset
47 // large value. Now reduce the value, so that the method can be
a61af66fc99e Initial load
duke
parents:
diff changeset
48 // executed many more times before re-entering the VM.
a61af66fc99e Initial load
duke
parents:
diff changeset
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;
e1e681a5558e fix PriorityQueue, enable PriorityQueue and CacheGraphs
Lukas Stadler <lukas.stadler@jku.at>
parents: 5163
diff changeset
51 if (CompilationPolicyChoice == 4) {
e1e681a5558e fix PriorityQueue, enable PriorityQueue and CacheGraphs
Lukas Stadler <lukas.stadler@jku.at>
parents: 5163
diff changeset
52 new_count = 1;
e1e681a5558e fix PriorityQueue, enable PriorityQueue and CacheGraphs
Lukas Stadler <lukas.stadler@jku.at>
parents: 5163
diff changeset
53 } else {
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));
e1e681a5558e fix PriorityQueue, enable PriorityQueue and CacheGraphs
Lukas Stadler <lukas.stadler@jku.at>
parents: 5163
diff changeset
55 }
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
a61af66fc99e Initial load
duke
parents:
diff changeset
58 if (old_count != new_count) set(state(), new_count);
a61af66fc99e Initial load
duke
parents:
diff changeset
59 }
a61af66fc99e Initial load
duke
parents:
diff changeset
60
a61af66fc99e Initial load
duke
parents:
diff changeset
61 void InvocationCounter::set_state(State state) {
a61af66fc99e Initial load
duke
parents:
diff changeset
62 assert(0 <= state && state < number_of_states, "illegal state");
a61af66fc99e Initial load
duke
parents:
diff changeset
63 int init = _init[state];
a61af66fc99e Initial load
duke
parents:
diff changeset
64 // prevent from going to zero, to distinguish from never-executed methods
a61af66fc99e Initial load
duke
parents:
diff changeset
65 if (init == 0 && count() > 0) init = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
66 int carry = (_counter & carry_mask); // the carry bit is sticky
a61af66fc99e Initial load
duke
parents:
diff changeset
67 _counter = (init << number_of_noncount_bits) | carry | state;
a61af66fc99e Initial load
duke
parents:
diff changeset
68 }
a61af66fc99e Initial load
duke
parents:
diff changeset
69
a61af66fc99e Initial load
duke
parents:
diff changeset
70
a61af66fc99e Initial load
duke
parents:
diff changeset
71 void InvocationCounter::print() {
a61af66fc99e Initial load
duke
parents:
diff changeset
72 tty->print_cr("invocation count: up = %d, limit = %d, carry = %s, state = %s",
a61af66fc99e Initial load
duke
parents:
diff changeset
73 count(), limit(),
a61af66fc99e Initial load
duke
parents:
diff changeset
74 carry() ? "true" : "false",
a61af66fc99e Initial load
duke
parents:
diff changeset
75 state_as_string(state()));
a61af66fc99e Initial load
duke
parents:
diff changeset
76 }
a61af66fc99e Initial load
duke
parents:
diff changeset
77
a61af66fc99e Initial load
duke
parents:
diff changeset
78 void InvocationCounter::print_short() {
a61af66fc99e Initial load
duke
parents:
diff changeset
79 tty->print(" [%d%s;%s]", count(), carry()?"+carry":"", state_as_short_string(state()));
a61af66fc99e Initial load
duke
parents:
diff changeset
80 }
a61af66fc99e Initial load
duke
parents:
diff changeset
81
a61af66fc99e Initial load
duke
parents:
diff changeset
82 // Initialization
a61af66fc99e Initial load
duke
parents:
diff changeset
83
a61af66fc99e Initial load
duke
parents:
diff changeset
84 int InvocationCounter::_init [InvocationCounter::number_of_states];
a61af66fc99e Initial load
duke
parents:
diff changeset
85 InvocationCounter::Action InvocationCounter::_action[InvocationCounter::number_of_states];
a61af66fc99e Initial load
duke
parents:
diff changeset
86 int InvocationCounter::InterpreterInvocationLimit;
a61af66fc99e Initial load
duke
parents:
diff changeset
87 int InvocationCounter::InterpreterBackwardBranchLimit;
a61af66fc99e Initial load
duke
parents:
diff changeset
88 int InvocationCounter::InterpreterProfileLimit;
a61af66fc99e Initial load
duke
parents:
diff changeset
89
a61af66fc99e Initial load
duke
parents:
diff changeset
90
a61af66fc99e Initial load
duke
parents:
diff changeset
91 const char* InvocationCounter::state_as_string(State state) {
a61af66fc99e Initial load
duke
parents:
diff changeset
92 switch (state) {
a61af66fc99e Initial load
duke
parents:
diff changeset
93 case wait_for_nothing : return "wait_for_nothing";
a61af66fc99e Initial load
duke
parents:
diff changeset
94 case wait_for_compile : return "wait_for_compile";
a61af66fc99e Initial load
duke
parents:
diff changeset
95 }
a61af66fc99e Initial load
duke
parents:
diff changeset
96 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
97 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
98 }
a61af66fc99e Initial load
duke
parents:
diff changeset
99
a61af66fc99e Initial load
duke
parents:
diff changeset
100 const char* InvocationCounter::state_as_short_string(State state) {
a61af66fc99e Initial load
duke
parents:
diff changeset
101 switch (state) {
a61af66fc99e Initial load
duke
parents:
diff changeset
102 case wait_for_nothing : return "not comp.";
a61af66fc99e Initial load
duke
parents:
diff changeset
103 case wait_for_compile : return "compileable";
a61af66fc99e Initial load
duke
parents:
diff changeset
104 }
a61af66fc99e Initial load
duke
parents:
diff changeset
105 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
106 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
107 }
a61af66fc99e Initial load
duke
parents:
diff changeset
108
a61af66fc99e Initial load
duke
parents:
diff changeset
109
a61af66fc99e Initial load
duke
parents:
diff changeset
110 static address do_nothing(methodHandle method, TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
111 // dummy action for inactive invocation counters
a61af66fc99e Initial load
duke
parents:
diff changeset
112 method->invocation_counter()->set_carry();
a61af66fc99e Initial load
duke
parents:
diff changeset
113 method->invocation_counter()->set_state(InvocationCounter::wait_for_nothing);
a61af66fc99e Initial load
duke
parents:
diff changeset
114 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
115 }
a61af66fc99e Initial load
duke
parents:
diff changeset
116
a61af66fc99e Initial load
duke
parents:
diff changeset
117
a61af66fc99e Initial load
duke
parents:
diff changeset
118 static address do_decay(methodHandle method, TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
119 // decay invocation counters so compilation gets delayed
a61af66fc99e Initial load
duke
parents:
diff changeset
120 method->invocation_counter()->decay();
a61af66fc99e Initial load
duke
parents:
diff changeset
121 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
122 }
a61af66fc99e Initial load
duke
parents:
diff changeset
123
a61af66fc99e Initial load
duke
parents:
diff changeset
124
a61af66fc99e Initial load
duke
parents:
diff changeset
125 void InvocationCounter::def(State state, int init, Action action) {
a61af66fc99e Initial load
duke
parents:
diff changeset
126 assert(0 <= state && state < number_of_states, "illegal state");
a61af66fc99e Initial load
duke
parents:
diff changeset
127 assert(0 <= init && init < count_limit, "initial value out of range");
a61af66fc99e Initial load
duke
parents:
diff changeset
128 _init [state] = init;
a61af66fc99e Initial load
duke
parents:
diff changeset
129 _action[state] = action;
a61af66fc99e Initial load
duke
parents:
diff changeset
130 }
a61af66fc99e Initial load
duke
parents:
diff changeset
131
a61af66fc99e Initial load
duke
parents:
diff changeset
132 address dummy_invocation_counter_overflow(methodHandle m, TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
133 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
134 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
135 }
a61af66fc99e Initial load
duke
parents:
diff changeset
136
a61af66fc99e Initial load
duke
parents:
diff changeset
137 void InvocationCounter::reinitialize(bool delay_overflow) {
a61af66fc99e Initial load
duke
parents:
diff changeset
138 // define states
a61af66fc99e Initial load
duke
parents:
diff changeset
139 guarantee((int)number_of_states <= (int)state_limit, "adjust number_of_state_bits");
a61af66fc99e Initial load
duke
parents:
diff changeset
140 def(wait_for_nothing, 0, do_nothing);
a61af66fc99e Initial load
duke
parents:
diff changeset
141 if (delay_overflow) {
a61af66fc99e Initial load
duke
parents:
diff changeset
142 def(wait_for_compile, 0, do_decay);
a61af66fc99e Initial load
duke
parents:
diff changeset
143 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
144 def(wait_for_compile, 0, dummy_invocation_counter_overflow);
a61af66fc99e Initial load
duke
parents:
diff changeset
145 }
a61af66fc99e Initial load
duke
parents:
diff changeset
146
a61af66fc99e Initial load
duke
parents:
diff changeset
147 InterpreterInvocationLimit = CompileThreshold << number_of_noncount_bits;
a61af66fc99e Initial load
duke
parents:
diff changeset
148 InterpreterProfileLimit = ((CompileThreshold * InterpreterProfilePercentage) / 100)<< number_of_noncount_bits;
a61af66fc99e Initial load
duke
parents:
diff changeset
149
a61af66fc99e Initial load
duke
parents:
diff changeset
150 // When methodData is collected, the backward branch limit is compared against a
a61af66fc99e Initial load
duke
parents:
diff changeset
151 // methodData counter, rather than an InvocationCounter. In the former case, we
a61af66fc99e Initial load
duke
parents:
diff changeset
152 // don't need the shift by number_of_noncount_bits, but we do need to adjust
a61af66fc99e Initial load
duke
parents:
diff changeset
153 // the factor by which we scale the threshold.
a61af66fc99e Initial load
duke
parents:
diff changeset
154 if (ProfileInterpreter) {
a61af66fc99e Initial load
duke
parents:
diff changeset
155 InterpreterBackwardBranchLimit = (CompileThreshold * (OnStackReplacePercentage - InterpreterProfilePercentage)) / 100;
a61af66fc99e Initial load
duke
parents:
diff changeset
156 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
157 InterpreterBackwardBranchLimit = ((CompileThreshold * OnStackReplacePercentage) / 100) << number_of_noncount_bits;
a61af66fc99e Initial load
duke
parents:
diff changeset
158 }
a61af66fc99e Initial load
duke
parents:
diff changeset
159
a61af66fc99e Initial load
duke
parents:
diff changeset
160 assert(0 <= InterpreterBackwardBranchLimit,
a61af66fc99e Initial load
duke
parents:
diff changeset
161 "OSR threshold should be non-negative");
a61af66fc99e Initial load
duke
parents:
diff changeset
162 assert(0 <= InterpreterProfileLimit &&
a61af66fc99e Initial load
duke
parents:
diff changeset
163 InterpreterProfileLimit <= InterpreterInvocationLimit,
a61af66fc99e Initial load
duke
parents:
diff changeset
164 "profile threshold should be less than the compilation threshold "
a61af66fc99e Initial load
duke
parents:
diff changeset
165 "and non-negative");
a61af66fc99e Initial load
duke
parents:
diff changeset
166 }
a61af66fc99e Initial load
duke
parents:
diff changeset
167
a61af66fc99e Initial load
duke
parents:
diff changeset
168 void invocationCounter_init() {
a61af66fc99e Initial load
duke
parents:
diff changeset
169 InvocationCounter::reinitialize(DelayCompilationDuringStartup);
a61af66fc99e Initial load
duke
parents:
diff changeset
170 }