1 HANDLE_OPCODE(OP_NEW_ARRAY /*vA, vB, class@CCCC*/) 2 { 3 ClassObject* arrayClass; 4 ArrayObject* newArray; 5 s4 length; 6 7 EXPORT_PC(); 8 9 vdst = INST_A(inst); 10 vsrc1 = INST_B(inst); /* length reg */ 11 ref = FETCH(1); 12 ILOGV("|new-array v%d,v%d,class@0x%04x (%d elements)", 13 vdst, vsrc1, ref, (s4) GET_REGISTER(vsrc1)); 14 length = (s4) GET_REGISTER(vsrc1); 15 if (length < 0) { 16 dvmThrowException("Ljava/lang/NegativeArraySizeException;", NULL); 17 GOTO_exceptionThrown(); 18 } 19 arrayClass = dvmDexGetResolvedClass(methodClassDex, ref); 20 if (arrayClass == NULL) { 21 arrayClass = dvmResolveClass(curMethod->clazz, ref, false); 22 if (arrayClass == NULL) 23 GOTO_exceptionThrown(); 24 } 25 /* verifier guarantees this is an array class */ 26 assert(dvmIsArrayClass(arrayClass)); 27 assert(dvmIsClassInitialized(arrayClass)); 28 29 newArray = dvmAllocArrayByClass(arrayClass, length, ALLOC_DONT_TRACK); 30 if (newArray == NULL) 31 GOTO_exceptionThrown(); 32 SET_REGISTER(vdst, (u4) newArray); 33 } 34 FINISH(2); 35 OP_END 36 37