1 /* 2 * Copyright (c) 2013, 2024, Oracle and/or its affiliates. All rights reserved. 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 * 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 Metadata { 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 virtual bool is_methodCounters() const { return true; } 56 57 static MethodCounters* allocate_no_exception(const methodHandle& mh); 58 static MethodCounters* allocate_with_exception(const methodHandle& mh, TRAPS); 59 60 void deallocate_contents(ClassLoaderData* loader_data) {} 61 62 static int method_counters_size() { 63 return align_up((int)sizeof(MethodCounters), wordSize) / wordSize; 64 } 65 virtual int size() const { 66 return method_counters_size(); 67 } 68 MetaspaceObj::Type type() const { return MethodCountersType; } 69 void clear_counters(); 70 71 #if COMPILER2_OR_JVMCI 72 void interpreter_throwout_increment() { 73 if (_interpreter_throwout_count < 65534) { 74 _interpreter_throwout_count++; 75 } 76 } 77 u2 interpreter_throwout_count() const { 78 return _interpreter_throwout_count; 79 } 80 void set_interpreter_throwout_count(u2 count) { 81 _interpreter_throwout_count = count; 82 } 83 #else // COMPILER2_OR_JVMCI 84 u2 interpreter_throwout_count() const { 85 return 0; 86 } 87 void set_interpreter_throwout_count(u2 count) { 88 assert(count == 0, "count must be 0"); 89 } 90 #endif // COMPILER2_OR_JVMCI 91 92 #if INCLUDE_JVMTI 93 u2 number_of_breakpoints() const { return _number_of_breakpoints; } 94 void incr_number_of_breakpoints() { ++_number_of_breakpoints; } 95 void decr_number_of_breakpoints() { --_number_of_breakpoints; } 96 void clear_number_of_breakpoints() { _number_of_breakpoints = 0; } 97 #endif 98 99 int prev_event_count() const { return _prev_event_count; } 100 void set_prev_event_count(int count) { _prev_event_count = count; } 101 jlong prev_time() const { return _prev_time; } 102 void set_prev_time(jlong time) { _prev_time = time; } 103 float rate() const { return _rate; } 104 void set_rate(float rate) { _rate = rate; } 105 106 int highest_comp_level() const { return _highest_comp_level; } 107 void set_highest_comp_level(int level) { _highest_comp_level = (u1)level; } 108 int highest_osr_comp_level() const { return _highest_osr_comp_level; } 109 void set_highest_osr_comp_level(int level) { _highest_osr_comp_level = (u1)level; } 110 111 // invocation counter 112 InvocationCounter* invocation_counter() { return &_invocation_counter; } 113 InvocationCounter* backedge_counter() { return &_backedge_counter; } 114 115 static ByteSize invocation_counter_offset() { 116 return byte_offset_of(MethodCounters, _invocation_counter); 117 } 118 119 static ByteSize backedge_counter_offset() { 120 return byte_offset_of(MethodCounters, _backedge_counter); 121 } 122 123 static ByteSize invoke_mask_offset() { 124 return byte_offset_of(MethodCounters, _invoke_mask); 125 } 126 127 static ByteSize backedge_mask_offset() { 128 return byte_offset_of(MethodCounters, _backedge_mask); 129 } 130 131 virtual const char* internal_name() const { return "{method counters}"; } 132 virtual void print_value_on(outputStream* st) const; 133 134 }; 135 #endif // SHARE_OOPS_METHODCOUNTERS_HPP