< prev index next >

src/hotspot/share/jfr/recorder/checkpoint/types/traceid/jfrTraceIdBits.inline.hpp

Print this page




  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_JFRTRACEIDBITS_INLINE_HPP
  26 #define SHARE_JFR_RECORDER_CHECKPOINT_TYPES_TRACEID_JFRTRACEIDBITS_INLINE_HPP
  27 
  28 #include "jfr/utilities/jfrTypes.hpp"
  29 #include "runtime/atomic.hpp"
  30 #include "runtime/orderAccess.hpp"
  31 #include "utilities/macros.hpp"
  32 
  33 #ifdef VM_LITTLE_ENDIAN
  34 static const int low_offset = 0;
  35 static const int leakp_offset = low_offset + 1;
  36 #else
  37 static const int low_offset = 7;
  38 static const int leakp_offset = low_offset - 1;
  39 #endif
  40 
  41 inline void set_bits(jbyte bits, jbyte* const dest) {
  42   assert(dest != NULL, "invariant");
  43   const jbyte current = OrderAccess::load_acquire(dest);
  44   if (bits != (current & bits)) {
  45     *dest |= bits;
  46   }
  47 }
  48 
  49 inline void set_mask(jbyte mask, jbyte* const dest) {
  50   assert(dest != NULL, "invariant");
  51   const jbyte current = OrderAccess::load_acquire(dest);
  52   if (mask != (current & mask)) {
  53     *dest &= mask;
  54   }
  55 }
  56 
  57 inline void set_bits_cas(jbyte bits, jbyte* const dest) {









  58   assert(dest != NULL, "invariant");
  59   do {
  60     const jbyte current = OrderAccess::load_acquire(dest);
  61     if (bits == (current & bits)) {
  62       return;
  63     }
  64     const jbyte new_value = current | bits;
  65     if (Atomic::cmpxchg(new_value, dest, current) == current) {
  66       return;
  67     }
  68   } while (true);
  69 }
  70 




  71 inline void clear_bits_cas(jbyte bits, jbyte* const dest) {
  72   assert(dest != NULL, "invariant");
  73   do {
  74     const jbyte current = OrderAccess::load_acquire(dest);
  75     if (bits != (current & bits)) {
  76       return;
  77     }
  78     const jbyte new_value = current ^ bits;
  79     if (Atomic::cmpxchg(new_value, dest, current) == current) {
  80       return;
  81     }
  82   } while (true);
  83 }
  84 
  85 inline void set_traceid_bits(jbyte bits, traceid* dest) {
  86   set_bits(bits, ((jbyte*)dest) + low_offset);
  87 }
  88 
  89 inline void set_traceid_bits_cas(jbyte bits, traceid* dest) {
  90   set_bits_cas(bits, ((jbyte*)dest) + low_offset);
  91 }
  92 
  93 inline void set_traceid_mask(jbyte mask, traceid* dest) {
  94   set_mask(mask, ((jbyte*)dest) + low_offset);
  95 }
  96 
  97 inline void set_leakp_traceid_bits(jbyte bits, traceid* dest) {
  98   set_bits(bits, ((jbyte*)dest) + leakp_offset);
  99 }
 100 
 101 inline void set_leakp_traceid_bits_cas(jbyte bits, traceid* dest) {
 102   set_bits_cas(bits, ((jbyte*)dest) + leakp_offset);


  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_JFRTRACEIDBITS_INLINE_HPP
  26 #define SHARE_JFR_RECORDER_CHECKPOINT_TYPES_TRACEID_JFRTRACEIDBITS_INLINE_HPP
  27 
  28 #include "jfr/utilities/jfrTypes.hpp"
  29 #include "runtime/atomic.hpp"

  30 #include "utilities/macros.hpp"
  31 
  32 #ifdef VM_LITTLE_ENDIAN
  33 static const int low_offset = 0;
  34 static const int leakp_offset = low_offset + 1;
  35 #else
  36 static const int low_offset = 7;
  37 static const int leakp_offset = low_offset - 1;
  38 #endif
  39 
  40 inline void set_bits(jbyte bits, jbyte* const dest) {
  41   assert(dest != NULL, "invariant");
  42   if (bits != (*dest & bits)) {

  43     *dest |= bits;
  44   }
  45 }
  46 
  47 inline jbyte traceid_and(jbyte current, jbyte bits) {
  48   return current & bits;




  49 }
  50 
  51 inline jbyte traceid_or(jbyte current, jbyte bits) {
  52   return current | bits;
  53 }
  54 
  55 inline jbyte traceid_xor(jbyte current, jbyte bits) {
  56   return current ^ bits;
  57 }
  58 
  59 template <jbyte op(jbyte, jbyte)>
  60 inline void set_bits_cas_form(jbyte bits, jbyte* const dest) {
  61   assert(dest != NULL, "invariant");
  62   do {
  63     const jbyte current = *dest;
  64     const jbyte new_value = op(current, bits);



  65     if (Atomic::cmpxchg(new_value, dest, current) == current) {
  66       return;
  67     }
  68   } while (true);
  69 }
  70 
  71 inline void set_bits_cas(jbyte bits, jbyte* const dest) {
  72   set_bits_cas_form<traceid_or>(bits, dest);
  73 }
  74 
  75 inline void clear_bits_cas(jbyte bits, jbyte* const dest) {
  76   set_bits_cas_form<traceid_xor>(bits, dest);
  77 }
  78 
  79 inline void set_mask(jbyte mask, jbyte* const dest) {
  80   set_bits_cas_form<traceid_and>(mask, dest);






  81 }
  82 
  83 inline void set_traceid_bits(jbyte bits, traceid* dest) {
  84   set_bits(bits, ((jbyte*)dest) + low_offset);
  85 }
  86 
  87 inline void set_traceid_bits_cas(jbyte bits, traceid* dest) {
  88   set_bits_cas(bits, ((jbyte*)dest) + low_offset);
  89 }
  90 
  91 inline void set_traceid_mask(jbyte mask, traceid* dest) {
  92   set_mask(mask, ((jbyte*)dest) + low_offset);
  93 }
  94 
  95 inline void set_leakp_traceid_bits(jbyte bits, traceid* dest) {
  96   set_bits(bits, ((jbyte*)dest) + leakp_offset);
  97 }
  98 
  99 inline void set_leakp_traceid_bits_cas(jbyte bits, traceid* dest) {
 100   set_bits_cas(bits, ((jbyte*)dest) + leakp_offset);
< prev index next >