1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
| static ClassObject* loadClassFromDex0(DvmDex* pDvmDex, const DexClassDef* pClassDef, const DexClassDataHeader* pHeader, const u1* pEncodedData, Object* classLoader) { ClassObject* newClass = NULL; const DexFile* pDexFile; const char* descriptor; int i;
pDexFile = pDvmDex->pDexFile; descriptor = dexGetClassDescriptor(pDexFile, pClassDef);
if (...){ } else { size_t size = classObjectSize(pHeader->staticFieldsSize); newClass = (ClassObject*) dvmMalloc(size, ALLOC_NON_MOVING); } if (newClass == NULL) return NULL;
DVM_OBJECT_INIT(newClass, gDvm.classJavaLangClass); dvmSetClassSerialNumber(newClass); newClass->descriptor = descriptor; SET_CLASS_FLAG(newClass, pClassDef->accessFlags); dvmSetFieldObject((Object *)newClass, OFFSETOF_MEMBER(ClassObject, classLoader), (Object *)classLoader); newClass->pDvmDex = pDvmDex; newClass->primitiveType = PRIM_NOT; newClass->status = CLASS_IDX;
newClass->super = (ClassObject*) pClassDef->superclassIdx;
const DexTypeList* pInterfacesList; pInterfacesList = dexGetInterfacesList(pDexFile, pClassDef); if (pInterfacesList != NULL) { newClass->interfaceCount = pInterfacesList->size; newClass->interfaces = (ClassObject**) dvmLinearAlloc(classLoader, newClass->interfaceCount * sizeof(ClassObject*));
for (i = 0; i < newClass->interfaceCount; i++) { const DexTypeItem* pType = dexGetTypeItem(pInterfacesList, i); newClass->interfaces[i] = (ClassObject*)(u4) pType->typeIdx; } dvmLinearReadOnly(classLoader, newClass->interfaces); } if (pHeader->staticFieldsSize != 0) { int count = (int) pHeader->staticFieldsSize; u4 lastIndex = 0; DexField field;
newClass->sfieldCount = count; for (i = 0; i < count; i++) { dexReadClassDataField(&pEncodedData, &field, &lastIndex); loadSFieldFromDex(newClass, &field, &newClass->sfields[i]); } }
if (pHeader->instanceFieldsSize != 0) { int count = (int) pHeader->instanceFieldsSize; u4 lastIndex = 0; DexField field;
newClass->ifieldCount = count; newClass->ifields = (InstField*) dvmLinearAlloc(classLoader, count * sizeof(InstField)); for (i = 0; i < count; i++) { dexReadClassDataField(&pEncodedData, &field, &lastIndex); loadIFieldFromDex(newClass, &field, &newClass->ifields[i]); } dvmLinearReadOnly(classLoader, newClass->ifields); }
u4 classDefIdx = dexGetIndexForClassDef(pDexFile, pClassDef); const void* classMapData; u4 numMethods;
if (gDvm.preciseGc) { classMapData = dvmRegisterMapGetClassData(pDexFile, classDefIdx, &numMethods);
if (classMapData != NULL && pHeader->directMethodsSize + pHeader->virtualMethodsSize != numMethods) { ALOGE("ERROR: in %s, direct=%d virtual=%d, maps have %d", newClass->descriptor, pHeader->directMethodsSize, pHeader->virtualMethodsSize, numMethods); assert(false); classMapData = NULL; } } else { classMapData = NULL; }
if (pHeader->directMethodsSize != 0) { int count = (int) pHeader->directMethodsSize; u4 lastIndex = 0; DexMethod method;
newClass->directMethodCount = count; newClass->directMethods = (Method*) dvmLinearAlloc(classLoader, count * sizeof(Method)); for (i = 0; i < count; i++) { dexReadClassDataMethod(&pEncodedData, &method, &lastIndex); loadMethodFromDex(newClass, &method, &newClass->directMethods[i]); if (classMapData != NULL) { const RegisterMap* pMap = dvmRegisterMapGetNext(&classMapData); if (dvmRegisterMapGetFormat(pMap) != kRegMapFormatNone) { newClass->directMethods[i].registerMap = pMap; assert((newClass->directMethods[i].registersSize+7) / 8 == newClass->directMethods[i].registerMap->regWidth); } } } dvmLinearReadOnly(classLoader, newClass->directMethods); }
if (pHeader->virtualMethodsSize != 0) { int count = (int) pHeader->virtualMethodsSize; u4 lastIndex = 0; DexMethod method;
newClass->virtualMethodCount = count; newClass->virtualMethods = (Method*) dvmLinearAlloc(classLoader, count * sizeof(Method)); for (i = 0; i < count; i++) { dexReadClassDataMethod(&pEncodedData, &method, &lastIndex); loadMethodFromDex(newClass, &method, &newClass->virtualMethods[i]); if (classMapData != NULL) { const RegisterMap* pMap = dvmRegisterMapGetNext(&classMapData); if (dvmRegisterMapGetFormat(pMap) != kRegMapFormatNone) { newClass->virtualMethods[i].registerMap = pMap; assert((newClass->virtualMethods[i].registersSize+7) / 8 == newClass->virtualMethods[i].registerMap->regWidth); } } } dvmLinearReadOnly(classLoader, newClass->virtualMethods); }
newClass->sourceFile = dexGetSourceFile(pDexFile, pClassDef);
return newClass; }
|