Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/jfr/leakprofiler/utilities/saveRestore.cpp
41155 views
1
/*
2
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*
23
*/
24
25
#include "precompiled.hpp"
26
#include "classfile/classLoaderDataGraph.hpp"
27
#include "jfr/leakprofiler/utilities/saveRestore.hpp"
28
#include "oops/oop.inline.hpp"
29
30
MarkWordContext::MarkWordContext() : _obj(NULL), _mark_word(markWord::zero()) {}
31
32
MarkWordContext::MarkWordContext(const oop obj) : _obj(obj), _mark_word(obj->mark()) {
33
assert(_obj->mark() == _mark_word, "invariant");
34
// now we will "poison" the mark word of the object
35
// to the intermediate monitor INFLATING state.
36
// This is an "impossible" state during a safepoint,
37
// hence we will use it to quickly identify objects
38
// during the reachability search from gc roots.
39
assert(markWord::zero() == markWord::INFLATING(), "invariant");
40
_obj->set_mark(markWord::INFLATING());
41
assert(markWord::zero() == obj->mark(), "invariant");
42
}
43
44
MarkWordContext::~MarkWordContext() {
45
if (_obj != NULL) {
46
_obj->set_mark(_mark_word);
47
assert(_obj->mark() == _mark_word, "invariant");
48
}
49
}
50
51
MarkWordContext::MarkWordContext(const MarkWordContext& rhs) : _obj(NULL), _mark_word(markWord::zero()) {
52
swap(const_cast<MarkWordContext&>(rhs));
53
}
54
55
void MarkWordContext::operator=(MarkWordContext rhs) {
56
swap(rhs);
57
}
58
59
void MarkWordContext::swap(MarkWordContext& rhs) {
60
oop temp_obj = rhs._obj;
61
markWord temp_mark_word = rhs._mark_word;
62
rhs._obj = _obj;
63
rhs._mark_word = _mark_word;
64
_obj = temp_obj;
65
_mark_word = temp_mark_word;
66
}
67
68
CLDClaimContext::CLDClaimContext() : _cld(NULL) {}
69
70
CLDClaimContext::CLDClaimContext(ClassLoaderData* cld) : _cld(cld) {
71
assert(_cld->claimed(), "invariant");
72
_cld->clear_claim();
73
}
74
75
CLDClaimContext::~CLDClaimContext() {
76
if (_cld != NULL) {
77
_cld->try_claim(ClassLoaderData::_claim_strong);
78
assert(_cld->claimed(), "invariant");
79
}
80
}
81
82
CLDClaimContext::CLDClaimContext(const CLDClaimContext& rhs) : _cld(NULL) {
83
swap(const_cast<CLDClaimContext&>(rhs));
84
}
85
86
void CLDClaimContext::operator=(CLDClaimContext rhs) {
87
swap(rhs);
88
}
89
90
void CLDClaimContext::swap(CLDClaimContext& rhs) {
91
ClassLoaderData* temp_cld = rhs._cld;
92
rhs._cld = _cld;
93
_cld = temp_cld;
94
}
95
96
CLDClaimStateClosure::CLDClaimStateClosure() : CLDClosure(), _state() {}
97
98
void CLDClaimStateClosure::do_cld(ClassLoaderData* cld) {
99
assert(cld != NULL, "invariant");
100
if (cld->claimed()) {
101
_state.save(cld);
102
}
103
}
104
105
SaveRestoreCLDClaimBits::SaveRestoreCLDClaimBits() : _claim_state_closure() {
106
// interferes with GC, so walk all oops that GC would.
107
ClassLoaderDataGraph::cld_do(&_claim_state_closure);
108
}
109
110
SaveRestoreCLDClaimBits::~SaveRestoreCLDClaimBits() {
111
ClassLoaderDataGraph::clear_claimed_marks();
112
}
113
114