Review request for JDK-8133300: Ensure symbol table immutability in Nashorn AST

Attila Szegedi attila.szegedi at
Mon Aug 31 08:58:21 UTC 2015

if the FunctionNode object is set as the cached representation of a RecompilableScriptFunctionData using its setCached method, its IS_CACHED flag is set to true. The flag is used in recompilation to determine the necessary compilation phases: if the function is cached, it means phases in Compiler.COMPILE_UPTO_CACHED were already run on it, so they don't need to be repeated. Otherwise the function is freshly reparsed, so the full compiler pipeline needs to be re-run.

There’s also the issue of re-marking external symbols as globals in RecompilableScriptFunctionData.cloneSymbols(). We normally don’t have to do that – I implemented that back when I was caching pre-pass ASTs. Now that we're only caching AST resulting from lazy compilation, we don't really need it except for split functions, which are incidentally cached from the eager pass :-)

When we lazily compile a function from scratch, all symbols outside of it are considered global (since AssignSymbols won't find them in the enclosing lexical scope, as the enclosing source text is not reparsed). OTOH, if we cache a FunctionNode resulting from the eager first pass, it will have the full lexical scope, so those symbols won't be marked as "global" (which is rather a misnomer at the moment and should be instead considered “external” instead). We need the cached AST and a lazily parsed AST to be identical though, otherwise things break down further down the line. 

Split functions are cached from eager pre-pass (and before they were serialized from eager pre-pass). They didn't suffer from this problem though as AssignSymbols was re-run every time after deserialization. Now however, I moved AssignSymbols to be a pre-cache phase. 

I'll modify the code though so that this marking of external symbols only happens when we cache a split function.


> On Aug 30, 2015, at 3:07 PM, Marcus Lagergren <marcus at> wrote:
> Can you elaborate a bit on the isCached mechanism in FunctionNode?
> /M
>> On 26 Aug 2015, at 14:18, Attila Szegedi <attila.szegedi at> wrote:
>> Please review JDK-8133300 "Ensure symbol table immutability in Nashorn AST" at <> for <>
>> Implementation notes for reviewers are here: < <>>
>> Thanks,
>> Attila.

More information about the nashorn-dev mailing list