应用程序使用Mozilla Rhino版本1.7R4预编译javascript文件并在运行时执行它。在DVM上运行时执行它时,在加载预编译的javascript类文件时会出现以下错误:
12-23 16:34:10.560: W/dalvikvm(12965): VFY: invoke type does not match method type of Lcom/test/converted/script;._c_script_0_literal1
12-23 16:34:10.560: W/dalvikvm(12965): VFY: rejecting opcode 0x6e at 0x000c
12-23 16:34:10.560: W/dalvikvm(12965): VFY: rejected Lcom/test/converted/script;._c_script_0 (Lcom/test/converted/script;Lorg/mozilla/javascript/Context;Lorg/mozilla/javascript/Scriptable;Lorg/mozilla/javascript/Scriptable;[Ljava/lang/Object;)Ljava/lang/Object;
12-23 16:34:10.560: W/dalvikvm(12965): Verifier rejected class Lcom/test/converted/script;
12-23 16:34:10.560: W/System.err(12965): java.lang.ClassNotFoundException: com.test.converted.script
12-23 16:34:10.560: W/System.err(12965): at java.lang.Class.classForName(Native Method)
12-23 16:34:10.560: W/System.err(12965): at java.lang.Class.forName(Class.java:217)
12-23 16:34:10.560: W/System.err(12965): at java.lang.Class.forName(Class.java:172)
12-23 16:34:10.560: W/System.err(12965): at com.notworkingrhino.AppImpl.populateScopeFromCompiledScriptClass(AppImpl.java:36)
12-23 16:34:10.560: W/System.err(12965): at com.notworkingrhino.AppImpl.loadScripts(AppImpl.java:25)
12-23 16:34:10.560: W/System.err(12965): at com.notworkingrhino.AppImpl.onCreate(AppImpl.java:17)
12-23 16:34:10.560: W/System.err(12965): at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:981)
12-23 16:34:10.560: W/System.err(12965): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4522)
12-23 16:34:10.560: W/System.err(12965): at android.app.ActivityThread.access$1300(ActivityThread.java:139)
12-23 16:34:10.560: W/System.err(12965): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1306)
12-23 16:34:10.560: W/System.err(12965): at android.os.Handler.dispatchMessage(Handler.java:99)
12-23 16:34:10.560: W/System.err(12965): at android.os.Looper.loop(Looper.java:156)
12-23 16:34:10.560: W/System.err(12965): at android.app.ActivityThread.main(ActivityThread.java:5005)
12-23 16:34:10.560: W/System.err(12965): at java.lang.reflect.Method.invokeNative(Native Method)
12-23 16:34:10.560: W/System.err(12965): at java.lang.reflect.Method.invoke(Method.java:511)
12-23 16:34:10.560: W/System.err(12965): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
12-23 16:34:10.560: W/System.err(12965): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
12-23 16:34:10.560: W/System.err(12965): at dalvik.system.NativeStart.main(Native Method)
12-23 16:34:10.560: W/System.err(12965): Caused by: java.lang.VerifyError: com/test/converted/script
12-23 16:34:10.560: W/System.err(12965): ... 18 more
在研究更多问题的同时,我发现“_c_script_0_literal1”方法在DVM上产生了一个问题,只有当任何Object Literal在javascript中有超过10个属性时才会生成。如果Object Literal有10个或少于10个属性,那么上面的方法不会在类文件中生成,而且工作正常。
请注意,具有“_c_script_0_literal1”方法的相同类文件在JVM上正常工作,但只会在DVM上产生问题。
供参考,请参考以下两个已编译Mozilla Rhino生成的javascript类文件的jar:
NotWorkingRhinoScripts.jar:包含以下javascript的类文件
var Codes = { ONE:1, 二:2, 三:3, 四:4, 五:5, 六:6, 七:7, 八:8, 九:9, 10:10, 十一:11 };
WorkingRhinoScripts.jar:包含以下javascript的类文件
var Codes = { ONE:1, 二:2, 三:3, 四:4, 五:5, 六:6, 七:7, 八:8, 九:9, 10:10 };