Mon, 12 Aug 2019 18:30:40 +0300
8223147: JFR Backport
8199712: Flight Recorder
8203346: JFR: Inconsistent signature of jfr_add_string_constant
8195817: JFR.stop should require name of recording
8195818: JFR.start should increase autogenerated name by one
8195819: Remove recording=x from jcmd JFR.check output
8203921: JFR thread sampling is missing fixes from JDK-8194552
8203929: Limit amount of data for JFR.dump
8203664: JFR start failure after AppCDS archive created with JFR StartFlightRecording
8003209: JFR events for network utilization
8207392: [PPC64] Implement JFR profiling
8202835: jfr/event/os/TestSystemProcess.java fails on missing events
Summary: Backport JFR from JDK11. Initial integration
Reviewed-by: neugens
dbuck@9063 | 1 | /* |
dbuck@9063 | 2 | * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved. |
dbuck@9063 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
dbuck@9063 | 4 | * |
dbuck@9063 | 5 | * This code is free software; you can redistribute it and/or modify it |
dbuck@9063 | 6 | * under the terms of the GNU General Public License version 2 only, as |
dbuck@9063 | 7 | * published by the Free Software Foundation. |
dbuck@9063 | 8 | * |
dbuck@9063 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
dbuck@9063 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
dbuck@9063 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
dbuck@9063 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
dbuck@9063 | 13 | * accompanied this code). |
dbuck@9063 | 14 | * |
dbuck@9063 | 15 | * You should have received a copy of the GNU General Public License version |
dbuck@9063 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
dbuck@9063 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
dbuck@9063 | 18 | * |
dbuck@9063 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
dbuck@9063 | 20 | * or visit www.oracle.com if you need additional information or have any |
dbuck@9063 | 21 | * questions. |
dbuck@9063 | 22 | * |
dbuck@9063 | 23 | */ |
dbuck@9063 | 24 | |
dbuck@9063 | 25 | #include "precompiled.hpp" |
dbuck@9063 | 26 | #include "classfile/classLoaderStats.hpp" |
dbuck@9063 | 27 | #include "utilities/globalDefinitions.hpp" |
dbuck@9063 | 28 | |
dbuck@9063 | 29 | |
dbuck@9063 | 30 | class ClassStatsClosure : public KlassClosure { |
dbuck@9063 | 31 | public: |
dbuck@9063 | 32 | int _num_classes; |
dbuck@9063 | 33 | |
dbuck@9063 | 34 | ClassStatsClosure() : |
dbuck@9063 | 35 | _num_classes(0) { |
dbuck@9063 | 36 | } |
dbuck@9063 | 37 | |
dbuck@9063 | 38 | virtual void do_klass(Klass* k) { |
dbuck@9063 | 39 | _num_classes++; |
dbuck@9063 | 40 | } |
dbuck@9063 | 41 | }; |
dbuck@9063 | 42 | |
dbuck@9063 | 43 | |
dbuck@9063 | 44 | void ClassLoaderStatsClosure::do_cld(ClassLoaderData* cld) { |
dbuck@9063 | 45 | oop cl = cld->class_loader(); |
dbuck@9063 | 46 | ClassLoaderStats* cls; |
dbuck@9063 | 47 | |
dbuck@9063 | 48 | // The hashtable key is the ClassLoader oop since we want to account |
dbuck@9063 | 49 | // for "real" classes and anonymous classes together |
dbuck@9063 | 50 | ClassLoaderStats** cls_ptr = _stats->get(cl); |
dbuck@9063 | 51 | if (cls_ptr == NULL) { |
dbuck@9063 | 52 | cls = new ClassLoaderStats(); |
dbuck@9063 | 53 | _stats->put(cl, cls); |
dbuck@9063 | 54 | _total_loaders++; |
dbuck@9063 | 55 | } else { |
dbuck@9063 | 56 | cls = *cls_ptr; |
dbuck@9063 | 57 | } |
dbuck@9063 | 58 | |
dbuck@9063 | 59 | if (!cld->is_anonymous()) { |
dbuck@9063 | 60 | cls->_cld = cld; |
dbuck@9063 | 61 | } |
dbuck@9063 | 62 | |
dbuck@9063 | 63 | cls->_class_loader = cl; |
dbuck@9063 | 64 | if (cl != NULL) { |
dbuck@9063 | 65 | cls->_parent = java_lang_ClassLoader::parent(cl); |
dbuck@9063 | 66 | addEmptyParents(cls->_parent); |
dbuck@9063 | 67 | } |
dbuck@9063 | 68 | |
dbuck@9063 | 69 | ClassStatsClosure csc; |
dbuck@9063 | 70 | cld->classes_do(&csc); |
dbuck@9063 | 71 | if(cld->is_anonymous()) { |
dbuck@9063 | 72 | cls->_anon_classes_count += csc._num_classes; |
dbuck@9063 | 73 | } else { |
dbuck@9063 | 74 | cls->_classes_count = csc._num_classes; |
dbuck@9063 | 75 | } |
dbuck@9063 | 76 | _total_classes += csc._num_classes; |
dbuck@9063 | 77 | |
dbuck@9063 | 78 | Metaspace* ms = cld->metaspace_or_null(); |
dbuck@9063 | 79 | if (ms != NULL) { |
dbuck@9063 | 80 | if(cld->is_anonymous()) { |
dbuck@9063 | 81 | cls->_anon_chunk_sz += ms->allocated_chunks_bytes(); |
dbuck@9063 | 82 | cls->_anon_block_sz += ms->allocated_blocks_bytes(); |
dbuck@9063 | 83 | } else { |
dbuck@9063 | 84 | cls->_chunk_sz = ms->allocated_chunks_bytes(); |
dbuck@9063 | 85 | cls->_block_sz = ms->allocated_blocks_bytes(); |
dbuck@9063 | 86 | } |
dbuck@9063 | 87 | _total_chunk_sz += ms->allocated_chunks_bytes(); |
dbuck@9063 | 88 | _total_block_sz += ms->allocated_blocks_bytes(); |
dbuck@9063 | 89 | } |
dbuck@9063 | 90 | } |
dbuck@9063 | 91 | |
dbuck@9063 | 92 | |
dbuck@9063 | 93 | // Handles the difference in pointer width on 32 and 64 bit platforms |
dbuck@9063 | 94 | #ifdef _LP64 |
dbuck@9063 | 95 | #define SPACE "%8s" |
dbuck@9063 | 96 | #else |
dbuck@9063 | 97 | #define SPACE "%s" |
dbuck@9063 | 98 | #endif |
dbuck@9063 | 99 | |
dbuck@9063 | 100 | |
dbuck@9063 | 101 | bool ClassLoaderStatsClosure::do_entry(oop const& key, ClassLoaderStats* const& cls) { |
dbuck@9063 | 102 | Klass* class_loader_klass = (cls->_class_loader == NULL ? NULL : cls->_class_loader->klass()); |
dbuck@9063 | 103 | Klass* parent_klass = (cls->_parent == NULL ? NULL : cls->_parent->klass()); |
dbuck@9063 | 104 | |
dbuck@9063 | 105 | _out->print(INTPTR_FORMAT " " INTPTR_FORMAT " " INTPTR_FORMAT " " UINTX_FORMAT_W(6) " " SIZE_FORMAT_W(8) " " SIZE_FORMAT_W(8) " ", |
dbuck@9063 | 106 | p2i(class_loader_klass), p2i(parent_klass), p2i(cls->_cld), |
dbuck@9063 | 107 | cls->_classes_count, |
dbuck@9063 | 108 | cls->_chunk_sz, cls->_block_sz); |
dbuck@9063 | 109 | if (class_loader_klass != NULL) { |
dbuck@9063 | 110 | _out->print("%s", class_loader_klass->external_name()); |
dbuck@9063 | 111 | } else { |
dbuck@9063 | 112 | _out->print("<boot class loader>"); |
dbuck@9063 | 113 | } |
dbuck@9063 | 114 | _out->cr(); |
dbuck@9063 | 115 | if (cls->_anon_classes_count > 0) { |
dbuck@9063 | 116 | _out->print_cr(SPACE SPACE SPACE " " UINTX_FORMAT_W(6) " " SIZE_FORMAT_W(8) " " SIZE_FORMAT_W(8) " + unsafe anonymous classes", |
dbuck@9063 | 117 | "", "", "", |
dbuck@9063 | 118 | cls->_anon_classes_count, |
dbuck@9063 | 119 | cls->_anon_chunk_sz, cls->_anon_block_sz); |
dbuck@9063 | 120 | } |
dbuck@9063 | 121 | return true; |
dbuck@9063 | 122 | } |
dbuck@9063 | 123 | |
dbuck@9063 | 124 | |
dbuck@9063 | 125 | void ClassLoaderStatsClosure::print() { |
dbuck@9063 | 126 | _out->print_cr("ClassLoader" SPACE " Parent" SPACE " CLD*" SPACE " Classes ChunkSz BlockSz Type", "", "", ""); |
dbuck@9063 | 127 | _stats->iterate(this); |
dbuck@9063 | 128 | _out->print("Total = " UINTX_FORMAT_W(-6), _total_loaders); |
dbuck@9063 | 129 | _out->print(SPACE SPACE SPACE " ", "", "", ""); |
dbuck@9063 | 130 | _out->print_cr(UINTX_FORMAT_W(6) " " SIZE_FORMAT_W(8) " " SIZE_FORMAT_W(8) " ", |
dbuck@9063 | 131 | _total_classes, |
dbuck@9063 | 132 | _total_chunk_sz, |
dbuck@9063 | 133 | _total_block_sz); |
dbuck@9063 | 134 | _out->print_cr("ChunkSz: Total size of all allocated metaspace chunks"); |
dbuck@9063 | 135 | _out->print_cr("BlockSz: Total size of all allocated metaspace blocks (each chunk has several blocks)"); |
dbuck@9063 | 136 | } |
dbuck@9063 | 137 | |
dbuck@9063 | 138 | |
dbuck@9063 | 139 | void ClassLoaderStatsClosure::addEmptyParents(oop cl) { |
dbuck@9063 | 140 | while (cl != NULL && java_lang_ClassLoader::loader_data(cl) == NULL) { |
dbuck@9063 | 141 | // This classloader has not loaded any classes |
dbuck@9063 | 142 | ClassLoaderStats** cls_ptr = _stats->get(cl); |
dbuck@9063 | 143 | if (cls_ptr == NULL) { |
dbuck@9063 | 144 | // It does not exist in our table - add it |
dbuck@9063 | 145 | ClassLoaderStats* cls = new ClassLoaderStats(); |
dbuck@9063 | 146 | cls->_class_loader = cl; |
dbuck@9063 | 147 | cls->_parent = java_lang_ClassLoader::parent(cl); |
dbuck@9063 | 148 | _stats->put(cl, cls); |
dbuck@9063 | 149 | _total_loaders++; |
dbuck@9063 | 150 | } |
dbuck@9063 | 151 | |
dbuck@9063 | 152 | cl = java_lang_ClassLoader::parent(cl); |
dbuck@9063 | 153 | } |
dbuck@9063 | 154 | } |
dbuck@9063 | 155 | |
dbuck@9063 | 156 | |
dbuck@9063 | 157 | void ClassLoaderStatsVMOperation::doit() { |
dbuck@9063 | 158 | ClassLoaderStatsClosure clsc (_out); |
dbuck@9063 | 159 | ClassLoaderDataGraph::cld_do(&clsc); |
dbuck@9063 | 160 | clsc.print(); |
dbuck@9063 | 161 | } |
dbuck@9063 | 162 | |
dbuck@9063 | 163 | |
dbuck@9063 | 164 | void ClassLoaderStatsDCmd::execute(DCmdSource source, TRAPS) { |
dbuck@9063 | 165 | ClassLoaderStatsVMOperation op(output()); |
dbuck@9063 | 166 | VMThread::execute(&op); |
dbuck@9063 | 167 | } |