Skip to content

Commit bbc6baf

Browse files
committed
disable GC in managed mode
1 parent f416afe commit bbc6baf

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed

graalpython/com.oracle.graal.python.cext/include/internal/pycore_object.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@ static inline void _PyObject_GC_UNTRACK(
195195
// Macros to accept any type for the parameter, and to automatically pass
196196
// the filename and the filename (if NDEBUG is not defined) where the macro
197197
// is called.
198+
#ifdef GRAALVM_PYTHON_LLVM_MANAGED
199+
# define _PyObject_GC_TRACK(op)
200+
# define _PyObject_GC_UNTRACK(op)
201+
#else
198202
#ifdef NDEBUG
199203
# define _PyObject_GC_TRACK(op) \
200204
_PyObject_GC_TRACK(_PyObject_CAST(op))
@@ -206,6 +210,7 @@ static inline void _PyObject_GC_UNTRACK(
206210
# define _PyObject_GC_UNTRACK(op) \
207211
_PyObject_GC_UNTRACK(__FILE__, __LINE__, _PyObject_CAST(op))
208212
#endif
213+
#endif
209214

210215
#ifdef Py_REF_DEBUG
211216
extern void _PyDebug_PrintTotalRefs(void);

graalpython/com.oracle.graal.python.cext/src/gcmodule.c

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2446,6 +2446,8 @@ PyInit_gc(void)
24462446
}
24472447
#endif // GraalPy change
24482448

2449+
#ifndef GRAALVM_PYTHON_LLVM_MANAGED
2450+
24492451
/* C API for controlling the state of the garbage collector */
24502452
int
24512453
PyGC_Enable(void)
@@ -2521,6 +2523,37 @@ _PyGC_CollectNoFail(PyThreadState *tstate)
25212523
gcstate->collecting = 0;
25222524
return n;
25232525
}
2526+
#else
2527+
int
2528+
PyGC_Enable(void)
2529+
{
2530+
return 0;
2531+
}
2532+
2533+
int
2534+
PyGC_Disable(void)
2535+
{
2536+
return 0;
2537+
}
2538+
2539+
int
2540+
PyGC_IsEnabled(void)
2541+
{
2542+
return 0;
2543+
}
2544+
2545+
Py_ssize_t
2546+
PyGC_Collect(void)
2547+
{
2548+
return 0;
2549+
}
2550+
2551+
PyAPI_FUNC(Py_ssize_t)
2552+
_PyGC_CollectNoFail(PyThreadState *tstate)
2553+
{
2554+
return 0;
2555+
}
2556+
#endif
25242557

25252558
#if 0 // GraalPy change
25262559
void
@@ -2601,6 +2634,7 @@ _PyGC_Fini(PyInterpreterState *interp)
26012634
}
26022635
#endif // GraalPy change
26032636

2637+
#ifndef GRAALVM_PYTHON_LLVM_MANAGED
26042638
/* for debugging */
26052639
void
26062640
_PyGC_Dump(PyGC_Head *g)
@@ -2694,6 +2728,28 @@ _PyObject_GC_Link(PyObject *op)
26942728
}
26952729
}
26962730

2731+
#else
2732+
2733+
void
2734+
_PyGC_Dump(PyGC_Head *g) {}
2735+
2736+
void
2737+
PyObject_GC_Track(void *op_raw) {}
2738+
2739+
void
2740+
PyObject_GC_UnTrack(void *op_raw) {}
2741+
2742+
int
2743+
PyObject_IS_GC(PyObject *obj)
2744+
{
2745+
return 0;
2746+
}
2747+
2748+
void
2749+
_PyObject_GC_Link(PyObject *op) {}
2750+
2751+
#endif
2752+
26972753
static PyObject *
26982754
gc_alloc(size_t basicsize, size_t presize)
26992755
{
@@ -2747,6 +2803,8 @@ _PyObject_GC_NewVar(PyTypeObject *tp, Py_ssize_t nitems)
27472803
return op;
27482804
}
27492805

2806+
#ifndef GRAALVM_PYTHON_LLVM_MANAGED
2807+
27502808
PyVarObject *
27512809
_PyObject_GC_Resize(PyVarObject *op, Py_ssize_t nitems)
27522810
{
@@ -2831,3 +2889,42 @@ _GraalPyObject_GC_NotifyOwnershipTransfer(PyObject *op)
28312889
CALL_TRAVERSE(traverse, op, visit_strong_reachable, NULL);
28322890
}
28332891
}
2892+
#else
2893+
2894+
2895+
PyVarObject *
2896+
_PyObject_GC_Resize(PyVarObject *op, Py_ssize_t nitems)
2897+
{
2898+
return NULL;
2899+
}
2900+
2901+
void
2902+
PyObject_GC_Del(void *op) {}
2903+
2904+
int
2905+
PyObject_GC_IsTracked(PyObject* obj)
2906+
{
2907+
return 0;
2908+
}
2909+
2910+
int
2911+
PyObject_GC_IsFinalized(PyObject *obj)
2912+
{
2913+
return 1;
2914+
}
2915+
2916+
2917+
void
2918+
GraalPyObject_GC_Del(void *op) {}
2919+
2920+
/* Exposes 'gc_collect_impl' such that we can call it from Java. */
2921+
PyAPI_FUNC(Py_ssize_t)
2922+
GraalPyGC_Collect(int generation)
2923+
{
2924+
return 0;
2925+
}
2926+
2927+
PyAPI_FUNC(void)
2928+
_GraalPyObject_GC_NotifyOwnershipTransfer(PyObject *op) {}
2929+
2930+
#endif

0 commit comments

Comments
 (0)