24 |
24 |
25 #ifndef SHARE_VM_OOPS_METHODCOUNTERS_HPP |
25 #ifndef SHARE_VM_OOPS_METHODCOUNTERS_HPP |
26 #define SHARE_VM_OOPS_METHODCOUNTERS_HPP |
26 #define SHARE_VM_OOPS_METHODCOUNTERS_HPP |
27 |
27 |
28 #include "oops/metadata.hpp" |
28 #include "oops/metadata.hpp" |
|
29 #include "compiler/compilerOracle.hpp" |
29 #include "interpreter/invocationCounter.hpp" |
30 #include "interpreter/invocationCounter.hpp" |
|
31 #include "runtime/arguments.hpp" |
30 |
32 |
31 class MethodCounters: public MetaspaceObj { |
33 class MethodCounters: public MetaspaceObj { |
32 friend class VMStructs; |
34 friend class VMStructs; |
33 private: |
35 private: |
34 int _interpreter_invocation_count; // Count of times invoked (reused as prev_event_count in tiered) |
36 int _interpreter_invocation_count; // Count of times invoked (reused as prev_event_count in tiered) |
43 // 2. (1..HotMethodDetectionLimit) - the method is warm, the counter is used |
45 // 2. (1..HotMethodDetectionLimit) - the method is warm, the counter is used |
44 // to figure out which methods can be flushed. |
46 // to figure out which methods can be flushed. |
45 // 3. (INT_MIN..0] - method is hot and will deopt and get |
47 // 3. (INT_MIN..0] - method is hot and will deopt and get |
46 // recompiled without the counters |
48 // recompiled without the counters |
47 int _nmethod_age; |
49 int _nmethod_age; |
48 |
50 int _interpreter_invocation_limit; // per-method InterpreterInvocationLimit |
|
51 int _interpreter_backward_branch_limit; // per-method InterpreterBackwardBranchLimit |
|
52 int _interpreter_profile_limit; // per-method InterpreterProfileLimit |
|
53 int _invoke_mask; // per-method Tier0InvokeNotifyFreqLog |
|
54 int _backedge_mask; // per-method Tier0BackedgeNotifyFreqLog |
49 #ifdef TIERED |
55 #ifdef TIERED |
50 float _rate; // Events (invocation and backedge counter increments) per millisecond |
56 float _rate; // Events (invocation and backedge counter increments) per millisecond |
51 jlong _prev_time; // Previous time the rate was acquired |
57 jlong _prev_time; // Previous time the rate was acquired |
52 u1 _highest_comp_level; // Highest compile level this method has ever seen. |
58 u1 _highest_comp_level; // Highest compile level this method has ever seen. |
53 u1 _highest_osr_comp_level; // Same for OSR level |
59 u1 _highest_osr_comp_level; // Same for OSR level |
54 #endif |
60 #endif |
55 |
61 |
56 MethodCounters() : _interpreter_invocation_count(0), |
62 MethodCounters(methodHandle mh) : _interpreter_invocation_count(0), |
57 _interpreter_throwout_count(0), |
63 _interpreter_throwout_count(0), |
58 _number_of_breakpoints(0), |
64 _number_of_breakpoints(0), |
59 _nmethod_age(INT_MAX) |
65 _nmethod_age(INT_MAX) |
60 #ifdef TIERED |
66 #ifdef TIERED |
61 , _rate(0), |
67 , _rate(0), |
62 _prev_time(0), |
68 _prev_time(0), |
63 _highest_comp_level(0), |
69 _highest_comp_level(0), |
64 _highest_osr_comp_level(0) |
70 _highest_osr_comp_level(0) |
65 #endif |
71 #endif |
66 { |
72 { |
67 invocation_counter()->init(); |
73 invocation_counter()->init(); |
68 backedge_counter()->init(); |
74 backedge_counter()->init(); |
69 |
75 |
70 if (StressCodeAging) { |
76 if (StressCodeAging) { |
71 set_nmethod_age(HotMethodDetectionLimit); |
77 set_nmethod_age(HotMethodDetectionLimit); |
72 } |
78 } |
|
79 |
|
80 // Set per-method thresholds. |
|
81 double scale = 1.0; |
|
82 CompilerOracle::has_option_value(mh, "CompileThresholdScaling", scale); |
|
83 |
|
84 int compile_threshold = Arguments::scaled_compile_threshold(CompileThreshold, scale); |
|
85 _interpreter_invocation_limit = compile_threshold << InvocationCounter::count_shift; |
|
86 if (ProfileInterpreter) { |
|
87 // If interpreter profiling is enabled, the backward branch limit |
|
88 // is compared against the method data counter rather than an invocation |
|
89 // counter, therefore no shifting of bits is required. |
|
90 _interpreter_backward_branch_limit = (compile_threshold * (OnStackReplacePercentage - InterpreterProfilePercentage)) / 100; |
|
91 } else { |
|
92 _interpreter_backward_branch_limit = ((compile_threshold * OnStackReplacePercentage) / 100) << InvocationCounter::count_shift; |
|
93 } |
|
94 _interpreter_profile_limit = ((compile_threshold * InterpreterProfilePercentage) / 100) << InvocationCounter::count_shift; |
|
95 _invoke_mask = right_n_bits(Arguments::scaled_freq_log(Tier0InvokeNotifyFreqLog, scale)) << InvocationCounter::count_shift; |
|
96 _backedge_mask = right_n_bits(Arguments::scaled_freq_log(Tier0BackedgeNotifyFreqLog, scale)) << InvocationCounter::count_shift; |
73 } |
97 } |
74 |
98 |
75 public: |
99 public: |
76 static MethodCounters* allocate(ClassLoaderData* loader_data, TRAPS); |
100 static MethodCounters* allocate(methodHandle mh, TRAPS); |
77 |
101 |
78 void deallocate_contents(ClassLoaderData* loader_data) {} |
102 void deallocate_contents(ClassLoaderData* loader_data) {} |
79 DEBUG_ONLY(bool on_stack() { return false; }) // for template |
103 DEBUG_ONLY(bool on_stack() { return false; }) // for template |
80 |
104 |
81 static int size() { return sizeof(MethodCounters) / wordSize; } |
105 static int size() { return sizeof(MethodCounters) / wordSize; } |
159 |
183 |
160 static int interpreter_invocation_counter_offset_in_bytes() { |
184 static int interpreter_invocation_counter_offset_in_bytes() { |
161 return offset_of(MethodCounters, _interpreter_invocation_count); |
185 return offset_of(MethodCounters, _interpreter_invocation_count); |
162 } |
186 } |
163 |
187 |
|
188 static ByteSize interpreter_invocation_limit_offset() { |
|
189 return byte_offset_of(MethodCounters, _interpreter_invocation_limit); |
|
190 } |
|
191 |
|
192 static ByteSize interpreter_backward_branch_limit_offset() { |
|
193 return byte_offset_of(MethodCounters, _interpreter_backward_branch_limit); |
|
194 } |
|
195 |
|
196 static ByteSize interpreter_profile_limit_offset() { |
|
197 return byte_offset_of(MethodCounters, _interpreter_profile_limit); |
|
198 } |
|
199 |
|
200 static ByteSize invoke_mask_offset() { |
|
201 return byte_offset_of(MethodCounters, _invoke_mask); |
|
202 } |
|
203 |
|
204 static ByteSize backedge_mask_offset() { |
|
205 return byte_offset_of(MethodCounters, _backedge_mask); |
|
206 } |
164 }; |
207 }; |
165 #endif //SHARE_VM_OOPS_METHODCOUNTERS_HPP |
208 #endif //SHARE_VM_OOPS_METHODCOUNTERS_HPP |