ソースを参照

Change how the JIT is enabled/disabled

jonathanvdc 8 年 前
コミット
174ef72417
2 ファイル変更15 行追加10 行削除
  1. 10 3
      kernel/modelverse_jit/jit.py
  2. 5 7
      kernel/modelverse_kernel/main.py

+ 10 - 3
kernel/modelverse_jit/jit.py

@@ -20,6 +20,11 @@ class ModelverseJit(object):
         }
         self.jit_count = 0
         self.max_instructions = 30 if max_instructions is None else max_instructions
+        self.jit_enabled = True
+
+    def set_jit_enabled(self, is_enabled=True):
+        """Enables or disables the JIT."""
+        self.jit_enabled = is_enabled
 
     def mark_entry_point(self, body_id):
         """Marks the node with the given identifier as a function entry point."""
@@ -34,9 +39,11 @@ class ModelverseJit(object):
 
     def is_jittable_entry_point(self, body_id):
         """Tells if the node with the given identifier is a function entry point that
-           has not been marked as non-jittable."""
-        return body_id in self.todo_entry_points or \
-               body_id in self.jitted_entry_points
+           has not been marked as non-jittable. This only returns `True` if the JIT
+           is enabled"""
+        return self.jit_enabled and (
+            body_id in self.todo_entry_points or
+            body_id in self.jitted_entry_points)
 
     def mark_no_jit(self, body_id):
         """Informs the JIT that the node with the given identifier is a function entry

+ 5 - 7
kernel/modelverse_kernel/main.py

@@ -21,8 +21,9 @@ class ModelverseKernel(object):
         #self.allow_compiled = False
 
         # `self.jit` handles most JIT-related functionality.
-        # Set it to `None` to disable the JIT.
         self.jit = jit.ModelverseJit()
+        # To disable the JIT, uncomment the line below:
+        #     self.jit.set_jit_enabled(False)
         self.debug_info = "(no debug information found)"
 
     def execute_yields(self, username, operation, params, reply):
@@ -65,8 +66,7 @@ class ModelverseKernel(object):
         elif inst is None:
             raise Exception("Instruction pointer could not be found!")
         elif isinstance(phase_v, string_types):
-            if phase_v == "init" and (inst in self.compiled or \
-                (self.jit is not None and self.jit.is_jittable_entry_point(inst))):
+            if phase_v == "init" and (inst in self.compiled or self.jit.is_jittable_entry_point(inst)):
                 #print("%-30s(%s)" % ("COMPILED " + str(self.compiled[inst]), phase_v))
                 gen = self.execute_primitive_or_jit(user_root, inst, username)
             elif inst_v is None:
@@ -693,8 +693,7 @@ class ModelverseKernel(object):
         if param is None:
             returnvalue, =  yield [("RD", [user_frame, "returnvalue"])]
             body, =         yield [("RD", [returnvalue, "body"])]
-            if self.jit is not None:
-                self.jit.mark_entry_point(body)
+            self.jit.mark_entry_point(body)
 
             phase_link, frame_link, prev_phase, new_phase, new_frame, new_evalstack, new_symbols, new_returnvalue = \
                             yield [("RDE", [user_frame, "phase"]),
@@ -739,8 +738,7 @@ class ModelverseKernel(object):
                                   ]
 
             body, =         yield [("RD", [new_IP, "body"])]
-            if self.jit is not None:
-                self.jit.mark_entry_point(body)
+            self.jit.mark_entry_point(body)
             
             name, =         yield [("RD", [last_param, "name"])]
             name_value, =   yield [("RV", [name])]