author | shade |
Wed, 30 Jan 2019 18:34:31 +0100 | |
changeset 53571 | 3997614d4834 |
parent 53546 | 63eb7e38ce84 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
53193
184c51e48260
8216262: Remove develop flag DelayCompilationDuringStartup
redestad
parents:
53002
diff
changeset
|
2 |
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
3261
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
3261
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
3261
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
26 |
#include "interpreter/invocationCounter.hpp" |
|
27 |
#include "runtime/frame.hpp" |
|
28 |
#include "runtime/handles.inline.hpp" |
|
1 | 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() { |
|
6453 | 45 |
set_carry_flag(); |
1 | 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(); |
|
50 |
int new_count = MIN2(old_count, (int) (CompileThreshold / 2)); |
|
2266
fe08ea2948cf
6805748: Assertion "don't reset to 0 -- could be mistaken for never-executed" in CompilationPolicy
coleenp
parents:
1
diff
changeset
|
51 |
// prevent from going to zero, to distinguish from never-executed methods |
fe08ea2948cf
6805748: Assertion "don't reset to 0 -- could be mistaken for never-executed" in CompilationPolicy
coleenp
parents:
1
diff
changeset
|
52 |
if (new_count == 0) new_count = 1; |
1 | 53 |
if (old_count != new_count) set(state(), new_count); |
54 |
} |
|
55 |
||
56 |
void InvocationCounter::set_state(State state) { |
|
57 |
assert(0 <= state && state < number_of_states, "illegal state"); |
|
58 |
int init = _init[state]; |
|
59 |
// prevent from going to zero, to distinguish from never-executed methods |
|
60 |
if (init == 0 && count() > 0) init = 1; |
|
61 |
int carry = (_counter & carry_mask); // the carry bit is sticky |
|
62 |
_counter = (init << number_of_noncount_bits) | carry | state; |
|
63 |
} |
|
64 |
||
65 |
||
66 |
void InvocationCounter::print() { |
|
67 |
tty->print_cr("invocation count: up = %d, limit = %d, carry = %s, state = %s", |
|
68 |
count(), limit(), |
|
69 |
carry() ? "true" : "false", |
|
70 |
state_as_string(state())); |
|
71 |
} |
|
72 |
||
73 |
void InvocationCounter::print_short() { |
|
74 |
tty->print(" [%d%s;%s]", count(), carry()?"+carry":"", state_as_short_string(state())); |
|
75 |
} |
|
76 |
||
77 |
// Initialization |
|
78 |
||
79 |
int InvocationCounter::_init [InvocationCounter::number_of_states]; |
|
80 |
InvocationCounter::Action InvocationCounter::_action[InvocationCounter::number_of_states]; |
|
81 |
||
53571
3997614d4834
8218031: Zero broken after JDK-8217922 (Compiler dead code removal)
shade
parents:
53546
diff
changeset
|
82 |
#ifdef CC_INTERP |
3997614d4834
8218031: Zero broken after JDK-8217922 (Compiler dead code removal)
shade
parents:
53546
diff
changeset
|
83 |
int InvocationCounter::InterpreterInvocationLimit; |
3997614d4834
8218031: Zero broken after JDK-8217922 (Compiler dead code removal)
shade
parents:
53546
diff
changeset
|
84 |
int InvocationCounter::InterpreterBackwardBranchLimit; |
3997614d4834
8218031: Zero broken after JDK-8217922 (Compiler dead code removal)
shade
parents:
53546
diff
changeset
|
85 |
#endif |
1 | 86 |
|
87 |
const char* InvocationCounter::state_as_string(State state) { |
|
88 |
switch (state) { |
|
89 |
case wait_for_nothing : return "wait_for_nothing"; |
|
90 |
case wait_for_compile : return "wait_for_compile"; |
|
46630
75aa3e39d02c
8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents:
17000
diff
changeset
|
91 |
default: |
75aa3e39d02c
8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents:
17000
diff
changeset
|
92 |
ShouldNotReachHere(); |
75aa3e39d02c
8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents:
17000
diff
changeset
|
93 |
return NULL; |
1 | 94 |
} |
95 |
} |
|
96 |
||
97 |
const char* InvocationCounter::state_as_short_string(State state) { |
|
98 |
switch (state) { |
|
99 |
case wait_for_nothing : return "not comp."; |
|
100 |
case wait_for_compile : return "compileable"; |
|
46630
75aa3e39d02c
8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents:
17000
diff
changeset
|
101 |
default: |
75aa3e39d02c
8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents:
17000
diff
changeset
|
102 |
ShouldNotReachHere(); |
75aa3e39d02c
8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents:
17000
diff
changeset
|
103 |
return NULL; |
1 | 104 |
} |
105 |
} |
|
106 |
||
107 |
||
46727
6e4a84748e2c
8183039: Re-examine methodHandle methods uninlined by 8144256
coleenp
parents:
46630
diff
changeset
|
108 |
static address do_nothing(const methodHandle& method, TRAPS) { |
1 | 109 |
// dummy action for inactive invocation counters |
17000
11bf92e571a2
8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents:
7397
diff
changeset
|
110 |
MethodCounters* mcs = method->method_counters(); |
11bf92e571a2
8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents:
7397
diff
changeset
|
111 |
assert(mcs != NULL, ""); |
11bf92e571a2
8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents:
7397
diff
changeset
|
112 |
mcs->invocation_counter()->set_carry(); |
11bf92e571a2
8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents:
7397
diff
changeset
|
113 |
mcs->invocation_counter()->set_state(InvocationCounter::wait_for_nothing); |
1 | 114 |
return NULL; |
115 |
} |
|
116 |
||
117 |
||
46727
6e4a84748e2c
8183039: Re-examine methodHandle methods uninlined by 8144256
coleenp
parents:
46630
diff
changeset
|
118 |
static address do_decay(const methodHandle& method, TRAPS) { |
1 | 119 |
// decay invocation counters so compilation gets delayed |
17000
11bf92e571a2
8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents:
7397
diff
changeset
|
120 |
MethodCounters* mcs = method->method_counters(); |
11bf92e571a2
8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents:
7397
diff
changeset
|
121 |
assert(mcs != NULL, ""); |
11bf92e571a2
8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents:
7397
diff
changeset
|
122 |
mcs->invocation_counter()->decay(); |
1 | 123 |
return NULL; |
124 |
} |
|
125 |
||
126 |
||
127 |
void InvocationCounter::def(State state, int init, Action action) { |
|
128 |
assert(0 <= state && state < number_of_states, "illegal state"); |
|
129 |
assert(0 <= init && init < count_limit, "initial value out of range"); |
|
130 |
_init [state] = init; |
|
131 |
_action[state] = action; |
|
132 |
} |
|
133 |
||
53193
184c51e48260
8216262: Remove develop flag DelayCompilationDuringStartup
redestad
parents:
53002
diff
changeset
|
134 |
void InvocationCounter::reinitialize() { |
1 | 135 |
// define states |
136 |
guarantee((int)number_of_states <= (int)state_limit, "adjust number_of_state_bits"); |
|
137 |
def(wait_for_nothing, 0, do_nothing); |
|
53193
184c51e48260
8216262: Remove develop flag DelayCompilationDuringStartup
redestad
parents:
53002
diff
changeset
|
138 |
def(wait_for_compile, 0, do_decay); |
53571
3997614d4834
8218031: Zero broken after JDK-8217922 (Compiler dead code removal)
shade
parents:
53546
diff
changeset
|
139 |
|
3997614d4834
8218031: Zero broken after JDK-8217922 (Compiler dead code removal)
shade
parents:
53546
diff
changeset
|
140 |
#ifdef CC_INTERP |
3997614d4834
8218031: Zero broken after JDK-8217922 (Compiler dead code removal)
shade
parents:
53546
diff
changeset
|
141 |
InterpreterInvocationLimit = CompileThreshold << number_of_noncount_bits; |
3997614d4834
8218031: Zero broken after JDK-8217922 (Compiler dead code removal)
shade
parents:
53546
diff
changeset
|
142 |
|
3997614d4834
8218031: Zero broken after JDK-8217922 (Compiler dead code removal)
shade
parents:
53546
diff
changeset
|
143 |
// When methodData is collected, the backward branch limit is compared against a |
3997614d4834
8218031: Zero broken after JDK-8217922 (Compiler dead code removal)
shade
parents:
53546
diff
changeset
|
144 |
// methodData counter, rather than an InvocationCounter. In the former case, we |
3997614d4834
8218031: Zero broken after JDK-8217922 (Compiler dead code removal)
shade
parents:
53546
diff
changeset
|
145 |
// don't need the shift by number_of_noncount_bits, but we do need to adjust |
3997614d4834
8218031: Zero broken after JDK-8217922 (Compiler dead code removal)
shade
parents:
53546
diff
changeset
|
146 |
// the factor by which we scale the threshold. |
3997614d4834
8218031: Zero broken after JDK-8217922 (Compiler dead code removal)
shade
parents:
53546
diff
changeset
|
147 |
if (ProfileInterpreter) { |
3997614d4834
8218031: Zero broken after JDK-8217922 (Compiler dead code removal)
shade
parents:
53546
diff
changeset
|
148 |
InterpreterBackwardBranchLimit = (int)((int64_t)CompileThreshold * (OnStackReplacePercentage - InterpreterProfilePercentage) / 100); |
3997614d4834
8218031: Zero broken after JDK-8217922 (Compiler dead code removal)
shade
parents:
53546
diff
changeset
|
149 |
} else { |
3997614d4834
8218031: Zero broken after JDK-8217922 (Compiler dead code removal)
shade
parents:
53546
diff
changeset
|
150 |
InterpreterBackwardBranchLimit = (int)(((int64_t)CompileThreshold * OnStackReplacePercentage / 100) << number_of_noncount_bits); |
3997614d4834
8218031: Zero broken after JDK-8217922 (Compiler dead code removal)
shade
parents:
53546
diff
changeset
|
151 |
} |
3997614d4834
8218031: Zero broken after JDK-8217922 (Compiler dead code removal)
shade
parents:
53546
diff
changeset
|
152 |
|
3997614d4834
8218031: Zero broken after JDK-8217922 (Compiler dead code removal)
shade
parents:
53546
diff
changeset
|
153 |
assert(0 <= InterpreterBackwardBranchLimit, "OSR threshold should be non-negative"); |
3997614d4834
8218031: Zero broken after JDK-8217922 (Compiler dead code removal)
shade
parents:
53546
diff
changeset
|
154 |
#endif |
1 | 155 |
} |
156 |
||
157 |
void invocationCounter_init() { |
|
53193
184c51e48260
8216262: Remove develop flag DelayCompilationDuringStartup
redestad
parents:
53002
diff
changeset
|
158 |
InvocationCounter::reinitialize(); |
1 | 159 |
} |