< prev index next >

src/hotspot/share/classfile/classPrinter.cpp

Print this page

  1 /*
  2  * Copyright (c) 2022, 2025, 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  *

142   void print_klass_name(InstanceKlass* ik) {
143     _st->print("[%3d] " INTPTR_FORMAT " class: %s mirror: " INTPTR_FORMAT " ", _num++,
144                p2i(ik), ik->name()->as_C_string(), p2i(ik->java_mirror()));
145     ik->class_loader_data()->print_value_on(_st);
146     _st->cr();
147   }
148 
149   void print_instance_klass(InstanceKlass* ik) {
150     ResourceMark rm;
151     if (_has_printed_methods) {
152       // We have printed some methods in the previous class.
153       // Print a new line to separate the two classes
154       _st->cr();
155     }
156     _has_printed_methods = false;
157     if (_always_print_class_name) {
158       print_klass_name(ik);
159     }
160 
161     if (has_mode(_flags, ClassPrinter::PRINT_CLASS_DETAILS)) {
162       _st->print("InstanceKlass: ");
163       ik->print_on(_st);
164       oop mirror = ik->java_mirror();
165       if (mirror != nullptr) {
166         _st->print("\nJava mirror oop for %s: ", ik->name()->as_C_string());
167         mirror->print_on(_st);
168       }
169     }
170 
171     if (has_mode(_flags, ClassPrinter::PRINT_METHOD_NAME)) {
172       bool print_codes = has_mode(_flags, ClassPrinter::PRINT_BYTECODE);
173       int len = ik->methods()->length();
174       int num_methods_printed = 0;
175 
176       Method** sorted_methods = NEW_RESOURCE_ARRAY(Method*, len);
177       for (int index = 0; index < len; index++) {
178         sorted_methods[index] = ik->methods()->at(index);
179       }
180 
181       qsort(sorted_methods, len, sizeof(Method*), compare_methods_alphabetically);
182 

  1 /*
  2  * Copyright (c) 2022, 2026, 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  *

142   void print_klass_name(InstanceKlass* ik) {
143     _st->print("[%3d] " INTPTR_FORMAT " class: %s mirror: " INTPTR_FORMAT " ", _num++,
144                p2i(ik), ik->name()->as_C_string(), p2i(ik->java_mirror()));
145     ik->class_loader_data()->print_value_on(_st);
146     _st->cr();
147   }
148 
149   void print_instance_klass(InstanceKlass* ik) {
150     ResourceMark rm;
151     if (_has_printed_methods) {
152       // We have printed some methods in the previous class.
153       // Print a new line to separate the two classes
154       _st->cr();
155     }
156     _has_printed_methods = false;
157     if (_always_print_class_name) {
158       print_klass_name(ik);
159     }
160 
161     if (has_mode(_flags, ClassPrinter::PRINT_CLASS_DETAILS)) {
162       _st->print("InstanceKlass (kind=%d): ", ik->kind());
163       ik->print_on(_st);
164       oop mirror = ik->java_mirror();
165       if (mirror != nullptr) {
166         _st->print("\nJava mirror oop for %s: ", ik->name()->as_C_string());
167         mirror->print_on(_st);
168       }
169     }
170 
171     if (has_mode(_flags, ClassPrinter::PRINT_METHOD_NAME)) {
172       bool print_codes = has_mode(_flags, ClassPrinter::PRINT_BYTECODE);
173       int len = ik->methods()->length();
174       int num_methods_printed = 0;
175 
176       Method** sorted_methods = NEW_RESOURCE_ARRAY(Method*, len);
177       for (int index = 0; index < len; index++) {
178         sorted_methods[index] = ik->methods()->at(index);
179       }
180 
181       qsort(sorted_methods, len, sizeof(Method*), compare_methods_alphabetically);
182 
< prev index next >