1 /*
 2 * Copyright (c) 2020, 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_JFR_RECORDER_CHECKPOINT_TYPES_TRACEID_JFROOPTRACEID_INLINE_HPP
26 #define SHARE_JFR_RECORDER_CHECKPOINT_TYPES_TRACEID_JFROOPTRACEID_INLINE_HPP
27 
28 #include "jfr/recorder/checkpoint/types/traceid/jfrOopTraceId.hpp"
29 #include "jfr/recorder/checkpoint/types/traceid/jfrTraceIdEpoch.hpp"
30 
31 template <typename T>
32 inline bool JfrOopTraceId<T>::store(oop ref, traceid value) {
33   assert(ref != NULL, "invariant");
34   assert(value != 0, "invariant");
35   return T::store(ref, value) == value;
36 }
37 
38 template <typename T>
39 inline traceid JfrOopTraceId<T>::load(oop ref) {
40   assert(ref != NULL, "invariant");
41   return T::load(ref);
42 }
43 
44 template <typename T>
45 inline traceid JfrOopTraceId<T>::epoch(traceid value) {
46   return value >> jfr_epoch_shift;
47 }
48 
49 template <typename T>
50 inline traceid JfrOopTraceId<T>::id(traceid value) {
51   return value & jfr_id_mask;
52 }
53 
54 inline bool is_current(traceid epoch) {
55   return JfrTraceIdEpoch::is_current_epoch_generation(epoch);
56 }
57 
58 inline bool need_checkpoint(traceid epoch) {
59   return !is_current(epoch);
60 }
61 
62 inline traceid embed_current_epoch(traceid id) {
63   return (JfrTraceIdEpoch::epoch_generation() << jfr_epoch_shift) | id;
64 }
65 
66 template <typename T>
67 inline bool JfrOopTraceId<T>::store_current_epoch(oop ref, traceid id) {
68   assert(ref != NULL, "invariant");
69   assert(id != 0, "invariant");
70   return store(ref, embed_current_epoch(id));
71 }
72 
73 template <typename T>
74 inline bool JfrOopTraceId<T>::should_write_checkpoint(oop ref, traceid value) {
75   assert(ref != NULL, "invariant");
76   return need_checkpoint(epoch(value)) && store_current_epoch(ref, id(value));
77 }
78 
79 #endif // SHARE_JFR_RECORDER_CHECKPOINT_TYPES_TRACEID_JFROOPTRACEID_INLINE_HPP