hotspot/src/share/vm/gc_implementation/g1/g1AllocRegion.cpp
changeset 10243 d00a21009f1f
parent 8928 e5c53268bef5
child 12381 1438e0fbfa27
equal deleted inserted replaced
10242:ec32bf88801c 10243:d00a21009f1f
   127     OrderAccess::storestore();
   127     OrderAccess::storestore();
   128     // Note that we first perform the allocation and then we store the
   128     // Note that we first perform the allocation and then we store the
   129     // region in _alloc_region. This is the reason why an active region
   129     // region in _alloc_region. This is the reason why an active region
   130     // can never be empty.
   130     // can never be empty.
   131     _alloc_region = new_alloc_region;
   131     _alloc_region = new_alloc_region;
       
   132     _count += 1;
   132     trace("region allocation successful");
   133     trace("region allocation successful");
   133     return result;
   134     return result;
   134   } else {
   135   } else {
   135     trace("region allocation failed");
   136     trace("region allocation failed");
   136     return NULL;
   137     return NULL;
   137   }
   138   }
   138   ShouldNotReachHere();
   139   ShouldNotReachHere();
   139 }
   140 }
   140 
   141 
   141 void G1AllocRegion::fill_in_ext_msg(ar_ext_msg* msg, const char* message) {
   142 void G1AllocRegion::fill_in_ext_msg(ar_ext_msg* msg, const char* message) {
   142   msg->append("[%s] %s b: %s r: "PTR_FORMAT" u: "SIZE_FORMAT,
   143   msg->append("[%s] %s c: "SIZE_FORMAT" b: %s r: "PTR_FORMAT" u: "SIZE_FORMAT,
   143               _name, message, BOOL_TO_STR(_bot_updates),
   144               _name, message, _count, BOOL_TO_STR(_bot_updates),
   144               _alloc_region, _used_bytes_before);
   145               _alloc_region, _used_bytes_before);
   145 }
   146 }
   146 
   147 
   147 void G1AllocRegion::init() {
   148 void G1AllocRegion::init() {
   148   trace("initializing");
   149   trace("initializing");
   149   assert(_alloc_region == NULL && _used_bytes_before == 0,
   150   assert(_alloc_region == NULL && _used_bytes_before == 0,
   150          ar_ext_msg(this, "pre-condition"));
   151          ar_ext_msg(this, "pre-condition"));
   151   assert(_dummy_region != NULL, "should have been set");
   152   assert(_dummy_region != NULL, ar_ext_msg(this, "should have been set"));
   152   _alloc_region = _dummy_region;
   153   _alloc_region = _dummy_region;
       
   154   _count = 0;
   153   trace("initialized");
   155   trace("initialized");
       
   156 }
       
   157 
       
   158 void G1AllocRegion::set(HeapRegion* alloc_region) {
       
   159   trace("setting");
       
   160   // We explicitly check that the region is not empty to make sure we
       
   161   // maintain the "the alloc region cannot be empty" invariant.
       
   162   assert(alloc_region != NULL && !alloc_region->is_empty(),
       
   163          ar_ext_msg(this, "pre-condition"));
       
   164   assert(_alloc_region == _dummy_region &&
       
   165          _used_bytes_before == 0 && _count == 0,
       
   166          ar_ext_msg(this, "pre-condition"));
       
   167 
       
   168   _used_bytes_before = alloc_region->used();
       
   169   _alloc_region = alloc_region;
       
   170   _count += 1;
       
   171   trace("set");
   154 }
   172 }
   155 
   173 
   156 HeapRegion* G1AllocRegion::release() {
   174 HeapRegion* G1AllocRegion::release() {
   157   trace("releasing");
   175   trace("releasing");
   158   HeapRegion* alloc_region = _alloc_region;
   176   HeapRegion* alloc_region = _alloc_region;
   159   retire(false /* fill_up */);
   177   retire(false /* fill_up */);
   160   assert(_alloc_region == _dummy_region, "post-condition of retire()");
   178   assert(_alloc_region == _dummy_region,
       
   179          ar_ext_msg(this, "post-condition of retire()"));
   161   _alloc_region = NULL;
   180   _alloc_region = NULL;
   162   trace("released");
   181   trace("released");
   163   return (alloc_region == _dummy_region) ? NULL : alloc_region;
   182   return (alloc_region == _dummy_region) ? NULL : alloc_region;
   164 }
   183 }
   165 
   184 
   194       }
   213       }
   195     } else {
   214     } else {
   196       jio_snprintf(rest_buffer, buffer_length, "");
   215       jio_snprintf(rest_buffer, buffer_length, "");
   197     }
   216     }
   198 
   217 
   199     tty->print_cr("[%s] %s : %s %s", _name, hr_buffer, str, rest_buffer);
   218     tty->print_cr("[%s] "SIZE_FORMAT" %s : %s %s",
       
   219                   _name, _count, hr_buffer, str, rest_buffer);
   200   }
   220   }
   201 }
   221 }
   202 #endif // G1_ALLOC_REGION_TRACING
   222 #endif // G1_ALLOC_REGION_TRACING
   203 
   223 
   204 G1AllocRegion::G1AllocRegion(const char* name,
   224 G1AllocRegion::G1AllocRegion(const char* name,
   205                              bool bot_updates)
   225                              bool bot_updates)
   206   : _name(name), _bot_updates(bot_updates),
   226   : _name(name), _bot_updates(bot_updates),
   207     _alloc_region(NULL), _used_bytes_before(0) { }
   227     _alloc_region(NULL), _count(0), _used_bytes_before(0) { }
   208 
   228