Closed
Bug 466176
Opened 17 years ago
Closed 7 years ago
Enhancement: Ability to interrupt execution and force a continuation externally
Categories
(Rhino Graveyard :: Core, enhancement)
Tracking
(Not tracked)
RESOLVED
INACTIVE
People
(Reporter: davidparks21, Unassigned)
Details
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3
Build Identifier: 1.7R2-RC1
In 1.7R2-RC1 we now have the ability to handle continuations in Java (bravo for this, great step forward!).
I would love to see this taken one step further - allow us to interrupt execution and force a continuation from an external point (example: from another thread).
I managed to implement this feature using hack method as follows to demonstrate feasibility:
1) In the Interpreter (in the interpretLoop method, on line "int op = iCode[frame.pc++];") I watch for a flag to be set requesting interruption.
2) I then watch each subsequent operation (op code) for the value Icode_LINE. When I find it I set another flag and continue processing Icode_LINE.
3) On the next iteration of the loop I now know that I am not in a place where injecting a function call could cause any harm (e.g. registers are clean and such).
4) Instead of processing the next iCode[frame++], I inject the following sequence of steps to execute a JS function (object and method names in this example are take from your example ContinuationsApiTest.class). Assumming that myObject and function f() have been added to the scope chain as is done in the test case mentioned:
a) set stringReg="myObject" (since Icode_LINE was just executed we know that the stringReg isn't currently being used).
b) op = Token.NAME
c) run the loop to perform the NAME lookup on "myObject", and again interject on the next loop
e) set stringReg="f"
f) set op = Icode_PROP_AND_THIS and process the operation, interjecting on the next loop
g) set op = Icode_REG_IND_C0, process it again
h) set op = Token.CALL and process again - this will execute the function myObject.f() which will force the continuation successfully.
i) The next interpreter instruction will be in this same frame, so we finish it off by setting op = Icode_POP_RESULT, clear the flags and let execution continue.
Reproducible: Always
I realize that there are 100 better ways to implement this feature, the example above only demonstrates that it should be possible to interrupt execution at a "safe" point and process a continuation, therefore it shouldn't take a massive re-coding effort to make possible continuation calls from external sources.
I may be missing some details, or maybe there will simply be some inherent limitations with this feature. But it would give us the ability to control the execution of the javascript interpreter either externally or even from places such as within debugger callbacks or instruction count callbacks.
Comment 1•7 years ago
|
||
Closing. Bug management is now done here:
https://github.com/mozilla/rhino
Status: UNCONFIRMED → RESOLVED
Closed: 7 years ago
Resolution: --- → INACTIVE
You need to log in
before you can comment on or make changes to this bug.
Description
•