This is the mail archive of the mailing list for the Java project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [cp-patches] [RFA/JDWP] ReferenceKey

On Fri, 2005-06-17 at 13:19 -0700, Keith Seitz wrote:
> > - Could java.util.WeakHashMap be used instead of writing your own?
> >    See java.lang.VMString.intern() for an example.
> Yeah, that's a good question. Originally, I wrote this thing using a
> Hashtable and SoftReferences, and the tables contained different
> mappings of various things.

One minor snafu -- maybe someone sees a way around this.

In order to facilitate the two types of needed lookups, we keep around
the two tables I mentioned:

oidTable maps from Object (ReferenceKey) to ObjectId
idTable maps from Long (numerical ID) to ObjectId

iodTable is used by the back-end and the VM parts to query IDs for
Objects to be passed to the debugger. idTable is for looking up objects
from commands sent by the debugger.

Whatever the table type (Hashtable or WeakHashMap), I would need to keep
a ReferenceQueue of the garbage collected Objects in order to clear the
IDs from garbage collected Objects from idTable.

Unfortunately, with the WeakHashMap, there is no way to get the keys put
into a ReferenceQueue (that I can see at least). Consequently, I'll
never know when to clean up the idTable unless I iterate over the table,
asking each ID whether its object is still valid.

So if I am to continue to use two tables for lookups, I need a little
more control over the garbage collection of keys than WeakHashMap
affords me, I think.

Perhaps there is a better way to implement IdManager? Shall I post that
so that people can see where these pieces fall into place?


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]