Esempio n. 1
0
MemRegion HeapRegionSeq::shrink_by(size_t shrink_bytes,
                                   size_t& num_regions_deleted) {
  assert(shrink_bytes % os::vm_page_size() == 0, "unaligned");
  assert(shrink_bytes % HeapRegion::GrainBytes == 0, "unaligned");

  if (_regions.length() == 0) {
    num_regions_deleted = 0;
    return MemRegion();
  }
  int j = _regions.length() - 1;
  HeapWord* end = _regions.at(j)->end();
  HeapWord* last_start = end;
  while (j >= 0 && shrink_bytes > 0) {
    HeapRegion* cur = _regions.at(j);
    // We have to leave humongous regions where they are,
    // and work around them.
    if (cur->isHumongous()) {
      return MemRegion(last_start, end);
    }
    cur->reset_zero_fill();
    assert(cur == _regions.top(), "Should be top");
    if (!cur->is_empty()) break;
    shrink_bytes -= cur->capacity();
    num_regions_deleted++;
    _regions.pop();
    last_start = cur->bottom();
    // We need to delete these somehow, but can't currently do so here: if
    // we do, the ZF thread may still access the deleted region.  We'll
    // leave this here as a reminder that we have to do something about
    // this.
    // delete cur;
    j--;
  }
  return MemRegion(last_start, end);
}
Esempio n. 2
0
HeapWord*
HeapRegionSeq::alloc_obj_from_region_index(int ind, size_t word_size) {
  assert(G1CollectedHeap::isHumongous(word_size),
         "Allocation size should be humongous");
  int cur = ind;
  int first = cur;
  size_t sumSizes = 0;
  while (cur < _regions.length() && sumSizes < word_size) {
    // Loop invariant:
    //  For all i in [first, cur):
    //       _regions.at(i)->is_empty()
    //    && _regions.at(i) is contiguous with its predecessor, if any
    //  && sumSizes is the sum of the sizes of the regions in the interval
    //       [first, cur)
    HeapRegion* curhr = _regions.at(cur);
    if (curhr->is_empty()
        && (first == cur
            || (_regions.at(cur-1)->end() ==
                curhr->bottom()))) {
      sumSizes += curhr->capacity() / HeapWordSize;
    } else {
      first = cur + 1;
      sumSizes = 0;
    }
    cur++;
  }
  if (sumSizes >= word_size) {
    _alloc_search_start = cur;
    // Mark the allocated regions as allocated.
    bool zf = G1CollectedHeap::heap()->allocs_are_zero_filled();
    HeapRegion* first_hr = _regions.at(first);
    for (int i = first; i < cur; i++) {
      HeapRegion* hr = _regions.at(i);
      if (zf)
        hr->ensure_zero_filled();
      {
        MutexLockerEx x(ZF_mon, Mutex::_no_safepoint_check_flag);
        hr->set_zero_fill_allocated();
      }
      size_t sz = hr->capacity() / HeapWordSize;
      HeapWord* tmp = hr->allocate(sz);
      assert(tmp != NULL, "Humongous allocation failure");
      MemRegion mr = MemRegion(tmp, sz);
      CollectedHeap::fill_with_object(mr);
      hr->declare_filled_region_to_BOT(mr);
      if (i == first) {
        first_hr->set_startsHumongous();
      } else {
        assert(i > first, "sanity");
        hr->set_continuesHumongous(first_hr);
      }
    }
    HeapWord* first_hr_bot = first_hr->bottom();
    HeapWord* obj_end = first_hr_bot + word_size;
    first_hr->set_top(obj_end);
    return first_hr_bot;
  } else {
    // If we started from the beginning, we want to know why we can't alloc.
    return NULL;
  }
}