Is there hash code / Heap address for primitive types in Java?

If you have local variables on the stack, they have variable numbers. These numbers are local to the stack frame, in which the method is executing, and two variables are same if they have the same number.

What i've got is java bytecode . I don't have be or c and I'm not aware of them . I only have the value of a on the stack If you have local variables on the stack, they have variable numbers.

These numbers are local to the stack frame, in which the method is executing, and two variables are same if they have the same number. If you have the two primitive values in your evaluation (argument/operand/result) stack, they are same (in a similar sense as for variables) if they exist at the same time at the same stack index. In your example, you see that the two GETFIELD manipulate/Test.

C : I instructions operate each on the current value on the stack (which is put there by ALOAD 1 or ALOAD 2). This current value is the object to which your variable belongs, so you could insert there your counting code for this object (do a DUP first).

Thats more what I was looking for . Do you know how can I get that variable number using ASM bytecode mechanism? – RanZilber Feb 25 at 19:50 I never used ASM, only read the VM spec, and there any command which accesses local variables does so by index.

– PaÅ­lo Ebermann Feb 25 at 20:04.

Primitives do not have identities. They are compared by value, not by reference. The address in memory of a primitive in a local variable is likely to be in a register or on the stack, and the location of a primitive member of an array or object is related to the heap address of its parent.

Java does not provide any standardized memory access facilities, and alternatives, like System. IdentityHashCode do not extend to them. Calling System.

IdentityHashCode with a primitive will cause a spurious boxing to occur which will give nonsensical results. If you really need to know the location of a primitive member, you can write C code with JNI bindings to get a handle to a java object, get a pointer, and convert that to a java integral type of the right width, but your best bet is to probably find some other way to do what you're trying to do. One other option is to use the existing java debugger hooks : download.oracle.com/javase/6/docs/techno....

It would be passed by reference. All the C code would tell you is the address of the argument to the JNI call. – DJClayworth Feb 25 at 19:38 samuel - thanks for the effort but that realy not what I'm looking for.

Look at the example I added in the edit – RanZilber Feb 25 at 19:41.

I'm not sure I understand the question, you want to know if b. A is infact the same variable as c. A?

In your case, b. A will be the same as c. A if b==c.

If you declare a static, it will be shared between all instances of foo.

That was working if I had the orignal code. What i've got is java bytecode . I don't have be or c and I'm not aware of them .

I only have the value of a on the stack – RanZilber Feb 25 at 19:33 I've added another example to my it more clear – RanZilber Feb 25 at 19:47 if you do x = b. A, then the value of b. A is copied to x.

X is stored on the stack or in a register, depending on optimization, and there is no reference to the original object. – Rolf Rander Feb 26 at 12:59.

When you asked about memory addresses, and got the identityhashCode answer, the key phrase was "some approximation". There is no guarantee that this value will be the memory address, and even the most aggressive assertion is that it is a mapping from the address to an integer. You absolutely cannot reliably determine the address of an object in Java, and shouldn't even think about trying with primitives.

For one thing there is no guarantee that the compiler won't move them. There isn't even a guarantee that the variable ever has an address. If you want to determine whether two objects are the same, you can use "==".

The question doesn't even make sense with primitives, and you shouldn't be doing it.

Agian . I Wish I could use '=='. My problem is that I'm working and writing with java bytecode here .

I cant think of any way to '==' in bytecode , mostly because I don't have the Object that cotains these attributes. Look at my example , I hope it will make my question more clear. – RanZilber Feb 25 at 19:44.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions