Abstract
The web browser is the “new desktop.” Not only do many users spend most of their time using the browser, the browser has also become host to rich and dynamic applications that were previously tailored to each individual operating system. The lingua franca of web scripting, JavaScript, was pivotal in this development.
Imagine that all desktop applications allocated memory from a single heap managed by the operating system. To reclaim memory upon application shutdown, all processes would then be garbage collected—not just the one being quit. While operating systems improved upon this approach long ago, this was how browsers managed memory until recently.
This article explores compartmentalized memory management, an approach tailored specifically to web browsers. The idea is to partition the JavaScript heap into compartments and allocate objects to compartments based on their origin. All objects in the same compartment reference each other direct, whereas cross-origin references go through wrapper objects.
We carefully evaluate our techniques using Mozilla’s Firefox browser—which now ships with our enhancements—and demonstrate the benefits of collecting each compartment independently. This simultaneously improves runtime performance (up to 36%) and reduces garbage collection pause times (up to 75%) as well as the memory footprint of the browser. In addition, enforcing the same-origin security policy becomes simple and efficient with compartments.
Supplemental Material
Available for Download
Supplemental movie, appendix, image and software files for, Thinking Inside the Box: Compartmentalized Garbage Collection
- Saleh E. Abdullahi and Graem A. Ringwood. 1998. Garbage collecting the Internet: A survey of distributed garbage collection. Computing Surveys 30, 330--373. http://doi.acm.org/10.1145/292469.292471. Google Scholar
Digital Library
- Alexander Aiken, Manuel Fähndrich, and Raph Levien. 1995. Better static memory management: Improving region-based analysis of higher-order languages. In Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI’95). ACM Press, New York, NY, 174--185. DOI:http://dx.doi.org/10.1145/207110.207137 Google Scholar
Digital Library
- A. W. Appel. 1989. Simple generational garbage collection and fast allocation. Software—Practice and Experience 19, 2, 171--183. DOI:http://dx.doi.org/10.1002/spe.4380190206 Google Scholar
Digital Library
- Apple. 2012. The WebKit Open Source Project. (2012). Retrieved February 29, 2016 from http://www.webkit.org/projects/javascript/index.html.Google Scholar
- Katherine Barabash and Erez Petrank. 2010. Tracing garbage collection on highly parallel platforms. In Proceedings of the International Symposium on Memory Management (ISMM’10). ACM, New York, NY, 1--10. Google Scholar
Digital Library
- David A. Barrett and Benjamin G. Zorn. 1993. Using lifetime predictors to improve memory allocation performance. In Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI’93). ACM Press, New York, NY, 187--196. DOI:http://dx.doi.org/10.1145/155090.155108 Google Scholar
Digital Library
- David A. Barrett and Benjamin G. Zorn. 1995. Garbage collection using a dynamic threatening boundary. In Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI’95). ACM Press, New York, NY, 301--314. DOI:http://dx.doi.org/10.1145/207110.207164 Google Scholar
Digital Library
- Emery D. Berger, Kathryn S. McKinley, Robert D. Blumofe, and Paul R. Wilson. 2000. Hoard: A scalable memory allocator for multithreaded applications. In Proceedings of the International Conference on Architectural Support for Programming Languages and Operating Systems (ASPLOS IX). ACM Press, New York, NY, 117--128. Google Scholar
Digital Library
- Emery D. Berger, Benjamin G. Zorn, and Kathryn S. McKinley. 2002. Reconsidering custom memory allocation. In Proceedings of the ACM SIGPLAN Conference on Object-Oriented Programming Systems, Languages, and Applications (OOPSLA’04). ACM Press, New York, NY, 1--12. Google Scholar
Digital Library
- Stephen M. Blackburn, Richard Jones, Kathryn S. McKinley, and J. Eliot B. Moss. 2002. Beltway: Getting around garbage collection gridlock. In Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI’02). ACM Press, New York, NY, 153--164. DOI:http://dx.doi.org/10.1145/512529.512548 Google Scholar
Digital Library
- Stephen M. Blackburn, Sharad Singhai, Matthew Hertz, Kathryn S. McKinely, and J. Eliot B. Moss. 2001. Pretenuring for Java. In Proceedings of the ACM SIGPLAN Conference on Object-Oriented Programming Systems, Languages, and Applications (OOPSLA’01). ACM Press, New York, NY, 342--352. DOI:http://dx.doi.org/10.1145/504282.504307 Google Scholar
Digital Library
- Guy E. Blelloch and Perry Cheng. 1999. On bounding time and space for multiprocessor garbage collection. In Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI’99). ACM Press, New York, NY, 104--117. DOI:http://dx.doi.org/10.1145/301618.301648 Google Scholar
Digital Library
- Robert D. Blumofe and Charles E. Leiserson. 1999. Scheduling multithreaded computations by work stealing. Journal of the ACM 46, 5, 720--748. Google Scholar
Digital Library
- Hans-J. Boehm, Russ Atkinson, and Michael Plass. 1995. Ropes: An alternative to strings. Software—Practice and Experience 25, 12, (December 1995), 1315--1330. Google Scholar
Digital Library
- Perry Cheng and Guy E. Blelloch. 2001. A parallel, real-time garbage collector. In Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI’01). ACM Press, New York, NY, 125--136. DOI:http://dx.doi.org/10.1145/378795.378823 Google Scholar
Digital Library
- Trishul M. Chilimbi and James R. Larus. 1998. Using generational garbage collection to implement cache-conscious data placement. In Proceedings of the International Symposium on Memory Management (ISMM’98). ACM, New York, NY, 37--48. DOI:http://dx.doi.org/10.1145/286860.286865 Google Scholar
Digital Library
- Tamar Domani, Gal Goldshtein, Elliot K. Kolodner, Ethan Lewis, Erez Petrank, and Dafna Sheinwald. 2002. Thread-local heaps for Java. In Proceedings of the International Symposium on Memory Management (ISMM’02). ACM Press, New York, NY, 76--87. DOI:http://dx.doi.org/10.1145/512429.512439 Google Scholar
Digital Library
- Patrick Dubroy and Ravin Balakrishnan. 2010. A study of tabbed browsing among Mozilla Firefox users. In Proceedings of the SIGCHI Conference on Human Factors in Computing Systems (CHI’10). ACM Press, New York, NY, 673--682. Google Scholar
Digital Library
- Toshio Endo, Kenjiro Taura, and Akinori Yonezawa. 1997. A scalable mark-sweep garbage collector on large-scale shared-memory machines. In SC. ACM, New York, NY, 48. Google Scholar
Digital Library
- Christine H. Flood, David Detlefs, Nir Shavit, and Xiaolan Zhang. 2001. Parallel garbage collection for shared memory multiprocessors. In Proceedings of the 2001 Symposium on Java Virtual Machine Research and Technology Symposium (JVM’01). USENIX Association, Berkeley, CA, 21--21. http://portal.acm.org/citation.cfm?id=1267847.1267868. Google Scholar
Digital Library
- Andreas Gal, Brendan Eich, Mike Shaver, David Anderson, David Mandelin, Mohammad R. Haghighat, Blake Kaplan, Graydon Hoare, Boris Zbarsky, Jason Orendorff, Jesse Ruderman, Edwin W. Smith, Rick Reitmaier, Michael Bebenita, Mason Chang, and Michael Franz. 2009. Trace-based just-in-time type specialization for dynamic languages. In Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI’09). ACM Press, New York, NY, 465--478. DOI:http://dx.doi.org/10.1145/1542476.1542528 Google Scholar
Digital Library
- Google. 2009. Introducing Google Chrome OS. Retrieved February 29, 2016 from http://googleblog.blogspot.com/2009/07/introducing-google-chrome-os.html.Google Scholar
- Google. 2012. Chrome V8 - Efficient Garbage Collection. (2012). Retrieved February 29, 2016 from https://developers.google.com/v8/design#garb_coll. Accessed 01/31/2013.Google Scholar
- Dirk Grunwald, Benjamin Zorn, and Robert Henderson. 1993. Improving the cache locality of memory allocation. In Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI’93). ACM Press, New York, NY, 177--186. DOI:http://dx.doi.org/10.1145/155090.155107 Google Scholar
Digital Library
- Samuel Z. Guyer and Kathryn S. McKinley. 2004. Finding your cronies: Static analysis for dynamic object colocation. In Proceedings of the ACM SIGPLAN Conference on Object-Oriented Programming Systems, Languages, and Applications (OOPSLA’04). ACM, New York, NY, 237--250. http://doi.acm.org/10.1145/1028976.1028996 Google Scholar
Digital Library
- Brian Hackett and Shu-yu Guo. 2012. Fast and precise hybrid type inference for JavaScript. In Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI’12), Jan Vitek, Haibo Lin, and Frank Tip (Eds.). ACM Press, New York, NY, 239--250. Google Scholar
Digital Library
- David R. Hanson. 1977. Storage management for an implementation of SNOBOL4. Software—Practice and Experience 7, 2, 179--192. DOI:http://dx.doi.org/10.1002/spe.4380070206Google Scholar
- D. R. Hanson. 1990. Fast allocation and deallocation of memory based on object lifetimes. Software—Practice and Experience 20, 1, 5--12. DOI:http://dx.doi.org/10.1002/spe.4380200104 Google Scholar
Digital Library
- Barry Hayes. 1991. Using key object opportunism to collect old objects. In Conference Proceedings on Object-Oriented Programming Systems, Languages, and Applications (OOPSLA’91). ACM Press, New York, NY, 33--46. DOI:http://dx.doi.org/10.1145/117954.117957 Google Scholar
Digital Library
- Martin Hirzel, Johannes Henkel, Amer Diwan, and Michael Hind. 2002. Understanding the connectivity of heap objects. In Proceedings of the International Symposium on Memory Management (ISMM’02). ACM Press, New York, NY, 36--49. DOI:http://dx.doi.org/10.1145/512429.512435 Google Scholar
Digital Library
- Urs Hölzle, Craig Chambers, and David Ungar. 1991. Optimizing dynamically-typed object-oriented languages with polymorphic inline caches. In Proceedings of the European Conference on Object-Oriented Programming (ECOOP’91). Springer, Berlin. Google Scholar
Digital Library
- Xianglong Huang, Stephen M. Blackburn, Kathryn S. McKinley, J. Eliot, B. Moss, Zhenlin Wang, and Perry Cheng. 2004. The garbage collection advantage: Improving program locality. In Proceedings of the ACM SIGPLAN Conference on Object-Oriented Programming Systems, Languages, and Applications (OOPSLA’04), John M. Vlissides and Douglas C. Schmidt (Eds.). ACM Press, New York, NY, 69--80. Google Scholar
Digital Library
- Richard L. Hudson and J. Eliot B. Moss. 1992. Incremental collection of mature objects. In Memory Management, Yves Bekkers and Jacques Cohen (Eds.). Lecture Notes in Computer Science, Vol. 637. Springer, Berlin, 388--403. DOI:http://dx.doi.org/10.1007/BFb0017203 Google Scholar
Digital Library
- R. J. M. Hughes. 1982. A semi-incremental garbage collection algorithm. Software: Practice and Experience 12, 11, 1081--1082. DOI:http://dx.doi.org/10.1002/spe.4380121108Google Scholar
Cross Ref
- Intel. 1997. Using the RDTSC Instruction for Performance Monitoring. Retrieved February 29, 2016 from http://www.ccsl.carleton.ca/∼jamuir/rdtscpm1.pdf.Google Scholar
- Mark Stuart Johnstone. 1997. Non-Compacting Memory Allocation and Real-Time Garbage Collection. Ph.D. Dissertation. University of Texas at Austin, Austin, TX. AAI9824978.Google Scholar
- Mark S. Johnstone and Paul R. Wilson. 1998. The memory fragmentation problem: Solved? In Proceedings of the International Symposium on Memory Management (ISMM’98). ACM, New York, NY, 26--36. DOI:http://dx.doi.org/10.1145/286860.286864 Google Scholar
Digital Library
- Richard Jones, Anthony Hosking, and Eliot Moss. 2011. The Garbage Collection Handbook: The Art of Automatic Memory Management. Chapman and Hall/CRC & Sons, Inc., London, UK. Google Scholar
Digital Library
- Eric Jul, Henry Levy, Norman Hutchinson, and Andrew Black. 1988. Fine-grained mobility in the Emerald system. ACM Transactions on Computer Systems 6, 1, 109--133. DOI:http://dx.doi.org/10.1145/35037.42182 Google Scholar
Digital Library
- Niels Christian Juul and Eric Jul. 1992. Comprehensive and robust garbage collection in a distributed system. In Proceedings of the International Symposium on Memory Management, Lecture Notes in Computer Science, Vol. 637. Springer, Berlin, 103--115. DOI:http://dx.doi.org/10.1007/BFb0017185 Google Scholar
Digital Library
- Donald E. Knuth. 1973. The Art of Computer Programming, Fundamental Algorithms (2nd ed.). Vol. 1. Addison Wesley, Boston, MA.Google Scholar
- Thomas Kotzmann, Christian Wimmer, Hanspeter Mössenböck, Thomas Rodriguez, Kenneth Russell, and David Cox. 2008. Design of the Java hotspot™ client compiler for Java 6. ACM Transactions on Architecture and Code Optimization 5, 1, 7:1--7:32. Google Scholar
Digital Library
- B. Lang and F. Dupont. 1987. Incremental incrementally compacting garbage collection. In Papers of the Symposium on Interpreters and Interpretive Techniques (SIGPLAN’87). ACM, New York, NY, 253--263. DOI:http://dx.doi.org/10.1145/29650.29677 Google Scholar
Digital Library
- Jens Lindström. 2009. Carakan Revisited. Retrieved February 29, 2016 from https://dev.opera.com/blog/carakan-revisited/.Google Scholar
- Linux Foundation. 2012. Tizen. Retrieved February 29, 2016 from https://www.tizen.org. Accessed 02/01/2013.Google Scholar
- Andrew Miadowicz. 2012. Advances in JavaScript Performance in IE10 and Windows 8. Retrieved February 29, 2016 from http://blogs.msdn.com/b/ie/archive/2012/06/13/advances-in-javascript-performance-in-ie10-and-windows-8.aspx.Google Scholar
- Microsoft. 2008. What’s New in Internet Explorer 8. Retrieved February 29, 2016 from http://msdn.microsoft.com/en-us/library/cc288472.aspxhttp://msdn.microsoft.com/en-us/library/cc288472spx.Google Scholar
- Mozilla. 2011. Kraken JavaScript Benchmark. Retrieved February 29, 2016 from http://krakenbenchmark.mozilla.org/.Google Scholar
- Mozilla. 2012. Experience Firefox OS on your Android device. Retrieved February 29, 2016 from http://www.mozilla.org/en-US/firefoxos/. Accessed 02/01/2013.Google Scholar
- Oracle. 2010. Java 2 Platform SE v.1.4.2 API Specification. https://docs.oracle.com/javase/1.4.2/docs/api/. Accessed 01/28/2013.Google Scholar
- Charles Reis and Steven D. Gribble. 2009. Isolating web programs in modern browser architectures. In Proceedings of the European Conference on Computer Systems. ACM Press, New York, NY, 219--232. DOI:http://dx.doi.org/10.1145/1519065.1519090 Google Scholar
Digital Library
- Jeffrey Richter. 2000. Garbage Collection: Automatic Memory Management in the Microsoft .NET Framework. http://www.cs.inf.ethz.ch/37-201/files/GC_in_NET.pdf. Accessed 01/28/2013.Google Scholar
- Douglas T. Ross. 1967. The AED free storage package. Communications of the ACM 10, 481--492. Issue 8. DOI:http://dx.doi.org/10.1145/363534.363546 Google Scholar
Digital Library
- J. Rudermann. 2001. The Same Origin Policy. Retrieved February 29, 2016 from https://developer.mozilla.org/En/Same_origin_policy_for_JavaScript.Google Scholar
- H. Schorr and W. M. Waite. 1967. An efficient machine-independent procedure for garbage collection in various list structures. Communications of the ACM 10, 8, 501--506. DOI:http://dx.doi.org/10.1145/363534.363554 Google Scholar
Digital Library
- Matthew L. Seidl and Benjamin G. Zorn. 1998. Segregating heap objects by reference behavior and lifetime. In Proceedings of the International Conference on Architectural Support for Programming Languages and Operating Systems (ASPLOS-VIII). ACM Press, New York, NY, 12--23. DOI:http://dx.doi.org/10.1145/291069.291012 Google Scholar
Digital Library
- Yefim Shuf, Manish Gupta, Rajesh Bordawekar, and Jaswinder Pal Singh. 2002. Exploiting prolific types for memory management and optimizations. In Proceedings of the ACM SIGPLAN Symposium on Principles of Programming Languages (POPL’02). ACM Press, New York, NY, 295--306. DOI:http://dx.doi.org/10.1145/503272.503300 Google Scholar
Digital Library
- Fridtjof Siebert. 2000. Eliminating external fragmentation in a nonmoving garbage collector for Java. In Proceedings of the 2000 International Conference on Compilers, Architecture, and Synthesis for Embedded Systems (CASES’00). ACM, New York, NY, 9--17. DOI:http://dx.doi.org/10.1145/354880.354883 Google Scholar
Digital Library
- Fridtjof Siebert. 2008. Limits of parallel marking garbage collection. In Proceedings of the International Symposium on Memory Management (ISMM’08). ACM, New York, NY, 21--29. DOI:http://dx.doi.org/10.1145/1375634.1375638 Google Scholar
Digital Library
- Sunil Soman, Laurent Daynès, and Chandra Krintz. 2006. Task-aware garbage collection in a multi-tasking virtual machine. In Proceedings of the International Symposium on Memory Management (ISMM’06). ACM, New York, NY, 64--73. DOI:http://dx.doi.org/10.1145/1133956.1133965 Google Scholar
Digital Library
- Sunil Soman, Chandra Krintz, and Laurent Daynès. 2008. MTM2: Scalable memory management for multi-tasking managed runtime environments. In ECOOP 2008 -- Object-Oriented Programming, Jan Vitek (Ed.). Springer, Berlin, 335--361. Google Scholar
Digital Library
- Steve Souders. 2013. HTTP Archive. (2013). Retrieved February 29, 2016 from http://httparchive.org/trends.php. Accessed 01/10/2013.Google Scholar
- Bjarne Steensgaard. 2000. Thread-specific heaps for multi-threaded programs. In Proceedings of the International Symposium on Memory Management (ISMM’00). ACM, New York, NY, 18--24. DOI:http://dx.doi.org/10.1145/362422.362432 Google Scholar
Digital Library
- Mads Tofte. 1998. A brief introduction to regions. In Proceedings of the International Symposium on Memory Management (ISMM’98). ACM, New York, NY, 186--195. http://doi.acm.org/10.1145/286860.286882. Google Scholar
Digital Library
- Mads Tofte and Jean-Pierre Talpin. 1997. Region-based memory management. Information and Computation 132, 2, 109--176. DOI:http://dx.doi.org/DOI:10.1006/inco.1996.2613 Google Scholar
Digital Library
- David Ungar. 1984. Generation scavenging: A non-disruptive high performance storage reclamation algorithm. In Proceedings of the 1st ACM SIGSOFT/SIGPLAN Software Engineering Symposium on Practical Software Development Environments (SDE 1). ACM, New York, NY, 157--167. DOI:http://dx.doi.org/10.1145/800020.808261 Google Scholar
Digital Library
- Kiem-Phong Vo. 1996. Vmalloc: A general and efficient memory allocator. Software—Practice and Experience 26, 3, 357--374. DOI:http://dx.doi.org/10.1002/(SICI)1097-024X(199603)26:3⟨357::AID-SPE15⟩3.0. CO;2-#Google Scholar
- Gregor Wagner. 2011. Domain Specific Memory Management in a Modern Web Browser. Ph.D. Dissertation. Donald Bren School of Information and Computer Sciences, University of California, Irvine, Irvine, CA. Google Scholar
Digital Library
- Gregor Wagner, Andreas Gal, Christian Wimmer, Brendan Eich, and Michael Franz. 2011. Compartmental memory management in a modern web browser. In Proceedings of the International Symposium on Memory Management (ISMM’11). ACM, New York, NY, 119--128. Google Scholar
Digital Library
- Paul R. Wilson. 1992. Uniprocessor garbage collection techniques. In Proceedings of the International Workshop on Memory Management (IWMM'92). Springer-Verlag, London, UK, 1--42. http://dl.acm.org/citation.cfm?id=664824. Google Scholar
Digital Library
- Paul R. Wilson, Michael S. Lam, and Thomas G. Moher. 1991. Effective “static-graph” reorganization to improve locality in garbage-collected systems. In Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI’91). ACM Press, New York, NY, 177--191. DOI:http://dx.doi.org/10.1145/113445.113461 Google Scholar
Digital Library
- Benjamin G. Zorn. 1989. Comparative Performance Evaluation of Garbage Collection Algorithms. Ph.D. Dissertation. EECS Department, University of California, Berkeley, Berkeley, CA. http://www.eecs.berkeley.edu/Pubs/TechRpts/1989/5313.html. Google Scholar
Digital Library
Index Terms
Thinking Inside the Box: Compartmentalized Garbage Collection
Recommendations
Compartmental memory management in a modern web browser
ISMM '11Since their inception, the usage pattern of web browsers has changed substantially. Rather than sequentially navigating static web sites, modern web browsers often manage a large number of simultaneous tabs displaying dynamic web content, each of which ...
Compartmental memory management in a modern web browser
ISMM '11: Proceedings of the international symposium on Memory managementSince their inception, the usage pattern of web browsers has changed substantially. Rather than sequentially navigating static web sites, modern web browsers often manage a large number of simultaneous tabs displaying dynamic web content, each of which ...
A generational on-the-fly garbage collector for Java
PLDI '00: Proceedings of the ACM SIGPLAN 2000 conference on Programming language design and implementationAn on-the-fly garbage collector does not stop the program threads to perform the collection. Instead, the collector executes in a separate thread (or process) in parallel to the program. On-the-fly collectors are useful for multi-threaded applications ...






Comments