pluotsorbet/int.ts

1764 строки
63 KiB
TypeScript
Исходник Обычный вид История

2015-05-09 07:14:44 +03:00
module J2ME {
2015-05-08 01:17:05 +03:00
2015-05-05 05:46:26 +03:00
import assert = Debug.assert;
import Bytecodes = Bytecode.Bytecodes;
import toHEX = IntegerUtilities.toHEX;
2015-05-08 01:17:05 +03:00
function toName(o) {
if (o instanceof MethodInfo) {
2015-05-11 02:00:43 +03:00
return "MI: " + o.implKey;
2015-05-08 01:17:05 +03:00
}
function getArrayInfo(o) {
var s = [];
var x = [];
2015-05-11 02:00:43 +03:00
for (var i = 0; i < Math.min(o.length, 8); i++) {
s.push(o[i]);
x.push(String.fromCharCode(o[i]));
}
2015-05-11 02:00:43 +03:00
var suffix = (o.length > 8 ? "..." : "");
return fromUTF8(o.klass.classInfo.utf8Name) +
", length: " + o.length +
", values: [" + s.join(", ") + suffix + "]" +
", chars: \"" + x.join("") + suffix + "\"";
}
2015-05-09 07:14:44 +03:00
function getObjectInfo(o) {
if (o.length !== undefined) {
return getArrayInfo(o);
}
return fromUTF8(o.klass.classInfo.utf8Name) + (o._address ? " " + toHEX(o._address) : "");
2015-05-09 07:14:44 +03:00
}
if (o && !o.klass) {
return o;
}
2015-05-08 01:17:05 +03:00
if (o && o.klass === Klasses.java.lang.Class) {
2015-05-09 07:14:44 +03:00
return "[" + getObjectInfo(o) + "] " + o.runtimeKlass.templateKlass.classInfo.getClassNameSlow();
2015-05-08 01:17:05 +03:00
}
if (o && o.klass === Klasses.java.lang.String) {
2015-05-09 07:14:44 +03:00
return "[" + getObjectInfo(o) + "] \"" + fromJavaString(o) + "\"";
2015-05-08 01:17:05 +03:00
}
2015-05-09 07:14:44 +03:00
return o ? ("[" + getObjectInfo(o) + "]") : "null";
2015-05-08 01:17:05 +03:00
}
2015-05-08 03:31:22 +03:00
/**
* The number of opcodes executed thus far.
*/
export var bytecodeCount = 0;
/**
* The number of times the interpreter method was called thus far.
*/
export var interpreterCount = 0;
export var onStackReplacementCount = 0;
/**
* The closest floating-point representation to this long value.
*/
function longToNumber(l: number, h: number): number {
return h * Constants.TWO_PWR_32_DBL + ((l >= 0) ? l : Constants.TWO_PWR_32_DBL + l);
}
function wordsToDouble(l: number, h: number): number {
aliasedI32[0] = l;
aliasedI32[1] = h;
return aliasedF64[0];
}
2015-05-10 04:32:02 +03:00
/**
* Calling Convention:
*
* Interpreter -> Interpreter:
* This follows the JVM bytecode calling convention. This interpreter is highly
* optimized for this calling convention.
*
* Compiled / Native -> Compiled / Native:
* 64-bit floats and single word values can be encoded using only one JS value. However, 64-bit longs cannot and
* require a (low, high) JS value pair. For example, the signature: "foo.(IDJi)J" is expressed as:
*
* function foo(i, d, lowBits, highBits, i) {
* return tempReturn0 = highBits, lowBits;
* }
*
* Returning longs is equally problamatic, the convention is to return the lowBits, and save the highBits in a
* global |tempReturn0| variable.
*/
/*
2015-05-10 04:32:02 +03:00
* Stack Frame Layout:
*
* LP ---> +--------------------------------+
2015-05-06 11:26:46 +03:00
* | Parameter 0 |
* +--------------------------------+
* | ... |
* +--------------------------------+
* | Parameter (P-1) |
* +--------------------------------+
* | Non-Parameter Local 0 |
* +--------------------------------+
* | ... |
* +--------------------------------+
* | Non-Parameter Local (L-1) |
2015-05-06 11:26:46 +03:00
* FP ---> +--------------------------------+
2015-05-16 01:22:12 +03:00
* | Caller Return Address | // The opPC of the caller's invoke bytecode.
2015-05-06 11:26:46 +03:00
* +--------------------------------+
* | Caller FP |
* +--------------------------------+
* | Callee Method Info |
* +--------------------------------+
2015-05-16 04:58:19 +03:00
* | Monitor |
* +--------------------------------+
* | Stack slot 0 |
* +--------------------------------+
* | ... |
* +--------------------------------+
* | Stack slot (S-1) |
* SP ---> +--------------------------------+
*/
enum FrameLayout {
2015-05-06 11:26:46 +03:00
CalleeMethodInfoOffset = 2,
CallerFPOffset = 1,
CallerRAOffset = 0,
2015-05-16 04:58:19 +03:00
MonitorOffset = 3,
CallerSaveSize = 4
}
export class FrameView {
public fp: number;
public sp: number;
public pc: number;
constructor() {
}
set(fp: number, sp: number, pc: number) {
this.fp = fp;
this.sp = sp;
this.pc = pc;
2015-05-05 05:46:26 +03:00
if (!release) {
2015-05-08 03:31:22 +03:00
var callee = ref[this.fp + FrameLayout.CalleeMethodInfoOffset];
2015-05-05 05:46:26 +03:00
assert(
callee === null ||
callee instanceof MethodInfo,
2015-05-08 01:17:05 +03:00
"Callee @" + (this.fp + FrameLayout.CalleeMethodInfoOffset) + " is not a MethodInfo, " + toName(callee)
2015-05-05 05:46:26 +03:00
);
}
}
setParameter(kind: Kind, i: number, v: any) {
switch (kind) {
case Kind.Reference:
2015-05-08 03:31:22 +03:00
ref[this.fp + this.parameterOffset + i] = v;
2015-05-05 05:46:26 +03:00
break;
case Kind.Int:
2015-05-08 03:31:22 +03:00
i32[this.fp + this.parameterOffset + i] = v;
2015-05-05 05:46:26 +03:00
break;
default:
2015-05-11 02:00:43 +03:00
release || assert(false, "Cannot set parameter of kind: " + Kind[kind]);
2015-05-05 05:46:26 +03:00
}
}
get methodInfo(): MethodInfo {
2015-05-08 03:31:22 +03:00
return ref[this.fp + FrameLayout.CalleeMethodInfoOffset];
}
set methodInfo(methodInfo: MethodInfo) {
2015-05-08 03:31:22 +03:00
ref[this.fp + FrameLayout.CalleeMethodInfoOffset] = methodInfo;
}
2015-05-16 04:58:19 +03:00
set monitor(object: java.lang.Object) {
ref[this.fp + FrameLayout.MonitorOffset] = object;
}
get monitor(): java.lang.Object {
return ref[this.fp + FrameLayout.MonitorOffset];
}
2015-05-06 11:26:46 +03:00
get parameterOffset() {
return this.methodInfo ? -this.methodInfo.codeAttribute.max_locals : 0;
}
2015-05-06 11:26:46 +03:00
get stackOffset(): number {
return FrameLayout.CallerSaveSize;
2015-05-05 05:46:26 +03:00
}
traceStack(writer: IndentingWriter) {
var fp = this.fp;
var sp = this.sp;
var pc = this.pc;
while (this.fp > FrameLayout.CallerSaveSize) {
writer.writeLn((this.methodInfo ? this.methodInfo.implKey : "null") + ", FP: " + this.fp + ", SP: " + this.sp + ", PC: " + this.pc);
2015-05-08 03:31:22 +03:00
this.set(i32[this.fp + FrameLayout.CallerFPOffset],
2015-05-06 11:26:46 +03:00
this.fp + this.parameterOffset,
2015-05-08 03:31:22 +03:00
i32[this.fp + FrameLayout.CallerRAOffset]);
2015-05-05 05:46:26 +03:00
}
this.fp = fp;
this.sp = sp;
this.pc = pc;
}
2015-05-11 02:00:43 +03:00
trace(writer: IndentingWriter) {
function toNumber(v) {
if (v < 0) {
return String(v);
} else if (v === 0) {
return " 0";
} else {
return "+" + v;
}
}
2015-05-08 01:17:05 +03:00
2015-05-11 02:00:43 +03:00
function clampString(v, n) {
if (v.length > n) {
return v.substring(0, n - 3) + "...";
}
return v;
}
2015-05-11 02:00:43 +03:00
writer.writeLn("Frame: " + this.methodInfo.implKey + ", FP: " + this.fp + ", SP: " + this.sp + ", PC: " + this.pc);
2015-05-06 11:26:46 +03:00
for (var i = Math.max(0, this.fp + this.parameterOffset); i < this.sp; i++) {
var prefix = " ";
if (i >= this.fp + this.stackOffset) {
prefix = "S" + (i - (this.fp + this.stackOffset)) + ": ";
2015-05-05 05:46:26 +03:00
} else if (i === this.fp + FrameLayout.CalleeMethodInfoOffset) {
prefix = "MI: ";
2015-05-05 05:46:26 +03:00
} else if (i === this.fp + FrameLayout.CallerFPOffset) {
prefix = "CF: ";
} else if (i === this.fp + FrameLayout.CallerRAOffset) {
prefix = "RA: ";
2015-05-06 11:26:46 +03:00
} else if (i >= this.fp + this.parameterOffset) {
prefix = "L" + (i - (this.fp + this.parameterOffset)) + ": ";
}
2015-05-11 02:00:43 +03:00
writer.writeLn(" " + prefix.padRight(' ', 5) + " " + toNumber(i - this.fp).padLeft(' ', 3) + " " + String(i).padLeft(' ', 4) + " " + toHEX(i << 2) + ": " +
2015-05-10 04:32:02 +03:00
String(i32[i]).padLeft(' ', 12) + " " +
2015-05-11 02:00:43 +03:00
toHEX(i32[i]) + " " +
2015-05-11 10:27:23 +03:00
((i32[i] >= 32 && i32[i] < 1024) ? String.fromCharCode(i32[i]) : "?") + " " +
2015-05-11 02:00:43 +03:00
clampString(String(f32[i]), 12).padLeft(' ', 12) + " " +
clampString(String(wordsToDouble(i32[i], i32[i + 1])), 12).padLeft(' ', 12) + " " +
2015-05-08 03:31:22 +03:00
toName(ref[i]));
}
}
}
2015-05-09 23:37:04 +03:00
export var interpreterCounter = new Metrics.Counter(true);
export class Thread {
/**
* Thread base pointer.
*/
tp: number;
/**
* Stack base pointer.
*/
bp: number
/**
* Current frame pointer.
*/
fp: number
/**
* Current stack pointer.
*/
sp: number
/**
* Current program counter.
*/
pc: number
/**
* Context associated with this thread.
*/
ctx: Context;
2015-05-05 05:46:26 +03:00
view: FrameView;
constructor(ctx: Context) {
2015-05-09 07:14:44 +03:00
this.tp = ASM._gcMalloc(1024 * 128);
2015-05-05 05:46:26 +03:00
this.bp = this.tp;
2015-05-06 11:26:46 +03:00
this.fp = this.bp;
this.sp = this.fp;
2015-05-05 05:46:26 +03:00
this.pc = -1;
this.view = new FrameView();
this.ctx = ctx;
}
2015-05-05 05:46:26 +03:00
set(fp: number, sp: number, pc: number) {
this.fp = fp;
this.sp = sp;
this.pc = pc;
}
2015-05-06 11:26:46 +03:00
get frame(): FrameView {
2015-05-05 05:46:26 +03:00
this.view.set(this.fp, this.sp, this.pc);
return this.view;
}
pushFrame(methodInfo: MethodInfo) {
2015-05-06 11:26:46 +03:00
var fp = this.fp;
2015-05-05 05:46:26 +03:00
if (methodInfo) {
2015-05-06 11:26:46 +03:00
this.fp = this.sp + methodInfo.codeAttribute.max_locals;
} else {
this.fp = this.sp;
2015-05-05 05:46:26 +03:00
}
2015-05-16 04:58:19 +03:00
i32[this.fp + FrameLayout.CallerRAOffset] = this.pc; // Caller RA
i32[this.fp + FrameLayout.CallerFPOffset] = fp; // Caller FP
ref[this.fp + FrameLayout.CalleeMethodInfoOffset] = methodInfo; // Callee
ref[this.fp + FrameLayout.MonitorOffset] = null; // Monitor
this.sp = this.fp + FrameLayout.CallerSaveSize;
2015-05-05 05:46:26 +03:00
this.pc = 0;
}
2015-05-08 01:17:05 +03:00
popFrame(methodInfo: MethodInfo): MethodInfo {
2015-05-08 03:31:22 +03:00
var mi = ref[this.fp + FrameLayout.CalleeMethodInfoOffset];
2015-05-06 11:26:46 +03:00
release || assert(mi === methodInfo);
2015-05-08 03:31:22 +03:00
this.pc = i32[this.fp + FrameLayout.CallerRAOffset];
2015-05-06 11:26:46 +03:00
var maxLocals = mi ? mi.codeAttribute.max_locals : 0;
this.sp = this.fp - maxLocals;
2015-05-08 03:31:22 +03:00
this.fp = i32[this.fp + FrameLayout.CallerFPOffset];
return ref[this.fp + FrameLayout.CalleeMethodInfoOffset]
2015-05-05 05:46:26 +03:00
}
2015-05-06 11:26:46 +03:00
run() {
return interpret(this);
}
exceptionUnwind(e: java.lang.Exception) {
release || traceWriter && traceWriter.writeLn("exceptionUnwind: " + toName(e));
2015-05-08 01:17:05 +03:00
var pc = -1;
2015-05-06 11:26:46 +03:00
var classInfo;
2015-05-08 03:31:22 +03:00
var mi = ref[this.fp + FrameLayout.CalleeMethodInfoOffset];
2015-05-08 01:17:05 +03:00
while (mi) {
release || traceWriter && traceWriter.writeLn("Looking for handler in: " + mi.implKey);
2015-05-06 11:26:46 +03:00
for (var i = 0; i < mi.exception_table_length; i++) {
var exceptionEntryView = mi.getExceptionEntryViewByIndex(i);
2015-05-16 01:22:12 +03:00
release || traceWriter && traceWriter.writeLn("Checking catch range: " + exceptionEntryView.start_pc + " - " + exceptionEntryView.end_pc);
2015-05-06 11:26:46 +03:00
if (this.pc >= exceptionEntryView.start_pc && this.pc < exceptionEntryView.end_pc) {
if (exceptionEntryView.catch_type === 0) {
2015-05-08 01:17:05 +03:00
pc = exceptionEntryView.handler_pc;
2015-05-06 11:26:46 +03:00
break;
} else {
classInfo = resolveClass(exceptionEntryView.catch_type, mi.classInfo);
2015-05-16 01:22:12 +03:00
release || traceWriter && traceWriter.writeLn("Checking catch type: " + classInfo.klass);
2015-05-06 11:26:46 +03:00
if (isAssignableTo(e.klass, classInfo.klass)) {
2015-05-08 01:17:05 +03:00
pc = exceptionEntryView.handler_pc;
2015-05-06 11:26:46 +03:00
break;
}
}
}
}
2015-05-08 01:17:05 +03:00
if (pc >= 0) {
this.pc = pc;
this.sp = this.fp + FrameLayout.CallerSaveSize;
2015-05-08 03:31:22 +03:00
ref[this.sp++] = e;
2015-05-06 11:26:46 +03:00
return;
}
2015-05-08 01:17:05 +03:00
mi = this.popFrame(mi);
release || traceWriter && traceWriter.outdent();
release || traceWriter && traceWriter.writeLn("<< I Unwind");
2015-05-08 01:17:05 +03:00
}
release || traceWriter && traceWriter.writeLn("Cannot catch: " + toName(e));
2015-05-08 01:17:05 +03:00
throw e;
2015-05-05 05:46:26 +03:00
}
}
2015-05-05 05:46:26 +03:00
export function prepareInterpretedMethod(methodInfo: MethodInfo): Function {
var method = function fastInterpreterFrameAdapter() {
var thread = $.ctx.nativeThread;
2015-05-08 01:17:05 +03:00
var fp = thread.fp;
// release || traceWriter && traceWriter.writeLn(">> I");
2015-05-05 05:46:26 +03:00
thread.pushFrame(null);
thread.pushFrame(methodInfo);
2015-05-06 11:26:46 +03:00
var frame = thread.frame;
2015-05-05 05:46:26 +03:00
var kinds = methodInfo.signatureKinds;
var index = 0;
if (!methodInfo.isStatic) {
2015-05-06 11:26:46 +03:00
frame.setParameter(Kind.Reference, index++, this);
2015-05-05 05:46:26 +03:00
}
for (var i = 1; i < kinds.length; i++) {
2015-05-06 11:26:46 +03:00
frame.setParameter(kinds[i], index++, arguments[i - 1]);
2015-05-05 05:46:26 +03:00
}
2015-05-16 04:58:19 +03:00
if (methodInfo.isSynchronized) {
var monitor = methodInfo.isStatic
? methodInfo.classInfo.getClassObject()
: this;
frame.monitor = monitor;
$.ctx.monitorEnter(monitor);
if (U === VMState.Pausing || U === VMState.Stopping) {
debugger;
return;
}
}
2015-05-08 01:17:05 +03:00
var v = interpret(thread);
release || assert(fp === thread.fp);
// release || traceWriter && traceWriter.writeLn("<< I");
2015-05-08 01:17:05 +03:00
return v;
2015-05-05 05:46:26 +03:00
};
(<any>method).methodInfo = methodInfo;
return method;
}
2015-05-05 05:46:26 +03:00
function resolveClass(index: number, classInfo: ClassInfo): ClassInfo {
var classInfo = classInfo.constantPool.resolveClass(index);
linkKlass(classInfo);
return classInfo;
}
var args = new Array(16);
2015-05-11 10:27:23 +03:00
enum ExceptionType {
ArithmeticException,
ArrayIndexOutOfBoundsException
}
/**
* Main interpreter loop. This method is carefully written to avoid memory allocation and
* function calls on fast paths. Thus, everything is inlined, even if it makes the code
* ugly.
*/
export function interpret(thread: Thread) {
2015-05-06 11:26:46 +03:00
var frame = thread.frame;
var mi = frame.methodInfo;
2015-05-08 03:31:22 +03:00
var maxLocals = mi.codeAttribute.max_locals;
var ci = mi.classInfo;
var cp = ci.constantPool;
var code = mi ? mi.codeAttribute.code : null;
var fp = thread.fp;
var lp = fp - maxLocals;
var sp = thread.sp;
2015-05-11 10:27:23 +03:00
var opPC = 0, pc = thread.pc;
2015-05-05 05:46:26 +03:00
var tag: TAGS;
var type, size;
2015-05-10 00:57:32 +03:00
var value, index, array, object, result, constant, offset, buffer, tag: TAGS, targetPC, returnValue, kind;
2015-05-11 04:50:37 +03:00
var address = 0, isStatic = false;
2015-05-05 05:46:26 +03:00
var ia = 0, ib = 0; // Integer Operands
2015-05-09 07:14:44 +03:00
var ll = 0, lh = 0; // Long Low / High
2015-05-05 05:46:26 +03:00
var fa = 0, fb = 0; // Float / Double Operands
2015-05-05 05:46:26 +03:00
var classInfo: ClassInfo;
var fieldInfo: FieldInfo;
2015-05-16 04:58:19 +03:00
var monitor: java.lang.Object;
2015-05-05 05:46:26 +03:00
function loadThreadState() {
fp = thread.fp;
lp = fp - maxLocals;
2015-05-05 05:46:26 +03:00
sp = thread.sp;
pc = thread.pc;
}
function classInitAndUnwindCheck(classInfo: ClassInfo, unusedPC: number) {
thread.set(fp, sp, pc);
2015-05-08 01:17:05 +03:00
classInitCheck(classInfo);
loadThreadState();
//if (U) {
// $.ctx.current().pc = pc;
// return;
//}
}
2015-05-11 10:27:23 +03:00
/**
* Thrown exceptions need to be constructed, and can thus damage the stack if we don't
* save the thread state. This is a helper function that does just that.
*/
function throwException(type: ExceptionType, a?) {
thread.set(fp, sp, opPC);
switch (type) {
case ExceptionType.ArrayIndexOutOfBoundsException:
throwArrayIndexOutOfBoundsException(a);
break;
case ExceptionType.ArithmeticException:
throwArithmeticException();
break;
}
}
2015-05-09 07:14:44 +03:00
// HEAD
while (true) {
2015-05-11 10:27:23 +03:00
opPC = pc, op = code[pc++];
2015-05-05 05:46:26 +03:00
2015-05-11 10:27:23 +03:00
if (!release) {
assert(code === mi.codeAttribute.code, "Bad Code.");
assert(ci === mi.classInfo, "Bad Class Info.");
assert(cp === ci.constantPool, "Bad Constant Pool.");
assert(lp === fp - mi.codeAttribute.max_locals, "Bad lp.");
bytecodeCount++;
2015-05-11 10:27:23 +03:00
if (traceStackWriter) {
frame.set(fp, sp, opPC); frame.trace(traceStackWriter);
traceStackWriter.writeLn();
traceStackWriter.greenLn(mi.implKey + ": PC: " + opPC + ", FP: " + fp + ", " + Bytecodes[op]);
}
2015-05-09 07:14:44 +03:00
}
2015-05-05 05:46:26 +03:00
2015-05-06 11:26:46 +03:00
try {
switch (op) {
case Bytecodes.NOP:
2015-05-08 10:57:48 +03:00
continue;
2015-05-06 11:26:46 +03:00
case Bytecodes.ACONST_NULL:
2015-05-08 03:31:22 +03:00
ref[sp++] = null;
2015-05-08 10:57:48 +03:00
continue;
2015-05-06 11:26:46 +03:00
case Bytecodes.ICONST_M1:
case Bytecodes.ICONST_0:
case Bytecodes.ICONST_1:
case Bytecodes.ICONST_2:
case Bytecodes.ICONST_3:
case Bytecodes.ICONST_4:
case Bytecodes.ICONST_5:
i32[sp++] = op - Bytecodes.ICONST_0;
2015-05-08 10:57:48 +03:00
continue;
2015-05-06 11:26:46 +03:00
case Bytecodes.FCONST_0:
case Bytecodes.FCONST_1:
case Bytecodes.FCONST_2:
f32[sp++] = op - Bytecodes.FCONST_0;
2015-05-08 10:57:48 +03:00
continue;
2015-05-09 07:14:44 +03:00
case Bytecodes.DCONST_0:
i32[sp++] = 0;
i32[sp++] = 0;
continue;
case Bytecodes.DCONST_1:
i32[sp++] = 0;
i32[sp++] = 1072693248;
continue;
2015-05-08 01:17:05 +03:00
case Bytecodes.LCONST_0:
case Bytecodes.LCONST_1:
2015-05-08 09:37:31 +03:00
i32[sp++] = op - Bytecodes.LCONST_0;
i32[sp++] = 0;
2015-05-08 10:57:48 +03:00
continue;
2015-05-06 11:26:46 +03:00
case Bytecodes.BIPUSH:
i32[sp++] = code[pc++] << 24 >> 24;
2015-05-08 10:57:48 +03:00
continue;
2015-05-06 11:26:46 +03:00
case Bytecodes.SIPUSH:
2015-05-09 23:37:04 +03:00
i32[sp++] = (code[pc++] << 8 | code[pc++]) << 16 >> 16;
2015-05-08 10:57:48 +03:00
continue;
2015-05-06 11:26:46 +03:00
case Bytecodes.LDC:
case Bytecodes.LDC_W:
2015-05-09 23:37:04 +03:00
index = (op === Bytecodes.LDC) ? code[pc++] : code[pc++] << 8 | code[pc++];
2015-05-10 00:57:32 +03:00
offset = cp.entries[index];
buffer = cp.buffer;
tag = buffer[offset++];
if (tag === TAGS.CONSTANT_Integer || tag === TAGS.CONSTANT_Float) {
i32[sp++] = buffer[offset++] << 24 | buffer[offset++] << 16 | buffer[offset++] << 8 | buffer[offset++];
2015-05-06 11:26:46 +03:00
} else if (tag === TAGS.CONSTANT_String) {
2015-05-10 00:57:32 +03:00
ref[sp++] = constant = ci.constantPool.resolve(index, tag, false);;
2015-05-06 11:26:46 +03:00
} else {
release || assert(false, TAGS[tag]);
2015-05-06 11:26:46 +03:00
}
2015-05-08 10:57:48 +03:00
continue;
2015-05-06 11:26:46 +03:00
case Bytecodes.LDC2_W:
2015-05-10 00:57:32 +03:00
index = code[pc++] << 8 | code[pc++];
offset = cp.entries[index];
buffer = cp.buffer;
tag = buffer[offset++];
if (tag === TAGS.CONSTANT_Long || tag === TAGS.CONSTANT_Double) {
i32[sp + 1] = buffer[offset++] << 24 | buffer[offset++] << 16 | buffer[offset++] << 8 | buffer[offset++];
i32[sp ] = buffer[offset++] << 24 | buffer[offset++] << 16 | buffer[offset++] << 8 | buffer[offset++];
sp += 2;
2015-05-06 11:26:46 +03:00
} else {
release || assert(false, TAGS[tag]);
2015-05-06 11:26:46 +03:00
}
2015-05-08 10:57:48 +03:00
continue;
2015-05-08 01:17:05 +03:00
case Bytecodes.ILOAD:
case Bytecodes.FLOAD:
2015-05-08 05:35:57 +03:00
i32[sp++] = i32[lp + code[pc++]];
2015-05-08 10:57:48 +03:00
continue;
2015-05-08 01:17:05 +03:00
case Bytecodes.ALOAD:
2015-05-08 05:35:57 +03:00
ref[sp++] = ref[lp + code[pc++]];
2015-05-08 10:57:48 +03:00
continue;
2015-05-08 01:17:05 +03:00
case Bytecodes.LLOAD:
case Bytecodes.DLOAD:
2015-05-09 12:47:47 +03:00
offset = lp + code[pc++];
i32[sp++] = i32[offset];
i32[sp++] = i32[offset + 1];
2015-05-08 10:57:48 +03:00
continue;
2015-05-08 01:17:05 +03:00
case Bytecodes.ILOAD_0:
case Bytecodes.ILOAD_1:
case Bytecodes.ILOAD_2:
case Bytecodes.ILOAD_3:
2015-05-08 05:35:57 +03:00
i32[sp++] = i32[lp + op - Bytecodes.ILOAD_0];
2015-05-08 10:57:48 +03:00
continue;
2015-05-08 01:17:05 +03:00
case Bytecodes.FLOAD_0:
case Bytecodes.FLOAD_1:
case Bytecodes.FLOAD_2:
case Bytecodes.FLOAD_3:
2015-05-08 05:35:57 +03:00
i32[sp++] = i32[lp + op - Bytecodes.FLOAD_0];
2015-05-08 10:57:48 +03:00
continue;
2015-05-06 11:26:46 +03:00
case Bytecodes.ALOAD_0:
2015-05-09 23:37:04 +03:00
ref[sp++] = ref[lp];
continue;
2015-05-06 11:26:46 +03:00
case Bytecodes.ALOAD_1:
case Bytecodes.ALOAD_2:
case Bytecodes.ALOAD_3:
2015-05-08 05:35:57 +03:00
ref[sp++] = ref[lp + op - Bytecodes.ALOAD_0];
2015-05-08 10:57:48 +03:00
continue;
2015-05-08 01:17:05 +03:00
case Bytecodes.LLOAD_0:
case Bytecodes.LLOAD_1:
case Bytecodes.LLOAD_2:
case Bytecodes.LLOAD_3:
2015-05-09 12:47:47 +03:00
offset = lp + op - Bytecodes.LLOAD_0;
i32[sp++] = i32[offset];
i32[sp++] = i32[offset + 1];
2015-05-08 10:57:48 +03:00
continue;
2015-05-08 01:17:05 +03:00
case Bytecodes.DLOAD_0:
case Bytecodes.DLOAD_1:
case Bytecodes.DLOAD_2:
case Bytecodes.DLOAD_3:
2015-05-09 12:47:47 +03:00
offset = lp + op - Bytecodes.DLOAD_0;
i32[sp++] = i32[offset];
i32[sp++] = i32[offset + 1];
2015-05-08 10:57:48 +03:00
continue;
2015-05-08 01:17:05 +03:00
case Bytecodes.IALOAD:
2015-05-08 05:35:57 +03:00
index = i32[--sp];
array = ref[--sp];
2015-05-08 09:37:31 +03:00
if ((index >>> 0) >= (array.length >>> 0)) {
2015-05-11 10:27:23 +03:00
throwException(ExceptionType.ArrayIndexOutOfBoundsException, index);
2015-05-08 09:37:31 +03:00
}
i32[sp++] = array[index];
2015-05-08 10:57:48 +03:00
continue;
2015-05-08 01:17:05 +03:00
case Bytecodes.BALOAD:
2015-05-08 05:35:57 +03:00
index = i32[--sp];
array = ref[--sp];
2015-05-08 09:37:31 +03:00
if ((index >>> 0) >= (array.length >>> 0)) {
2015-05-11 10:27:23 +03:00
throwException(ExceptionType.ArrayIndexOutOfBoundsException, index);
2015-05-08 09:37:31 +03:00
}
i32[sp++] = array[index];
2015-05-08 10:57:48 +03:00
continue;
2015-05-08 01:17:05 +03:00
case Bytecodes.CALOAD:
2015-05-08 05:35:57 +03:00
index = i32[--sp];
array = ref[--sp];
2015-05-08 09:37:31 +03:00
if ((index >>> 0) >= (array.length >>> 0)) {
2015-05-11 10:27:23 +03:00
throwException(ExceptionType.ArrayIndexOutOfBoundsException, index);
2015-05-08 09:37:31 +03:00
}
i32[sp++] = array[index];
2015-05-08 10:57:48 +03:00
continue;
2015-05-08 01:17:05 +03:00
case Bytecodes.SALOAD:
2015-05-08 05:35:57 +03:00
index = i32[--sp];
array = ref[--sp];
2015-05-08 09:37:31 +03:00
if ((index >>> 0) >= (array.length >>> 0)) {
2015-05-11 10:27:23 +03:00
throwException(ExceptionType.ArrayIndexOutOfBoundsException, index);
2015-05-08 09:37:31 +03:00
}
i32[sp++] = array[index];
2015-05-08 10:57:48 +03:00
continue;
2015-05-09 07:14:44 +03:00
case Bytecodes.FALOAD:
index = i32[--sp];
array = ref[--sp];
if ((index >>> 0) >= (array.length >>> 0)) {
2015-05-11 10:27:23 +03:00
throwException(ExceptionType.ArrayIndexOutOfBoundsException, index);
2015-05-09 07:14:44 +03:00
}
f32[sp++] = array[index];
continue;
case Bytecodes.AALOAD:
index = i32[--sp];
array = ref[--sp];
if ((index >>> 0) >= (array.length >>> 0)) {
2015-05-11 10:27:23 +03:00
throwException(ExceptionType.ArrayIndexOutOfBoundsException, index);
2015-05-09 07:14:44 +03:00
}
ref[sp++] = array[index];
continue;
case Bytecodes.DALOAD:
index = i32[--sp];
array = ref[--sp];
if ((index >>> 0) >= (array.length >>> 0)) {
2015-05-11 10:27:23 +03:00
throwException(ExceptionType.ArrayIndexOutOfBoundsException, index);
2015-05-09 07:14:44 +03:00
}
aliasedF64[0] = array[index];
i32[sp++] = aliasedI32[0];
i32[sp++] = aliasedI32[1];
2015-05-09 07:14:44 +03:00
continue;
2015-05-08 01:17:05 +03:00
case Bytecodes.ISTORE:
case Bytecodes.FSTORE:
2015-05-08 05:35:57 +03:00
i32[lp + code[pc++]] = i32[--sp];
2015-05-08 10:57:48 +03:00
continue;
2015-05-08 01:17:05 +03:00
case Bytecodes.ASTORE:
2015-05-08 05:35:57 +03:00
ref[lp + code[pc++]] = ref[--sp];
2015-05-08 10:57:48 +03:00
continue;
2015-05-08 01:17:05 +03:00
case Bytecodes.LSTORE:
case Bytecodes.DSTORE:
2015-05-09 12:47:47 +03:00
offset = lp + code[pc++];
i32[offset + 1] = i32[--sp];
i32[offset] = i32[--sp];
2015-05-08 10:57:48 +03:00
continue;
2015-05-06 11:26:46 +03:00
case Bytecodes.ISTORE_0:
case Bytecodes.ISTORE_1:
case Bytecodes.ISTORE_2:
case Bytecodes.ISTORE_3:
2015-05-08 05:35:57 +03:00
i32[lp + op - Bytecodes.ISTORE_0] = i32[--sp];
2015-05-08 10:57:48 +03:00
continue;
2015-05-06 11:26:46 +03:00
case Bytecodes.FSTORE_0:
case Bytecodes.FSTORE_1:
case Bytecodes.FSTORE_2:
case Bytecodes.FSTORE_3:
2015-05-08 05:35:57 +03:00
i32[lp + op - Bytecodes.FSTORE_0] = i32[--sp];
2015-05-08 10:57:48 +03:00
continue;
2015-05-06 11:26:46 +03:00
case Bytecodes.ASTORE_0:
case Bytecodes.ASTORE_1:
case Bytecodes.ASTORE_2:
case Bytecodes.ASTORE_3:
2015-05-08 05:35:57 +03:00
ref[lp + op - Bytecodes.ASTORE_0] = ref[--sp];
2015-05-08 10:57:48 +03:00
continue;
2015-05-08 01:17:05 +03:00
case Bytecodes.LSTORE_0:
case Bytecodes.LSTORE_1:
case Bytecodes.LSTORE_2:
case Bytecodes.LSTORE_3:
2015-05-09 12:47:47 +03:00
offset = lp + op - Bytecodes.LSTORE_0;
i32[offset + 1] = i32[--sp];
i32[offset] = i32[--sp];
continue;
case Bytecodes.DSTORE_0:
case Bytecodes.DSTORE_1:
case Bytecodes.DSTORE_2:
2015-05-08 01:17:05 +03:00
case Bytecodes.DSTORE_3:
2015-05-09 12:47:47 +03:00
offset = lp + op - Bytecodes.DSTORE_0;
i32[offset + 1] = i32[--sp];
i32[offset] = i32[--sp];
2015-05-08 10:57:48 +03:00
continue;
2015-05-06 11:26:46 +03:00
case Bytecodes.IASTORE:
2015-05-08 05:35:57 +03:00
value = i32[--sp];
index = i32[--sp];
array = ref[--sp];
2015-05-08 09:37:31 +03:00
if ((index >>> 0) >= (array.length >>> 0)) {
2015-05-11 10:27:23 +03:00
throwException(ExceptionType.ArrayIndexOutOfBoundsException, index);
2015-05-08 09:37:31 +03:00
}
2015-05-08 03:31:22 +03:00
array[index] = value;
2015-05-08 10:57:48 +03:00
continue;
2015-05-06 11:26:46 +03:00
case Bytecodes.FASTORE:
2015-05-09 07:14:44 +03:00
value = f32[--sp];
2015-05-08 05:35:57 +03:00
index = i32[--sp];
array = ref[--sp];
2015-05-08 09:37:31 +03:00
if ((index >>> 0) >= (array.length >>> 0)) {
2015-05-11 10:27:23 +03:00
throwException(ExceptionType.ArrayIndexOutOfBoundsException, index);
2015-05-08 09:37:31 +03:00
}
2015-05-08 03:31:22 +03:00
array[index] = value;
2015-05-08 10:57:48 +03:00
continue;
2015-05-06 11:26:46 +03:00
case Bytecodes.BASTORE:
2015-05-08 05:35:57 +03:00
value = i32[--sp];
index = i32[--sp];
array = ref[--sp];
2015-05-08 09:37:31 +03:00
if ((index >>> 0) >= (array.length >>> 0)) {
2015-05-11 10:27:23 +03:00
throwException(ExceptionType.ArrayIndexOutOfBoundsException, index);
2015-05-08 09:37:31 +03:00
}
2015-05-08 03:31:22 +03:00
array[index] = value;
2015-05-08 10:57:48 +03:00
continue;
2015-05-06 11:26:46 +03:00
case Bytecodes.CASTORE:
2015-05-08 05:35:57 +03:00
value = i32[--sp];
index = i32[--sp];
array = ref[--sp];
2015-05-08 09:37:31 +03:00
if ((index >>> 0) >= (array.length >>> 0)) {
2015-05-11 10:27:23 +03:00
throwException(ExceptionType.ArrayIndexOutOfBoundsException, index);
2015-05-08 09:37:31 +03:00
}
2015-05-08 03:31:22 +03:00
array[index] = value;
2015-05-08 10:57:48 +03:00
continue;
2015-05-06 11:26:46 +03:00
case Bytecodes.SASTORE:
2015-05-08 05:35:57 +03:00
value = i32[--sp];
index = i32[--sp];
array = ref[--sp];
2015-05-08 09:37:31 +03:00
if ((index >>> 0) >= (array.length >>> 0)) {
2015-05-11 10:27:23 +03:00
throwException(ExceptionType.ArrayIndexOutOfBoundsException, index);
2015-05-08 09:37:31 +03:00
}
2015-05-06 11:26:46 +03:00
array[index] = value;
2015-05-08 10:57:48 +03:00
continue;
2015-05-09 07:14:44 +03:00
case Bytecodes.LASTORE:
lh = i32[--sp];
ll = i32[--sp];
index = i32[--sp];
array = ref[--sp];
if ((index >>> 0) >= (array.length >>> 0)) {
2015-05-11 10:27:23 +03:00
throwException(ExceptionType.ArrayIndexOutOfBoundsException, index);
2015-05-09 07:14:44 +03:00
}
array.value[index * 2 ] = ll;
array.value[index * 2 + 1] = lh;
2015-05-09 07:14:44 +03:00
continue;
case Bytecodes.LALOAD:
index = i32[--sp];
array = ref[--sp];
if ((index >>> 0) >= (array.length >>> 0)) {
2015-05-11 10:27:23 +03:00
throwException(ExceptionType.ArrayIndexOutOfBoundsException, index);
2015-05-09 07:14:44 +03:00
}
i32[sp++] = array.value[index * 2 ];
i32[sp++] = array.value[index * 2 + 1];
2015-05-09 07:14:44 +03:00
continue;
case Bytecodes.DASTORE:
aliasedI32[1] = i32[--sp];
aliasedI32[0] = i32[--sp];
value = aliasedF64[0];
2015-05-09 07:14:44 +03:00
index = i32[--sp];
array = ref[--sp];
if ((index >>> 0) >= (array.length >>> 0)) {
2015-05-11 10:27:23 +03:00
throwException(ExceptionType.ArrayIndexOutOfBoundsException, index);
2015-05-09 07:14:44 +03:00
}
array[index] = value;
continue;
case Bytecodes.AASTORE:
value = ref[--sp];
index = i32[--sp];
array = ref[--sp];
if ((index >>> 0) >= (array.length >>> 0)) {
2015-05-11 10:27:23 +03:00
throwException(ExceptionType.ArrayIndexOutOfBoundsException, index);
2015-05-09 07:14:44 +03:00
}
checkArrayStore(array, value);
array[index] = value;
2015-05-11 02:00:43 +03:00
continue;
2015-05-08 10:52:22 +03:00
case Bytecodes.POP:
--sp;
2015-05-08 10:57:48 +03:00
continue;
2015-05-08 10:52:22 +03:00
case Bytecodes.POP2:
sp -= 2;
2015-05-08 10:57:48 +03:00
continue;
2015-05-15 09:28:30 +03:00
case Bytecodes.DUP: // ... a -> ... a, a
i32[sp] = i32[sp - 1]; ref[sp] = ref[sp - 1];
2015-05-06 11:26:46 +03:00
sp++;
2015-05-08 10:57:48 +03:00
continue;
2015-05-15 09:28:30 +03:00
case Bytecodes.DUP2: // ... b, a -> ... b, a, b, a
i32[sp ] = i32[sp - 2]; ref[sp ] = ref[sp - 2]; // b
i32[sp + 1] = i32[sp - 1]; ref[sp + 1] = ref[sp - 1]; // a
2015-05-09 12:47:47 +03:00
sp += 2;
2015-05-11 02:00:43 +03:00
continue;
2015-05-15 09:28:30 +03:00
case Bytecodes.DUP_X1: // ... b, a -> ... a, b, a
i32[sp ] = i32[sp - 1]; ref[sp ] = ref[sp - 1]; // a
i32[sp - 1] = i32[sp - 2]; ref[sp - 1] = ref[sp - 2]; // b
i32[sp - 2] = i32[sp]; ref[sp - 2] = ref[sp]; // a
sp++;
continue;
2015-05-15 09:28:30 +03:00
case Bytecodes.DUP_X2: // ... c, b, a -> ... a, c, b, a
i32[sp ] = i32[sp - 1]; ref[sp ] = ref[sp - 1]; // a
i32[sp - 1] = i32[sp - 2]; ref[sp - 1] = ref[sp - 2]; // b
i32[sp - 2] = i32[sp - 3]; ref[sp - 2] = ref[sp - 3]; // c
i32[sp - 3] = i32[sp]; ref[sp - 3] = ref[sp]; // a
2015-05-08 10:52:22 +03:00
sp++;
2015-05-08 10:57:48 +03:00
continue;
2015-05-15 09:28:30 +03:00
case Bytecodes.DUP2_X1: // ... c, b, a -> ... b, a, c, b, a
i32[sp + 1] = i32[sp - 1]; ref[sp + 1] = ref[sp - 1]; // a
i32[sp ] = i32[sp - 2]; ref[sp ] = ref[sp - 2]; // b
i32[sp - 1] = i32[sp - 3]; ref[sp - 1] = ref[sp - 3]; // c
i32[sp - 2] = i32[sp + 1]; ref[sp - 2] = ref[sp + 1]; // a
i32[sp - 3] = i32[sp ]; ref[sp - 3] = ref[sp ]; // b
sp += 2;
continue;
case Bytecodes.DUP2: // ... b, a -> ... b, a, b, a
i32[sp + 1] = i32[sp - 1]; ref[sp + 1] = ref[sp - 1]; // a
i32[sp ] = i32[sp - 2]; ref[sp ] = ref[sp - 2]; // b
sp += 2;
continue;
case Bytecodes.DUP2_X2: // ... d, c, b, a -> ... b, a, d, c, b, a
i32[sp + 1] = i32[sp - 1]; ref[sp + 1] = ref[sp - 1]; // a
i32[sp ] = i32[sp - 2]; ref[sp ] = ref[sp - 2]; // b
i32[sp - 1] = i32[sp - 3]; ref[sp - 1] = ref[sp - 3]; // c
i32[sp - 2] = i32[sp - 4]; ref[sp - 2] = ref[sp - 4]; // d
i32[sp - 3] = i32[sp + 1]; ref[sp - 3] = ref[sp + 1]; // a
i32[sp - 4] = i32[sp ]; ref[sp - 4] = ref[sp ]; // b
sp += 2;
continue;
case Bytecodes.SWAP:
ia = i32[sp - 1]; object = ref[sp - 1];
i32[sp - 1] = i32[sp - 2]; ref[sp - 1] = ref[sp - 2];
i32[sp - 2] = ia; ref[sp - 2] = object;
continue;
2015-05-08 01:17:05 +03:00
case Bytecodes.IINC:
index = code[pc++];
2015-05-08 09:37:31 +03:00
value = code[pc++] << 24 >> 24;
2015-05-09 23:37:04 +03:00
i32[lp + index] = i32[lp + index] + value | 0;
2015-05-08 10:57:48 +03:00
continue;
2015-05-06 11:26:46 +03:00
// case Bytecodes.IINC_GOTO:
// index = frame.read8();
// value = frame.read8Signed();
// frame.local[index] += frame.local[index];
// frame.pc ++;
// frame.pc = frame.readTargetPC();
// break;
2015-05-08 01:17:05 +03:00
case Bytecodes.IADD:
i32[sp - 2] = (i32[sp - 2] + i32[sp - 1]) | 0; sp--;
2015-05-08 10:57:48 +03:00
continue;
2015-05-08 01:17:05 +03:00
case Bytecodes.LADD:
ASM._lAdd(sp - 4 << 2, sp - 4 << 2, sp - 2 << 2); sp -= 2;
2015-05-08 10:57:48 +03:00
continue;
case Bytecodes.FADD:
f32[sp - 2] = f32[sp - 2] + f32[sp - 1]; sp--;
2015-05-11 02:00:43 +03:00
continue;
2015-05-10 00:57:32 +03:00
case Bytecodes.DADD:
aliasedI32[0] = i32[sp - 4];
aliasedI32[1] = i32[sp - 3]; ia = aliasedF64[0];
aliasedI32[0] = i32[sp - 2];
aliasedI32[1] = i32[sp - 1]; ib = aliasedF64[0];
aliasedF64[0] = ia + ib;
i32[sp - 4] = aliasedI32[0];
i32[sp - 3] = aliasedI32[1];
sp -= 2;
continue;
2015-05-08 01:17:05 +03:00
case Bytecodes.ISUB:
i32[sp - 2] = (i32[sp - 2] - i32[sp - 1]) | 0; sp--;
2015-05-08 10:57:48 +03:00
continue;
2015-05-08 01:17:05 +03:00
case Bytecodes.LSUB:
ASM._lSub(sp - 4 << 2, sp - 4 << 2, sp - 2 << 2); sp -= 2;
2015-05-08 10:57:48 +03:00
continue;
case Bytecodes.FSUB:
f32[sp - 2] = f32[sp - 2] - f32[sp - 1]; sp--;
2015-05-11 02:00:43 +03:00
continue;
2015-05-10 00:57:32 +03:00
case Bytecodes.DSUB:
aliasedI32[0] = i32[sp - 4];
aliasedI32[1] = i32[sp - 3]; ia = aliasedF64[0];
aliasedI32[0] = i32[sp - 2];
aliasedI32[1] = i32[sp - 1]; ib = aliasedF64[0];
aliasedF64[0] = ia - ib;
i32[sp - 4] = aliasedI32[0];
i32[sp - 3] = aliasedI32[1];
sp -= 2;
continue;
2015-05-08 01:17:05 +03:00
case Bytecodes.IMUL:
i32[sp - 2] = Math.imul(i32[sp - 2], i32[sp - 1]) | 0; sp--;
2015-05-08 10:57:48 +03:00
continue;
2015-05-08 10:52:22 +03:00
case Bytecodes.LMUL:
ASM._lMul(sp - 4 << 2, sp - 4 << 2, sp - 2 << 2); sp -= 2;
2015-05-08 10:57:48 +03:00
continue;
case Bytecodes.FMUL:
f32[sp - 2] = f32[sp - 2] * f32[sp - 1]; sp--;
continue;
2015-05-10 00:57:32 +03:00
case Bytecodes.DMUL:
aliasedI32[0] = i32[sp - 4];
aliasedI32[1] = i32[sp - 3]; ia = aliasedF64[0];
aliasedI32[0] = i32[sp - 2];
aliasedI32[1] = i32[sp - 1]; ib = aliasedF64[0];
aliasedF64[0] = ia * ib;
i32[sp - 4] = aliasedI32[0];
i32[sp - 3] = aliasedI32[1];
sp -= 2;
continue;
2015-05-08 11:19:17 +03:00
case Bytecodes.IDIV:
if (i32[sp - 1] === 0) {
2015-05-11 10:27:23 +03:00
throwException(ExceptionType.ArithmeticException);
2015-05-08 11:19:17 +03:00
}
ia = i32[sp - 2];
ib = i32[sp - 1];
i32[sp - 2] = (ia === Constants.INT_MIN && ib === -1) ? ia : ((ia / ib) | 0); sp--;
2015-05-10 00:57:32 +03:00
continue;
2015-05-08 10:52:22 +03:00
case Bytecodes.LDIV:
if (i32[sp - 2] === 0 && i32[sp - 1] === 0) {
2015-05-11 10:27:23 +03:00
throwException(ExceptionType.ArithmeticException);
2015-05-08 10:52:22 +03:00
}
ASM._lDiv(sp - 4 << 2, sp - 4 << 2, sp - 2 << 2); sp -= 2;
2015-05-08 10:57:48 +03:00
continue;
2015-05-09 07:14:44 +03:00
case Bytecodes.FDIV:
fb = f32[--sp];
fa = f32[--sp];
f32[sp++] = Math.fround(fa / fb);
continue;
2015-05-06 11:26:46 +03:00
case Bytecodes.DDIV:
2015-05-10 00:57:32 +03:00
aliasedI32[0] = i32[sp - 4];
aliasedI32[1] = i32[sp - 3]; ia = aliasedF64[0];
aliasedI32[0] = i32[sp - 2];
aliasedI32[1] = i32[sp - 1]; ib = aliasedF64[0];
aliasedF64[0] = ia / ib;
i32[sp - 4] = aliasedI32[0];
i32[sp - 3] = aliasedI32[1];
sp -= 2;
2015-05-11 02:00:43 +03:00
continue;
2015-05-08 11:19:17 +03:00
case Bytecodes.IREM:
if (i32[sp - 1] === 0) {
2015-05-11 10:27:23 +03:00
throwException(ExceptionType.ArithmeticException);
2015-05-08 11:19:17 +03:00
}
2015-05-09 12:47:47 +03:00
i32[sp - 2] = (i32[sp - 2] % i32[sp - 1]) | 0; sp--;
2015-05-11 02:00:43 +03:00
continue;
2015-05-08 10:52:22 +03:00
case Bytecodes.LREM:
if (i32[sp - 2] === 0 && i32[sp - 1] === 0) {
2015-05-11 10:27:23 +03:00
throwException(ExceptionType.ArithmeticException);
2015-05-08 10:52:22 +03:00
}
ASM._lRem(sp - 4 << 2, sp - 4 << 2, sp - 2 << 2); sp -= 2;
2015-05-08 10:57:48 +03:00
continue;
2015-05-09 07:14:44 +03:00
case Bytecodes.FREM:
fb = f32[--sp];
fa = f32[--sp];
f32[sp++] = Math.fround(fa % fb);
2015-05-11 02:00:43 +03:00
continue;
2015-05-10 00:57:32 +03:00
case Bytecodes.DREM:
aliasedI32[0] = i32[sp - 4];
aliasedI32[1] = i32[sp - 3]; ia = aliasedF64[0];
aliasedI32[0] = i32[sp - 2];
aliasedI32[1] = i32[sp - 1]; ib = aliasedF64[0];
aliasedF64[0] = ia % ib;
i32[sp - 4] = aliasedI32[0];
i32[sp - 3] = aliasedI32[1];
sp -= 2;
continue;
2015-05-06 11:26:46 +03:00
case Bytecodes.INEG:
2015-05-08 03:31:22 +03:00
i32[sp - 1] = -i32[sp - 1] | 0;
2015-05-08 10:57:48 +03:00
continue;
case Bytecodes.LNEG:
ASM._lNeg(sp - 2 << 2, sp - 2 << 2);
continue;
case Bytecodes.FNEG:
f32[sp - 1] = -f32[sp - 1];
2015-05-11 02:00:43 +03:00
continue;
2015-05-10 00:57:32 +03:00
case Bytecodes.DNEG:
aliasedI32[0] = i32[sp - 2];
aliasedI32[1] = i32[sp - 1];
aliasedF64[0] = -aliasedF64[0];
i32[sp - 2] = aliasedI32[0];
i32[sp - 1] = aliasedI32[1];
continue;
2015-05-06 11:26:46 +03:00
case Bytecodes.ISHL:
2015-05-08 05:35:57 +03:00
ib = i32[--sp];
ia = i32[--sp];
i32[sp++] = ia << ib;
2015-05-08 10:57:48 +03:00
continue;
2015-05-08 10:52:22 +03:00
case Bytecodes.LSHL:
ASM._lShl(sp - 3 << 2, sp - 3 << 2, i32[sp - 1]); sp -= 1;
2015-05-08 10:57:48 +03:00
continue;
2015-05-06 11:26:46 +03:00
case Bytecodes.ISHR:
2015-05-08 05:35:57 +03:00
ib = i32[--sp];
ia = i32[--sp];
i32[sp++] = ia >> ib;
2015-05-08 10:57:48 +03:00
continue;
2015-05-08 10:52:22 +03:00
case Bytecodes.LSHR:
ASM._lShr(sp - 3 << 2, sp - 3 << 2, i32[sp - 1]); sp -= 1;
2015-05-08 10:57:48 +03:00
continue;
2015-05-06 11:26:46 +03:00
case Bytecodes.IUSHR:
2015-05-08 05:35:57 +03:00
ib = i32[--sp];
ia = i32[--sp];
i32[sp++] = ia >>> ib;
2015-05-08 10:57:48 +03:00
continue;
2015-05-08 10:52:22 +03:00
case Bytecodes.LUSHR:
ASM._lUshr(sp - 3 << 2, sp - 3 << 2, i32[sp - 1]); sp -= 1;
2015-05-08 10:57:48 +03:00
continue;
2015-05-06 11:26:46 +03:00
case Bytecodes.IAND:
2015-05-08 05:35:57 +03:00
i32[sp - 2] &= i32[--sp];
2015-05-08 10:57:48 +03:00
continue;
2015-05-10 00:57:32 +03:00
case Bytecodes.LAND:
i32[sp - 4] &= i32[sp - 2];
i32[sp - 3] &= i32[sp - 1]; sp -= 2;
break;
2015-05-06 11:26:46 +03:00
case Bytecodes.IOR:
2015-05-08 05:35:57 +03:00
i32[sp - 2] |= i32[--sp];
2015-05-08 10:57:48 +03:00
continue;
2015-05-10 00:57:32 +03:00
case Bytecodes.LOR:
i32[sp - 4] |= i32[sp - 2];
i32[sp - 3] |= i32[sp - 1]; sp -= 2;
continue;
2015-05-06 11:26:46 +03:00
case Bytecodes.IXOR:
2015-05-08 05:35:57 +03:00
i32[sp - 2] ^= i32[--sp];
2015-05-08 10:57:48 +03:00
continue;
2015-05-10 00:57:32 +03:00
case Bytecodes.LXOR:
i32[sp - 4] ^= i32[sp - 2];
i32[sp - 3] ^= i32[sp - 1]; sp -= 2;
continue;
2015-05-09 07:14:44 +03:00
case Bytecodes.LCMP:
ASM._lCmp(sp - 4 << 2, sp - 4 << 2, sp - 2 << 2); sp -= 3;
2015-05-10 00:57:32 +03:00
continue;
2015-05-09 07:14:44 +03:00
case Bytecodes.FCMPL:
case Bytecodes.FCMPG:
fb = f32[--sp];
fa = f32[--sp];
if (isNaN(fa) || isNaN(fb)) {
i32[sp++] = op === Bytecodes.FCMPL ? -1 : 1;
} else if (fa > fb) {
i32[sp++] = 1;
} else if (fa < fb) {
i32[sp++] = -1;
} else {
i32[sp++] = 0;
}
2015-05-10 00:57:32 +03:00
continue;
2015-05-09 07:14:44 +03:00
case Bytecodes.DCMPL:
case Bytecodes.DCMPG:
aliasedI32[0] = i32[sp - 2];
aliasedI32[1] = i32[sp - 1];
fb = aliasedF64[0];
aliasedI32[0] = i32[sp - 4];
aliasedI32[1] = i32[sp - 3];
fa = aliasedF64[0];
2015-05-09 07:14:44 +03:00
sp -= 4;
if (isNaN(fa) || isNaN(fb)) {
i32[sp++] = op === Bytecodes.DCMPL ? -1 : 1;
} else if (fa > fb) {
i32[sp++] = 1;
} else if (fa < fb) {
i32[sp++] = -1;
} else {
i32[sp++] = 0;
}
2015-05-10 00:57:32 +03:00
continue;
2015-05-06 11:26:46 +03:00
case Bytecodes.IFEQ:
2015-05-15 11:16:12 +03:00
targetPC = opPC + ((code[pc++] << 8 | code[pc++]) << 16 >> 16);
2015-05-08 05:35:57 +03:00
if (i32[--sp] === 0) {
2015-05-06 11:26:46 +03:00
pc = targetPC;
}
2015-05-08 10:57:48 +03:00
continue;
2015-05-06 11:26:46 +03:00
case Bytecodes.IFNE:
2015-05-15 11:16:12 +03:00
targetPC = opPC + ((code[pc++] << 8 | code[pc++]) << 16 >> 16);
2015-05-08 05:35:57 +03:00
if (i32[--sp] !== 0) {
2015-05-06 11:26:46 +03:00
pc = targetPC;
}
2015-05-08 10:57:48 +03:00
continue;
2015-05-06 11:26:46 +03:00
case Bytecodes.IFLT:
2015-05-15 11:16:12 +03:00
targetPC = opPC + ((code[pc++] << 8 | code[pc++]) << 16 >> 16);
2015-05-08 05:35:57 +03:00
if (i32[--sp] < 0) {
2015-05-06 11:26:46 +03:00
pc = targetPC;
}
2015-05-08 10:57:48 +03:00
continue;
2015-05-06 11:26:46 +03:00
case Bytecodes.IFGE:
2015-05-15 11:16:12 +03:00
targetPC = opPC + ((code[pc++] << 8 | code[pc++]) << 16 >> 16);
2015-05-08 05:35:57 +03:00
if (i32[--sp] >= 0) {
2015-05-06 11:26:46 +03:00
pc = targetPC;
}
2015-05-08 10:57:48 +03:00
continue;
2015-05-06 11:26:46 +03:00
case Bytecodes.IFGT:
2015-05-15 11:16:12 +03:00
targetPC = opPC + ((code[pc++] << 8 | code[pc++]) << 16 >> 16);
2015-05-08 05:35:57 +03:00
if (i32[--sp] > 0) {
2015-05-06 11:26:46 +03:00
pc = targetPC;
}
2015-05-08 10:57:48 +03:00
continue;
2015-05-06 11:26:46 +03:00
case Bytecodes.IFLE:
2015-05-15 11:16:12 +03:00
targetPC = opPC + ((code[pc++] << 8 | code[pc++]) << 16 >> 16);
2015-05-08 05:35:57 +03:00
if (i32[--sp] <= 0) {
2015-05-06 11:26:46 +03:00
pc = targetPC;
}
2015-05-08 10:57:48 +03:00
continue;
2015-05-06 11:26:46 +03:00
case Bytecodes.IF_ICMPEQ:
2015-05-15 11:16:12 +03:00
targetPC = opPC + ((code[pc++] << 8 | code[pc++]) << 16 >> 16);
2015-05-08 05:35:57 +03:00
if (i32[--sp] === i32[--sp]) {
2015-05-06 11:26:46 +03:00
pc = targetPC;
}
2015-05-08 10:57:48 +03:00
continue;
2015-05-06 11:26:46 +03:00
case Bytecodes.IF_ICMPNE:
2015-05-15 11:16:12 +03:00
targetPC = opPC + ((code[pc++] << 8 | code[pc++]) << 16 >> 16);
2015-05-08 05:35:57 +03:00
if (i32[--sp] !== i32[--sp]) {
2015-05-06 11:26:46 +03:00
pc = targetPC;
}
2015-05-08 10:57:48 +03:00
continue;
2015-05-06 11:26:46 +03:00
case Bytecodes.IF_ICMPLT:
2015-05-15 11:16:12 +03:00
targetPC = opPC + ((code[pc++] << 8 | code[pc++]) << 16 >> 16);
2015-05-08 05:35:57 +03:00
if (i32[--sp] > i32[--sp]) {
2015-05-06 11:26:46 +03:00
pc = targetPC;
}
2015-05-08 10:57:48 +03:00
continue;
2015-05-06 11:26:46 +03:00
case Bytecodes.IF_ICMPGE:
2015-05-15 11:16:12 +03:00
targetPC = opPC + ((code[pc++] << 8 | code[pc++]) << 16 >> 16);
2015-05-08 05:35:57 +03:00
if (i32[--sp] <= i32[--sp]) {
2015-05-06 11:26:46 +03:00
pc = targetPC;
}
2015-05-08 10:57:48 +03:00
continue;
2015-05-06 11:26:46 +03:00
case Bytecodes.IF_ICMPGT:
2015-05-15 11:16:12 +03:00
targetPC = opPC + ((code[pc++] << 8 | code[pc++]) << 16 >> 16);
2015-05-08 05:35:57 +03:00
if (i32[--sp] < i32[--sp]) {
2015-05-06 11:26:46 +03:00
pc = targetPC;
}
2015-05-08 10:57:48 +03:00
continue;
2015-05-06 11:26:46 +03:00
case Bytecodes.IF_ICMPLE:
2015-05-15 11:16:12 +03:00
targetPC = opPC + ((code[pc++] << 8 | code[pc++]) << 16 >> 16);
2015-05-08 05:35:57 +03:00
if (i32[--sp] >= i32[--sp]) {
2015-05-06 11:26:46 +03:00
pc = targetPC;
}
2015-05-08 10:57:48 +03:00
continue;
2015-05-06 11:26:46 +03:00
case Bytecodes.IF_ACMPEQ:
2015-05-15 11:16:12 +03:00
targetPC = opPC + ((code[pc++] << 8 | code[pc++]) << 16 >> 16);
2015-05-08 05:35:57 +03:00
if (ref[--sp] === ref[--sp]) {
2015-05-06 11:26:46 +03:00
pc = targetPC;
}
2015-05-08 10:57:48 +03:00
continue;
2015-05-06 11:26:46 +03:00
case Bytecodes.IF_ACMPNE:
2015-05-15 11:16:12 +03:00
targetPC = opPC + ((code[pc++] << 8 | code[pc++]) << 16 >> 16);
2015-05-08 05:35:57 +03:00
if (ref[--sp] !== ref[--sp]) {
2015-05-06 11:26:46 +03:00
pc = targetPC;
}
2015-05-08 10:57:48 +03:00
continue;
2015-05-06 11:26:46 +03:00
case Bytecodes.IFNULL:
2015-05-15 11:16:12 +03:00
targetPC = opPC + ((code[pc++] << 8 | code[pc++]) << 16 >> 16);
2015-05-08 05:35:57 +03:00
if (!ref[--sp]) {
2015-05-06 11:26:46 +03:00
pc = targetPC;
}
2015-05-08 10:57:48 +03:00
continue;
2015-05-06 11:26:46 +03:00
case Bytecodes.IFNONNULL:
2015-05-15 11:16:12 +03:00
targetPC = opPC + ((code[pc++] << 8 | code[pc++]) << 16 >> 16);
2015-05-08 05:35:57 +03:00
if (ref[--sp]) {
2015-05-06 11:26:46 +03:00
pc = targetPC;
}
2015-05-08 10:57:48 +03:00
continue;
2015-05-06 11:26:46 +03:00
case Bytecodes.GOTO:
2015-05-15 11:16:12 +03:00
pc = opPC + ((code[pc++] << 8 | code[pc++]) << 16 >> 16);
2015-05-08 10:57:48 +03:00
continue;
2015-05-06 11:26:46 +03:00
// case Bytecodes.GOTO_W:
// frame.pc = frame.read32Signed() - 1;
// break;
// case Bytecodes.JSR:
// pc = frame.read16();
// stack.push(frame.pc);
// frame.pc = pc;
// break;
// case Bytecodes.JSR_W:
// pc = frame.read32();
// stack.push(frame.pc);
// frame.pc = pc;
// break;
// case Bytecodes.RET:
// frame.pc = frame.local[frame.read8()];
// break;
case Bytecodes.I2L:
2015-05-08 03:31:22 +03:00
i32[sp] = i32[sp - 1] < 0 ? -1 : 0; sp++;
2015-05-08 10:57:48 +03:00
continue;
2015-05-10 00:57:32 +03:00
case Bytecodes.I2F:
aliasedF32[0] = i32[--sp];
2015-05-15 23:34:07 +03:00
i32[sp++] = aliasedI32[0];
2015-05-10 00:57:32 +03:00
continue;
case Bytecodes.I2D:
aliasedF64[0] = i32[--sp];
2015-05-15 23:34:07 +03:00
i32[sp++] = aliasedI32[0];
i32[sp++] = aliasedI32[1];
2015-05-10 00:57:32 +03:00
continue;
2015-05-08 10:52:22 +03:00
case Bytecodes.L2I:
sp--;
2015-05-08 10:57:48 +03:00
continue;
case Bytecodes.L2F:
aliasedF32[0] = Math.fround(longToNumber(i32[sp - 2], i32[sp - 1]));
i32[sp - 2] = aliasedI32[0];
sp --;
continue;
case Bytecodes.L2D:
aliasedF64[0] = longToNumber(i32[sp - 2], i32[sp - 1]);
i32[sp - 2] = aliasedI32[0];
i32[sp - 1] = aliasedI32[1];
continue;
case Bytecodes.F2I:
fa = f32[sp - 1];
if (fa > Constants.INT_MAX) {
i32[sp - 1] = Constants.INT_MAX;
} else if (fa < Constants.INT_MIN) {
i32[sp - 1] = Constants.INT_MIN;
} else {
i32[sp - 1] = fa | 0;
}
continue;
case Bytecodes.F2L:
fa = f32[--sp];
value = Long.fromNumber(fa);
i32[sp++] = value.low_;
i32[sp++] = value.high_;
2015-05-11 02:00:43 +03:00
continue;
2015-05-10 00:57:32 +03:00
case Bytecodes.F2D:
aliasedF64[0] = f32[--sp];
2015-05-15 23:34:07 +03:00
i32[sp++] = aliasedI32[0];
i32[sp++] = aliasedI32[1];
2015-05-11 02:00:43 +03:00
continue;
2015-05-10 00:57:32 +03:00
case Bytecodes.D2I:
aliasedI32[0] = i32[sp - 2];
aliasedI32[1] = i32[sp - 1];
fa = aliasedF64[0];
if (fa > Constants.INT_MAX) {
i32[sp - 2] = Constants.INT_MAX;
} else if (fa < Constants.INT_MIN) {
i32[sp - 2] = Constants.INT_MIN;
} else {
i32[sp - 2] = fa | 0;
}
sp --;
2015-05-11 02:00:43 +03:00
continue;
case Bytecodes.D2L:
aliasedI32[0] = i32[sp - 2];
aliasedI32[1] = i32[sp - 1];
fa = aliasedF64[0];
if (fa === Number.POSITIVE_INFINITY) {
i32[sp - 2] = Constants.LONG_MAX_LOW;
i32[sp - 1] = Constants.LONG_MAX_HIGH;
} else if (fa === Number.NEGATIVE_INFINITY) {
i32[sp - 2] = Constants.LONG_MIN_LOW;
i32[sp - 1] = Constants.LONG_MIN_HIGH;
} else {
value = Long.fromNumber(fa);
i32[sp - 2] = value.low_;
i32[sp - 1] = value.high_;
}
continue;
case Bytecodes.D2F:
aliasedI32[0] = i32[sp - 2];
aliasedI32[1] = i32[sp - 1];
f32[sp - 2] = Math.fround(aliasedF64[0]);
sp --;
2015-05-11 02:00:43 +03:00
continue;
2015-05-08 01:17:05 +03:00
case Bytecodes.I2B:
2015-05-08 03:31:22 +03:00
i32[sp - 1] = (i32[sp - 1] << 24) >> 24;
2015-05-08 10:57:48 +03:00
continue;
2015-05-08 01:17:05 +03:00
case Bytecodes.I2C:
2015-05-08 03:31:22 +03:00
i32[sp - 1] &= 0xffff;
2015-05-08 10:57:48 +03:00
continue;
2015-05-08 01:17:05 +03:00
case Bytecodes.I2S:
2015-05-11 10:27:23 +03:00
i32[sp - 1] = (i32[sp - 1] << 16) >> 16;
2015-05-08 10:57:48 +03:00
continue;
2015-05-09 12:47:47 +03:00
case Bytecodes.TABLESWITCH:
pc = (pc + 3) & ~0x03; // Consume Padding
offset = code[pc++] << 24 | code[pc++] << 16 | code[pc++] << 8 | code[pc++];
ia = code[pc++] << 24 | code[pc++] << 16 | code[pc++] << 8 | code[pc++];
ib = code[pc++] << 24 | code[pc++] << 16 | code[pc++] << 8 | code[pc++];
value = i32[--sp];
if (value >= ia && value <= ib) {
pc += (value - ia) << 2;
offset = code[pc++] << 24 | code[pc++] << 16 | code[pc++] << 8 | code[pc++];
}
pc = opPC + offset;
2015-05-11 02:00:43 +03:00
continue;
2015-05-09 12:47:47 +03:00
case Bytecodes.LOOKUPSWITCH:
pc = (pc + 3) & ~0x03; // Consume Padding
offset = code[pc++] << 24 | code[pc++] << 16 | code[pc++] << 8 | code[pc++];
var npairs = code[pc++] << 24 | code[pc++] << 16 | code[pc++] << 8 | code[pc++];
value = i32[--sp];
lookup:
for (var i = 0; i < npairs; i++) {
var key = code[pc++] << 24 | code[pc++] << 16 | code[pc++] << 8 | code[pc++];
if (key === value) {
offset = code[pc++] << 24 | code[pc++] << 16 | code[pc++] << 8 | code[pc++];
} else {
pc += 4;
}
if (key >= value) {
break lookup;
}
}
pc = opPC + offset;
2015-05-11 02:00:43 +03:00
continue;
2015-05-08 01:17:05 +03:00
case Bytecodes.ANEWARRAY:
2015-05-09 23:37:04 +03:00
index = code[pc++] << 8 | code[pc++];
2015-05-08 01:17:05 +03:00
classInfo = resolveClass(index, ci);
classInitAndUnwindCheck(classInfo, opPC);
2015-05-08 05:35:57 +03:00
size = i32[--sp];
ref[sp++] = newArray(classInfo.klass, size);
2015-05-08 10:57:48 +03:00
continue;
2015-05-09 07:14:44 +03:00
case Bytecodes.MULTIANEWARRAY:
2015-05-09 23:37:04 +03:00
index = code[pc++] << 8 | code[pc++];
2015-05-09 07:14:44 +03:00
classInfo = resolveClass(index, ci);
var dimensions = code[pc++];
var lengths = new Array(dimensions);
for (var i = 0; i < dimensions; i++) {
lengths[i] = i32[--sp];
}
ref[sp++] = J2ME.newMultiArray(classInfo.klass, lengths.reverse());
2015-05-11 02:00:43 +03:00
continue;
2015-05-08 01:17:05 +03:00
case Bytecodes.ARRAYLENGTH:
2015-05-08 05:35:57 +03:00
array = ref[--sp];
i32[sp++] = array.length;
2015-05-08 10:57:48 +03:00
continue;
2015-05-06 11:26:46 +03:00
case Bytecodes.GETFIELD:
2015-05-09 07:14:44 +03:00
case Bytecodes.GETSTATIC:
2015-05-09 23:37:04 +03:00
index = code[pc++] << 8 | code[pc++];
fieldInfo = cp.resolved[index] || cp.resolveField(index, false);
2015-05-09 07:14:44 +03:00
if (op === Bytecodes.GETSTATIC) {
classInitAndUnwindCheck(fieldInfo.classInfo, opPC);
2015-05-16 04:58:19 +03:00
if (U) {
debugger;
return;
}
2015-05-09 07:14:44 +03:00
object = fieldInfo.classInfo.getStaticObject($.ctx);
} else {
object = ref[--sp];
}
2015-05-11 04:50:37 +03:00
address = object._address + fieldInfo.byteOffset;
switch (fieldInfo.kind) {
case Kind.Reference:
ref[sp++] = ref[address >> 2];
continue;
case Kind.Int:
case Kind.Byte:
case Kind.Char:
case Kind.Short:
case Kind.Boolean:
case Kind.Float:
i32[sp++] = i32[address >> 2];
continue;
case Kind.Long:
case Kind.Double:
i32[sp++] = i32[address >> 2];
i32[sp++] = i32[address + 4 >> 2];
continue;
default:
release || assert(false);
}
2015-05-11 02:00:43 +03:00
continue;
2015-05-06 11:26:46 +03:00
case Bytecodes.PUTFIELD:
case Bytecodes.PUTSTATIC:
2015-05-09 23:37:04 +03:00
index = code[pc++] << 8 | code[pc++];
fieldInfo = cp.resolved[index] || cp.resolveField(index, false);
2015-05-11 04:50:37 +03:00
isStatic = op === Bytecodes.PUTSTATIC;
if (isStatic) {
2015-05-09 07:14:44 +03:00
classInitAndUnwindCheck(fieldInfo.classInfo, opPC);
2015-05-16 04:58:19 +03:00
if (U) {
debugger;
return;
}
2015-05-09 07:14:44 +03:00
object = fieldInfo.classInfo.getStaticObject($.ctx);
} else {
2015-05-11 04:50:37 +03:00
object = ref[sp - (isTwoSlot(fieldInfo.kind) ? 3 : 2)];
}
address = object._address + fieldInfo.byteOffset;
switch (fieldInfo.kind) {
case Kind.Reference:
ref[address >> 2] = ref[--sp];
break;
case Kind.Int:
case Kind.Byte:
case Kind.Char:
case Kind.Short:
case Kind.Boolean:
case Kind.Float:
i32[address >> 2] = i32[--sp];
break;
case Kind.Long:
case Kind.Double:
i32[address + 4 >> 2] = i32[--sp];
i32[address >> 2] = i32[--sp];
break;
default:
release || assert(false);
}
if (!isStatic) {
sp--; // Pop Reference
2015-05-09 07:14:44 +03:00
}
2015-05-11 02:00:43 +03:00
continue;
2015-05-06 11:26:46 +03:00
case Bytecodes.NEW:
2015-05-09 23:37:04 +03:00
index = code[pc++] << 8 | code[pc++];
release || traceWriter && traceWriter.writeLn(mi.implKey + " " + index);
2015-05-06 11:26:46 +03:00
classInfo = resolveClass(index, ci);
thread.set(fp, sp, pc);
classInitAndUnwindCheck(classInfo, opPC);
2015-05-06 11:26:46 +03:00
if (U) {
2015-05-16 04:58:19 +03:00
debugger;
2015-05-06 11:26:46 +03:00
return;
}
loadThreadState();
2015-05-08 05:35:57 +03:00
ref[sp++] = newObject(classInfo.klass);
2015-05-08 10:57:48 +03:00
continue;
2015-05-08 01:17:05 +03:00
case Bytecodes.CHECKCAST:
2015-05-09 23:37:04 +03:00
index = code[pc++] << 8 | code[pc++];
2015-05-08 01:17:05 +03:00
classInfo = resolveClass(index, mi.classInfo);
2015-05-08 05:35:57 +03:00
object = ref[sp - 1];
2015-05-08 01:17:05 +03:00
if (object && !isAssignableTo(object.klass, classInfo.klass)) {
throw $.newClassCastException (
object.klass.classInfo.getClassNameSlow() + " is not assignable to " +
classInfo.getClassNameSlow()
);
}
2015-05-08 10:57:48 +03:00
continue;
2015-05-08 01:17:05 +03:00
case Bytecodes.INSTANCEOF:
2015-05-09 23:37:04 +03:00
index = code[pc++] << 8 | code[pc++];
2015-05-08 01:17:05 +03:00
classInfo = resolveClass(index, ci);
2015-05-08 05:35:57 +03:00
object = ref[--sp];
2015-05-08 01:17:05 +03:00
result = !object ? false : isAssignableTo(object.klass, classInfo.klass);
i32[sp++] = result ? 1 : 0;
2015-05-08 10:57:48 +03:00
continue;
2015-05-08 01:17:05 +03:00
case Bytecodes.ATHROW:
2015-05-08 05:35:57 +03:00
object = ref[--sp];
2015-05-08 01:17:05 +03:00
if (!object) {
throw $.newNullPointerException();
}
throw object;
2015-05-08 10:57:48 +03:00
continue;
2015-05-06 11:26:46 +03:00
case Bytecodes.MONITORENTER:
2015-05-08 05:35:57 +03:00
object = ref[--sp];
2015-05-06 11:26:46 +03:00
thread.ctx.monitorEnter(object);
if (U === VMState.Pausing || U === VMState.Stopping) {
return;
}
2015-05-08 10:57:48 +03:00
continue;
2015-05-06 11:26:46 +03:00
case Bytecodes.MONITOREXIT:
2015-05-08 05:35:57 +03:00
object = ref[--sp];
2015-05-06 11:26:46 +03:00
thread.ctx.monitorExit(object);
2015-05-08 10:57:48 +03:00
continue;
2015-05-10 00:57:32 +03:00
case Bytecodes.WIDE:
var op = code[pc++];
switch (op) {
case Bytecodes.ILOAD:
case Bytecodes.FLOAD:
i32[sp++] = i32[lp + (code[pc++] << 8 | code[pc++])];
continue;
case Bytecodes.ALOAD:
ref[sp++] = ref[lp + (code[pc++] << 8 | code[pc++])];
continue;
case Bytecodes.LLOAD:
case Bytecodes.DLOAD:
offset = lp + (code[pc++] << 8 | code[pc++]);
i32[sp++] = i32[offset];
i32[sp++] = i32[offset + 1];
continue;
case Bytecodes.ISTORE:
case Bytecodes.FSTORE:
i32[lp + (code[pc++] << 8 | code[pc++])] = i32[--sp];
continue;
case Bytecodes.ASTORE:
ref[lp + (code[pc++] << 8 | code[pc++])] = ref[--sp];
continue;
case Bytecodes.LSTORE:
case Bytecodes.DSTORE:
offset = lp + (code[pc++] << 8 | code[pc++]);
i32[offset + 1] = i32[--sp];
i32[offset] = i32[--sp];
continue;
case Bytecodes.IINC:
index = code[pc++] << 8 | code[pc++];
2015-05-16 00:36:01 +03:00
value = (code[pc++] << 8 | code[pc++]) << 16 >> 16;
2015-05-10 00:57:32 +03:00
i32[lp + index] = i32[lp + index] + value | 0;
continue;
//case Bytecodes.RET:
// this.pc = this.local[this.read16()];
// break;
default:
var opName = Bytecodes[op];
throw new Error("Wide opcode " + opName + " [" + op + "] not supported.");
}
continue;
2015-05-06 11:26:46 +03:00
case Bytecodes.NEWARRAY:
type = code[pc++];
2015-05-08 05:35:57 +03:00
size = i32[--sp];
2015-05-08 03:31:22 +03:00
ref[sp++] = newArray(PrimitiveClassInfo["????ZCFDBSIJ"[type]].klass, size);
2015-05-08 10:57:48 +03:00
continue;
2015-05-08 01:17:05 +03:00
case Bytecodes.LRETURN:
case Bytecodes.DRETURN:
case Bytecodes.IRETURN:
case Bytecodes.FRETURN:
case Bytecodes.ARETURN:
2015-05-06 11:26:46 +03:00
case Bytecodes.RETURN:
2015-05-10 02:41:11 +03:00
var lastSP = sp;
2015-05-11 10:27:23 +03:00
var lastMI = mi;
2015-05-16 01:22:12 +03:00
opPC = i32[fp + FrameLayout.CallerRAOffset];
2015-05-10 02:41:11 +03:00
sp = fp - maxLocals;
2015-05-08 03:31:22 +03:00
fp = i32[fp + FrameLayout.CallerFPOffset];
mi = ref[fp + FrameLayout.CalleeMethodInfoOffset];
2015-05-16 04:58:19 +03:00
monitor = ref[fp + FrameLayout.MonitorOffset];
2015-05-06 11:26:46 +03:00
if (mi === null) {
2015-05-16 01:22:12 +03:00
thread.set(fp, sp, opPC);
2015-05-06 11:26:46 +03:00
thread.popFrame(null);
2015-05-10 02:41:11 +03:00
// REDUX: What do we do about the return value here?
2015-05-06 11:26:46 +03:00
return;
}
2015-05-16 04:58:19 +03:00
if (mi.isSynchronized && monitor) {
$.ctx.monitorExit(monitor);
}
2015-05-08 03:31:22 +03:00
maxLocals = mi.codeAttribute.max_locals;
lp = fp - maxLocals;
release || traceWriter && traceWriter.outdent();
2015-05-11 10:27:23 +03:00
release || traceWriter && traceWriter.writeLn("<< I " + lastMI.implKey);
2015-05-06 11:26:46 +03:00
ci = mi.classInfo;
cp = ci.constantPool;
code = mi.codeAttribute.code;
2015-05-16 01:22:12 +03:00
// Calculate the PC based on the size of the caller's invoke bytecode.
pc = opPC + (code[opPC] === Bytecodes.INVOKEINTERFACE ? 5 : 3);
2015-05-10 02:41:11 +03:00
// Push return value.
switch (op) {
case Bytecodes.LRETURN:
case Bytecodes.DRETURN:
i32[sp++] = i32[lastSP - 2]; // Low Bits
// Fallthrough
2015-05-10 02:41:11 +03:00
case Bytecodes.IRETURN:
case Bytecodes.FRETURN:
i32[sp++] = i32[lastSP - 1];
continue;
case Bytecodes.ARETURN:
ref[sp++] = ref[lastSP - 1];
continue;
}
2015-05-08 10:57:48 +03:00
continue;
2015-05-06 11:26:46 +03:00
case Bytecodes.INVOKEVIRTUAL:
case Bytecodes.INVOKESPECIAL:
case Bytecodes.INVOKESTATIC:
case Bytecodes.INVOKEINTERFACE:
2015-05-08 11:19:17 +03:00
index = code[pc++] << 8 | code[pc++];
2015-05-06 11:26:46 +03:00
if (op === Bytecodes.INVOKEINTERFACE) {
pc += 2; // Args Number & Zero
}
2015-05-11 04:50:37 +03:00
isStatic = (op === Bytecodes.INVOKESTATIC);
2015-05-06 11:26:46 +03:00
// Resolve method and do the class init check if necessary.
2015-05-08 11:19:17 +03:00
var calleeMethodInfo = cp.resolved[index] || cp.resolveMethod(index, isStatic);
2015-05-16 04:58:19 +03:00
var calleeTargetMethodInfo: MethodInfo = null;
2015-05-06 11:26:46 +03:00
var callee = null;
object = null;
if (!isStatic) {
2015-05-08 03:31:22 +03:00
object = ref[sp - calleeMethodInfo.argumentSlots];
2015-05-06 11:26:46 +03:00
}
2015-05-16 04:58:19 +03:00
if (isStatic) {
classInitAndUnwindCheck(calleeMethodInfo.classInfo, opPC);
if (U) {
thread.set(fp, sp, opPC);
return;
}
}
2015-05-06 11:26:46 +03:00
switch (op) {
case Bytecodes.INVOKESPECIAL:
checkNull(object);
case Bytecodes.INVOKESTATIC:
2015-05-09 07:14:44 +03:00
calleeTargetMethodInfo = calleeMethodInfo;
2015-05-06 11:26:46 +03:00
break;
case Bytecodes.INVOKEVIRTUAL:
calleeTargetMethodInfo = object.klass.classInfo.vTable[calleeMethodInfo.vTableIndex];
2015-05-09 07:14:44 +03:00
break;
2015-05-06 11:26:46 +03:00
case Bytecodes.INVOKEINTERFACE:
2015-05-09 07:14:44 +03:00
calleeTargetMethodInfo = object.klass.classInfo.iTable[calleeMethodInfo.mangledName];
2015-05-06 11:26:46 +03:00
break;
default:
release || traceWriter && traceWriter.writeLn("Not Implemented: " + Bytecodes[op]);
2015-05-06 11:26:46 +03:00
assert(false, "Not Implemented: " + Bytecodes[op]);
}
2015-05-06 11:26:46 +03:00
// Call Native or Compiled Method.
if (calleeTargetMethodInfo.isNative || calleeTargetMethodInfo.state === MethodState.Compiled) {
args.length = 0;
var signatureKinds = calleeTargetMethodInfo.signatureKinds;
for (var i = signatureKinds.length - 1; i > 0; i--) {
kind = signatureKinds[i];
switch (kind) {
case Kind.Double: // Doubles are passed in as a number value.
aliasedI32[1] = i32[--sp];
aliasedI32[0] = i32[--sp];
args.unshift(aliasedF64[0]);
break;
case Kind.Float:
args.unshift(f32[--sp]);
break;
case Kind.Long:
args.unshift(i32[--sp]); // High Bits
// Fallthrough
case Kind.Int:
case Kind.Byte:
case Kind.Char:
case Kind.Short:
case Kind.Boolean:
args.unshift(i32[--sp]);
break;
case Kind.Reference:
args.unshift(ref[--sp]);
break;
default:
release || assert(false, "Invalid Kind: " + Kind[kind]);
}
}
2015-05-06 11:26:46 +03:00
if (!isStatic) {
--sp; // Pop Reference
}
2015-05-16 04:58:19 +03:00
thread.set(fp, sp, opPC);
2015-05-09 07:14:44 +03:00
callee = calleeTargetMethodInfo.fn || getLinkedMethod(calleeTargetMethodInfo);
if (!release) {
// assert(callee.length === args.length, "Function " + callee + " (" + calleeTargetMethodInfo.implKey + "), should have " + args.length + " arguments.");
}
2015-05-06 11:26:46 +03:00
result = callee.apply(object, args);
2015-05-15 04:09:45 +03:00
//if (!release) {
// checkReturnValue(calleeMethodInfo, returnValue);
//}
if (U) {
return;
}
2015-05-10 04:32:02 +03:00
if (!release) {
assert(!(result instanceof Long.constructor), "NO LONGS ALLOWED");
}
2015-05-16 04:58:19 +03:00
//loadThreadState();
kind = signatureKinds[0];
// Push return value.
switch (kind) {
case Kind.Double: // Doubles are passed in as a number value.
aliasedF64[0] = result;
i32[sp++] = aliasedI32[0];
i32[sp++] = aliasedI32[1];
continue;
case Kind.Float:
f32[sp++] = result;
continue;
case Kind.Long:
i32[sp++] = result;
i32[sp++] = tempReturn0;
continue;
case Kind.Int:
case Kind.Byte:
case Kind.Char:
case Kind.Short:
case Kind.Boolean:
i32[sp++] = result;
continue;
case Kind.Reference:
ref[sp++] = result;
continue;
case Kind.Void:
continue;
default:
release || assert(false, "Invalid Kind: " + Kind[kind]);
2015-05-06 11:26:46 +03:00
}
continue;
}
release || traceWriter && traceWriter.writeLn(">> I " + calleeMethodInfo.implKey);
2015-05-06 11:26:46 +03:00
mi = calleeTargetMethodInfo;
2015-05-08 03:31:22 +03:00
maxLocals = mi.codeAttribute.max_locals;
2015-05-06 11:26:46 +03:00
ci = mi.classInfo;
cp = ci.constantPool;
2015-05-16 04:58:19 +03:00
var callerFPOffset = fp;
2015-05-06 11:26:46 +03:00
// Reserve space for non-parameter locals.
2015-05-16 04:58:19 +03:00
lp = sp - mi.argumentSlots;
fp = lp + maxLocals;
sp = fp + FrameLayout.CallerSaveSize;
2015-05-06 11:26:46 +03:00
// Caller saved values.
2015-05-16 04:58:19 +03:00
i32[fp + FrameLayout.CallerRAOffset] = opPC;
i32[fp + FrameLayout.CallerFPOffset] = callerFPOffset;
ref[fp + FrameLayout.CalleeMethodInfoOffset] = mi;
ref[fp + FrameLayout.MonitorOffset] = null; // Monitor
if (calleeTargetMethodInfo.isSynchronized) {
monitor = calleeTargetMethodInfo.isStatic
? calleeTargetMethodInfo.classInfo.getClassObject()
: object;
ref[fp + FrameLayout.MonitorOffset] = monitor;
$.ctx.monitorEnter(monitor);
if (U === VMState.Pausing || U === VMState.Stopping) {
frame.set(fp, sp, opPC);
return;
}
}
2015-05-06 11:26:46 +03:00
opPC = pc = 0;
code = mi.codeAttribute.code;
release || traceWriter && traceWriter.indent();
2015-05-06 11:26:46 +03:00
continue;
default:
release || traceWriter && traceWriter.writeLn("Not Implemented: " + Bytecodes[op] + ", PC: " + opPC + ", CODE: " + code.length);
release || assert(false, "Not Implemented: " + Bytecodes[op]);
2015-05-08 10:57:48 +03:00
continue;
2015-05-06 11:26:46 +03:00
}
} catch (e) {
release || traceWriter && traceWriter.redLn("XXX I Caught: " + e + ", details: " + toName(e));
// release || traceWriter && traceWriter.writeLns(e.stack);
// release || traceWriter && traceWriter.writeLn(jsGlobal.getBacktrace());
thread.set(fp, sp, opPC);
2015-05-08 01:17:05 +03:00
e = translateException(e);
if (!e.klass) {
// A non-java exception was thrown. Rethrow so it is not handled by exceptionUnwind.
2015-05-08 01:17:05 +03:00
throw e;
}
thread.exceptionUnwind(e);
2015-05-08 01:17:05 +03:00
loadThreadState();
mi = thread.frame.methodInfo;
2015-05-08 03:31:22 +03:00
maxLocals = mi.codeAttribute.max_locals;
lp = fp - maxLocals;
2015-05-08 01:17:05 +03:00
ci = mi.classInfo;
cp = ci.constantPool;
code = mi.codeAttribute.code;
continue;
2015-05-06 11:26:46 +03:00
}
}
}
2015-05-09 12:47:47 +03:00
// print(disassemble(interpret));
}