Mercurial > hg > graal-jvmci-8
annotate src/share/vm/gc_implementation/g1/g1Allocator.hpp @ 24234:ea6f94ab283b default tip
Added tag jvmci-0.36 for changeset 8128b98d4736
author | Gilles Duboscq <gilles.m.duboscq@oracle.com> |
---|---|
date | Mon, 18 Sep 2017 18:49:45 +0200 |
parents | c132be0fb74d |
children |
rev | line source |
---|---|
20404
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
1 /* |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
4 * |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
8 * |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
13 * accompanied this code). |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
14 * |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
18 * |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
21 * questions. |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
22 * |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
23 */ |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
24 |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
25 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1ALLOCATOR_HPP |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
26 #define SHARE_VM_GC_IMPLEMENTATION_G1_G1ALLOCATOR_HPP |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
27 |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
28 #include "gc_implementation/g1/g1AllocationContext.hpp" |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
29 #include "gc_implementation/g1/g1AllocRegion.hpp" |
22901
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
30 #include "gc_implementation/g1/g1InCSetState.hpp" |
20404
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
31 #include "gc_implementation/shared/parGCAllocBuffer.hpp" |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
32 |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
33 // Base class for G1 allocators. |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
34 class G1Allocator : public CHeapObj<mtGC> { |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
35 friend class VMStructs; |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
36 protected: |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
37 G1CollectedHeap* _g1h; |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
38 |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
39 // Outside of GC pauses, the number of bytes used in all regions other |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
40 // than the current allocation region. |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
41 size_t _summary_bytes_used; |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
42 |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
43 public: |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
44 G1Allocator(G1CollectedHeap* heap) : |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
45 _g1h(heap), _summary_bytes_used(0) { } |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
46 |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
47 static G1Allocator* create_allocator(G1CollectedHeap* g1h); |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
48 |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
49 virtual void init_mutator_alloc_region() = 0; |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
50 virtual void release_mutator_alloc_region() = 0; |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
51 |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
52 virtual void init_gc_alloc_regions(EvacuationInfo& evacuation_info) = 0; |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
53 virtual void release_gc_alloc_regions(uint no_of_gc_workers, EvacuationInfo& evacuation_info) = 0; |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
54 virtual void abandon_gc_alloc_regions() = 0; |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
55 |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
56 virtual MutatorAllocRegion* mutator_alloc_region(AllocationContext_t context) = 0; |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
57 virtual SurvivorGCAllocRegion* survivor_gc_alloc_region(AllocationContext_t context) = 0; |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
58 virtual OldGCAllocRegion* old_gc_alloc_region(AllocationContext_t context) = 0; |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
59 virtual size_t used() = 0; |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
60 virtual bool is_retained_old_region(HeapRegion* hr) = 0; |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
61 |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
62 void reuse_retained_old_region(EvacuationInfo& evacuation_info, |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
63 OldGCAllocRegion* old, |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
64 HeapRegion** retained); |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
65 |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
66 size_t used_unlocked() const { |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
67 return _summary_bytes_used; |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
68 } |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
69 |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
70 void increase_used(size_t bytes) { |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
71 _summary_bytes_used += bytes; |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
72 } |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
73 |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
74 void decrease_used(size_t bytes) { |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
75 assert(_summary_bytes_used >= bytes, |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
76 err_msg("invariant: _summary_bytes_used: "SIZE_FORMAT" should be >= bytes: "SIZE_FORMAT, |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
77 _summary_bytes_used, bytes)); |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
78 _summary_bytes_used -= bytes; |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
79 } |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
80 |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
81 void set_used(size_t bytes) { |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
82 _summary_bytes_used = bytes; |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
83 } |
20417 | 84 |
85 virtual HeapRegion* new_heap_region(uint hrs_index, | |
86 G1BlockOffsetSharedArray* sharedOffsetArray, | |
87 MemRegion mr) { | |
88 return new HeapRegion(hrs_index, sharedOffsetArray, mr); | |
89 } | |
20404
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
90 }; |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
91 |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
92 // The default allocator for G1. |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
93 class G1DefaultAllocator : public G1Allocator { |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
94 protected: |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
95 // Alloc region used to satisfy mutator allocation requests. |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
96 MutatorAllocRegion _mutator_alloc_region; |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
97 |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
98 // Alloc region used to satisfy allocation requests by the GC for |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
99 // survivor objects. |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
100 SurvivorGCAllocRegion _survivor_gc_alloc_region; |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
101 |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
102 // Alloc region used to satisfy allocation requests by the GC for |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
103 // old objects. |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
104 OldGCAllocRegion _old_gc_alloc_region; |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
105 |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
106 HeapRegion* _retained_old_gc_alloc_region; |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
107 public: |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
108 G1DefaultAllocator(G1CollectedHeap* heap) : G1Allocator(heap), _retained_old_gc_alloc_region(NULL) { } |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
109 |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
110 virtual void init_mutator_alloc_region(); |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
111 virtual void release_mutator_alloc_region(); |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
112 |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
113 virtual void init_gc_alloc_regions(EvacuationInfo& evacuation_info); |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
114 virtual void release_gc_alloc_regions(uint no_of_gc_workers, EvacuationInfo& evacuation_info); |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
115 virtual void abandon_gc_alloc_regions(); |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
116 |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
117 virtual bool is_retained_old_region(HeapRegion* hr) { |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
118 return _retained_old_gc_alloc_region == hr; |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
119 } |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
120 |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
121 virtual MutatorAllocRegion* mutator_alloc_region(AllocationContext_t context) { |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
122 return &_mutator_alloc_region; |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
123 } |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
124 |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
125 virtual SurvivorGCAllocRegion* survivor_gc_alloc_region(AllocationContext_t context) { |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
126 return &_survivor_gc_alloc_region; |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
127 } |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
128 |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
129 virtual OldGCAllocRegion* old_gc_alloc_region(AllocationContext_t context) { |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
130 return &_old_gc_alloc_region; |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
131 } |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
132 |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
133 virtual size_t used() { |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
134 assert(Heap_lock->owner() != NULL, |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
135 "Should be owned on this thread's behalf."); |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
136 size_t result = _summary_bytes_used; |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
137 |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
138 // Read only once in case it is set to NULL concurrently |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
139 HeapRegion* hr = mutator_alloc_region(AllocationContext::current())->get(); |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
140 if (hr != NULL) { |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
141 result += hr->used(); |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
142 } |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
143 return result; |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
144 } |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
145 }; |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
146 |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
147 class G1ParGCAllocBuffer: public ParGCAllocBuffer { |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
148 private: |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
149 bool _retired; |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
150 |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
151 public: |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
152 G1ParGCAllocBuffer(size_t gclab_word_size); |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
153 virtual ~G1ParGCAllocBuffer() { |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
154 guarantee(_retired, "Allocation buffer has not been retired"); |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
155 } |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
156 |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
157 virtual void set_buf(HeapWord* buf) { |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
158 ParGCAllocBuffer::set_buf(buf); |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
159 _retired = false; |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
160 } |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
161 |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
162 virtual void retire(bool end_of_gc, bool retain) { |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
163 if (_retired) { |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
164 return; |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
165 } |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
166 ParGCAllocBuffer::retire(end_of_gc, retain); |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
167 _retired = true; |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
168 } |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
169 }; |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
170 |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
171 class G1ParGCAllocator : public CHeapObj<mtGC> { |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
172 friend class G1ParScanThreadState; |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
173 protected: |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
174 G1CollectedHeap* _g1h; |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
175 |
22901
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
176 // The survivor alignment in effect in bytes. |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
177 // == 0 : don't align survivors |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
178 // != 0 : align survivors to that alignment |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
179 // These values were chosen to favor the non-alignment case since some |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
180 // architectures have a special compare against zero instructions. |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
181 const uint _survivor_alignment_bytes; |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
182 |
20404
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
183 size_t _alloc_buffer_waste; |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
184 size_t _undo_waste; |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
185 |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
186 void add_to_alloc_buffer_waste(size_t waste) { _alloc_buffer_waste += waste; } |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
187 void add_to_undo_waste(size_t waste) { _undo_waste += waste; } |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
188 |
22901
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
189 virtual void retire_alloc_buffers() = 0; |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
190 virtual G1ParGCAllocBuffer* alloc_buffer(InCSetState dest, AllocationContext_t context) = 0; |
20404
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
191 |
22901
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
192 // Calculate the survivor space object alignment in bytes. Returns that or 0 if |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
193 // there are no restrictions on survivor alignment. |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
194 static uint calc_survivor_alignment_bytes() { |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
195 assert(SurvivorAlignmentInBytes >= ObjectAlignmentInBytes, "sanity"); |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
196 if (SurvivorAlignmentInBytes == ObjectAlignmentInBytes) { |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
197 // No need to align objects in the survivors differently, return 0 |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
198 // which means "survivor alignment is not used". |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
199 return 0; |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
200 } else { |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
201 assert(SurvivorAlignmentInBytes > 0, "sanity"); |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
202 return SurvivorAlignmentInBytes; |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
203 } |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
204 } |
20404
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
205 |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
206 public: |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
207 G1ParGCAllocator(G1CollectedHeap* g1h) : |
22901
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
208 _g1h(g1h), _survivor_alignment_bytes(calc_survivor_alignment_bytes()), |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
209 _alloc_buffer_waste(0), _undo_waste(0) { |
20404
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
210 } |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
211 |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
212 static G1ParGCAllocator* create_allocator(G1CollectedHeap* g1h); |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
213 |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
214 size_t alloc_buffer_waste() { return _alloc_buffer_waste; } |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
215 size_t undo_waste() {return _undo_waste; } |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
216 |
22901
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
217 // Allocate word_sz words in dest, either directly into the regions or by |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
218 // allocating a new PLAB. Returns the address of the allocated memory, NULL if |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
219 // not successful. |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
220 HeapWord* allocate_direct_or_new_plab(InCSetState dest, |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
221 size_t word_sz, |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
222 AllocationContext_t context); |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
223 |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
224 // Allocate word_sz words in the PLAB of dest. Returns the address of the |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
225 // allocated memory, NULL if not successful. |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
226 HeapWord* plab_allocate(InCSetState dest, |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
227 size_t word_sz, |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
228 AllocationContext_t context) { |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
229 G1ParGCAllocBuffer* buffer = alloc_buffer(dest, context); |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
230 if (_survivor_alignment_bytes == 0) { |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
231 return buffer->allocate(word_sz); |
20404
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
232 } else { |
22901
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
233 return buffer->allocate_aligned(word_sz, _survivor_alignment_bytes); |
20404
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
234 } |
22901
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
235 } |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
236 |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
237 HeapWord* allocate(InCSetState dest, size_t word_sz, |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
238 AllocationContext_t context) { |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
239 HeapWord* const obj = plab_allocate(dest, word_sz, context); |
20404
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
240 if (obj != NULL) { |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
241 return obj; |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
242 } |
22901
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
243 return allocate_direct_or_new_plab(dest, word_sz, context); |
20404
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
244 } |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
245 |
22901
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
246 void undo_allocation(InCSetState dest, HeapWord* obj, size_t word_sz, AllocationContext_t context) { |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
247 if (alloc_buffer(dest, context)->contains(obj)) { |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
248 assert(alloc_buffer(dest, context)->contains(obj + word_sz - 1), |
20404
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
249 "should contain whole object"); |
22901
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
250 alloc_buffer(dest, context)->undo_allocation(obj, word_sz); |
20404
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
251 } else { |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
252 CollectedHeap::fill_with_object(obj, word_sz); |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
253 add_to_undo_waste(word_sz); |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
254 } |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
255 } |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
256 }; |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
257 |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
258 class G1DefaultParGCAllocator : public G1ParGCAllocator { |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
259 G1ParGCAllocBuffer _surviving_alloc_buffer; |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
260 G1ParGCAllocBuffer _tenured_alloc_buffer; |
22901
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
261 G1ParGCAllocBuffer* _alloc_buffers[InCSetState::Num]; |
20404
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
262 |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
263 public: |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
264 G1DefaultParGCAllocator(G1CollectedHeap* g1h); |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
265 |
22901
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
266 virtual G1ParGCAllocBuffer* alloc_buffer(InCSetState dest, AllocationContext_t context) { |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
267 assert(dest.is_valid(), |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
268 err_msg("Allocation buffer index out-of-bounds: " CSETSTATE_FORMAT, dest.value())); |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
269 assert(_alloc_buffers[dest.value()] != NULL, |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
270 err_msg("Allocation buffer is NULL: " CSETSTATE_FORMAT, dest.value())); |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
20417
diff
changeset
|
271 return _alloc_buffers[dest.value()]; |
20404
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
272 } |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
273 |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
274 virtual void retire_alloc_buffers() ; |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
275 }; |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
276 |
227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff
changeset
|
277 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1ALLOCATOR_HPP |