0N/A/*
553N/A * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
553N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
553N/A * or visit www.oracle.com if you need additional information or have any
553N/A * questions.
0N/A *
0N/A */
0N/A
0N/A#ifndef SHARE_VM_SERVICES_CLASSLOADINGSERVICE_HPP
0N/A#define SHARE_VM_SERVICES_CLASSLOADINGSERVICE_HPP
0N/A
0N/A#include "runtime/handles.hpp"
0N/A#include "runtime/perfData.hpp"
0N/A#include "utilities/growableArray.hpp"
0N/A
0N/Aclass instanceKlass;
0N/A
0N/A// VM monitoring and management support for the Class Loading subsystem
0N/Aclass ClassLoadingService : public AllStatic {
0N/Aprivate:
0N/A // Counters for classes loaded from class files
0N/A static PerfCounter* _classes_loaded_count;
0N/A static PerfCounter* _classes_unloaded_count;
0N/A static PerfCounter* _classbytes_loaded;
0N/A static PerfCounter* _classbytes_unloaded;
0N/A
0N/A // Counters for classes loaded from shared archive
0N/A static PerfCounter* _shared_classes_loaded_count;
0N/A static PerfCounter* _shared_classes_unloaded_count;
0N/A static PerfCounter* _shared_classbytes_loaded;
0N/A static PerfCounter* _shared_classbytes_unloaded;
0N/A
static PerfVariable* _class_methods_size;
static size_t compute_class_size(instanceKlass* k);
public:
static void init();
static bool get_verbose() { return TraceClassLoading; }
static bool set_verbose(bool verbose);
static void reset_trace_class_unloading();
static jlong loaded_class_count() {
return _classes_loaded_count->get_value() + _shared_classes_loaded_count->get_value();
}
static jlong unloaded_class_count() {
return _classes_unloaded_count->get_value() + _shared_classes_unloaded_count->get_value();
}
static jlong loaded_class_bytes() {
if (UsePerfData) {
return _classbytes_loaded->get_value() + _shared_classbytes_loaded->get_value();
} else {
return -1;
}
}
static jlong unloaded_class_bytes() {
if (UsePerfData) {
return _classbytes_unloaded->get_value() + _shared_classbytes_unloaded->get_value();
} else {
return -1;
}
}
static jlong loaded_shared_class_count() {
return _shared_classes_loaded_count->get_value();
}
static jlong unloaded_shared_class_count() {
return _shared_classes_unloaded_count->get_value();
}
static jlong loaded_shared_class_bytes() {
if (UsePerfData) {
return _shared_classbytes_loaded->get_value();
} else {
return -1;
}
}
static jlong unloaded_shared_class_bytes() {
if (UsePerfData) {
return _shared_classbytes_unloaded->get_value();
} else {
return -1;
}
}
static jlong class_method_data_size() {
return (UsePerfData ? _class_methods_size->get_value() : -1);
}
static void notify_class_loaded(instanceKlass* k, bool shared_class);
// All unloaded classes are non-shared
static void notify_class_unloaded(instanceKlass* k);
static void add_class_method_size(int size) {
if (UsePerfData) {
_class_methods_size->inc(size);
}
}
};
// FIXME: make this piece of code to be shared by M&M and JVMTI
class LoadedClassesEnumerator : public StackObj {
private:
static GrowableArray<KlassHandle>* _loaded_classes;
// _current_thread is for creating a KlassHandle with a faster version constructor
static Thread* _current_thread;
GrowableArray<KlassHandle>* _klass_handle_array;
public:
LoadedClassesEnumerator(Thread* cur_thread);
int num_loaded_classes() { return _klass_handle_array->length(); }
KlassHandle get_klass(int index) { return _klass_handle_array->at(index); }
static void add_loaded_class(klassOop k) {
// FIXME: For now - don't include array klasses
// The spec is unclear at this point to count array klasses or not
// and also indirect creation of array of super class and secondaries
//
// for (klassOop l = k; l != NULL; l = Klass::cast(l)->array_klass_or_null()) {
// KlassHandle h(_current_thread, l);
// _loaded_classes->append(h);
// }
KlassHandle h(_current_thread, k);
_loaded_classes->append(h);
}
};
#endif // SHARE_VM_SERVICES_CLASSLOADINGSERVICE_HPP