summaryrefslogtreecommitdiff
path: root/gnu/classpath/jdwp/id
diff options
context:
space:
mode:
authorKeith Seitz <keiths@redhat.com>2005-08-20 19:10:20 +0000
committerKeith Seitz <keiths@redhat.com>2005-08-20 19:10:20 +0000
commitc57c525cf50b37d401a193f3f4af1e69774fa90c (patch)
treeb4aeaa3a0f25a00720a5b22f94219892779fc1bd /gnu/classpath/jdwp/id
parent30782c610357d719c14e6b719154f90c235de9e8 (diff)
downloadclasspath-c57c525cf50b37d401a193f3f4af1e69774fa90c.tar.gz
* gnu/classpath/jdwp/id/ClassLoaderId.java (getClassLoader): New method.
* gnu/classpath/jdwp/id/ClassObjectId.java (getClassObject): New method. * gnu/classpath/jdwp/id/JdwpId.java (getReference): New method. (setReference): New method. * gnu/classpath/jdwp/id/ObjectId.java (getObject): New method. * gnu/classpath/jdwp/id/ReferenceTypeId.java (getType): New method. * gnu/classpath/jdwp/id/StringId.java (getString): New method. * gnu/classpath/jdwp/id/ThreadGroupId.java (getThreadGroup): New method. * gnu/classpath/jdwp/id/ThreadId.java (getThread): New method. * gnu/classpath/jdwp/id/ObjectId.java (setId): New method. (disableCollection): New method. (enableCollection): New method. * gnu/classpath/jdwp/id/JdwpId.java (equals): Remove test for class equality. (setId): Make public.
Diffstat (limited to 'gnu/classpath/jdwp/id')
-rw-r--r--gnu/classpath/jdwp/id/ClassLoaderId.java18
-rw-r--r--gnu/classpath/jdwp/id/ClassObjectId.java18
-rw-r--r--gnu/classpath/jdwp/id/JdwpId.java34
-rw-r--r--gnu/classpath/jdwp/id/ObjectId.java42
-rw-r--r--gnu/classpath/jdwp/id/ReferenceTypeId.java18
-rw-r--r--gnu/classpath/jdwp/id/StringId.java18
-rw-r--r--gnu/classpath/jdwp/id/ThreadGroupId.java18
-rw-r--r--gnu/classpath/jdwp/id/ThreadId.java21
8 files changed, 181 insertions, 6 deletions
diff --git a/gnu/classpath/jdwp/id/ClassLoaderId.java b/gnu/classpath/jdwp/id/ClassLoaderId.java
index 133872566..37c4c3655 100644
--- a/gnu/classpath/jdwp/id/ClassLoaderId.java
+++ b/gnu/classpath/jdwp/id/ClassLoaderId.java
@@ -40,6 +40,7 @@ exception statement from your version. */
package gnu.classpath.jdwp.id;
import gnu.classpath.jdwp.JdwpConstants;
+import gnu.classpath.jdwp.exception.InvalidClassLoaderException;
/**
* A class which represents a JDWP thread id
@@ -61,4 +62,21 @@ public class ClassLoaderId
{
super (JdwpConstants.Tag.CLASS_LOADER);
}
+
+ /**
+ * Gets the ClassLoader represented by this ID
+ *
+ * @throws InvalidClassLoaderException if ClassLoader is garbage collected,
+ * or otherwise invalid
+ */
+ public ClassLoader getClassLoader ()
+ throws InvalidClassLoaderException
+ {
+ ClassLoader cl = (ClassLoader) _reference.get ();
+
+ if (cl == null)
+ throw new InvalidClassLoaderException (getId ());
+
+ return cl;
+ }
}
diff --git a/gnu/classpath/jdwp/id/ClassObjectId.java b/gnu/classpath/jdwp/id/ClassObjectId.java
index e5559ce10..3e1642212 100644
--- a/gnu/classpath/jdwp/id/ClassObjectId.java
+++ b/gnu/classpath/jdwp/id/ClassObjectId.java
@@ -40,6 +40,7 @@ exception statement from your version. */
package gnu.classpath.jdwp.id;
import gnu.classpath.jdwp.JdwpConstants;
+import gnu.classpath.jdwp.exception.InvalidClassException;
/**
* A class which represents a JDWP class object id
@@ -61,4 +62,21 @@ public class ClassObjectId
{
super (JdwpConstants.Tag.CLASS_OBJECT);
}
+
+ /**
+ * Gets the Class object represented by this ID
+ *
+ * @throws InvalidClassException if Class is garbage collected,
+ * or otherwise invalid
+ */
+ public Class getClassObject ()
+ throws InvalidClassException
+ {
+ Class cl = (Class) _reference.get ();
+
+ if (cl == null)
+ throw new InvalidClassException (getId ());
+
+ return cl;
+ }
}
diff --git a/gnu/classpath/jdwp/id/JdwpId.java b/gnu/classpath/jdwp/id/JdwpId.java
index 37f82e208..7f610e353 100644
--- a/gnu/classpath/jdwp/id/JdwpId.java
+++ b/gnu/classpath/jdwp/id/JdwpId.java
@@ -41,6 +41,7 @@ package gnu.classpath.jdwp.id;
import java.io.DataOutputStream;
import java.io.IOException;
+import java.lang.ref.SoftReference;
/**
* A baseclass for all object types reported to the debugger
@@ -62,6 +63,11 @@ public abstract class JdwpId
private byte _tag;
/**
+ * The object/class represented by this Id
+ */
+ protected SoftReference _reference;
+
+ /**
* Constructs an empty <code>JdwpId</code>
*/
public JdwpId (byte tag)
@@ -72,7 +78,7 @@ public abstract class JdwpId
/**
* Sets the id for this object reference
*/
- void setId (long id)
+ public void setId (long id)
{
_id = id;
}
@@ -86,15 +92,33 @@ public abstract class JdwpId
}
/**
+ * Gets the object/class reference for this ID
+ *
+ * @returns a refernce to the object or class
+ */
+ public SoftReference getReference ()
+ {
+ return _reference;
+ }
+
+ /**
+ * Sets the object/class reference for this ID
+ *
+ * @param ref a refernce to the object or class
+ */
+ public void setReference (SoftReference ref)
+ {
+ _reference = ref;
+ }
+
+ /**
* Compares two object ids for equality. Two object ids
* are equal if they point to the same type and contain to
- * the same id number. (NOTE: This is a much stricter check
- * than is necessary: all <code>JdwpId</code>s have unique
- * ids.)
+ * the same id number.
*/
public boolean equals (JdwpId id)
{
- return ((id.getClass () == getClass ()) && (id.getId () == getId ()));
+ return (id.getId () == getId ());
}
/**
diff --git a/gnu/classpath/jdwp/id/ObjectId.java b/gnu/classpath/jdwp/id/ObjectId.java
index e34a3b59e..3e2abd4f6 100644
--- a/gnu/classpath/jdwp/id/ObjectId.java
+++ b/gnu/classpath/jdwp/id/ObjectId.java
@@ -40,12 +40,15 @@ exception statement from your version. */
package gnu.classpath.jdwp.id;
import gnu.classpath.jdwp.JdwpConstants;
+import gnu.classpath.jdwp.exception.InvalidObjectException;
import java.io.DataOutputStream;
import java.io.IOException;
/**
- * A class which represents a JDWP object id for an object
+ * This is a base class for all ObjectID-like entities in JDWP,
+ * inculding Objects, ClassObject, ClassLoader, Thread, ThreadGroup,
+ * etc.
*
* @author Keith Seitz <keiths@redhat.com>
*/
@@ -57,6 +60,9 @@ public class ObjectId
*/
public static final Class typeClass = Object.class;
+ // Handle to disable garbage collection
+ private Object _handle;
+
/**
* Constructs a new <code>ObjectId</code>
*/
@@ -85,6 +91,23 @@ public class ObjectId
}
/**
+ * Returns the object referred to by this ID
+ *
+ * @returns the object
+ * @throws InvalidObjectException if the object was garbage collected
+ * or is invalid
+ */
+ public Object getObject ()
+ throws InvalidObjectException
+ {
+ Object obj = _reference.get ();
+ if (obj == null)
+ throw new InvalidObjectException (_id);
+
+ return obj;
+ }
+
+ /**
* Writes the id to the stream
*
* @param outStream the stream to which to write
@@ -96,4 +119,21 @@ public class ObjectId
// All we need to do is write out our id as an 8-byte integer
outStream.writeLong (_id);
}
+
+ /**
+ * Disable garbage collection on object
+ */
+ public void disableCollection ()
+ throws InvalidObjectException
+ {
+ _handle = getObject ();
+ }
+
+ /**
+ * Enable garbage collection on object
+ */
+ public void enableCollection ()
+ {
+ _handle = null;
+ }
}
diff --git a/gnu/classpath/jdwp/id/ReferenceTypeId.java b/gnu/classpath/jdwp/id/ReferenceTypeId.java
index cdb78040a..e7a5d2c3d 100644
--- a/gnu/classpath/jdwp/id/ReferenceTypeId.java
+++ b/gnu/classpath/jdwp/id/ReferenceTypeId.java
@@ -39,6 +39,8 @@ exception statement from your version. */
package gnu.classpath.jdwp.id;
+import gnu.classpath.jdwp.exception.InvalidClassException;
+
import java.io.DataOutputStream;
import java.io.IOException;
@@ -68,6 +70,22 @@ public class ReferenceTypeId
}
/**
+ * Gets the class associated with this ID
+ *
+ * @returns the class
+ * @throws InvalidClassException if the class is not valid
+ */
+ public Class getType ()
+ throws InvalidClassException
+ {
+ Class clazz = (Class) _reference.get ();
+ if (clazz == null)
+ throw new InvalidClassException (_id);
+
+ return clazz;
+ }
+
+ /**
* Outputs the reference type ID to the given output stream
*
* @param outStream the stream to which to write the data
diff --git a/gnu/classpath/jdwp/id/StringId.java b/gnu/classpath/jdwp/id/StringId.java
index ea1a83a56..1ba8f6d4d 100644
--- a/gnu/classpath/jdwp/id/StringId.java
+++ b/gnu/classpath/jdwp/id/StringId.java
@@ -40,6 +40,7 @@ exception statement from your version. */
package gnu.classpath.jdwp.id;
import gnu.classpath.jdwp.JdwpConstants;
+import gnu.classpath.jdwp.exception.InvalidStringException;
/**
* A class which represents a JDWP string id
@@ -61,4 +62,21 @@ public class StringId
{
super (JdwpConstants.Tag.STRING);
}
+
+ /**
+ * Gets the String represented by this ID
+ *
+ * @throws InvalidStringException if String is garbage collected,
+ * or otherwise invalid
+ */
+ public String getString ()
+ throws InvalidStringException
+ {
+ String string = (String) _reference.get ();
+
+ if (string == null)
+ throw new InvalidStringException (getId ());
+
+ return string;
+ }
}
diff --git a/gnu/classpath/jdwp/id/ThreadGroupId.java b/gnu/classpath/jdwp/id/ThreadGroupId.java
index aef7d5b54..f4d9d803d 100644
--- a/gnu/classpath/jdwp/id/ThreadGroupId.java
+++ b/gnu/classpath/jdwp/id/ThreadGroupId.java
@@ -40,6 +40,7 @@ exception statement from your version. */
package gnu.classpath.jdwp.id;
import gnu.classpath.jdwp.JdwpConstants;
+import gnu.classpath.jdwp.exception.InvalidThreadGroupException;
/**
* A class which represents a JDWP thread group id
@@ -61,4 +62,21 @@ public class ThreadGroupId
{
super (JdwpConstants.Tag.THREAD_GROUP);
}
+
+ /**
+ * Gets the thread group represented by this ID
+ *
+ * @throws InvalidThreadGroupException if the group is invalid
+ * or garbage collected
+ */
+ public ThreadGroup getThreadGroup ()
+ throws InvalidThreadGroupException
+ {
+ ThreadGroup group = (ThreadGroup) _reference.get ();
+
+ if (group == null)
+ throw new InvalidThreadGroupException (getId ());
+
+ return group;
+ }
}
diff --git a/gnu/classpath/jdwp/id/ThreadId.java b/gnu/classpath/jdwp/id/ThreadId.java
index 733bf5510..207d6b0a1 100644
--- a/gnu/classpath/jdwp/id/ThreadId.java
+++ b/gnu/classpath/jdwp/id/ThreadId.java
@@ -40,6 +40,7 @@ exception statement from your version. */
package gnu.classpath.jdwp.id;
import gnu.classpath.jdwp.JdwpConstants;
+import gnu.classpath.jdwp.exception.InvalidThreadException;
/**
* A class which represents a JDWP thread id
@@ -61,4 +62,24 @@ public class ThreadId
{
super (JdwpConstants.Tag.THREAD);
}
+
+ /**
+ * Gets the Thread represented by this ID
+ *
+ * @throws InvalidThreadException if thread is garbage collected,
+ * exited, or otherwise invalid
+ */
+ public Thread getThread ()
+ throws InvalidThreadException
+ {
+ Thread thread = (Thread) _reference.get ();
+
+ /* Spec says if thread is null, not valid, or exited,
+ throw invalid thread */
+ // FIXME: not valid? exited? Is this check valid?
+ if (thread == null || !thread.isAlive ())
+ throw new InvalidThreadException (getId ());
+
+ return thread;
+ }
}