4646public 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