This commit is contained in:
Michael Bebenita 2014-12-01 09:47:42 -08:00
Родитель caeb112305
Коммит 40dfa017b2
7 изменённых файлов: 123 добавлений и 120 удалений

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

@ -1,11 +1,70 @@
module J2ME {
declare var Frame;
declare var VM;
declare var Instrument;
declare var setZeroTimeout;
declare var Long;
declare var JavaException;
export class Frame {
methodInfo: MethodInfo;
locals: any [];
stack: any [];
code: Uint8Array;
bci: number;
cp: any;
localsBase: number;
lockObject: java.lang.Object;
profileData: any;
constructor(methodInfo: MethodInfo, locals: any [], localsBase: number) {
this.methodInfo = methodInfo;
this.cp = methodInfo.classInfo.constant_pool;
this.code = methodInfo.code;
this.bci = 0;
this.stack = [];
this.locals = locals;
this.localsBase = localsBase;
this.lockObject = null;
this.profileData = null;
}
getLocal(i: number): any {
return this.locals[this.localsBase + i];
}
setLocal(i: number, value: any) {
this.locals[this.localsBase + i] = value;
}
read8(): number {
return this.code[this.bci++];
}
read16(): number {
return this.read8() << 8 | this.read8();
}
read32(): number {
return this.read16() << 16 | this.read16();
}
read8signed(): number {
var x = this.read8();
return (x > 0x7f) ? (x - 0x100) : x;
}
read16signed(): number {
var x = this.read16();
return (x > 0x7fff) ? (x - 0x10000) : x;
}
read32signed(): number {
var x = this.read32();
return (x > 0x7fffffff) ? (x - 0x100000000) : x;
}
}
export class Context {
frames: any [];
frameSets: any [];
@ -352,4 +411,5 @@ module J2ME {
}
}
var Context = J2ME.Context;
var Context = J2ME.Context;
var Frame = J2ME.Frame;

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

@ -32,55 +32,3 @@ Array.prototype.popType = function(signature) {
Array.prototype.read = function(i) {
return this[this.length - i];
};
var Frame = function(methodInfo, locals, localsBase) {
this.methodInfo = methodInfo;
this.cp = methodInfo.classInfo.constant_pool;
this.code = methodInfo.code;
this.ip = 0;
this.stack = [];
this.locals = locals;
this.localsBase = localsBase;
this.lockObject = null;
this.profileData = null;
}
Frame.prototype.getLocal = function(idx) {
return this.locals[this.localsBase + idx];
}
Frame.prototype.setLocal = function(idx, value) {
this.locals[this.localsBase + idx] = value;
}
Frame.prototype.read8 = function() {
return this.code[this.ip++];
};
Frame.prototype.read16 = function() {
return this.read8()<<8 | this.read8();
};
Frame.prototype.read32 = function() {
return this.read16()<<16 | this.read16();
};
Frame.prototype.read8signed = function() {
var x = this.read8();
return (x > 0x7f) ? (x - 0x100) : x;
}
Frame.prototype.read16signed = function() {
var x = this.read16();
return (x > 0x7fff) ? (x - 0x10000) : x;
}
Frame.prototype.read32signed = function() {
var x = this.read32();
return (x > 0x7fffffff) ? (x - 0x100000000) : x;
}

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

@ -92,7 +92,7 @@ module J2ME {
var exception_table = frame.methodInfo.exception_table;
var handler_pc = null;
for (var i=0; exception_table && i<exception_table.length; i++) {
if (frame.ip >= exception_table[i].start_pc && frame.ip <= exception_table[i].end_pc) {
if (frame.bci >= exception_table[i].start_pc && frame.bci <= exception_table[i].end_pc) {
if (exception_table[i].catch_type === 0) {
handler_pc = exception_table[i].handler_pc;
} else {
@ -107,13 +107,13 @@ module J2ME {
var classInfo = frame.methodInfo.classInfo;
if (classInfo && classInfo.className) {
stackTrace.push(" - " + classInfo.className + "." + frame.methodInfo.name + "(), bci=" + frame.ip);
stackTrace.push(" - " + classInfo.className + "." + frame.methodInfo.name + "(), bci=" + frame.bci);
}
if (handler_pc != null) {
stack.length = 0;
stack.push(ex);
frame.ip = handler_pc;
frame.bci = handler_pc;
if (VM.DEBUG_PRINT_ALL_EXCEPTIONS) {
console.error(buildExceptionLog(ex, stackTrace));
@ -157,7 +157,7 @@ module J2ME {
try {
ctx.pushClassInitFrame(classInfo);
} catch (e) {
frame.ip = ip;
frame.bci = ip;
throwHelper(e);
}
}
@ -181,7 +181,7 @@ module J2ME {
var op: Bytecodes = frame.read8();
if (traceSourceLocation) {
if (frame.methodInfo) {
var sourceLocation = frame.methodInfo.getSourceLocationForBci(frame.ip - 1);
var sourceLocation = frame.methodInfo.getSourceLocationForBci(frame.bci - 1);
if (sourceLocation && !sourceLocation.equals(lastSourceLocation)) {
traceWriter && traceWriter.greenLn(sourceLocation.toString() + " " + CLASSES.getSourceLine(sourceLocation));
lastSourceLocation = sourceLocation;
@ -191,7 +191,7 @@ module J2ME {
interpreterCounter && interpreterCounter.count(Bytecodes[op]);
// console.trace(ctx.thread.pid, frame.methodInfo.classInfo.className + " " + frame.methodInfo.name + " " + (frame.ip - 1) + " " + OPCODES[op] + " " + stack.join(","));
// console.trace(ctx.thread.pid, frame.methodInfo.classInfo.className + " " + frame.methodInfo.name + " " + (frame.bci - 1) + " " + OPCODES[op] + " " + stack.join(","));
switch (op) {
case Bytecodes.NOP:
break;
@ -677,87 +677,87 @@ module J2ME {
}
break;
case Bytecodes.IFEQ:
var jmp = frame.ip - 1 + frame.read16signed();
frame.ip = stack.pop() === 0 ? jmp : frame.ip;
var jmp = frame.bci - 1 + frame.read16signed();
frame.bci = stack.pop() === 0 ? jmp : frame.bci;
break;
case Bytecodes.IFNE:
var jmp = frame.ip - 1 + frame.read16signed();
frame.ip = stack.pop() !== 0 ? jmp : frame.ip;
var jmp = frame.bci - 1 + frame.read16signed();
frame.bci = stack.pop() !== 0 ? jmp : frame.bci;
break;
case Bytecodes.IFLT:
var jmp = frame.ip - 1 + frame.read16signed();
frame.ip = stack.pop() < 0 ? jmp : frame.ip;
var jmp = frame.bci - 1 + frame.read16signed();
frame.bci = stack.pop() < 0 ? jmp : frame.bci;
break;
case Bytecodes.IFGE:
var jmp = frame.ip - 1 + frame.read16signed();
frame.ip = stack.pop() >= 0 ? jmp : frame.ip;
var jmp = frame.bci - 1 + frame.read16signed();
frame.bci = stack.pop() >= 0 ? jmp : frame.bci;
break;
case Bytecodes.IFGT:
var jmp = frame.ip - 1 + frame.read16signed();
frame.ip = stack.pop() > 0 ? jmp : frame.ip;
var jmp = frame.bci - 1 + frame.read16signed();
frame.bci = stack.pop() > 0 ? jmp : frame.bci;
break;
case Bytecodes.IFLE:
var jmp = frame.ip - 1 + frame.read16signed();
frame.ip = stack.pop() <= 0 ? jmp : frame.ip;
var jmp = frame.bci - 1 + frame.read16signed();
frame.bci = stack.pop() <= 0 ? jmp : frame.bci;
break;
case Bytecodes.IF_ICMPEQ:
var jmp = frame.ip - 1 + frame.read16signed();
frame.ip = stack.pop() === stack.pop() ? jmp : frame.ip;
var jmp = frame.bci - 1 + frame.read16signed();
frame.bci = stack.pop() === stack.pop() ? jmp : frame.bci;
break;
case Bytecodes.IF_ICMPNE:
var jmp = frame.ip - 1 + frame.read16signed();
frame.ip = stack.pop() !== stack.pop() ? jmp : frame.ip;
var jmp = frame.bci - 1 + frame.read16signed();
frame.bci = stack.pop() !== stack.pop() ? jmp : frame.bci;
break;
case Bytecodes.IF_ICMPLT:
var jmp = frame.ip - 1 + frame.read16signed();
frame.ip = stack.pop() > stack.pop() ? jmp : frame.ip;
var jmp = frame.bci - 1 + frame.read16signed();
frame.bci = stack.pop() > stack.pop() ? jmp : frame.bci;
break;
case Bytecodes.IF_ICMPGE:
var jmp = frame.ip - 1 + frame.read16signed();
frame.ip = stack.pop() <= stack.pop() ? jmp : frame.ip;
var jmp = frame.bci - 1 + frame.read16signed();
frame.bci = stack.pop() <= stack.pop() ? jmp : frame.bci;
break;
case Bytecodes.IF_ICMPGT:
var jmp = frame.ip - 1 + frame.read16signed();
frame.ip = stack.pop() < stack.pop() ? jmp : frame.ip;
var jmp = frame.bci - 1 + frame.read16signed();
frame.bci = stack.pop() < stack.pop() ? jmp : frame.bci;
break;
case Bytecodes.IF_ICMPLE:
var jmp = frame.ip - 1 + frame.read16signed();
frame.ip = stack.pop() >= stack.pop() ? jmp : frame.ip;
var jmp = frame.bci - 1 + frame.read16signed();
frame.bci = stack.pop() >= stack.pop() ? jmp : frame.bci;
break;
case Bytecodes.IF_ACMPEQ:
var jmp = frame.ip - 1 + frame.read16signed();
frame.ip = stack.pop() === stack.pop() ? jmp : frame.ip;
var jmp = frame.bci - 1 + frame.read16signed();
frame.bci = stack.pop() === stack.pop() ? jmp : frame.bci;
break;
case Bytecodes.IF_ACMPNE:
var jmp = frame.ip - 1 + frame.read16signed();
frame.ip = stack.pop() !== stack.pop() ? jmp : frame.ip;
var jmp = frame.bci - 1 + frame.read16signed();
frame.bci = stack.pop() !== stack.pop() ? jmp : frame.bci;
break;
case Bytecodes.IFNULL:
var jmp = frame.ip - 1 + frame.read16signed();
frame.ip = !stack.pop() ? jmp : frame.ip;
var jmp = frame.bci - 1 + frame.read16signed();
frame.bci = !stack.pop() ? jmp : frame.bci;
break;
case Bytecodes.IFNONNULL:
var jmp = frame.ip - 1 + frame.read16signed();
frame.ip = stack.pop() ? jmp : frame.ip;
var jmp = frame.bci - 1 + frame.read16signed();
frame.bci = stack.pop() ? jmp : frame.bci;
break;
case Bytecodes.GOTO:
frame.ip += frame.read16signed() - 1;
frame.bci += frame.read16signed() - 1;
break;
case Bytecodes.GOTO_W:
frame.ip += frame.read32signed() - 1;
frame.bci += frame.read32signed() - 1;
break;
case Bytecodes.JSR:
var jmp = frame.read16();
stack.push(frame.ip);
frame.ip = jmp;
stack.push(frame.bci);
frame.bci = jmp;
break;
case Bytecodes.JSR_W:
var jmp = frame.read32();
stack.push(frame.ip);
frame.ip = jmp;
stack.push(frame.bci);
frame.bci = jmp;
break;
case Bytecodes.RET:
frame.ip = frame.getLocal(frame.read8());
frame.bci = frame.getLocal(frame.read8());
break;
case Bytecodes.I2L:
stack.push2(Long.fromInt(stack.pop()));
@ -804,9 +804,9 @@ module J2ME {
stack.push((stack.pop() << 16) >> 16);
break;
case Bytecodes.TABLESWITCH:
var startip: number = frame.ip;
while ((frame.ip & 3) != 0)
frame.ip++;
var startip: number = frame.bci;
while ((frame.bci & 3) != 0)
frame.bci++;
var def = frame.read32signed();
var low = frame.read32signed();
var high = frame.read32signed();
@ -815,15 +815,15 @@ module J2ME {
if (val < low || val > high) {
jmp = def;
} else {
frame.ip += (val - low) << 2;
frame.bci += (val - low) << 2;
jmp = frame.read32signed();
}
frame.ip = startip - 1 + jmp;
frame.bci = startip - 1 + jmp;
break;
case Bytecodes.LOOKUPSWITCH:
var startip: number = frame.ip;
while ((frame.ip & 3) != 0)
frame.ip++;
var startip: number = frame.bci;
while ((frame.bci & 3) != 0)
frame.bci++;
var jmp = frame.read32signed();
var size = frame.read32();
var val = frame.stack.pop();
@ -838,7 +838,7 @@ module J2ME {
break lookup;
}
}
frame.ip = startip - 1 + jmp;
frame.bci = startip - 1 + jmp;
break;
case Bytecodes.NEWARRAY:
var type = frame.read8();
@ -905,7 +905,7 @@ module J2ME {
var field = cp[idx];
if (field.tag)
field = resolve(idx, true);
classInitCheck(field.classInfo, frame.ip-3);
classInitCheck(field.classInfo, frame.bci-3);
var value = field.getStatic();
if (typeof value === "undefined") {
value = util.defaultValue(field.signature);
@ -917,7 +917,7 @@ module J2ME {
var field = cp[idx];
if (field.tag)
field = resolve(idx, true);
classInitCheck(field.classInfo, frame.ip-3);
classInitCheck(field.classInfo, frame.bci-3);
field.setStatic(stack.popType(field.signature));
break;
case Bytecodes.NEW:
@ -925,7 +925,7 @@ module J2ME {
var classInfo = cp[idx];
if (classInfo.tag)
classInfo = resolve(idx);
classInitCheck(classInfo, frame.ip-3);
classInitCheck(classInfo, frame.bci-3);
stack.push(util.newObject(classInfo));
break;
case Bytecodes.CHECKCAST:
@ -952,7 +952,7 @@ module J2ME {
case Bytecodes.ATHROW:
if (ctx.frameSets.length > 0) {
// Compiled code can't handle exceptions, so throw a yield to make all the compiled code bailout.
frame.ip--;
frame.bci--;
throw VM.Yield;
}
var obj = stack.pop();
@ -1001,7 +1001,7 @@ module J2ME {
frame.setLocal(idx, frame.getLocal(idx) + val);
break;
case Bytecodes.RET:
frame.ip = frame.getLocal(frame.read16());
frame.bci = frame.getLocal(frame.read16());
break;
default:
var opName = Bytecodes[op];
@ -1012,7 +1012,7 @@ module J2ME {
case Bytecodes.INVOKESPECIAL:
case Bytecodes.INVOKESTATIC:
case Bytecodes.INVOKEINTERFACE:
var startip: number = frame.ip - 1;
var startip: number = frame.bci - 1;
var idx = frame.read16();
if (op === 0xb9) {
var argsNumber = frame.read8();

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

@ -114,9 +114,6 @@ module J2ME {
catch_type: number;
}
declare var Frame;
export class CompiledMethodInfo {
constructor(public args: string [], public body: string, public referencedClasses: ClassInfo []) {
// ...

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

@ -2,7 +2,6 @@
module J2ME {
export var CLASSES = new ClassRegistry();
declare var util;
declare var Frame;
import Isolate = com.sun.cldc.isolate.Isolate;
export class JVM {

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

@ -386,7 +386,7 @@ Native.create("java/lang/Throwable.fillInStackTrace.()V", function(ctx) {
return;
var classInfo = methodInfo.classInfo;
var className = classInfo.className;
this.stackTrace.unshift({ className: className, methodName: methodName, offset: frame.ip });
this.stackTrace.unshift({ className: className, methodName: methodName, offset: frame.bci });
}.bind(this));
});

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

@ -9,7 +9,6 @@ declare var throwHelper;
module J2ME {
declare var Native, Override;
declare var VM;
declare var Frame;
declare var Long;