Skip to content
Closed
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
8 changes: 5 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if (WINDOWS)
set(SHARED_FLAGS "-DPy_BUILD_CORE -DPy_BUILD_CORE_MODULE")
set(SHARED_FLAGS "-DPy_BUILD_CORE -DPy_BUILD_CORE_MODULE")
set(CXX_FLAGS "")
else()
set(SHARED_FLAGS "-DPy_BUILD_CORE -DPy_BUILD_CORE_MODULE -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -Wall -Wextra -Wno-attributes -Wno-c99-designator -Wno-c++11-narrowing -Wno-cast-function-type -Wno-cast-function-type-mismatch -Wno-deprecated-declarations -Wno-missing-field-initializers -Wno-null-pointer-subtraction -Wno-parentheses -Wno-sign-compare -Wno-unknown-pragmas -Wno-unused-function -Wno-unused-parameter")
set(SHARED_FLAGS "-DPy_BUILD_CORE -DPy_BUILD_CORE_MODULE -fPIC -fvisibility=hidden -Wall -Wextra -Wno-attributes -Wno-c99-designator -Wno-c++11-narrowing -Wno-cast-function-type -Wno-cast-function-type-mismatch -Wno-deprecated-declarations -Wno-missing-field-initializers -Wno-null-pointer-subtraction -Wno-parentheses -Wno-sign-compare -Wno-unknown-pragmas -Wno-unused-function -Wno-unused-parameter")
set(CXX_FLAGS "-fvisibility-inlines-hidden")
endif()

macro(set_flag VAR)
Expand All @@ -67,7 +69,7 @@ set_flag(ENABLE_USDT)
set_flag(ENABLE_ZLIB)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SHARED_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SHARED_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_FLAGS} ${SHARED_FLAGS}")

##############################################################################
# Apply LTO (Link-Time Optimization) if enabled
Expand Down
3 changes: 3 additions & 0 deletions build/fbcode_builder/manifests/rebalancer
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ branch = main
[build]
builder = cmake

[cmake.defines]
CMAKE_POSITION_INDEPENDENT_CODE=ON

[dependencies]
boost
fbthrift
Expand Down
11 changes: 11 additions & 0 deletions cinderx/Common/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ constexpr bool kPyRefDebug =
false;
#endif

// True when CinderX is built against a free-threaded (Py_GIL_DISABLED) Python.
//
// When false, code can assume the GIL is held. When true, it cannot, the GIL
// might still be held at any given moment but that's no longer guaranteed.
constexpr bool kFreeThreadedBuild =
#ifdef Py_GIL_DISABLED
true;
#else
false;
#endif

struct jit_string_deleter {
void operator()(jit_string_t* ss) const {
ss_free(ss);
Expand Down
14 changes: 13 additions & 1 deletion cinderx/Interpreter/3.15/Includes/Python/ceval_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@
#define STOP_TRACING() ((void)(0));
#endif


/* PRE_DISPATCH_GOTO() does lltrace if enabled. Normally a no-op */
#ifdef Py_DEBUG
#define PRE_DISPATCH_GOTO() if (frame->lltrace >= 5) { \
Expand Down Expand Up @@ -329,11 +328,24 @@ GETITEM(PyObject *v, Py_ssize_t i) {
#define CONSTS() _PyFrame_GetCode(frame)->co_consts
#define NAMES() _PyFrame_GetCode(frame)->co_names

#if defined(WITH_DTRACE) && !defined(Py_BUILD_CORE_MODULE)
static void dtrace_function_entry(_PyInterpreterFrame *);
static void dtrace_function_return(_PyInterpreterFrame *);

#define DTRACE_FUNCTION_ENTRY() \
if (PyDTrace_FUNCTION_ENTRY_ENABLED()) { \
dtrace_function_entry(frame); \
}

#define DTRACE_FUNCTION_RETURN() \
if (PyDTrace_FUNCTION_RETURN_ENABLED()) { \
dtrace_function_return(frame); \
}
#else
#define DTRACE_FUNCTION_ENTRY() ((void)0)
#define DTRACE_FUNCTION_RETURN() ((void)0)
#endif

/* This takes a uint16_t instead of a _Py_BackoffCounter,
* because it is used directly on the cache entry in generated code,
* which is always an integral type. */
Expand Down
79 changes: 51 additions & 28 deletions cinderx/Interpreter/3.15/Includes/generated_cases.c.h
Original file line number Diff line number Diff line change
Expand Up @@ -646,11 +646,16 @@
_PyStackRef ds;
_PyStackRef ss;
_PyStackRef value;
// _GUARD_NOS_ANY_DICT
// _GUARD_NOS_DICT_SUBSCRIPT
{
nos = stack_pointer[-2];
PyObject *o = PyStackRef_AsPyObjectBorrow(nos);
if (!PyAnyDict_CheckExact(o)) {
if (!Py_TYPE(o)->tp_as_mapping) {
UPDATE_MISS_STATS(BINARY_OP);
assert(_PyOpcode_Deopt[opcode] == (BINARY_OP));
JUMP_TO_PREDICTED(BINARY_OP);
}
if (Py_TYPE(o)->tp_as_mapping->mp_subscript != _PyDict_Subscript) {
UPDATE_MISS_STATS(BINARY_OP);
assert(_PyOpcode_Deopt[opcode] == (BINARY_OP));
JUMP_TO_PREDICTED(BINARY_OP);
Expand All @@ -663,18 +668,12 @@
dict_st = nos;
PyObject *sub = PyStackRef_AsPyObjectBorrow(sub_st);
PyObject *dict = PyStackRef_AsPyObjectBorrow(dict_st);
assert(PyAnyDict_CheckExact(dict));
assert(Py_TYPE(dict)->tp_as_mapping->mp_subscript == _PyDict_Subscript);
STAT_INC(BINARY_OP, hit);
PyObject *res_o;
_PyFrame_SetStackPointer(frame, stack_pointer);
int rc = PyDict_GetItemRef(dict, sub, &res_o);
PyObject *res_o = _PyDict_Subscript(dict, sub);
stack_pointer = _PyFrame_GetStackPointer(frame);
if (rc == 0) {
_PyFrame_SetStackPointer(frame, stack_pointer);
_PyErr_SetKeyError(sub);
stack_pointer = _PyFrame_GetStackPointer(frame);
}
if (rc <= 0) {
if (res_o == NULL) {
JUMP_TO_LABEL(error);
}
res = PyStackRef_FromPyObjectSteal(res_o);
Expand Down Expand Up @@ -1927,6 +1926,14 @@
JUMP_TO_PREDICTED(CALL);
}
}
// _CHECK_RECURSION_REMAINING
{
if (tstate->py_recursion_remaining <= 1) {
UPDATE_MISS_STATS(CALL);
assert(_PyOpcode_Deopt[opcode] == (CALL));
JUMP_TO_PREDICTED(CALL);
}
}
// _ALLOCATE_OBJECT
{
PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable);
Expand Down Expand Up @@ -9328,6 +9335,7 @@
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
_PyFrame_SetStackPointer(frame, stack_pointer);
assert(STACK_LEVEL() == 0);
DTRACE_FUNCTION_RETURN();
_Py_LeaveRecursiveCallPy(tstate);
_PyInterpreterFrame *dying = frame;
frame = tstate->current_frame = dying->previous;
Expand All @@ -9353,6 +9361,7 @@
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(INSTRUMENTED_YIELD_VALUE);
opcode = INSTRUMENTED_YIELD_VALUE;
_PyStackRef val;
_PyStackRef value;
_PyStackRef retval;
Expand Down Expand Up @@ -9389,6 +9398,7 @@
stack_pointer += -1;
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
_PyFrame_SetStackPointer(frame, stack_pointer);
DTRACE_FUNCTION_RETURN();
tstate->exc_info = gen->gi_exc_state.previous_item;
gen->gi_exc_state.previous_item = NULL;
_Py_LeaveRecursiveCallPy(tstate);
Expand All @@ -9398,13 +9408,12 @@
((_PyThreadStateImpl *)tstate)->generator_return_kind = GENERATOR_YIELD;
FT_ATOMIC_STORE_INT8_RELEASE(gen->gi_frame_state, FRAME_SUSPENDED + oparg);
assert(INLINE_CACHE_ENTRIES_SEND == INLINE_CACHE_ENTRIES_FOR_ITER);
#if TIER_ONE
assert(frame->instr_ptr->op.code == INSTRUMENTED_LINE ||
frame->instr_ptr->op.code == INSTRUMENTED_INSTRUCTION ||
_PyOpcode_Deopt[frame->instr_ptr->op.code] == SEND ||
_PyOpcode_Deopt[frame->instr_ptr->op.code] == FOR_ITER ||
_PyOpcode_Deopt[frame->instr_ptr->op.code] == INTERPRETER_EXIT ||
_PyOpcode_Deopt[frame->instr_ptr->op.code] == ENTER_EXECUTOR);
#if TIER_ONE && defined(Py_DEBUG)
if (!PyStackRef_IsNone(frame->f_executable)) {
int i = frame->instr_ptr - _PyFrame_GetBytecode(frame);
int opcode = _Py_GetBaseCodeUnit(_PyFrame_GetCode(frame), i).op.code;
assert(opcode == SEND || opcode == FOR_ITER);
}
#endif
stack_pointer = _PyFrame_GetStackPointer(frame);
LOAD_IP(1 + INLINE_CACHE_ENTRIES_SEND);
Expand Down Expand Up @@ -12527,6 +12536,7 @@
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
_PyFrame_SetStackPointer(frame, stack_pointer);
assert(STACK_LEVEL() == 0);
DTRACE_FUNCTION_RETURN();
_Py_LeaveRecursiveCallPy(tstate);
_PyInterpreterFrame *dying = frame;
frame = tstate->current_frame = dying->previous;
Expand Down Expand Up @@ -13482,11 +13492,16 @@
_PyStackRef dict_st;
_PyStackRef sub;
_PyStackRef st;
// _GUARD_NOS_DICT
// _GUARD_NOS_DICT_STORE_SUBSCRIPT
{
nos = stack_pointer[-2];
PyObject *o = PyStackRef_AsPyObjectBorrow(nos);
if (!PyDict_CheckExact(o)) {
if (!Py_TYPE(o)->tp_as_mapping) {
UPDATE_MISS_STATS(STORE_SUBSCR);
assert(_PyOpcode_Deopt[opcode] == (STORE_SUBSCR));
JUMP_TO_PREDICTED(STORE_SUBSCR);
}
if (Py_TYPE(o)->tp_as_mapping->mp_ass_subscript != _PyDict_StoreSubscript) {
UPDATE_MISS_STATS(STORE_SUBSCR);
assert(_PyOpcode_Deopt[opcode] == (STORE_SUBSCR));
JUMP_TO_PREDICTED(STORE_SUBSCR);
Expand All @@ -13499,7 +13514,7 @@
dict_st = nos;
value = stack_pointer[-3];
PyObject *dict = PyStackRef_AsPyObjectBorrow(dict_st);
assert(PyDict_CheckExact(dict));
assert(Py_TYPE(dict)->tp_as_mapping->mp_ass_subscript == _PyDict_StoreSubscript);
STAT_INC(STORE_SUBSCR, hit);
_PyFrame_SetStackPointer(frame, stack_pointer);
int err = _PyDict_SetItem_Take2((PyDictObject *)dict,
Expand Down Expand Up @@ -14386,6 +14401,7 @@
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(YIELD_VALUE);
opcode = YIELD_VALUE;
_PyStackRef value;
_PyStackRef retval;
// _MAKE_HEAP_SAFE
Expand All @@ -14405,6 +14421,7 @@
stack_pointer += -1;
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
_PyFrame_SetStackPointer(frame, stack_pointer);
DTRACE_FUNCTION_RETURN();
tstate->exc_info = gen->gi_exc_state.previous_item;
gen->gi_exc_state.previous_item = NULL;
_Py_LeaveRecursiveCallPy(tstate);
Expand All @@ -14414,13 +14431,12 @@
((_PyThreadStateImpl *)tstate)->generator_return_kind = GENERATOR_YIELD;
FT_ATOMIC_STORE_INT8_RELEASE(gen->gi_frame_state, FRAME_SUSPENDED + oparg);
assert(INLINE_CACHE_ENTRIES_SEND == INLINE_CACHE_ENTRIES_FOR_ITER);
#if TIER_ONE
assert(frame->instr_ptr->op.code == INSTRUMENTED_LINE ||
frame->instr_ptr->op.code == INSTRUMENTED_INSTRUCTION ||
_PyOpcode_Deopt[frame->instr_ptr->op.code] == SEND ||
_PyOpcode_Deopt[frame->instr_ptr->op.code] == FOR_ITER ||
_PyOpcode_Deopt[frame->instr_ptr->op.code] == INTERPRETER_EXIT ||
_PyOpcode_Deopt[frame->instr_ptr->op.code] == ENTER_EXECUTOR);
#if TIER_ONE && defined(Py_DEBUG)
if (!PyStackRef_IsNone(frame->f_executable)) {
int i = frame->instr_ptr - _PyFrame_GetBytecode(frame);
int opcode = _Py_GetBaseCodeUnit(_PyFrame_GetCode(frame), i).op.code;
assert(opcode == SEND || opcode == FOR_ITER);
}
#endif
stack_pointer = _PyFrame_GetStackPointer(frame);
LOAD_IP(1 + INLINE_CACHE_ENTRIES_SEND);
Expand Down Expand Up @@ -14552,6 +14568,13 @@ JUMP_TO_LABEL(error);
}

LABEL(exit_unwind)
{
assert(_PyErr_Occurred(tstate));
DTRACE_FUNCTION_RETURN();
JUMP_TO_LABEL(exit_unwind_notrace);
}

LABEL(exit_unwind_notrace)
{
assert(_PyErr_Occurred(tstate));
_Py_LeaveRecursiveCallPy(tstate);
Expand Down
1 change: 1 addition & 0 deletions cinderx/Interpreter/3.15/cinderx_opcode_targets.h
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@ static PyObject *Py_PRESERVE_NONE_CC _TAIL_CALL_pop_1_error(TAIL_CALL_PARAMS);
static PyObject *Py_PRESERVE_NONE_CC _TAIL_CALL_error(TAIL_CALL_PARAMS);
static PyObject *Py_PRESERVE_NONE_CC _TAIL_CALL_exception_unwind(TAIL_CALL_PARAMS);
static PyObject *Py_PRESERVE_NONE_CC _TAIL_CALL_exit_unwind(TAIL_CALL_PARAMS);
static PyObject *Py_PRESERVE_NONE_CC _TAIL_CALL_exit_unwind_notrace(TAIL_CALL_PARAMS);
static PyObject *Py_PRESERVE_NONE_CC _TAIL_CALL_start_frame(TAIL_CALL_PARAMS);
static PyObject *Py_PRESERVE_NONE_CC _TAIL_CALL_stop_tracing(TAIL_CALL_PARAMS);

Expand Down
Loading
Loading