Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get object from memory by hash code

Tags:

java

jvm

My question is relate to security level of JVM

How we can we get the object from memory by proving hash code?

Today i was thinking. I create an object of class A in an execution environment One. And get the hash code from here of that object.

Now in another execution environment i want to get back class A object by providing hash code.

I think it is possible. Because when I execute environment one. Again and again i get that JVM return the same hash code.

Means it first find the object in its cache. If it get the reference, it just return it.


So now back to question, we have to understand what data is copied when we write =.

  Object a=new Object();// here as we know reference of new object will be stored in refvar a.

Then what in actual is passes through.

If we get what data is passed by =(equal operator). We will able to get the object from memory.

Thanks

like image 472
Deepak Agrawal Avatar asked Mar 11 '14 10:03

Deepak Agrawal


2 Answers

How we can we get the object from memory by proving hash code?

You can't without access to the internals of the JVM. Even then you would need to scan every object in memory. You would also have the problem than multiple objects with the same hashCode. BTW: By default objects don't have a hashCode until you ask for one.

I think it is possible. Because when I execute environment one. Again and again i get that JVM return the same hash code.

This only works because you are recreating the exact conditions where the hashCode as generated, the slightest changes and you would get different hashCodes.

Means it first find the object in its cache. If it get the reference, it just return it.

By it you mean a cache you would need to maintain, no such cache exists in the JVM.

So now back to question, we have to understand what data is copied when we write =.

Object a=new Object();// here as we know reference of new object will be stored in refvar a.

Then what in actual is passes through.

The reference is passed, like you said. Nothing else.

like image 182
Peter Lawrey Avatar answered Nov 05 '22 23:11

Peter Lawrey


I guess it is irrelevant since hash code may or may not be related to memory address take a look documentation

in general each JVM has its own memory stack so whether you can access object from other JVM is depending on JVM implementation and I guess it is rarely possible.

like image 35
Vilen Avatar answered Nov 05 '22 21:11

Vilen