Top


定義場所(file name)

hotspot/src/share/vm/memory/space.cpp

説明(description)

// This version requires locking.

名前(function name)

inline HeapWord* ContiguousSpace::allocate_impl(size_t size,
                                                HeapWord* const end_value) {

本体部(body)

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

      // In G1 there are places where a GC worker can allocates into a
      // region using this serial allocation code without being prone to a
      // race with other GC workers (we ensure that no other GC worker can
      // access the same region at the same time). So the assert below is
      // too strong in the case of G1.
      assert(Heap_lock->owned_by_self() ||
             (SafepointSynchronize::is_at_safepoint() &&
                                   (Thread::current()->is_VM_thread() || UseG1GC)),
             "not locked");

  {- -------------------------------------------
  (1) 空き領域(top と end の差)が size 引数分より小さければ NULL をリターンする.
      そうでなければ, top 位置を size 引数分だけ前進させてメモリを確保し, 結果をリターンする.
      ---------------------------------------- -}

      HeapWord* obj = top();
      if (pointer_delta(end_value, obj) >= size) {
        HeapWord* new_top = obj + size;
        set_top(new_top);
        assert(is_aligned(obj) && is_aligned(new_top), "checking alignment");
        return obj;
      } else {
        return NULL;
      }
    }

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