author | herrick |
Fri, 18 Oct 2019 14:14:37 -0400 | |
branch | JDK-8200758-branch |
changeset 58696 | 61c44899b4eb |
parent 54786 | ebf733a324d4 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
49824
e242740a92b8
8201556: Disallow reading oops in ClassLoaderData if unloading
coleenp
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4576
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4576
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4576
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
26 |
#include "classfile/systemDictionary.hpp" |
|
27 |
#include "memory/allocation.hpp" |
|
37248 | 28 |
#include "memory/resourceArea.hpp" |
7397 | 29 |
#include "oops/oop.inline.hpp" |
30 |
#include "runtime/mutexLocker.hpp" |
|
31 |
#include "services/classLoadingService.hpp" |
|
32 |
#include "services/memoryService.hpp" |
|
33 |
#include "utilities/dtrace.hpp" |
|
15482
470d0b0c09f1
8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents:
13975
diff
changeset
|
34 |
#include "utilities/macros.hpp" |
31371
311143309e73
8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents:
24424
diff
changeset
|
35 |
#include "utilities/defaultStream.hpp" |
35917
463d67f86eaa
8079408: Reimplement TraceClassLoading, TraceClassUnloading, and TraceClassLoaderData with Unified Logging.
mockner
parents:
33611
diff
changeset
|
36 |
#include "logging/log.hpp" |
463d67f86eaa
8079408: Reimplement TraceClassLoading, TraceClassUnloading, and TraceClassLoaderData with Unified Logging.
mockner
parents:
33611
diff
changeset
|
37 |
#include "logging/logConfiguration.hpp" |
1 | 38 |
|
39 |
#ifdef DTRACE_ENABLED |
|
40 |
||
41 |
// Only bother with this argument setup if dtrace is available |
|
42 |
||
10739 | 43 |
#define HOTSPOT_CLASS_unloaded HOTSPOT_CLASS_UNLOADED |
44 |
#define HOTSPOT_CLASS_loaded HOTSPOT_CLASS_LOADED |
|
45 |
#define DTRACE_CLASSLOAD_PROBE(type, clss, shared) \ |
|
46 |
{ \ |
|
47 |
char* data = NULL; \ |
|
48 |
int len = 0; \ |
|
49 |
Symbol* name = (clss)->name(); \ |
|
50 |
if (name != NULL) { \ |
|
51 |
data = (char*)name->bytes(); \ |
|
52 |
len = name->utf8_length(); \ |
|
53 |
} \ |
|
54 |
HOTSPOT_CLASS_##type( /* type = unloaded, loaded */ \ |
|
49824
e242740a92b8
8201556: Disallow reading oops in ClassLoaderData if unloading
coleenp
parents:
47216
diff
changeset
|
55 |
data, len, (void*)(clss)->class_loader_data(), (shared)); \ |
10739 | 56 |
} |
57 |
||
1 | 58 |
#else // ndef DTRACE_ENABLED |
59 |
||
60 |
#define DTRACE_CLASSLOAD_PROBE(type, clss, shared) |
|
61 |
||
62 |
#endif |
|
63 |
||
13975
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13728
diff
changeset
|
64 |
#if INCLUDE_MANAGEMENT |
1 | 65 |
// counters for classes loaded from class files |
66 |
PerfCounter* ClassLoadingService::_classes_loaded_count = NULL; |
|
67 |
PerfCounter* ClassLoadingService::_classes_unloaded_count = NULL; |
|
68 |
PerfCounter* ClassLoadingService::_classbytes_loaded = NULL; |
|
69 |
PerfCounter* ClassLoadingService::_classbytes_unloaded = NULL; |
|
70 |
||
71 |
// counters for classes loaded from shared archive |
|
72 |
PerfCounter* ClassLoadingService::_shared_classes_loaded_count = NULL; |
|
73 |
PerfCounter* ClassLoadingService::_shared_classes_unloaded_count = NULL; |
|
74 |
PerfCounter* ClassLoadingService::_shared_classbytes_loaded = NULL; |
|
75 |
PerfCounter* ClassLoadingService::_shared_classbytes_unloaded = NULL; |
|
76 |
PerfVariable* ClassLoadingService::_class_methods_size = NULL; |
|
77 |
||
78 |
void ClassLoadingService::init() { |
|
79 |
EXCEPTION_MARK; |
|
80 |
||
81 |
// These counters are for java.lang.management API support. |
|
82 |
// They are created even if -XX:-UsePerfData is set and in |
|
83 |
// that case, they will be allocated on C heap. |
|
84 |
_classes_loaded_count = |
|
85 |
PerfDataManager::create_counter(JAVA_CLS, "loadedClasses", |
|
86 |
PerfData::U_Events, CHECK); |
|
87 |
||
88 |
_classes_unloaded_count = |
|
89 |
PerfDataManager::create_counter(JAVA_CLS, "unloadedClasses", |
|
90 |
PerfData::U_Events, CHECK); |
|
91 |
||
92 |
_shared_classes_loaded_count = |
|
93 |
PerfDataManager::create_counter(JAVA_CLS, "sharedLoadedClasses", |
|
94 |
PerfData::U_Events, CHECK); |
|
95 |
||
96 |
_shared_classes_unloaded_count = |
|
97 |
PerfDataManager::create_counter(JAVA_CLS, "sharedUnloadedClasses", |
|
98 |
PerfData::U_Events, CHECK); |
|
99 |
||
100 |
if (UsePerfData) { |
|
101 |
_classbytes_loaded = |
|
102 |
PerfDataManager::create_counter(SUN_CLS, "loadedBytes", |
|
103 |
PerfData::U_Bytes, CHECK); |
|
104 |
||
105 |
_classbytes_unloaded = |
|
106 |
PerfDataManager::create_counter(SUN_CLS, "unloadedBytes", |
|
107 |
PerfData::U_Bytes, CHECK); |
|
108 |
_shared_classbytes_loaded = |
|
109 |
PerfDataManager::create_counter(SUN_CLS, "sharedLoadedBytes", |
|
110 |
PerfData::U_Bytes, CHECK); |
|
111 |
||
112 |
_shared_classbytes_unloaded = |
|
113 |
PerfDataManager::create_counter(SUN_CLS, "sharedUnloadedBytes", |
|
114 |
PerfData::U_Bytes, CHECK); |
|
115 |
_class_methods_size = |
|
116 |
PerfDataManager::create_variable(SUN_CLS, "methodBytes", |
|
117 |
PerfData::U_Bytes, CHECK); |
|
118 |
} |
|
119 |
} |
|
120 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
10739
diff
changeset
|
121 |
void ClassLoadingService::notify_class_unloaded(InstanceKlass* k) { |
1 | 122 |
DTRACE_CLASSLOAD_PROBE(unloaded, k, false); |
123 |
// Classes that can be unloaded must be non-shared |
|
124 |
_classes_unloaded_count->inc(); |
|
125 |
||
126 |
if (UsePerfData) { |
|
127 |
// add the class size |
|
128 |
size_t size = compute_class_size(k); |
|
129 |
_classbytes_unloaded->inc(size); |
|
130 |
||
131 |
// Compute method size & subtract from running total. |
|
132 |
// We are called during phase 1 of mark sweep, so it's |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
10739
diff
changeset
|
133 |
// still ok to iterate through Method*s here. |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
10739
diff
changeset
|
134 |
Array<Method*>* methods = k->methods(); |
1 | 135 |
for (int i = 0; i < methods->length(); i++) { |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
10739
diff
changeset
|
136 |
_class_methods_size->inc(-methods->at(i)->size()); |
1 | 137 |
} |
138 |
} |
|
139 |
} |
|
140 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
10739
diff
changeset
|
141 |
void ClassLoadingService::notify_class_loaded(InstanceKlass* k, bool shared_class) { |
1 | 142 |
DTRACE_CLASSLOAD_PROBE(loaded, k, shared_class); |
143 |
PerfCounter* classes_counter = (shared_class ? _shared_classes_loaded_count |
|
144 |
: _classes_loaded_count); |
|
145 |
// increment the count |
|
146 |
classes_counter->inc(); |
|
147 |
||
148 |
if (UsePerfData) { |
|
149 |
PerfCounter* classbytes_counter = (shared_class ? _shared_classbytes_loaded |
|
150 |
: _classbytes_loaded); |
|
151 |
// add the class size |
|
152 |
size_t size = compute_class_size(k); |
|
153 |
classbytes_counter->inc(size); |
|
154 |
} |
|
155 |
} |
|
156 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
10739
diff
changeset
|
157 |
size_t ClassLoadingService::compute_class_size(InstanceKlass* k) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
10739
diff
changeset
|
158 |
// lifted from ClassStatistics.do_class(Klass* k) |
1 | 159 |
|
160 |
size_t class_size = 0; |
|
161 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
10739
diff
changeset
|
162 |
class_size += k->size(); |
1 | 163 |
|
33611
9abd65805e19
8139203: Consistent naming for klass type predicates
coleenp
parents:
33105
diff
changeset
|
164 |
if (k->is_instance_klass()) { |
1 | 165 |
class_size += k->methods()->size(); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
10739
diff
changeset
|
166 |
// FIXME: Need to count the contents of methods |
1 | 167 |
class_size += k->constants()->size(); |
168 |
class_size += k->local_interfaces()->size(); |
|
50219
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
49824
diff
changeset
|
169 |
if (k->transitive_interfaces() != NULL) { |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
49824
diff
changeset
|
170 |
class_size += k->transitive_interfaces()->size(); |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
49824
diff
changeset
|
171 |
} |
1 | 172 |
// We do not have to count implementors, since we only store one! |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
10739
diff
changeset
|
173 |
// FIXME: How should these be accounted for, now when they have moved. |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
10739
diff
changeset
|
174 |
//class_size += k->fields()->size(); |
1 | 175 |
} |
176 |
return class_size * oopSize; |
|
177 |
} |
|
178 |
||
179 |
bool ClassLoadingService::set_verbose(bool verbose) { |
|
180 |
MutexLocker m(Management_lock); |
|
181 |
// verbose will be set to the previous value |
|
40924 | 182 |
LogLevelType level = verbose ? LogLevel::Info : LogLevel::Off; |
183 |
LogConfiguration::configure_stdout(level, false, LOG_TAGS(class, load)); |
|
1 | 184 |
reset_trace_class_unloading(); |
185 |
return verbose; |
|
186 |
} |
|
187 |
||
188 |
// Caller to this function must own Management_lock |
|
189 |
void ClassLoadingService::reset_trace_class_unloading() { |
|
190 |
assert(Management_lock->owned_by_self(), "Must own the Management_lock"); |
|
191 |
bool value = MemoryService::get_verbose() || ClassLoadingService::get_verbose(); |
|
40924 | 192 |
LogLevelType level = value ? LogLevel::Info : LogLevel::Off; |
193 |
LogConfiguration::configure_stdout(level, false, LOG_TAGS(class, unload)); |
|
1 | 194 |
} |
195 |
||
13975
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13728
diff
changeset
|
196 |
#endif // INCLUDE_MANAGEMENT |