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