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