Question

Oracle incuded a stripped rhino in jdk6

One of the stripped features is the rhino js to bytecode compiler

Is it possible to include it at application level?

Id like to increase the performance without changing the jsr223 calls

Was it helpful?

Solution

I got it working

basically all you need to do is to include rhino's org.mozilla.javascript.optimizer package.

However this is not as easy as just dropping it into your project, because oracle changed the namespace of the rhino implementation.

So you have to port the package, which includes tons of Strings that point into the wrong namespace (for class generation)

also I needed to inject the Optimizer into the internal rhino context:

Class c = Class.forName("sun.org.mozilla.javascript.internal.Context");
Field field = c.getDeclaredField("codegenClass");
field.setAccessible(true);
field.set(c, org.mozilla.javascript.optimizer.Codegen.class);

there could also be an 'auto inject' way - Rhinos Context class automatically expects the Codegen class in a specific package - it depends on the oracle port of the context class, but i didn't find any sources..

But this apporoach has a big downside:

the codegen port targets a specific rhino version and may not work on all vm versions or may break on a vm update

So i dropped the jsr233 api and used rhino directly as library. I also experienced a big performance increase - i expect that the jsr233 api adds a lot of overhead to some js invocations.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top