src/share/vm/services/classLoadingService.cpp

Fri, 25 Jan 2013 10:04:08 -0500

author
zgu
date
Fri, 25 Jan 2013 10:04:08 -0500
changeset 4492
8b46b0196eb0
parent 4165
fb19af007ffc
child 4542
db9981fd3124
permissions
-rw-r--r--

8000692: Remove old KERNEL code
Summary: Removed depreciated kernel VM source code from hotspot VM
Reviewed-by: dholmes, acorn

duke@435 1 /*
coleenp@4037 2 * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #include "precompiled.hpp"
stefank@2314 26 #include "classfile/systemDictionary.hpp"
stefank@2314 27 #include "memory/allocation.hpp"
stefank@2314 28 #include "memory/universe.hpp"
stefank@2314 29 #include "oops/oop.inline.hpp"
stefank@2314 30 #include "runtime/mutexLocker.hpp"
stefank@2314 31 #include "services/classLoadingService.hpp"
stefank@2314 32 #include "services/memoryService.hpp"
stefank@2314 33 #include "utilities/dtrace.hpp"
duke@435 34
duke@435 35 #ifdef DTRACE_ENABLED
duke@435 36
duke@435 37 // Only bother with this argument setup if dtrace is available
duke@435 38
dcubed@3202 39 #ifndef USDT2
dcubed@3202 40
duke@435 41 HS_DTRACE_PROBE_DECL4(hotspot, class__loaded, char*, int, oop, bool);
duke@435 42 HS_DTRACE_PROBE_DECL4(hotspot, class__unloaded, char*, int, oop, bool);
duke@435 43
duke@435 44 #define DTRACE_CLASSLOAD_PROBE(type, clss, shared) \
duke@435 45 { \
duke@435 46 char* data = NULL; \
duke@435 47 int len = 0; \
coleenp@2497 48 Symbol* name = (clss)->name(); \
duke@435 49 if (name != NULL) { \
duke@435 50 data = (char*)name->bytes(); \
duke@435 51 len = name->utf8_length(); \
duke@435 52 } \
duke@435 53 HS_DTRACE_PROBE4(hotspot, class__##type, \
duke@435 54 data, len, (clss)->class_loader(), (shared)); \
duke@435 55 }
duke@435 56
dcubed@3202 57 #else /* USDT2 */
dcubed@3202 58
dcubed@3202 59 #define HOTSPOT_CLASS_unloaded HOTSPOT_CLASS_UNLOADED
dcubed@3202 60 #define HOTSPOT_CLASS_loaded HOTSPOT_CLASS_LOADED
dcubed@3202 61 #define DTRACE_CLASSLOAD_PROBE(type, clss, shared) \
dcubed@3202 62 { \
dcubed@3202 63 char* data = NULL; \
dcubed@3202 64 int len = 0; \
dcubed@3202 65 Symbol* name = (clss)->name(); \
dcubed@3202 66 if (name != NULL) { \
dcubed@3202 67 data = (char*)name->bytes(); \
dcubed@3202 68 len = name->utf8_length(); \
dcubed@3202 69 } \
dcubed@3202 70 HOTSPOT_CLASS_##type( /* type = unloaded, loaded */ \
dcubed@3202 71 data, len, (clss)->class_loader(), (shared)); \
dcubed@3202 72 }
dcubed@3202 73
dcubed@3202 74 #endif /* USDT2 */
duke@435 75 #else // ndef DTRACE_ENABLED
duke@435 76
duke@435 77 #define DTRACE_CLASSLOAD_PROBE(type, clss, shared)
duke@435 78
duke@435 79 #endif
duke@435 80
jprovino@4165 81 #if INCLUDE_MANAGEMENT
duke@435 82 // counters for classes loaded from class files
duke@435 83 PerfCounter* ClassLoadingService::_classes_loaded_count = NULL;
duke@435 84 PerfCounter* ClassLoadingService::_classes_unloaded_count = NULL;
duke@435 85 PerfCounter* ClassLoadingService::_classbytes_loaded = NULL;
duke@435 86 PerfCounter* ClassLoadingService::_classbytes_unloaded = NULL;
duke@435 87
duke@435 88 // counters for classes loaded from shared archive
duke@435 89 PerfCounter* ClassLoadingService::_shared_classes_loaded_count = NULL;
duke@435 90 PerfCounter* ClassLoadingService::_shared_classes_unloaded_count = NULL;
duke@435 91 PerfCounter* ClassLoadingService::_shared_classbytes_loaded = NULL;
duke@435 92 PerfCounter* ClassLoadingService::_shared_classbytes_unloaded = NULL;
duke@435 93 PerfVariable* ClassLoadingService::_class_methods_size = NULL;
duke@435 94
duke@435 95 void ClassLoadingService::init() {
duke@435 96 EXCEPTION_MARK;
duke@435 97
duke@435 98 // These counters are for java.lang.management API support.
duke@435 99 // They are created even if -XX:-UsePerfData is set and in
duke@435 100 // that case, they will be allocated on C heap.
duke@435 101 _classes_loaded_count =
duke@435 102 PerfDataManager::create_counter(JAVA_CLS, "loadedClasses",
duke@435 103 PerfData::U_Events, CHECK);
duke@435 104
duke@435 105 _classes_unloaded_count =
duke@435 106 PerfDataManager::create_counter(JAVA_CLS, "unloadedClasses",
duke@435 107 PerfData::U_Events, CHECK);
duke@435 108
duke@435 109 _shared_classes_loaded_count =
duke@435 110 PerfDataManager::create_counter(JAVA_CLS, "sharedLoadedClasses",
duke@435 111 PerfData::U_Events, CHECK);
duke@435 112
duke@435 113 _shared_classes_unloaded_count =
duke@435 114 PerfDataManager::create_counter(JAVA_CLS, "sharedUnloadedClasses",
duke@435 115 PerfData::U_Events, CHECK);
duke@435 116
duke@435 117 if (UsePerfData) {
duke@435 118 _classbytes_loaded =
duke@435 119 PerfDataManager::create_counter(SUN_CLS, "loadedBytes",
duke@435 120 PerfData::U_Bytes, CHECK);
duke@435 121
duke@435 122 _classbytes_unloaded =
duke@435 123 PerfDataManager::create_counter(SUN_CLS, "unloadedBytes",
duke@435 124 PerfData::U_Bytes, CHECK);
duke@435 125 _shared_classbytes_loaded =
duke@435 126 PerfDataManager::create_counter(SUN_CLS, "sharedLoadedBytes",
duke@435 127 PerfData::U_Bytes, CHECK);
duke@435 128
duke@435 129 _shared_classbytes_unloaded =
duke@435 130 PerfDataManager::create_counter(SUN_CLS, "sharedUnloadedBytes",
duke@435 131 PerfData::U_Bytes, CHECK);
duke@435 132 _class_methods_size =
duke@435 133 PerfDataManager::create_variable(SUN_CLS, "methodBytes",
duke@435 134 PerfData::U_Bytes, CHECK);
duke@435 135 }
duke@435 136 }
duke@435 137
coleenp@4037 138 void ClassLoadingService::notify_class_unloaded(InstanceKlass* k) {
duke@435 139 DTRACE_CLASSLOAD_PROBE(unloaded, k, false);
duke@435 140 // Classes that can be unloaded must be non-shared
duke@435 141 _classes_unloaded_count->inc();
duke@435 142
duke@435 143 if (UsePerfData) {
duke@435 144 // add the class size
duke@435 145 size_t size = compute_class_size(k);
duke@435 146 _classbytes_unloaded->inc(size);
duke@435 147
duke@435 148 // Compute method size & subtract from running total.
duke@435 149 // We are called during phase 1 of mark sweep, so it's
coleenp@4037 150 // still ok to iterate through Method*s here.
coleenp@4037 151 Array<Method*>* methods = k->methods();
duke@435 152 for (int i = 0; i < methods->length(); i++) {
coleenp@4037 153 _class_methods_size->inc(-methods->at(i)->size());
duke@435 154 }
duke@435 155 }
duke@435 156
duke@435 157 if (TraceClassUnloading) {
duke@435 158 ResourceMark rm;
coleenp@4037 159 tty->print_cr("[Unloading class %s " INTPTR_FORMAT "]", k->external_name(), k);
duke@435 160 }
duke@435 161 }
duke@435 162
coleenp@4037 163 void ClassLoadingService::notify_class_loaded(InstanceKlass* k, bool shared_class) {
duke@435 164 DTRACE_CLASSLOAD_PROBE(loaded, k, shared_class);
duke@435 165 PerfCounter* classes_counter = (shared_class ? _shared_classes_loaded_count
duke@435 166 : _classes_loaded_count);
duke@435 167 // increment the count
duke@435 168 classes_counter->inc();
duke@435 169
duke@435 170 if (UsePerfData) {
duke@435 171 PerfCounter* classbytes_counter = (shared_class ? _shared_classbytes_loaded
duke@435 172 : _classbytes_loaded);
duke@435 173 // add the class size
duke@435 174 size_t size = compute_class_size(k);
duke@435 175 classbytes_counter->inc(size);
duke@435 176 }
duke@435 177 }
duke@435 178
coleenp@4037 179 size_t ClassLoadingService::compute_class_size(InstanceKlass* k) {
coleenp@4037 180 // lifted from ClassStatistics.do_class(Klass* k)
duke@435 181
duke@435 182 size_t class_size = 0;
duke@435 183
coleenp@4037 184 class_size += k->size();
duke@435 185
duke@435 186 if (k->oop_is_instance()) {
duke@435 187 class_size += k->methods()->size();
coleenp@4037 188 // FIXME: Need to count the contents of methods
duke@435 189 class_size += k->constants()->size();
duke@435 190 class_size += k->local_interfaces()->size();
duke@435 191 class_size += k->transitive_interfaces()->size();
duke@435 192 // We do not have to count implementors, since we only store one!
coleenp@4037 193 // FIXME: How should these be accounted for, now when they have moved.
coleenp@4037 194 //class_size += k->fields()->size();
duke@435 195 }
duke@435 196 return class_size * oopSize;
duke@435 197 }
duke@435 198
duke@435 199
duke@435 200 bool ClassLoadingService::set_verbose(bool verbose) {
duke@435 201 MutexLocker m(Management_lock);
duke@435 202
duke@435 203 // verbose will be set to the previous value
duke@435 204 bool succeed = CommandLineFlags::boolAtPut((char*)"TraceClassLoading", &verbose, MANAGEMENT);
duke@435 205 assert(succeed, "Setting TraceClassLoading flag fails");
duke@435 206 reset_trace_class_unloading();
duke@435 207
duke@435 208 return verbose;
duke@435 209 }
duke@435 210
duke@435 211 // Caller to this function must own Management_lock
duke@435 212 void ClassLoadingService::reset_trace_class_unloading() {
duke@435 213 assert(Management_lock->owned_by_self(), "Must own the Management_lock");
duke@435 214 bool value = MemoryService::get_verbose() || ClassLoadingService::get_verbose();
duke@435 215 bool succeed = CommandLineFlags::boolAtPut((char*)"TraceClassUnloading", &value, MANAGEMENT);
duke@435 216 assert(succeed, "Setting TraceClassUnLoading flag fails");
duke@435 217 }
duke@435 218
duke@435 219 GrowableArray<KlassHandle>* LoadedClassesEnumerator::_loaded_classes = NULL;
duke@435 220 Thread* LoadedClassesEnumerator::_current_thread = NULL;
duke@435 221
duke@435 222 LoadedClassesEnumerator::LoadedClassesEnumerator(Thread* cur_thread) {
duke@435 223 assert(cur_thread == Thread::current(), "Check current thread");
duke@435 224
duke@435 225 int init_size = ClassLoadingService::loaded_class_count();
duke@435 226 _klass_handle_array = new GrowableArray<KlassHandle>(init_size);
duke@435 227
duke@435 228 // For consistency of the loaded classes, grab the SystemDictionary lock
duke@435 229 MutexLocker sd_mutex(SystemDictionary_lock);
duke@435 230
duke@435 231 // Set _loaded_classes and _current_thread and begin enumerating all classes.
duke@435 232 // Only one thread will do the enumeration at a time.
duke@435 233 // These static variables are needed and they are used by the static method
duke@435 234 // add_loaded_class called from classes_do().
duke@435 235 _loaded_classes = _klass_handle_array;
duke@435 236 _current_thread = cur_thread;
duke@435 237
duke@435 238 SystemDictionary::classes_do(&add_loaded_class);
duke@435 239
duke@435 240 // FIXME: Exclude array klasses for now
duke@435 241 // Universe::basic_type_classes_do(&add_loaded_class);
duke@435 242 }
jprovino@4165 243
jprovino@4165 244 #endif // INCLUDE_MANAGEMENT

mercurial