< prev index next >

src/share/vm/gc/g1/g1AllocRegion.cpp

Print this page
rev 8978 : imported patch remove_err_msg
rev 8979 : [mq]: vmerr_static


  74       // If the allocation was successful we should fill in the space.
  75       CollectedHeap::fill_with_object(dummy, free_word_size);
  76       alloc_region->set_pre_dummy_top(dummy);
  77       result += free_word_size * HeapWordSize;
  78       break;
  79     }
  80 
  81     free_word_size = alloc_region->free() / HeapWordSize;
  82     // It's also possible that someone else beats us to the
  83     // allocation and they fill up the region. In that case, we can
  84     // just get out of the loop.
  85   }
  86   result += alloc_region->free();
  87 
  88   assert(alloc_region->free() / HeapWordSize < min_word_size_to_fill,
  89          "post-condition");
  90   return result;
  91 }
  92 
  93 size_t G1AllocRegion::retire(bool fill_up) {
  94   assert(_alloc_region != NULL, ar_ext_msg(this, "not initialized properly"));
  95 
  96   size_t result = 0;
  97 
  98   trace("retiring");
  99   HeapRegion* alloc_region = _alloc_region;
 100   if (alloc_region != _dummy_region) {
 101     // We never have to check whether the active region is empty or not,
 102     // and potentially free it if it is, given that it's guaranteed that
 103     // it will never be empty.
 104     assert(!alloc_region->is_empty(),
 105            ar_ext_msg(this, "the alloc region should never be empty"));
 106 
 107     if (fill_up) {
 108       result = fill_up_remaining_space(alloc_region, _bot_updates);
 109     }
 110 
 111     assert(alloc_region->used() >= _used_bytes_before,
 112            ar_ext_msg(this, "invariant"));
 113     size_t allocated_bytes = alloc_region->used() - _used_bytes_before;
 114     retire_region(alloc_region, allocated_bytes);
 115     _used_bytes_before = 0;
 116     _alloc_region = _dummy_region;
 117   }
 118   trace("retired");
 119 
 120   return result;
 121 }
 122 
 123 HeapWord* G1AllocRegion::new_alloc_region_and_allocate(size_t word_size,
 124                                                        bool force) {
 125   assert(_alloc_region == _dummy_region, ar_ext_msg(this, "pre-condition"));
 126   assert(_used_bytes_before == 0, ar_ext_msg(this, "pre-condition"));
 127 
 128   trace("attempting region allocation");
 129   HeapRegion* new_alloc_region = allocate_new_region(word_size, force);
 130   if (new_alloc_region != NULL) {
 131     new_alloc_region->reset_pre_dummy_top();
 132     // Need to do this before the allocation
 133     _used_bytes_before = new_alloc_region->used();
 134     HeapWord* result = allocate(new_alloc_region, word_size, _bot_updates);
 135     assert(result != NULL, ar_ext_msg(this, "the allocation should succeeded"));
 136 
 137     OrderAccess::storestore();
 138     // Note that we first perform the allocation and then we store the
 139     // region in _alloc_region. This is the reason why an active region
 140     // can never be empty.
 141     update_alloc_region(new_alloc_region);
 142     trace("region allocation successful");
 143     return result;
 144   } else {
 145     trace("region allocation failed");
 146     return NULL;
 147   }
 148   ShouldNotReachHere();
 149 }
 150 
 151 void G1AllocRegion::fill_in_ext_msg(ar_ext_msg* msg, const char* message) {
 152   msg->append("[%s] %s c: %u b: %s r: " PTR_FORMAT " u: " SIZE_FORMAT,
 153               _name, message, _count, BOOL_TO_STR(_bot_updates),
 154               p2i(_alloc_region), _used_bytes_before);
 155 }
 156 
 157 void G1AllocRegion::init() {
 158   trace("initializing");
 159   assert(_alloc_region == NULL && _used_bytes_before == 0,
 160          ar_ext_msg(this, "pre-condition"));
 161   assert(_dummy_region != NULL, ar_ext_msg(this, "should have been set"));
 162   _alloc_region = _dummy_region;
 163   _count = 0;
 164   trace("initialized");
 165 }
 166 
 167 void G1AllocRegion::set(HeapRegion* alloc_region) {
 168   trace("setting");
 169   // We explicitly check that the region is not empty to make sure we
 170   // maintain the "the alloc region cannot be empty" invariant.
 171   assert(alloc_region != NULL && !alloc_region->is_empty(),
 172          ar_ext_msg(this, "pre-condition"));
 173   assert(_alloc_region == _dummy_region &&
 174          _used_bytes_before == 0 && _count == 0,
 175          ar_ext_msg(this, "pre-condition"));
 176 
 177   _used_bytes_before = alloc_region->used();
 178   _alloc_region = alloc_region;
 179   _count += 1;
 180   trace("set");
 181 }
 182 
 183 void G1AllocRegion::update_alloc_region(HeapRegion* alloc_region) {
 184   trace("update");
 185   // We explicitly check that the region is not empty to make sure we
 186   // maintain the "the alloc region cannot be empty" invariant.
 187   assert(alloc_region != NULL && !alloc_region->is_empty(),
 188          ar_ext_msg(this, "pre-condition"));
 189 
 190   _alloc_region = alloc_region;
 191   _alloc_region->set_allocation_context(allocation_context());
 192   _count += 1;
 193   trace("updated");
 194 }
 195 
 196 HeapRegion* G1AllocRegion::release() {
 197   trace("releasing");
 198   HeapRegion* alloc_region = _alloc_region;
 199   retire(false /* fill_up */);
 200   assert(_alloc_region == _dummy_region,
 201          ar_ext_msg(this, "post-condition of retire()"));
 202   _alloc_region = NULL;
 203   trace("released");
 204   return (alloc_region == _dummy_region) ? NULL : alloc_region;
 205 }
 206 
 207 #if G1_ALLOC_REGION_TRACING
 208 void G1AllocRegion::trace(const char* str, size_t min_word_size, size_t desired_word_size, size_t actual_word_size, HeapWord* result) {
 209   // All the calls to trace that set either just the size or the size
 210   // and the result are considered part of level 2 tracing and are
 211   // skipped during level 1 tracing.
 212   if ((actual_word_size == 0 && result == NULL) || (G1_ALLOC_REGION_TRACING > 1)) {
 213     const size_t buffer_length = 128;
 214     char hr_buffer[buffer_length];
 215     char rest_buffer[buffer_length];
 216 
 217     HeapRegion* alloc_region = _alloc_region;
 218     if (alloc_region == NULL) {
 219       jio_snprintf(hr_buffer, buffer_length, "NULL");
 220     } else if (alloc_region == _dummy_region) {
 221       jio_snprintf(hr_buffer, buffer_length, "DUMMY");




  74       // If the allocation was successful we should fill in the space.
  75       CollectedHeap::fill_with_object(dummy, free_word_size);
  76       alloc_region->set_pre_dummy_top(dummy);
  77       result += free_word_size * HeapWordSize;
  78       break;
  79     }
  80 
  81     free_word_size = alloc_region->free() / HeapWordSize;
  82     // It's also possible that someone else beats us to the
  83     // allocation and they fill up the region. In that case, we can
  84     // just get out of the loop.
  85   }
  86   result += alloc_region->free();
  87 
  88   assert(alloc_region->free() / HeapWordSize < min_word_size_to_fill,
  89          "post-condition");
  90   return result;
  91 }
  92 
  93 size_t G1AllocRegion::retire(bool fill_up) {
  94   assert(_alloc_region != NULL, G1_ALLOC_REGION_MSG("not initialized properly"));
  95 
  96   size_t result = 0;
  97 
  98   trace("retiring");
  99   HeapRegion* alloc_region = _alloc_region;
 100   if (alloc_region != _dummy_region) {
 101     // We never have to check whether the active region is empty or not,
 102     // and potentially free it if it is, given that it's guaranteed that
 103     // it will never be empty.
 104     assert(!alloc_region->is_empty(),
 105            G1_ALLOC_REGION_MSG("the alloc region should never be empty"));
 106 
 107     if (fill_up) {
 108       result = fill_up_remaining_space(alloc_region, _bot_updates);
 109     }
 110 
 111     assert(alloc_region->used() >= _used_bytes_before,
 112            G1_ALLOC_REGION_MSG("invariant"));
 113     size_t allocated_bytes = alloc_region->used() - _used_bytes_before;
 114     retire_region(alloc_region, allocated_bytes);
 115     _used_bytes_before = 0;
 116     _alloc_region = _dummy_region;
 117   }
 118   trace("retired");
 119 
 120   return result;
 121 }
 122 
 123 HeapWord* G1AllocRegion::new_alloc_region_and_allocate(size_t word_size,
 124                                                        bool force) {
 125   assert(_alloc_region == _dummy_region, G1_ALLOC_REGION_MSG("pre-condition"));
 126   assert(_used_bytes_before == 0, G1_ALLOC_REGION_MSG("pre-condition"));
 127 
 128   trace("attempting region allocation");
 129   HeapRegion* new_alloc_region = allocate_new_region(word_size, force);
 130   if (new_alloc_region != NULL) {
 131     new_alloc_region->reset_pre_dummy_top();
 132     // Need to do this before the allocation
 133     _used_bytes_before = new_alloc_region->used();
 134     HeapWord* result = allocate(new_alloc_region, word_size, _bot_updates);
 135     assert(result != NULL, G1_ALLOC_REGION_MSG("the allocation should succeeded"));
 136 
 137     OrderAccess::storestore();
 138     // Note that we first perform the allocation and then we store the
 139     // region in _alloc_region. This is the reason why an active region
 140     // can never be empty.
 141     update_alloc_region(new_alloc_region);
 142     trace("region allocation successful");
 143     return result;
 144   } else {
 145     trace("region allocation failed");
 146     return NULL;
 147   }
 148   ShouldNotReachHere();
 149 }
 150 






 151 void G1AllocRegion::init() {
 152   trace("initializing");
 153   assert(_alloc_region == NULL && _used_bytes_before == 0,
 154          G1_ALLOC_REGION_MSG("pre-condition"));
 155   assert(_dummy_region != NULL, G1_ALLOC_REGION_MSG("should have been set"));
 156   _alloc_region = _dummy_region;
 157   _count = 0;
 158   trace("initialized");
 159 }
 160 
 161 void G1AllocRegion::set(HeapRegion* alloc_region) {
 162   trace("setting");
 163   // We explicitly check that the region is not empty to make sure we
 164   // maintain the "the alloc region cannot be empty" invariant.
 165   assert(alloc_region != NULL && !alloc_region->is_empty(),
 166          G1_ALLOC_REGION_MSG("pre-condition"));
 167   assert(_alloc_region == _dummy_region &&
 168          _used_bytes_before == 0 && _count == 0,
 169          G1_ALLOC_REGION_MSG("pre-condition"));
 170 
 171   _used_bytes_before = alloc_region->used();
 172   _alloc_region = alloc_region;
 173   _count += 1;
 174   trace("set");
 175 }
 176 
 177 void G1AllocRegion::update_alloc_region(HeapRegion* alloc_region) {
 178   trace("update");
 179   // We explicitly check that the region is not empty to make sure we
 180   // maintain the "the alloc region cannot be empty" invariant.
 181   assert(alloc_region != NULL && !alloc_region->is_empty(),
 182          G1_ALLOC_REGION_MSG("pre-condition"));
 183 
 184   _alloc_region = alloc_region;
 185   _alloc_region->set_allocation_context(allocation_context());
 186   _count += 1;
 187   trace("updated");
 188 }
 189 
 190 HeapRegion* G1AllocRegion::release() {
 191   trace("releasing");
 192   HeapRegion* alloc_region = _alloc_region;
 193   retire(false /* fill_up */);
 194   assert(_alloc_region == _dummy_region,
 195          G1_ALLOC_REGION_MSG("post-condition of retire()"));
 196   _alloc_region = NULL;
 197   trace("released");
 198   return (alloc_region == _dummy_region) ? NULL : alloc_region;
 199 }
 200 
 201 #if G1_ALLOC_REGION_TRACING
 202 void G1AllocRegion::trace(const char* str, size_t min_word_size, size_t desired_word_size, size_t actual_word_size, HeapWord* result) {
 203   // All the calls to trace that set either just the size or the size
 204   // and the result are considered part of level 2 tracing and are
 205   // skipped during level 1 tracing.
 206   if ((actual_word_size == 0 && result == NULL) || (G1_ALLOC_REGION_TRACING > 1)) {
 207     const size_t buffer_length = 128;
 208     char hr_buffer[buffer_length];
 209     char rest_buffer[buffer_length];
 210 
 211     HeapRegion* alloc_region = _alloc_region;
 212     if (alloc_region == NULL) {
 213       jio_snprintf(hr_buffer, buffer_length, "NULL");
 214     } else if (alloc_region == _dummy_region) {
 215       jio_snprintf(hr_buffer, buffer_length, "DUMMY");


< prev index next >