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 /* ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
16 * The Original Code is [Open Source Virtual Machine.].
18 * The Initial Developer of the Original Code is
19 * Adobe System Incorporated.
20 * Portions created by the Initial Developer are Copyright (C) 2004-2006
21 * the Initial Developer. All Rights Reserved.
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
44 // "behavior change: an object of POD type constructed with an initializer of the form () will be default-initialized"
45 #pragma warning(disable:4345) // b/c GCObject doesn't have a ctor
47 // we turn on exceptions in DEBUG builds
48 #pragma warning(disable:4291) // no matching operator delete found; memory will not be freed if initialization throws an exception
63 GCWeakRef
* createWeakRef(int extra
=0)
65 // Bogusly use up some extra stack.
67 // Certain compilers/platforms require this (at least gcc/MacIntel).
68 // A pointer to the temporary GCObject can be left on the stack, so
69 // far down that CleanStack doesn't dare touch it. Leaving the
70 // pointer there causes the temporary to be marked, and not collected,
71 // which causes tests to fail with assertions.
73 // The extra 64 bytes here causes the temporary to end up higher on
74 // the stack (numerically lesser address, on Intel at least) where
75 // CleanStack will clobber it.
78 VMPI_sprintf(buf
, "%d", extra
); // don't optimize away buf
80 return (new (gc
, extra
) GCObject())->GetWeakRef();
83 void weakRefSweepSmall()
85 GCWeakRef
*ref
= createWeakRef();
90 GCAssert(ref
->isNull());
93 void weakRefSweepLarge()
95 GCWeakRef
*ref
= createWeakRef(5000);
100 GCAssert(ref
->isNull());
103 void weakRefFreeSmall()
105 GCWeakRef
*ref
= createWeakRef();
107 GCAssert(ref
->isNull());
110 void weakRefFreeLarge()
112 GCWeakRef
*ref
= createWeakRef(5000);
114 GCAssert(ref
->isNull());
117 class RCObjectAddRefInDtor
: public RCObject
120 RCObjectAddRefInDtor(RCObject
** _stackPinners
, int _length
) : rcs(_stackPinners
), length(_length
) {}
121 ~RCObjectAddRefInDtor()
123 // whack these, used create freelist
124 for(int i
=0, n
=length
; i
<n
;i
++)
129 // add/remove myself (this was the apollo bug)
137 // naked pointer so I can kick these pinners out out of the ZCT during reap
142 GCWeakRef
* createProblem(RCObject
**stackPinners
)
144 // now create one that causes some removes from the dtor
145 return (new (gc
) RCObjectAddRefInDtor(stackPinners
, 3))->GetWeakRef();
151 // prime ZCT with some pinners
152 RCObject
*stackPinners
[3];
153 VMPI_memset(stackPinners
, 0, sizeof(stackPinners
));
155 GCWeakRef
*wr
= createProblem(stackPinners
);
157 stackPinners
[0] = new (gc
) RCObject();
158 stackPinners
[1] = new (gc
) RCObject();
159 stackPinners
[2] = new (gc
) RCObject();
162 for(int i
=0, n
=1000;i
<n
; i
++)
167 // it may still be alive if we had a dirty stack
172 // See comments in header file regarding what might happen if this is called.
173 void RunGCTests(GC
*g
)