The class cache

Hannes Wallnoefer hannes.wallnoefer at oracle.com
Wed Mar 12 09:50:46 UTC 2014


Hi Tal,

I'm right now pushing a change for JDK-8021350 that allows sharing 
script classes between global scopes. Currently, script classes are 
bound to the global object in various ways, so the change is not 
trivial, and it's not possible to share compiled scripts between global 
scopes with the nashorn.jar in current JDK8 builds. The script sharing 
feature is planned for the 8u20 release.

The class sharing will be per script engine, meaning that if you use 
multiple scopes with one script engine classes will be reused, when you 
use multiple script engines scripts will be recompiled for each engine.

I'd be interested to know whether this would work for you. If you'd like 
to test the class sharing feature I can help you getting started.

Hannes

Am 2014-03-12 10:27, schrieb Tal Liron:
> In Nashorn, the ClassCache is set per Global instance.
>
> This is fine if your application has only one global instance. 
> However, my application design involves creating many Global 
> instances. (Actually, I create and destroy them on the fly per user 
> request in an HTTP server scenario.) The problem is that all code has 
> to constantly be recompiled, and the cache is essentially never used. 
> Since recompilation is so very expensive in Nashorn, this results in 
> awful performance.
>
> How can I implement a shared ClassCache? I can't extend and modify 
> Global behavior, because it's a final class.
>
> I've tried to cache ScriptFunction instances myself, but I get 
> exceptions when I try to run them with a different Global instance 
> than the one that created them.



More information about the nashorn-dev mailing list