Skip to content

Commit 838f69c

Browse files
committed
8252329: runtime/LoadClass/TestResize.java timed out
Reviewed-by: mbaesken Backport-of: f93beacd2f64aab0f930ac822859380c00c51f0c
1 parent f21f00c commit 838f69c

File tree

4 files changed

+56
-28
lines changed

4 files changed

+56
-28
lines changed

src/hotspot/share/classfile/classLoaderData.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -985,14 +985,23 @@ void ClassLoaderData::print_on(outputStream* out) const {
985985
}
986986
out->print_cr(" - handles %d", _handles.count());
987987
out->print_cr(" - dependency count %d", _dependency_count);
988-
out->print (" - klasses {");
989-
PrintKlassClosure closure(out);
990-
((ClassLoaderData*)this)->classes_do(&closure);
988+
out->print (" - klasses { ");
989+
if (Verbose) {
990+
PrintKlassClosure closure(out);
991+
((ClassLoaderData*)this)->classes_do(&closure);
992+
} else {
993+
out->print("...");
994+
}
991995
out->print_cr(" }");
992996
out->print_cr(" - packages " INTPTR_FORMAT, p2i(_packages));
993997
out->print_cr(" - module " INTPTR_FORMAT, p2i(_modules));
994998
out->print_cr(" - unnamed module " INTPTR_FORMAT, p2i(_unnamed_module));
995-
out->print_cr(" - dictionary " INTPTR_FORMAT, p2i(_dictionary));
999+
if (_dictionary != nullptr) {
1000+
out->print (" - dictionary " INTPTR_FORMAT " ", p2i(_dictionary));
1001+
_dictionary->print_size(out);
1002+
} else {
1003+
out->print_cr(" - dictionary " INTPTR_FORMAT, p2i(_dictionary));
1004+
}
9961005
if (_jmethod_ids != NULL) {
9971006
out->print (" - jmethod count ");
9981007
Method::print_jmethod_ids_count(this, out);

src/hotspot/share/classfile/dictionary.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -586,13 +586,17 @@ void DictionaryEntry::print_count(outputStream *st) {
586586

587587
// ----------------------------------------------------------------------------
588588

589+
void Dictionary::print_size(outputStream* st) const {
590+
st->print_cr("Java dictionary (table_size=%d, classes=%d, resizable=%s)",
591+
table_size(), number_of_entries(), BOOL_TO_STR(_resizable));
592+
}
593+
589594
void Dictionary::print_on(outputStream* st) const {
590595
ResourceMark rm;
591596

592597
assert(loader_data() != NULL, "loader data should not be null");
593598
assert(!loader_data()->has_class_mirror_holder(), "cld should have a ClassLoader holder not a Class holder");
594-
st->print_cr("Java dictionary (table_size=%d, classes=%d, resizable=%s)",
595-
table_size(), number_of_entries(), BOOL_TO_STR(_resizable));
599+
print_size(st);
596600
st->print_cr("^ indicates that initiating loader is different from defining loader");
597601

598602
for (int index = 0; index < table_size(); index++) {

src/hotspot/share/classfile/dictionary.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -79,6 +79,7 @@ class Dictionary : public Hashtable<InstanceKlass*, mtClass> {
7979
TRAPS);
8080

8181
void print_on(outputStream* st) const;
82+
void print_size(outputStream* st) const;
8283
void verify();
8384

8485
private:

test/hotspot/jtreg/runtime/LoadClass/TestResize.java

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
public class TestResize {
4747

4848
static double MAX_LOAD_FACTOR = 5.0; // see _resize_load_trigger in dictionary.cpp
49+
static int CLASSES_TO_LOAD = 30000;
4950

5051
static int getInt(String string) {
5152
int start = 0;
@@ -73,6 +74,7 @@ static void analyzeOutputOn(ProcessBuilder pb) throws Exception {
7374
analyzer.shouldHaveExitValue(0);
7475

7576
boolean resized = false;
77+
boolean checked_load_factor = false;
7678

7779
// Split string into lines using platform independent end of line marker.
7880
String[] lines = output.split("\\R");
@@ -82,45 +84,57 @@ static void analyzeOutputOn(ProcessBuilder pb) throws Exception {
8284
if (line.contains("resizing system dictionaries")) {
8385
resized = true;
8486
}
85-
} else if (resized && line.startsWith("Java dictionary (")) {
86-
// ex. Java dictionary (table_size=10103, classes=5002)
87-
Scanner scanner = new Scanner(line);
88-
scanner.next(); // skip "Java"
89-
scanner.next(); // skip "dictionary"
90-
int table_size = getInt(scanner.next()); // process "(table_size=40423"
91-
int classes = getInt(scanner.next()); // process ", classes=50002"
92-
scanner.close();
87+
} else if (resized) {
88+
int index = -1;
89+
if ((index = line.indexOf("Java dictionary (")) != -1) {
90+
// ex. Java dictionary (table_size=10103, classes=5002)
91+
String dict = line.substring(index);
92+
Scanner scanner = new Scanner(dict);
93+
scanner.next(); // skip "Java"
94+
scanner.next(); // skip "dictionary"
95+
int table_size = getInt(scanner.next()); // process "(table_size=40423"
96+
int classes = getInt(scanner.next()); // process ", classes=50002"
97+
scanner.close();
9398

94-
double loadFactor = (double)classes / (double)table_size;
95-
if (loadFactor > MAX_LOAD_FACTOR) {
99+
checked_load_factor = classes >= CLASSES_TO_LOAD;
96100

97-
// We've hit an error, so print all of the output.
98-
System.out.println(output);
101+
double loadFactor = (double)classes / (double)table_size;
102+
if (loadFactor > MAX_LOAD_FACTOR) {
99103

100-
throw new RuntimeException("Load factor too high, expected MAX " + MAX_LOAD_FACTOR +
101-
", got " + loadFactor + " [table size " + table_size + ", number of clases " + classes + "]");
102-
} else {
103-
System.out.println("PASS table_size: " + table_size + ", classes: " + classes +
104-
", load factor: " + loadFactor + " <= " + MAX_LOAD_FACTOR);
105-
// There are more than one system dictionary to check, so keep looking...
104+
// We've hit an error, so print all of the output.
105+
System.out.println(output);
106+
107+
throw new RuntimeException("Load factor too high, expected MAX " + MAX_LOAD_FACTOR +
108+
", got " + loadFactor + " [table size " + table_size + ", number of clases " + classes + "]");
109+
} else {
110+
checked_load_factor = true;
111+
System.out.println("PASS table_size: " + table_size + ", classes: " + classes +
112+
", load factor: " + loadFactor + " <= " + MAX_LOAD_FACTOR);
113+
// There are more than one system dictionary to check, so keep looking...
114+
}
106115
}
107116
}
108117
}
109118

110119
if (!resized) {
111120
System.out.println("PASS trivially. No resizing occurred, so did not check the load.");
121+
} else {
122+
// Make sure the load factor was checked
123+
if (!checked_load_factor) {
124+
throw new RuntimeException("Test didn't check load factor");
125+
}
112126
}
113127
}
114128

115129
public static void main(String[] args) throws Exception {
116-
// -XX:+PrintSystemDictionaryAtExit will print the details of system dictionary,
130+
// -XX:+PrintClassLoaderDataGraphAtExit will print the summary of the dictionaries,
117131
// that will allow us to calculate the table's load factor.
118132
// -Xlog:safepoint+cleanup will print out cleanup details at safepoint
119133
// that will allow us to detect if the system dictionary resized.
120-
ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder("-XX:+PrintSystemDictionaryAtExit",
134+
ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder("-XX:+PrintClassLoaderDataGraphAtExit",
121135
"-Xlog:safepoint+cleanup",
122136
"TriggerResize",
123-
"50000");
137+
String.valueOf(CLASSES_TO_LOAD));
124138
analyzeOutputOn(pb);
125139
}
126140
}

0 commit comments

Comments
 (0)