optimization - Redundant opcodes in Android dex -
i'm looking android performance issues @ moment , noticing sub-optimal patterns in dex code. i'm wondering if knows if expected, , rationale behind might be.
for example, consider following java code:
m_testfield += i; dosomething(m_testfield);
when built , run through baksmali looks following:
iget v1, p0, lcom/example/mainactivity$fieldtest;->m_testfield:i add-int/2addr v1, v0 iput v1, p0, lcom/example/mainactivity$fieldtest;->m_testfield:i iget v1, p0, lcom/example/mainactivity$fieldtest;->m_testfield:i invoke-direct {p0, v1}, lcom/example/mainactivity$fieldtest;->dosomething(i)v
the part that's concerning me iget opcode read value of instance field register v1. same field written same v1 register in preceding opcode, opcode appear redundant.
the thing can think of done make more thread-safe. surely should programmer's responsibility (by using sync blocks) instead of compiler's responsibility. although i'm not 100% certain, think above behaviour quite different c/c++ compilers do.
i should same dex produced when proguard used. should mention i'm using latest android tools , late model jdk.
every access field independent. behavior describe, need add local variable:
int local = m_testfield; // iget local = local + i; m_testfield = local; // iput dosomething(local);
that said, combination of interpreter, just-in-time compiler , ahead-of-time compiler may end making these optimizations @ runtime anyway.
Comments
Post a Comment