< prev index next >

src/hotspot/share/classfile/classPrinter.cpp

Print this page

 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 #include "precompiled.hpp"
 26 #include "classfile/classLoaderData.hpp"
 27 #include "classfile/classLoaderDataGraph.hpp"
 28 #include "classfile/classPrinter.hpp"
 29 #include "memory/iterator.hpp"
 30 #include "memory/resourceArea.hpp"
 31 #include "oops/instanceKlass.hpp"
 32 #include "oops/klass.hpp"
 33 #include "oops/method.hpp"
 34 #include "oops/symbol.hpp"
 35 #include "utilities/ostream.hpp"
 36 
 37 class ClassPrinter::KlassPrintClosure : public LockedClassesDo {
 38   const char* _class_name_pattern;
 39   const char* _method_name_pattern;
 40   const char* _method_signature_pattern;
 41   bool _always_print_class_name;
 42   int _flags;
 43   outputStream* _st;
 44   int _num;
 45   bool _has_printed_methods;
 46 public:
 47   KlassPrintClosure(const char* class_name_pattern,
 48                     const char* method_name_pattern,
 49                     const char* method_signature_pattern,
 50                     bool always_print_class_name,
 51                     int flags, outputStream* st)
 52     : _class_name_pattern(class_name_pattern),
 53       _method_name_pattern(method_name_pattern),
 54       _method_signature_pattern(method_signature_pattern),
 55       _always_print_class_name(always_print_class_name),
 56       _flags(flags), _st(st), _num(0), _has_printed_methods(false)
 57   {

 58     if (has_mode(_flags, PRINT_METHOD_HANDLE)) {
 59       _flags |= (PRINT_METHOD_NAME | PRINT_BYTECODE);
 60     }
 61     if (has_mode(_flags, PRINT_DYNAMIC)) {
 62       _flags |= (PRINT_METHOD_NAME | PRINT_BYTECODE);
 63     }
 64     if (has_mode(_flags, PRINT_BYTECODE_ADDR)) {
 65       _flags |= (PRINT_METHOD_NAME | PRINT_BYTECODE);
 66     }
 67     if (has_mode(_flags, PRINT_BYTECODE)) {
 68       _flags |= (PRINT_METHOD_NAME);
 69     }
 70   }
 71 
 72   virtual void do_klass(Klass* k) {
 73     if (!k->is_instance_klass()) {
 74       return;
 75     }
 76     print_instance_klass(InstanceKlass::cast(k));
 77   }
 78 
 79   static bool match(const char* pattern, Symbol* sym) {
 80     return (pattern == nullptr || sym->is_star_match(pattern));
 81   }
 82 
 83   void print_klass_name(InstanceKlass* ik) {
 84     _st->print("[%3d] " INTPTR_FORMAT " class %s ", _num++, p2i(ik), ik->name()->as_C_string());

 85     ik->class_loader_data()->print_value_on(_st);
 86     _st->cr();
 87   }
 88 
 89   void print_instance_klass(InstanceKlass* ik) {
 90     if (ik->is_loaded() && ik->name()->is_star_match(_class_name_pattern)) {
 91       ResourceMark rm;
 92       if (_has_printed_methods) {
 93         // We have printed some methods in the previous class.
 94         // Print a new line to separate the two classes
 95         _st->cr();
 96       }
 97       _has_printed_methods = false;
 98       if (_always_print_class_name) {
 99         print_klass_name(ik);
100       }
101 
102       if (has_mode(_flags, ClassPrinter::PRINT_METHOD_NAME)) {
103         bool print_codes = has_mode(_flags, ClassPrinter::PRINT_BYTECODE);
104         int len = ik->methods()->length();

 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 #include "precompiled.hpp"
 26 #include "classfile/classLoaderData.hpp"
 27 #include "classfile/classLoaderDataGraph.hpp"
 28 #include "classfile/classPrinter.hpp"
 29 #include "memory/iterator.hpp"
 30 #include "memory/resourceArea.hpp"
 31 #include "oops/instanceKlass.hpp"
 32 #include "oops/klass.inline.hpp"
 33 #include "oops/method.hpp"
 34 #include "oops/symbol.hpp"
 35 #include "utilities/ostream.hpp"
 36 
 37 class ClassPrinter::KlassPrintClosure : public LockedClassesDo {
 38   const char* _class_name_pattern;
 39   const char* _method_name_pattern;
 40   const char* _method_signature_pattern;
 41   bool _always_print_class_name;
 42   int _flags;
 43   outputStream* _st;
 44   int _num;
 45   bool _has_printed_methods;
 46 public:
 47   KlassPrintClosure(const char* class_name_pattern,
 48                     const char* method_name_pattern,
 49                     const char* method_signature_pattern,
 50                     bool always_print_class_name,
 51                     int flags, outputStream* st)
 52     : _class_name_pattern(class_name_pattern),
 53       _method_name_pattern(method_name_pattern),
 54       _method_signature_pattern(method_signature_pattern),
 55       _always_print_class_name(always_print_class_name),
 56       _flags(flags), _st(st), _num(0), _has_printed_methods(false)
 57   {
 58     _flags |= (PRINT_PROFILE);
 59     if (has_mode(_flags, PRINT_METHOD_HANDLE)) {
 60       _flags |= (PRINT_METHOD_NAME | PRINT_BYTECODE);
 61     }
 62     if (has_mode(_flags, PRINT_DYNAMIC)) {
 63       _flags |= (PRINT_METHOD_NAME | PRINT_BYTECODE);
 64     }
 65     if (has_mode(_flags, PRINT_BYTECODE_ADDR)) {
 66       _flags |= (PRINT_METHOD_NAME | PRINT_BYTECODE);
 67     }
 68     if (has_mode(_flags, PRINT_BYTECODE)) {
 69       _flags |= (PRINT_METHOD_NAME);
 70     }
 71   }
 72 
 73   virtual void do_klass(Klass* k) {
 74     if (!k->is_instance_klass()) {
 75       return;
 76     }
 77     print_instance_klass(InstanceKlass::cast(k));
 78   }
 79 
 80   static bool match(const char* pattern, Symbol* sym) {
 81     return (pattern == nullptr || sym->is_star_match(pattern));
 82   }
 83 
 84   void print_klass_name(InstanceKlass* ik) {
 85     _st->print("[%3d] " INTPTR_FORMAT " class %s mirror: " INTPTR_FORMAT " ", _num++,
 86                p2i(ik), ik->name()->as_C_string(), p2i(ik->java_mirror()));
 87     ik->class_loader_data()->print_value_on(_st);
 88     _st->cr();
 89   }
 90 
 91   void print_instance_klass(InstanceKlass* ik) {
 92     if (ik->is_loaded() && ik->name()->is_star_match(_class_name_pattern)) {
 93       ResourceMark rm;
 94       if (_has_printed_methods) {
 95         // We have printed some methods in the previous class.
 96         // Print a new line to separate the two classes
 97         _st->cr();
 98       }
 99       _has_printed_methods = false;
100       if (_always_print_class_name) {
101         print_klass_name(ik);
102       }
103 
104       if (has_mode(_flags, ClassPrinter::PRINT_METHOD_NAME)) {
105         bool print_codes = has_mode(_flags, ClassPrinter::PRINT_BYTECODE);
106         int len = ik->methods()->length();
< prev index next >