|
17 | 17 | #include "cinderx/Common/import.h" |
18 | 18 | #include "cinderx/Common/log.h" |
19 | 19 | #include "cinderx/Common/ref.h" |
| 20 | +#include "cinderx/Common/string.h" |
20 | 21 | #include "cinderx/Common/util.h" |
21 | 22 | #include "cinderx/Interpreter/interpreter.h" |
22 | 23 | #include "cinderx/Jit/code_allocator.h" |
@@ -102,30 +103,6 @@ UnitDeletedCallback handle_unit_deleted_during_preload = nullptr; |
102 | 103 | std::unordered_map<BorrowedRef<PyCodeObject>, BorrowedRef<PyFunctionObject>> |
103 | 104 | jit_code_outer_funcs; |
104 | 105 |
|
105 | | -// Frequently-used strings that we intern at JIT startup and hold references to. |
106 | | -#define INTERNED_STRINGS(X) \ |
107 | | - X(bc_offset) \ |
108 | | - X(code_hash) \ |
109 | | - X(count) \ |
110 | | - X(description) \ |
111 | | - X(filename) \ |
112 | | - X(firstlineno) \ |
113 | | - X(func_qualname) \ |
114 | | - X(guilty_type) \ |
115 | | - X(int) \ |
116 | | - X(lineno) \ |
117 | | - X(normal) \ |
118 | | - X(normvector) \ |
119 | | - X(opname) \ |
120 | | - X(reason) \ |
121 | | - X(split_dict_keys) \ |
122 | | - X(type_name) \ |
123 | | - X(types) |
124 | | - |
125 | | -#define DECLARE_STR(s) static PyObject* s_str_##s{nullptr}; |
126 | | -INTERNED_STRINGS(DECLARE_STR) |
127 | | -#undef DECLARE_STR |
128 | | - |
129 | 106 | std::array<PyObject*, hir::kNumOpcodes> s_hir_opnames; |
130 | 107 |
|
131 | 108 | std::atomic<int> g_compile_workers_attempted; |
@@ -2029,6 +2006,16 @@ int check(int ret) { |
2029 | 2006 | } |
2030 | 2007 |
|
2031 | 2008 | Ref<> make_deopt_stats() { |
| 2009 | + DEFINE_STATIC_STRING(count); |
| 2010 | + DEFINE_STATIC_STRING(description); |
| 2011 | + DEFINE_STATIC_STRING(filename); |
| 2012 | + DEFINE_STATIC_STRING(func_qualname); |
| 2013 | + DEFINE_STATIC_STRING(guilty_type); |
| 2014 | + DEFINE_STATIC_STRING(lineno); |
| 2015 | + DEFINE_STATIC_STRING(normal); |
| 2016 | + DEFINE_STATIC_STRING(int); |
| 2017 | + DEFINE_STATIC_STRING(reason); |
| 2018 | + |
2032 | 2019 | auto runtime = Runtime::get(); |
2033 | 2020 | auto stats = Ref<>::steal(check(PyList_New(0))); |
2034 | 2021 |
|
@@ -2066,19 +2053,19 @@ Ref<> make_deopt_stats() { |
2066 | 2053 | auto normals = Ref<>::steal(check(PyDict_New())); |
2067 | 2054 | auto ints = Ref<>::steal(check(PyDict_New())); |
2068 | 2055 |
|
2069 | | - check(PyDict_SetItem(event, s_str_normal, normals)); |
2070 | | - check(PyDict_SetItem(event, s_str_int, ints)); |
2071 | | - check(PyDict_SetItem(normals, s_str_func_qualname, func_qualname)); |
2072 | | - check(PyDict_SetItem(normals, s_str_filename, code->co_filename)); |
2073 | | - check(PyDict_SetItem(ints, s_str_lineno, lineno)); |
2074 | | - check(PyDict_SetItem(normals, s_str_reason, reason)); |
2075 | | - check(PyDict_SetItem(normals, s_str_description, description)); |
| 2056 | + check(PyDict_SetItem(event, s_normal, normals)); |
| 2057 | + check(PyDict_SetItem(event, s_int, ints)); |
| 2058 | + check(PyDict_SetItem(normals, s_func_qualname, func_qualname)); |
| 2059 | + check(PyDict_SetItem(normals, s_filename, code->co_filename)); |
| 2060 | + check(PyDict_SetItem(ints, s_lineno, lineno)); |
| 2061 | + check(PyDict_SetItem(normals, s_reason, reason)); |
| 2062 | + check(PyDict_SetItem(normals, s_description, description)); |
2076 | 2063 |
|
2077 | 2064 | auto count = Ref<>::steal(check(PyLong_FromSize_t(count_raw))); |
2078 | | - check(PyDict_SetItem(ints, s_str_count, count)); |
| 2065 | + check(PyDict_SetItem(ints, s_count, count)); |
2079 | 2066 | auto type_str = |
2080 | 2067 | Ref<>::steal(check(PyUnicode_InternFromString(type_name))); |
2081 | | - check(PyDict_SetItem(normals, s_str_guilty_type, type_str) < 0); |
| 2068 | + check(PyDict_SetItem(normals, s_guilty_type, type_str) < 0); |
2082 | 2069 | check(PyList_Append(stats, event)); |
2083 | 2070 | }; |
2084 | 2071 |
|
@@ -2792,13 +2779,6 @@ int register_fork_callback(BorrowedRef<> cinderjit_module) { |
2792 | 2779 |
|
2793 | 2780 | // Initialize some interned strings that can be used even when the JIT is off. |
2794 | 2781 | int initializeInternedStrings() { |
2795 | | -#define INTERN_STR(s) \ |
2796 | | - if ((s_str_##s = PyUnicode_InternFromString(#s)) == nullptr) { \ |
2797 | | - return -1; \ |
2798 | | - } |
2799 | | - INTERNED_STRINGS(INTERN_STR) |
2800 | | -#undef INTERN_STR |
2801 | | - |
2802 | 2782 | #define HIR_OP(opname) \ |
2803 | 2783 | if ((s_hir_opnames.at(static_cast<size_t>(hir::Opcode::k##opname)) = \ |
2804 | 2784 | PyUnicode_InternFromString(#opname)) == nullptr) { \ |
@@ -2859,10 +2839,6 @@ void dump_jit_stats() { |
2859 | 2839 | } |
2860 | 2840 |
|
2861 | 2841 | void finalizeInternedStrings() { |
2862 | | -#define CLEAR_STR(s) Py_CLEAR(s_str_##s); |
2863 | | - INTERNED_STRINGS(CLEAR_STR) |
2864 | | -#undef CLEAR_STR |
2865 | | - |
2866 | 2842 | for (PyObject*& opname : s_hir_opnames) { |
2867 | 2843 | Py_CLEAR(opname); |
2868 | 2844 | } |
|
0 commit comments