Fix occasional stack overflow during Compiler::restoreState
@@ -3646,31 +3646,38 @@ public class Compiler extends AbstractCompiler implements ErrorHandler, SourceFi
});
}
- @GwtIncompatible("ObjectInputStream")
+ @GwtIncompatible("ClassNotFoundException")
public void restoreState(InputStream inputStream) throws IOException, ClassNotFoundException {
initWarningsGuard(options.getWarningsGuard());
maybeSetTracker();
- CompilerState compilerState =
runInCompilerThread(
() -> {
Tracer tracer = newTracer(PassNames.DESERIALIZE_COMPILER_STATE);
logger.fine("Deserializing the CompilerState");
try {
- // Do not close the input stream, caller is responsible for closing it.
- return (CompilerState) new ObjectInputStream(inputStream).readObject();
+ deserializeCompilerState(inputStream);
+ return null;
} finally {
logger.fine("Finished deserializing CompilerState");
stopTracer(tracer, PassNames.DESERIALIZE_COMPILER_STATE);
}
});
+ if (tracker != null) {
+ tracker.updateAfterDeserialize(jsRoot);
+ }
+ }
+
+ @GwtIncompatible("ObjectInputStream")
+ // this method must be called from within a "compiler thread" with a larger stack
+ private void deserializeCompilerState(InputStream inputStream)
+ throws IOException, ClassNotFoundException {
+ // Do not close the input stream, caller is responsible for closing it.
+ CompilerState compilerState = (CompilerState) new ObjectInputStream(inputStream).readObject();
+
TypedAstDeserializer.DeserializedAst deserializedAst =
- runInCompilerThread(
- () -> {
- Tracer tracer = newTracer("deserializeTypedAst");
- try {
- return TypedAstDeserializer.deserializeFullAst(
+ TypedAstDeserializer.deserializeFullAst(
this,
SYNTHETIC_EXTERNS_FILE,
// pass an empty list instead of any existing SourceFile objects.
@@ -3681,10 +3688,6 @@ public class Compiler extends AbstractCompiler implements ErrorHandler, SourceFi
ImmutableList.of(),
inputStream,
compilerState.typeCheckingHasRun);
- } finally {
- stopTracer(tracer, "deserializeTypedAst");
- }
- });
featureSet = compilerState.featureSet;
scriptNodeByFilename.clear();
@@ -3767,10 +3770,6 @@ public class Compiler extends AbstractCompiler implements ErrorHandler, SourceFi
.getFirstChild()
.getChildAtIndex(compilerState.lastInjectedLibraryIndexInFirstScript)
: null;
-
- if (tracker != null) {
- tracker.updateAfterDeserialize(jsRoot);
- }
}
/** Returns the module type for the provided namespace. */
