1
1
/*
2
- * Copyright (c) 2019, 2020 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2019, 2021 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
@@ -97,21 +97,33 @@ public static void launch(String expectedMessage, String... toolArgs)
97
97
launch (expectedMessage , Arrays .asList (toolArgs ));
98
98
}
99
99
100
- public static void printStackTraces (String file ) throws IOException {
100
+ /* Returns false if the attempt should be retried. */
101
+ public static boolean printStackTraces (String file , boolean allowRetry ) throws IOException {
101
102
try {
102
103
String output = HprofReader .getStack (file , 0 );
103
104
// We only require JShellToolProvider to be in the output if we did the
104
105
// short sleep. If we did not, the java process may not have executed far
105
106
// enough along to even start the main thread.
106
107
if (doSleep && !output .contains ("JShellToolProvider" )) {
107
- throw new RuntimeException ("'JShellToolProvider' missing from stdout/stderr" );
108
+ // This check will very rarely fail due to not be able to get the stack trace
109
+ // of the main thread do to it actively executing. See JDK-8269556. We retry once
110
+ // if that happens. This failure is so rare that this should be enough to make it
111
+ // extremely unlikely that we ever see this test fail again for this reason.
112
+ if (!allowRetry ) {
113
+ throw new RuntimeException ("'JShellToolProvider' missing from stdout/stderr" );
114
+ } else {
115
+ System .out .println ("'JShellToolProvider' missing. Allow one retry." );
116
+ return true ; // Allow one retry
117
+ }
108
118
}
109
119
} catch (Exception ex ) {
110
120
throw new RuntimeException ("Test ERROR " + ex , ex );
111
121
}
122
+ return false ;
112
123
}
113
124
114
- public static void testHeapDump () throws IOException {
125
+ /* Returns false if the attempt should be retried. */
126
+ public static boolean testHeapDump (boolean allowRetry ) throws IOException {
115
127
File hprofFile = new File ("jhsdb.jmap.heap." +
116
128
System .currentTimeMillis () + ".hprof" );
117
129
if (hprofFile .exists ()) {
@@ -124,10 +136,12 @@ public static void testHeapDump() throws IOException {
124
136
assertTrue (hprofFile .exists () && hprofFile .isFile (),
125
137
"Could not create dump file " + hprofFile .getAbsolutePath ());
126
138
127
- printStackTraces (hprofFile .getAbsolutePath ());
139
+ boolean retry = printStackTraces (hprofFile .getAbsolutePath (), allowRetry );
128
140
129
141
System .out .println ("hprof file size: " + hprofFile .length ());
130
142
hprofFile .delete ();
143
+
144
+ return retry ;
131
145
}
132
146
133
147
public static void launchJshell () throws IOException {
@@ -149,7 +163,7 @@ public static void launchJshell() throws IOException {
149
163
// Give jshell a chance to fully start up. This makes SA more stable for the jmap dump.
150
164
try {
151
165
if (doSleep ) {
152
- Thread .sleep (2000 );
166
+ Thread .sleep (4000 );
153
167
}
154
168
} catch (Exception e ) {
155
169
}
@@ -166,7 +180,12 @@ public static void main(String[] args) throws Exception {
166
180
} else if (args .length != 0 ) {
167
181
throw new RuntimeException ("Too many args: " + args .length );
168
182
}
169
- testHeapDump ();
183
+
184
+ boolean retry = testHeapDump (true );
185
+ // In case of rare failure to find 'JShellToolProvider' in the output, allow one retry.
186
+ if (retry ) {
187
+ testHeapDump (false );
188
+ }
170
189
171
190
// The test throws RuntimeException on error.
172
191
// IOException is thrown if Jshell can't start because of some bad
0 commit comments