Commit 7d5ea0c8 authored by Rudi Chen's avatar Rudi Chen

Move closer towards exposing the public gc interface only in one file.

parent 34532626
......@@ -16,6 +16,7 @@
#define PYSTON_ASMWRITING_REWRITER_H
#include <deque>
#include <list>
#include <map>
#include <memory>
#include <tuple>
......
......@@ -20,7 +20,6 @@
#include "core/common.h"
#include "core/types.h"
#include "core/util.h"
#include "gc/collector.h"
#include "runtime/dict.h"
#include "runtime/objmodel.h"
#include "runtime/types.h"
......
......@@ -35,7 +35,6 @@
#include "core/stats.h"
#include "core/thread_utils.h"
#include "core/util.h"
#include "gc/roots.h"
#include "runtime/generator.h"
#include "runtime/import.h"
#include "runtime/inline/boxing.h"
......
......@@ -20,7 +20,6 @@
#include "asm_writing/rewriter.h"
#include "codegen/ast_interpreter.h"
#include "codegen/patchpoints.h"
#include "gc/heap.h"
namespace pyston {
......
......@@ -32,7 +32,6 @@
#include "core/stats.h"
#include "core/types.h"
#include "core/util.h"
#include "gc/collector.h"
#include "runtime/objmodel.h"
#include "runtime/types.h"
......
......@@ -17,7 +17,7 @@
#include <algorithm>
#include "core/thread_utils.h"
#include "gc/heap.h"
#include "gc/gc.h"
namespace pyston {
......
......@@ -29,7 +29,6 @@
#include "core/stats.h"
#include "core/thread_utils.h"
#include "core/util.h"
#include "gc/collector.h"
#include "runtime/objmodel.h" // _printStacktrace
namespace pyston {
......
......@@ -23,7 +23,7 @@
#include "core/common.h"
#include "core/thread_utils.h"
#include "gc/collector.h"
#include "gc/gc.h"
namespace pyston {
class Box;
......
......@@ -15,25 +15,11 @@
#ifndef PYSTON_GC_COLLECTOR_H
#define PYSTON_GC_COLLECTOR_H
#include <deque>
#include <list>
#include <vector>
#include "core/types.h"
namespace pyston {
namespace gc {
#define TRACE_GC_MARKING 0
#if TRACE_GC_MARKING
extern FILE* trace_fp;
#define GC_TRACE_LOG(...) fprintf(pyston::gc::trace_fp, __VA_ARGS__)
#else
#define GC_TRACE_LOG(...)
#endif
class Box;
extern std::deque<Box*> pending_finalization_list;
extern std::deque<PyWeakReference*> weakrefs_needing_callback_list;
namespace gc {
// Mark this gc-allocated object as being a root, even if there are no visible references to it.
// (Note: this marks the gc allocation itself, not the pointer that points to one. For that, use
......@@ -63,19 +49,6 @@ public:
Box* operator->() { return value; }
};
void callPendingDestructionLogic();
void runCollection();
// Python programs are allowed to pause the GC. This is supposed to pause automatic GC,
// but does not seem to pause manual calls to gc.collect(). So, callers should check gcIsEnabled(),
// if appropriate, before calling runCollection().
bool gcIsEnabled();
void disableGC();
void enableGC();
// These are mostly for debugging:
bool isValidGCMemory(void* p); // if p is a valid gc-allocated pointer (or a non-heap root)
bool isValidGCObject(void* p); // whether p is valid gc memory and is set to have Python destructor semantics applied
bool isNonheapRoot(void* p);
void registerPythonObject(Box* b);
void invalidateOrderedFinalizerList();
......
......@@ -15,11 +15,29 @@
#ifndef PYSTON_GC_GC_H
#define PYSTON_GC_GC_H
#include <deque>
// Files outside of the gc/ folder should only import gc.h or gc_alloc.h
// which are the "public" memory management interface.
#define GC_KEEP_ALIVE(t) asm volatile("" : : "X"(t))
#define TRACE_GC_MARKING 0
#if TRACE_GC_MARKING
extern FILE* trace_fp;
#define GC_TRACE_LOG(...) fprintf(pyston::gc::trace_fp, __VA_ARGS__)
#else
#define GC_TRACE_LOG(...)
#endif
struct _PyWeakReference;
typedef struct _PyWeakReference PyWeakReference;
namespace pyston {
namespace gc {
// GOAL: Eventually, move any declaration that needs to be visible outside the gc/ folder
// to this file and only expose this header.
class Box;
namespace gc {
class TraceStack;
class GCVisitor {
......@@ -65,6 +83,31 @@ extern "C" void* gc_alloc(size_t nbytes, GCKind kind);
extern "C" void* gc_realloc(void* ptr, size_t bytes);
extern "C" void gc_free(void* ptr);
// Python programs are allowed to pause the GC. This is supposed to pause automatic GC,
// but does not seem to pause manual calls to gc.collect(). So, callers should check gcIsEnabled(),
// if appropriate, before calling runCollection().
bool gcIsEnabled();
void disableGC();
void enableGC();
void runCollection();
void dumpHeapStatistics(int level);
// These are exposed since the GC isn't necessarily responsible for calling finalizeres.
void callPendingDestructionLogic();
extern std::deque<Box*> pending_finalization_list;
extern std::deque<PyWeakReference*> weakrefs_needing_callback_list;
// These should only be used for debugging outside of the GC module. Except for functions that print
// some debugging information, it should be possible to replace calls to these functions with true
// without changing the behavior of the program.
// If p is a valid gc-allocated pointer (or a non-heap root)
bool isValidGCMemory(void* p);
// Whether p is valid gc memory and is set to have Python destructor semantics applied
bool isValidGCObject(void* p);
// Use this if a C++ object needs to be allocated in our heap.
class GCAllocatedRuntime {
public:
......
......@@ -17,6 +17,7 @@
#include <cstdlib>
#include "core/types.h"
#include "gc/collector.h"
#include "gc/heap.h"
......
......@@ -648,7 +648,6 @@ public:
};
extern Heap global_heap;
void dumpHeapStatistics(int level);
} // namespace gc
} // namespace pyston
......
......@@ -17,11 +17,10 @@
#include "core/common.h"
#include "core/threading.h"
#include "gc/gc.h"
namespace pyston {
#define GC_KEEP_ALIVE(t) asm volatile("" : : "X"(t))
template <class T> class StackRoot {
public:
explicit StackRoot(T* t) : t(t) {}
......
......@@ -14,7 +14,6 @@
#include "core/common.h"
#include "core/types.h"
#include "gc/collector.h"
#include "runtime/objmodel.h"
#include "runtime/types.h"
......
......@@ -23,7 +23,6 @@
#include "codegen/unwinding.h"
#include "core/ast.h"
#include "core/types.h"
#include "gc/collector.h"
#include "runtime/file.h"
#include "runtime/inline/boxing.h"
#include "runtime/int.h"
......
......@@ -26,7 +26,6 @@
#include "codegen/unwinding.h"
#include "core/ast.h"
#include "core/types.h"
#include "gc/collector.h"
#include "runtime/classobj.h"
#include "runtime/file.h"
#include "runtime/ics.h"
......
......@@ -13,7 +13,7 @@
// limitations under the License.
#include "core/types.h"
#include "gc/collector.h"
#include "gc/gc.h"
#include "runtime/types.h"
namespace pyston {
......
......@@ -26,7 +26,6 @@
#include "capi/types.h"
#include "codegen/unwinding.h"
#include "core/types.h"
#include "gc/collector.h"
#include "runtime/file.h"
#include "runtime/inline/boxing.h"
#include "runtime/inline/list.h"
......
......@@ -18,7 +18,6 @@
#include "capi/types.h"
#include "core/types.h"
#include "gc/collector.h"
#include "runtime/objmodel.h"
#include "runtime/types.h"
......
......@@ -17,7 +17,6 @@
#include <sstream>
#include "core/ast.h"
#include "gc/collector.h"
#include "runtime/objmodel.h"
#include "runtime/set.h"
......
......@@ -19,7 +19,6 @@
#include "core/common.h"
#include "core/stats.h"
#include "core/types.h"
#include "gc/collector.h"
#include "runtime/ics.h"
#include "runtime/inline/list.h"
#include "runtime/objmodel.h"
......
......@@ -19,7 +19,6 @@
#include "codegen/unwinding.h"
#include "core/ast.h"
#include "core/options.h"
#include "gc/collector.h"
#include "runtime/objmodel.h"
#include "runtime/traceback.h"
#include "runtime/types.h"
......
......@@ -28,7 +28,6 @@
#include "core/common.h"
#include "core/stats.h"
#include "core/types.h"
#include "gc/collector.h"
#include "runtime/ctxswitching.h"
#include "runtime/objmodel.h"
#include "runtime/types.h"
......
......@@ -21,7 +21,6 @@
#include "core/contiguous_map.h"
#include "core/types.h"
#include "gc/gc_alloc.h"
namespace pyston {
......
......@@ -20,7 +20,6 @@
#include "core/ast.h"
#include "core/threading.h"
#include "core/types.h"
#include "gc/heap.h"
#include "runtime/complex.h"
#include "runtime/float.h"
#include "runtime/generator.h"
......
......@@ -23,7 +23,6 @@
#include "core/options.h"
#include "core/stats.h"
#include "core/types.h"
#include "gc/collector.h"
#include "runtime/float.h"
#include "runtime/inline/boxing.h"
#include "runtime/long.h"
......
......@@ -22,7 +22,6 @@
#include "core/options.h"
#include "core/stats.h"
#include "core/types.h"
#include "gc/collector.h"
#include "runtime/inline/boxing.h"
#include "runtime/objmodel.h"
#include "runtime/types.h"
......
......@@ -22,7 +22,6 @@
#include "core/common.h"
#include "core/stats.h"
#include "core/types.h"
#include "gc/collector.h"
#include "gc/roots.h"
#include "runtime/inline/list.h"
#include "runtime/objmodel.h"
......
......@@ -26,7 +26,6 @@
#include "core/options.h"
#include "core/stats.h"
#include "core/types.h"
#include "gc/collector.h"
#include "runtime/float.h"
#include "runtime/inline/boxing.h"
#include "runtime/objmodel.h"
......
......@@ -37,9 +37,7 @@
#include "core/options.h"
#include "core/stats.h"
#include "core/types.h"
#include "gc/collector.h"
#include "gc/heap.h"
#include "gc/roots.h"
#include "gc/gc.h"
#include "runtime/classobj.h"
#include "runtime/dict.h"
#include "runtime/file.h"
......
......@@ -14,7 +14,6 @@
#include "runtime/set.h"
#include "gc/collector.h"
#include "runtime/objmodel.h"
namespace pyston {
......
......@@ -28,7 +28,6 @@
#include "core/common.h"
#include "core/types.h"
#include "core/util.h"
#include "gc/collector.h"
#include "runtime/dict.h"
#include "runtime/long.h"
#include "runtime/objmodel.h"
......
......@@ -18,7 +18,6 @@
#include "capi/types.h"
#include "core/types.h"
#include "gc/collector.h"
#include "runtime/objmodel.h"
#include "runtime/types.h"
......
......@@ -23,7 +23,6 @@
#include "core/common.h"
#include "core/stats.h"
#include "core/types.h"
#include "gc/collector.h"
#include "runtime/inline/list.h"
#include "runtime/list.h"
#include "runtime/objmodel.h"
......
......@@ -21,7 +21,6 @@
#include "core/common.h"
#include "core/stats.h"
#include "core/types.h"
#include "gc/collector.h"
#include "runtime/objmodel.h"
#include "runtime/types.h"
#include "runtime/util.h"
......
......@@ -33,7 +33,6 @@
#include "core/options.h"
#include "core/stats.h"
#include "core/types.h"
#include "gc/collector.h"
#include "runtime/classobj.h"
#include "runtime/complex.h"
#include "runtime/dict.h"
......
......@@ -5,7 +5,7 @@
#include "gtest/gtest.h"
#include "core/types.h"
#include "gc/gc_alloc.h"
#include "gc/gc.h"
#include "runtime/types.h"
#include "unittests.h"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment