Nashorn caches compiled code? Can I clear the cache?

Attila Szegedi attila.szegedi at oracle.com
Mon Jun 15 07:31:54 UTC 2015


It is absolutely the right place to ask :-)

If you’re programmatically using Nashorn, code is cached within a ScriptEngine instance, so discarding a ScriptEngine and creating a new one will get rid of cached code too.

Hope that helps,
  Attila.

> On Jun 15, 2015, at 5:55 AM, Kaj Magnus Lindberg <kajmagnus79 at gmail.com> wrote:
> 
> Hi,
> 
> Nashorn caches compiled scripts in-meomory somehow right? Is there any way
> to clear this cache?
> 
> I'm wondering, because when Play Framework (that's a Scala web framework)
> reloads my Scala application after I've edited some source code files, all
> Scala and Java classes are properly reloaded. (Play Framework reloads
> classes "live", without terminating the process.) Except for Scala code
> that gets run after I've called back from Nashorn to Scala: when inside
> Nashorn, old code gets reused, Nashorn apparently doesn't know that Play
> Framework wants everyone to refresh all classes.
> 
> So I think perhaps I can tell Nashorn to discard its compiled code cache so
> it starts using the new classes instead. Can I do that somehow? Like,
> `some.package.Nashorn.clearCompiledScriptsCodeCache()`.
> 
> I'm not sure if what I'm asking is a good idea. If not, or if it's just not
> possible, then I suppose I'll have to kill my app instead of just
> "soft-reloading" it, if I've changed anything that Nashorn uses.
> 
> (The effects of Nashorn using old classes, are for example that singletons
> get duplicated: when inside Nashorn, a singleton object resolves to an old
> instance with an old field value = 333, but when outside Nashorn, the
> singleton resolves to a new version of the class with newly added fields
> and the value that was previously 333 now instead correctly shows 444 (I
> edited it to 444).)
> 
> jjs -v
> nashorn 1.8.0_45
> 
> I hope this is the right place to ask. Thanks for building Nashorn and best
> regards,
> KajMagnus



More information about the nashorn-dev mailing list