add ClassTest.java and hashCode()

This commit is contained in:
Andreas Gal 2014-07-26 18:47:38 -07:00
Родитель bde88bd000
Коммит 2a08d3b8ea
1 изменённых файлов: 15 добавлений и 0 удалений

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

@ -9,6 +9,8 @@ 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.log(key);
}
methodInfo.native.call(null, ctx, ctx.current().stack);
}
@ -94,6 +96,19 @@ Native["java/lang/Object.getClass.()Ljava/lang/Class;"] = function(ctx, stack) {
stack.push(stack.pop().class.getClassObject());
}
Native["java/lang/Object.hashCode.()I"] = (function() {
var gen = 0;
return function(ctx, stack) {
var obj = stack.pop();
var hashCode = obj.hashCode;
if (hashCode) {
hashCode = obj.hashCode = gen;
gen = (gen+1) & 0x7fffffff;
}
stack.push(hashCode);
};
})();
Native["java/lang/Class.invoke_clinit.()V"] = function(ctx, stack) {
var classInfo = stack.pop().vmClass;
var clinit = CLASSES.getMethod(classInfo, "<clinit>", "()V", true);