src/hotspot/share/gc/shared/memAllocator.hpp
author coleenp
Thu, 10 Jan 2019 15:13:51 -0500
changeset 53244 9807daeb47c4
parent 51945 c573d2633417
child 54784 31b27600b5db
permissions -rw-r--r--
8216167: Update include guards to reflect correct directories Summary: Use script and some manual fixup to fix directores names in include guards. Reviewed-by: lfoltan, eosterlund, kbarrett
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50882
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
     1
/*
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 51945
diff changeset
     2
 * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
50882
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
     4
 *
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
     7
 * published by the Free Software Foundation.
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
     8
 *
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    13
 * accompanied this code).
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    14
 *
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    18
 *
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    21
 * questions.
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    22
 *
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    23
 */
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    24
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 51945
diff changeset
    25
#ifndef SHARE_GC_SHARED_MEMALLOCATOR_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 51945
diff changeset
    26
#define SHARE_GC_SHARED_MEMALLOCATOR_HPP
50882
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    27
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    28
#include "gc/shared/collectedHeap.hpp"
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    29
#include "memory/memRegion.hpp"
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    30
#include "oops/oopsHierarchy.hpp"
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    31
#include "utilities/exceptions.hpp"
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    32
#include "utilities/macros.hpp"
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    33
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    34
// These fascilities are used for allocating, and initializing newly allocated objects.
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    35
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    36
class MemAllocator: StackObj {
51945
c573d2633417 8211269: Make declaration of Allocation protected in MemAllocator
rkennke
parents: 50882
diff changeset
    37
protected:
50882
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    38
  class Allocation;
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    39
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    40
  CollectedHeap* const _heap;
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    41
  Thread* const        _thread;
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    42
  Klass* const         _klass;
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    43
  const size_t         _word_size;
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    44
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    45
private:
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    46
  // Allocate from the current thread's TLAB, with broken-out slow path.
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    47
  HeapWord* allocate_inside_tlab(Allocation& allocation) const;
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    48
  HeapWord* allocate_inside_tlab_slow(Allocation& allocation) const;
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    49
  HeapWord* allocate_outside_tlab(Allocation& allocation) const;
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    50
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    51
protected:
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    52
  MemAllocator(Klass* klass, size_t word_size, Thread* thread)
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    53
    : _heap(Universe::heap()),
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    54
      _thread(thread),
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    55
      _klass(klass),
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    56
      _word_size(word_size)
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    57
  { }
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    58
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    59
  // This function clears the memory of the object
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    60
  void mem_clear(HeapWord* mem) const;
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    61
  // This finish constructing an oop by installing the mark word and the Klass* pointer
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    62
  // last. At the point when the Klass pointer is initialized, this is a constructed object
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    63
  // that must be parseable as an oop by concurrent collectors.
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    64
  oop finish(HeapWord* mem) const;
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    65
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    66
  // Raw memory allocation. This may or may not use TLAB allocations to satisfy the
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    67
  // allocation. A GC implementation may override this function to satisfy the allocation
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    68
  // in any way. But the default is to try a TLAB allocation, and otherwise perform
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    69
  // mem_allocate.
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    70
  virtual HeapWord* mem_allocate(Allocation& allocation) const;
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    71
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    72
  virtual MemRegion obj_memory_range(oop obj) const {
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    73
    return MemRegion((HeapWord*)obj, _word_size);
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    74
  }
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    75
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    76
public:
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    77
  oop allocate() const;
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    78
  virtual oop initialize(HeapWord* mem) const = 0;
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    79
};
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    80
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    81
class ObjAllocator: public MemAllocator {
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    82
public:
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    83
  ObjAllocator(Klass* klass, size_t word_size, Thread* thread = Thread::current())
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    84
    : MemAllocator(klass, word_size, thread) {}
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    85
  virtual oop initialize(HeapWord* mem) const;
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    86
};
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    87
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    88
class ObjArrayAllocator: public MemAllocator {
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    89
  const int  _length;
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    90
  const bool _do_zero;
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    91
protected:
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    92
  virtual MemRegion obj_memory_range(oop obj) const;
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    93
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    94
public:
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    95
  ObjArrayAllocator(Klass* klass, size_t word_size, int length, bool do_zero,
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    96
                    Thread* thread = Thread::current())
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    97
    : MemAllocator(klass, word_size, thread),
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    98
      _length(length),
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    99
      _do_zero(do_zero) {}
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
   100
  virtual oop initialize(HeapWord* mem) const;
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
   101
};
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
   102
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
   103
class ClassAllocator: public MemAllocator {
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
   104
public:
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
   105
  ClassAllocator(Klass* klass, size_t word_size, Thread* thread = Thread::current())
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
   106
    : MemAllocator(klass, word_size, thread) {}
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
   107
  virtual oop initialize(HeapWord* mem) const;
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
   108
};
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
   109
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 51945
diff changeset
   110
#endif // SHARE_GC_SHARED_MEMALLOCATOR_HPP