Last Comment Bug 397680 - Need to support Context.observeInstructionCount for compiled mode
: Need to support Context.observeInstructionCount for compiled mode
Status: RESOLVED FIXED
:
Product: Rhino
Classification: Components
Component: Compiler (show other bugs)
: 1.6R6
: x86 All
: -- enhancement (vote)
: ---
Assigned To: Nobody; OK to take it and work on it
:
Mentors:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2007-09-26 12:59 PDT by Norris Boyd
Modified: 2007-10-05 12:40 PDT (History)
2 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---


Attachments
A Patch for Codegen.java (158.87 KB, patch)
2007-10-03 14:23 PDT, Ohad Serfaty
no flags Details | Diff | Review
Patch to ScriptRuntime.java (122.25 KB, patch)
2007-10-03 14:25 PDT, Ohad Serfaty
no flags Details | Diff | Review
PAtch to compilerEnviros.java (6.24 KB, patch)
2007-10-03 14:26 PDT, Ohad Serfaty
no flags Details | Diff | Review
PAtch to Context.java (90.49 KB, application/octet-stream)
2007-10-03 14:27 PDT, Ohad Serfaty
no flags Details

Description Norris Boyd 2007-09-26 12:59:42 PDT
from mozilla.dev.tech.js-engine:

> 3. stopping the script in higher optimized code is impossible under
> the current rhino conditions. I can use the Thread.stop() method but
> am reluctant to do so as it is unsafe. Is it possible to have a stop()
> or interrupt() function to stop execution of a malicious script thats
> running in highly optimized  context ?

You're right that this is a feature request and a good one. The right
way to do this is to implement Context.observeInstructionCount for
compiled mode. There would need to be some way to indicate to the
compiler that you'd like to observe the count, and then compile in
callbacks from the generated Java classes at key points (backwards
jumps, function returns) that increment a counter by some value that
approximates the count of executed Java instructions. The runtime
could then monitor these like is already done for interpreted scripts.
Comment 2 Ohad Serfaty 2007-10-03 14:23:17 PDT
Created attachment 283434 [details] [diff] [review]
A Patch for Codegen.java

the function addInstructionCount adds a call in the compiled call to ScriptRuntime to append the number of instructions that is appropriate
Comment 3 Ohad Serfaty 2007-10-03 14:25:16 PDT
Created attachment 283435 [details] [diff] [review]
Patch to ScriptRuntime.java

Added the function that is being called by the compiled class - and adds the instruction count that is given by the argument.
Comment 4 Ohad Serfaty 2007-10-03 14:26:20 PDT
Created attachment 283437 [details] [diff] [review]
PAtch to compilerEnviros.java
Comment 5 Ohad Serfaty 2007-10-03 14:27:19 PDT
Created attachment 283438 [details]
PAtch to Context.java
Comment 6 Norris Boyd 2007-10-05 12:40:56 PDT
I changed the approach a bit and added some additional supporting code. 

Committed:

Checking in src/org/mozilla/javascript/CompilerEnvirons.java;
/cvsroot/mozilla/js/rhino/src/org/mozilla/javascript/CompilerEnvirons.java,v  <--  CompilerEnvirons.java
new revision: 1.17; previous revision: 1.16
done
Checking in src/org/mozilla/javascript/Context.java;
/cvsroot/mozilla/js/rhino/src/org/mozilla/javascript/Context.java,v  <--  Context.java
new revision: 1.261; previous revision: 1.260
done
Checking in src/org/mozilla/javascript/ScriptRuntime.java;
/cvsroot/mozilla/js/rhino/src/org/mozilla/javascript/ScriptRuntime.java,v  <--  ScriptRuntime.java
new revision: 1.278; previous revision: 1.277
done
Checking in src/org/mozilla/javascript/optimizer/Codegen.java;
/cvsroot/mozilla/js/rhino/src/org/mozilla/javascript/optimizer/Codegen.java,v  <--  Codegen.java
new revision: 1.256; previous revision: 1.255
done
Checking in toolsrc/org/mozilla/javascript/tools/jsc/Main.java;
/cvsroot/mozilla/js/rhino/toolsrc/org/mozilla/javascript/tools/jsc/Main.java,v  <--  Main.java
new revision: 1.14; previous revision: 1.13
done
Checking in toolsrc/org/mozilla/javascript/tools/resources/Messages.properties;
/cvsroot/mozilla/js/rhino/toolsrc/org/mozilla/javascript/tools/resources/Messages.properties,v  <--  Messages.properties
new revision: 1.32; previous revision: 1.31
done

Note You need to log in before you can comment on or make changes to this bug.