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