Hello,

We are working on a project that requires storing the pointer addresses of 
HeapObjects as keys in a hash table. Since V8's GC will move HeapObjects 
around in memory or delete them, this hash table needs to be updated on GC 
cycles. The JSWeakMap class (subclass of JSWeakCollection) seems to be a 
good fit for this. Questions:

1) How suitable is using JSWeakMap for storing generic HeapObjects as keys? 
We see that in JSWeakCollection::Set() there's a DCHECK for testing if the 
keys are either JSReceiver or Symbol. Any potential pitfalls for inserting 
object types other than JSReceiver or Symbol into a JSWeakMap? We know that 
for an object to be inserted into the table we need to supply 
JSWeakCollection::Set() with the object's identify hash. Suppose we can 
generate this hash for any HeapObject (e.g., worst case just use 
Smi::kMaxValue), are there other things we need to look out for?

2) For computing the identity hash of a HeapObject, is it feasible to use 
ObjectAddressForHashing()? The source comment says this function will 
return the object's offset in a MemoryChunk. But if GC moves the object, 
wouldn't its offset in MemoryChunk change also?

Thanks!

-- 
-- 
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- 
You received this message because you are subscribed to the Google Groups 
"v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to