author | coleenp |
Tue, 22 Dec 2015 11:11:29 -0500 | |
changeset 35214 | d86005e0b4c2 |
parent 33611 | 9abd65805e19 |
child 35917 | 463d67f86eaa |
permissions | -rw-r--r-- |
1 | 1 |
/* |
31371
311143309e73
8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents:
24424
diff
changeset
|
2 |
* Copyright (c) 2003, 2015, 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" |
|
28 |
#include "memory/universe.hpp" |
|
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" |
1 | 36 |
|
37 |
#ifdef DTRACE_ENABLED |
|
38 |
||
39 |
// Only bother with this argument setup if dtrace is available |
|
40 |
||
10739 | 41 |
#define HOTSPOT_CLASS_unloaded HOTSPOT_CLASS_UNLOADED |
42 |
#define HOTSPOT_CLASS_loaded HOTSPOT_CLASS_LOADED |
|
43 |
#define DTRACE_CLASSLOAD_PROBE(type, clss, shared) \ |
|
44 |
{ \ |
|
45 |
char* data = NULL; \ |
|
46 |
int len = 0; \ |
|
47 |
Symbol* name = (clss)->name(); \ |
|
48 |
if (name != NULL) { \ |
|
49 |
data = (char*)name->bytes(); \ |
|
50 |
len = name->utf8_length(); \ |
|
51 |
} \ |
|
52 |
HOTSPOT_CLASS_##type( /* type = unloaded, loaded */ \ |
|
53 |
data, len, (clss)->class_loader(), (shared)); \ |
|
54 |
} |
|
55 |
||
1 | 56 |
#else // ndef DTRACE_ENABLED |
57 |
||
58 |
#define DTRACE_CLASSLOAD_PROBE(type, clss, shared) |
|
59 |
||
60 |
#endif |
|
61 |
||
13975
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13728
diff
changeset
|
62 |
#if INCLUDE_MANAGEMENT |
1 | 63 |
// counters for classes loaded from class files |
64 |
PerfCounter* ClassLoadingService::_classes_loaded_count = NULL; |
|
65 |
PerfCounter* ClassLoadingService::_classes_unloaded_count = NULL; |
|
66 |
PerfCounter* ClassLoadingService::_classbytes_loaded = NULL; |
|
67 |
PerfCounter* ClassLoadingService::_classbytes_unloaded = NULL; |
|
68 |
||
69 |
// counters for classes loaded from shared archive |
|
70 |
PerfCounter* ClassLoadingService::_shared_classes_loaded_count = NULL; |
|
71 |
PerfCounter* ClassLoadingService::_shared_classes_unloaded_count = NULL; |
|
72 |
PerfCounter* ClassLoadingService::_shared_classbytes_loaded = NULL; |
|
73 |
PerfCounter* ClassLoadingService::_shared_classbytes_unloaded = NULL; |
|
74 |
PerfVariable* ClassLoadingService::_class_methods_size = NULL; |
|
75 |
||
76 |
void ClassLoadingService::init() { |
|
77 |
EXCEPTION_MARK; |
|
78 |
||
79 |
// These counters are for java.lang.management API support. |
|
80 |
// They are created even if -XX:-UsePerfData is set and in |
|
81 |
// that case, they will be allocated on C heap. |
|
82 |
_classes_loaded_count = |
|
83 |
PerfDataManager::create_counter(JAVA_CLS, "loadedClasses", |
|
84 |
PerfData::U_Events, CHECK); |
|
85 |
||
86 |
_classes_unloaded_count = |
|
87 |
PerfDataManager::create_counter(JAVA_CLS, "unloadedClasses", |
|
88 |
PerfData::U_Events, CHECK); |
|
89 |
||
90 |
_shared_classes_loaded_count = |
|
91 |
PerfDataManager::create_counter(JAVA_CLS, "sharedLoadedClasses", |
|
92 |
PerfData::U_Events, CHECK); |
|
93 |
||
94 |
_shared_classes_unloaded_count = |
|
95 |
PerfDataManager::create_counter(JAVA_CLS, "sharedUnloadedClasses", |
|
96 |
PerfData::U_Events, CHECK); |
|
97 |
||
98 |
if (UsePerfData) { |
|
99 |
_classbytes_loaded = |
|
100 |
PerfDataManager::create_counter(SUN_CLS, "loadedBytes", |
|
101 |
PerfData::U_Bytes, CHECK); |
|
102 |
||
103 |
_classbytes_unloaded = |
|
104 |
PerfDataManager::create_counter(SUN_CLS, "unloadedBytes", |
|
105 |
PerfData::U_Bytes, CHECK); |
|
106 |
_shared_classbytes_loaded = |
|
107 |
PerfDataManager::create_counter(SUN_CLS, "sharedLoadedBytes", |
|
108 |
PerfData::U_Bytes, CHECK); |
|
109 |
||
110 |
_shared_classbytes_unloaded = |
|
111 |
PerfDataManager::create_counter(SUN_CLS, "sharedUnloadedBytes", |
|
112 |
PerfData::U_Bytes, CHECK); |
|
113 |
_class_methods_size = |
|
114 |
PerfDataManager::create_variable(SUN_CLS, "methodBytes", |
|
115 |
PerfData::U_Bytes, CHECK); |
|
116 |
} |
|
117 |
} |
|
118 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
10739
diff
changeset
|
119 |
void ClassLoadingService::notify_class_unloaded(InstanceKlass* k) { |
1 | 120 |
DTRACE_CLASSLOAD_PROBE(unloaded, k, false); |
121 |
// Classes that can be unloaded must be non-shared |
|
122 |
_classes_unloaded_count->inc(); |
|
123 |
||
124 |
if (UsePerfData) { |
|
125 |
// add the class size |
|
126 |
size_t size = compute_class_size(k); |
|
127 |
_classbytes_unloaded->inc(size); |
|
128 |
||
129 |
// Compute method size & subtract from running total. |
|
130 |
// 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
|
131 |
// still ok to iterate through Method*s here. |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
10739
diff
changeset
|
132 |
Array<Method*>* methods = k->methods(); |
1 | 133 |
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
|
134 |
_class_methods_size->inc(-methods->at(i)->size()); |
1 | 135 |
} |
136 |
} |
|
137 |
||
138 |
if (TraceClassUnloading) { |
|
139 |
ResourceMark rm; |
|
24424
2658d7834c6e
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
22796
diff
changeset
|
140 |
tty->print_cr("[Unloading class %s " INTPTR_FORMAT "]", k->external_name(), p2i(k)); |
1 | 141 |
} |
142 |
} |
|
143 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
10739
diff
changeset
|
144 |
void ClassLoadingService::notify_class_loaded(InstanceKlass* k, bool shared_class) { |
1 | 145 |
DTRACE_CLASSLOAD_PROBE(loaded, k, shared_class); |
146 |
PerfCounter* classes_counter = (shared_class ? _shared_classes_loaded_count |
|
147 |
: _classes_loaded_count); |
|
148 |
// increment the count |
|
149 |
classes_counter->inc(); |
|
150 |
||
151 |
if (UsePerfData) { |
|
152 |
PerfCounter* classbytes_counter = (shared_class ? _shared_classbytes_loaded |
|
153 |
: _classbytes_loaded); |
|
154 |
// add the class size |
|
155 |
size_t size = compute_class_size(k); |
|
156 |
classbytes_counter->inc(size); |
|
157 |
} |
|
158 |
} |
|
159 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
10739
diff
changeset
|
160 |
size_t ClassLoadingService::compute_class_size(InstanceKlass* k) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
10739
diff
changeset
|
161 |
// lifted from ClassStatistics.do_class(Klass* k) |
1 | 162 |
|
163 |
size_t class_size = 0; |
|
164 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
10739
diff
changeset
|
165 |
class_size += k->size(); |
1 | 166 |
|
33611
9abd65805e19
8139203: Consistent naming for klass type predicates
coleenp
parents:
33105
diff
changeset
|
167 |
if (k->is_instance_klass()) { |
1 | 168 |
class_size += k->methods()->size(); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
10739
diff
changeset
|
169 |
// FIXME: Need to count the contents of methods |
1 | 170 |
class_size += k->constants()->size(); |
171 |
class_size += k->local_interfaces()->size(); |
|
172 |
class_size += k->transitive_interfaces()->size(); |
|
173 |
// 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
|
174 |
// 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
|
175 |
//class_size += k->fields()->size(); |
1 | 176 |
} |
177 |
return class_size * oopSize; |
|
178 |
} |
|
179 |
||
180 |
bool ClassLoadingService::set_verbose(bool verbose) { |
|
181 |
MutexLocker m(Management_lock); |
|
182 |
||
183 |
// verbose will be set to the previous value |
|
31371
311143309e73
8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents:
24424
diff
changeset
|
184 |
Flag::Error error = CommandLineFlags::boolAtPut("TraceClassLoading", &verbose, Flag::MANAGEMENT); |
33105
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
31371
diff
changeset
|
185 |
assert(error==Flag::SUCCESS, "Setting TraceClassLoading flag failed with error %s", Flag::flag_error_str(error)); |
1 | 186 |
reset_trace_class_unloading(); |
187 |
||
188 |
return verbose; |
|
189 |
} |
|
190 |
||
191 |
// Caller to this function must own Management_lock |
|
192 |
void ClassLoadingService::reset_trace_class_unloading() { |
|
193 |
assert(Management_lock->owned_by_self(), "Must own the Management_lock"); |
|
194 |
bool value = MemoryService::get_verbose() || ClassLoadingService::get_verbose(); |
|
31371
311143309e73
8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents:
24424
diff
changeset
|
195 |
Flag::Error error = CommandLineFlags::boolAtPut("TraceClassUnloading", &value, Flag::MANAGEMENT); |
33105
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
31371
diff
changeset
|
196 |
assert(error==Flag::SUCCESS, "Setting TraceClassUnLoading flag failed with error %s", Flag::flag_error_str(error)); |
1 | 197 |
} |
198 |
||
199 |
GrowableArray<KlassHandle>* LoadedClassesEnumerator::_loaded_classes = NULL; |
|
200 |
Thread* LoadedClassesEnumerator::_current_thread = NULL; |
|
201 |
||
202 |
LoadedClassesEnumerator::LoadedClassesEnumerator(Thread* cur_thread) { |
|
203 |
assert(cur_thread == Thread::current(), "Check current thread"); |
|
204 |
||
205 |
int init_size = ClassLoadingService::loaded_class_count(); |
|
206 |
_klass_handle_array = new GrowableArray<KlassHandle>(init_size); |
|
207 |
||
208 |
// For consistency of the loaded classes, grab the SystemDictionary lock |
|
209 |
MutexLocker sd_mutex(SystemDictionary_lock); |
|
210 |
||
211 |
// Set _loaded_classes and _current_thread and begin enumerating all classes. |
|
212 |
// Only one thread will do the enumeration at a time. |
|
213 |
// These static variables are needed and they are used by the static method |
|
214 |
// add_loaded_class called from classes_do(). |
|
215 |
_loaded_classes = _klass_handle_array; |
|
216 |
_current_thread = cur_thread; |
|
217 |
||
218 |
SystemDictionary::classes_do(&add_loaded_class); |
|
219 |
||
220 |
// FIXME: Exclude array klasses for now |
|
221 |
// Universe::basic_type_classes_do(&add_loaded_class); |
|
222 |
} |
|
13975
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13728
diff
changeset
|
223 |
|
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13728
diff
changeset
|
224 |
#endif // INCLUDE_MANAGEMENT |