Merge commit 'c532ecc14508c543e93ce4ec01ec16f4c39ce202' into jitjit

Conflicts:
	vm.js
This commit is contained in:
Marco Castelluccio 2014-10-13 09:48:59 -07:00
Родитель 1a76a3aa53 c532ecc145
Коммит 0db57ce89a
1 изменённых файлов: 27 добавлений и 27 удалений

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

@ -27,44 +27,44 @@ function checkArrayAccess(ctx, refArray, idx) {
}
}
function resolve(ctx, cp, op, idx) {
function resolve(ctx, cp, idx, isStatic) {
var constant = cp[idx];
if (!constant.tag)
return constant;
switch(constant.tag) {
case TAGS.CONSTANT_Integer:
case 3: // TAGS.CONSTANT_Integer
constant = constant.integer;
break;
case TAGS.CONSTANT_Float:
case 4: // TAGS.CONSTANT_Float
constant = constant.float;
break;
case TAGS.CONSTANT_String:
case 8: // TAGS.CONSTANT_String
constant = ctx.newString(cp[constant.string_index].bytes);
break;
case TAGS.CONSTANT_Long:
case 5: // TAGS.CONSTANT_Long
constant = Long.fromBits(constant.lowBits, constant.highBits);
break;
case TAGS.CONSTANT_Double:
case 6: // TAGS.CONSTANT_Double
constant = constant.double;
break;
case TAGS.CONSTANT_Class:
case 7: // TAGS.CONSTANT_Class
constant = CLASSES.getClass(cp[constant.name_index].bytes);
break;
case TAGS.CONSTANT_Fieldref:
var classInfo = resolve(ctx, cp, op, constant.class_index);
case 9: // TAGS.CONSTANT_Fieldref
var classInfo = resolve(ctx, cp, constant.class_index, isStatic);
var fieldName = cp[cp[constant.name_and_type_index].name_index].bytes;
var signature = cp[cp[constant.name_and_type_index].signature_index].bytes;
constant = CLASSES.getField(classInfo, ((op === 0xb2 || op === 0xb3) ? "S" : "I") + "." + fieldName + "." + signature);
constant = CLASSES.getField(classInfo, (isStatic ? "S" : "I") + "." + fieldName + "." + signature);
if (!constant)
ctx.raiseExceptionAndYield("java/lang/RuntimeException",
classInfo.className + "." + fieldName + "." + signature + " not found");
break;
case TAGS.CONSTANT_Methodref:
case TAGS.CONSTANT_InterfaceMethodref:
var classInfo = resolve(ctx, cp, op, constant.class_index);
case 10: // TAGS.CONSTANT_Methodref
case 11: // TAGS.CONSTANT_InterfaceMethodref
var classInfo = resolve(ctx, cp, constant.class_index, isStatic);
var methodName = cp[cp[constant.name_and_type_index].name_index].bytes;
var signature = cp[cp[constant.name_and_type_index].signature_index].bytes;
constant = CLASSES.getMethod(classInfo, ((op === 0xb8) ? "S" : "I") + "." + methodName + "." + signature);
constant = CLASSES.getMethod(classInfo, (isStatic ? "S" : "I") + "." + methodName + "." + signature);
if (!constant)
ctx.raiseExceptionAndYield("java/lang/RuntimeException",
classInfo.className + "." + methodName + "." + signature + " not found");
@ -136,7 +136,7 @@ function throw_(ex, ctx) {
if (exception_table[i].catch_type === 0) {
handler_pc = exception_table[i].handler_pc;
} else {
var classInfo = resolve(ctx, cp, OPCODES.athrow, exception_table[i].catch_type);
var classInfo = resolve(ctx, cp, exception_table[i].catch_type);
if (ex.class.isAssignableTo(classInfo)) {
handler_pc = exception_table[i].handler_pc;
break;
@ -243,14 +243,14 @@ VM.execute = function(ctx) {
var idx = (op === 0x12) ? frame.read8() : frame.read16();
var constant = cp[idx];
if (constant.tag)
constant = resolve(ctx, cp, op, idx);
constant = resolve(ctx, cp, idx);
stack.push(constant);
break;
case 0x14: // ldc2_w
var idx = frame.read16();
var constant = cp[idx];
if (constant.tag)
constant = resolve(ctx, cp, op, idx);
constant = resolve(ctx, cp, idx);
stack.push2(constant);
break;
case 0x15: // iload
@ -845,7 +845,7 @@ VM.execute = function(ctx) {
var idx = frame.read16();
var classInfo = cp[idx];
if (classInfo.tag)
classInfo = resolve(ctx, cp, op, idx);
classInfo = resolve(ctx, cp, idx);
var size = stack.pop();
if (size < 0) {
ctx.raiseExceptionAndYield("java/lang/NegativeArraySizeException", size);
@ -860,7 +860,7 @@ VM.execute = function(ctx) {
var idx = frame.read16();
var classInfo = cp[idx];
if (classInfo.tag)
classInfo = resolve(ctx, cp, op, idx);
classInfo = resolve(ctx, cp, idx);
var dimensions = frame.read8();
var lengths = new Array(dimensions);
for (var i=0; i<dimensions; i++)
@ -878,7 +878,7 @@ VM.execute = function(ctx) {
var idx = frame.read16();
var field = cp[idx];
if (field.tag)
field = resolve(ctx, cp, op, idx);
field = resolve(ctx, cp, idx, false);
var obj = stack.pop();
if (!obj) {
ctx.raiseExceptionAndYield("java/lang/NullPointerException");
@ -889,7 +889,7 @@ VM.execute = function(ctx) {
var idx = frame.read16();
var field = cp[idx];
if (field.tag)
field = resolve(ctx, cp, op, idx);
field = resolve(ctx, cp, idx, false);
var val = stack.popType(field.signature);
var obj = stack.pop();
if (!obj) {
@ -901,7 +901,7 @@ VM.execute = function(ctx) {
var idx = frame.read16();
var field = cp[idx];
if (field.tag)
field = resolve(ctx, cp, op, idx);
field = resolve(ctx, cp, idx, true);
classInitCheck(ctx, frame, field.classInfo, frame.ip-3);
var value = ctx.runtime.getStatic(field);
if (typeof value === "undefined") {
@ -913,7 +913,7 @@ VM.execute = function(ctx) {
var idx = frame.read16();
var field = cp[idx];
if (field.tag)
field = resolve(ctx, cp, op, idx);
field = resolve(ctx, cp, idx, true);
classInitCheck(ctx, frame, field.classInfo, frame.ip-3);
ctx.runtime.setStatic(field, stack.popType(field.signature));
break;
@ -921,7 +921,7 @@ VM.execute = function(ctx) {
var idx = frame.read16();
var classInfo = cp[idx];
if (classInfo.tag)
classInfo = resolve(ctx, cp, op, idx);
classInfo = resolve(ctx, cp, idx);
classInitCheck(ctx, frame, classInfo, frame.ip-3);
stack.push(ctx.newObject(classInfo));
break;
@ -929,7 +929,7 @@ VM.execute = function(ctx) {
var idx = frame.read16();
var classInfo = cp[idx];
if (classInfo.tag)
classInfo = resolve(ctx, cp, op, idx);
classInfo = resolve(ctx, cp, idx);
var obj = stack[stack.length - 1];
if (obj && !obj.class.isAssignableTo(classInfo)) {
ctx.raiseExceptionAndYield("java/lang/ClassCastException",
@ -941,7 +941,7 @@ VM.execute = function(ctx) {
var idx = frame.read16();
var classInfo = cp[idx];
if (classInfo.tag)
classInfo = resolve(ctx, cp, op, idx);
classInfo = resolve(ctx, cp, idx);
var obj = stack.pop();
var result = !obj ? false : obj.class.isAssignableTo(classInfo);
stack.push(result ? 1 : 0);
@ -1015,7 +1015,7 @@ VM.execute = function(ctx) {
var isStatic = (op === 0xb8);
var methodInfo = cp[idx];
if (methodInfo.tag) {
methodInfo = resolve(ctx, cp, op, idx);
methodInfo = resolve(ctx, cp, idx, isStatic);
if (isStatic)
classInitCheck(ctx, frame, methodInfo.classInfo, startip);
}