diff --git a/context.ts b/context.ts index 14ad2af3..5b4df1c5 100644 --- a/context.ts +++ b/context.ts @@ -472,10 +472,32 @@ module J2ME { } pushClassInitFrame(classInfo: ClassInfo) { - if (this.runtime.initialized[classInfo.className]) { + if (this.runtime.initialized[classInfo.className] || + this.runtime.pending[classInfo.className]) { return; } + var needsInitialization = true; + if (!classInfo.staticInitializer) { + needsInitialization = false; + // Special case Isolate. + if (classInfo.className === "com/sun/cldc/isolate/Isolate") { + needsInitialization = true; + } + var superClass = classInfo.superClass; + while (superClass) { + if (!this.runtime.initialized[superClass.className] && + superClass.staticInitializer) { + needsInitialization = true; + break; + } + superClass = superClass.superClass; + } + } linkKlass(classInfo); + if (!needsInitialization) { + this.runtime.initialized[classInfo.className] = true; + return; + } var classInitFrame = this.getClassInitFrame(classInfo); this.executeFrames([classInitFrame]); } diff --git a/runtime.ts b/runtime.ts index 0668cf93..5c4e8cad 100644 --- a/runtime.ts +++ b/runtime.ts @@ -1691,7 +1691,7 @@ module J2ME { } export function classInitCheck(classInfo: ClassInfo, pc: number) { - if (classInfo.isArrayClass || $.initialized[classInfo.className]) { + if (classInfo.isArrayClass) { return; } $.ctx.pushClassInitFrame(classInfo);