JDK-8062393 : Caching code with optimistic.types=true and --lazy-compilation=true generate more code than with --lazy-compilation=false
  • Type: Bug
  • Component: core-libs
  • Sub-Component: jdk.nashorn
  • Affected Version: 8u40,9
  • Priority: P3
  • Status: Resolved
  • Resolution: Won't Fix
  • OS: linux
  • CPU: generic
  • Submitted: 2014-10-29
  • Updated: 2014-11-28
  • Resolved: 2014-11-28
Related Reports
Relates :  
I am not sure, but this situation is not right,
In documentation : 
Use lazy code generation strategies - do not compile the entire script at once.
I ran simple script (nashorn/test/examples/array-micro.js) :

$ jjs --persistent-code-cache=true --lazy-compilation=true --optimistic-types=true  array-micro.js 
after : 
$ ls nashorn_code_cache | wc 
     21      21     710

remove nashorn_code_cache directory...

$ jjs --persistent-code-cache=true --lazy-compilation=false --optimistic-types=true  array-micro.js 
after :
$ ls nashorn_code_cache | wc  
 5       5     168

for jdk9 it is reproduce too.

I've looked at this in depth and there is inherent problem when using persistent code caching with optimistic types and lazy compilation disabled. Optimistic typing operates on a per function basis, i.e. we can only ever generate and store optimistic code one function at a time. With lazy compilation disabled, all functions are loaded when the script is compiled. This means that the only way we ever (re)load a better/later version of a function is by throwing UnwarrantedOptimismException and generating a continuation method for the current function. However, in persistent code store we only store full functions, not continuations (for obvious reasons). Because of this, persistent code store can not fully operate with lazy compilation disabled. I'm closing this bug as won't-fix.