is there hash code / Heap address for primitive types in Java? -
i trying find approximization address on heap , , guys gave me function system.identityhashcode(object)
.
the problem - function doesn't fit primitive types. i'll explain why.
i'm given input java compiled program - class file. goal plot graphs contain information variable access between time. have no idea of how code looks in advance , , tactic instrumentation of own bytecode every load , store instruction. i'm using asm java bytecode instrumentation.
therefore, can't like:
identityhashcode(integer.valueof(...))
because have no indication whether type int, double, long, etc.
i want able determine between different instances of same class:
for example :
class foo { int a; } foo b; foo c; b.a++; c.a++;
but when comes bytecode , there no relation between name "b" / "c" , attribute a. "see" is incremented. both regarded ! if object a
have used system.identityhashcode() distinguish between them. can't.
to make myself clear, @ following example:
package manipulate; public class test { int c; public static void main(string[] args) { test a=new test(); test b=new test(); a.c++; b.c++; } }
which translated (main function) following bytecode:
l0 linenumber 7 l0 new manipulate/test dup invokespecial manipulate/test.<init>()v astore 1 l1 linenumber 8 l1 new manipulate/test dup invokespecial manipulate/test.<init>()v astore 2 l2 linenumber 9 l2 aload 1 dup getfield manipulate/test.c : iconst_1 iadd putfield manipulate/test.c : l3 linenumber 10 l3 aload 2 dup getfield manipulate/test.c : iconst_1 iadd putfield manipulate/test.c : l4 linenumber 11 l4 return
and can see, i've got on stack value of integer c. therefore, given code, can't determine between these 2 c's!
what i've got java bytecode . dont have b or c , i'm not aware of them . have value of on stack
if have local variables on stack, have variable numbers. these numbers local stack frame, in method executing, , 2 variables same if have same number.
if have 2 primitive values in evaluation (argument/operand/result) stack, same (in similar sense variables) if exist @ same time @ same stack index.
in example, see 2 getfield manipulate/test.c : i
instructions operate each on current value on stack (which put there aload 1
or aload 2
). current value object variable belongs, insert there counting code object (do dup first).
Comments
Post a Comment