/** * Calculate and return the private size of a method implementation. * * Calculated as: debug info size + instructions size + try-catch size * * @return size in bytes */ public int getSize() { int debugSize = getDebugInfo().getSize(); //set last offset just before bytecode instructions (after insns_size) int lastOffset = codeOffset + CodeItem.INSTRUCTION_START_OFFSET; //set code_item ending offset to the end of instructions list (insns_size * ushort) lastOffset += dexFile.readSmallUint(codeOffset + CodeItem.INSTRUCTION_COUNT_OFFSET) * 2; //read any exception handlers and move code_item offset to the end for (DexBackedTryBlock tryBlock: getTryBlocks()) { Iterator<? extends DexBackedExceptionHandler> tryHandlerIter = tryBlock.getExceptionHandlers().iterator(); while (tryHandlerIter.hasNext()) { tryHandlerIter.next(); } lastOffset = ((VariableSizeListIterator)tryHandlerIter).getReaderOffset(); } //method impl size = debug block size + code_item size return debugSize + (lastOffset - codeOffset); } }
/** * Calculate and return the private size of a method implementation. * * Calculated as: debug info size + instructions size + try-catch size * * @return size in bytes */ public int getSize() { int debugSize = getDebugInfo().getSize(); //set last offset just before bytecode instructions (after insns_size) int lastOffset = codeOffset + CodeItem.INSTRUCTION_START_OFFSET; //set code_item ending offset to the end of instructions list (insns_size * ushort) lastOffset += dexFile.readSmallUint(codeOffset + CodeItem.INSTRUCTION_COUNT_OFFSET) * 2; //read any exception handlers and move code_item offset to the end for (DexBackedTryBlock tryBlock: getTryBlocks()) { Iterator<? extends DexBackedExceptionHandler> tryHandlerIter = tryBlock.getExceptionHandlers().iterator(); while (tryHandlerIter.hasNext()) { tryHandlerIter.next(); } lastOffset = ((VariableSizeListIterator)tryHandlerIter).getReaderOffset(); } //method impl size = debug block size + code_item size return debugSize + (lastOffset - codeOffset); } }