author | pliden |
Fri, 23 Aug 2019 08:48:18 +0200 | |
changeset 57850 | b2b77f6922dc |
parent 54784 | 31b27600b5db |
child 57852 | 92f994585e25 |
permissions | -rw-r--r-- |
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 | 62 |
virtual oop finish(HeapWord* mem) const; |
50882
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
63 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
64 |
// 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
|
65 |
// allocation. A GC implementation may override this function to satisfy the allocation |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
66 |
// 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
|
67 |
// mem_allocate. |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
68 |
virtual HeapWord* mem_allocate(Allocation& allocation) const; |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
69 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
70 |
virtual MemRegion obj_memory_range(oop obj) const { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
71 |
return MemRegion((HeapWord*)obj, _word_size); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
72 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
73 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
74 |
public: |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
75 |
oop allocate() const; |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
76 |
virtual oop initialize(HeapWord* mem) const = 0; |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
77 |
}; |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
78 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
79 |
class ObjAllocator: public MemAllocator { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
80 |
public: |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
81 |
ObjAllocator(Klass* klass, size_t word_size, Thread* thread = Thread::current()) |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
82 |
: MemAllocator(klass, word_size, thread) {} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
83 |
virtual oop initialize(HeapWord* mem) const; |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
84 |
}; |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
85 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
86 |
class ObjArrayAllocator: public MemAllocator { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
87 |
const int _length; |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
88 |
const bool _do_zero; |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
89 |
protected: |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
90 |
virtual MemRegion obj_memory_range(oop obj) const; |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
91 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
92 |
public: |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
93 |
ObjArrayAllocator(Klass* klass, size_t word_size, int length, bool do_zero, |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
94 |
Thread* thread = Thread::current()) |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
95 |
: MemAllocator(klass, word_size, thread), |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
96 |
_length(length), |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
97 |
_do_zero(do_zero) {} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
98 |
virtual oop initialize(HeapWord* mem) const; |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
99 |
}; |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
100 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
101 |
class ClassAllocator: public MemAllocator { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
102 |
public: |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
103 |
ClassAllocator(Klass* klass, size_t word_size, Thread* thread = Thread::current()) |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
104 |
: MemAllocator(klass, word_size, thread) {} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
105 |
virtual oop initialize(HeapWord* mem) const; |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
106 |
}; |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
107 |
|
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
51945
diff
changeset
|
108 |
#endif // SHARE_GC_SHARED_MEMALLOCATOR_HPP |