简体   繁体   English

Java脚本(jsr223):是否可以(重新)添加rhino编译功能

[英]Java Scripting (jsr223): is it possible to (re)add the rhino compile feature

Oracle incuded a stripped rhino in jdk6 甲骨文在JDK6中发现了犀牛

One of the stripped features is the rhino js to bytecode compiler 剥离的功能之一是Rhino js到字节码编译器

Is it possible to include it at application level? 是否可以在应用程序级别包含它?

Id like to increase the performance without changing the jsr223 calls 我想在不更改jsr223调用的情况下提高性能

I got it working 我知道了

basically all you need to do is to include rhino's org.mozilla.javascript.optimizer package. 基本上,您所需要做的就是包含rhino的org.mozilla.javascript.optimizer软件包。

However this is not as easy as just dropping it into your project, because oracle changed the namespace of the rhino implementation. 但是,这并不像将其放入项目中那样容易,因为oracle更改了rhino实现的名称空间。

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: 我还需要将Optimizer注入内部犀牛环境:

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.. 可能还有一种“自动注入”方式-Rhinos Context类自动期望特定包中的Codegen类-它取决于上下文类的oracle端口,但我没有找到任何源。

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 codegen端口针对特定的Rhino版本,可能无法在所有vm版本上使用,或者可能在vm更新上中断

So i dropped the jsr233 api and used rhino directly as library. 因此,我删除了jsr233 API,并直接将rhino用作库。 I also experienced a big performance increase - i expect that the jsr233 api adds a lot of overhead to some js invocations. 我也经历了很大的性能提升-我希望jsr233 API为某些js调用增加了很多开销。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM