heap object representation in spidermonkey

11 October 2018 2:33 PM (spidermonkey | v8 | jsc | igalia | compilers | javascript | firefox)

I was having a look through SpiderMonkey's source code today and found something interesting about how it represents heap objects and wanted to share.

I was first looking to see how to implement arbitrary-length integers ("bigints") by storing the digits inline in the allocated object. (I'll use the term "object" here, but from JS's perspective, bigints are rather values; they don't have identity. But I digress.) So you have a header indicating how many words it takes to store the digits, and the digits follow. This is how JavaScriptCore and V8 implementations of bigints work.

Incidentally, JSC's implementation was taken from V8. V8's was taken from Dart. Dart's was taken from Go. We might take SpiderMonkey's from Scheme48. Good times, right??

When seeing if SpiderMonkey could use this same strategy, I couldn't find how to make a variable-sized GC-managed allocation. It turns out that in SpiderMonkey you can't do that! SM's memory management system wants to work in terms of fixed-sized "cells". Even for objects that store properties inline in named slots, that's implemented in terms of standard cell sizes. So if an object has 6 slots, it might be implemented as instances of cells that hold 8 slots.

Truly variable-sized allocations seem to be managed off-heap, via malloc or other allocators. I am not quite sure how this works for GC-traced allocations like arrays, but let's assume that somehow it does.

Anyway, the point of this blog post. I was looking to see which part of SpiderMonkey reserves space for type information. For example, almost all objects in V8 start with a "map" word. This is the object's "hidden class". To know what kind of object you've got, you look at the map word. That word points to information corresponding to a class of objects; it's not available to store information that might vary between objects of that same class.

Interestingly, SpiderMonkey doesn't have a map word! Or at least, it doesn't have them on all allocations. Concretely, BigInt values don't need to reserve space for a map word. I can start storing data right from the beginning of the object.

But how can this work, you ask? How does the engine know what the type of some arbitrary object is?

The answer has a few interesting wrinkles. Firstly I should say that for objects that need hidden classes -- e.g. generic JavaScript objects -- there is indeed a map word. SpiderMonkey calls it a "Shape" instead of a "map" or a "hidden class" or a "structure" (as in JSC), but it's there, for that subset of objects.

But not all heap objects need to have these words. Strings, for example, are values rather than objects, and in SpiderMonkey they just have a small type code rather than a map word. But you know it's a string rather than something else in two ways: one, for "newborn" objects (those in the nursery), the GC reserves a bit to indicate whether the object is a string or not. (Really: it's specific to strings.)

For objects promoted out to the heap ("tenured" objects), objects of similar kinds are allocated in the same memory region (in kind-specific "arenas"). There are about a dozen trace kinds, corresponding to arena kinds. To get the kind of object, you find its arena by rounding the object's address down to the arena size, then look at the arena to see what kind of objects it has.

There's another cell bit reserved to indicate that an object has been moved, and that the rest of the bits have been overwritten with a forwarding pointer. These two reserved bits mostly don't conflict with any use a derived class might want to make from the first word of an object; if the derived class uses the first word for integer data, it's easy to just reserve the bits. If the first word is a pointer, then it's probably always aligned to a 4- or 8-byte boundary, so the low bits are zero anyway.

The upshot is that while we won't be able to allocate digits inline to BigInt objects in SpiderMonkey in the general case, we won't have a per-object map word overhead; and we can optimize the common case of digits requiring only a word or two of storage to have the digit pointer point to inline storage. GC is about compromise, and it seems this can be a good one.

Well, that's all I wanted to say. Looking forward to getting BigInt turned on upstream in Firefox!

115 responses

  1. John Cowan says:

    Chicken used to use Scheme48 code, but has replaced it with native code. You can find this in the Chicken 4 numbers egg or as part of Chicken 5.

  2. Play Store says:

    Nice post. Thanks for sharing.

  3. says:


  4. Cheap Assignment Writer says:

    It is simple and it is extremely valuable for net searchers to visit and know how to deal with the issues identified with site confirmation issues. This article will disclose how to blog remark and what makes for good blog remarks.

  5. windows 10 desktop icons says:

    Your are so intelligent and your blog writing skill was really perfect. i am always prefer to add my system main apps in desktop because i am easy to open this apps in single click, if you are don't know about the icon setting then go to learn there suggest web page and make easier your system controlling.

  6. dell bios update says:

    Thank you for sharing this post.

  7. Best Portable Outdoor Dog Fence Reviews 2019 says:

    Thanks for the update. I hope it will work for me.

  8. Quickbooks Tech Support says:

    The topic you have raised are very valid points in your post. It really happened some person do not have the right idea. But with your awesome tips, one can easily identify it.

  9. WikiManagementInc says:

    i can say that SpiderMonkey's source code is not that much easier code to understand i,ve share a post on code issue you can have explore for it

  10. travel to iran says:

    Truly quality blog posts on this website, saved to fav

  11. Parallels 14 coupon code says:

    Seems a great post. The source code of SpiderMonkey is difficult to understand for most of the people. Only users with specialized skills can understand it.

  12. dell promo code says:

    Truly quality blog posts on this website, saved to fav

  13. David says:

    Amazing and useful content. I fully agree with you. good job.

  14. Aman says:

    I am very really grateful for your blog post. You will find a lot of Great work

  15. kriti says:

    Sophistique interior service provide a dream house
    where a person aspires to live with his family friends,
    spend the great prescious time of his life express his love
    towards his wife and children and protect his children
    from any sort of ailment.

  16. Epson connect printer setup says:

    Ensure that both ends of the USB cable are firmly inserted. If the printer is networked then make sure the Ethernet cable is firmly inserted.

  17. Anny@123 says:

    A macro virus becomes active when a document infected with the virus is opened using the program it is designed to attack.

  18. Grammys 2019 says:

    Nice One

  19. Best essay writing service reviews says:

    I was searching on the internet for these types of posts. This is great information and I believe you created good quality item for your readers. Keep working, congrats!

  20. QuickBooks Online Phone Number says:

    You are doing a great job to share this informative article, I really like it. Keep posting and Thanks for sharing.

  21. QuickBooks Online Help says:

    Great Post, Love to read.

  22. QuickBooks Support says:

    The users to get excellent user experience with QuickBooks, they need instant help and QuickBooks technical support. The help offered is very efficient, and errors can get fixed remotely. QuickBooks support team is available 24/7 by calling on QuickBooks support number) and offers prompt error resolution.

  23. <a href="">Lauren Tree Service Silver Spring</a> says:

    Cool. can I share this post to my blog? I'd appreciate it. Cheers!

  24. Ronald M. Lynch says:

    Cool. can I share this post to my blog? I'd appreciate it. Cheers! Lauren Tree Service Silver Spring

  25. Recover Roadrunner Password says:

    Thanks for sharing; this is a fantastic blog post. Really looking forward to read more. Really Great.

  26. AOL Mail Forgot Password says:

    Thanks for this awesome post. keep posting like this post in the future.

  27. QuickBooks support phone number says:

    QuickBooks is an accounting software which is very useful and eminent for small and medium-sized business. Despite being a dependable and reliable software, the software might show up various types of issues and difficulties in QuickBooks. Dial our QuickBooks support phone number 18004173165 and get connected to our customer care executives who are available 24/7 round the clock to help you to fix all of your queries related to this software. Visit us-

  28. QuickBooks Payroll Support Phone Number says:

    At QuickBooks Payroll Support Phone Number +1-800-417-3165 helps you deal with the issues that pop up in this software. When it comes to errors, there are so much that you may face.visit us-

  29. APKDime says:

    APKDime is a hub of unlimited apk mods and daily updates. Get the latest thousands of Android games on your laptop. Download latest applications without any issue.

  30. QuickBooks Online Support says:

    Such a great information you are sharing, I really like your effort, keep doing. Also, anyone needs help in business or want to know about QuickBooks contact our QuickBooks Online Support Phone Number +1-888-885-7555 any time of 24*7 days.

  31. Kim Kiyosaki says:

    Kim Kiyosaki Biography is the story of a young woman who was fascinated by the world of entrepreneurship, ventured into it and made it big. ... He is an entrepreneur, business owner, investor and author, a multi-millionaire. She began her career as an employee of a Honolulu, Hawaii business magazine.

  32. Tech Customer Support says:

    QuickBooks Payroll is an outstanding version for QuickBooks that has helped in the overall development of numerous industries, organizations as well as institutions. QuickBooks Payroll Support Phone Number +1 833-228-2822 is answered by a team.
    Read More

  33. funflares says:

    thankyou very much for information

  34. QuickBooks Support Phone Number says:

  35. Canelo vs Jacobs channel says:

    Excellent blog post. I certainly appreciate this website. Continue the good work!

  36. Quickbooks online support says:

    If you are looking for immediate support for any kind of issue related to Quickbooks online support you can contact with our professionals. Our Quickbooks professionals guide you and suggest a better solution to your problem. All these technologies are very easy to use and it is also a user-friendly interface. There are many other advantages of Quickbooks desktop that helps the accounting system. If you want to the Quickbooks upgrade version you can dial our toll-free no. 1844-442-0333. Quickbooks is the one-stop clarification for providing all Quickbooks online support solution.

  37. superbpaper review says:

    Thank you for this article.

  38. ropeeni says:

    thank you very much for information

  39. QuickBooks Support says:

    Here I would like to suggest You that Quickbooks Support is the best smarter business tools which resolve any financial issues in business accounting software. If you are facing a lot of problems to handle the Quickbooks application, just a dial my toll-free no. +1-844-442-0333, your query has resolved as soon as possible. Our technical team is always ready for you.

  40. Carryminati says:


  41. QuickBooks Support Phone Number says:

    We as QuickBooks Support Phone Number +1-844-233-5335 team provide our matchless support for the issues in QuickBooks to its users worldwide. It goes without saying that QuickBooks is one of the most helpful accounting software present in the current time. Visit us-

  42. Ludo Game says:

    Ludo Game is a very interesting game and so many new features in new ludo games, you can try to ludo game and enjoy the new features of ludo games.

  43. Watch Rambo V Last Blood Full Movie Online says:

    I’m going to out for brussels. I’ll appreciate in case you proceed
    this in future. Many people can be benefited out of your writing.
    Cheers! Thank you so much for the great and very beneficial stuff that you have shared with the world. You may already have changed lots and lots of people’s life just from your experience and skills. In fact, I wanted to start my own blog to raise awareness of family breakups and the loss of many children who got involved with the gang and drugs dealing. I want to teach, support and empower the young couples and parents in order to prevent them from family failures and breakups.
    well my blog is kind of this personal story one but also directed to like, share things I’ve learned, my inspiration, how I got through things, etc to help others and I have a lot of content but layouts and titles etc are a little of a struggle. Anyways, I have no idea how to get the word out for people to read it. Do you have any ideas? Thank you!!!

  44. examine this article says:

    This post was worthy of my attention. Thank you!

  45. Garima Chaurasia says:

    I really appreciate your post. Thanks for sharing such useful information. Thanks for sharing amazing information!!!!!!

  46. Tree Pruning says:

    Thanks for the information on this. I really enjoy the write-up.

  47. says:

    Such a great blog – bright and informative. Thank you for your opinion and helpful articles.

  48. HP Printer Support says:

    HP Printer Support is active helpline that is available round the clock to resolve Hp printer problems.

  49. AOL Tech Support Phone Number says:

    AOL Tech Support Phone Number is a customer care helpline that is offered by one of world's best mail service provider.

  50. Dell Printer Support says:

    Dell Printer Support is a team of well experienced experts who takes care of your dell device problems.

  51. Webroot Phone Number says:

    For help with antivirus and PC security, dial Webroot Phone Number and get best help. Webroot Phone Number is active 24/7. Call our experts they will provide best help.

  52. Brother printer support says:

    All the services are available 24*7 for you. We are constantly providing Brother Printer Help Services USA to different areas of the world. Individuals are satisfied with our unbeatable services and hung up with joy in their voice.

  53. unclog drain says:

    many thanks a good deal this amazing site can be conventional in addition to relaxed.

  54. says:

    Hi friends, its enormous post on the topic of educationand entirely explained, keep it up all the time.

  55. lisa jany says:

    Hi, I am reading your blog for the third time and every time I read, I found it more informative. It’s difficult to find the entire concept in a single page for a vast topic like yours.You can easily save your time and money by downloading QuickBooks accounting software.For any information contact us at QuickBooks Support Phone Number 1-800-311-5657.Visit our website:

  56. gamcore says:

    inspiration, how I got through things, etc to help others and I have a lot

  57. detailed list says:

    This is what i call substance information. you can never go wrong reading.

  58. mark smith says:

    Hi i am Mary .We provide toll free QuickBooks Support +1-877-756-9341 to complete help for solving all quarries related to QuickBooks Software. Our Support teams are accessible 24X7. Get more information so visit our sites :-

  59. پخش تراکت says:


    It was good / Thank you
    It’s goooood
    Send me here for my friend
    I happened to come from Google here
    Thank you

  60. washing machine repair says:

    This is the perfect blog for everyone who really wants to find out about this topic. Thanks for sharing such good information.If anyone searching for the best washing machine repair service in Dubai. visit my profile.

  61. UAE data recovery says:

    this article is really good. but, can you explain more about it.
    If anybody formats their data and they are looking a best data recovery services they can connect with us.

  62. Change AOL Mail Password says:

    I am not the student of java-script nor i knew anything about it before reading your blog, spent good time with a full knowledge content.

  63. online casinos in India says:

    This is the ideal blog for anyone who truly desires to find out about this subject matter. Thanks for sharing such accurate facts.

  64. Epson Printer Error Code 0x10 says:

    your blog has a nice content great structure nice color combination, used everything is so great, keep making blog on more informative topics.

  65. Quickbooks online support says:

    Good article, it’s very helpful to all. I am very impressed about that you mentioned in this article, thanks for sharing this post. I got best useful information from your site’s blog.

  66. Independence Day Indian Memes says:

    Good article, it’s very helpful to all. I am very impressed about that you mentioned in this article

  67. Emma Mackey says:

    Very good helpful article

  68. روغن خراطین says:

    Great really / Wooooow
    I came from Google
    Thankful // best

  69. hp printer support says:

    HP Company is the maker of high-quality printers. It is one of the most famous names in the printer industry. It is the biggest producer of Computers, printers, and other electronic devices. It gives users with friendly devices. HP printers are more known for its excellent printing technology. HP printer more simple and reliable printer. So if you are looking for the HP printer customer technical support and services? Then you are in right place we give HP printer technical support services at very affordable prices. Dial our toll-free HP printer support number +1-854-400-5545 for fast and efficient technical support. Our technical expert team helps anytime to support the HP printer customer support toll free number.

  70. روغن ریحان says:

    Good news. Appreciate this post. Thank you for compiling and sharing it.

    I came from Google
    Thankful // best

  71. QuickBooks Payroll Support phone Number says:

    Our support team at Quickbooks Payroll Support Phone Number +1-855-548-3394 helps you deal with the issues that pop up in this software. When it comes to errors, there are so much that you may face.

  72. QuickBooks Support Phone Number USA says:

    QuickBooks Support Phone Number USA +1 855-548-3394 is the best spot to request prompt assistance for all QuickBooks errors. QuickBooks is accounting software which is known for its simple to utilize accounting highlights.

  73. Cheap Essay Writing Services USA says:

    Our custom writing company provides custom papers that will earn you the highest of grades because students can easily become frustrated trying to meet deadlines. Seek our affordable writing services today.

  74. روغن خراطین says:


    I arrived here a few days ago from Google

    I want to comment so thank you that it is useful

    I sent here for my friend. I need her


  75. click here says:

    Your current web-site is fairly quickly growing to be certainly one of my top feature. So, I just stumbled on creative weblog and I just need to state that this amazing is a nice blog post. Bless you pertaining to this kind of knowledge.

  76. tile installer says:

    I appreciate the effort you put into this but the post is mostly nonsense and covers a very thin argument. I suggest you beef up your info bank first so you can come up with a more decent entry next time.

  77. wikidekh says:

    Good post......

  78. Sierra Skye says:

    I really appreciate your post. Thanks for sharing such useful information.

  79. Bigg Boss Hindi Vote Online says:

    bigg boss season 13 is going to start from 29 september of this year.

  80. Hasnain Khan says:

    Best post I've ever seen. Thanks for this kind of amazing post. Keep working.

  81. adamschule85 says:

    I agree with numerous points and others need my full concentration to consider. car games unblocked

  82. HowToImpressaGirl says:

    Great post I really become your fan after reading this awesome post.

  83. <a href=""></a> says:

    If you are a student and do not write a good essay in English. Then they can always be ordered from professionals. Follow the link!

  84. Jason Boo says:

    If you are a student and do not write a good essay in English. Then they can always be ordered from professionals. Follow the link

  85. Jason Boo says:

    Hi there!

  86. Jason Boo says:
  87. John says:

    Such a great information you shared and i must appreciate your content tone through which make your readers stick to it your content or wikipedia page creators too.

  88. St Kitts real estate says:

    Great post I really like this.

  89. Cassandra D. Everhart says:

    Extremely good post.Really thank you! Will read on… tree removal

  90. HP Wireless Printer Offline says:

    Go through easy steps in the blog to fix HP Wireless Printer Offline issue. You can reach advanced printer experts at HP to fix the issue if still have no clue about the same.

  91. Anil Patel says:

    thanx for sharing the quality post.

  92. Mortal says:

    hi this is a good post

  93. hp printer says its offline says:

    Thanks for the information.

  94. Star Wars The Rise of Skywalker Full Movie Online says:

    Star Wars: The Rise of Skywalker (also known as Star Wars: Episode IX – The Rise of Skywalker) is an upcoming American epic space-opera film produced, co-written, and directed by J. J. Abrams. It will be the third installment of the Star Wars sequel trilogy—following The Force Awakens (2015)[a] and The Last Jedi (2017)—and the final episode of the nine-part 'Skywalker saga'.[b] The film is being produced by Lucasfilm and Bad Robot Productions, and will be distributed by Walt Disney Studios Motion Pictures. Its ensemble cast includes Daisy Ridley, Adam Driver, John Boyega, Oscar Isaac, Lupita Nyong'o, Domhnall Gleeson, Kelly Marie Tran, Richard E. Grant, Keri Russell, Mark Hamill, Anthony Daniels, Carrie Fisher,[c] Billy Dee Williams, and Ian McDiarmid. Watch Star Wars The Rise of Skywalker Full Movie Online
    The Rise of Skywalker will see the Resistance face the First Order once more, and the end of the ancient conflict between the Jedi and the Sith. Principal photography began in August 2018 at Pinewood Studios in England, and wrapped in February 2019. The film is scheduled to be released in the United States on December 20, 2019 .

  95. How to fix Printer Offline says:

    Printer is offline is the common error. The blog explains "How to fix Printer Offline" the issue. Follow the easy steps to fix the issue easily.

  96. سمباد says:

    The installation process is explained very well and in a very definite way.
    Anyone can understand this

    Also visit

  97. Sell My House Fast Minnesota says:

    This is very trustable site for all. Dear visitors, you can get here any update news of all spots in anytime

  98. کاغذ دیواری says:

    very good tnx

  99. hormuz island says:

    [URL=]hormuz island[/URL]

  100. wallcovering says:
  101. padra says:

    This is very trustable site for all. Dear visitors, you can get here any update news of all spots in anytime

  102. <a href=""> WBSSバンタム級決勝戦 放送</a> says:

    井上尚弥vsノニトドネア 生放送

  103. free amazon gift card generator says:

    Free V Bucks How To Get Fortnite Free V Bucks Using The Latest Free V Bucks,You are looking for 100% working Fortnite VBucks Generator right? Welcome You to the right website. Our v bucks generator is working on PS4, Xbox, Nintendo,PC and also ios and Android. [url=]fortnite free v bucks[/url] . Its 100% working and update version of 2019. Fortnite Hack V Bucks Generator made by us to produce unlimited quantities of Free fortnite V Bucks.

    Our Free Amazon gift card generator is an online tool that lets you generate free Amazon gift cards. Get free Amazon gift card codes without Survey, [url=]free amazon gift card generator[/url] . Amazon gift card generator will help you to generate unlimited free amazon cards without any human verification.

  104. پکیج says:

    Good for me
    The installation process is explained very well and in a very definite way.
    Anyone can understand this
    loading site is go000ood

  105. candy crush soda says:

    It is wonderful to be here with everyone, I have a lot of knowledge from what you share, to say thank you, the information and knowledge here helps me a lot

  106. boxnovel says:

    Very elaborate and insightful article. It gives me a fair amount of knowledge. It helps a lot for my work.

  107. auto detailing saskatoon says:

    Very usable and makes sense. Thank you!

  108. Prasad says:

    Very Informative article. Thank you for sharing with us!

  109. Patta chitta says:


  110. Anit Patel says:

    Excellent list of free online course. You list are very usefull for me. Thank you, I appreciate this piece!

  111. Panik says:

    It's relatively simple to use Spidermonkey.Just need to know how the barrier works and check GC collect any live object or not. Other kinds of stuff

  112. Blogvile says:

    There's another cell bit reserved to indicate that an object has been moved, thanks you giving information

  113. Computer Repair service in Ghaziabad says:

    This is also a very good post which I really enjoyed reading. In case you searching for the best Computer Repair service in Ghaziabad. For more details call: 9205059199

  114. روغن خراطین says:

    Hello good time
    I didn't want to comment
    I'll send it to my friend in WhatsApp
    Thank you

  115. روغن آرگان says:

    Hello good time
    Thank you
    I'll send it to my friend in WhatsApp
    I didn't want to comment

Leave a Reply