Conflicts:
	classinfo.js
This commit is contained in:
Marco Castelluccio 2014-10-09 13:57:18 -07:00
Родитель ee0bcbcb3b 29e57f37dd
Коммит ecd5b1d9a9
6 изменённых файлов: 27 добавлений и 49 удалений

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

@ -174,9 +174,6 @@ Classes.prototype.getMethod = function(classInfo, methodKey) {
var methods = c.methods;
for (var i=0; i<methods.length; ++i) {
var method = methods[i];
if (!method.key) {
method.key = (method.isStatic ? "S" : "I") + "." + method.name + "." + method.signature;
}
if (method.key === methodKey) {
return classInfo.vmc[methodKey] = method;
}

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

@ -30,6 +30,10 @@ FieldInfo.prototype.toString = function() {
return "[field " + this.name + "]";
}
function missingNativeImpl(key, ctx, stack) {
console.error("Attempted to invoke missing native:", key);
}
function MethodInfo(m, classInfo, constantPool) {
this.classInfo = classInfo;
this.name = constantPool[m.name_index].bytes;
@ -55,6 +59,23 @@ function MethodInfo(m, classInfo, constantPool) {
Override.hasMethod(this) ? Override :
null);
this.key = (this.isStatic ? "S." : "I.") + this.name + "." + this.signature;
this.implKey = this.classInfo.className + "." + this.name + "." + this.signature;
if (this.isNative) {
if (this.implKey in Native) {
this.alternateImpl = Native[this.implKey];
} else {
// Some Native MethodInfos are constructed but never called;
// that's fine, unless we actually try to call them.
this.alternateImpl = missingNativeImpl.bind(null, this.implKey);
}
} else if (this.implKey in Override) {
this.alternateImpl = Override[this.implKey];
} else {
this.alternateImpl = null;
}
this.numCalled = 0;
this.compiled = null;
this.dontCompile = false;

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

@ -10,12 +10,8 @@ var Instrument = {
profiling: false,
profile: null,
getKey: function(methodInfo) {
return methodInfo.classInfo.className + "." + methodInfo.name + "." + methodInfo.signature;
},
callEnterHooks: function(methodInfo, caller, callee) {
var key = this.getKey(methodInfo);
var key = methodInfo.implKey;
if (Instrument.enter[key]) {
Instrument.enter[key](caller, callee);
}
@ -36,7 +32,7 @@ var Instrument = {
},
callExitHooks: function(methodInfo, caller, callee) {
var key = this.getKey(methodInfo);
var key = methodInfo.implKey;
if (this.profiling) {
var now = performance.now();
@ -101,16 +97,16 @@ var Instrument = {
this.profiling = false;
},
measure: function(Alt, ctx, methodInfo) {
measure: function(alternateImpl, ctx, methodInfo) {
var key = methodInfo.implKey;
if (this.profiling) {
var then = performance.now();
Alt.invoke(ctx, methodInfo);
var key = this.getKey(methodInfo);
alternateImpl.call(null, ctx, ctx.current().stack);
var methodProfileData = this.profile[key] || (this.profile[key] = { count: 0, cost: 0 });
methodProfileData.count++;
methodProfileData.cost += performance.now() - then;
} else {
Alt.invoke(ctx, methodInfo);
alternateImpl.call(null, ctx, ctx.current().stack);
}
},
};

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

@ -5,18 +5,6 @@
var Native = {};
Native.invoke = function(ctx, methodInfo) {
if (!methodInfo.native) {
var key = methodInfo.classInfo.className + "." + methodInfo.name + "." + methodInfo.signature;
methodInfo.native = Native[key];
if (!methodInfo.native) {
console.error("Missing native: " + key);
ctx.raiseExceptionAndYield("java/lang/RuntimeException", key + " not found");
}
}
methodInfo.native.call(null, ctx, ctx.current().stack);
}
Native["java/lang/System.arraycopy.(Ljava/lang/Object;ILjava/lang/Object;II)V"] = function(ctx, stack) {
var length = stack.pop(), dstOffset = stack.pop(), dst = stack.pop(), srcOffset = stack.pop(), src = stack.pop();
if (!src || !dst)

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

@ -5,26 +5,6 @@
var Override = {};
Override.getKey = function(methodInfo) {
return methodInfo.classInfo.className + "." + methodInfo.name + "." + methodInfo.signature;
}
Override.hasMethod = function(methodInfo) {
return ("override" in methodInfo || Override.getKey(methodInfo) in Override);
}
Override.invoke = function(ctx, methodInfo) {
if (!methodInfo.override) {
var key = Override.getKey(methodInfo);
methodInfo.override = Override[key];
if (!methodInfo.override) {
console.error("Missing override: " + key);
ctx.raiseExceptionAndYield("java/lang/RuntimeException", key + " not found");
}
}
methodInfo.override.call(null, ctx, ctx.current().stack);
}
Override["com/ibm/oti/connection/file/Connection.decode.(Ljava/lang/String;)Ljava/lang/String;"] = function(ctx, stack) {
var string = util.fromJavaString(stack.pop());
stack.push(ctx.newString(decodeURIComponent(string)));

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

@ -1056,10 +1056,6 @@ VM.execute = function(ctx) {
case OPCODES.invokevirtual:
case OPCODES.invokeinterface:
if (methodInfo.classInfo != obj.class) {
if (!methodInfo.key) {
methodInfo.key = "I." + methodInfo.name + "." + methodInfo.signature;
}
// Check if the method is already in the virtual method cache
if (obj.class.vmc[methodInfo.key]) {
methodInfo = obj.class.vmc[methodInfo.key];