< prev index next >

src/hotspot/share/gc/shenandoah/shenandoahSharedVariables.hpp

Print this page

104   bool operator>=(ShenandoahSharedFlag& other) { fatal("Use is_set() instead"); return false; }
105   bool operator< (ShenandoahSharedFlag& other) { fatal("Use is_set() instead"); return false; }
106   bool operator<=(ShenandoahSharedFlag& other) { fatal("Use is_set() instead"); return false; }
107 
108 } ShenandoahSharedFlag;
109 
110 typedef struct ShenandoahSharedBitmap {
111   shenandoah_padding(0);
112   volatile ShenandoahSharedValue value;
113   shenandoah_padding(1);
114 
115   ShenandoahSharedBitmap() {
116     clear();
117   }
118 
119   void set(uint mask) {
120     assert (mask < (sizeof(ShenandoahSharedValue) * CHAR_MAX), "sanity");
121     ShenandoahSharedValue mask_val = (ShenandoahSharedValue) mask;
122     while (true) {
123       ShenandoahSharedValue ov = Atomic::load_acquire(&value);
124       if ((ov & mask_val) != 0) {

125         // already set
126         return;
127       }
128 
129       ShenandoahSharedValue nv = ov | mask_val;
130       if (Atomic::cmpxchg(&value, ov, nv) == ov) {
131         // successfully set
132         return;
133       }
134     }
135   }
136 
137   void unset(uint mask) {
138     assert (mask < (sizeof(ShenandoahSharedValue) * CHAR_MAX), "sanity");
139     ShenandoahSharedValue mask_val = (ShenandoahSharedValue) mask;
140     while (true) {
141       ShenandoahSharedValue ov = Atomic::load_acquire(&value);
142       if ((ov & mask_val) == 0) {
143         // already unset
144         return;
145       }
146 
147       ShenandoahSharedValue nv = ov & ~mask_val;
148       if (Atomic::cmpxchg(&value, ov, nv) == ov) {
149         // successfully unset
150         return;
151       }
152     }
153   }
154 
155   void clear() {
156     Atomic::release_store_fence(&value, (ShenandoahSharedValue)0);
157   }
158 

159   bool is_set(uint mask) const {
160     return !is_unset(mask);
161   }
162 








163   bool is_unset(uint mask) const {
164     assert (mask < (sizeof(ShenandoahSharedValue) * CHAR_MAX), "sanity");
165     return (Atomic::load_acquire(&value) & (ShenandoahSharedValue) mask) == 0;
166   }
167 
168   bool is_clear() const {
169     return (Atomic::load_acquire(&value)) == 0;
170   }
171 
172   void set_cond(uint mask, bool val) {
173     if (val) {
174       set(mask);
175     } else {
176       unset(mask);
177     }
178   }
179 
180   volatile ShenandoahSharedValue* addr_of() {
181     return &value;
182   }

104   bool operator>=(ShenandoahSharedFlag& other) { fatal("Use is_set() instead"); return false; }
105   bool operator< (ShenandoahSharedFlag& other) { fatal("Use is_set() instead"); return false; }
106   bool operator<=(ShenandoahSharedFlag& other) { fatal("Use is_set() instead"); return false; }
107 
108 } ShenandoahSharedFlag;
109 
110 typedef struct ShenandoahSharedBitmap {
111   shenandoah_padding(0);
112   volatile ShenandoahSharedValue value;
113   shenandoah_padding(1);
114 
115   ShenandoahSharedBitmap() {
116     clear();
117   }
118 
119   void set(uint mask) {
120     assert (mask < (sizeof(ShenandoahSharedValue) * CHAR_MAX), "sanity");
121     ShenandoahSharedValue mask_val = (ShenandoahSharedValue) mask;
122     while (true) {
123       ShenandoahSharedValue ov = Atomic::load_acquire(&value);
124       // We require all bits of mask_val to be set
125       if ((ov & mask_val) == mask_val) {
126         // already set
127         return;
128       }
129 
130       ShenandoahSharedValue nv = ov | mask_val;
131       if (Atomic::cmpxchg(&value, ov, nv) == ov) {
132         // successfully set: if value returned from cmpxchg equals ov, then nv has overwritten value.
133         return;
134       }
135     }
136   }
137 
138   void unset(uint mask) {
139     assert (mask < (sizeof(ShenandoahSharedValue) * CHAR_MAX), "sanity");
140     ShenandoahSharedValue mask_val = (ShenandoahSharedValue) mask;
141     while (true) {
142       ShenandoahSharedValue ov = Atomic::load_acquire(&value);
143       if ((ov & mask_val) == 0) {
144         // already unset
145         return;
146       }
147 
148       ShenandoahSharedValue nv = ov & ~mask_val;
149       if (Atomic::cmpxchg(&value, ov, nv) == ov) {
150         // successfully unset
151         return;
152       }
153     }
154   }
155 
156   void clear() {
157     Atomic::release_store_fence(&value, (ShenandoahSharedValue)0);
158   }
159 
160   // Returns true iff any bit set in mask is set in this.value.
161   bool is_set(uint mask) const {
162     return !is_unset(mask);
163   }
164 
165   // Returns true iff all bits set in mask are set in this.value.
166   bool is_set_exactly(uint mask) const {
167     assert (mask < (sizeof(ShenandoahSharedValue) * CHAR_MAX), "sanity");
168     uint uvalue = Atomic::load_acquire(&value);
169     return (uvalue & mask) == mask;
170   }
171 
172   // Returns true iff all bits set in mask are unset in this.value.
173   bool is_unset(uint mask) const {
174     assert (mask < (sizeof(ShenandoahSharedValue) * CHAR_MAX), "sanity");
175     return (Atomic::load_acquire(&value) & (ShenandoahSharedValue) mask) == 0;
176   }
177 
178   bool is_clear() const {
179     return (Atomic::load_acquire(&value)) == 0;
180   }
181 
182   void set_cond(uint mask, bool val) {
183     if (val) {
184       set(mask);
185     } else {
186       unset(mask);
187     }
188   }
189 
190   volatile ShenandoahSharedValue* addr_of() {
191     return &value;
192   }
< prev index next >