Mercurial > hg > truffle
annotate src/share/vm/interpreter/invocationCounter.hpp @ 7816:4e1278443941
Remove Kind.Jsr.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Mon, 18 Feb 2013 20:55:18 -0800 |
parents | bd7a7ce2e264 |
children | a9311ec68721 abe03600372a |
rev | line source |
---|---|
0 | 1 /* |
6972
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
1972
diff
changeset
|
2 * Copyright (c) 1997, 2012, 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:
0
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
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:
0
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #ifndef SHARE_VM_INTERPRETER_INVOCATIONCOUNTER_HPP |
26 #define SHARE_VM_INTERPRETER_INVOCATIONCOUNTER_HPP | |
27 | |
28 #include "memory/allocation.hpp" | |
29 #include "runtime/handles.hpp" | |
30 #include "utilities/exceptions.hpp" | |
31 | |
0 | 32 // InvocationCounters are used to trigger actions when a limit (threshold) is reached. |
33 // For different states, different limits and actions can be defined in the initialization | |
34 // routine of InvocationCounters. | |
35 // | |
36 // Implementation notes: For space reasons, state & counter are both encoded in one word, | |
37 // The state is encoded using some of the least significant bits, the counter is using the | |
38 // more significant bits. The counter is incremented before a method is activated and an | |
39 // action is triggered when when count() > limit(). | |
40 | |
41 class InvocationCounter VALUE_OBJ_CLASS_SPEC { | |
42 friend class VMStructs; | |
6972
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
1972
diff
changeset
|
43 friend class ciReplay; |
0 | 44 private: // bit no: |31 3| 2 | 1 0 | |
45 unsigned int _counter; // format: [count|carry|state] | |
46 | |
47 enum PrivateConstants { | |
48 number_of_state_bits = 2, | |
49 number_of_carry_bits = 1, | |
50 number_of_noncount_bits = number_of_state_bits + number_of_carry_bits, | |
51 number_of_count_bits = BitsPerInt - number_of_noncount_bits, | |
52 state_limit = nth_bit(number_of_state_bits), | |
53 count_grain = nth_bit(number_of_state_bits + number_of_carry_bits), | |
54 carry_mask = right_n_bits(number_of_carry_bits) << number_of_state_bits, | |
55 state_mask = right_n_bits(number_of_state_bits), | |
56 status_mask = right_n_bits(number_of_state_bits + number_of_carry_bits), | |
57 count_mask = ((int)(-1) ^ status_mask) | |
58 }; | |
59 | |
60 public: | |
61 static int InterpreterInvocationLimit; // CompileThreshold scaled for interpreter use | |
62 static int InterpreterBackwardBranchLimit; // A separate threshold for on stack replacement | |
63 static int InterpreterProfileLimit; // Profiling threshold scaled for interpreter use | |
64 | |
65 typedef address (*Action)(methodHandle method, TRAPS); | |
66 | |
67 enum PublicConstants { | |
68 count_increment = count_grain, // use this value to increment the 32bit _counter word | |
1783 | 69 count_mask_value = count_mask, // use this value to mask the backedge counter |
70 count_shift = number_of_noncount_bits, | |
71 count_limit = nth_bit(number_of_count_bits - 1) | |
0 | 72 }; |
73 | |
74 enum State { | |
75 wait_for_nothing, // do nothing when count() > limit() | |
76 wait_for_compile, // introduce nmethod when count() > limit() | |
77 number_of_states // must be <= state_limit | |
78 }; | |
79 | |
80 // Manipulation | |
81 void reset(); // sets state to wait state | |
82 void init(); // sets state into original state | |
83 void set_state(State state); // sets state and initializes counter correspondingly | |
84 inline void set(State state, int count); // sets state and counter | |
85 inline void decay(); // decay counter (divide by two) | |
86 void set_carry(); // set the sticky carry bit | |
1783 | 87 void set_carry_flag() { _counter |= carry_mask; } |
0 | 88 |
6972
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
1972
diff
changeset
|
89 int raw_counter() { return _counter; } |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
1972
diff
changeset
|
90 |
0 | 91 // Accessors |
92 State state() const { return (State)(_counter & state_mask); } | |
93 bool carry() const { return (_counter & carry_mask) != 0; } | |
94 int limit() const { return CompileThreshold; } | |
95 Action action() const { return _action[state()]; } | |
96 int count() const { return _counter >> number_of_noncount_bits; } | |
97 | |
98 int get_InvocationLimit() const { return InterpreterInvocationLimit >> number_of_noncount_bits; } | |
99 int get_BackwardBranchLimit() const { return InterpreterBackwardBranchLimit >> number_of_noncount_bits; } | |
100 int get_ProfileLimit() const { return InterpreterProfileLimit >> number_of_noncount_bits; } | |
101 | |
102 // Test counter using scaled limits like the asm interpreter would do rather than doing | |
103 // the shifts to normalize the counter. | |
104 | |
105 bool reached_InvocationLimit() const { return _counter >= (unsigned int) InterpreterInvocationLimit; } | |
106 bool reached_BackwardBranchLimit() const { return _counter >= (unsigned int) InterpreterBackwardBranchLimit; } | |
107 | |
108 // Do this just like asm interpreter does for max speed | |
109 bool reached_ProfileLimit(InvocationCounter *back_edge_count) const { | |
110 return (_counter && count_mask) + back_edge_count->_counter >= (unsigned int) InterpreterProfileLimit; | |
111 } | |
112 | |
113 void increment() { _counter += count_increment; } | |
114 | |
115 | |
116 // Printing | |
117 void print(); | |
118 void print_short(); | |
119 | |
120 // Miscellaneous | |
121 static ByteSize counter_offset() { return byte_offset_of(InvocationCounter, _counter); } | |
122 static void reinitialize(bool delay_overflow); | |
123 | |
124 private: | |
125 static int _init [number_of_states]; // the counter limits | |
126 static Action _action[number_of_states]; // the actions | |
127 | |
128 static void def(State state, int init, Action action); | |
129 static const char* state_as_string(State state); | |
130 static const char* state_as_short_string(State state); | |
131 }; | |
132 | |
133 inline void InvocationCounter::set(State state, int count) { | |
134 assert(0 <= state && state < number_of_states, "illegal state"); | |
135 int carry = (_counter & carry_mask); // the carry bit is sticky | |
136 _counter = (count << number_of_noncount_bits) | carry | state; | |
137 } | |
138 | |
139 inline void InvocationCounter::decay() { | |
140 int c = count(); | |
141 int new_count = c >> 1; | |
142 // prevent from going to zero, to distinguish from never-executed methods | |
143 if (c > 0 && new_count == 0) new_count = 1; | |
144 set(state(), new_count); | |
145 } | |
1783 | 146 |
1972 | 147 |
148 #endif // SHARE_VM_INTERPRETER_INVOCATIONCOUNTER_HPP |