< prev index next >

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

Print this page




  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");




  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   G1_ALLOC_REGION_ASSERT(_alloc_region != NULL, "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     G1_ALLOC_REGION_ASSERT(!alloc_region->is_empty(),
 105                            "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     G1_ALLOC_REGION_ASSERT(alloc_region->used() >= _used_bytes_before, "invariant");

 112     size_t allocated_bytes = alloc_region->used() - _used_bytes_before;
 113     retire_region(alloc_region, allocated_bytes);
 114     _used_bytes_before = 0;
 115     _alloc_region = _dummy_region;
 116   }
 117   trace("retired");
 118 
 119   return result;
 120 }
 121 
 122 HeapWord* G1AllocRegion::new_alloc_region_and_allocate(size_t word_size,
 123                                                        bool force) {
 124   G1_ALLOC_REGION_ASSERT(_alloc_region == _dummy_region, "pre-condition");
 125   G1_ALLOC_REGION_ASSERT(_used_bytes_before == 0, "pre-condition");
 126 
 127   trace("attempting region allocation");
 128   HeapRegion* new_alloc_region = allocate_new_region(word_size, force);
 129   if (new_alloc_region != NULL) {
 130     new_alloc_region->reset_pre_dummy_top();
 131     // Need to do this before the allocation
 132     _used_bytes_before = new_alloc_region->used();
 133     HeapWord* result = allocate(new_alloc_region, word_size, _bot_updates);
 134     G1_ALLOC_REGION_ASSERT(result != NULL, "the allocation should succeeded");
 135 
 136     OrderAccess::storestore();
 137     // Note that we first perform the allocation and then we store the
 138     // region in _alloc_region. This is the reason why an active region
 139     // can never be empty.
 140     update_alloc_region(new_alloc_region);
 141     trace("region allocation successful");
 142     return result;
 143   } else {
 144     trace("region allocation failed");
 145     return NULL;
 146   }
 147   ShouldNotReachHere();
 148 }
 149 
 150 void G1AllocRegion::init() {
 151   trace("initializing");
 152   G1_ALLOC_REGION_ASSERT(_alloc_region == NULL && _used_bytes_before == 0, "pre-condition");
 153   G1_ALLOC_REGION_ASSERT(_dummy_region != NULL, "should have been set");

 154   _alloc_region = _dummy_region;
 155   _count = 0;
 156   trace("initialized");
 157 }
 158 
 159 void G1AllocRegion::set(HeapRegion* alloc_region) {
 160   trace("setting");
 161   // We explicitly check that the region is not empty to make sure we
 162   // maintain the "the alloc region cannot be empty" invariant.
 163   G1_ALLOC_REGION_ASSERT(alloc_region != NULL && !alloc_region->is_empty(), "pre-condition");
 164   G1_ALLOC_REGION_ASSERT(_alloc_region == _dummy_region &&

 165                          _used_bytes_before == 0 && _count == 0,
 166                          "pre-condition");
 167 
 168   _used_bytes_before = alloc_region->used();
 169   _alloc_region = alloc_region;
 170   _count += 1;
 171   trace("set");
 172 }
 173 
 174 void G1AllocRegion::update_alloc_region(HeapRegion* alloc_region) {
 175   trace("update");
 176   // We explicitly check that the region is not empty to make sure we
 177   // maintain the "the alloc region cannot be empty" invariant.
 178   G1_ALLOC_REGION_ASSERT(alloc_region != NULL && !alloc_region->is_empty(), "pre-condition");

 179 
 180   _alloc_region = alloc_region;
 181   _alloc_region->set_allocation_context(allocation_context());
 182   _count += 1;
 183   trace("updated");
 184 }
 185 
 186 HeapRegion* G1AllocRegion::release() {
 187   trace("releasing");
 188   HeapRegion* alloc_region = _alloc_region;
 189   retire(false /* fill_up */);
 190   G1_ALLOC_REGION_ASSERT(_alloc_region == _dummy_region, "post-condition of retire()");

 191   _alloc_region = NULL;
 192   trace("released");
 193   return (alloc_region == _dummy_region) ? NULL : alloc_region;
 194 }
 195 
 196 #if G1_ALLOC_REGION_TRACING
 197 void G1AllocRegion::trace(const char* str, size_t min_word_size, size_t desired_word_size, size_t actual_word_size, HeapWord* result) {
 198   // All the calls to trace that set either just the size or the size
 199   // and the result are considered part of level 2 tracing and are
 200   // skipped during level 1 tracing.
 201   if ((actual_word_size == 0 && result == NULL) || (G1_ALLOC_REGION_TRACING > 1)) {
 202     const size_t buffer_length = 128;
 203     char hr_buffer[buffer_length];
 204     char rest_buffer[buffer_length];
 205 
 206     HeapRegion* alloc_region = _alloc_region;
 207     if (alloc_region == NULL) {
 208       jio_snprintf(hr_buffer, buffer_length, "NULL");
 209     } else if (alloc_region == _dummy_region) {
 210       jio_snprintf(hr_buffer, buffer_length, "DUMMY");


< prev index next >