Merge remote-tracking branch 'redux/master' into sh4-pool
[tamarin-stm.git] / extensions / ST_mmgc_dependent.st
blob12c103580567f52383f94c3a566844360ae3567f
1 // -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4 -*-
2 // vi: set ts=4 sw=4 expandtab: (add to ~/.vimrc: set modeline modelines=5) */
3 //
4 // ***** BEGIN LICENSE BLOCK *****
5 // Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 //
7 // The contents of this file are subject to the Mozilla Public License Version
8 // 1.1 (the "License"); you may not use this file except in compliance with
9 // the License. You may obtain a copy of the License at
10 // http://www.mozilla.org/MPL/
12 // Software distributed under the License is distributed on an "AS IS" basis,
13 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14 // for the specific language governing rights and limitations under the
15 // License.
17 // The Original Code is [Open Source Virtual Machine.].
19 // The Initial Developer of the Original Code is
20 // Adobe System Incorporated.
21 // Portions created by the Initial Developer are Copyright (C) 2004-2006
22 // the Initial Developer. All Rights Reserved.
24 // Contributor(s):
25 //   Adobe AS3 Team
27 // Alternatively, the contents of this file may be used under the terms of
28 // either the GNU General Public License Version 2 or later (the "GPL"), or
29 // the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 // in which case the provisions of the GPL or the LGPL are applicable instead
31 // of those above. If you wish to allow use of your version of this file only
32 // under the terms of either the GPL or the LGPL, and not to allow others to
33 // use your version of this file under the terms of the MPL, indicate your
34 // decision by deleting the provisions above and replace them with the notice
35 // and other provisions required by the GPL or the LGPL. If you do not delete
36 // the provisions above, a recipient may use your version of this file under
37 // the terms of any one of the MPL, the GPL or the LGPL.
39 // ***** END LICENSE BLOCK ***** */
41 // Bugzilla 543560 - here we risk deleting an object that is still on the mark stack because
42 // of how we perform large-object splitting.  The setup is that user code that deletes the object
43 // gets to run after the first part of the large object has been popped off the mark stack
44 // but before the rest has been handled.
46 %%component mmgc
47 %%category  dependent
49 %%prefix
50 using namespace MMgc;
52 static const size_t nbytes = 16*1024*1024;
54 class DependentAllocHolder : public GCFinalizedObject {
55 public:
57   DependentAllocHolder() {
58     memory = (char*)FixedMalloc::GetFixedMalloc()->Alloc(nbytes);
59     GC::GetGC(this)->SignalDependentAllocation(nbytes);
60   }
62   virtual ~DependentAllocHolder() {
63     FixedMalloc::GetFixedMalloc()->Free(memory);
64     memory = NULL;
65     GC::GetGC(this)->SignalDependentDeallocation(nbytes);
66   }
67   private:
68     char* memory;
71 %%decls
72 private:
73     MMgc::GC *gc;
75 %%prologue
76     gc = new GC(GCHeap::GetGCHeap(), GC::kIncrementalGC);
78 %%epilogue
79     delete gc;
81 %%test dependent_alloc
82     size_t maxheap = 0;
83     {
84         MMGC_GCENTER(gc);
86         int count = 100;
87         for (int c=0; c<count; c++) {
88             (void)(new (gc) DependentAllocHolder());
89             size_t heapsize = gc->policy.blocksOwnedByGC() * GCHeap::kBlockSize;
90             // printf("%lu\n", (unsigned long)heapsize);
91             if (heapsize > maxheap)
92                 maxheap = heapsize;
93         }
94     }
96     // This is tricky to get right but for this test the 16MB blocks will dominate
97     // completely.  So assume that heap size must stay below L*2*16MB for the
98     // L that applies at 32MB.
100 %%verify size_t(gc->policy.queryLoadForHeapsize(double(2*nbytes)) * 2.0 * double(nbytes)) >= maxheap