1 /*
 2 <<<<<<< HEAD
 3  * Copyright (c) 2002, 2024, Oracle and/or its affiliates. All rights reserved.
 4 =======
 5  * Copyright (c) 2002, 2026, Oracle and/or its affiliates. All rights reserved.
 6 >>>>>>> master
 7  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 8  *
 9  * This code is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU General Public License version 2 only, as
11  * published by the Free Software Foundation.
12  *
13  * This code is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16  * version 2 for more details (a copy is included in the LICENSE file that
17  * accompanied this code).
18  *
19  * You should have received a copy of the GNU General Public License version
20  * 2 along with this work; if not, write to the Free Software Foundation,
21  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
22  *
23  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
24  * or visit www.oracle.com if you need additional information or have any
25  * questions.
26  *
27  */
28 
29 #ifndef SHARE_RUNTIME_PERFDATA_INLINE_HPP
30 #define SHARE_RUNTIME_PERFDATA_INLINE_HPP
31 
32 #include "runtime/perfData.hpp"
33 
34 #include "services/management.hpp"
35 #include "utilities/globalCounter.inline.hpp"
36 #include "utilities/globalDefinitions.hpp"
37 #include "utilities/growableArray.hpp"
38 
39 inline int PerfDataList::length() {
40   return _set->length();
41 }
42 
43 inline void PerfDataList::append(PerfData *p) {
44   _set->append(p);
45 }
46 
47 inline PerfData* PerfDataList::at(int index) {
48   return _set->at(index);
49 }
50 
51 inline bool PerfDataManager::exists(const char* name) {
52   if (_all != nullptr) {
53     return _all->contains(name);
54   } else {
55     return false;
56   }
57 }
58 
59 inline jlong PerfTickCounters::elapsed_counter_value_ms() const {
60   return Management::ticks_to_ms(_elapsed_counter->get_value());
61 }
62 
63 inline jlong PerfTickCounters::thread_counter_value_ms() const {
64   return Management::ticks_to_ms(_thread_counter->get_value());
65 }
66 
67 inline jlong PerfTickCounters::elapsed_counter_value_us() const {
68   return Management::ticks_to_us(_elapsed_counter->get_value());
69 }
70 
71 inline jlong PerfTickCounters::thread_counter_value_us() const {
72   return Management::ticks_to_us(_thread_counter->get_value());
73 }
74 
75 inline SafePerfTraceTime::SafePerfTraceTime(PerfLongCounter* timerp) : _timerp(timerp) {
76   GlobalCounter::CriticalSection cs(Thread::current());
77   if (!UsePerfData || !PerfDataManager::has_PerfData() || timerp == nullptr) {
78     return;
79   }
80   _t.start();
81 }
82 
83 inline SafePerfTraceTime::~SafePerfTraceTime() {
84   GlobalCounter::CriticalSection cs(Thread::current());
85   if (!UsePerfData || !PerfDataManager::has_PerfData() || !_t.is_active()) {
86     return;
87   }
88 
89   _t.stop();
90   _timerp->inc(_t.ticks());
91 }
92 
93 #endif // SHARE_RUNTIME_PERFDATA_INLINE_HPP