diff --git a/actors.ts b/actors.ts index 767f45a9..c58fbf4a 100644 --- a/actors.ts +++ b/actors.ts @@ -295,6 +295,15 @@ module J2ME { return CLASSES.getField(this, fieldKey); } + getClassInitLockObject(ctx: Context) { + if (!(this.className in ctx.runtime.classInitLockObjects)) { + ctx.runtime.classInitLockObjects[this.className] = { + classInfo: this + }; + } + return ctx.runtime.classInitLockObjects[this.className]; + } + toString() { return "[class " + this.className + "]"; } diff --git a/context.ts b/context.ts index 282e27f2..7ace88d6 100644 --- a/context.ts +++ b/context.ts @@ -155,7 +155,7 @@ module J2ME { 0xb1, // return ]) }); - return new Frame(syntheticMethod, [classInfo.getClassObject(this)], 0); + return new Frame(syntheticMethod, [classInfo.getClassInitLockObject(this)], 0); } pushClassInitFrame(classInfo: ClassInfo) { diff --git a/native.js b/native.js index 400d6a72..43cb19a3 100644 --- a/native.js +++ b/native.js @@ -254,7 +254,7 @@ Native.create("java/lang/Object.notifyAll.()V", function(ctx) { }); Native.create("java/lang/Class.invoke_clinit.()V", function(ctx) { - var classInfo = this.runtimeKlass.templateKlass.classInfo; + var classInfo = this.classInfo; var className = classInfo.className; var runtime = ctx.runtime; if (runtime.initialized[className] || runtime.pending[className]) @@ -263,7 +263,8 @@ Native.create("java/lang/Class.invoke_clinit.()V", function(ctx) { if (className === "com/sun/cldc/isolate/Isolate") { // The very first isolate is granted access to the isolate API. // ctx.runtime.setStatic(CLASSES.getField(classInfo, "S._API_access_ok.I"), 1); - CLASSES.getField(classInfo, "S._API_access_ok.I").set(this, 1); + var isolate = classInfo.getClassObject(ctx).classObject; + CLASSES.getField(classInfo, "S._API_access_ok.I").set(isolate, 1); } var clinit = CLASSES.getMethod(classInfo, "S..()V"); var frames = []; @@ -282,7 +283,7 @@ Native.create("java/lang/Class.invoke_clinit.()V", function(ctx) { }); Native.create("java/lang/Class.init9.()V", function(ctx) { - var classInfo = this.runtimeKlass.templateKlass.classInfo; + var classInfo = this.classInfo; var className = classInfo.className; var runtime = ctx.runtime; if (runtime.initialized[className]) diff --git a/runtime.ts b/runtime.ts index e7e0f855..93c8bd0d 100644 --- a/runtime.ts +++ b/runtime.ts @@ -129,6 +129,7 @@ module J2ME { pending: any; staticFields: any; classObjects: any; + classInitLockObjects: any; ctx: Context; isolate: com.sun.cldc.isolate.Isolate; @@ -148,6 +149,7 @@ module J2ME { this.staticFields = {}; this.classObjects = {}; this.ctx = null; + this.classInitLockObjects = {}; this._runtimeId = RuntimeTemplate._nextRuntimeId ++; this._nextHashCode = this._runtimeId << 24; }