Wed, 03 Jul 2019 20:42:37 +0800
Merge
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. |
aoqi@0 | 8 | * |
aoqi@0 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 13 | * accompanied this code). |
aoqi@0 | 14 | * |
aoqi@0 | 15 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 18 | * |
aoqi@0 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 20 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 21 | * questions. |
aoqi@0 | 22 | * |
aoqi@0 | 23 | */ |
aoqi@0 | 24 | |
aoqi@0 | 25 | #ifndef SHARE_VM_SERVICES_CLASSLOADINGSERVICE_HPP |
aoqi@0 | 26 | #define SHARE_VM_SERVICES_CLASSLOADINGSERVICE_HPP |
aoqi@0 | 27 | |
aoqi@0 | 28 | #include "runtime/handles.hpp" |
aoqi@0 | 29 | #include "runtime/perfData.hpp" |
aoqi@0 | 30 | #include "utilities/growableArray.hpp" |
aoqi@0 | 31 | #include "utilities/macros.hpp" |
aoqi@0 | 32 | |
aoqi@0 | 33 | class InstanceKlass; |
aoqi@0 | 34 | |
aoqi@0 | 35 | // VM monitoring and management support for the Class Loading subsystem |
aoqi@0 | 36 | class ClassLoadingService : public AllStatic { |
aoqi@0 | 37 | private: |
aoqi@0 | 38 | // Counters for classes loaded from class files |
aoqi@0 | 39 | static PerfCounter* _classes_loaded_count; |
aoqi@0 | 40 | static PerfCounter* _classes_unloaded_count; |
aoqi@0 | 41 | static PerfCounter* _classbytes_loaded; |
aoqi@0 | 42 | static PerfCounter* _classbytes_unloaded; |
aoqi@0 | 43 | |
aoqi@0 | 44 | // Counters for classes loaded from shared archive |
aoqi@0 | 45 | static PerfCounter* _shared_classes_loaded_count; |
aoqi@0 | 46 | static PerfCounter* _shared_classes_unloaded_count; |
aoqi@0 | 47 | static PerfCounter* _shared_classbytes_loaded; |
aoqi@0 | 48 | static PerfCounter* _shared_classbytes_unloaded; |
aoqi@0 | 49 | |
aoqi@0 | 50 | static PerfVariable* _class_methods_size; |
aoqi@0 | 51 | |
aoqi@0 | 52 | static size_t compute_class_size(InstanceKlass* k); |
aoqi@0 | 53 | |
aoqi@0 | 54 | public: |
aoqi@0 | 55 | static void init(); |
aoqi@0 | 56 | |
aoqi@0 | 57 | static bool get_verbose() { return TraceClassLoading; } |
aoqi@0 | 58 | static bool set_verbose(bool verbose); |
aoqi@0 | 59 | static void reset_trace_class_unloading() NOT_MANAGEMENT_RETURN; |
aoqi@0 | 60 | |
aoqi@0 | 61 | static jlong loaded_class_count() { |
aoqi@0 | 62 | return _classes_loaded_count->get_value() + _shared_classes_loaded_count->get_value(); |
aoqi@0 | 63 | } |
aoqi@0 | 64 | static jlong unloaded_class_count() { |
aoqi@0 | 65 | return _classes_unloaded_count->get_value() + _shared_classes_unloaded_count->get_value(); |
aoqi@0 | 66 | } |
aoqi@0 | 67 | static jlong loaded_class_bytes() { |
aoqi@0 | 68 | if (UsePerfData) { |
aoqi@0 | 69 | return _classbytes_loaded->get_value() + _shared_classbytes_loaded->get_value(); |
aoqi@0 | 70 | } else { |
aoqi@0 | 71 | return -1; |
aoqi@0 | 72 | } |
aoqi@0 | 73 | } |
aoqi@0 | 74 | static jlong unloaded_class_bytes() { |
aoqi@0 | 75 | if (UsePerfData) { |
aoqi@0 | 76 | return _classbytes_unloaded->get_value() + _shared_classbytes_unloaded->get_value(); |
aoqi@0 | 77 | } else { |
aoqi@0 | 78 | return -1; |
aoqi@0 | 79 | } |
aoqi@0 | 80 | } |
aoqi@0 | 81 | |
aoqi@0 | 82 | static jlong loaded_shared_class_count() { |
aoqi@0 | 83 | return _shared_classes_loaded_count->get_value(); |
aoqi@0 | 84 | } |
aoqi@0 | 85 | static jlong unloaded_shared_class_count() { |
aoqi@0 | 86 | return _shared_classes_unloaded_count->get_value(); |
aoqi@0 | 87 | } |
aoqi@0 | 88 | static jlong loaded_shared_class_bytes() { |
aoqi@0 | 89 | if (UsePerfData) { |
aoqi@0 | 90 | return _shared_classbytes_loaded->get_value(); |
aoqi@0 | 91 | } else { |
aoqi@0 | 92 | return -1; |
aoqi@0 | 93 | } |
aoqi@0 | 94 | } |
aoqi@0 | 95 | static jlong unloaded_shared_class_bytes() { |
aoqi@0 | 96 | if (UsePerfData) { |
aoqi@0 | 97 | return _shared_classbytes_unloaded->get_value(); |
aoqi@0 | 98 | } else { |
aoqi@0 | 99 | return -1; |
aoqi@0 | 100 | } |
aoqi@0 | 101 | } |
aoqi@0 | 102 | static jlong class_method_data_size() { |
aoqi@0 | 103 | return (UsePerfData ? _class_methods_size->get_value() : -1); |
aoqi@0 | 104 | } |
aoqi@0 | 105 | |
aoqi@0 | 106 | static void notify_class_loaded(InstanceKlass* k, bool shared_class) |
aoqi@0 | 107 | NOT_MANAGEMENT_RETURN; |
aoqi@0 | 108 | // All unloaded classes are non-shared |
aoqi@0 | 109 | static void notify_class_unloaded(InstanceKlass* k) NOT_MANAGEMENT_RETURN; |
aoqi@0 | 110 | static void add_class_method_size(int size) { |
aoqi@0 | 111 | #if INCLUDE_MANAGEMENT |
aoqi@0 | 112 | if (UsePerfData) { |
aoqi@0 | 113 | _class_methods_size->inc(size); |
aoqi@0 | 114 | } |
aoqi@0 | 115 | #endif // INCLUDE_MANAGEMENT |
aoqi@0 | 116 | } |
aoqi@0 | 117 | }; |
aoqi@0 | 118 | |
aoqi@0 | 119 | // FIXME: make this piece of code to be shared by M&M and JVMTI |
aoqi@0 | 120 | class LoadedClassesEnumerator : public StackObj { |
aoqi@0 | 121 | private: |
aoqi@0 | 122 | static GrowableArray<KlassHandle>* _loaded_classes; |
aoqi@0 | 123 | // _current_thread is for creating a KlassHandle with a faster version constructor |
aoqi@0 | 124 | static Thread* _current_thread; |
aoqi@0 | 125 | |
aoqi@0 | 126 | GrowableArray<KlassHandle>* _klass_handle_array; |
aoqi@0 | 127 | |
aoqi@0 | 128 | public: |
aoqi@0 | 129 | LoadedClassesEnumerator(Thread* cur_thread); |
aoqi@0 | 130 | |
aoqi@0 | 131 | int num_loaded_classes() { return _klass_handle_array->length(); } |
aoqi@0 | 132 | KlassHandle get_klass(int index) { return _klass_handle_array->at(index); } |
aoqi@0 | 133 | |
aoqi@0 | 134 | static void add_loaded_class(Klass* k) { |
aoqi@0 | 135 | // FIXME: For now - don't include array klasses |
aoqi@0 | 136 | // The spec is unclear at this point to count array klasses or not |
aoqi@0 | 137 | // and also indirect creation of array of super class and secondaries |
aoqi@0 | 138 | // |
aoqi@0 | 139 | // for (Klass* l = k; l != NULL; l = l->array_klass_or_null()) { |
aoqi@0 | 140 | // KlassHandle h(_current_thread, l); |
aoqi@0 | 141 | // _loaded_classes->append(h); |
aoqi@0 | 142 | // } |
aoqi@0 | 143 | KlassHandle h(_current_thread, k); |
aoqi@0 | 144 | _loaded_classes->append(h); |
aoqi@0 | 145 | } |
aoqi@0 | 146 | }; |
aoqi@0 | 147 | |
aoqi@0 | 148 | #endif // SHARE_VM_SERVICES_CLASSLOADINGSERVICE_HPP |