Make unwind flag global so that it can be optimized by the JIT.

This commit is contained in:
Michael Bebenita 2014-12-16 20:46:05 -08:00
Родитель 5d41042625
Коммит 8abc167fda
5 изменённых файлов: 36 добавлений и 34 удалений

Просмотреть файл

@ -191,7 +191,7 @@ module J2ME {
traceWriter.enter("> " + MethodType[MethodType.Interpreted][0] + " " + frameDetails);
}
var returnValue = VM.execute(this);
if ($.Y) {
if (U) {
flattenFrameSet();
return;
}
@ -287,16 +287,16 @@ module J2ME {
this.setCurrent();
do {
VM.execute(this);
if ($.Y) {
if (U) {
Array.prototype.push.apply(this.frames, this.bailoutFrames);
this.bailoutFrames = [];
}
if ($.Y === VmState.Yielding) {
if (U === VMState.Yielding) {
// Ignore the yield and continue executing instructions on this thread.
$.Y = VmState.Running;
U = VMState.Running;
continue;
} else if ($.Y === VmState.Pausing) {
$.Y = VmState.Running;
} else if (U === VMState.Pausing) {
U = VMState.Running;
Instrument.callPauseHooks(this.current());
return;
}
@ -308,16 +308,16 @@ module J2ME {
this.setCurrent();
Instrument.callResumeHooks(ctx.current());
VM.execute(ctx);
if ($.Y) {
if (U) {
Array.prototype.push.apply(this.frames, this.bailoutFrames);
this.bailoutFrames = [];
}
if ($.Y === VmState.Pausing) {
$.Y = VmState.Running;
if (U === VMState.Pausing) {
U = VMState.Running;
Instrument.callPauseHooks(this.current());
return;
}
$.Y = VmState.Running;
U = VMState.Running;
Instrument.callPauseHooks(ctx.current());
if (ctx.frames.length === 0) {
@ -364,7 +364,7 @@ module J2ME {
} else {
while (this.lockLevel-- > 0) {
this.monitorEnter(obj);
if ($.Y === VmState.Pausing) {
if (U === VMState.Pausing) {
return;
}
}

Просмотреть файл

@ -155,7 +155,7 @@ module J2ME {
return;
ctx.pushClassInitFrame(classInfo);
if ($.Y) {
if (U) {
frame.bci = ip;
return;
}
@ -923,7 +923,7 @@ module J2ME {
if (field.tag)
field = resolve(idx, true);
classInitCheck(field.classInfo, frame.bci - 3);
if ($.Y) {
if (U) {
return;
}
var value = field.getStatic();
@ -938,7 +938,7 @@ module J2ME {
if (field.tag)
field = resolve(idx, true);
classInitCheck(field.classInfo, frame.bci - 3);
if ($.Y) {
if (U) {
return;
}
field.setStatic(stack.popType(field.signature));
@ -949,7 +949,7 @@ module J2ME {
if (classInfo.tag)
classInfo = resolve(idx);
classInitCheck(classInfo, frame.bci - 3);
if ($.Y) {
if (U) {
return;
}
stack.push(util.newObject(classInfo));
@ -988,7 +988,7 @@ module J2ME {
throw ctx.createException("java/lang/NullPointerException");
}
ctx.monitorEnter(obj);
if ($.Y === VmState.Pausing) {
if (U === VMState.Pausing) {
return;
}
break;
@ -1048,7 +1048,7 @@ module J2ME {
methodInfo = resolve(idx, isStatic);
if (isStatic) {
classInitCheck(methodInfo.classInfo, startip);
if ($.Y) {
if (U) {
return;
}
}
@ -1079,7 +1079,7 @@ module J2ME {
}
var returnValue = fn.apply(obj, args);
if ($.Y) {
if (U) {
return;
}

Просмотреть файл

@ -520,11 +520,11 @@ module J2ME.C4.Backend {
var to = id(this.variable.name);
cx.useVariable(this.variable);
block.body.push(new AST.ExpressionStatement(assignment(to, result)));
var ifYield = new AST.IfStatement(property(id("$"), "Y"), new AST.BlockStatement([
var ifUnwind = new AST.IfStatement(id("U"), new AST.BlockStatement([
new AST.ExpressionStatement(call(property(id("$"), "B"), compileState(this.state, cx))),
new AST.ReturnStatement(undefined)
]));
block.body.push(ifYield);
block.body.push(ifUnwind);
return block;
}
return result;

6
jvm.ts
Просмотреть файл

@ -21,10 +21,10 @@ module J2ME {
var array = newStringArray(args.length);
for (var n = 0; n < args.length; ++n)
array[n] = args[n] ? util.newString(args[n]) : null;
array[n] = args[n] ? J2ME.newString(args[n]) : null;
ctx.frames.push(new Frame(CLASSES.getMethod(isolateClassInfo, "I.<init>.(Ljava/lang/String;[Ljava/lang/String;)V"),
[ isolate, util.newString(className.replace(/\./g, "/")), array ], 0));
[ isolate, J2ME.newString(className.replace(/\./g, "/")), array ], 0));
ctx.execute();
ctx.frames.push(new Frame(CLASSES.getMethod(isolateClassInfo, "I.start.()V"), [ isolate ], 0));
@ -55,7 +55,7 @@ module J2ME {
ctx.thread.alive = true;
ctx.frames.push(new Frame(CLASSES.getMethod(CLASSES.java_lang_Thread, "I.<init>.(Ljava/lang/String;)V"),
[ runtime.mainThread, util.newString("main") ], 0));
[ runtime.mainThread, J2ME.newString("main") ], 0));
var oldCtx = $.ctx;
ctx.execute();
oldCtx.setCurrent();

Просмотреть файл

@ -271,7 +271,7 @@ module J2ME {
if (internedStrings.has(s)) {
return internedStrings.get(s);
}
var obj = util.newString(s);
var obj = J2ME.newString(s);
internedStrings.set(s, obj);
return obj;
}
@ -285,7 +285,7 @@ module J2ME {
}
}
export enum VmState {
export enum VMState {
Running = 0,
Yielding = 1,
Pausing = 2
@ -295,11 +295,6 @@ module J2ME {
private static _nextId: number = 0;
id: number;
/**
* Are we currently unwinding the stack because of a Yield?
*/
Y: VmState = VmState.Running;
/**
* Bailout callback whenever a JIT frame is unwound.
*/
@ -308,11 +303,11 @@ module J2ME {
}
yield() {
this.Y = VmState.Yielding;
U = VMState.Yielding;
}
pause() {
this.Y = VmState.Pausing;
U = VMState.Pausing;
}
constructor(jvm: JVM) {
@ -504,7 +499,7 @@ module J2ME {
});
initWriter && initWriter.writeLn("Running Static Constructor: " + classInfo.className);
$.ctx.pushClassInitFrame(classInfo);
assert(!$.Y);
assert(!U);
//// TODO: monitorEnter
//if (klass.staticInitializer) {
// klass.staticInitializer.call(runtimeKlass);
@ -742,7 +737,7 @@ module J2ME {
: frame.getLocal(0);
}
$.ctx.monitorEnter(frame.lockObject);
if ($.Y === VmState.Pausing) {
if (U === VMState.Pausing) {
$.ctx.frames.push(frame);
return;
}
@ -1026,6 +1021,13 @@ module J2ME {
var Runtime = J2ME.Runtime;
/**
* Are we currently unwinding the stack because of a Yield? This technically
* belonges to a context but we store it in the global object because it is
* read very often.
*/
var U: J2ME.VMState = J2ME.VMState.Running;
/**
* Runtime exports for compiled code.
*/