def test_py_code(self) -> None: code_obj = _jit_function_2.__code__ cinderjit.jit_list_append( f"{code_obj.co_name}@{code_obj.co_filename}:{code_obj.co_firstlineno}" ) py_code_objs = cinderjit.get_jit_list()[1] thisfile = os.path.basename(__file__) self.assertIn(code_obj.co_firstlineno, py_code_objs[code_obj.co_name][thisfile]) self.assertNotIn(_no_jit_function.__code__.co_name, py_code_objs) _jit_function_2() self.assertTrue(cinderjit.is_jit_compiled(_jit_function_2)) _no_jit_function() self.assertFalse(cinderjit.is_jit_compiled(_no_jit_function))
def test_py_function(self) -> None: meth = _JitClass.jitMethod func = _jit_function_1 cinderjit.jit_list_append(f"{meth.__module__}:{meth.__qualname__}") cinderjit.jit_list_append(f"{func.__module__}:{func.__qualname__}") py_funcs = cinderjit.get_jit_list()[0] self.assertIn(meth.__qualname__, py_funcs[__name__]) self.assertIn(func.__qualname__, py_funcs[__name__]) self.assertNotIn(_no_jit_function.__qualname__, py_funcs[__name__]) meth(None) self.assertTrue(cinderjit.is_jit_compiled(meth)) func() self.assertTrue(cinderjit.is_jit_compiled(func)) _no_jit_function() self.assertFalse(cinderjit.is_jit_compiled(_no_jit_function))
def test_function(self): # Tricky: f -> d -> f, code should call d.clear() after the exec to # break the cycle. d = {} exec("def f(): pass\n", d) try: import cinderjit is_jit_compiled = cinderjit.is_jit_compiled(d["f"]) except ImportError: is_jit_compiled = False gc.collect() del d if is_jit_compiled: # If the JIT is enabled and f ends up getting JIT-compiled, we'll # store a weak reference to it. When gc.collect() is called, that # weakref will be collected, thereby increasing the count from 2 # to 3. self.assertEqual(gc.collect(), 3) else: self.assertEqual(gc.collect(), 2)
def assert_not_jitted(self, func): if cinderjit is None: return self.assertFalse(cinderjit.is_jit_compiled(func))
def assert_jitted(self, func): if cinderjit is None: return self.assertTrue(cinderjit.is_jit_compiled(func), func.__name__)