src/hotspot/share/gc/shared/memAllocator.hpp
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 57852 92f994585e25
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
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
  Thread* const        _thread;
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    41
  Klass* const         _klass;
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    42
  const size_t         _word_size;
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    43
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    44
private:
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    45
  // Allocate from the current thread's TLAB, with broken-out slow path.
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    46
  HeapWord* allocate_inside_tlab(Allocation& allocation) const;
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    47
  HeapWord* allocate_inside_tlab_slow(Allocation& allocation) const;
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    48
  HeapWord* allocate_outside_tlab(Allocation& allocation) const;
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    49
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    50
protected:
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    51
  MemAllocator(Klass* klass, size_t word_size, Thread* thread)
54784
31b27600b5db 8223622: Move Universe usage out of memAllocator.hpp
stefank
parents: 53244
diff changeset
    52
    : _thread(thread),
50882
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    53
      _klass(klass),
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    54
      _word_size(word_size)
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    55
  { }
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    56
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    57
  // This function clears the memory of the object
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    58
  void mem_clear(HeapWord* mem) const;
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    59
  // 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
    60
  // 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
    61
  // that must be parseable as an oop by concurrent collectors.
57850
b2b77f6922dc 8227226: ZGC: Segmented array clearing
pliden
parents: 54784
diff changeset
    62
  virtual oop finish(HeapWord* mem) const;
50882
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    63
57852
92f994585e25 8229127: Make some methods in the allocation path non-virtual
pliden
parents: 57850
diff changeset
    64
  // Raw memory allocation. This will try to do a TLAB allocation, and otherwise fall
92f994585e25 8229127: Make some methods in the allocation path non-virtual
pliden
parents: 57850
diff changeset
    65
  // back to calling CollectedHeap::mem_allocate().
92f994585e25 8229127: Make some methods in the allocation path non-virtual
pliden
parents: 57850
diff changeset
    66
  HeapWord* mem_allocate(Allocation& allocation) const;
50882
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    67
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    68
  virtual MemRegion obj_memory_range(oop obj) const {
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    69
    return MemRegion((HeapWord*)obj, _word_size);
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    70
  }
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
public:
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    73
  oop allocate() const;
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    74
  virtual oop initialize(HeapWord* mem) const = 0;
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
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    77
class ObjAllocator: public MemAllocator {
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    78
public:
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    79
  ObjAllocator(Klass* klass, size_t word_size, Thread* thread = Thread::current())
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    80
    : MemAllocator(klass, word_size, thread) {}
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    81
  virtual oop initialize(HeapWord* mem) const;
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    82
};
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    83
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    84
class ObjArrayAllocator: public MemAllocator {
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    85
  const int  _length;
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    86
  const bool _do_zero;
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    87
protected:
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    88
  virtual MemRegion obj_memory_range(oop obj) const;
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    89
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    90
public:
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    91
  ObjArrayAllocator(Klass* klass, size_t word_size, int length, bool do_zero,
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    92
                    Thread* thread = Thread::current())
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    93
    : MemAllocator(klass, word_size, thread),
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    94
      _length(length),
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    95
      _do_zero(do_zero) {}
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    96
  virtual oop initialize(HeapWord* mem) const;
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    97
};
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    98
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
    99
class ClassAllocator: public MemAllocator {
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
   100
public:
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
   101
  ClassAllocator(Klass* klass, size_t word_size, Thread* thread = Thread::current())
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
   102
    : MemAllocator(klass, word_size, thread) {}
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
   103
  virtual oop initialize(HeapWord* mem) const;
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
   104
};
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff changeset
   105
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 51945
diff changeset
   106
#endif // SHARE_GC_SHARED_MEMALLOCATOR_HPP