Top


定義場所(file name)

hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp

名前(function name)

HeapRegion* G1CollectedHeap::new_region(size_t word_size, bool do_expand) {

本体部(body)

  {- -------------------------------------------
  (1) (assert)
      ---------------------------------------- -}

      assert(!isHumongous(word_size) ||
                                      word_size <= (size_t) HeapRegion::GrainWords,
             "the only time we use this to allocate a humongous region is "
             "when we are allocating a single humongous region");

  {- -------------------------------------------
  (1) (変数宣言など)
      ---------------------------------------- -}

      HeapRegion* res;

  {- -------------------------------------------
  (1) (デバッグ用の処理) (develop オプションである G1StressConcRegionFreeing がセットされている場合にのみ実行)
      ---------------------------------------- -}

      if (G1StressConcRegionFreeing) {
        if (!_secondary_free_list.is_empty()) {
          if (G1ConcRegionFreeingVerbose) {
            gclog_or_tty->print_cr("G1ConcRegionFreeing [region alloc] : "
                                   "forced to look at the secondary_free_list");
          }
          res = new_region_try_secondary_free_list();
          if (res != NULL) {
            return res;
          }
        }
      }

  {- -------------------------------------------
  (1) HeapRegionLinkedList::remove_head_or_null() を呼んで, 
      MasterFreeRegionList からの確保を試みる.
      ---------------------------------------- -}

      res = _free_list.remove_head_or_null();

  {- -------------------------------------------
  (1) もし確保が失敗したら, 
      G1CollectedHeap::new_region_try_secondary_free_list() を呼んで
      SecondaryFreeRegionList からの確保を試みる.

      (ついでに(トレース出力)も出している)
      ---------------------------------------- -}

      if (res == NULL) {
        if (G1ConcRegionFreeingVerbose) {
          gclog_or_tty->print_cr("G1ConcRegionFreeing [region alloc] : "
                                 "res == NULL, trying the secondary_free_list");
        }
        res = new_region_try_secondary_free_list();
      }

  {- -------------------------------------------
  (1) それでも確保が失敗し, かつ失敗時にはヒープを拡張してもいいことになっていれば (= do_expand 引数が true であれば), 
      G1CollectedHeap::expand() を呼んでヒープの拡張を試みる.
      拡張が成功すれば, HeapRegionLinkedList::remove_head() を呼んで
      MasterFreeRegionList から HeapRegion を確保する.

      (拡張が失敗した場合は, 確保は諦める)
      ---------------------------------------- -}

      if (res == NULL && do_expand) {
        if (expand(word_size * HeapWordSize)) {
          // The expansion succeeded and so we should have at least one
          // region on the free list.
          res = _free_list.remove_head();
        }
      }

  {- -------------------------------------------
  (1) (トレース出力)
      ---------------------------------------- -}

      if (res != NULL) {
        if (G1PrintHeapRegions) {
          gclog_or_tty->print_cr("new alloc region %d:["PTR_FORMAT","PTR_FORMAT"], "
                                 "top "PTR_FORMAT, res->hrs_index(),
                                 res->bottom(), res->end(), res->top());
        }
      }

  {- -------------------------------------------
  (1) 結果をリターン
      ---------------------------------------- -}

      return res;
    }

This document is available under the GNU GENERAL PUBLIC LICENSE Version 2.