diff options
author | Mark Wielaard <mark@gcc.gnu.org> | 2006-05-18 17:29:21 +0000 |
---|---|---|
committer | Mark Wielaard <mark@gcc.gnu.org> | 2006-05-18 17:29:21 +0000 |
commit | 4f9533c7722fa07511a94d005227961f4a4dec23 (patch) | |
tree | 9f9c470de62ee62fba1331a396450d728d2b1fad /libjava/classpath/java/rmi/dgc/VMID.java | |
parent | eaec4980e139903ae9b274d1abcf3a13946603a8 (diff) | |
download | gcc-4f9533c7722fa07511a94d005227961f4a4dec23.zip gcc-4f9533c7722fa07511a94d005227961f4a4dec23.tar.gz gcc-4f9533c7722fa07511a94d005227961f4a4dec23.tar.bz2 |
Imported GNU Classpath 0.90
Imported GNU Classpath 0.90
* scripts/makemake.tcl: LocaleData.java moved to gnu/java/locale.
* sources.am: Regenerated.
* gcj/javaprims.h: Regenerated.
* Makefile.in: Regenerated.
* gcj/Makefile.in: Regenerated.
* include/Makefile.in: Regenerated.
* testsuite/Makefile.in: Regenerated.
* gnu/java/lang/VMInstrumentationImpl.java: New override.
* gnu/java/net/local/LocalSocketImpl.java: Likewise.
* gnu/classpath/jdwp/VMMethod.java: Likewise.
* gnu/classpath/jdwp/VMVirtualMachine.java: Update to latest
interface.
* java/lang/Thread.java: Add UncaughtExceptionHandler.
* java/lang/reflect/Method.java: Implements GenericDeclaration and
isSynthetic(),
* java/lang/reflect/Field.java: Likewise.
* java/lang/reflect/Constructor.java
* java/lang/Class.java: Implements Type, GenericDeclaration,
getSimpleName() and getEnclosing*() methods.
* java/lang/Class.h: Add new public methods.
* java/lang/Math.java: Add signum(), ulp() and log10().
* java/lang/natMath.cc (log10): New function.
* java/security/VMSecureRandom.java: New override.
* java/util/logging/Logger.java: Updated to latest classpath
version.
* java/util/logging/LogManager.java: New override.
From-SVN: r113887
Diffstat (limited to 'libjava/classpath/java/rmi/dgc/VMID.java')
-rw-r--r-- | libjava/classpath/java/rmi/dgc/VMID.java | 139 |
1 files changed, 95 insertions, 44 deletions
diff --git a/libjava/classpath/java/rmi/dgc/VMID.java b/libjava/classpath/java/rmi/dgc/VMID.java index f960d9c..dc989c2 100644 --- a/libjava/classpath/java/rmi/dgc/VMID.java +++ b/libjava/classpath/java/rmi/dgc/VMID.java @@ -1,5 +1,5 @@ -/* VMID.java - Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc. +/* VMID.java -- The object ID, unique between all virtual machines. + Copyright (c) 1996, 1997, 1998, 1999, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -41,37 +41,72 @@ import java.io.Serializable; import java.net.InetAddress; import java.net.UnknownHostException; import java.rmi.server.UID; - +import java.util.Arrays; + +/** + * An identifier that is unique accross the all virtual machines. This class is + * used by distributed garbage collector to identify the virtual machine of + * the client, but may also be used in various other cases, when such identifier + * is required. This class separately stores and transfers the host IP + * address, but will try to do its best also for the case if it failed to + * determine it. The alternative algorithms are used in {@link UID} that is + * part of this class. The VMID's, created on the same host, but in the two + * separately (parallely) running virtual machines are different. + */ public final class VMID implements Serializable { + /** + * Use SVUID for interoperability. + */ static final long serialVersionUID = -538642295484486218L; - static final boolean areWeUnique; + /** + * If true, the IP of this host can ve reliably determined. + */ + static boolean areWeUnique; + /** + * The IP address of the local host. + */ static byte[] localAddr; + /** + * The IP address of the local host. + */ private byte[] addr; + /** + * The cached hash code. + */ + transient int hash; + + /** + * The UID of this VMID. + */ private UID uid; static - { - byte[] addr; - boolean awu = true; - try { - addr = InetAddress.getLocalHost().getAddress(); - if (addr[0] == 127 && addr[1] == 0 && addr[2] == 0 && addr[3] == 1) { - awu = false; - } - } - catch (UnknownHostException _) { - addr = new byte[]{ 127, 0, 0, 1 }; - awu = false; + { + // This "local host" value usually indicates that the local + // IP address cannot be reliably determined. + byte[] localHost = new byte[] { 127, 0, 0, 1 }; + + try + { + localAddr = InetAddress.getLocalHost().getAddress(); + areWeUnique = !Arrays.equals(localHost, localAddr); + } + catch (UnknownHostException uhex) + { + localAddr = localHost; + areWeUnique = false; + } } - localAddr = addr; - areWeUnique = awu; - } - + + /** + * Create the new VMID. All VMID's are unique accross tha all virtual + * machines. + */ public VMID() { addr = localAddr; @@ -79,42 +114,58 @@ public final class VMID implements Serializable } /** - * @deprecated + * Return true if it is possible to get the accurate address of this host. + * If false is returned, the created VMID's are less reliable, but the + * starting time and possibly the memory allocation are also taken into + * consideration in the incorporated UID. Hence the VMID's, created on the + * different virtual machines, still should be different. + * + * @deprecated VMID's are more or less always reliable. + * + * @return false if the local host ip address is 127.0.0.1 or unknown, + * true otherwise. */ public static boolean isUnique () { return areWeUnique; } - + + /** + * Get the hash code of this VMID. + */ public int hashCode () { - return super.hashCode(); - } - - public boolean equals (Object obj) - { - if (!(obj instanceof VMID)) - { - return false; - } - - VMID other = (VMID) obj; - if (addr.length != other.addr.length) + if (hash==0) { - return false; + for (int i = 0; i < localAddr.length; i++) + hash += addr[i]; + hash = hash ^ uid.hashCode(); } - - for (int i = addr.length - 1; i >= 0; i--) + return hash; + } + + /** + * Returns true if the passed parameter is also VMID and it is equal to this + * VMID. The VMID should only be equal to itself (also if the passed value is + * another instance, cloned by serialization). + */ + public boolean equals(Object obj) + { + if (obj instanceof VMID) { - if (addr[i] != other.addr[i]) - { - return false; - } + VMID other = (VMID) obj; + + // The UID's are compared faster than arrays. + return uid.equals(other.uid) && Arrays.equals(addr, other.addr); } - - return uid.equals(other.uid); - } + else + return false; + } + + /** + * Get the string representation of this VMID. + */ public String toString () { StringBuffer buf = new StringBuffer ("[VMID: "); |