1b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Copyright 2013 the V8 project authors. All rights reserved.
21e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// Redistribution and use in source and binary forms, with or without
31e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// modification, are permitted provided that the following conditions are
41e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// met:
51e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block//
61e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block//     * Redistributions of source code must retain the above copyright
71e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block//       notice, this list of conditions and the following disclaimer.
81e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block//     * Redistributions in binary form must reproduce the above
91e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block//       copyright notice, this list of conditions and the following
101e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block//       disclaimer in the documentation and/or other materials provided
111e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block//       with the distribution.
121e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block//     * Neither the name of Google Inc. nor the names of its
131e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block//       contributors may be used to endorse or promote products derived
141e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block//       from this software without specific prior written permission.
151e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block//
161e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
171e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
181e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
191e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
201e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
211e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
221e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
231e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
241e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
251e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
261e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
271e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block
28b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Running this test with --trace_gc will show heap size growth due to
29b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// leaking objects via embedded maps in optimized code.
30592a9fc1d8ea420377a2e7efd0600e20b058be2bBen Murdoch
31b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochvar counter = 0;
32592a9fc1d8ea420377a2e7efd0600e20b058be2bBen Murdoch
33b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochfunction nextid() {
34b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  counter += 1;
35b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  return counter;
363ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch}
37592a9fc1d8ea420377a2e7efd0600e20b058be2bBen Murdoch
38b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochfunction Scope() {
39b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  this.id = nextid();
40b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  this.parent = null;
41b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  this.left = null;
42b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  this.right = null;
43b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  this.head = null;
44b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  this.tail = null;
45b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  this.counter = 0;
463ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch}
4785b71799222b55eb5dd74ea26efe0c64ab655c8cBen Murdoch
48b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochScope.prototype = {
49b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  new: function() {
50b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    var Child,
51b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch        child;
52b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    Child = function() {};
53b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    Child.prototype = this;
54b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    child = new Child();
55b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    child.id = nextid();
56b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    child.parent = this;
57b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    child.left = this.last;
58b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    child.right = null;
59b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    child.head = null;
60b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    child.tail = null;
61b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    child.counter = 0;
62b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    if (this.head) {
63b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch      this.tail.right = child;
64b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch      this.tail = child;
65b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    } else {
66b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch      this.head = this.tail = child;
673ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch    }
68b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    return child;
69b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  },
70b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
71b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  destroy: function() {
72b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    if ($root == this) return;
73b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    var parent = this.parent;
74b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    if (parent.head == this) parent.head = this.right;
75b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    if (parent.tail == this) parent.tail = this.left;
76b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    if (this.left) this.left.right = this.right;
77b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    if (this.right) this.right.left = this.left;
783ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch  }
79b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch};
80b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
81b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochfunction inc(scope) {
82b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  scope.counter = scope.counter + 1;
833ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch}
8485b71799222b55eb5dd74ea26efe0c64ab655c8cBen Murdoch
85b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochvar $root = new Scope();
86b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
87b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochn = 100000;
88b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochm = 10;
8985b71799222b55eb5dd74ea26efe0c64ab655c8cBen Murdoch
90b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochfunction doit() {
91b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch   var a = $root.new();
92b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch   var b = a.new();
93b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch   inc(b);
94b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch   if (i > m) $root.head.destroy();
95b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}
96592a9fc1d8ea420377a2e7efd0600e20b058be2bBen Murdoch
97b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochfor (var i = 0; i < n; i++) {
98b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch   doit();
99b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}
100