Bug 604547: Set expectedfail for deep failure (r=cpeyer)
[tamarin-stm.git] / extensions / ST_mmgc_575631.cpp
blobbdb5391f029b811f52ee5128fdcd864c5c98b8ec
1 // Generated from ST_mmgc_575631.st
2 // -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4 -*-
3 // vi: set ts=4 sw=4 expandtab: (add to ~/.vimrc: set modeline modelines=5)
4 //
5 // ***** BEGIN LICENSE BLOCK *****
6 // Version: MPL 1.1/GPL 2.0/LGPL 2.1
7 //
8 // The contents of this file are subject to the Mozilla Public License Version
9 // 1.1 (the "License"); you may not use this file except in compliance with
10 // the License. You may obtain a copy of the License at
11 // http://www.mozilla.org/MPL/
13 // Software distributed under the License is distributed on an "AS IS" basis,
14 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
15 // for the specific language governing rights and limitations under the
16 // License.
18 // The Original Code is [Open Source Virtual Machine.].
20 // The Initial Developer of the Original Code is
21 // Adobe System Incorporated.
22 // Portions created by the Initial Developer are Copyright (C) 2004-2006
23 // the Initial Developer. All Rights Reserved.
25 // Contributor(s):
26 // Adobe AS3 Team
28 // Alternatively, the contents of this file may be used under the terms of
29 // either the GNU General Public License Version 2 or later (the "GPL"), or
30 // the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
31 // in which case the provisions of the GPL or the LGPL are applicable instead
32 // of those above. If you wish to allow use of your version of this file only
33 // under the terms of either the GPL or the LGPL, and not to allow others to
34 // use your version of this file under the terms of the MPL, indicate your
35 // decision by deleting the provisions above and replace them with the notice
36 // and other provisions required by the GPL or the LGPL. If you do not delete
37 // the provisions above, a recipient may use your version of this file under
38 // the terms of any one of the MPL, the GPL or the LGPL.
40 // ***** END LICENSE BLOCK ***** */
42 // Bugzilla 565631 - We occasionally interleave invoking finalizers
43 // and clearing mark bits in GCAlloc::Finalize; so a finalizer can
44 // observe a live object that does not have its mark bit set.
46 // This complicates things because we want to ensure that unmarked
47 // weakly-referenced objects are resurrected by the GC if the weak
48 // reference is dereferenced during presweep, but we do not want to
49 // schedule collection work (or set bits that are supposed to be
50 // unmarked) during finalization.
52 // (Long term we might want to get rid of the interleaving of
53 // finalization and mark-bit clearing. Short term, lets just
54 // try to detect this on our own.)
56 #include "avmshell.h"
57 #ifdef VMCFG_SELFTEST
58 namespace avmplus {
59 using namespace MMgc;
61 // Upon destruction, start reading weak refs of "friends" near and far
62 class Snoopy : public GCFinalizedObject
64 public:
65 Snoopy(int key, GCWeakRef** refs, int len)
66 : key(key), friends(refs), len(len)
68 ++alive_count;
70 ~Snoopy();
71 static int alive_count;
72 private:
73 int key;
74 GCWeakRef** friends;
75 int len;
78 // To take D samples from an array of N elems, walk thru by floor(N/D)
79 // steps (but avoid the pathological case when the floor is zero).
80 int compute_stride(int numerator, int denominator)
82 int delta = numerator / denominator;
83 return (delta > 0) ? delta : 1;
86 class ST_mmgc_bugzilla_575631 : public Selftest {
87 public:
88 ST_mmgc_bugzilla_575631(AvmCore* core);
89 virtual void run(int n);
90 private:
91 static const char* ST_names[];
92 static const bool ST_explicits[];
93 void test0();
94 // collecting twice is only "sure" way to gc in presence of incrementality
95 void collect2() { core->gc->Collect(); core->gc->Collect(); }
98 ST_mmgc_bugzilla_575631::ST_mmgc_bugzilla_575631(AvmCore* core)
99 : Selftest(core, "mmgc", "bugzilla_575631", ST_mmgc_bugzilla_575631::ST_names,ST_mmgc_bugzilla_575631::ST_explicits)
101 const char* ST_mmgc_bugzilla_575631::ST_names[] = {"drizzle", NULL };
102 const bool ST_mmgc_bugzilla_575631::ST_explicits[] = {false, false };
103 void ST_mmgc_bugzilla_575631::run(int n) {
104 switch(n) {
105 case 0: test0(); return;
109 /*static*/ int Snoopy::alive_count = 0;
111 const int arr_len = 1000;
112 const int lookups_per_destruct = 10;
113 const int destructs = 10;
114 Snoopy::~Snoopy()
116 int delta = compute_stride(arr_len, lookups_per_destruct);
118 for ( int i = 1 ; i < arr_len ; i += delta ) {
119 int idx = (key + i) % len;
120 // printf("referencing ref[%d] from Snoopy(%d)\n", idx, key);
121 friends[idx]->get();
123 --alive_count;
126 void ST_mmgc_bugzilla_575631::test0() {
128 GC* gc = core->gc;
130 Snoopy* objs[arr_len];
131 GCWeakRef* refs[arr_len];
133 // initial setup:
134 for (int i=0 ; i < arr_len; ++i ) {
135 objs[i] = new (gc) Snoopy(i, refs, arr_len);
136 refs[i] = objs[i]->GetWeakRef();
139 collect2();
141 int delta = compute_stride(arr_len, destructs);
143 for (int i=0; i < arr_len; i += delta) {
144 objs[i] = NULL;
145 collect2();
148 // not assert failing within get() is passing the test.
149 #line 132 "ST_mmgc_575631.st"
150 verifyPass(1, "1", __FILE__, __LINE__);
151 ; // (make my auto-indenter happy)
153 // cleanup code; letting ~Snoopy occur outside test extent is big no-no.
155 for (int i=0; i < arr_len; ++i ) {
156 if (! refs[i]->isNull())
157 delete objs[i];
160 // if something went wrong above and some Snoopy's are still alive,
161 // we'll get burned during their destructors. Make sure that
162 // does not happen.
163 #line 145 "ST_mmgc_575631.st"
164 verifyPass((Snoopy::alive_count == 0), "(Snoopy::alive_count == 0)", __FILE__, __LINE__);
170 void create_mmgc_bugzilla_575631(AvmCore* core) { new ST_mmgc_bugzilla_575631(core); }
172 #endif