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