1 // -*- c-basic-offset: 2 -*-
3 * This file is part of the KDE libraries
4 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
5 * Copyright (C) 2001 Peter Kelly (pmk@post.com)
6 * Copyright (C) 2003 Apple Computer, Inc.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #ifndef _KJSCOLLECTOR_H_
25 #define _KJSCOLLECTOR_H_
29 #define KJS_MEM_LIMIT 500000
34 * @short Garbage collector.
37 // disallow direct construction/destruction
41 * Register an object with the collector. The following assumptions are
43 * @li the operator new() of the object class is overloaded.
44 * @li operator delete() has been overloaded as well and does not free
45 * the memory on its own.
47 * @param s Size of the memory to be registered.
48 * @return A pointer to the allocated memory.
50 static void* allocate(size_t s);
52 * Run the garbage collection. This involves calling the delete operator
53 * on each object and freeing the used memory.
55 static bool collect();
57 static bool outOfMemory() { return memoryFull; }
61 * Check that nothing is left when the last interpreter gets deleted
63 static void finalCheck();
67 static int numInterpreters();
68 static int numGCNotAllowedObjects();
69 static int numReferencedObjects();
70 static const void *rootObjectClasses(); // actually returns CFSetRef
72 #if TEST_CONSERVATIVE_GC | USE_CONSERVATIVE_GC
75 static void registerThread();
79 #if TEST_CONSERVATIVE_GC | USE_CONSERVATIVE_GC
80 static void markProtectedObjects();
81 static void markCurrentThreadConservatively();
82 static void markOtherThreadConservatively(Thread *thread);
83 static void markStackObjectsConservatively();
84 static void markStackObjectsConservatively(void *start, void *end);
87 static bool memoryFull;
92 #endif /* _KJSCOLLECTOR_H_ */