1 /* 2 * Copyright (c) 2018, 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_METHOD_INLINE_HPP 26 #define SHARE_OOPS_METHOD_INLINE_HPP 27 28 #include "oops/method.hpp" 29 30 #include "classfile/vmIntrinsics.hpp" 31 #include "oops/methodCounters.hpp" 32 #include "runtime/atomic.hpp" 33 34 inline address Method::from_compiled_entry() const { 35 return Atomic::load_acquire(&_from_compiled_entry); 36 } 37 38 inline address Method::from_compiled_inline_ro_entry() const { 39 return Atomic::load_acquire(&_from_compiled_inline_ro_entry); 40 } 41 42 inline address Method::from_compiled_inline_entry() const { 43 return Atomic::load_acquire(&_from_compiled_inline_entry); 44 } 45 46 inline address Method::from_interpreted_entry() const { 47 return Atomic::load_acquire(&_from_interpreted_entry); 48 } 49 50 inline nmethod* Method::code() const { 51 assert( check_code(), "" ); 52 return Atomic::load_acquire(&_code); 53 } 54 55 // Write (bci, line number) pair to stream 56 inline void CompressedLineNumberWriteStream::write_pair_regular(int bci_delta, int line_delta) { 57 // bci and line number does not compress into single byte. 58 // Write out escape character and use regular compression for bci and line number. 59 write_byte((jubyte)0xFF); 60 write_signed_int(bci_delta); 61 write_signed_int(line_delta); 62 } 63 64 inline void CompressedLineNumberWriteStream::write_pair_inline(int bci, int line) { 65 int bci_delta = bci - _bci; 66 int line_delta = line - _line; 67 _bci = bci; 68 _line = line; 69 // Skip (0,0) deltas - they do not add information and conflict with terminator. 70 if (bci_delta == 0 && line_delta == 0) return; 71 // Check if bci is 5-bit and line number 3-bit unsigned. 72 if (((bci_delta & ~0x1F) == 0) && ((line_delta & ~0x7) == 0)) { 73 // Compress into single byte. 74 jubyte value = (jubyte)((bci_delta << 3) | line_delta); 75 // Check that value doesn't match escape character. 76 if (value != 0xFF) { 77 write_byte(value); 78 return; 79 } 80 } 81 write_pair_regular(bci_delta, line_delta); 82 } 83 84 inline void CompressedLineNumberWriteStream::write_pair(int bci, int line) { 85 write_pair_inline(bci, line); 86 } 87 88 inline bool Method::has_compiled_code() const { return code() != nullptr; } 89 90 inline bool Method::is_empty_method() const { 91 return code_size() == 1 92 && *code_base() == Bytecodes::_return; 93 } 94 95 inline bool Method::is_continuation_enter_intrinsic() const { 96 return intrinsic_id() == vmIntrinsics::_Continuation_enterSpecial; 97 } 98 99 inline bool Method::is_continuation_yield_intrinsic() const { 100 return intrinsic_id() == vmIntrinsics::_Continuation_doYield; 101 } 102 103 inline bool Method::is_continuation_native_intrinsic() const { 104 return intrinsic_id() == vmIntrinsics::_Continuation_enterSpecial || 105 intrinsic_id() == vmIntrinsics::_Continuation_doYield; 106 } 107 108 inline bool Method::is_special_native_intrinsic() const { 109 return is_method_handle_intrinsic() || is_continuation_native_intrinsic(); 110 } 111 112 #if INCLUDE_JVMTI 113 inline u2 Method::number_of_breakpoints() const { 114 MethodCounters* mcs = method_counters(); 115 if (mcs == nullptr) { 116 return 0; 117 } else { 118 return mcs->number_of_breakpoints(); 119 } 120 } 121 122 inline void Method::incr_number_of_breakpoints(Thread* current) { 123 MethodCounters* mcs = get_method_counters(current); 124 if (mcs != nullptr) { 125 mcs->incr_number_of_breakpoints(); 126 } 127 } 128 129 inline void Method::decr_number_of_breakpoints(Thread* current) { 130 MethodCounters* mcs = get_method_counters(current); 131 if (mcs != nullptr) { 132 mcs->decr_number_of_breakpoints(); 133 } 134 } 135 136 // Initialization only 137 inline void Method::clear_number_of_breakpoints() { 138 MethodCounters* mcs = method_counters(); 139 if (mcs != nullptr) { 140 mcs->clear_number_of_breakpoints(); 141 } 142 } 143 #endif // INCLUDE_JVMTI 144 145 #if COMPILER2_OR_JVMCI 146 inline void Method::interpreter_throwout_increment(Thread* current) { 147 MethodCounters* mcs = get_method_counters(current); 148 if (mcs != nullptr) { 149 mcs->interpreter_throwout_increment(); 150 } 151 } 152 #endif 153 154 inline int Method::interpreter_throwout_count() const { 155 MethodCounters* mcs = method_counters(); 156 if (mcs == nullptr) { 157 return 0; 158 } else { 159 return mcs->interpreter_throwout_count(); 160 } 161 } 162 163 inline int Method::prev_event_count() const { 164 MethodCounters* mcs = method_counters(); 165 return mcs == nullptr ? 0 : mcs->prev_event_count(); 166 } 167 168 inline void Method::set_prev_event_count(int count) { 169 MethodCounters* mcs = method_counters(); 170 if (mcs != nullptr) { 171 mcs->set_prev_event_count(count); 172 } 173 } 174 175 inline jlong Method::prev_time() const { 176 MethodCounters* mcs = method_counters(); 177 return mcs == nullptr ? 0 : mcs->prev_time(); 178 } 179 180 inline void Method::set_prev_time(jlong time) { 181 MethodCounters* mcs = method_counters(); 182 if (mcs != nullptr) { 183 mcs->set_prev_time(time); 184 } 185 } 186 187 inline float Method::rate() const { 188 MethodCounters* mcs = method_counters(); 189 return mcs == nullptr ? 0 : mcs->rate(); 190 } 191 192 inline void Method::set_rate(float rate) { 193 MethodCounters* mcs = method_counters(); 194 if (mcs != nullptr) { 195 mcs->set_rate(rate); 196 } 197 } 198 199 #endif // SHARE_OOPS_METHOD_INLINE_HPP