Skip to content

Commit ba303c0

Browse files
Matias Saavedra Silvacoleenp
Matias Saavedra Silva
authored andcommitted
8295893: Improve printing of Constant Pool Cache Entries
Reviewed-by: dholmes, coleenp, iklam
1 parent f8b2574 commit ba303c0

File tree

2 files changed

+103
-22
lines changed

2 files changed

+103
-22
lines changed

src/hotspot/share/oops/cpCache.cpp

+37-22
Original file line numberDiff line numberDiff line change
@@ -623,31 +623,46 @@ Method* ConstantPoolCacheEntry::get_interesting_method_entry() {
623623
void ConstantPoolCacheEntry::print(outputStream* st, int index, const ConstantPoolCache* cache) const {
624624
// print separator
625625
if (index == 0) st->print_cr(" -------------");
626-
// print entry
627-
st->print("%3d (" PTR_FORMAT ") ", index, (intptr_t)this);
628-
st->print_cr("[%02x|%02x|%5d]", bytecode_2(), bytecode_1(),
629-
constant_pool_index());
630-
st->print_cr(" [ " PTR_FORMAT "]", (intptr_t)_f1);
631-
st->print_cr(" [ " PTR_FORMAT "]", (intptr_t)_f2);
632-
st->print_cr(" [ " PTR_FORMAT "]", (intptr_t)_flags);
633-
634-
if ((bytecode_1() == Bytecodes::_invokehandle ||
635-
bytecode_1() == Bytecodes::_invokedynamic)) {
626+
// print universal entry info
627+
st->print_cr("%3d", index);
628+
st->print_cr(" - this: " PTR_FORMAT, p2i(this));
629+
st->print_cr(" - bytecode 1: %s %02x", Bytecodes::name(bytecode_1()), bytecode_1());
630+
st->print_cr(" - bytecode 2: %s %02x", Bytecodes::name(bytecode_2()), bytecode_2());
631+
st->print_cr(" - cp index: %5d", constant_pool_index());
632+
if (is_method_entry()) {
633+
ResourceMark rm;
636634
constantPoolHandle cph(Thread::current(), cache->constant_pool());
637635
Method* m = method_if_resolved(cph);
638-
oop appendix = appendix_if_resolved(cph);
639-
ResourceMark rm;
640-
if (m != NULL) {
641-
st->print_cr(" Method%s: " INTPTR_FORMAT " %s.%s%s",
642-
m->is_native() ? " (native)" : "",
643-
p2i(m),
644-
m->method_holder()->name()->as_C_string(),
645-
m->name()->as_C_string(), m->signature()->as_C_string());
646-
}
647-
if (appendix != NULL) {
648-
st->print(" appendix: ");
649-
appendix->print_on(st);
636+
st->print_cr(" - F1: [ " PTR_FORMAT "]", (intptr_t)_f1);
637+
st->print_cr(" - F2: [ " PTR_FORMAT "]", (intptr_t)_f2);
638+
st->print_cr(" - method: " INTPTR_FORMAT " %s", p2i(m), m != nullptr ? m->external_name() : nullptr);
639+
st->print_cr(" - flag values: [%02x|0|0|%01x|%01x|%01x|%01x|0|%01x|%01x|00|00|%02x]",
640+
flag_state(), has_local_signature(), has_appendix(),
641+
is_forced_virtual(), is_final(), is_vfinal(),
642+
indy_resolution_failed(), parameter_size());
643+
st->print_cr(" - tos: %s\n - local signature: %01x\n"
644+
" - has appendix: %01x\n - forced virtual: %01x\n"
645+
" - final: %01x\n - virtual final: %01x\n - resolution failed: %01x\n"
646+
" - num parameters: %02x",
647+
type2name(as_BasicType(flag_state())), has_local_signature(), has_appendix(),
648+
is_forced_virtual(), is_final(), is_vfinal(),
649+
indy_resolution_failed(), parameter_size());
650+
if (bytecode_1() == Bytecodes::_invokehandle ||
651+
bytecode_1() == Bytecodes::_invokedynamic) {
652+
oop appendix = appendix_if_resolved(cph);
653+
if (appendix != nullptr) {
654+
st->print(" appendix: ");
655+
appendix->print_on(st);
656+
}
650657
}
658+
} else {
659+
assert(is_field_entry(), "must be a field entry");
660+
st->print_cr(" - F1: [ " PTR_FORMAT "]", (intptr_t)_f1);
661+
st->print_cr(" - F2: [ " PTR_FORMAT "]", (intptr_t)_f2);
662+
st->print_cr(" - flag values: [%02x|0|1|0|0|0|%01x|%01x|0|0|%04x]",
663+
flag_state(), is_final(), is_volatile(), field_index());
664+
st->print_cr(" - tos: %s\n - final: %d\n - volatile: %d\n - field index: %04x",
665+
type2name(as_BasicType(flag_state())), is_final(), is_volatile(), field_index());
651666
}
652667
st->print_cr(" -------------");
653668
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright (c) 2022, 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+
#include "precompiled.hpp"
24+
#include "classfile/vmClasses.hpp"
25+
#include "memory/resourceArea.hpp"
26+
#include "oops/constantPool.hpp"
27+
#include "oops/cpCache.hpp"
28+
#include "oops/method.hpp"
29+
#include "runtime/javaThread.hpp"
30+
#include "runtime/interfaceSupport.inline.hpp"
31+
#include "utilities/ostream.hpp"
32+
#include "unittest.hpp"
33+
34+
// Tests for ConstantPoolCache::print_on() function
35+
TEST_VM(ConstantPoolCache, print_on) {
36+
JavaThread* THREAD = JavaThread::current();
37+
ThreadInVMfromNative invm(THREAD);
38+
ResourceMark rm;
39+
stringStream ss;
40+
41+
InstanceKlass* klass = vmClasses::System_klass();
42+
klass->constants()->cache()->print_on(&ss);
43+
44+
const char* output = ss.freeze();
45+
// method entry test
46+
ASSERT_TRUE(strstr(output, "this") != NULL) << "must have \"this\"";
47+
ASSERT_TRUE(strstr(output, "bytecode 1:") != NULL) << "must have \"bytecode 1\"";
48+
ASSERT_TRUE(strstr(output, "bytecode 2:") != NULL) << "must have \"bytecode 2\"";
49+
ASSERT_TRUE(strstr(output, "cp index:") != NULL) << "must have constant pool index";
50+
ASSERT_TRUE(strstr(output, "F1:") != NULL) << "must have F1 value";
51+
ASSERT_TRUE(strstr(output, "F2:") != NULL) << "must have F2 value";
52+
ASSERT_TRUE(strstr(output, "method:") != NULL) << "must have a method";
53+
ASSERT_TRUE(strstr(output, "flag values:") != NULL) << "must have a flag";
54+
ASSERT_TRUE(strstr(output, "tos:") != NULL) << "must have result type";
55+
ASSERT_TRUE(strstr(output, "local signature:") != NULL) << "must have local signature flag";
56+
ASSERT_TRUE(strstr(output, "has appendix:") != NULL) << "must have appendix flag";
57+
ASSERT_TRUE(strstr(output, "forced virtual:") != NULL) << "must have forced virtual flag";
58+
ASSERT_TRUE(strstr(output, "final:") != NULL) << "must have final flag";
59+
ASSERT_TRUE(strstr(output, "virtual final:") != NULL) << "must have virtual final flag";
60+
ASSERT_TRUE(strstr(output, "resolution failed:") != NULL) << "must have resolution failed flag";
61+
ASSERT_TRUE(strstr(output, "num parameters:") != NULL) << "must have number of parameters";
62+
63+
// field entry test
64+
ASSERT_TRUE(strstr(output, "volatile:") != NULL) << "must have volatile flag";
65+
ASSERT_TRUE(strstr(output, "field index:") != NULL) << "must have field index";
66+
}

0 commit comments

Comments
 (0)