Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8303277

Add Atomic bit operations

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Duplicate
    • P3
    • None
    • 21
    • hotspot
    • None

    Description

      Atomically setting/clearing/flipping bits in bytes/words is sometimes needed and currently performed in an ad-hoc manner by the code that needs it. We could add something like (per [~jrose] suggestion):

      template<typename D, typename T>
      inline bool
      Atomic::change_bits(D volatile* dest,
                          T dest_mask, // mask of bits which may be changed (0=>none)
                          int effect) { // 1=>set, 0=>clear, -1=>toggle
        for (;;) {
          u1 d0 = *dest;
          u1 d1 = d0 ^ (dest_mask & (effect < 0 ? (T)-1 : effect ? d0 : ~d0));
          if (d0 == d1) return false;
          d1 = Atomic::cmpxchg(dest, d0, d1);
          if (d0 == d1) return true;
        }
      }

      or split it out into bit_set, bit_clear, bit_toggle.

      Code that could potentially use this is in:

      java_lang_String::test_and_set_flag
      ClassLoaderData::clear_claim
      ClassLoaderData::try_claim
      set_defined_by_cds_in_class_path
      BitMap::par_set_bit/BitMap::par_clear_bit/BitMap::par_put_range_within_word
      AccessFlags::atomic_set[clear]_bits

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              dholmes David Holmes
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: