Activate instruction count based thread termination. Replace deprecated context enter()/exit() calls.
This commit is contained in:
parent
33fac6be68
commit
bff550c6d9
2 changed files with 18 additions and 16 deletions
|
@ -131,7 +131,7 @@ public final class RhinoCore implements ScopeProvider {
|
|||
wrapper = new WrapMaker();
|
||||
wrapper.setJavaPrimitiveWrap(false);
|
||||
|
||||
Context context = contextFactory.enter();
|
||||
Context context = contextFactory.enterContext();
|
||||
|
||||
try {
|
||||
// create global object
|
||||
|
@ -182,7 +182,7 @@ public final class RhinoCore implements ScopeProvider {
|
|||
app.logError("Cannot initialize interpreter", e);
|
||||
throw new RuntimeException(e.getMessage(), e);
|
||||
} finally {
|
||||
contextFactory.exit();
|
||||
Context.exit();
|
||||
isInitialized = true;
|
||||
}
|
||||
}
|
||||
|
@ -1124,7 +1124,7 @@ public final class RhinoCore implements ScopeProvider {
|
|||
protected void onContextCreated(Context cx) {
|
||||
cx.setWrapFactory(wrapper);
|
||||
cx.setOptimizationLevel(optLevel);
|
||||
// cx.setInstructionObserverThreshold(5000);
|
||||
cx.setInstructionObserverThreshold(10000);
|
||||
if (cx.isValidLanguageVersion(languageVersion)) {
|
||||
cx.setLanguageVersion(languageVersion);
|
||||
} else {
|
||||
|
@ -1155,9 +1155,11 @@ public final class RhinoCore implements ScopeProvider {
|
|||
* This can be used to customize {@link Context} without introducing
|
||||
* additional subclasses.
|
||||
*/
|
||||
/* protected void observeInstructionCount(Context cx, int instructionCount) {
|
||||
if (instructionCount >= 0xfffffff)
|
||||
throw new EvaluatorException("Exceeded instruction count, interrupting");
|
||||
} */
|
||||
protected void observeInstructionCount(Context cx, int instructionCount) {
|
||||
RhinoEngine engine = RhinoEngine.getRhinoEngine();
|
||||
if (engine != null && engine.thread != Thread.currentThread()) {
|
||||
throw new EvaluatorException("Request timed out");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -86,7 +86,7 @@ public class RhinoEngine implements ScriptingEngine {
|
|||
this.reval = reval;
|
||||
initRhinoCore(app);
|
||||
|
||||
context = core.contextFactory.enter();
|
||||
context = core.contextFactory.enterContext();
|
||||
|
||||
try {
|
||||
extensionGlobals = new HashMap();
|
||||
|
@ -113,7 +113,7 @@ public class RhinoEngine implements ScriptingEngine {
|
|||
app.logError("Cannot initialize interpreter", e);
|
||||
throw new RuntimeException(e.getMessage(), e);
|
||||
} finally {
|
||||
core.contextFactory.exit ();
|
||||
Context.exit();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -162,7 +162,7 @@ public class RhinoEngine implements ScriptingEngine {
|
|||
// (chicken and egg problem, kind of)
|
||||
thread = Thread.currentThread();
|
||||
global = new GlobalObject(core, app, true);
|
||||
context = core.contextFactory.enter();
|
||||
context = core.contextFactory.enterContext();
|
||||
|
||||
if (core.hasTracer) {
|
||||
context.setDebugger(new Tracer(getResponse()), null);
|
||||
|
@ -214,7 +214,7 @@ public class RhinoEngine implements ScriptingEngine {
|
|||
public synchronized void exitContext() {
|
||||
// unregister the engine threadlocal
|
||||
engines.set(null);
|
||||
core.contextFactory.exit();
|
||||
Context.exit();
|
||||
thread = null;
|
||||
global = null;
|
||||
}
|
||||
|
@ -345,7 +345,7 @@ public class RhinoEngine implements ScriptingEngine {
|
|||
* Let the evaluator know that the current evaluation has been
|
||||
* aborted.
|
||||
*/
|
||||
public void abort() {
|
||||
public void abort() {
|
||||
// current request has been aborted.
|
||||
Thread t = thread;
|
||||
// set thread to null
|
||||
|
@ -528,7 +528,7 @@ public class RhinoEngine implements ScriptingEngine {
|
|||
* @throws java.io.IOException
|
||||
*/
|
||||
public void serialize(Object obj, OutputStream out) throws IOException {
|
||||
core.contextFactory.enter();
|
||||
core.contextFactory.enterContext();
|
||||
engines.set(this);
|
||||
try {
|
||||
// use a special ScriptableOutputStream that unwraps Wrappers
|
||||
|
@ -557,7 +557,7 @@ public class RhinoEngine implements ScriptingEngine {
|
|||
sout.writeObject(obj);
|
||||
sout.flush();
|
||||
} finally {
|
||||
core.contextFactory.exit();
|
||||
Context.exit();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -571,7 +571,7 @@ public class RhinoEngine implements ScriptingEngine {
|
|||
* @throws java.io.IOException
|
||||
*/
|
||||
public Object deserialize(InputStream in) throws IOException, ClassNotFoundException {
|
||||
core.contextFactory.enter();
|
||||
core.contextFactory.enterContext();
|
||||
engines.set(this);
|
||||
try {
|
||||
ObjectInputStream sin = new ScriptableInputStream(in, core.global) {
|
||||
|
@ -584,7 +584,7 @@ public class RhinoEngine implements ScriptingEngine {
|
|||
};
|
||||
return sin.readObject();
|
||||
} finally {
|
||||
core.contextFactory.exit();
|
||||
Context.exit();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue