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