Skip to content

Commit

Permalink
8252329: runtime/LoadClass/TestResize.java timed out
Browse files Browse the repository at this point in the history
Reviewed-by: hseigel, iklam
  • Loading branch information
coleenp committed Jul 7, 2022
1 parent 3e60e82 commit f93beac
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 29 deletions.
17 changes: 13 additions & 4 deletions src/hotspot/share/classfile/classLoaderData.cpp
Expand Up @@ -992,14 +992,23 @@ void ClassLoaderData::print_on(outputStream* out) const {
}
out->print_cr(" - handles %d", _handles.count());
out->print_cr(" - dependency count %d", _dependency_count);
out->print (" - klasses {");
PrintKlassClosure closure(out);
((ClassLoaderData*)this)->classes_do(&closure);
out->print (" - klasses { ");
if (Verbose) {
PrintKlassClosure closure(out);
((ClassLoaderData*)this)->classes_do(&closure);
} else {
out->print("...");
}
out->print_cr(" }");
out->print_cr(" - packages " INTPTR_FORMAT, p2i(_packages));
out->print_cr(" - module " INTPTR_FORMAT, p2i(_modules));
out->print_cr(" - unnamed module " INTPTR_FORMAT, p2i(_unnamed_module));
out->print_cr(" - dictionary " INTPTR_FORMAT, p2i(_dictionary));
if (_dictionary != nullptr) {
out->print (" - dictionary " INTPTR_FORMAT " ", p2i(_dictionary));
_dictionary->print_size(out);
} else {
out->print_cr(" - dictionary " INTPTR_FORMAT, p2i(_dictionary));
}
if (_jmethod_ids != NULL) {
out->print (" - jmethod count ");
Method::print_jmethod_ids_count(this, out);
Expand Down
8 changes: 6 additions & 2 deletions src/hotspot/share/classfile/dictionary.cpp
Expand Up @@ -586,13 +586,17 @@ void DictionaryEntry::print_count(outputStream *st) {

// ----------------------------------------------------------------------------

void Dictionary::print_size(outputStream* st) const {
st->print_cr("Java dictionary (table_size=%d, classes=%d, resizable=%s)",
table_size(), number_of_entries(), BOOL_TO_STR(_resizable));
}

void Dictionary::print_on(outputStream* st) const {
ResourceMark rm;

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

for (int index = 0; index < table_size(); index++) {
Expand Down
3 changes: 2 additions & 1 deletion src/hotspot/share/classfile/dictionary.hpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -79,6 +79,7 @@ class Dictionary : public Hashtable<InstanceKlass*, mtClass> {
TRAPS);

void print_on(outputStream* st) const;
void print_size(outputStream* st) const;
void verify();

private:
Expand Down
58 changes: 36 additions & 22 deletions test/hotspot/jtreg/runtime/LoadClass/TestResize.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -46,6 +46,7 @@
public class TestResize {

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

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

boolean resized = false;
boolean checked_load_factor = false;

// Split string into lines using platform independent end of line marker.
String[] lines = output.split("\\R");
Expand All @@ -82,45 +84,57 @@ static void analyzeOutputOn(ProcessBuilder pb) throws Exception {
if (line.contains("resizing system dictionaries")) {
resized = true;
}
} else if (resized && line.startsWith("Java dictionary (")) {
// ex. Java dictionary (table_size=10103, classes=5002)
Scanner scanner = new Scanner(line);
scanner.next(); // skip "Java"
scanner.next(); // skip "dictionary"
int table_size = getInt(scanner.next()); // process "(table_size=40423"
int classes = getInt(scanner.next()); // process ", classes=50002"
scanner.close();
} else if (resized) {
int index = -1;
if ((index = line.indexOf("Java dictionary (")) != -1) {
// ex. Java dictionary (table_size=10103, classes=5002)
String dict = line.substring(index);
Scanner scanner = new Scanner(dict);
scanner.next(); // skip "Java"
scanner.next(); // skip "dictionary"
int table_size = getInt(scanner.next()); // process "(table_size=40423"
int classes = getInt(scanner.next()); // process ", classes=50002"
scanner.close();

double loadFactor = (double)classes / (double)table_size;
if (loadFactor > MAX_LOAD_FACTOR) {
checked_load_factor = classes >= CLASSES_TO_LOAD;

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

throw new RuntimeException("Load factor too high, expected MAX " + MAX_LOAD_FACTOR +
", got " + loadFactor + " [table size " + table_size + ", number of clases " + classes + "]");
} else {
System.out.println("PASS table_size: " + table_size + ", classes: " + classes +
", load factor: " + loadFactor + " <= " + MAX_LOAD_FACTOR);
// There are more than one system dictionary to check, so keep looking...
// We've hit an error, so print all of the output.
System.out.println(output);

throw new RuntimeException("Load factor too high, expected MAX " + MAX_LOAD_FACTOR +
", got " + loadFactor + " [table size " + table_size + ", number of clases " + classes + "]");
} else {
checked_load_factor = true;
System.out.println("PASS table_size: " + table_size + ", classes: " + classes +
", load factor: " + loadFactor + " <= " + MAX_LOAD_FACTOR);
// There are more than one system dictionary to check, so keep looking...
}
}
}
}

if (!resized) {
System.out.println("PASS trivially. No resizing occurred, so did not check the load.");
} else {
// Make sure the load factor was checked
if (!checked_load_factor) {
throw new RuntimeException("Test didn't check load factor");
}
}
}

public static void main(String[] args) throws Exception {
// -XX:+PrintSystemDictionaryAtExit will print the details of system dictionary,
// -XX:+PrintClassLoaderDataGraphAtExit will print the summary of the dictionaries,
// that will allow us to calculate the table's load factor.
// -Xlog:safepoint+cleanup will print out cleanup details at safepoint
// that will allow us to detect if the system dictionary resized.
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+PrintSystemDictionaryAtExit",
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+PrintClassLoaderDataGraphAtExit",
"-Xlog:safepoint+cleanup",
"TriggerResize",
"50000");
String.valueOf(CLASSES_TO_LOAD));
analyzeOutputOn(pb);
}
}

1 comment on commit f93beac

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.