Extending V8 object header

43 views
Skip to first unread message

gese...@gmail.com

unread,
Apr 27, 2016, 7:13:48 PM4/27/16
to v8-users
Hi all!

As we know V8 objects, despite having C++ class definitions, are not created in the same way as normal C++ objects. Instead, a small object header is used and object components are addressed by offsets relative to the object's base address. For example, the offset of HeapObject's map is given in the class definition as kMapOffset. To retrieve the map, an accessor method is defined which ultimately calls READ_FIELD().

Has anyone here tried to extend object header? I currently find myself in a situation where it would be convenient to add a pointer field into the header of all objects derived from HeapObject. It's easy enough to add another kXYZOffset and change HeapObject::kHeaderSize accordingly (and fixing a handful of STATIC_ASSERT's). I'm wondering what else needs to be taken into account to make it work. So far I've taken care to add this new field after the map and initializing the new field to NULL whenever AllocateRaw() is called, but Chromium crashes on startup. What else am I missing? Or is V8 too optimized for this to be easily done?

Jochen Eisinger

unread,
Apr 28, 2016, 3:40:55 AM4/28/16
to v8-users
Changing the object layout of a base class is non-trivial, mainly because of the many different places that have hard-coded assumptions.

If you just need an additional pointer in certain objects, have you considered creating those objects via ObjectTemplates / FunctionTemplates and add "internal fields"? This gives you additional slots in the objects you can use for whatever you like.

--
--
v8-users mailing list
v8-u...@googlegroups.com
http://groups.google.com/group/v8-users
---
You received this message because you are subscribed to the Google Groups "v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages