author | tonyp |
Thu, 07 Apr 2016 10:55:54 +0200 | |
changeset 37422 | 8a7443b5edf8 |
parent 37045 | 41e3f98fa3dc |
child 38080 | bb02a3ad3b0a |
permissions | -rw-r--r-- |
36202
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
1 |
/* |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
4 |
* |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
8 |
* |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
13 |
* accompanied this code). |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
14 |
* |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
18 |
* |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
21 |
* questions. |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
22 |
* |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
23 |
*/ |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
24 |
|
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
25 |
#ifndef SHARE_VM_GC_SHARED_PRESERVEDMARKS_HPP |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
26 |
#define SHARE_VM_GC_SHARED_PRESERVEDMARKS_HPP |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
27 |
|
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
28 |
#include "memory/allocation.hpp" |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
29 |
#include "memory/padded.hpp" |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
30 |
#include "oops/oop.hpp" |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
31 |
#include "utilities/stack.hpp" |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
32 |
|
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
33 |
class OopAndMarkOop { |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
34 |
private: |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
35 |
oop _o; |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
36 |
markOop _m; |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
37 |
|
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
38 |
public: |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
39 |
OopAndMarkOop(oop obj, markOop m) : _o(obj), _m(m) { } |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
40 |
|
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
41 |
void set_mark() const { |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
42 |
_o->set_mark(_m); |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
43 |
} |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
44 |
}; |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
45 |
typedef Stack<OopAndMarkOop, mtGC> OopAndMarkOopStack; |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
46 |
|
37422
8a7443b5edf8
8152312: ParNew: Restore preserved marks in parallel
tonyp
parents:
37045
diff
changeset
|
47 |
class WorkGang; |
8a7443b5edf8
8152312: ParNew: Restore preserved marks in parallel
tonyp
parents:
37045
diff
changeset
|
48 |
|
36202
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
49 |
class PreservedMarks VALUE_OBJ_CLASS_SPEC { |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
50 |
private: |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
51 |
OopAndMarkOopStack _stack; |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
52 |
|
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
53 |
inline bool should_preserve_mark(oop obj, markOop m) const; |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
54 |
inline void push(oop obj, markOop m); |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
55 |
|
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
56 |
public: |
37045
41e3f98fa3dc
8146991: Introduce per-worker preserved mark stacks in ParallelGC
tonyp
parents:
36202
diff
changeset
|
57 |
size_t size() const { return _stack.size(); } |
36202
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
58 |
inline void push_if_necessary(oop obj, markOop m); |
37422
8a7443b5edf8
8152312: ParNew: Restore preserved marks in parallel
tonyp
parents:
37045
diff
changeset
|
59 |
// Iterate over the stack, restore all preserved marks, and |
8a7443b5edf8
8152312: ParNew: Restore preserved marks in parallel
tonyp
parents:
37045
diff
changeset
|
60 |
// reclaim the memory taken up by the stack segments. |
36202
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
61 |
void restore(); |
37422
8a7443b5edf8
8152312: ParNew: Restore preserved marks in parallel
tonyp
parents:
37045
diff
changeset
|
62 |
|
8a7443b5edf8
8152312: ParNew: Restore preserved marks in parallel
tonyp
parents:
37045
diff
changeset
|
63 |
inline static void init_forwarded_mark(oop obj); |
8a7443b5edf8
8152312: ParNew: Restore preserved marks in parallel
tonyp
parents:
37045
diff
changeset
|
64 |
|
8a7443b5edf8
8152312: ParNew: Restore preserved marks in parallel
tonyp
parents:
37045
diff
changeset
|
65 |
// Assert the stack is empty and has no cached segments. |
8a7443b5edf8
8152312: ParNew: Restore preserved marks in parallel
tonyp
parents:
37045
diff
changeset
|
66 |
void assert_empty() PRODUCT_RETURN; |
8a7443b5edf8
8152312: ParNew: Restore preserved marks in parallel
tonyp
parents:
37045
diff
changeset
|
67 |
|
8a7443b5edf8
8152312: ParNew: Restore preserved marks in parallel
tonyp
parents:
37045
diff
changeset
|
68 |
inline PreservedMarks(); |
8a7443b5edf8
8152312: ParNew: Restore preserved marks in parallel
tonyp
parents:
37045
diff
changeset
|
69 |
~PreservedMarks() { assert_empty(); } |
36202
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
70 |
}; |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
71 |
|
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
72 |
class RemoveForwardedPointerClosure: public ObjectClosure { |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
73 |
public: |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
74 |
virtual void do_object(oop obj); |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
75 |
}; |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
76 |
|
37045
41e3f98fa3dc
8146991: Introduce per-worker preserved mark stacks in ParallelGC
tonyp
parents:
36202
diff
changeset
|
77 |
class PreservedMarksSet : public CHeapObj<mtGC> { |
36202
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
78 |
private: |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
79 |
// true -> _stacks will be allocated in the C heap |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
80 |
// false -> _stacks will be allocated in the resource arena |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
81 |
const bool _in_c_heap; |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
82 |
|
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
83 |
// Number of stacks we have allocated (typically, one stack per GC worker). |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
84 |
// This should be >= 1 if the stacks have been initialized, |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
85 |
// or == 0 if they have not. |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
86 |
uint _num; |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
87 |
|
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
88 |
// Stack array (typically, one stack per GC worker) of length _num. |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
89 |
// This should be != NULL if the stacks have been initialized, |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
90 |
// or == NULL if they have not. |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
91 |
Padded<PreservedMarks>* _stacks; |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
92 |
|
37422
8a7443b5edf8
8152312: ParNew: Restore preserved marks in parallel
tonyp
parents:
37045
diff
changeset
|
93 |
// Internal version of restore() that uses a WorkGang for parallelism. |
8a7443b5edf8
8152312: ParNew: Restore preserved marks in parallel
tonyp
parents:
37045
diff
changeset
|
94 |
void restore_internal(WorkGang* workers, volatile size_t* total_size_addr); |
8a7443b5edf8
8152312: ParNew: Restore preserved marks in parallel
tonyp
parents:
37045
diff
changeset
|
95 |
|
36202
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
96 |
public: |
37422
8a7443b5edf8
8152312: ParNew: Restore preserved marks in parallel
tonyp
parents:
37045
diff
changeset
|
97 |
uint num() const { return _num; } |
8a7443b5edf8
8152312: ParNew: Restore preserved marks in parallel
tonyp
parents:
37045
diff
changeset
|
98 |
|
36202
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
99 |
// Return the i'th stack. |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
100 |
PreservedMarks* get(uint i = 0) const { |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
101 |
assert(_num > 0 && _stacks != NULL, "stacks should have been initialized"); |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
102 |
assert(i < _num, "pre-condition"); |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
103 |
return (_stacks + i); |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
104 |
} |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
105 |
|
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
106 |
// Allocate stack array. |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
107 |
void init(uint num); |
37422
8a7443b5edf8
8152312: ParNew: Restore preserved marks in parallel
tonyp
parents:
37045
diff
changeset
|
108 |
|
8a7443b5edf8
8152312: ParNew: Restore preserved marks in parallel
tonyp
parents:
37045
diff
changeset
|
109 |
// Itrerate over all stacks, restore all presered marks, and reclaim |
8a7443b5edf8
8152312: ParNew: Restore preserved marks in parallel
tonyp
parents:
37045
diff
changeset
|
110 |
// the memory taken up by the stack segments. If the executor is |
8a7443b5edf8
8152312: ParNew: Restore preserved marks in parallel
tonyp
parents:
37045
diff
changeset
|
111 |
// NULL, restoration will be done serially. If the executor is not |
8a7443b5edf8
8152312: ParNew: Restore preserved marks in parallel
tonyp
parents:
37045
diff
changeset
|
112 |
// NULL, restoration could be done in parallel (when it makes |
8a7443b5edf8
8152312: ParNew: Restore preserved marks in parallel
tonyp
parents:
37045
diff
changeset
|
113 |
// sense). Supported executors: WorkGang (Serial, CMS, G1) |
8a7443b5edf8
8152312: ParNew: Restore preserved marks in parallel
tonyp
parents:
37045
diff
changeset
|
114 |
template <class E> |
8a7443b5edf8
8152312: ParNew: Restore preserved marks in parallel
tonyp
parents:
37045
diff
changeset
|
115 |
inline void restore(E* executor); |
8a7443b5edf8
8152312: ParNew: Restore preserved marks in parallel
tonyp
parents:
37045
diff
changeset
|
116 |
|
8a7443b5edf8
8152312: ParNew: Restore preserved marks in parallel
tonyp
parents:
37045
diff
changeset
|
117 |
// Do the restoration serially. Temporary, to be used by PS until we |
8a7443b5edf8
8152312: ParNew: Restore preserved marks in parallel
tonyp
parents:
37045
diff
changeset
|
118 |
// can support GCTaskManager in restore(E*). |
36202
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
119 |
void restore(); |
37422
8a7443b5edf8
8152312: ParNew: Restore preserved marks in parallel
tonyp
parents:
37045
diff
changeset
|
120 |
|
36202
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
121 |
// Reclaim stack array. |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
122 |
void reclaim(); |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
123 |
|
37422
8a7443b5edf8
8152312: ParNew: Restore preserved marks in parallel
tonyp
parents:
37045
diff
changeset
|
124 |
// Assert all the stacks are empty and have no cached segments. |
36202
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
125 |
void assert_empty() PRODUCT_RETURN; |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
126 |
|
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
127 |
PreservedMarksSet(bool in_c_heap) |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
128 |
: _in_c_heap(in_c_heap), _num(0), _stacks(NULL) { } |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
129 |
|
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
130 |
~PreservedMarksSet() { |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
131 |
assert(_stacks == NULL && _num == 0, "stacks should have been reclaimed"); |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
132 |
} |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
133 |
}; |
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
134 |
|
219f8808c3bd
8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff
changeset
|
135 |
#endif // SHARE_VM_GC_SHARED_PRESERVEDMARKS_HPP |