1 /*
   2  * Copyright (c) 2016, 2018, 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_VM_JFR_CHECKPOINT_CONSTANT_TRACEID_JFRTRACEIDEPOCH_HPP
  26 #define SHARE_VM_JFR_CHECKPOINT_CONSTANT_TRACEID_JFRTRACEIDEPOCH_HPP
  27 
  28 #include "memory/allocation.hpp"
  29 #include "jfr/utilities/jfrTypes.hpp"
  30 #include "trace/traceMacros.hpp"
  31 
  32 class JfrTraceIdEpoch : AllStatic {
  33   friend class JfrCheckpointManager;
  34  private:
  35   static bool _epoch_state;
  36   static void shift_epoch();
  37 
  38  public:
  39   static bool epoch() {
  40     return _epoch_state;
  41   }
  42 
  43   static jlong epoch_address() {
  44     return (jlong)&_epoch_state;
  45   }
  46 
  47   static u1 current() {
  48     return _epoch_state ? (u1)1 : (u1)0;
  49   }
  50 
  51   static u1 previous() {
  52     return _epoch_state ? (u1)0 : (u1)1;
  53   }
  54 
  55   static traceid in_use_this_epoch_bit() {
  56     return _epoch_state ? USED_EPOCH_2_BIT : USED_EPOCH_1_BIT;
  57   }
  58 
  59   static traceid in_use_prev_epoch_bit() {
  60     return _epoch_state ? USED_EPOCH_1_BIT : USED_EPOCH_2_BIT;
  61   }
  62 
  63   static traceid leakp_in_use_this_epoch_bit() {
  64     return _epoch_state ? LEAKP_USED_EPOCH_2_BIT : LEAKP_USED_EPOCH_1_BIT;
  65   }
  66 
  67   static traceid leakp_in_use_prev_epoch_bit() {
  68     return _epoch_state ? LEAKP_USED_EPOCH_1_BIT : LEAKP_USED_EPOCH_2_BIT;
  69   }
  70 
  71   static traceid method_in_use_this_epoch_bit() {
  72     return _epoch_state ? METHOD_USED_EPOCH_2_BIT : METHOD_USED_EPOCH_1_BIT;
  73   }
  74 
  75   static traceid method_in_use_prev_epoch_bit() {
  76     return _epoch_state ? METHOD_USED_EPOCH_1_BIT : METHOD_USED_EPOCH_2_BIT;
  77   }
  78 
  79   static traceid method_and_class_in_use_this_epoch_bits() {
  80     return _epoch_state ? METHOD_AND_CLASS_IN_USE_EPOCH_2_BITS : METHOD_AND_CLASS_IN_USE_EPOCH_1_BITS;
  81   }
  82 
  83   static traceid method_and_class_in_use_prev_epoch_bits() {
  84     return _epoch_state ? METHOD_AND_CLASS_IN_USE_EPOCH_1_BITS :  METHOD_AND_CLASS_IN_USE_EPOCH_2_BITS;
  85   }
  86 };
  87 
  88 #endif // SHARE_VM_JFR_CHECKPOINT_CONSTANT_TRACEID_JFRTRACEIDEPOCH_HPP