Merge commit '7db214865011a419a7ecdd22248ce52afa1ef847' into jitjit

Conflicts:
	vm.js
This commit is contained in:
Marco Castelluccio 2014-10-13 09:38:28 -07:00
Родитель 1674677257 7db2148650
Коммит 0810f7149d
1 изменённых файлов: 9 добавлений и 34 удалений

43
vm.js
Просмотреть файл

@ -21,13 +21,10 @@ VM.trace = function(type, pid, methodInfo, returnVal) {
function checkArrayAccess(ctx, refArray, idx) {
if (!refArray) {
ctx.raiseExceptionAndYield("java/lang/NullPointerException");
return false;
}
if (idx < 0 || idx >= refArray.length) {
ctx.raiseExceptionAndYield("java/lang/ArrayIndexOutOfBoundsException", idx);
return false;
}
return true;
}
function resolve(ctx, cp, op, idx) {
@ -309,16 +306,14 @@ VM.execute = function(ctx) {
case 0x35: // saload
var idx = stack.pop();
var refArray = stack.pop();
if (!checkArrayAccess(ctx, refArray, idx))
break;
checkArrayAccess(ctx, refArray, idx);
stack.push(refArray[idx]);
break;
case 0x2f: // laload
case 0x31: // daload
var idx = stack.pop();
var refArray = stack.pop();
if (!checkArrayAccess(ctx, refArray, idx))
break;
checkArrayAccess(ctx, refArray, idx);
stack.push2(refArray[idx]);
break;
case 0x36: // istore
@ -374,8 +369,7 @@ VM.execute = function(ctx) {
var val = stack.pop();
var idx = stack.pop();
var refArray = stack.pop();
if (!checkArrayAccess(ctx, refArray, idx))
break;
checkArrayAccess(ctx, refArray, idx);
refArray[idx] = val;
break;
case 0x50: // lastore
@ -383,19 +377,16 @@ VM.execute = function(ctx) {
var val = stack.pop2();
var idx = stack.pop();
var refArray = stack.pop();
if (!checkArrayAccess(ctx, refArray, idx))
break;
checkArrayAccess(ctx, refArray, idx);
refArray[idx] = val;
break;
case 0x53: // aastore
var val = stack.pop();
var idx = stack.pop();
var refArray = stack.pop();
if (!checkArrayAccess(ctx, refArray, idx))
break;
checkArrayAccess(ctx, refArray, idx);
if (val && !val.class.isAssignableTo(refArray.class.elementClass)) {
ctx.raiseExceptionAndYield("java/lang/ArrayStoreException");
break;
}
refArray[idx] = val;
break;
@ -508,7 +499,6 @@ VM.execute = function(ctx) {
var a = stack.pop();
if (!b) {
ctx.raiseExceptionAndYield("java/lang/ArithmeticException", "/ by zero");
break;
}
stack.push((a === util.INT_MIN && b === -1) ? a : ((a / b)|0));
break;
@ -517,7 +507,6 @@ VM.execute = function(ctx) {
var a = stack.pop2();
if (b.isZero()) {
ctx.raiseExceptionAndYield("java/lang/ArithmeticException", "/ by zero");
break;
}
stack.push2(a.div(b));
break;
@ -536,7 +525,6 @@ VM.execute = function(ctx) {
var a = stack.pop();
if (!b) {
ctx.raiseExceptionAndYield("java/lang/ArithmeticException", "/ by zero");
break;
}
stack.push(a % b);
break;
@ -545,7 +533,6 @@ VM.execute = function(ctx) {
var a = stack.pop2();
if (b.isZero()) {
ctx.raiseExceptionAndYield("java/lang/ArithmeticException", "/ by zero");
break;
}
stack.push2(a.modulo(b));
break;
@ -851,7 +838,6 @@ VM.execute = function(ctx) {
var size = stack.pop();
if (size < 0) {
ctx.raiseExceptionAndYield("java/lang/NegativeArraySizeException", size);
break;
}
stack.push(ctx.newPrimitiveArray("????ZCFDBSIJ"[type], size));
break;
@ -863,7 +849,6 @@ VM.execute = function(ctx) {
var size = stack.pop();
if (size < 0) {
ctx.raiseExceptionAndYield("java/lang/NegativeArraySizeException", size);
break;
}
var className = classInfo.className;
if (className[0] !== "[")
@ -886,7 +871,6 @@ VM.execute = function(ctx) {
var obj = stack.pop();
if (!obj) {
ctx.raiseExceptionAndYield("java/lang/NullPointerException");
break;
}
stack.push(obj.length);
break;
@ -898,7 +882,6 @@ VM.execute = function(ctx) {
var obj = stack.pop();
if (!obj) {
ctx.raiseExceptionAndYield("java/lang/NullPointerException");
break;
}
stack.pushType(field.signature, field.get(obj));
break;
@ -911,7 +894,6 @@ VM.execute = function(ctx) {
var obj = stack.pop();
if (!obj) {
ctx.raiseExceptionAndYield("java/lang/NullPointerException");
break;
}
field.set(obj, val);
break;
@ -949,13 +931,10 @@ VM.execute = function(ctx) {
if (classInfo.tag)
classInfo = resolve(ctx, cp, op, idx);
var obj = stack[stack.length - 1];
if (obj) {
if (!obj.class.isAssignableTo(classInfo)) {
ctx.raiseExceptionAndYield("java/lang/ClassCastException",
obj.class.className + " is not assignable to " +
classInfo.className);
break;
}
if (obj && !obj.class.isAssignableTo(classInfo)) {
ctx.raiseExceptionAndYield("java/lang/ClassCastException",
obj.class.className + " is not assignable to " +
classInfo.className);
}
break;
case 0xc1: // instanceof
@ -971,7 +950,6 @@ VM.execute = function(ctx) {
var obj = stack.pop();
if (!obj) {
ctx.raiseExceptionAndYield("java/lang/NullPointerException");
break;
}
frame = throw_(obj, ctx);
stack = frame.stack;
@ -981,7 +959,6 @@ VM.execute = function(ctx) {
var obj = stack.pop();
if (!obj) {
ctx.raiseExceptionAndYield("java/lang/NullPointerException");
break;
}
ctx.monitorEnter(obj);
break;
@ -989,7 +966,6 @@ VM.execute = function(ctx) {
var obj = stack.pop();
if (!obj) {
ctx.raiseExceptionAndYield("java/lang/NullPointerException");
break;
}
ctx.monitorExit(obj);
break;
@ -1047,7 +1023,6 @@ VM.execute = function(ctx) {
var obj = stack[stack.length - methodInfo.consumes];
if (!obj) {
ctx.raiseExceptionAndYield("java/lang/NullPointerException");
break;
}
switch (op) {