在 Javascript 上使用 Rhino 的 evaluateString() 时出现 Android StackOverflow 错误
我正在尝试使用 Android 版 Rhino 来与私人网站上的聊天服务进行交互。我实际上不需要查看应用程序的聊天屏幕,所以这就是为什么我认为 Rhino 可能是一个好方法,因为它隐藏了所有窗口/浏览器内容。
1)这是正确的方法吗?我尝试这个的唯一原因是因为我听说 WebView 不安全/最好的解决方案? (如果这对于我的情况来说根本不正确,请纠正我!)
2)所以我刚刚下载了 javascript 并尝试创建一个 Context 并评估字符串。我有合适的范围等等。此外,我还确保将优化级别设置为 -1,因为 Dalvik 代码不会运行从 Rhino 生成的 JVM 字节码。然而,我得到的错误是这样的:
D/dalvikvm( 465): GC_FOR_MALLOC freed 1840 objects / 326872 bytes in 57ms
I/dalvikvm( 465): threadid=1: stack overflow on call to Lorg/mozilla/javascript/TokenStream;.getChar:I
I/dalvikvm( 465): method requires 36+20+8=64 bytes, fp is 0x4186933c (60 left)
I/dalvikvm( 465): expanding stack end (0x41869300 to 0x41869000)
I/dalvikvm( 465): Shrank stack (to 0x41869300, curFrame is 0x41869754)
D/dalvikvm( 465): GC_FOR_MALLOC freed 5607 objects / 262320 bytes in 47ms
W/dalvikvm( 465): Exception Lorg/mozilla/javascript/EvaluatorException; thrown during Lcom/test/testing/rhinochat/TestChat;.<clinit>
I/dalvikvm( 465): Rejecting re-init on previously-failed class Lcom/test/testing/rhinochat/TestChat; v=0x0
D/AndroidRuntime( 465): Shutting down VM
W/dalvikvm( 465): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
E/AndroidRuntime( 465): FATAL EXCEPTION: main
E/AndroidRuntime( 465): java.lang.NoClassDefFoundError: com.test.testing.rhinochat.TestChat
E/AndroidRuntime( 465): at com.test.testing.rhinochat.TestChatRunner.run(TestChatRunner.java:46)
E/AndroidRuntime( 465): at com.test.testing.rhinochat.StartChat.onCreate(StartChat.java:10)
E/AndroidRuntime( 465): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
E/AndroidRuntime( 465): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
E/AndroidRuntime( 465): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
E/AndroidRuntime( 465): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
E/AndroidRuntime( 465): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
E/AndroidRuntime( 465): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 465): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 465): at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime( 465): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 465): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 465): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime( 465): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
E/AndroidRuntime( 465): at dalvik.system.NativeStart.main(Native Method)
W/ActivityManager( 59): Force finishing activity com.test.testing/.rhinochat.StartChat
W/ActivityManager( 59): Force finishing activity com.test.testing/.RhinoOnAndroidActivity
W/ActivityManager( 59): Activity pause timeout for HistoryRecord{450a1240 com.test.testing/.rhinochat.StartChat}
我已经从 Eclipse 设置了允许的最大堆栈空间(我认为最大长度或类似的荒谬的东西),但仍然得到这个错误。使用各种设备进行测试并得到相同的结果。
这里有一个问题:我在桌面上运行我的代码,即使没有对编译器进行优化,所有内容都可以完美编译和运行。但是当我在 Android 上运行相同的代码时,它崩溃了。 (我已经尝试过模拟器和多个硬件设备)
所以在这一点上我非常困惑。有谁知道为什么会发生这种情况?有没有办法让 Dalvik 在编译/运行这个 javascript 时表现得像 JVM?这是javascript的错吗?如果是这样,为什么我在桌面上使用相同的 JavaScript 时没有遇到相同的错误?
更糟糕的是,我什至不知道如何获得有关 javascript 错误抛出的任何提示,或者堆栈跟踪或任何任何
帮助或提示,我们将不胜感激。
节日快乐,感谢您阅读问题。
i'm trying to use Rhino for Android in order to interact with this Chat service on private website. I don't actually need to look at the chat screen with the app, so that's why i thought maybe Rhino is a good approach because it hides all the window/browsery stuff.
1) is this even the right approach? the only reason i'm trying this is because i've heard that WebViews were not safe/the best solution? (please do correct me on this if this is not true at all for my situation!)
2) so i just downloaded the javascript and tried to create a Context and evaluateString on that. i have the right scope and all that. Furthermore, i also made sure to set the optimization level to -1, because Dalvik code won't run JVM bytecode generated from Rhino. however, the error i'm getting is this:
D/dalvikvm( 465): GC_FOR_MALLOC freed 1840 objects / 326872 bytes in 57ms
I/dalvikvm( 465): threadid=1: stack overflow on call to Lorg/mozilla/javascript/TokenStream;.getChar:I
I/dalvikvm( 465): method requires 36+20+8=64 bytes, fp is 0x4186933c (60 left)
I/dalvikvm( 465): expanding stack end (0x41869300 to 0x41869000)
I/dalvikvm( 465): Shrank stack (to 0x41869300, curFrame is 0x41869754)
D/dalvikvm( 465): GC_FOR_MALLOC freed 5607 objects / 262320 bytes in 47ms
W/dalvikvm( 465): Exception Lorg/mozilla/javascript/EvaluatorException; thrown during Lcom/test/testing/rhinochat/TestChat;.<clinit>
I/dalvikvm( 465): Rejecting re-init on previously-failed class Lcom/test/testing/rhinochat/TestChat; v=0x0
D/AndroidRuntime( 465): Shutting down VM
W/dalvikvm( 465): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
E/AndroidRuntime( 465): FATAL EXCEPTION: main
E/AndroidRuntime( 465): java.lang.NoClassDefFoundError: com.test.testing.rhinochat.TestChat
E/AndroidRuntime( 465): at com.test.testing.rhinochat.TestChatRunner.run(TestChatRunner.java:46)
E/AndroidRuntime( 465): at com.test.testing.rhinochat.StartChat.onCreate(StartChat.java:10)
E/AndroidRuntime( 465): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
E/AndroidRuntime( 465): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
E/AndroidRuntime( 465): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
E/AndroidRuntime( 465): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
E/AndroidRuntime( 465): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
E/AndroidRuntime( 465): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 465): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 465): at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime( 465): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 465): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 465): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime( 465): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
E/AndroidRuntime( 465): at dalvik.system.NativeStart.main(Native Method)
W/ActivityManager( 59): Force finishing activity com.test.testing/.rhinochat.StartChat
W/ActivityManager( 59): Force finishing activity com.test.testing/.RhinoOnAndroidActivity
W/ActivityManager( 59): Activity pause timeout for HistoryRecord{450a1240 com.test.testing/.rhinochat.StartChat}
i've set the max allowed stack space from Eclipse (i think the max long or something ridiculous like that) and still getting this error. tested with various devices and same results.
here's the catch: i run my code on my desktop, and everything compiles and runs perfectly, even with no optimization on compiler. but when i run the SAME EXACT code on Android, it crashes. (i've tried both emulator and multiple hardware devices)
so at this point i'm super stumped. Does anyone have any idea as to why this is happening? is there a way i can make Dalvik behave like JVM when compiling/running this javascript? is this the javascript's fault? and if so, how come i don't get the same error on my desktop with the same javascript?
To make matters worse, i don't even know how to get any hints on what the javascript error is throwing, or a stack trace or anything
ANY help or hints would be severely appreciated.
happy holidays, and thanks for reading the question.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,问题是我没有问正确的问题。我不应该惊慌失措并抛出一堆信息。
事实证明,如果您设置最大堆栈大小,它就会完全被忽略。因此,通过将堆栈大小设置为相当合理的数量,它就会起作用。当然,这需要调整堆栈空间并准确地弄清楚在什么时候事情会起作用。事实证明,使用 100kb 的堆栈空间对我来说已经足够了,因为我也将它放在了一个单独的线程中。
okay, so the problem was that i didn't ask the right question. i shouldn't have freaked out and threw a bunch of information out.
it turns out if you set the max stack size, it just completely gets ignored. so by setting the stack size to a fairly reasonable amount, it'll work. of course, this requires tweaking with the stack space and figuring out exactly at which point things will work. it turns out using 100kb of stack space was enough for me, given that i had also put it in a separate thread.