src/share/vm/services/classLoadingService.cpp

Thu, 26 Sep 2013 10:25:02 -0400

author
hseigel
date
Thu, 26 Sep 2013 10:25:02 -0400
changeset 5784
190899198332
parent 4542
db9981fd3124
child 5802
268e7a2178d7
permissions
-rw-r--r--

7195622: CheckUnhandledOops has limited usefulness now
Summary: Enable CHECK_UNHANDLED_OOPS in fastdebug builds across all supported platforms.
Reviewed-by: coleenp, hseigel, dholmes, stefank, twisti, ihse, rdurbin
Contributed-by: lois.foltan@oracle.com

duke@435 1 /*
hseigel@5784 2 * Copyright (c) 2003, 2013, 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"
jprovino@4542 34 #include "utilities/macros.hpp"
duke@435 35
duke@435 36 #ifdef DTRACE_ENABLED
duke@435 37
duke@435 38 // Only bother with this argument setup if dtrace is available
duke@435 39
dcubed@3202 40 #ifndef USDT2
dcubed@3202 41
duke@435 42 HS_DTRACE_PROBE_DECL4(hotspot, class__loaded, char*, int, oop, bool);
duke@435 43 HS_DTRACE_PROBE_DECL4(hotspot, class__unloaded, char*, int, oop, bool);
duke@435 44
duke@435 45 #define DTRACE_CLASSLOAD_PROBE(type, clss, shared) \
duke@435 46 { \
duke@435 47 char* data = NULL; \
duke@435 48 int len = 0; \
coleenp@2497 49 Symbol* name = (clss)->name(); \
duke@435 50 if (name != NULL) { \
duke@435 51 data = (char*)name->bytes(); \
duke@435 52 len = name->utf8_length(); \
duke@435 53 } \
duke@435 54 HS_DTRACE_PROBE4(hotspot, class__##type, \
hseigel@5784 55 data, len, SOLARIS_ONLY((void *))(clss)->class_loader(), (shared)); \
duke@435 56 }
duke@435 57
dcubed@3202 58 #else /* USDT2 */
dcubed@3202 59
dcubed@3202 60 #define HOTSPOT_CLASS_unloaded HOTSPOT_CLASS_UNLOADED
dcubed@3202 61 #define HOTSPOT_CLASS_loaded HOTSPOT_CLASS_LOADED
dcubed@3202 62 #define DTRACE_CLASSLOAD_PROBE(type, clss, shared) \
dcubed@3202 63 { \
dcubed@3202 64 char* data = NULL; \
dcubed@3202 65 int len = 0; \
dcubed@3202 66 Symbol* name = (clss)->name(); \
dcubed@3202 67 if (name != NULL) { \
dcubed@3202 68 data = (char*)name->bytes(); \
dcubed@3202 69 len = name->utf8_length(); \
dcubed@3202 70 } \
dcubed@3202 71 HOTSPOT_CLASS_##type( /* type = unloaded, loaded */ \
dcubed@3202 72 data, len, (clss)->class_loader(), (shared)); \
dcubed@3202 73 }
dcubed@3202 74
dcubed@3202 75 #endif /* USDT2 */
duke@435 76 #else // ndef DTRACE_ENABLED
duke@435 77
duke@435 78 #define DTRACE_CLASSLOAD_PROBE(type, clss, shared)
duke@435 79
duke@435 80 #endif
duke@435 81
jprovino@4165 82 #if INCLUDE_MANAGEMENT
duke@435 83 // counters for classes loaded from class files
duke@435 84 PerfCounter* ClassLoadingService::_classes_loaded_count = NULL;
duke@435 85 PerfCounter* ClassLoadingService::_classes_unloaded_count = NULL;
duke@435 86 PerfCounter* ClassLoadingService::_classbytes_loaded = NULL;
duke@435 87 PerfCounter* ClassLoadingService::_classbytes_unloaded = NULL;
duke@435 88
duke@435 89 // counters for classes loaded from shared archive
duke@435 90 PerfCounter* ClassLoadingService::_shared_classes_loaded_count = NULL;
duke@435 91 PerfCounter* ClassLoadingService::_shared_classes_unloaded_count = NULL;
duke@435 92 PerfCounter* ClassLoadingService::_shared_classbytes_loaded = NULL;
duke@435 93 PerfCounter* ClassLoadingService::_shared_classbytes_unloaded = NULL;
duke@435 94 PerfVariable* ClassLoadingService::_class_methods_size = NULL;
duke@435 95
duke@435 96 void ClassLoadingService::init() {
duke@435 97 EXCEPTION_MARK;
duke@435 98
duke@435 99 // These counters are for java.lang.management API support.
duke@435 100 // They are created even if -XX:-UsePerfData is set and in
duke@435 101 // that case, they will be allocated on C heap.
duke@435 102 _classes_loaded_count =
duke@435 103 PerfDataManager::create_counter(JAVA_CLS, "loadedClasses",
duke@435 104 PerfData::U_Events, CHECK);
duke@435 105
duke@435 106 _classes_unloaded_count =
duke@435 107 PerfDataManager::create_counter(JAVA_CLS, "unloadedClasses",
duke@435 108 PerfData::U_Events, CHECK);
duke@435 109
duke@435 110 _shared_classes_loaded_count =
duke@435 111 PerfDataManager::create_counter(JAVA_CLS, "sharedLoadedClasses",
duke@435 112 PerfData::U_Events, CHECK);
duke@435 113
duke@435 114 _shared_classes_unloaded_count =
duke@435 115 PerfDataManager::create_counter(JAVA_CLS, "sharedUnloadedClasses",
duke@435 116 PerfData::U_Events, CHECK);
duke@435 117
duke@435 118 if (UsePerfData) {
duke@435 119 _classbytes_loaded =
duke@435 120 PerfDataManager::create_counter(SUN_CLS, "loadedBytes",
duke@435 121 PerfData::U_Bytes, CHECK);
duke@435 122
duke@435 123 _classbytes_unloaded =
duke@435 124 PerfDataManager::create_counter(SUN_CLS, "unloadedBytes",
duke@435 125 PerfData::U_Bytes, CHECK);
duke@435 126 _shared_classbytes_loaded =
duke@435 127 PerfDataManager::create_counter(SUN_CLS, "sharedLoadedBytes",
duke@435 128 PerfData::U_Bytes, CHECK);
duke@435 129
duke@435 130 _shared_classbytes_unloaded =
duke@435 131 PerfDataManager::create_counter(SUN_CLS, "sharedUnloadedBytes",
duke@435 132 PerfData::U_Bytes, CHECK);
duke@435 133 _class_methods_size =
duke@435 134 PerfDataManager::create_variable(SUN_CLS, "methodBytes",
duke@435 135 PerfData::U_Bytes, CHECK);
duke@435 136 }
duke@435 137 }
duke@435 138
coleenp@4037 139 void ClassLoadingService::notify_class_unloaded(InstanceKlass* k) {
duke@435 140 DTRACE_CLASSLOAD_PROBE(unloaded, k, false);
duke@435 141 // Classes that can be unloaded must be non-shared
duke@435 142 _classes_unloaded_count->inc();
duke@435 143
duke@435 144 if (UsePerfData) {
duke@435 145 // add the class size
duke@435 146 size_t size = compute_class_size(k);
duke@435 147 _classbytes_unloaded->inc(size);
duke@435 148
duke@435 149 // Compute method size & subtract from running total.
duke@435 150 // We are called during phase 1 of mark sweep, so it's
coleenp@4037 151 // still ok to iterate through Method*s here.
coleenp@4037 152 Array<Method*>* methods = k->methods();
duke@435 153 for (int i = 0; i < methods->length(); i++) {
coleenp@4037 154 _class_methods_size->inc(-methods->at(i)->size());
duke@435 155 }
duke@435 156 }
duke@435 157
duke@435 158 if (TraceClassUnloading) {
duke@435 159 ResourceMark rm;
coleenp@4037 160 tty->print_cr("[Unloading class %s " INTPTR_FORMAT "]", k->external_name(), k);
duke@435 161 }
duke@435 162 }
duke@435 163
coleenp@4037 164 void ClassLoadingService::notify_class_loaded(InstanceKlass* k, bool shared_class) {
duke@435 165 DTRACE_CLASSLOAD_PROBE(loaded, k, shared_class);
duke@435 166 PerfCounter* classes_counter = (shared_class ? _shared_classes_loaded_count
duke@435 167 : _classes_loaded_count);
duke@435 168 // increment the count
duke@435 169 classes_counter->inc();
duke@435 170
duke@435 171 if (UsePerfData) {
duke@435 172 PerfCounter* classbytes_counter = (shared_class ? _shared_classbytes_loaded
duke@435 173 : _classbytes_loaded);
duke@435 174 // add the class size
duke@435 175 size_t size = compute_class_size(k);
duke@435 176 classbytes_counter->inc(size);
duke@435 177 }
duke@435 178 }
duke@435 179
coleenp@4037 180 size_t ClassLoadingService::compute_class_size(InstanceKlass* k) {
coleenp@4037 181 // lifted from ClassStatistics.do_class(Klass* k)
duke@435 182
duke@435 183 size_t class_size = 0;
duke@435 184
coleenp@4037 185 class_size += k->size();
duke@435 186
duke@435 187 if (k->oop_is_instance()) {
duke@435 188 class_size += k->methods()->size();
coleenp@4037 189 // FIXME: Need to count the contents of methods
duke@435 190 class_size += k->constants()->size();
duke@435 191 class_size += k->local_interfaces()->size();
duke@435 192 class_size += k->transitive_interfaces()->size();
duke@435 193 // We do not have to count implementors, since we only store one!
coleenp@4037 194 // FIXME: How should these be accounted for, now when they have moved.
coleenp@4037 195 //class_size += k->fields()->size();
duke@435 196 }
duke@435 197 return class_size * oopSize;
duke@435 198 }
duke@435 199
duke@435 200
duke@435 201 bool ClassLoadingService::set_verbose(bool verbose) {
duke@435 202 MutexLocker m(Management_lock);
duke@435 203
duke@435 204 // verbose will be set to the previous value
duke@435 205 bool succeed = CommandLineFlags::boolAtPut((char*)"TraceClassLoading", &verbose, MANAGEMENT);
duke@435 206 assert(succeed, "Setting TraceClassLoading flag fails");
duke@435 207 reset_trace_class_unloading();
duke@435 208
duke@435 209 return verbose;
duke@435 210 }
duke@435 211
duke@435 212 // Caller to this function must own Management_lock
duke@435 213 void ClassLoadingService::reset_trace_class_unloading() {
duke@435 214 assert(Management_lock->owned_by_self(), "Must own the Management_lock");
duke@435 215 bool value = MemoryService::get_verbose() || ClassLoadingService::get_verbose();
duke@435 216 bool succeed = CommandLineFlags::boolAtPut((char*)"TraceClassUnloading", &value, MANAGEMENT);
duke@435 217 assert(succeed, "Setting TraceClassUnLoading flag fails");
duke@435 218 }
duke@435 219
duke@435 220 GrowableArray<KlassHandle>* LoadedClassesEnumerator::_loaded_classes = NULL;
duke@435 221 Thread* LoadedClassesEnumerator::_current_thread = NULL;
duke@435 222
duke@435 223 LoadedClassesEnumerator::LoadedClassesEnumerator(Thread* cur_thread) {
duke@435 224 assert(cur_thread == Thread::current(), "Check current thread");
duke@435 225
duke@435 226 int init_size = ClassLoadingService::loaded_class_count();
duke@435 227 _klass_handle_array = new GrowableArray<KlassHandle>(init_size);
duke@435 228
duke@435 229 // For consistency of the loaded classes, grab the SystemDictionary lock
duke@435 230 MutexLocker sd_mutex(SystemDictionary_lock);
duke@435 231
duke@435 232 // Set _loaded_classes and _current_thread and begin enumerating all classes.
duke@435 233 // Only one thread will do the enumeration at a time.
duke@435 234 // These static variables are needed and they are used by the static method
duke@435 235 // add_loaded_class called from classes_do().
duke@435 236 _loaded_classes = _klass_handle_array;
duke@435 237 _current_thread = cur_thread;
duke@435 238
duke@435 239 SystemDictionary::classes_do(&add_loaded_class);
duke@435 240
duke@435 241 // FIXME: Exclude array klasses for now
duke@435 242 // Universe::basic_type_classes_do(&add_loaded_class);
duke@435 243 }
jprovino@4165 244
jprovino@4165 245 #endif // INCLUDE_MANAGEMENT

mercurial