Skip to content

Commit ec71e2d

Browse files
author
Daniel D. Daugherty
committed
8271221: [BACKOUT] JDK-8271063 Print injected fields for InstanceKlass
Reviewed-by: coleenp
1 parent f4b3ee5 commit ec71e2d

File tree

4 files changed

+35
-63
lines changed

4 files changed

+35
-63
lines changed

src/hotspot/share/oops/instanceKlass.cpp

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@
8888
#include "utilities/events.hpp"
8989
#include "utilities/macros.hpp"
9090
#include "utilities/stringUtils.hpp"
91-
#include "utilities/pair.hpp"
9291
#ifdef COMPILER1
9392
#include "c1/c1_Compiler.hpp"
9493
#endif
@@ -1624,57 +1623,43 @@ void InstanceKlass::do_local_static_fields(void f(fieldDescriptor*, Handle, TRAP
16241623
}
16251624
}
16261625

1626+
1627+
static int compare_fields_by_offset(int* a, int* b) {
1628+
return a[0] - b[0];
1629+
}
1630+
16271631
void InstanceKlass::do_nonstatic_fields(FieldClosure* cl) {
16281632
InstanceKlass* super = superklass();
16291633
if (super != NULL) {
16301634
super->do_nonstatic_fields(cl);
16311635
}
16321636
fieldDescriptor fd;
16331637
int length = java_fields_count();
1638+
// In DebugInfo nonstatic fields are sorted by offset.
1639+
int* fields_sorted = NEW_C_HEAP_ARRAY(int, 2*(length+1), mtClass);
1640+
int j = 0;
16341641
for (int i = 0; i < length; i += 1) {
16351642
fd.reinitialize(this, i);
16361643
if (!fd.is_static()) {
1637-
cl->do_field(&fd);
1644+
fields_sorted[j + 0] = fd.offset();
1645+
fields_sorted[j + 1] = i;
1646+
j += 2;
16381647
}
16391648
}
1640-
}
1641-
1642-
// first in Pair is offset, second is index.
1643-
static int compare_fields_by_offset(Pair<int,int>* a, Pair<int,int>* b) {
1644-
return a->first - b->first;
1645-
}
1646-
1647-
void InstanceKlass::print_nonstatic_fields(FieldClosure* cl) {
1648-
InstanceKlass* super = superklass();
1649-
if (super != NULL) {
1650-
super->print_nonstatic_fields(cl);
1651-
}
1652-
ResourceMark rm;
1653-
fieldDescriptor fd;
1654-
// In DebugInfo nonstatic fields are sorted by offset.
1655-
GrowableArray<Pair<int,int> > fields_sorted;
1656-
int i = 0;
1657-
for (AllFieldStream fs(this); !fs.done(); fs.next()) {
1658-
if (!fs.access_flags().is_static()) {
1659-
fd = fs.field_descriptor();
1660-
Pair<int,int> f(fs.offset(), fs.index());
1661-
fields_sorted.push(f);
1662-
i++;
1663-
}
1664-
}
1665-
if (i > 0) {
1666-
int length = i;
1667-
assert(length == fields_sorted.length(), "duh");
1649+
if (j > 0) {
1650+
length = j;
16681651
// _sort_Fn is defined in growableArray.hpp.
1669-
fields_sorted.sort(compare_fields_by_offset);
1670-
for (int i = 0; i < length; i++) {
1671-
fd.reinitialize(this, fields_sorted.at(i).second);
1672-
assert(!fd.is_static() && fd.offset() == fields_sorted.at(i).first, "only nonstatic fields");
1652+
qsort(fields_sorted, length/2, 2*sizeof(int), (_sort_Fn)compare_fields_by_offset);
1653+
for (int i = 0; i < length; i += 2) {
1654+
fd.reinitialize(this, fields_sorted[i + 1]);
1655+
assert(!fd.is_static() && fd.offset() == fields_sorted[i], "only nonstatic fields");
16731656
cl->do_field(&fd);
16741657
}
16751658
}
1659+
FREE_C_HEAP_ARRAY(int, fields_sorted);
16761660
}
16771661

1662+
16781663
void InstanceKlass::array_klasses_do(void f(Klass* k, TRAPS), TRAPS) {
16791664
if (array_klasses() != NULL)
16801665
array_klasses()->array_klasses_do(f, THREAD);
@@ -3452,7 +3437,7 @@ void InstanceKlass::print_on(outputStream* st) const {
34523437
st->print_cr(BULLET"---- non-static fields (%d words):", nonstatic_field_size());
34533438
FieldPrinter print_nonstatic_field(st);
34543439
InstanceKlass* ik = const_cast<InstanceKlass*>(this);
3455-
ik->print_nonstatic_fields(&print_nonstatic_field);
3440+
ik->do_nonstatic_fields(&print_nonstatic_field);
34563441

34573442
st->print(BULLET"non-static oop maps: ");
34583443
OopMapBlock* map = start_of_nonstatic_oop_maps();
@@ -3494,20 +3479,30 @@ void InstanceKlass::oop_print_on(oop obj, outputStream* st) {
34943479
st->print(BULLET"string: ");
34953480
java_lang_String::print(obj, st);
34963481
st->cr();
3482+
if (!WizardMode) return; // that is enough
34973483
}
34983484
}
34993485

35003486
st->print_cr(BULLET"---- fields (total size %d words):", oop_size(obj));
35013487
FieldPrinter print_field(st, obj);
3502-
print_nonstatic_fields(&print_field);
3488+
do_nonstatic_fields(&print_field);
35033489

35043490
if (this == vmClasses::Class_klass()) {
35053491
st->print(BULLET"signature: ");
35063492
java_lang_Class::print_signature(obj, st);
35073493
st->cr();
3494+
Klass* mirrored_klass = java_lang_Class::as_Klass(obj);
3495+
st->print(BULLET"fake entry for mirror: ");
3496+
Metadata::print_value_on_maybe_null(st, mirrored_klass);
3497+
st->cr();
3498+
Klass* array_klass = java_lang_Class::array_klass_acquire(obj);
3499+
st->print(BULLET"fake entry for array: ");
3500+
Metadata::print_value_on_maybe_null(st, array_klass);
3501+
st->cr();
3502+
st->print_cr(BULLET"fake entry for oop_size: %d", java_lang_Class::oop_size(obj));
3503+
st->print_cr(BULLET"fake entry for static_oop_field_count: %d", java_lang_Class::static_oop_field_count(obj));
35083504
Klass* real_klass = java_lang_Class::as_Klass(obj);
35093505
if (real_klass != NULL && real_klass->is_instance_klass()) {
3510-
st->print_cr(BULLET"---- static fields (%d words):", java_lang_Class::static_oop_field_count(obj));
35113506
InstanceKlass::cast(real_klass)->do_local_static_fields(&print_field);
35123507
}
35133508
} else if (this == vmClasses::MethodType_klass()) {

src/hotspot/share/oops/instanceKlass.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,6 @@ class InstanceKlass: public Klass {
10071007
void do_local_static_fields(FieldClosure* cl);
10081008
void do_nonstatic_fields(FieldClosure* cl); // including inherited fields
10091009
void do_local_static_fields(void f(fieldDescriptor*, Handle, TRAPS), Handle, TRAPS);
1010-
void print_nonstatic_fields(FieldClosure* cl); // including inherited and injected fields
10111010

10121011
void methods_do(void f(Method* method));
10131012
void array_klasses_do(void f(Klass* k));

src/hotspot/share/runtime/fieldDescriptor.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ void fieldDescriptor::reinitialize(InstanceKlass* ik, int index) {
110110
assert(field_holder() == ik, "must be already initialized to this class");
111111
}
112112
FieldInfo* f = ik->field(index);
113+
assert(!f->is_internal(), "regular Java fields only");
114+
113115
_access_flags = accessFlags_from(f->access_flags());
114116
guarantee(f->name_index() != 0 && f->signature_index() != 0, "bad constant pool index for fieldDescriptor");
115117
_index = index;
@@ -123,16 +125,14 @@ void fieldDescriptor::verify() const {
123125
assert(_index == badInt, "constructor must be called"); // see constructor
124126
} else {
125127
assert(_index >= 0, "good index");
126-
assert(access_flags().is_internal() ||
127-
_index < field_holder()->java_fields_count(), "oob");
128+
assert(_index < field_holder()->java_fields_count(), "oob");
128129
}
129130
}
130131

131132
#endif /* PRODUCT */
132133

133134
void fieldDescriptor::print_on(outputStream* st) const {
134135
access_flags().print_on(st);
135-
if (access_flags().is_internal()) st->print("internal ");
136136
name()->print_value_on(st);
137137
st->print(" ");
138138
signature()->print_value_on(st);

test/hotspot/gtest/oops/test_instanceKlass.cpp

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@
2222
*/
2323

2424
#include "precompiled.hpp"
25-
#include "classfile/systemDictionary.hpp"
2625
#include "classfile/vmClasses.hpp"
2726
#include "memory/resourceArea.hpp"
2827
#include "oops/instanceKlass.hpp"
29-
#include "oops/klass.inline.hpp"
3028
#include "unittest.hpp"
3129

3230
// Tests for InstanceKlass::is_class_loader_instance_klass() function
@@ -39,23 +37,3 @@ TEST_VM(InstanceKlass, string_klass) {
3937
InstanceKlass* klass = vmClasses::String_klass();
4038
ASSERT_TRUE(!klass->is_class_loader_instance_klass());
4139
}
42-
43-
TEST_VM(InstanceKlass, class_loader_printer) {
44-
ResourceMark rm;
45-
oop loader = SystemDictionary::java_platform_loader();
46-
stringStream st;
47-
loader->print_on(&st);
48-
// See if injected loader_data field is printed in string
49-
ASSERT_TRUE(strstr(st.as_string(), "internal 'loader_data'") != NULL) << "Must contain internal fields";
50-
st.reset();
51-
// See if mirror injected fields are printed.
52-
oop mirror = vmClasses::ClassLoader_klass()->java_mirror();
53-
mirror->print_on(&st);
54-
ASSERT_TRUE(strstr(st.as_string(), "internal 'protection_domain'") != NULL) << "Must contain internal fields";
55-
// We should test other printing functions too.
56-
st.reset();
57-
Method* method = vmClasses::ClassLoader_klass()->methods()->at(0); // we know there's a method here!
58-
method->print_on(&st);
59-
ASSERT_TRUE(strstr(st.as_string(), "method holder:") != NULL) << "Must contain method_holder field";
60-
ASSERT_TRUE(strstr(st.as_string(), "'java/lang/ClassLoader'") != NULL) << "Must be in ClassLoader";
61-
}

0 commit comments

Comments
 (0)