2007-12-01 00:00:00 +00:00
|
|
|
/*
|
2013-09-26 10:25:02 -04:00
|
|
|
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
|
2007-12-01 00:00:00 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
2010-05-27 19:08:38 -07:00
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
2007-12-01 00:00:00 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "precompiled.hpp"
|
|
|
|
#include "classfile/systemDictionary.hpp"
|
|
|
|
#include "memory/allocation.hpp"
|
|
|
|
#include "memory/universe.hpp"
|
|
|
|
#include "oops/oop.inline.hpp"
|
|
|
|
#include "runtime/mutexLocker.hpp"
|
|
|
|
#include "services/classLoadingService.hpp"
|
|
|
|
#include "services/memoryService.hpp"
|
|
|
|
#include "utilities/dtrace.hpp"
|
2013-01-23 13:02:39 -05:00
|
|
|
#include "utilities/macros.hpp"
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
#ifdef DTRACE_ENABLED
|
|
|
|
|
|
|
|
// Only bother with this argument setup if dtrace is available
|
|
|
|
|
2011-10-13 09:35:42 -07:00
|
|
|
#define HOTSPOT_CLASS_unloaded HOTSPOT_CLASS_UNLOADED
|
|
|
|
#define HOTSPOT_CLASS_loaded HOTSPOT_CLASS_LOADED
|
|
|
|
#define DTRACE_CLASSLOAD_PROBE(type, clss, shared) \
|
|
|
|
{ \
|
|
|
|
char* data = NULL; \
|
|
|
|
int len = 0; \
|
|
|
|
Symbol* name = (clss)->name(); \
|
|
|
|
if (name != NULL) { \
|
|
|
|
data = (char*)name->bytes(); \
|
|
|
|
len = name->utf8_length(); \
|
|
|
|
} \
|
|
|
|
HOTSPOT_CLASS_##type( /* type = unloaded, loaded */ \
|
|
|
|
data, len, (clss)->class_loader(), (shared)); \
|
|
|
|
}
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
#else // ndef DTRACE_ENABLED
|
|
|
|
|
|
|
|
#define DTRACE_CLASSLOAD_PROBE(type, clss, shared)
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2012-10-10 14:35:58 -04:00
|
|
|
#if INCLUDE_MANAGEMENT
|
2007-12-01 00:00:00 +00:00
|
|
|
// counters for classes loaded from class files
|
|
|
|
PerfCounter* ClassLoadingService::_classes_loaded_count = NULL;
|
|
|
|
PerfCounter* ClassLoadingService::_classes_unloaded_count = NULL;
|
|
|
|
PerfCounter* ClassLoadingService::_classbytes_loaded = NULL;
|
|
|
|
PerfCounter* ClassLoadingService::_classbytes_unloaded = NULL;
|
|
|
|
|
|
|
|
// counters for classes loaded from shared archive
|
|
|
|
PerfCounter* ClassLoadingService::_shared_classes_loaded_count = NULL;
|
|
|
|
PerfCounter* ClassLoadingService::_shared_classes_unloaded_count = NULL;
|
|
|
|
PerfCounter* ClassLoadingService::_shared_classbytes_loaded = NULL;
|
|
|
|
PerfCounter* ClassLoadingService::_shared_classbytes_unloaded = NULL;
|
|
|
|
PerfVariable* ClassLoadingService::_class_methods_size = NULL;
|
|
|
|
|
|
|
|
void ClassLoadingService::init() {
|
|
|
|
EXCEPTION_MARK;
|
|
|
|
|
|
|
|
// These counters are for java.lang.management API support.
|
|
|
|
// They are created even if -XX:-UsePerfData is set and in
|
|
|
|
// that case, they will be allocated on C heap.
|
|
|
|
_classes_loaded_count =
|
|
|
|
PerfDataManager::create_counter(JAVA_CLS, "loadedClasses",
|
|
|
|
PerfData::U_Events, CHECK);
|
|
|
|
|
|
|
|
_classes_unloaded_count =
|
|
|
|
PerfDataManager::create_counter(JAVA_CLS, "unloadedClasses",
|
|
|
|
PerfData::U_Events, CHECK);
|
|
|
|
|
|
|
|
_shared_classes_loaded_count =
|
|
|
|
PerfDataManager::create_counter(JAVA_CLS, "sharedLoadedClasses",
|
|
|
|
PerfData::U_Events, CHECK);
|
|
|
|
|
|
|
|
_shared_classes_unloaded_count =
|
|
|
|
PerfDataManager::create_counter(JAVA_CLS, "sharedUnloadedClasses",
|
|
|
|
PerfData::U_Events, CHECK);
|
|
|
|
|
|
|
|
if (UsePerfData) {
|
|
|
|
_classbytes_loaded =
|
|
|
|
PerfDataManager::create_counter(SUN_CLS, "loadedBytes",
|
|
|
|
PerfData::U_Bytes, CHECK);
|
|
|
|
|
|
|
|
_classbytes_unloaded =
|
|
|
|
PerfDataManager::create_counter(SUN_CLS, "unloadedBytes",
|
|
|
|
PerfData::U_Bytes, CHECK);
|
|
|
|
_shared_classbytes_loaded =
|
|
|
|
PerfDataManager::create_counter(SUN_CLS, "sharedLoadedBytes",
|
|
|
|
PerfData::U_Bytes, CHECK);
|
|
|
|
|
|
|
|
_shared_classbytes_unloaded =
|
|
|
|
PerfDataManager::create_counter(SUN_CLS, "sharedUnloadedBytes",
|
|
|
|
PerfData::U_Bytes, CHECK);
|
|
|
|
_class_methods_size =
|
|
|
|
PerfDataManager::create_variable(SUN_CLS, "methodBytes",
|
|
|
|
PerfData::U_Bytes, CHECK);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
void ClassLoadingService::notify_class_unloaded(InstanceKlass* k) {
|
2007-12-01 00:00:00 +00:00
|
|
|
DTRACE_CLASSLOAD_PROBE(unloaded, k, false);
|
|
|
|
// Classes that can be unloaded must be non-shared
|
|
|
|
_classes_unloaded_count->inc();
|
|
|
|
|
|
|
|
if (UsePerfData) {
|
|
|
|
// add the class size
|
|
|
|
size_t size = compute_class_size(k);
|
|
|
|
_classbytes_unloaded->inc(size);
|
|
|
|
|
|
|
|
// Compute method size & subtract from running total.
|
|
|
|
// We are called during phase 1 of mark sweep, so it's
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
// still ok to iterate through Method*s here.
|
|
|
|
Array<Method*>* methods = k->methods();
|
2007-12-01 00:00:00 +00:00
|
|
|
for (int i = 0; i < methods->length(); i++) {
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
_class_methods_size->inc(-methods->at(i)->size());
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (TraceClassUnloading) {
|
|
|
|
ResourceMark rm;
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
tty->print_cr("[Unloading class %s " INTPTR_FORMAT "]", k->external_name(), k);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
void ClassLoadingService::notify_class_loaded(InstanceKlass* k, bool shared_class) {
|
2007-12-01 00:00:00 +00:00
|
|
|
DTRACE_CLASSLOAD_PROBE(loaded, k, shared_class);
|
|
|
|
PerfCounter* classes_counter = (shared_class ? _shared_classes_loaded_count
|
|
|
|
: _classes_loaded_count);
|
|
|
|
// increment the count
|
|
|
|
classes_counter->inc();
|
|
|
|
|
|
|
|
if (UsePerfData) {
|
|
|
|
PerfCounter* classbytes_counter = (shared_class ? _shared_classbytes_loaded
|
|
|
|
: _classbytes_loaded);
|
|
|
|
// add the class size
|
|
|
|
size_t size = compute_class_size(k);
|
|
|
|
classbytes_counter->inc(size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
size_t ClassLoadingService::compute_class_size(InstanceKlass* k) {
|
|
|
|
// lifted from ClassStatistics.do_class(Klass* k)
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
size_t class_size = 0;
|
|
|
|
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
class_size += k->size();
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
if (k->oop_is_instance()) {
|
|
|
|
class_size += k->methods()->size();
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
// FIXME: Need to count the contents of methods
|
2007-12-01 00:00:00 +00:00
|
|
|
class_size += k->constants()->size();
|
|
|
|
class_size += k->local_interfaces()->size();
|
|
|
|
class_size += k->transitive_interfaces()->size();
|
|
|
|
// We do not have to count implementors, since we only store one!
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
// FIXME: How should these be accounted for, now when they have moved.
|
|
|
|
//class_size += k->fields()->size();
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
return class_size * oopSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool ClassLoadingService::set_verbose(bool verbose) {
|
|
|
|
MutexLocker m(Management_lock);
|
|
|
|
|
|
|
|
// verbose will be set to the previous value
|
2013-09-26 12:07:53 -07:00
|
|
|
bool succeed = CommandLineFlags::boolAtPut((char*)"TraceClassLoading", &verbose, Flag::MANAGEMENT);
|
2007-12-01 00:00:00 +00:00
|
|
|
assert(succeed, "Setting TraceClassLoading flag fails");
|
|
|
|
reset_trace_class_unloading();
|
|
|
|
|
|
|
|
return verbose;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Caller to this function must own Management_lock
|
|
|
|
void ClassLoadingService::reset_trace_class_unloading() {
|
|
|
|
assert(Management_lock->owned_by_self(), "Must own the Management_lock");
|
|
|
|
bool value = MemoryService::get_verbose() || ClassLoadingService::get_verbose();
|
2013-09-26 12:07:53 -07:00
|
|
|
bool succeed = CommandLineFlags::boolAtPut((char*)"TraceClassUnloading", &value, Flag::MANAGEMENT);
|
2007-12-01 00:00:00 +00:00
|
|
|
assert(succeed, "Setting TraceClassUnLoading flag fails");
|
|
|
|
}
|
|
|
|
|
|
|
|
GrowableArray<KlassHandle>* LoadedClassesEnumerator::_loaded_classes = NULL;
|
|
|
|
Thread* LoadedClassesEnumerator::_current_thread = NULL;
|
|
|
|
|
|
|
|
LoadedClassesEnumerator::LoadedClassesEnumerator(Thread* cur_thread) {
|
|
|
|
assert(cur_thread == Thread::current(), "Check current thread");
|
|
|
|
|
|
|
|
int init_size = ClassLoadingService::loaded_class_count();
|
|
|
|
_klass_handle_array = new GrowableArray<KlassHandle>(init_size);
|
|
|
|
|
|
|
|
// For consistency of the loaded classes, grab the SystemDictionary lock
|
|
|
|
MutexLocker sd_mutex(SystemDictionary_lock);
|
|
|
|
|
|
|
|
// Set _loaded_classes and _current_thread and begin enumerating all classes.
|
|
|
|
// Only one thread will do the enumeration at a time.
|
|
|
|
// These static variables are needed and they are used by the static method
|
|
|
|
// add_loaded_class called from classes_do().
|
|
|
|
_loaded_classes = _klass_handle_array;
|
|
|
|
_current_thread = cur_thread;
|
|
|
|
|
|
|
|
SystemDictionary::classes_do(&add_loaded_class);
|
|
|
|
|
|
|
|
// FIXME: Exclude array klasses for now
|
|
|
|
// Universe::basic_type_classes_do(&add_loaded_class);
|
|
|
|
}
|
2012-10-10 14:35:58 -04:00
|
|
|
|
|
|
|
#endif // INCLUDE_MANAGEMENT
|