Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions INSTRUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,14 @@ printf "\nAllocation lifecycle (MALLOC/DEALLOC):\n" && \
```

Each line in `/tmp/firm2_events.ndjson` is NDJSON with the common envelope (`event_id`, `pid`, `tid`, `ts_ns`) and the emitter-specific payload fields, letting you inspect or post-process the full stream.

### AST type definition events during the CPython build

The AST type-definition emitter (`emit_ast_type_def_event_json`) runs when the interpreter creates the `ast.*` types during initialization, which happens while the freshly built interpreter is used to compile the standard library. If you want those `"type":"ast_type_def"` lines to appear during `make`/`make install`, export the gate before invoking the build so `_firm2_enabled()` evaluates to true for the bootstrap interpreter:

```bash
FIRMAMENT2_ENABLE=1 make -j"$(nproc)"
FIRMAMENT2_ENABLE=1 make install
```

Without the environment variable set, the generated code is still present but the emitter is a no-op.
2 changes: 2 additions & 0 deletions Modules/_opcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#endif

#include "Python.h"
#include "pycore_asdl.h"
#include "Python-ast.h"
#include "compile.h"
#include "opcode.h"
#include "pycore_ceval.h" // SPECIAL_MAX
Expand Down
2 changes: 2 additions & 0 deletions Modules/_testinternalcapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#undef NDEBUG

#include "Python.h"
#include "pycore_asdl.h"
#include "Python-ast.h"
#include "pycore_backoff.h" // JUMP_BACKWARD_INITIAL_VALUE
#include "pycore_bitutils.h" // _Py_bswap32()
#include "pycore_bytesobject.h" // _PyBytes_Find()
Expand Down
41 changes: 41 additions & 0 deletions Objects/codeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
#include <string.h>
#include <stdlib.h>

#ifdef Py_GIL_DISABLED
#define INITIAL_SPECIALIZED_CODE_SIZE 1
#endif

/* ------------------------------------------------------------------------
* Firmament2: per-code provenance tag via a lightweight pointer map.
* We keep a singly-linked list mapping code-object pointers to tags.
Expand Down Expand Up @@ -3155,6 +3159,43 @@ code__varname_from_oparg_impl(PyCodeObject *self, int oparg)
return Py_NewRef(name);
}

#ifdef Py_GIL_DISABLED
static int
code_traverse(PyObject *self, visitproc visit, void *arg)
{
PyCodeObject *co = _PyCodeObject_CAST(self);

Py_VISIT(co->co_consts);
Py_VISIT(co->co_names);
Py_VISIT(co->co_localsplusnames);
Py_VISIT(co->co_localspluskinds);
Py_VISIT(co->co_filename);
Py_VISIT(co->co_name);
Py_VISIT(co->co_qualname);
Py_VISIT(co->co_linetable);
Py_VISIT(co->co_exceptiontable);

if (co->_co_cached != NULL) {
Py_VISIT(co->_co_cached->_co_code);
Py_VISIT(co->_co_cached->_co_cellvars);
Py_VISIT(co->_co_cached->_co_freevars);
Py_VISIT(co->_co_cached->_co_varnames);
}

Py_VISIT(co->_co_monitoring);

#ifdef _Py_TIER2
if (co->co_executors != NULL) {
for (int i = 0; i < co->co_executors->size; i++) {
Py_VISIT(co->co_executors->executors[i]);
}
}
#endif

return 0;
}
#endif

/* XXX code objects need to participate in GC? */

static struct PyMethodDef code_methods[] = {
Expand Down
2 changes: 1 addition & 1 deletion Python/Python-ast.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.