java - Null check emitted for 'this' access? -


when access own instance field via this reference (for example, object or int field private method), generated android dalvik bytecode contain iget bytecode instruction:

iget v2, p0, lcom/example/myapp/myclass;->status:i 

this same instruction emitted when access object's field (i.e. not via this pointer), doesn't seem distinguish between other objects , yourself. in bytecode, understandable, jit more.

checking android source code, don't see null check automatically eliminated jit such cases (i.e. when access this). eliminated in basic blocks already-null-checked dalvik registers, fine, (to me) seems eliminated this access (even if it's first instruction of basic block, or instruction, this cannot null).

what missing? security/runtime typesafety reasons? or overlook source code? why cannot vm (jit) handle this in distinguished way? (i understand native code can't, because this memory address else.)


edit: far can see, "already-null-checked" flags cleared each time basic block ends in dvm. i'm saying "already-null-checked" flag registers hold this pre-set 1 (and value not need cleared during transitions between basic blocks).

from bytecode's perspective, accessing fields on "this" object no different accessing them on other object - still have pass in register contains "this" reference. since there's no way guarantee register being passed in contain non-null value, still has perform nullness check, other object.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -