1 /* 2 * Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #ifndef SHARE_CLASSFILE_CLASSPRINTER_HPP 26 #define SHARE_CLASSFILE_CLASSPRINTER_HPP 27 28 #include "memory/allStatic.hpp" 29 #include "utilities/globalDefinitions.hpp" 30 31 class InstanceKlass; 32 class Method; 33 class outputStream; 34 class Symbol; 35 36 // ClassPrinter is intended to be called from findclass() and findmethod() 37 // in debug.cpp (inside a debugger, such as gdb). 38 // 39 // The ClassPrinter::print_xxx() functions hold the ClassLoaderDataGraph_lock 40 // (and the ttyLocker if ClassPrinter::PRINT_BYTECODE is selected). A deadlock 41 // may happen if these functions are called in a context where these locks 42 // are already held. Use with caution. 43 44 class ClassPrinter : public AllStatic { 45 class KlassPrintClosure; 46 47 public: 48 49 enum Mode : int { 50 PRINT_METHOD_NAME = 1 << 0, 51 PRINT_BYTECODE = 1 << 1, 52 PRINT_BYTECODE_ADDR = 1 << 2, 53 PRINT_DYNAMIC = 1 << 3, // extra information for invokedynamic (and dynamic constant ...) 54 PRINT_METHOD_HANDLE = 1 << 4, // extra information for invokehandle 55 }; 56 static bool has_mode(int flags, Mode mode) { 57 return (flags & static_cast<int>(mode)) != 0; 58 } 59 60 static void print_flags_help(outputStream* os); 61 62 // Parameters for print_classes() and print_methods(): 63 // 64 // - The patterns are matched by StringUtils::is_star_match() 65 // - class_name_pattern matches Klass::external_name(). E.g., "java/lang/Object" or "*ang/Object" 66 // - method_pattern may optionally include the signature. E.g., "wait", "wait:()V" or "*ai*t:(*)V" 67 // - flags must be OR'ed from ClassPrinter::Mode 68 // 69 // print_classes("java/lang/Object", 0x3, os) -> find j.l.Object and disasm all of its methods 70 // print_methods("*ang/Object*", "wait", 0xff, os) -> detailed disasm of all "wait" methods in j.l.Object 71 // print_methods("*ang/Object*", "wait:(*J*)V", 0x1, os) -> list all "wait" methods in j.l.Object that have a long parameter 72 static void print_classes(const char* class_name_pattern, int flags, outputStream* os); 73 static void print_methods(const char* class_name_pattern, 74 const char* method_pattern, int flags, outputStream* os); 75 }; 76 77 #endif // SHARE_CLASSFILE_CLASSPRINTER_HPP