Change handling of edge case.
Generally speaking, you can't create an instance of a class before
the class is initialized. When you're talking about java.lang.Class
itself, this doesn't apply. We were trying to sneak in a just-in-time
initialization, but the recent addition of SMP-mandated opcode rewrites
screwed things up a bit.
Happily, the creation of the java.lang.Class class object now happens
at a known time, which means we can explicitly initialize the class
at the right time (when it's far enough along to be able to execute
the class initializer, but before anything tries to use a virtual
method or instance field in java.lang.Class).
Also, changed a LOGE+abort to a simple assert. The test in question is
performed earlier during linking, so this doesn't merit more than an
assertion.
Bug 3045762.
Change-Id: Ifffb5083a3de108e1d91b3de7b75fd5e97705912
diff --git a/vm/oo/Class.c b/vm/oo/Class.c
index 8f55815..b7fbb59 100644
--- a/vm/oo/Class.c
+++ b/vm/oo/Class.c
@@ -1604,13 +1604,7 @@
assert(dvmIsClassLinked(clazz));
assert(gDvm.classJavaLangClass != NULL);
assert(clazz->obj.clazz == gDvm.classJavaLangClass);
- if (clazz != gDvm.classJavaLangObject) {
- if (clazz->super == NULL) {
- LOGE("Non-Object has no superclass (gDvm.classJavaLangObject=%p)\n",
- gDvm.classJavaLangObject);
- dvmAbort();
- }
- }
+ assert(clazz == gDvm.classJavaLangObject || clazz->super != NULL);
if (!dvmIsInterfaceClass(clazz)) {
//LOGI("class=%s vtableCount=%d, virtualMeth=%d\n",
// clazz->descriptor, clazz->vtableCount,
@@ -1618,21 +1612,6 @@
assert(clazz->vtableCount >= clazz->virtualMethodCount);
}
- /*
- * Normally class objects are initialized before we instantiate them,
- * but we can't do that with java.lang.Class (chicken, meet egg). We
- * do it explicitly here.
- *
- * The verifier could call here to find Class while verifying Class,
- * so we need to check for CLASS_VERIFYING as well as !initialized.
- */
- if (clazz == gDvm.classJavaLangClass && !dvmIsClassInitialized(clazz) &&
- !(clazz->status == CLASS_VERIFYING))
- {
- LOGV("+++ explicitly initializing %s\n", clazz->descriptor);
- dvmInitClass(clazz);
- }
-
bail:
if (profilerNotified)
dvmMethodTraceClassPrepEnd();