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
25 #ifndef SHARE_OOPS_METHODCOUNTERS_HPP
26 #define SHARE_OOPS_METHODCOUNTERS_HPP
27
28 #include "oops/metadata.hpp"
29 #include "compiler/compilerDefinitions.hpp"
30 #include "interpreter/invocationCounter.hpp"
31 #include "utilities/align.hpp"
32
33 class MethodCounters : public MetaspaceObj {
34 friend class VMStructs;
35 friend class JVMCIVMStructs;
36 private:
37 InvocationCounter _invocation_counter; // Incremented before each activation of the method - used to trigger frequency-based optimizations
38 InvocationCounter _backedge_counter; // Incremented before each backedge taken - used to trigger frequency-based optimizations
39 jlong _prev_time; // Previous time the rate was acquired
40 float _rate; // Events (invocation and backedge counter increments) per millisecond
41 int _invoke_mask; // per-method Tier0InvokeNotifyFreqLog
42 int _backedge_mask; // per-method Tier0BackedgeNotifyFreqLog
43 int _prev_event_count; // Total number of events saved at previous callback
44 #if COMPILER2_OR_JVMCI
45 u2 _interpreter_throwout_count; // Count of times method was exited via exception while interpreting
46 #endif
47 #if INCLUDE_JVMTI
48 u2 _number_of_breakpoints; // fullspeed debugging support
49 #endif
50 u1 _highest_comp_level; // Highest compile level this method has ever seen.
51 u1 _highest_osr_comp_level; // Same for OSR level
52
53 MethodCounters(const methodHandle& mh);
54 public:
55 static MethodCounters* allocate_no_exception(const methodHandle& mh);
56 static MethodCounters* allocate_with_exception(const methodHandle& mh, TRAPS);
57
58 DEBUG_ONLY(bool on_stack() { return false; })
59 void deallocate_contents(ClassLoaderData* loader_data) {}
60
61 void metaspace_pointers_do(MetaspaceClosure* it) { return; }
62
63 static int size() {
64 return align_up((int)sizeof(MethodCounters), wordSize) / wordSize;
65 }
66
67 MetaspaceObj::Type type() const { return MethodCountersType; }
68 void clear_counters();
69
70 #if COMPILER2_OR_JVMCI
71 void interpreter_throwout_increment() {
72 if (_interpreter_throwout_count < 65534) {
73 _interpreter_throwout_count++;
74 }
75 }
76 u2 interpreter_throwout_count() const {
77 return _interpreter_throwout_count;
78 }
79 void set_interpreter_throwout_count(u2 count) {
80 _interpreter_throwout_count = count;
81 }
82 #else // COMPILER2_OR_JVMCI
83 u2 interpreter_throwout_count() const {
84 return 0;
85 }
86 void set_interpreter_throwout_count(u2 count) {
87 assert(count == 0, "count must be 0");
89 #endif // COMPILER2_OR_JVMCI
90
91 #if INCLUDE_JVMTI
92 u2 number_of_breakpoints() const { return _number_of_breakpoints; }
93 void incr_number_of_breakpoints() { ++_number_of_breakpoints; }
94 void decr_number_of_breakpoints() { --_number_of_breakpoints; }
95 void clear_number_of_breakpoints() { _number_of_breakpoints = 0; }
96 #endif
97
98 int prev_event_count() const { return _prev_event_count; }
99 void set_prev_event_count(int count) { _prev_event_count = count; }
100 jlong prev_time() const { return _prev_time; }
101 void set_prev_time(jlong time) { _prev_time = time; }
102 float rate() const { return _rate; }
103 void set_rate(float rate) { _rate = rate; }
104
105 int highest_comp_level() const { return _highest_comp_level; }
106 void set_highest_comp_level(int level) { _highest_comp_level = (u1)level; }
107 int highest_osr_comp_level() const { return _highest_osr_comp_level; }
108 void set_highest_osr_comp_level(int level) { _highest_osr_comp_level = (u1)level; }
109
110 // invocation counter
111 InvocationCounter* invocation_counter() { return &_invocation_counter; }
112 InvocationCounter* backedge_counter() { return &_backedge_counter; }
113
114 static ByteSize invocation_counter_offset() {
115 return byte_offset_of(MethodCounters, _invocation_counter);
116 }
117
118 static ByteSize backedge_counter_offset() {
119 return byte_offset_of(MethodCounters, _backedge_counter);
120 }
121
122 static ByteSize invoke_mask_offset() {
123 return byte_offset_of(MethodCounters, _invoke_mask);
124 }
125
126 static ByteSize backedge_mask_offset() {
127 return byte_offset_of(MethodCounters, _backedge_mask);
128 }
129
130 const char* internal_name() const { return "{method counters}"; }
131 void print_value_on(outputStream* st) const;
132 };
133 #endif // SHARE_OOPS_METHODCOUNTERS_HPP
|
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
25 #ifndef SHARE_OOPS_METHODCOUNTERS_HPP
26 #define SHARE_OOPS_METHODCOUNTERS_HPP
27
28 #include "oops/metadata.hpp"
29 #include "compiler/compilerDefinitions.hpp"
30 #include "interpreter/invocationCounter.hpp"
31 #include "utilities/align.hpp"
32
33 class MethodTrainingData;
34
35 class MethodCounters : public Metadata {
36 friend class VMStructs;
37 friend class JVMCIVMStructs;
38
39 // Used by CDS. These classes need to access the private default constructor.
40 template <class T> friend class CppVtableTesterA;
41 template <class T> friend class CppVtableTesterB;
42 template <class T> friend class CppVtableCloner;
43
44 private:
45 InvocationCounter _invocation_counter; // Incremented before each activation of the method - used to trigger frequency-based optimizations
46 InvocationCounter _backedge_counter; // Incremented before each backedge taken - used to trigger frequency-based optimizations
47
48 // Back pointer to the Method*
49 Method* _method;
50
51 MethodTrainingData* _method_training_data;
52 jlong _prev_time; // Previous time the rate was acquired
53 float _rate; // Events (invocation and backedge counter increments) per millisecond
54 int _invoke_mask; // per-method Tier0InvokeNotifyFreqLog
55 int _backedge_mask; // per-method Tier0BackedgeNotifyFreqLog
56 int _prev_event_count; // Total number of events saved at previous callback
57 #if COMPILER2_OR_JVMCI
58 u2 _interpreter_throwout_count; // Count of times method was exited via exception while interpreting
59 #endif
60 #if INCLUDE_JVMTI
61 u2 _number_of_breakpoints; // fullspeed debugging support
62 #endif
63 u1 _highest_comp_level; // Highest compile level this method has ever seen.
64 u1 _highest_osr_comp_level; // Same for OSR level
65 bool _training_data_lookup_failed;
66
67 MethodCounters(const methodHandle& mh);
68 MethodCounters();
69
70 public:
71 virtual bool is_methodCounters() const { return true; }
72 Method* method() const { return _method; }
73 static MethodCounters* allocate_no_exception(const methodHandle& mh);
74 static MethodCounters* allocate_with_exception(const methodHandle& mh, TRAPS);
75
76 void deallocate_contents(ClassLoaderData* loader_data) {}
77
78 static int method_counters_size() {
79 return align_up((int)sizeof(MethodCounters), wordSize) / wordSize;
80 }
81 virtual int size() const {
82 return method_counters_size();
83 }
84
85 MetaspaceObj::Type type() const { return MethodCountersType; }
86 void metaspace_pointers_do(MetaspaceClosure* iter);
87
88 void clear_counters();
89
90 #if COMPILER2_OR_JVMCI
91 void interpreter_throwout_increment() {
92 if (_interpreter_throwout_count < 65534) {
93 _interpreter_throwout_count++;
94 }
95 }
96 u2 interpreter_throwout_count() const {
97 return _interpreter_throwout_count;
98 }
99 void set_interpreter_throwout_count(u2 count) {
100 _interpreter_throwout_count = count;
101 }
102 #else // COMPILER2_OR_JVMCI
103 u2 interpreter_throwout_count() const {
104 return 0;
105 }
106 void set_interpreter_throwout_count(u2 count) {
107 assert(count == 0, "count must be 0");
109 #endif // COMPILER2_OR_JVMCI
110
111 #if INCLUDE_JVMTI
112 u2 number_of_breakpoints() const { return _number_of_breakpoints; }
113 void incr_number_of_breakpoints() { ++_number_of_breakpoints; }
114 void decr_number_of_breakpoints() { --_number_of_breakpoints; }
115 void clear_number_of_breakpoints() { _number_of_breakpoints = 0; }
116 #endif
117
118 int prev_event_count() const { return _prev_event_count; }
119 void set_prev_event_count(int count) { _prev_event_count = count; }
120 jlong prev_time() const { return _prev_time; }
121 void set_prev_time(jlong time) { _prev_time = time; }
122 float rate() const { return _rate; }
123 void set_rate(float rate) { _rate = rate; }
124
125 int highest_comp_level() const { return _highest_comp_level; }
126 void set_highest_comp_level(int level) { _highest_comp_level = (u1)level; }
127 int highest_osr_comp_level() const { return _highest_osr_comp_level; }
128 void set_highest_osr_comp_level(int level) { _highest_osr_comp_level = (u1)level; }
129 bool has_training_data_lookup_failed() const { return _training_data_lookup_failed; }
130 void set_training_data_lookup_failed() { _training_data_lookup_failed = true; }
131
132
133 // invocation counter
134 InvocationCounter* invocation_counter() { return &_invocation_counter; }
135 InvocationCounter* backedge_counter() { return &_backedge_counter; }
136
137 static ByteSize invocation_counter_offset() {
138 return byte_offset_of(MethodCounters, _invocation_counter);
139 }
140
141 static ByteSize backedge_counter_offset() {
142 return byte_offset_of(MethodCounters, _backedge_counter);
143 }
144
145 static ByteSize invoke_mask_offset() {
146 return byte_offset_of(MethodCounters, _invoke_mask);
147 }
148
149 static ByteSize backedge_mask_offset() {
150 return byte_offset_of(MethodCounters, _backedge_mask);
151 }
152
153 virtual const char* internal_name() const { return "{method counters}"; }
154
155 MethodTrainingData* method_training_data() const { return _method_training_data; }
156 bool init_method_training_data(MethodTrainingData* tdata) {
157 return (_method_training_data == tdata ||
158 Atomic::replace_if_null(&_method_training_data, tdata));
159 }
160
161 #if INCLUDE_CDS
162 void remove_unshareable_info();
163 void restore_unshareable_info(TRAPS);
164 #endif
165
166 // Printing
167 void print_on (outputStream* st) const;
168 void print_value_on(outputStream* st) const;
169 void print_data_on(outputStream* st) const;
170 };
171 #endif // SHARE_OOPS_METHODCOUNTERS_HPP
|