2013年9月10日星期二

How to get the memory address where the object JAVA

How to get to the object through the object ID stored in the memory address ? Thank you !
------ Solution ---------------------------------------- ----
get less memory address. java access to memory addresses not practical significance.
------ For reference only -------------------------------------- -
JAVA memory address of an object can not seem to get ...
JAVA memory can not operate
To address why ?
Each object has a unique identifier within the ( pseudo virtual machine address )
------ For reference only ------------------ ---------------------
this for less than
------ For reference only --------- ------------------------------
JVM is not going to let programmers know the memory address where the object , in order to secure bar , JAVA after all, not assembly ah. But can make use of other tools , such as OLLYDBG there Cheat Engine, used more is both a
------ For reference only ------------- --------------------------
direct object hashcode (), because to some extent hashcode is marked objects memory address.
------ For reference only -------------------------------------- -
hash value
------ For reference only ------------------------------- --------
+1
------ For reference only ------------------------- --------------
definitely get the java program within
------ For reference only ------------- --------------------------


-1

hashCode and addresses only have a certain relationship , but not equal to the address !
------ For reference only ------------------------------------ ---
HashCode not a memory address is calculated according to the arrangement of a value equivalent to the object ID , but not the memory address , we must pay attention to this misunderstanding . Now I use simple code to prove
import java.util.ArrayList;
import java.util.List;

public class Prove
{
public static void main(String[] args)
{
List<Integer> list = new ArrayList<Integer>();
for (int i = 0; i < 3000; i++)
{
Prove p = new Prove();
if (!list.contains(p.hashCode()))
list.add(p.hashCode());
}
System.out.println(list.size());
}
}

I generated 3000 Prove objects should newly allocated 3000 memory address , but only the last 2998个hashCode
------ For reference only ------------------- --------------------
java get the bottom of things , it seems to be with the other programs it
------ For reference only - -------------------------------------
java memory can not be operated
only hashcode and memory address unrelated
------ For reference only ---------------------------- -----------
I now want to do a thing is: to understand the principles of the JVM mapping table , looking through the object to the object ID value stored in memory physical address. Thank you !
------ For reference only -------------------------------------- -
java can not directly access the memory, so you do not get the memory address of an object , and even if you got no use
------ For reference only --------- ------------------------------
I want to do one thing , to find out the logic of the object with the object ID stored in memory the relationship between the physical address , that is the memory map table ( if possible present) What is the principle ?
------ For reference only -------------------------------------- -
java reverse engineering


-------------------------------
java novice school QQ group 144648357

------ For reference only ---------------------------------- -----
System.out.println (objName);
------ For reference only --------------------- ------------------
object logical ID and physical address what relationship exists between you ?
------ For reference only -------------------------------------- -


What is "Object logical ID"?
------ For reference only -------------------------------------- -
get less memory address. java access to memory addresses not practical significance.
------ For reference only -------------------------------------- -
System.out.println ( class object ) Is this okay ?
This output is not that exactly address codes do ?
------ For reference only -------------------------------------- -
java advantage is not concerned about memory management and other complex content .
JAVA to get the memory address is not necessary, because without some memory -related operations


------ For reference only ---------------------------------- -----

solving
------ For reference only ------------------------- --------------



System.out.println ( object )

output of such a statement is not the address of the object , although it looks like . In fact, this statement is equivalent to:
System.out.println ( objects . toString ());

Here's toString () method in the base class for all classes defined in Object , its source code is as follows:
public String toString () {
return getClass (). getName () + "@" + Integer.toHexString (hashCode ());
}

That is, if a class does not override Object.toString () method, then get a print statement would be : class name + "@ " + hexadecimal representation of the object hash

------ For reference only ---------------------------------- -----
hash?
------ For reference only -------------------------------------- -
you want to do ?
------ For reference only -------------------------- -------------
indeed get less , and hashCode with memory addresses are not linked to
------ For reference only ------ ---------------------------------

very good
---- - For reference only ---------------------------------------
; String a = new String ("abc");
String b = new String ("abc");
System.out.println (a == b); / / false
System.out.println (a.equals (b)); / / true
System.out.println (a.hashCode () == b.hashCode ()); / / true
a and b, the memory address must be different , but it has the same hashcode

------ For reference only ---------------------------------- -----
jdk Description:
String 's hashCode function . Of course, different objects have different hashCode function, if override the Object class hashCode words.
hashCode
public int hashCode()Returns a hash code for this string. The hash code for a String object is computed as
s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
using int arithmetic, where s[i] is the ith character of the string, n is the length of the string, and ^ indicates exponentiation. (The hash value of the empty string is zero.)

Overrides:
hashCode in class Object
Returns:
a hash code value for this object.
See Also:
Object.equals(java.lang.Object), System.identityHashCode(java.lang.Object)

hashCode value related with the memory address , but when there is a conflict .
looks like a jmap after jhat can see the address , is less clear.

没有评论:

发表评论