Comments inline. On Wed, Oct 11, 2017 at 12:06 AM <[email protected]> wrote:
> 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: > Just use a on-heap hash table, for example an ObjectHashTable. As long as that hash table is alive, keys and values it contains stay alive. Not sure if a weak map is what you need, as it does not keep the keys alive. > > 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? > You wouldn't be able to use numbers as keys. > > 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? > I think the preferred way is to use Object::GetHash. > > 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. > -- * • * *Yang Guo** • **Google Germany GmbH* * • *Erika-Mann-Str. 33 * • *80636 Munich • [email protected] Geschäftsführer: Paul Manicle, Halimah DeLaine Prado Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg Diese E-Mail ist vertraulich. Wenn Sie nicht der richtige Adressat sind, leiten Sie diese bitte nicht weiter, informieren Sie den Absender und löschen Sie die E-Mail und alle Anhänge. Vielen Dank. This e-mail is confidential. If you are not the right addressee please do not forward it, please inform the sender, and please erase this e-mail including any attachments. 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.
