2014-11-27 12:15:46 +03:00
|
|
|
module J2ME {
|
|
|
|
declare var util;
|
2014-12-19 00:03:59 +03:00
|
|
|
declare var Promise;
|
2014-11-27 12:15:46 +03:00
|
|
|
|
2014-12-26 06:08:53 +03:00
|
|
|
import BytecodeStream = Bytecode.BytecodeStream;
|
2015-01-19 23:28:04 +03:00
|
|
|
import BlockMap = Bytecode.BlockMap;
|
2014-12-25 20:39:01 +03:00
|
|
|
import checkArrayBounds = J2ME.checkArrayBounds;
|
|
|
|
import checkDivideByZero = J2ME.checkDivideByZero;
|
|
|
|
import checkDivideByZeroLong = J2ME.checkDivideByZeroLong;
|
|
|
|
|
2014-11-27 12:15:46 +03:00
|
|
|
import Bytecodes = Bytecode.Bytecodes;
|
|
|
|
import assert = Debug.assert;
|
2014-12-22 05:21:30 +03:00
|
|
|
import popManyInto = ArrayUtilities.popManyInto;
|
2014-11-27 12:15:46 +03:00
|
|
|
|
2015-01-15 07:40:05 +03:00
|
|
|
export var interpreterCounter = null; // new Metrics.Counter(true);
|
2015-01-19 06:54:01 +03:00
|
|
|
export var interpreterMethodCounter = new Metrics.Counter(true);
|
2014-12-01 03:21:34 +03:00
|
|
|
|
2014-12-10 05:19:35 +03:00
|
|
|
var traceArrayAccess = false;
|
|
|
|
|
2014-12-25 03:46:31 +03:00
|
|
|
function traceArrayStore(index: number, array: any [], value: any) {
|
|
|
|
traceWriter.writeLn(toDebugString(array) + "[" + index + "] = " + toDebugString(value));
|
2014-11-27 12:15:46 +03:00
|
|
|
}
|
|
|
|
|
2014-12-25 03:46:31 +03:00
|
|
|
function traceArrayLoad(index: number, array: any []) {
|
|
|
|
assert(array[index] !== undefined);
|
|
|
|
traceWriter.writeLn(toDebugString(array) + "[" + index + "] (" + toDebugString(array[index]) + ")");
|
2014-11-27 12:15:46 +03:00
|
|
|
}
|
|
|
|
|
2015-02-24 23:45:18 +03:00
|
|
|
function classInitAndUnwindCheck(classInfo: ClassInfo, pc: number) {
|
|
|
|
classInitCheck(classInfo);
|
|
|
|
if (U) {
|
|
|
|
$.ctx.current().pc = pc;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-26 06:08:53 +03:00
|
|
|
/**
|
|
|
|
* Optimize method bytecode.
|
|
|
|
*/
|
|
|
|
function optimizeMethodBytecode(methodInfo: MethodInfo) {
|
2015-01-15 07:40:05 +03:00
|
|
|
interpreterCounter && interpreterCounter.count("optimize: " + methodInfo.implKey);
|
2014-12-26 06:08:53 +03:00
|
|
|
var stream = new BytecodeStream(methodInfo.code);
|
|
|
|
while (stream.currentBC() !== Bytecodes.END) {
|
2015-01-08 00:46:01 +03:00
|
|
|
if (stream.rawCurrentBC() === Bytecodes.WIDE) {
|
|
|
|
stream.next();
|
|
|
|
continue;
|
|
|
|
}
|
2014-12-26 06:08:53 +03:00
|
|
|
switch (stream.currentBC()) {
|
|
|
|
case Bytecodes.ALOAD:
|
|
|
|
if (stream.nextBC() === Bytecodes.ILOAD) {
|
|
|
|
stream.writeCurrentBC(Bytecodes.ALOAD_ILOAD);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Bytecodes.IINC:
|
|
|
|
if (stream.nextBC() === Bytecodes.GOTO) {
|
|
|
|
stream.writeCurrentBC(Bytecodes.IINC_GOTO);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Bytecodes.ARRAYLENGTH:
|
|
|
|
if (stream.nextBC() === Bytecodes.IF_ICMPGE) {
|
|
|
|
stream.writeCurrentBC(Bytecodes.ARRAYLENGTH_IF_ICMPGE);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
stream.next();
|
|
|
|
}
|
|
|
|
methodInfo.isOptimized = true;
|
|
|
|
}
|
|
|
|
|
2015-01-15 04:13:14 +03:00
|
|
|
function resolve(index: number, classInfo: ClassInfo, isStatic: boolean = false): any {
|
|
|
|
return classInfo.resolve(index, isStatic);
|
2014-12-26 06:49:09 +03:00
|
|
|
}
|
|
|
|
|
2015-01-15 04:13:14 +03:00
|
|
|
function resolveField(index: number, classInfo: ClassInfo, isStatic: boolean): FieldInfo {
|
2015-01-16 12:44:35 +03:00
|
|
|
return <FieldInfo><any>classInfo.resolve(index, isStatic);
|
2014-12-26 06:49:09 +03:00
|
|
|
}
|
|
|
|
|
2015-01-15 04:13:14 +03:00
|
|
|
function resolveClass(index: number, classInfo: ClassInfo, isStatic: boolean): ClassInfo {
|
2015-01-16 12:44:35 +03:00
|
|
|
var classInfo: ClassInfo = <any>classInfo.resolve(index, isStatic);
|
2015-01-15 04:13:14 +03:00
|
|
|
linkKlass(classInfo);
|
|
|
|
return classInfo;
|
2014-12-26 06:49:09 +03:00
|
|
|
}
|
|
|
|
|
2015-01-15 04:13:14 +03:00
|
|
|
function resolveMethod(index: number, classInfo: ClassInfo, isStatic: boolean): MethodInfo {
|
2015-01-16 12:44:35 +03:00
|
|
|
return <MethodInfo><any>classInfo.resolve(index, isStatic);
|
2014-12-26 06:49:09 +03:00
|
|
|
}
|
|
|
|
|
2014-12-26 08:03:45 +03:00
|
|
|
/**
|
|
|
|
* Debugging helper to make sure native methods were implemented correctly.
|
|
|
|
*/
|
|
|
|
function checkReturnValue(methodInfo: MethodInfo, returnValue: any) {
|
2015-01-30 05:06:48 +03:00
|
|
|
if (U) {
|
|
|
|
if (typeof returnValue !== "undefined") {
|
2015-02-07 01:54:07 +03:00
|
|
|
assert(false, "Expected undefined return value during unwind, got " + returnValue + " in " + methodInfo.implKey);
|
2015-01-30 05:06:48 +03:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!(getKindCheck(methodInfo.getReturnKind())(returnValue))) {
|
2015-02-07 01:54:07 +03:00
|
|
|
assert(false, "Expected " + Kind[methodInfo.getReturnKind()] + " return value, got " + returnValue + " in " + methodInfo.implKey);
|
2014-12-26 08:03:45 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-18 11:53:16 +03:00
|
|
|
/**
|
|
|
|
* The number of opcodes executed thus far.
|
|
|
|
*/
|
2015-01-16 11:46:34 +03:00
|
|
|
export var bytecodeCount = 0;
|
2014-12-18 11:53:16 +03:00
|
|
|
|
2015-01-19 06:54:01 +03:00
|
|
|
/**
|
|
|
|
* The number of times the interpreter method was called thus far.
|
|
|
|
*/
|
|
|
|
export var interpreterCount = 0;
|
|
|
|
|
|
|
|
export var onStackReplacementCount = 0;
|
|
|
|
|
2014-12-21 11:49:20 +03:00
|
|
|
/**
|
|
|
|
* Temporarily used for fn.apply.
|
|
|
|
*/
|
|
|
|
var argArray = [];
|
|
|
|
|
2014-12-30 01:11:39 +03:00
|
|
|
function buildExceptionLog(ex, stackTrace) {
|
|
|
|
var className = ex.klass.classInfo.className;
|
|
|
|
var detailMessage = util.fromJavaString(CLASSES.getField(ex.klass.classInfo, "I.detailMessage.Ljava/lang/String;").get(ex));
|
|
|
|
return className + ": " + (detailMessage || "") + "\n" + stackTrace.map(function(entry) {
|
|
|
|
return " - " + entry.className + "." + entry.methodName + "(), pc=" + entry.offset;
|
|
|
|
}).join("\n") + "\n\n";
|
|
|
|
}
|
2014-11-27 12:15:46 +03:00
|
|
|
|
2015-01-16 15:58:54 +03:00
|
|
|
function tryCatch(e) {
|
2014-12-30 02:43:27 +03:00
|
|
|
var ctx = $.ctx;
|
2014-12-30 01:11:39 +03:00
|
|
|
var frame = ctx.current();
|
2015-01-16 15:58:54 +03:00
|
|
|
var frames = ctx.frames;
|
2014-12-30 01:11:39 +03:00
|
|
|
var stack = frame.stack;
|
2014-11-27 12:15:46 +03:00
|
|
|
|
2015-01-16 15:58:54 +03:00
|
|
|
var exClass = e.class;
|
|
|
|
if (!e.stackTrace) {
|
|
|
|
e.stackTrace = [];
|
2014-12-30 01:11:39 +03:00
|
|
|
}
|
2014-11-27 12:15:46 +03:00
|
|
|
|
2015-01-16 15:58:54 +03:00
|
|
|
var stackTrace = e.stackTrace;
|
2014-11-27 12:15:46 +03:00
|
|
|
|
2014-12-30 01:11:39 +03:00
|
|
|
do {
|
|
|
|
var exception_table = frame.methodInfo.exception_table;
|
|
|
|
var handler_pc = null;
|
2015-01-16 15:58:54 +03:00
|
|
|
for (var i = 0; exception_table && i < exception_table.length; i++) {
|
2015-01-19 06:54:01 +03:00
|
|
|
if (frame.opPC >= exception_table[i].start_pc && frame.opPC < exception_table[i].end_pc) {
|
2014-12-30 01:11:39 +03:00
|
|
|
if (exception_table[i].catch_type === 0) {
|
|
|
|
handler_pc = exception_table[i].handler_pc;
|
|
|
|
break;
|
|
|
|
} else {
|
2015-01-15 04:13:14 +03:00
|
|
|
classInfo = resolveClass(exception_table[i].catch_type, frame.methodInfo.classInfo, false);
|
2015-01-16 15:58:54 +03:00
|
|
|
if (isAssignableTo(e.klass, classInfo.klass)) {
|
2014-11-27 12:15:46 +03:00
|
|
|
handler_pc = exception_table[i].handler_pc;
|
2014-12-01 21:25:23 +03:00
|
|
|
break;
|
2014-11-27 12:15:46 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-12-30 01:11:39 +03:00
|
|
|
}
|
2014-11-27 12:15:46 +03:00
|
|
|
|
2015-01-15 04:13:14 +03:00
|
|
|
var classInfo = frame.methodInfo.classInfo;
|
2014-12-30 01:11:39 +03:00
|
|
|
if (classInfo && classInfo.className) {
|
|
|
|
stackTrace.push({
|
|
|
|
className: classInfo.className,
|
|
|
|
methodName: frame.methodInfo.name,
|
|
|
|
offset: frame.pc
|
|
|
|
});
|
|
|
|
}
|
2014-11-27 12:15:46 +03:00
|
|
|
|
2014-12-30 01:11:39 +03:00
|
|
|
if (handler_pc != null) {
|
|
|
|
stack.length = 0;
|
2015-01-16 15:58:54 +03:00
|
|
|
stack.push(e);
|
2014-12-30 01:11:39 +03:00
|
|
|
frame.pc = handler_pc;
|
2014-11-27 12:15:46 +03:00
|
|
|
|
2014-12-30 01:11:39 +03:00
|
|
|
if (VM.DEBUG_PRINT_ALL_EXCEPTIONS) {
|
2015-01-16 15:58:54 +03:00
|
|
|
console.error(buildExceptionLog(e, stackTrace));
|
2014-11-27 12:15:46 +03:00
|
|
|
}
|
|
|
|
|
2014-12-30 01:11:39 +03:00
|
|
|
return;
|
|
|
|
}
|
2015-01-17 03:40:58 +03:00
|
|
|
frames.pop();
|
|
|
|
frame = frames[frames.length - 1];
|
|
|
|
if (Frame.isMarker(frame)) {
|
2015-01-16 15:58:54 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
stack = frame.stack;
|
|
|
|
} while (true);
|
2014-11-27 12:15:46 +03:00
|
|
|
|
2015-01-16 15:58:54 +03:00
|
|
|
if (ctx.current() === Frame.Start) {
|
2014-12-30 01:11:39 +03:00
|
|
|
ctx.kill();
|
2015-02-10 15:54:51 +03:00
|
|
|
if (ctx.thread && ctx.thread._lock && ctx.thread._lock.waiting.length > 0) {
|
2015-01-16 15:58:54 +03:00
|
|
|
console.error(buildExceptionLog(e, stackTrace));
|
2015-02-04 22:03:32 +03:00
|
|
|
for (var i = 0; i < ctx.thread._lock.waiting.length; i++) {
|
|
|
|
var waitingCtx = ctx.thread._lock.waiting[i];
|
|
|
|
ctx.thread._lock.waiting[i] = null;
|
2014-12-30 01:11:39 +03:00
|
|
|
waitingCtx.wakeup(ctx.thread);
|
2015-02-04 22:03:32 +03:00
|
|
|
}
|
2014-11-27 12:15:46 +03:00
|
|
|
}
|
2015-01-16 15:58:54 +03:00
|
|
|
throw new Error(buildExceptionLog(e, stackTrace));
|
2014-12-30 01:11:39 +03:00
|
|
|
} else {
|
2015-01-16 15:58:54 +03:00
|
|
|
throw e;
|
2014-11-27 12:15:46 +03:00
|
|
|
}
|
2014-12-30 01:11:39 +03:00
|
|
|
}
|
2014-11-27 12:15:46 +03:00
|
|
|
|
2014-12-30 02:43:27 +03:00
|
|
|
export function interpret() {
|
|
|
|
var ctx = $.ctx;
|
2015-01-16 15:58:54 +03:00
|
|
|
|
2015-01-17 03:40:58 +03:00
|
|
|
// These must always be kept up to date with the current frame.
|
|
|
|
var frame = ctx.current();
|
|
|
|
release || assert (!Frame.isMarker(frame));
|
2015-01-16 15:58:54 +03:00
|
|
|
var frames = ctx.frames;
|
2015-01-15 04:13:14 +03:00
|
|
|
var mi = frame.methodInfo;
|
2015-01-17 03:40:58 +03:00
|
|
|
var ci = mi.classInfo;
|
2015-01-20 22:02:05 +03:00
|
|
|
var rp = ci.resolved_constant_pool;
|
2014-12-30 01:11:39 +03:00
|
|
|
var stack = frame.stack;
|
2015-01-17 03:40:58 +03:00
|
|
|
|
|
|
|
|
2014-12-30 01:11:39 +03:00
|
|
|
var returnValue = null;
|
|
|
|
|
2014-11-27 12:15:46 +03:00
|
|
|
|
2014-12-08 21:55:05 +03:00
|
|
|
var traceBytecodes = false;
|
2014-11-27 14:28:52 +03:00
|
|
|
var traceSourceLocation = true;
|
|
|
|
|
2014-12-26 06:49:09 +03:00
|
|
|
var index: any, value: any, constant: any;
|
2014-12-25 20:39:53 +03:00
|
|
|
var a: any, b: any, c: any;
|
2015-01-19 06:54:01 +03:00
|
|
|
var pc: number;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is used to detect backwards branches for the purpose of on stack replacement.
|
|
|
|
*/
|
|
|
|
var lastPC: number = -1;
|
|
|
|
|
2014-12-25 20:39:53 +03:00
|
|
|
var type;
|
|
|
|
var size;
|
2014-12-26 06:49:09 +03:00
|
|
|
|
2014-12-25 21:11:18 +03:00
|
|
|
var array: any;
|
|
|
|
var object: java.lang.Object;
|
2014-12-26 06:49:09 +03:00
|
|
|
var fieldInfo: FieldInfo;
|
|
|
|
var classInfo: ClassInfo;
|
2014-12-26 06:08:53 +03:00
|
|
|
|
2015-01-21 02:56:29 +03:00
|
|
|
// We don't want to optimize methods for interpretation if we're going to be using the JIT until
|
|
|
|
// we teach the Baseline JIT about the new bytecodes.
|
|
|
|
if (!enableRuntimeCompilation && !frame.methodInfo.isOptimized && frame.methodInfo.bytecodeCount > 100) {
|
2014-12-26 06:08:53 +03:00
|
|
|
optimizeMethodBytecode(frame.methodInfo);
|
|
|
|
}
|
|
|
|
|
2015-01-23 04:03:43 +03:00
|
|
|
mi.interpreterCallCount ++;
|
2015-01-08 02:46:53 +03:00
|
|
|
|
2015-01-30 03:50:20 +03:00
|
|
|
interpreterCount ++;
|
2015-01-19 06:54:01 +03:00
|
|
|
|
2014-11-27 12:15:46 +03:00
|
|
|
while (true) {
|
2015-01-30 03:50:20 +03:00
|
|
|
bytecodeCount ++;
|
2015-01-21 02:56:29 +03:00
|
|
|
mi.bytecodeCount ++;
|
|
|
|
|
|
|
|
// TODO: Make sure this works even if we JIT everything. At the moment it fails
|
|
|
|
// for synthetic method frames which have bad max_local counts.
|
|
|
|
|
|
|
|
// Inline heuristics that trigger JIT compilation here.
|
2015-01-21 03:50:08 +03:00
|
|
|
if (enableRuntimeCompilation &&
|
|
|
|
mi.state < MethodState.Compiled && // Give up if we're at this state.
|
2015-01-21 02:56:29 +03:00
|
|
|
mi.backwardsBranchCount + mi.interpreterCallCount > 10) {
|
|
|
|
compileAndLinkMethod(mi);
|
|
|
|
}
|
2015-01-19 06:54:01 +03:00
|
|
|
|
2014-12-16 05:54:47 +03:00
|
|
|
try {
|
2015-01-21 02:56:29 +03:00
|
|
|
if (frame.pc < lastPC) {
|
|
|
|
mi.backwardsBranchCount ++;
|
2015-01-26 00:41:37 +03:00
|
|
|
if (enableOnStackReplacement && mi.state === MethodState.Compiled) {
|
2015-01-19 06:54:01 +03:00
|
|
|
// Just because we've jumped backwards doesn't mean we are at a loop header but it does mean that we are
|
|
|
|
// at the beggining of a basic block. This is a really cheap test and a convenient place to perform an
|
|
|
|
// on stack replacement.
|
|
|
|
|
2015-02-12 00:10:53 +03:00
|
|
|
if (mi.onStackReplacementEntryPoints.indexOf(frame.pc) > -1) {
|
2015-01-30 03:50:20 +03:00
|
|
|
onStackReplacementCount++;
|
2015-01-19 23:28:04 +03:00
|
|
|
|
2015-01-26 00:41:37 +03:00
|
|
|
// The current frame will be swapped out for a JIT frame, so pop it off the interpreter stack.
|
|
|
|
frames.pop();
|
2015-01-19 06:54:01 +03:00
|
|
|
|
2015-01-26 00:41:37 +03:00
|
|
|
// Remember the return kind since we'll need it later.
|
|
|
|
var returnKind = mi.getReturnKind();
|
2015-01-19 06:54:01 +03:00
|
|
|
|
2015-01-26 00:41:37 +03:00
|
|
|
// Set the global OSR frame to the current frame.
|
|
|
|
O = frame;
|
|
|
|
|
|
|
|
// Set the current frame before doing the OSR in case an exception is thrown.
|
|
|
|
frame = frames[frames.length - 1];
|
|
|
|
|
|
|
|
// Perform OSR, the callee reads the frame stored in |O| and updates its own state.
|
|
|
|
returnValue = O.methodInfo.fn();
|
|
|
|
if (U) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Usual code to return from the interpreter or push the return value.
|
|
|
|
if (Frame.isMarker(frame)) {
|
|
|
|
return returnValue;
|
|
|
|
}
|
|
|
|
mi = frame.methodInfo;
|
|
|
|
ci = mi.classInfo;
|
|
|
|
rp = ci.resolved_constant_pool;
|
|
|
|
stack = frame.stack;
|
|
|
|
lastPC = -1;
|
|
|
|
|
|
|
|
if (returnKind !== Kind.Void) {
|
|
|
|
if (isTwoSlot(returnKind)) {
|
|
|
|
stack.push2(returnValue);
|
|
|
|
} else {
|
|
|
|
stack.push(returnValue);
|
|
|
|
}
|
2015-01-19 06:54:01 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lastPC = frame.opPC = frame.pc;
|
|
|
|
var op: Bytecodes = frame.read8();
|
|
|
|
|
2014-12-16 05:54:47 +03:00
|
|
|
switch (op) {
|
|
|
|
case Bytecodes.NOP:
|
|
|
|
break;
|
|
|
|
case Bytecodes.ACONST_NULL:
|
|
|
|
stack.push(null);
|
|
|
|
break;
|
|
|
|
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:
|
2014-12-25 03:46:31 +03:00
|
|
|
stack.push(op - Bytecodes.ICONST_0);
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
2014-12-25 03:46:31 +03:00
|
|
|
case Bytecodes.FCONST_0:
|
|
|
|
case Bytecodes.FCONST_1:
|
|
|
|
case Bytecodes.FCONST_2:
|
|
|
|
stack.push(op - Bytecodes.FCONST_0);
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
2014-12-25 03:46:31 +03:00
|
|
|
case Bytecodes.DCONST_0:
|
|
|
|
case Bytecodes.DCONST_1:
|
|
|
|
stack.push2(op - Bytecodes.DCONST_0);
|
|
|
|
break;
|
|
|
|
case Bytecodes.LCONST_0:
|
2014-12-16 05:54:47 +03:00
|
|
|
case Bytecodes.LCONST_1:
|
2014-12-25 03:46:31 +03:00
|
|
|
stack.push2(Long.fromInt(op - Bytecodes.LCONST_0));
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
|
|
|
case Bytecodes.BIPUSH:
|
2014-12-25 03:46:31 +03:00
|
|
|
stack.push(frame.read8Signed());
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
|
|
|
case Bytecodes.SIPUSH:
|
2014-12-25 03:46:31 +03:00
|
|
|
stack.push(frame.read16Signed());
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
|
|
|
case Bytecodes.LDC:
|
|
|
|
case Bytecodes.LDC_W:
|
2014-12-25 20:39:53 +03:00
|
|
|
index = (op === Bytecodes.LDC) ? frame.read8() : frame.read16();
|
2015-01-17 03:40:58 +03:00
|
|
|
constant = resolve(index, ci, false);
|
2014-12-16 05:54:47 +03:00
|
|
|
stack.push(constant);
|
|
|
|
break;
|
|
|
|
case Bytecodes.LDC2_W:
|
2014-12-25 20:39:53 +03:00
|
|
|
index = frame.read16();
|
2015-01-17 03:40:58 +03:00
|
|
|
constant = resolve(index, ci, false);
|
2014-12-16 05:54:47 +03:00
|
|
|
stack.push2(constant);
|
|
|
|
break;
|
|
|
|
case Bytecodes.ILOAD:
|
2014-12-26 06:08:53 +03:00
|
|
|
stack.push(frame.getLocal(frame.read8()));
|
|
|
|
break;
|
2014-12-16 05:54:47 +03:00
|
|
|
case Bytecodes.FLOAD:
|
2014-12-26 06:08:53 +03:00
|
|
|
stack.push(frame.getLocal(frame.read8()));
|
|
|
|
break;
|
2014-12-16 05:54:47 +03:00
|
|
|
case Bytecodes.ALOAD:
|
|
|
|
stack.push(frame.getLocal(frame.read8()));
|
|
|
|
break;
|
2014-12-26 06:08:53 +03:00
|
|
|
case Bytecodes.ALOAD_ILOAD:
|
|
|
|
stack.push(frame.getLocal(frame.read8()));
|
|
|
|
frame.pc ++;
|
|
|
|
stack.push(frame.getLocal(frame.read8()));
|
|
|
|
break;
|
2014-12-16 05:54:47 +03:00
|
|
|
case Bytecodes.LLOAD:
|
|
|
|
case Bytecodes.DLOAD:
|
|
|
|
stack.push2(frame.getLocal(frame.read8()));
|
|
|
|
break;
|
|
|
|
case Bytecodes.ILOAD_0:
|
|
|
|
case Bytecodes.ILOAD_1:
|
|
|
|
case Bytecodes.ILOAD_2:
|
|
|
|
case Bytecodes.ILOAD_3:
|
2014-12-25 03:46:31 +03:00
|
|
|
stack.push(frame.getLocal(op - Bytecodes.ILOAD_0));
|
|
|
|
break;
|
|
|
|
case Bytecodes.FLOAD_0:
|
|
|
|
case Bytecodes.FLOAD_1:
|
|
|
|
case Bytecodes.FLOAD_2:
|
2014-12-16 05:54:47 +03:00
|
|
|
case Bytecodes.FLOAD_3:
|
2014-12-25 03:46:31 +03:00
|
|
|
stack.push(frame.getLocal(op - Bytecodes.FLOAD_0));
|
|
|
|
break;
|
|
|
|
case Bytecodes.ALOAD_0:
|
|
|
|
case Bytecodes.ALOAD_1:
|
|
|
|
case Bytecodes.ALOAD_2:
|
2014-12-16 05:54:47 +03:00
|
|
|
case Bytecodes.ALOAD_3:
|
2014-12-25 03:46:31 +03:00
|
|
|
stack.push(frame.getLocal(op - Bytecodes.ALOAD_0));
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
|
|
|
case Bytecodes.LLOAD_0:
|
|
|
|
case Bytecodes.LLOAD_1:
|
|
|
|
case Bytecodes.LLOAD_2:
|
|
|
|
case Bytecodes.LLOAD_3:
|
2014-12-25 03:46:31 +03:00
|
|
|
stack.push2(frame.getLocal(op - Bytecodes.LLOAD_0));
|
|
|
|
break;
|
|
|
|
case Bytecodes.DLOAD_0:
|
|
|
|
case Bytecodes.DLOAD_1:
|
|
|
|
case Bytecodes.DLOAD_2:
|
2014-12-16 05:54:47 +03:00
|
|
|
case Bytecodes.DLOAD_3:
|
2014-12-25 03:46:31 +03:00
|
|
|
stack.push2(frame.getLocal(op - Bytecodes.DLOAD_0));
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
|
|
|
case Bytecodes.IALOAD:
|
|
|
|
case Bytecodes.FALOAD:
|
|
|
|
case Bytecodes.AALOAD:
|
|
|
|
case Bytecodes.BALOAD:
|
|
|
|
case Bytecodes.CALOAD:
|
|
|
|
case Bytecodes.SALOAD:
|
2014-12-25 20:39:53 +03:00
|
|
|
index = stack.pop();
|
|
|
|
array = stack.pop();
|
2014-12-25 20:39:01 +03:00
|
|
|
checkArrayBounds(array, index);
|
2014-12-25 03:46:31 +03:00
|
|
|
stack.push(array[index]);
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
|
|
|
case Bytecodes.LALOAD:
|
|
|
|
case Bytecodes.DALOAD:
|
2014-12-25 20:39:53 +03:00
|
|
|
index = stack.pop();
|
|
|
|
array = stack.pop();
|
2014-12-25 20:39:01 +03:00
|
|
|
checkArrayBounds(array, index);
|
2014-12-25 03:46:31 +03:00
|
|
|
stack.push2(array[index]);
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
|
|
|
case Bytecodes.ISTORE:
|
|
|
|
case Bytecodes.FSTORE:
|
|
|
|
case Bytecodes.ASTORE:
|
|
|
|
frame.setLocal(frame.read8(), stack.pop());
|
|
|
|
break;
|
|
|
|
case Bytecodes.LSTORE:
|
|
|
|
case Bytecodes.DSTORE:
|
|
|
|
frame.setLocal(frame.read8(), stack.pop2());
|
|
|
|
break;
|
|
|
|
case Bytecodes.ISTORE_0:
|
|
|
|
case Bytecodes.FSTORE_0:
|
|
|
|
case Bytecodes.ASTORE_0:
|
|
|
|
frame.setLocal(0, stack.pop());
|
|
|
|
break;
|
|
|
|
case Bytecodes.ISTORE_1:
|
|
|
|
case Bytecodes.FSTORE_1:
|
|
|
|
case Bytecodes.ASTORE_1:
|
|
|
|
frame.setLocal(1, stack.pop());
|
|
|
|
break;
|
|
|
|
case Bytecodes.ISTORE_2:
|
|
|
|
case Bytecodes.FSTORE_2:
|
|
|
|
case Bytecodes.ASTORE_2:
|
|
|
|
frame.setLocal(2, stack.pop());
|
|
|
|
break;
|
|
|
|
case Bytecodes.ISTORE_3:
|
|
|
|
case Bytecodes.FSTORE_3:
|
|
|
|
case Bytecodes.ASTORE_3:
|
|
|
|
frame.setLocal(3, stack.pop());
|
|
|
|
break;
|
|
|
|
case Bytecodes.LSTORE_0:
|
|
|
|
case Bytecodes.DSTORE_0:
|
|
|
|
frame.setLocal(0, stack.pop2());
|
|
|
|
break;
|
|
|
|
case Bytecodes.LSTORE_1:
|
|
|
|
case Bytecodes.DSTORE_1:
|
|
|
|
frame.setLocal(1, stack.pop2());
|
|
|
|
break;
|
|
|
|
case Bytecodes.LSTORE_2:
|
|
|
|
case Bytecodes.DSTORE_2:
|
|
|
|
frame.setLocal(2, stack.pop2());
|
|
|
|
break;
|
|
|
|
case Bytecodes.LSTORE_3:
|
|
|
|
case Bytecodes.DSTORE_3:
|
|
|
|
frame.setLocal(3, stack.pop2());
|
|
|
|
break;
|
|
|
|
case Bytecodes.IASTORE:
|
|
|
|
case Bytecodes.FASTORE:
|
|
|
|
case Bytecodes.BASTORE:
|
|
|
|
case Bytecodes.CASTORE:
|
|
|
|
case Bytecodes.SASTORE:
|
2014-12-25 20:39:53 +03:00
|
|
|
value = stack.pop();
|
|
|
|
index = stack.pop();
|
|
|
|
array = stack.pop();
|
2014-12-25 20:39:01 +03:00
|
|
|
checkArrayBounds(array, index);
|
2014-12-25 03:46:31 +03:00
|
|
|
array[index] = value;
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
|
|
|
case Bytecodes.LASTORE:
|
|
|
|
case Bytecodes.DASTORE:
|
2014-12-25 20:39:53 +03:00
|
|
|
value = stack.pop2();
|
|
|
|
index = stack.pop();
|
|
|
|
array = stack.pop();
|
2014-12-25 20:39:01 +03:00
|
|
|
checkArrayBounds(array, index);
|
2014-12-25 03:46:31 +03:00
|
|
|
array[index] = value;
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
|
|
|
case Bytecodes.AASTORE:
|
2014-12-25 20:39:53 +03:00
|
|
|
value = stack.pop();
|
|
|
|
index = stack.pop();
|
|
|
|
array = stack.pop();
|
2014-12-25 20:39:01 +03:00
|
|
|
checkArrayBounds(array, index);
|
|
|
|
checkArrayStore(array, value);
|
2014-12-25 03:46:31 +03:00
|
|
|
array[index] = value;
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
|
|
|
case Bytecodes.POP:
|
|
|
|
stack.pop();
|
|
|
|
break;
|
|
|
|
case Bytecodes.POP2:
|
|
|
|
stack.pop2();
|
|
|
|
break;
|
|
|
|
case Bytecodes.DUP:
|
2014-12-26 06:08:53 +03:00
|
|
|
stack.push(stack[stack.length - 1]);
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
|
|
|
case Bytecodes.DUP_X1:
|
2014-12-25 20:39:53 +03:00
|
|
|
a = stack.pop();
|
|
|
|
b = stack.pop();
|
2014-12-16 05:54:47 +03:00
|
|
|
stack.push(a);
|
|
|
|
stack.push(b);
|
|
|
|
stack.push(a);
|
|
|
|
break;
|
|
|
|
case Bytecodes.DUP_X2:
|
2014-12-25 20:39:53 +03:00
|
|
|
a = stack.pop();
|
|
|
|
b = stack.pop();
|
|
|
|
c = stack.pop();
|
2014-12-16 05:54:47 +03:00
|
|
|
stack.push(a);
|
|
|
|
stack.push(c);
|
|
|
|
stack.push(b);
|
|
|
|
stack.push(a);
|
|
|
|
break;
|
|
|
|
case Bytecodes.DUP2:
|
2014-12-25 20:39:53 +03:00
|
|
|
a = stack.pop();
|
|
|
|
b = stack.pop();
|
2014-12-16 05:54:47 +03:00
|
|
|
stack.push(b);
|
|
|
|
stack.push(a);
|
|
|
|
stack.push(b);
|
|
|
|
stack.push(a);
|
|
|
|
break;
|
|
|
|
case Bytecodes.DUP2_X1:
|
2014-12-25 20:39:53 +03:00
|
|
|
a = stack.pop();
|
|
|
|
b = stack.pop();
|
|
|
|
c = stack.pop();
|
2014-12-16 05:54:47 +03:00
|
|
|
stack.push(b);
|
|
|
|
stack.push(a);
|
|
|
|
stack.push(c);
|
|
|
|
stack.push(b);
|
|
|
|
stack.push(a);
|
|
|
|
break;
|
|
|
|
case Bytecodes.DUP2_X2:
|
2014-12-25 20:39:53 +03:00
|
|
|
a = stack.pop();
|
|
|
|
b = stack.pop();
|
|
|
|
c = stack.pop();
|
2014-12-16 05:54:47 +03:00
|
|
|
var d = stack.pop();
|
|
|
|
stack.push(b);
|
|
|
|
stack.push(a);
|
|
|
|
stack.push(d);
|
|
|
|
stack.push(c);
|
|
|
|
stack.push(b);
|
|
|
|
stack.push(a);
|
|
|
|
break;
|
|
|
|
case Bytecodes.SWAP:
|
2014-12-25 20:39:53 +03:00
|
|
|
a = stack.pop();
|
|
|
|
b = stack.pop();
|
2014-12-16 05:54:47 +03:00
|
|
|
stack.push(a);
|
|
|
|
stack.push(b);
|
|
|
|
break;
|
|
|
|
case Bytecodes.IINC:
|
2014-12-25 20:39:53 +03:00
|
|
|
index = frame.read8();
|
|
|
|
value = frame.read8Signed();
|
2015-01-17 03:40:58 +03:00
|
|
|
frame.incLocal(index, value);
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
2014-12-26 06:08:53 +03:00
|
|
|
case Bytecodes.IINC_GOTO:
|
|
|
|
index = frame.read8();
|
|
|
|
value = frame.read8Signed();
|
|
|
|
frame.setLocal(index, frame.getLocal(index) + value);
|
|
|
|
frame.pc ++;
|
|
|
|
frame.pc = frame.readTargetPC();
|
|
|
|
break;
|
2014-12-16 05:54:47 +03:00
|
|
|
case Bytecodes.IADD:
|
|
|
|
stack.push((stack.pop() + stack.pop()) | 0);
|
|
|
|
break;
|
|
|
|
case Bytecodes.LADD:
|
|
|
|
stack.push2(stack.pop2().add(stack.pop2()));
|
|
|
|
break;
|
|
|
|
case Bytecodes.FADD:
|
|
|
|
stack.push(Math.fround(stack.pop() + stack.pop()));
|
|
|
|
break;
|
|
|
|
case Bytecodes.DADD:
|
|
|
|
stack.push2(stack.pop2() + stack.pop2());
|
|
|
|
break;
|
|
|
|
case Bytecodes.ISUB:
|
|
|
|
stack.push((-stack.pop() + stack.pop()) | 0);
|
|
|
|
break;
|
|
|
|
case Bytecodes.LSUB:
|
|
|
|
stack.push2(stack.pop2().negate().add(stack.pop2()));
|
|
|
|
break;
|
|
|
|
case Bytecodes.FSUB:
|
|
|
|
stack.push(Math.fround(-stack.pop() + stack.pop()));
|
|
|
|
break;
|
|
|
|
case Bytecodes.DSUB:
|
|
|
|
stack.push2(-stack.pop2() + stack.pop2());
|
|
|
|
break;
|
|
|
|
case Bytecodes.IMUL:
|
|
|
|
stack.push(Math.imul(stack.pop(), stack.pop()));
|
|
|
|
break;
|
|
|
|
case Bytecodes.LMUL:
|
|
|
|
stack.push2(stack.pop2().multiply(stack.pop2()));
|
|
|
|
break;
|
|
|
|
case Bytecodes.FMUL:
|
|
|
|
stack.push(Math.fround(stack.pop() * stack.pop()));
|
|
|
|
break;
|
|
|
|
case Bytecodes.DMUL:
|
|
|
|
stack.push2(stack.pop2() * stack.pop2());
|
|
|
|
break;
|
|
|
|
case Bytecodes.IDIV:
|
2014-12-25 20:39:53 +03:00
|
|
|
b = stack.pop();
|
|
|
|
a = stack.pop();
|
2014-12-25 20:39:01 +03:00
|
|
|
checkDivideByZero(b);
|
|
|
|
stack.push((a === Constants.INT_MIN && b === -1) ? a : ((a / b) | 0));
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
|
|
|
case Bytecodes.LDIV:
|
2014-12-25 20:39:53 +03:00
|
|
|
b = stack.pop2();
|
|
|
|
a = stack.pop2();
|
2014-12-25 20:39:01 +03:00
|
|
|
checkDivideByZeroLong(b);
|
2014-12-16 05:54:47 +03:00
|
|
|
stack.push2(a.div(b));
|
|
|
|
break;
|
|
|
|
case Bytecodes.FDIV:
|
2014-12-25 20:39:53 +03:00
|
|
|
b = stack.pop();
|
|
|
|
a = stack.pop();
|
2014-12-16 05:54:47 +03:00
|
|
|
stack.push(Math.fround(a / b));
|
|
|
|
break;
|
|
|
|
case Bytecodes.DDIV:
|
2014-12-25 20:39:53 +03:00
|
|
|
b = stack.pop2();
|
|
|
|
a = stack.pop2();
|
2014-12-16 05:54:47 +03:00
|
|
|
stack.push2(a / b);
|
|
|
|
break;
|
|
|
|
case Bytecodes.IREM:
|
2014-12-25 20:39:53 +03:00
|
|
|
b = stack.pop();
|
|
|
|
a = stack.pop();
|
2014-12-25 20:39:01 +03:00
|
|
|
checkDivideByZero(b);
|
2014-12-16 05:54:47 +03:00
|
|
|
stack.push(a % b);
|
|
|
|
break;
|
|
|
|
case Bytecodes.LREM:
|
2014-12-25 20:39:53 +03:00
|
|
|
b = stack.pop2();
|
|
|
|
a = stack.pop2();
|
2014-12-25 20:39:01 +03:00
|
|
|
checkDivideByZeroLong(b);
|
2014-12-16 05:54:47 +03:00
|
|
|
stack.push2(a.modulo(b));
|
|
|
|
break;
|
|
|
|
case Bytecodes.FREM:
|
2014-12-25 20:39:53 +03:00
|
|
|
b = stack.pop();
|
|
|
|
a = stack.pop();
|
2014-12-16 05:54:47 +03:00
|
|
|
stack.push(Math.fround(a % b));
|
|
|
|
break;
|
|
|
|
case Bytecodes.DREM:
|
2014-12-25 20:39:53 +03:00
|
|
|
b = stack.pop2();
|
|
|
|
a = stack.pop2();
|
2014-12-16 05:54:47 +03:00
|
|
|
stack.push2(a % b);
|
|
|
|
break;
|
|
|
|
case Bytecodes.INEG:
|
|
|
|
stack.push((-stack.pop()) | 0);
|
|
|
|
break;
|
|
|
|
case Bytecodes.LNEG:
|
|
|
|
stack.push2(stack.pop2().negate());
|
|
|
|
break;
|
|
|
|
case Bytecodes.FNEG:
|
|
|
|
stack.push(-stack.pop());
|
|
|
|
break;
|
|
|
|
case Bytecodes.DNEG:
|
|
|
|
stack.push2(-stack.pop2());
|
|
|
|
break;
|
|
|
|
case Bytecodes.ISHL:
|
2014-12-25 20:39:53 +03:00
|
|
|
b = stack.pop();
|
|
|
|
a = stack.pop();
|
2014-12-16 05:54:47 +03:00
|
|
|
stack.push(a << b);
|
|
|
|
break;
|
|
|
|
case Bytecodes.LSHL:
|
2014-12-25 20:39:53 +03:00
|
|
|
b = stack.pop();
|
|
|
|
a = stack.pop2();
|
2014-12-16 05:54:47 +03:00
|
|
|
stack.push2(a.shiftLeft(b));
|
|
|
|
break;
|
|
|
|
case Bytecodes.ISHR:
|
2014-12-25 20:39:53 +03:00
|
|
|
b = stack.pop();
|
|
|
|
a = stack.pop();
|
2014-12-16 05:54:47 +03:00
|
|
|
stack.push(a >> b);
|
|
|
|
break;
|
|
|
|
case Bytecodes.LSHR:
|
2014-12-25 20:39:53 +03:00
|
|
|
b = stack.pop();
|
|
|
|
a = stack.pop2();
|
2014-12-16 05:54:47 +03:00
|
|
|
stack.push2(a.shiftRight(b));
|
|
|
|
break;
|
|
|
|
case Bytecodes.IUSHR:
|
2014-12-25 20:39:53 +03:00
|
|
|
b = stack.pop();
|
|
|
|
a = stack.pop();
|
2014-12-16 05:54:47 +03:00
|
|
|
stack.push(a >>> b);
|
|
|
|
break;
|
|
|
|
case Bytecodes.LUSHR:
|
2014-12-25 20:39:53 +03:00
|
|
|
b = stack.pop();
|
|
|
|
a = stack.pop2();
|
2014-12-16 05:54:47 +03:00
|
|
|
stack.push2(a.shiftRightUnsigned(b));
|
|
|
|
break;
|
|
|
|
case Bytecodes.IAND:
|
|
|
|
stack.push(stack.pop() & stack.pop());
|
|
|
|
break;
|
|
|
|
case Bytecodes.LAND:
|
|
|
|
stack.push2(stack.pop2().and(stack.pop2()));
|
|
|
|
break;
|
|
|
|
case Bytecodes.IOR:
|
|
|
|
stack.push(stack.pop() | stack.pop());
|
|
|
|
break;
|
|
|
|
case Bytecodes.LOR:
|
|
|
|
stack.push2(stack.pop2().or(stack.pop2()));
|
|
|
|
break;
|
|
|
|
case Bytecodes.IXOR:
|
|
|
|
stack.push(stack.pop() ^ stack.pop());
|
|
|
|
break;
|
|
|
|
case Bytecodes.LXOR:
|
|
|
|
stack.push2(stack.pop2().xor(stack.pop2()));
|
|
|
|
break;
|
|
|
|
case Bytecodes.LCMP:
|
2014-12-25 20:39:53 +03:00
|
|
|
b = stack.pop2();
|
|
|
|
a = stack.pop2();
|
2014-12-16 05:54:47 +03:00
|
|
|
if (a.greaterThan(b)) {
|
|
|
|
stack.push(1);
|
|
|
|
} else if (a.lessThan(b)) {
|
|
|
|
stack.push(-1);
|
|
|
|
} else {
|
|
|
|
stack.push(0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Bytecodes.FCMPL:
|
2014-12-25 20:39:53 +03:00
|
|
|
b = stack.pop();
|
|
|
|
a = stack.pop();
|
2014-12-16 05:54:47 +03:00
|
|
|
if (isNaN(a) || isNaN(b)) {
|
|
|
|
stack.push(-1);
|
|
|
|
} else if (a > b) {
|
|
|
|
stack.push(1);
|
|
|
|
} else if (a < b) {
|
|
|
|
stack.push(-1);
|
|
|
|
} else {
|
|
|
|
stack.push(0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Bytecodes.FCMPG:
|
2014-12-25 20:39:53 +03:00
|
|
|
b = stack.pop();
|
|
|
|
a = stack.pop();
|
2014-12-16 05:54:47 +03:00
|
|
|
if (isNaN(a) || isNaN(b)) {
|
|
|
|
stack.push(1);
|
|
|
|
} else if (a > b) {
|
|
|
|
stack.push(1);
|
|
|
|
} else if (a < b) {
|
|
|
|
stack.push(-1);
|
|
|
|
} else {
|
|
|
|
stack.push(0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Bytecodes.DCMPL:
|
2014-12-25 20:39:53 +03:00
|
|
|
b = stack.pop2();
|
|
|
|
a = stack.pop2();
|
2014-12-16 05:54:47 +03:00
|
|
|
if (isNaN(a) || isNaN(b)) {
|
|
|
|
stack.push(-1);
|
|
|
|
} else if (a > b) {
|
|
|
|
stack.push(1);
|
|
|
|
} else if (a < b) {
|
|
|
|
stack.push(-1);
|
|
|
|
} else {
|
|
|
|
stack.push(0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Bytecodes.DCMPG:
|
2014-12-25 20:39:53 +03:00
|
|
|
b = stack.pop2();
|
|
|
|
a = stack.pop2();
|
2014-12-16 05:54:47 +03:00
|
|
|
if (isNaN(a) || isNaN(b)) {
|
|
|
|
stack.push(1);
|
|
|
|
} else if (a > b) {
|
|
|
|
stack.push(1);
|
|
|
|
} else if (a < b) {
|
|
|
|
stack.push(-1);
|
|
|
|
} else {
|
|
|
|
stack.push(0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Bytecodes.IFEQ:
|
2014-12-25 21:03:06 +03:00
|
|
|
pc = frame.readTargetPC();
|
|
|
|
if (stack.pop() === 0) {
|
|
|
|
frame.pc = pc;
|
|
|
|
}
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
|
|
|
case Bytecodes.IFNE:
|
2014-12-25 21:03:06 +03:00
|
|
|
pc = frame.readTargetPC();
|
|
|
|
if (stack.pop() !== 0) {
|
|
|
|
frame.pc = pc;
|
|
|
|
}
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
|
|
|
case Bytecodes.IFLT:
|
2014-12-25 21:03:06 +03:00
|
|
|
pc = frame.readTargetPC();
|
|
|
|
if (stack.pop() < 0) {
|
|
|
|
frame.pc = pc;
|
|
|
|
}
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
|
|
|
case Bytecodes.IFGE:
|
2014-12-25 21:03:06 +03:00
|
|
|
pc = frame.readTargetPC();
|
|
|
|
if (stack.pop() >= 0) {
|
|
|
|
frame.pc = pc;
|
|
|
|
}
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
|
|
|
case Bytecodes.IFGT:
|
2014-12-25 21:03:06 +03:00
|
|
|
pc = frame.readTargetPC();
|
|
|
|
if (stack.pop() > 0) {
|
|
|
|
frame.pc = pc;
|
|
|
|
}
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
|
|
|
case Bytecodes.IFLE:
|
2014-12-25 21:03:06 +03:00
|
|
|
pc = frame.readTargetPC();
|
|
|
|
if (stack.pop() <= 0) {
|
|
|
|
frame.pc = pc;
|
|
|
|
}
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
|
|
|
case Bytecodes.IF_ICMPEQ:
|
2014-12-25 21:03:06 +03:00
|
|
|
pc = frame.readTargetPC();
|
|
|
|
if (stack.pop() === stack.pop()) {
|
|
|
|
frame.pc = pc;
|
|
|
|
}
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
|
|
|
case Bytecodes.IF_ICMPNE:
|
2014-12-25 21:03:06 +03:00
|
|
|
pc = frame.readTargetPC();
|
|
|
|
if (stack.pop() !== stack.pop()) {
|
|
|
|
frame.pc = pc;
|
|
|
|
}
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
|
|
|
case Bytecodes.IF_ICMPLT:
|
2014-12-25 21:03:06 +03:00
|
|
|
pc = frame.readTargetPC();
|
|
|
|
if (stack.pop() > stack.pop()) {
|
|
|
|
frame.pc = pc;
|
|
|
|
}
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
|
|
|
case Bytecodes.IF_ICMPGE:
|
2014-12-25 21:03:06 +03:00
|
|
|
pc = frame.readTargetPC();
|
|
|
|
if (stack.pop() <= stack.pop()) {
|
|
|
|
frame.pc = pc;
|
|
|
|
}
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
|
|
|
case Bytecodes.IF_ICMPGT:
|
2014-12-25 21:03:06 +03:00
|
|
|
pc = frame.readTargetPC();
|
|
|
|
if (stack.pop() < stack.pop()) {
|
|
|
|
frame.pc = pc;
|
|
|
|
}
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
|
|
|
case Bytecodes.IF_ICMPLE:
|
2014-12-25 21:03:06 +03:00
|
|
|
pc = frame.readTargetPC();
|
|
|
|
if (stack.pop() >= stack.pop()) {
|
|
|
|
frame.pc = pc;
|
|
|
|
}
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
|
|
|
case Bytecodes.IF_ACMPEQ:
|
2014-12-25 21:03:06 +03:00
|
|
|
pc = frame.readTargetPC();
|
|
|
|
if (stack.pop() === stack.pop()) {
|
|
|
|
frame.pc = pc;
|
|
|
|
}
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
|
|
|
case Bytecodes.IF_ACMPNE:
|
2014-12-25 21:03:06 +03:00
|
|
|
pc = frame.readTargetPC();
|
|
|
|
if (stack.pop() !== stack.pop()) {
|
|
|
|
frame.pc = pc;
|
|
|
|
}
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
|
|
|
case Bytecodes.IFNULL:
|
2014-12-25 21:03:06 +03:00
|
|
|
pc = frame.readTargetPC();
|
|
|
|
if (!stack.pop()) {
|
|
|
|
frame.pc = pc;
|
|
|
|
}
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
|
|
|
case Bytecodes.IFNONNULL:
|
2014-12-25 21:03:06 +03:00
|
|
|
pc = frame.readTargetPC();
|
|
|
|
if (stack.pop()) {
|
|
|
|
frame.pc = pc;
|
|
|
|
}
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
|
|
|
case Bytecodes.GOTO:
|
2014-12-25 21:03:06 +03:00
|
|
|
frame.pc = frame.readTargetPC();
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
|
|
|
case Bytecodes.GOTO_W:
|
2014-12-25 21:03:06 +03:00
|
|
|
frame.pc = frame.read32Signed() - 1;
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
|
|
|
case Bytecodes.JSR:
|
2014-12-25 21:03:06 +03:00
|
|
|
pc = frame.read16();
|
|
|
|
stack.push(frame.pc);
|
|
|
|
frame.pc = pc;
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
|
|
|
case Bytecodes.JSR_W:
|
2014-12-25 21:03:06 +03:00
|
|
|
pc = frame.read32();
|
|
|
|
stack.push(frame.pc);
|
|
|
|
frame.pc = pc;
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
|
|
|
case Bytecodes.RET:
|
2014-12-25 21:03:06 +03:00
|
|
|
frame.pc = frame.getLocal(frame.read8());
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
|
|
|
case Bytecodes.I2L:
|
|
|
|
stack.push2(Long.fromInt(stack.pop()));
|
|
|
|
break;
|
|
|
|
case Bytecodes.I2F:
|
|
|
|
break;
|
|
|
|
case Bytecodes.I2D:
|
|
|
|
stack.push2(stack.pop());
|
|
|
|
break;
|
|
|
|
case Bytecodes.L2I:
|
|
|
|
stack.push(stack.pop2().toInt());
|
|
|
|
break;
|
|
|
|
case Bytecodes.L2F:
|
|
|
|
stack.push(Math.fround(stack.pop2().toNumber()));
|
|
|
|
break;
|
|
|
|
case Bytecodes.L2D:
|
|
|
|
stack.push2(stack.pop2().toNumber());
|
|
|
|
break;
|
|
|
|
case Bytecodes.F2I:
|
|
|
|
stack.push(util.double2int(stack.pop()));
|
|
|
|
break;
|
|
|
|
case Bytecodes.F2L:
|
|
|
|
stack.push2(Long.fromNumber(stack.pop()));
|
|
|
|
break;
|
|
|
|
case Bytecodes.F2D:
|
|
|
|
stack.push2(stack.pop());
|
|
|
|
break;
|
|
|
|
case Bytecodes.D2I:
|
|
|
|
stack.push(util.double2int(stack.pop2()));
|
|
|
|
break;
|
|
|
|
case Bytecodes.D2L:
|
|
|
|
stack.push2(util.double2long(stack.pop2()));
|
|
|
|
break;
|
|
|
|
case Bytecodes.D2F:
|
|
|
|
stack.push(Math.fround(stack.pop2()));
|
|
|
|
break;
|
|
|
|
case Bytecodes.I2B:
|
|
|
|
stack.push((stack.pop() << 24) >> 24);
|
|
|
|
break;
|
|
|
|
case Bytecodes.I2C:
|
|
|
|
stack.push(stack.pop() & 0xffff);
|
|
|
|
break;
|
|
|
|
case Bytecodes.I2S:
|
|
|
|
stack.push((stack.pop() << 16) >> 16);
|
|
|
|
break;
|
|
|
|
case Bytecodes.TABLESWITCH:
|
2014-12-25 21:03:06 +03:00
|
|
|
frame.pc = frame.tableSwitch();
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
|
|
|
case Bytecodes.LOOKUPSWITCH:
|
2014-12-25 21:03:06 +03:00
|
|
|
frame.pc = frame.lookupSwitch();
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
|
|
|
case Bytecodes.NEWARRAY:
|
2014-12-25 20:39:53 +03:00
|
|
|
type = frame.read8();
|
|
|
|
size = stack.pop();
|
2015-01-28 02:36:13 +03:00
|
|
|
stack.push(newArray(PrimitiveClassInfo["????ZCFDBSIJ"[type]].klass, size));
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
|
|
|
case Bytecodes.ANEWARRAY:
|
2014-12-25 20:39:53 +03:00
|
|
|
index = frame.read16();
|
2015-01-15 04:13:14 +03:00
|
|
|
classInfo = resolveClass(index, mi.classInfo, false);
|
2015-02-24 23:45:18 +03:00
|
|
|
classInitAndUnwindCheck(classInfo, frame.pc - 3);
|
2014-12-25 20:39:53 +03:00
|
|
|
size = stack.pop();
|
2015-01-28 01:59:21 +03:00
|
|
|
stack.push(newArray(classInfo.klass, size));
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
|
|
|
case Bytecodes.MULTIANEWARRAY:
|
2014-12-25 20:39:53 +03:00
|
|
|
index = frame.read16();
|
2015-01-15 04:13:14 +03:00
|
|
|
classInfo = resolveClass(index, mi.classInfo, false);
|
2014-12-16 05:54:47 +03:00
|
|
|
var dimensions = frame.read8();
|
|
|
|
var lengths = new Array(dimensions);
|
|
|
|
for (var i = 0; i < dimensions; i++)
|
|
|
|
lengths[i] = stack.pop();
|
2015-02-28 03:28:45 +03:00
|
|
|
stack.push(J2ME.newMultiArray(classInfo.klass, lengths.reverse()));
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
|
|
|
case Bytecodes.ARRAYLENGTH:
|
2014-12-25 21:11:18 +03:00
|
|
|
array = stack.pop();
|
|
|
|
stack.push(array.length);
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
2014-12-26 06:08:53 +03:00
|
|
|
case Bytecodes.ARRAYLENGTH_IF_ICMPGE:
|
|
|
|
array = stack.pop();
|
|
|
|
stack.push(array.length);
|
|
|
|
frame.pc ++;
|
|
|
|
pc = frame.readTargetPC();
|
|
|
|
if (stack.pop() <= stack.pop()) {
|
|
|
|
frame.pc = pc;
|
|
|
|
}
|
|
|
|
break;
|
2014-12-16 05:54:47 +03:00
|
|
|
case Bytecodes.GETFIELD:
|
2014-12-25 20:39:53 +03:00
|
|
|
index = frame.read16();
|
2015-01-15 04:13:14 +03:00
|
|
|
fieldInfo = resolveField(index, mi.classInfo, false);
|
2014-12-25 21:11:18 +03:00
|
|
|
object = stack.pop();
|
2014-12-26 06:49:09 +03:00
|
|
|
stack.pushKind(fieldInfo.kind, fieldInfo.get(object));
|
2015-01-17 03:40:58 +03:00
|
|
|
frame.patch(3, Bytecodes.GETFIELD, Bytecodes.RESOLVED_GETFIELD);
|
|
|
|
break;
|
|
|
|
case Bytecodes.RESOLVED_GETFIELD:
|
2015-01-20 22:02:05 +03:00
|
|
|
fieldInfo = <FieldInfo><any>rp[frame.read16()];
|
2015-01-17 03:40:58 +03:00
|
|
|
object = stack.pop();
|
|
|
|
stack.pushKind(fieldInfo.kind, fieldInfo.get(object));
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
|
|
|
case Bytecodes.PUTFIELD:
|
2014-12-25 20:39:53 +03:00
|
|
|
index = frame.read16();
|
2015-01-15 04:13:14 +03:00
|
|
|
fieldInfo = resolveField(index, mi.classInfo, false);
|
2014-12-26 06:49:09 +03:00
|
|
|
value = stack.popKind(fieldInfo.kind);
|
2014-12-25 21:11:18 +03:00
|
|
|
object = stack.pop();
|
2014-12-26 06:49:09 +03:00
|
|
|
fieldInfo.set(object, value);
|
2015-01-17 03:40:58 +03:00
|
|
|
frame.patch(3, Bytecodes.PUTFIELD, Bytecodes.RESOLVED_PUTFIELD);
|
|
|
|
break;
|
|
|
|
case Bytecodes.RESOLVED_PUTFIELD:
|
2015-01-20 22:02:05 +03:00
|
|
|
fieldInfo = <FieldInfo><any>rp[frame.read16()];
|
2015-01-17 03:40:58 +03:00
|
|
|
value = stack.popKind(fieldInfo.kind);
|
|
|
|
object = stack.pop();
|
|
|
|
fieldInfo.set(object, value);
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
|
|
|
case Bytecodes.GETSTATIC:
|
2014-12-25 20:39:53 +03:00
|
|
|
index = frame.read16();
|
2015-01-15 04:13:14 +03:00
|
|
|
fieldInfo = resolveField(index, mi.classInfo, true);
|
2015-02-24 23:45:18 +03:00
|
|
|
classInitAndUnwindCheck(fieldInfo.classInfo, frame.pc - 3);
|
2014-12-17 07:46:05 +03:00
|
|
|
if (U) {
|
2014-12-16 06:38:08 +03:00
|
|
|
return;
|
|
|
|
}
|
2014-12-26 06:49:09 +03:00
|
|
|
value = fieldInfo.getStatic();
|
|
|
|
stack.pushKind(fieldInfo.kind, value);
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
|
|
|
case Bytecodes.PUTSTATIC:
|
2014-12-25 20:39:53 +03:00
|
|
|
index = frame.read16();
|
2015-01-15 04:13:14 +03:00
|
|
|
fieldInfo = resolveField(index, mi.classInfo, true);
|
2015-02-24 23:45:18 +03:00
|
|
|
classInitAndUnwindCheck(fieldInfo.classInfo, frame.pc - 3);
|
2014-12-17 07:46:05 +03:00
|
|
|
if (U) {
|
2014-12-16 06:38:08 +03:00
|
|
|
return;
|
|
|
|
}
|
2014-12-26 06:49:09 +03:00
|
|
|
fieldInfo.setStatic(stack.popKind(fieldInfo.kind));
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
|
|
|
case Bytecodes.NEW:
|
2014-12-25 20:39:53 +03:00
|
|
|
index = frame.read16();
|
2015-01-15 04:13:14 +03:00
|
|
|
classInfo = resolveClass(index, mi.classInfo, false);
|
2015-02-24 23:45:18 +03:00
|
|
|
classInitAndUnwindCheck(classInfo, frame.pc - 3);
|
2014-12-17 07:46:05 +03:00
|
|
|
if (U) {
|
2014-12-16 06:38:08 +03:00
|
|
|
return;
|
|
|
|
}
|
2015-01-28 02:10:04 +03:00
|
|
|
stack.push(newObject(classInfo.klass));
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
|
|
|
case Bytecodes.CHECKCAST:
|
2014-12-25 20:39:53 +03:00
|
|
|
index = frame.read16();
|
2015-01-15 04:13:14 +03:00
|
|
|
classInfo = resolveClass(index, mi.classInfo, false);
|
2014-12-25 21:11:18 +03:00
|
|
|
object = stack[stack.length - 1];
|
|
|
|
if (object && !isAssignableTo(object.klass, classInfo.klass)) {
|
2014-12-23 19:00:11 +03:00
|
|
|
throw $.newClassCastException(
|
2014-12-25 21:11:18 +03:00
|
|
|
object.klass.classInfo.className + " is not assignable to " +
|
2014-12-16 05:54:47 +03:00
|
|
|
classInfo.className);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Bytecodes.INSTANCEOF:
|
2014-12-25 20:39:53 +03:00
|
|
|
index = frame.read16();
|
2015-01-15 04:13:14 +03:00
|
|
|
classInfo = resolveClass(index, mi.classInfo, false);
|
2014-12-25 21:11:18 +03:00
|
|
|
object = stack.pop();
|
|
|
|
var result = !object ? false : isAssignableTo(object.klass, classInfo.klass);
|
2014-12-16 05:54:47 +03:00
|
|
|
stack.push(result ? 1 : 0);
|
|
|
|
break;
|
|
|
|
case Bytecodes.ATHROW:
|
2014-12-25 21:11:18 +03:00
|
|
|
object = stack.pop();
|
|
|
|
if (!object) {
|
2014-12-23 19:00:11 +03:00
|
|
|
throw $.newNullPointerException();
|
2014-12-16 05:54:47 +03:00
|
|
|
}
|
2014-12-25 21:11:18 +03:00
|
|
|
throw object;
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
|
|
|
case Bytecodes.MONITORENTER:
|
2014-12-25 21:11:18 +03:00
|
|
|
object = stack.pop();
|
|
|
|
ctx.monitorEnter(object);
|
2015-02-04 09:35:10 +03:00
|
|
|
if (U === VMState.Pausing || U === VMState.Stopping) {
|
2014-12-16 05:54:47 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Bytecodes.MONITOREXIT:
|
2014-12-25 21:11:18 +03:00
|
|
|
object = stack.pop();
|
|
|
|
ctx.monitorExit(object);
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
|
|
|
case Bytecodes.WIDE:
|
2014-12-25 21:17:00 +03:00
|
|
|
frame.wide();
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
2015-01-17 03:40:58 +03:00
|
|
|
case Bytecodes.RESOLVED_INVOKEVIRTUAL:
|
|
|
|
index = frame.read16();
|
2015-01-20 22:02:05 +03:00
|
|
|
var calleeMethodInfo = <MethodInfo><any>rp[index];
|
2015-01-17 03:40:58 +03:00
|
|
|
var object = frame.peekInvokeObject(calleeMethodInfo);
|
|
|
|
|
|
|
|
calleeMethod = object[calleeMethodInfo.mangledName];
|
|
|
|
var calleeTargetMethodInfo: MethodInfo = calleeMethod.methodInfo;
|
|
|
|
|
2015-01-22 06:55:23 +03:00
|
|
|
if (calleeTargetMethodInfo &&
|
|
|
|
!calleeTargetMethodInfo.isSynchronized &&
|
|
|
|
!calleeTargetMethodInfo.isNative &&
|
|
|
|
calleeTargetMethodInfo.state !== MethodState.Compiled) {
|
2015-01-17 03:40:58 +03:00
|
|
|
var calleeFrame = Frame.create(calleeTargetMethodInfo, [], 0);
|
|
|
|
ArrayUtilities.popManyInto(stack, calleeTargetMethodInfo.consumeArgumentSlots, calleeFrame.local);
|
|
|
|
frames.push(calleeFrame);
|
|
|
|
frame = calleeFrame;
|
|
|
|
mi = frame.methodInfo;
|
2015-01-22 13:20:51 +03:00
|
|
|
mi.interpreterCallCount ++;
|
2015-01-17 03:40:58 +03:00
|
|
|
ci = mi.classInfo;
|
2015-01-20 22:02:05 +03:00
|
|
|
rp = ci.resolved_constant_pool;
|
2015-01-17 03:40:58 +03:00
|
|
|
stack = frame.stack;
|
2015-01-19 06:54:01 +03:00
|
|
|
lastPC = -1;
|
2015-01-17 03:40:58 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Call directy.
|
|
|
|
var returnValue;
|
|
|
|
var argumentSlots = calleeMethodInfo.argumentSlots;
|
|
|
|
switch (argumentSlots) {
|
|
|
|
case 0:
|
|
|
|
returnValue = calleeMethod.call(object);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
a = stack.pop();
|
|
|
|
returnValue = calleeMethod.call(object, a);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
b = stack.pop();
|
|
|
|
a = stack.pop();
|
|
|
|
returnValue = calleeMethod.call(object, a, b);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
c = stack.pop();
|
|
|
|
b = stack.pop();
|
|
|
|
a = stack.pop();
|
|
|
|
returnValue = calleeMethod.call(object, a, b, c);
|
|
|
|
break;
|
|
|
|
default:
|
2015-02-28 00:42:20 +03:00
|
|
|
Debug.assertUnreachable("Unexpected number of arguments");
|
|
|
|
break;
|
2015-01-17 03:40:58 +03:00
|
|
|
}
|
|
|
|
stack.pop();
|
|
|
|
if (!release) {
|
|
|
|
checkReturnValue(calleeMethodInfo, returnValue);
|
|
|
|
}
|
|
|
|
if (U) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (calleeMethodInfo.getReturnKind() !== Kind.Void) {
|
|
|
|
if (isTwoSlot(calleeMethodInfo.getReturnKind())) {
|
|
|
|
stack.push2(returnValue);
|
|
|
|
} else {
|
|
|
|
stack.push(returnValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2014-12-16 05:54:47 +03:00
|
|
|
case Bytecodes.INVOKEVIRTUAL:
|
|
|
|
case Bytecodes.INVOKESPECIAL:
|
|
|
|
case Bytecodes.INVOKESTATIC:
|
|
|
|
case Bytecodes.INVOKEINTERFACE:
|
2014-12-25 20:39:53 +03:00
|
|
|
index = frame.read16();
|
2014-12-26 08:03:45 +03:00
|
|
|
if (op === Bytecodes.INVOKEINTERFACE) {
|
2015-01-17 03:40:58 +03:00
|
|
|
frame.read16(); // Args Number & Zero
|
2014-12-16 05:54:47 +03:00
|
|
|
}
|
2014-12-26 08:03:45 +03:00
|
|
|
var isStatic = (op === Bytecodes.INVOKESTATIC);
|
2015-01-17 03:40:58 +03:00
|
|
|
|
|
|
|
// Resolve method and do the class init check if necessary.
|
|
|
|
var calleeMethodInfo = resolveMethod(index, mi.classInfo, isStatic);
|
2015-01-22 03:51:48 +03:00
|
|
|
|
|
|
|
// Fast path for some of the most common interpreter call targets.
|
|
|
|
if (calleeMethodInfo.implKey === "java/lang/Object.<init>.()V") {
|
|
|
|
stack.pop();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-01-17 03:40:58 +03:00
|
|
|
if (isStatic) {
|
2015-02-24 23:45:18 +03:00
|
|
|
classInitAndUnwindCheck(calleeMethodInfo.classInfo, lastPC);
|
2015-01-17 03:40:58 +03:00
|
|
|
if (U) {
|
|
|
|
return;
|
2014-12-16 06:38:08 +03:00
|
|
|
}
|
2014-12-16 05:54:47 +03:00
|
|
|
}
|
2015-01-17 03:40:58 +03:00
|
|
|
|
|
|
|
// Figure out the target method.
|
|
|
|
var calleeTargetMethodInfo: MethodInfo = calleeMethodInfo;
|
2014-12-25 21:11:18 +03:00
|
|
|
object = null;
|
2015-01-17 03:40:58 +03:00
|
|
|
var calleeMethod: any;
|
2014-12-16 05:54:47 +03:00
|
|
|
if (!isStatic) {
|
2015-01-17 03:40:58 +03:00
|
|
|
object = frame.peekInvokeObject(calleeMethodInfo);
|
2014-12-16 05:54:47 +03:00
|
|
|
switch (op) {
|
|
|
|
case Bytecodes.INVOKEVIRTUAL:
|
2015-01-17 03:40:58 +03:00
|
|
|
if (!calleeTargetMethodInfo.hasTwoSlotArguments &&
|
|
|
|
calleeTargetMethodInfo.argumentSlots < 4) {
|
|
|
|
frame.patch(3, Bytecodes.INVOKEVIRTUAL, Bytecodes.RESOLVED_INVOKEVIRTUAL);
|
|
|
|
}
|
2014-12-16 05:54:47 +03:00
|
|
|
case Bytecodes.INVOKEINTERFACE:
|
2015-01-17 03:40:58 +03:00
|
|
|
calleeMethod = object[calleeMethodInfo.mangledName];
|
|
|
|
calleeTargetMethodInfo = calleeMethod.methodInfo;
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
|
|
|
case Bytecodes.INVOKESPECIAL:
|
2014-12-26 06:08:53 +03:00
|
|
|
checkNull(object);
|
2015-01-17 03:40:58 +03:00
|
|
|
calleeMethod = calleeMethodInfo.fn;
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
2015-01-17 03:40:58 +03:00
|
|
|
calleeMethod = calleeMethodInfo.fn;
|
2014-11-27 12:15:46 +03:00
|
|
|
}
|
2015-01-17 03:40:58 +03:00
|
|
|
// Call method directly in the interpreter if we can.
|
2015-01-21 02:56:29 +03:00
|
|
|
if (calleeTargetMethodInfo && !calleeTargetMethodInfo.isNative && calleeTargetMethodInfo.state !== MethodState.Compiled) {
|
2015-01-17 03:40:58 +03:00
|
|
|
var calleeFrame = Frame.create(calleeTargetMethodInfo, [], 0);
|
|
|
|
ArrayUtilities.popManyInto(stack, calleeTargetMethodInfo.consumeArgumentSlots, calleeFrame.local);
|
|
|
|
frames.push(calleeFrame);
|
|
|
|
frame = calleeFrame;
|
|
|
|
mi = frame.methodInfo;
|
2015-01-22 13:20:51 +03:00
|
|
|
mi.interpreterCallCount ++;
|
2015-01-17 03:40:58 +03:00
|
|
|
ci = mi.classInfo;
|
2015-01-20 22:02:05 +03:00
|
|
|
rp = ci.resolved_constant_pool;
|
2015-01-17 03:40:58 +03:00
|
|
|
stack = frame.stack;
|
2015-01-19 06:54:01 +03:00
|
|
|
lastPC = -1;
|
2015-01-17 03:40:58 +03:00
|
|
|
if (calleeTargetMethodInfo.isSynchronized) {
|
|
|
|
if (!calleeFrame.lockObject) {
|
|
|
|
frame.lockObject = calleeTargetMethodInfo.isStatic
|
|
|
|
? calleeTargetMethodInfo.classInfo.getClassObject()
|
|
|
|
: frame.getLocal(0);
|
|
|
|
}
|
|
|
|
ctx.monitorEnter(calleeFrame.lockObject);
|
2015-02-04 09:35:10 +03:00
|
|
|
if (U === VMState.Pausing || U === VMState.Stopping) {
|
2015-01-17 03:40:58 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Call directy.
|
2014-12-21 11:49:20 +03:00
|
|
|
var returnValue;
|
2015-01-17 03:40:58 +03:00
|
|
|
var argumentSlots = calleeMethodInfo.hasTwoSlotArguments ? -1 : calleeMethodInfo.argumentSlots;
|
2014-12-31 04:48:53 +03:00
|
|
|
switch (argumentSlots) {
|
2014-12-21 11:49:20 +03:00
|
|
|
case 0:
|
2015-01-17 03:40:58 +03:00
|
|
|
returnValue = calleeMethod.call(object);
|
2014-12-21 11:49:20 +03:00
|
|
|
break;
|
|
|
|
case 1:
|
2014-12-25 20:39:53 +03:00
|
|
|
a = stack.pop();
|
2015-01-17 03:40:58 +03:00
|
|
|
returnValue = calleeMethod.call(object, a);
|
2014-12-21 11:49:20 +03:00
|
|
|
break;
|
|
|
|
case 2:
|
2014-12-25 20:39:53 +03:00
|
|
|
b = stack.pop();
|
|
|
|
a = stack.pop();
|
2015-01-17 03:40:58 +03:00
|
|
|
returnValue = calleeMethod.call(object, a, b);
|
2014-12-21 11:49:20 +03:00
|
|
|
break;
|
|
|
|
case 3:
|
2014-12-25 20:39:53 +03:00
|
|
|
c = stack.pop();
|
|
|
|
b = stack.pop();
|
|
|
|
a = stack.pop();
|
2015-01-17 03:40:58 +03:00
|
|
|
returnValue = calleeMethod.call(object, a, b, c);
|
2014-12-21 11:49:20 +03:00
|
|
|
break;
|
|
|
|
default:
|
2015-01-17 03:40:58 +03:00
|
|
|
if (calleeMethodInfo.hasTwoSlotArguments) {
|
|
|
|
frame.popArgumentsInto(calleeMethodInfo.signatureDescriptor, argArray);
|
2014-12-26 08:34:17 +03:00
|
|
|
} else {
|
2015-01-17 03:40:58 +03:00
|
|
|
popManyInto(stack, calleeMethodInfo.argumentSlots, argArray);
|
2014-12-21 11:49:20 +03:00
|
|
|
}
|
2015-01-17 03:40:58 +03:00
|
|
|
var returnValue = calleeMethod.apply(object, argArray);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isStatic) {
|
|
|
|
stack.pop();
|
2014-12-16 05:54:47 +03:00
|
|
|
}
|
2014-12-21 11:08:46 +03:00
|
|
|
|
|
|
|
if (!release) {
|
2015-01-17 03:40:58 +03:00
|
|
|
checkReturnValue(calleeMethodInfo, returnValue);
|
2014-12-19 00:03:59 +03:00
|
|
|
}
|
2014-12-21 11:08:46 +03:00
|
|
|
|
2014-12-17 07:46:05 +03:00
|
|
|
if (U) {
|
2014-12-16 04:38:27 +03:00
|
|
|
return;
|
|
|
|
}
|
2014-12-16 04:06:53 +03:00
|
|
|
|
2015-01-17 03:40:58 +03:00
|
|
|
if (calleeMethodInfo.getReturnKind() !== Kind.Void) {
|
|
|
|
if (isTwoSlot(calleeMethodInfo.getReturnKind())) {
|
2014-12-16 05:54:47 +03:00
|
|
|
stack.push2(returnValue);
|
|
|
|
} else {
|
|
|
|
stack.push(returnValue);
|
|
|
|
}
|
2014-12-02 04:01:28 +03:00
|
|
|
}
|
2014-12-16 05:54:47 +03:00
|
|
|
break;
|
2015-01-16 15:58:54 +03:00
|
|
|
|
|
|
|
case Bytecodes.LRETURN:
|
|
|
|
case Bytecodes.DRETURN:
|
|
|
|
returnValue = stack.pop();
|
2014-12-16 05:54:47 +03:00
|
|
|
case Bytecodes.IRETURN:
|
|
|
|
case Bytecodes.FRETURN:
|
|
|
|
case Bytecodes.ARETURN:
|
2015-01-16 15:58:54 +03:00
|
|
|
returnValue = stack.pop();
|
|
|
|
case Bytecodes.RETURN:
|
|
|
|
var callee = frames.pop();
|
|
|
|
if (callee.lockObject) {
|
|
|
|
ctx.monitorExit(callee.lockObject);
|
2014-12-16 05:54:47 +03:00
|
|
|
}
|
2015-01-17 03:40:58 +03:00
|
|
|
callee.free();
|
2015-01-16 15:58:54 +03:00
|
|
|
frame = frames[frames.length - 1];
|
|
|
|
if (Frame.isMarker(frame)) { // Marker or Start Frame
|
|
|
|
if (op === Bytecodes.RETURN) {
|
|
|
|
return undefined;
|
|
|
|
}
|
2014-12-16 05:54:47 +03:00
|
|
|
return returnValue;
|
2015-01-16 15:58:54 +03:00
|
|
|
}
|
2015-01-17 03:40:58 +03:00
|
|
|
mi = frame.methodInfo;
|
|
|
|
ci = mi.classInfo;
|
2015-01-20 22:02:05 +03:00
|
|
|
rp = ci.resolved_constant_pool;
|
2015-01-19 06:54:01 +03:00
|
|
|
stack = frame.stack;
|
|
|
|
lastPC = -1;
|
2015-01-16 15:58:54 +03:00
|
|
|
if (op === Bytecodes.RETURN) {
|
|
|
|
// Nop.
|
|
|
|
} else if (op === Bytecodes.LRETURN || op === Bytecodes.DRETURN) {
|
|
|
|
stack.push2(returnValue);
|
2014-12-30 01:11:39 +03:00
|
|
|
} else {
|
2015-01-16 15:58:54 +03:00
|
|
|
stack.push(returnValue);
|
2014-12-16 05:54:47 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
var opName = Bytecodes[op];
|
|
|
|
throw new Error("Opcode " + opName + " [" + op + "] not supported.");
|
|
|
|
}
|
|
|
|
} catch (e) {
|
2015-01-23 02:17:07 +03:00
|
|
|
// This can happen if we OSR into a frame that is right after a marker
|
|
|
|
// frame. If an exception occurs in this frame, then we end up here and
|
|
|
|
// the current frame is a marker frame, so we'll need to rethrow.
|
|
|
|
if (Frame.isMarker(ctx.current())) {
|
|
|
|
throw e;
|
|
|
|
}
|
2015-01-17 03:40:58 +03:00
|
|
|
e = translateException(e);
|
|
|
|
if (!e.klass) {
|
|
|
|
// A non-java exception was thrown. Rethrow so it is not handled by tryCatch.
|
2015-01-03 02:43:51 +03:00
|
|
|
throw e;
|
2014-12-17 04:46:47 +03:00
|
|
|
}
|
2015-01-16 15:58:54 +03:00
|
|
|
tryCatch(e);
|
2014-12-30 01:11:39 +03:00
|
|
|
frame = ctx.current();
|
2015-01-16 15:58:54 +03:00
|
|
|
assert (!Frame.isMarker(frame));
|
2015-01-17 03:40:58 +03:00
|
|
|
mi = frame.methodInfo;
|
|
|
|
ci = mi.classInfo;
|
2015-01-20 22:02:05 +03:00
|
|
|
rp = ci.resolved_constant_pool;
|
2015-01-17 03:40:58 +03:00
|
|
|
stack = frame.stack;
|
2015-01-19 06:54:01 +03:00
|
|
|
lastPC = -1;
|
2014-12-16 05:54:47 +03:00
|
|
|
continue;
|
2014-11-27 12:15:46 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class VM {
|
|
|
|
static execute = interpret;
|
2014-12-10 05:19:35 +03:00
|
|
|
static Yield = {toString: function () { return "YIELD" }};
|
|
|
|
static Pause = {toString: function () { return "PAUSE" }};
|
2014-11-27 12:15:46 +03:00
|
|
|
static DEBUG_PRINT_ALL_EXCEPTIONS = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-14 03:47:42 +03:00
|
|
|
var VM = J2ME.VM;
|