Commit ea8890e8 authored by Marius Wachtler's avatar Marius Wachtler Committed by GitHub

Merge pull request #1348 from undingen/fewer_handleFrameExit

microptimizations: use DEFAULT_CLASS_SIMPLE, non gc code object, fewer handleFrameExit calls 
parents 0611d82f 0be24aec
...@@ -37,7 +37,7 @@ public: ...@@ -37,7 +37,7 @@ public:
Py_XINCREF(module); Py_XINCREF(module);
} }
DEFAULT_CLASS(capifunc_cls); DEFAULT_CLASS_SIMPLE(capifunc_cls, true);
PyCFunction getFunction() { return method_def->ml_meth; } PyCFunction getFunction() { return method_def->ml_meth; }
......
...@@ -1318,7 +1318,7 @@ public: ...@@ -1318,7 +1318,7 @@ public:
Py_XINCREF(idx_long); Py_XINCREF(idx_long);
} }
DEFAULT_CLASS(enumerate_cls); DEFAULT_CLASS_SIMPLE(enumerate_cls, true);
static Box* new_(Box* cls, Box* obj, Box* start) { static Box* new_(Box* cls, Box* obj, Box* start) {
RELEASE_ASSERT(cls == enumerate_cls, ""); RELEASE_ASSERT(cls == enumerate_cls, "");
......
...@@ -126,7 +126,7 @@ private: ...@@ -126,7 +126,7 @@ private:
public: public:
BoxedThreadLock() { lock_lock = PyThread_allocate_lock(); } BoxedThreadLock() { lock_lock = PyThread_allocate_lock(); }
DEFAULT_CLASS(thread_lock_cls); DEFAULT_CLASS_SIMPLE(thread_lock_cls, false);
static Box* acquire(Box* _self, Box* _waitflag) { static Box* acquire(Box* _self, Box* _waitflag) {
RELEASE_ASSERT(_self->cls == thread_lock_cls, ""); RELEASE_ASSERT(_self->cls == thread_lock_cls, "");
......
...@@ -100,18 +100,9 @@ Box* BoxedCode::flags(Box* b, void*) noexcept { ...@@ -100,18 +100,9 @@ Box* BoxedCode::flags(Box* b, void*) noexcept {
return boxInt(flags); return boxInt(flags);
} }
int BoxedCode::traverse(Box* self, visitproc visit, void* arg) noexcept {
BoxedCode* o = static_cast<BoxedCode*>(self);
Py_VISIT(o->_filename);
Py_VISIT(o->_name);
return 0;
}
void BoxedCode::dealloc(Box* b) noexcept { void BoxedCode::dealloc(Box* b) noexcept {
BoxedCode* o = static_cast<BoxedCode*>(b); BoxedCode* o = static_cast<BoxedCode*>(b);
PyObject_GC_UnTrack(o);
Py_XDECREF(o->_filename); Py_XDECREF(o->_filename);
Py_XDECREF(o->_name); Py_XDECREF(o->_name);
...@@ -210,9 +201,8 @@ extern "C" int PyCode_HasFreeVars(PyCodeObject* _code) noexcept { ...@@ -210,9 +201,8 @@ extern "C" int PyCode_HasFreeVars(PyCodeObject* _code) noexcept {
} }
void setupCode() { void setupCode() {
code_cls code_cls = BoxedClass::create(type_cls, object_cls, 0, 0, sizeof(BoxedCode), false, "code", false,
= BoxedClass::create(type_cls, object_cls, 0, 0, sizeof(BoxedCode), false, "code", false, (destructor)BoxedCode::dealloc, NULL, false, (traverseproc)NULL, NOCLEAR);
(destructor)BoxedCode::dealloc, NULL, true, (traverseproc)BoxedCode::traverse, NOCLEAR);
code_cls->giveAttrBorrowed("__new__", Py_None); // Hacky way of preventing users from instantiating this code_cls->giveAttrBorrowed("__new__", Py_None); // Hacky way of preventing users from instantiating this
......
...@@ -35,7 +35,7 @@ public: ...@@ -35,7 +35,7 @@ public:
Py_XINCREF(name); Py_XINCREF(name);
} }
DEFAULT_CLASS(code_cls); DEFAULT_CLASS_SIMPLE(code_cls, false);
// These need to be static functions rather than methods because function // These need to be static functions rather than methods because function
// pointers could point to them. // pointers could point to them.
...@@ -48,7 +48,6 @@ public: ...@@ -48,7 +48,6 @@ public:
static Box* varnames(Box* b, void*) noexcept; static Box* varnames(Box* b, void*) noexcept;
static Box* flags(Box* b, void*) noexcept; static Box* flags(Box* b, void*) noexcept;
static int traverse(Box* self, visitproc visit, void* arg) noexcept;
static void dealloc(Box* b) noexcept; static void dealloc(Box* b) noexcept;
}; };
} }
......
...@@ -163,7 +163,7 @@ public: ...@@ -163,7 +163,7 @@ public:
assert(hasExited()); assert(hasExited());
} }
DEFAULT_CLASS(frame_cls); DEFAULT_CLASS_SIMPLE(frame_cls, true);
static BORROWED(Box*) boxFrame(FrameInfo* fi) { static BORROWED(Box*) boxFrame(FrameInfo* fi) {
if (fi->frame_obj == NULL) if (fi->frame_obj == NULL)
...@@ -271,6 +271,12 @@ extern "C" void deinitFrame(FrameInfo* frame_info) noexcept { ...@@ -271,6 +271,12 @@ extern "C" void deinitFrame(FrameInfo* frame_info) noexcept {
PyErr_Clear(); PyErr_Clear();
} }
if (frame_info->exc.type) {
Py_CLEAR(frame_info->exc.type);
Py_CLEAR(frame_info->exc.value);
Py_CLEAR(frame_info->exc.traceback);
}
assert(cur_thread_state.frame_info == frame_info); assert(cur_thread_state.frame_info == frame_info);
cur_thread_state.frame_info = frame_info->back; cur_thread_state.frame_info = frame_info->back;
BoxedFrame* frame = frame_info->frame_obj; BoxedFrame* frame = frame_info->frame_obj;
...@@ -289,12 +295,6 @@ extern "C" void deinitFrame(FrameInfo* frame_info) noexcept { ...@@ -289,12 +295,6 @@ extern "C" void deinitFrame(FrameInfo* frame_info) noexcept {
Py_CLEAR(frame_info->boxedLocals); Py_CLEAR(frame_info->boxedLocals);
if (frame_info->exc.type) {
Py_CLEAR(frame_info->exc.type);
Py_CLEAR(frame_info->exc.value);
Py_CLEAR(frame_info->exc.traceback);
}
Py_CLEAR(frame_info->globals); Py_CLEAR(frame_info->globals);
assert(!PyErr_Occurred()); assert(!PyErr_Occurred());
......
...@@ -434,7 +434,8 @@ extern "C" BoxedGenerator* createGenerator(BoxedFunctionBase* function, Box* arg ...@@ -434,7 +434,8 @@ extern "C" BoxedGenerator* createGenerator(BoxedFunctionBase* function, Box* arg
static uint64_t* generator_timer_counter = Stats::getStatCounter("us_timer_generator_toplevel"); static uint64_t* generator_timer_counter = Stats::getStatCounter("us_timer_generator_toplevel");
#endif #endif
extern "C" BoxedGenerator::BoxedGenerator(BoxedFunctionBase* function, Box* arg1, Box* arg2, Box* arg3, Box** args) extern "C" BoxedGenerator::BoxedGenerator(BoxedFunctionBase* function, Box* arg1, Box* arg2, Box* arg3, Box** args)
: function(function), : weakreflist(NULL),
function(function),
arg1(arg1), arg1(arg1),
arg2(arg2), arg2(arg2),
arg3(arg3), arg3(arg3),
...@@ -442,6 +443,7 @@ extern "C" BoxedGenerator::BoxedGenerator(BoxedFunctionBase* function, Box* arg1 ...@@ -442,6 +443,7 @@ extern "C" BoxedGenerator::BoxedGenerator(BoxedFunctionBase* function, Box* arg1
entryExited(false), entryExited(false),
running(false), running(false),
returnValue(nullptr), returnValue(nullptr),
iterated_from__hasnext__(false),
exception(nullptr, nullptr, nullptr), exception(nullptr, nullptr, nullptr),
context(nullptr), context(nullptr),
returnContext(nullptr), returnContext(nullptr),
......
...@@ -59,7 +59,7 @@ public: ...@@ -59,7 +59,7 @@ public:
friend class BoxedXrangeIterator; friend class BoxedXrangeIterator;
DEFAULT_CLASS(xrange_cls); DEFAULT_CLASS_SIMPLE(xrange_cls, false);
}; };
class BoxedXrangeIterator : public Box { class BoxedXrangeIterator : public Box {
...@@ -87,7 +87,7 @@ public: ...@@ -87,7 +87,7 @@ public:
cur = start; cur = start;
} }
DEFAULT_CLASS(xrange_iterator_cls); DEFAULT_CLASS_SIMPLE(xrange_iterator_cls, true);
static llvm_compat_bool xrangeIteratorHasnextUnboxed(Box* s) __attribute__((visibility("default"))) { static llvm_compat_bool xrangeIteratorHasnextUnboxed(Box* s) __attribute__((visibility("default"))) {
assert(s->cls == xrange_iterator_cls); assert(s->cls == xrange_iterator_cls);
......
...@@ -76,7 +76,7 @@ public: ...@@ -76,7 +76,7 @@ public:
BoxedIterWrapper(Box* iter) : iter(iter), next(NULL) { Py_INCREF(iter); } BoxedIterWrapper(Box* iter) : iter(iter), next(NULL) { Py_INCREF(iter); }
DEFAULT_CLASS(iterwrapper_cls); DEFAULT_CLASS_SIMPLE(iterwrapper_cls, true);
static void dealloc(BoxedIterWrapper* o) noexcept { static void dealloc(BoxedIterWrapper* o) noexcept {
PyObject_GC_UnTrack(o); PyObject_GC_UnTrack(o);
......
...@@ -61,7 +61,7 @@ public: ...@@ -61,7 +61,7 @@ public:
BoxedSetIterator(BoxedSet* s) : s(s), it(s->s.begin()), size(s->s.size()) { Py_INCREF(s); } BoxedSetIterator(BoxedSet* s) : s(s), it(s->s.begin()), size(s->s.size()) { Py_INCREF(s); }
DEFAULT_CLASS(set_iterator_cls); DEFAULT_CLASS_SIMPLE(set_iterator_cls, true);
bool hasNext() { return it != s->s.end(); } bool hasNext() { return it != s->s.end(); }
......
...@@ -31,11 +31,11 @@ public: ...@@ -31,11 +31,11 @@ public:
Set s; Set s;
Box** weakreflist; /* List of weak references */ Box** weakreflist; /* List of weak references */
BoxedSet() __attribute__((visibility("default"))) {} BoxedSet() __attribute__((visibility("default"))) : weakreflist(NULL) {}
template <typename T> __attribute__((visibility("default"))) BoxedSet(T&& s) : s(std::forward<T>(s)) {} template <typename T> __attribute__((visibility("default"))) BoxedSet(T&& s) : s(std::forward<T>(s)) {}
DEFAULT_CLASS(set_cls); DEFAULT_CLASS_SIMPLE(set_cls, true);
static void dealloc(Box* b) noexcept; static void dealloc(Box* b) noexcept;
static int traverse(Box* self, visitproc visit, void* arg) noexcept; static int traverse(Box* self, visitproc visit, void* arg) noexcept;
......
...@@ -38,7 +38,7 @@ public: ...@@ -38,7 +38,7 @@ public:
Py_INCREF(obj_type); Py_INCREF(obj_type);
} }
DEFAULT_CLASS(super_cls); DEFAULT_CLASS_SIMPLE(super_cls, true);
static void dealloc(Box* b) noexcept { static void dealloc(Box* b) noexcept {
BoxedSuper* self = (BoxedSuper*)b; BoxedSuper* self = (BoxedSuper*)b;
......
...@@ -27,7 +27,7 @@ public: ...@@ -27,7 +27,7 @@ public:
int pos; int pos;
BoxedTupleIterator(BoxedTuple* t); BoxedTupleIterator(BoxedTuple* t);
DEFAULT_CLASS(tuple_iterator_cls); DEFAULT_CLASS_SIMPLE(tuple_iterator_cls, true);
static void dealloc(BoxedTupleIterator* o) noexcept { static void dealloc(BoxedTupleIterator* o) noexcept {
PyObject_GC_UnTrack(o); PyObject_GC_UnTrack(o);
......
...@@ -2265,14 +2265,13 @@ private: ...@@ -2265,14 +2265,13 @@ private:
public: public:
AttrWrapperIter(AttrWrapper* aw); AttrWrapperIter(AttrWrapper* aw);
DEFAULT_CLASS(attrwrapperiter_cls); DEFAULT_CLASS_SIMPLE(attrwrapperiter_cls, false);
static Box* hasnext(Box* _self); static Box* hasnext(Box* _self);
static Box* next(Box* _self); static Box* next(Box* _self);
static Box* next_capi(Box* _self) noexcept; static Box* next_capi(Box* _self) noexcept;
static void dealloc(Box* b) noexcept; static void dealloc(Box* b) noexcept;
static int traverse(Box* self, visitproc visit, void* arg) noexcept;
}; };
// A dictionary-like wrapper around the attributes array. // A dictionary-like wrapper around the attributes array.
......
...@@ -1116,7 +1116,7 @@ public: ...@@ -1116,7 +1116,7 @@ public:
BoxedBuiltinFunctionOrMethod(FunctionMetadata* f, const char* name, std::initializer_list<Box*> defaults, BoxedBuiltinFunctionOrMethod(FunctionMetadata* f, const char* name, std::initializer_list<Box*> defaults,
BoxedClosure* closure = NULL, const char* doc = NULL); BoxedClosure* closure = NULL, const char* doc = NULL);
DEFAULT_CLASS(builtin_function_or_method_cls); DEFAULT_CLASS_SIMPLE(builtin_function_or_method_cls, true);
}; };
extern "C" void _PyModule_Clear(PyObject*) noexcept; extern "C" void _PyModule_Clear(PyObject*) noexcept;
...@@ -1268,7 +1268,7 @@ public: ...@@ -1268,7 +1268,7 @@ public:
void* stack_begin; void* stack_begin;
FrameInfo* top_caller_frame_info; // The FrameInfo that called into this generator. FrameInfo* top_caller_frame_info; // The FrameInfo that called into this generator.
// For abandoned-generator collection -- WIP // For abandoned-generator collection
FrameInfo* paused_frame_info; // The FrameInfo the generator was on when it called yield (or NULL if the generator FrameInfo* paused_frame_info; // The FrameInfo the generator was on when it called yield (or NULL if the generator
// hasn't started or has exited). // hasn't started or has exited).
...@@ -1281,7 +1281,7 @@ public: ...@@ -1281,7 +1281,7 @@ public:
BoxedGenerator(BoxedFunctionBase* function, Box* arg1, Box* arg2, Box* arg3, Box** args); BoxedGenerator(BoxedFunctionBase* function, Box* arg1, Box* arg2, Box* arg3, Box** args);
DEFAULT_CLASS(generator_cls); DEFAULT_CLASS_SIMPLE(generator_cls, true);
}; };
Box* objectSetattr(Box* obj, Box* attr, Box* value); Box* objectSetattr(Box* obj, Box* attr, Box* value);
......
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