Commits

Mark Shannon committed 983fdf7 Draft

Add poly_value to trace object and fix failure in test_pickle

Comments (0)

Files changed (4)

Include/optimiser.h

     PyObject *trace_guarded_by;
     PyObject *trace_weakrefs; /* List of weak references */
     PyDictKeysObject **trace_keys;
+    PyObject *poly_value;
 };
 
 void HotPyTraceObject_Init(HotPyTraceObject*, PyObject*, PyObject*, PyObject*, PyObject*);

Python/register_interpreter.c

                 else
                     break;
             }
-            else if (poly_exit->entries[i].value == NULL)
+            else if (poly_exit->entries[i].value == NULL) {
                 assert(poly_exit->entries[i].execution_count == 0);
                 poly_exit->entries[i].execution_count = 1;
                 Py_INCREF(value);
                 poly_exit->entries[i].value = value;
                 break;
+            }
         }
         if (i < HOTPY_POLYMORPHIC_LIMIT) {
             assert(poly_exit->entries[i].value == value);

Python/trace_interpreter.c

                 else
                     break;
             }
-            else if (poly_exit->entries[i].value == NULL)
+            else if (poly_exit->entries[i].value == NULL) {
                 assert(poly_exit->entries[i].execution_count == 0);
                 poly_exit->entries[i].execution_count = 1;
                 poly_exit->entries[i].value = value;
+                assert(poly_exit->entries[i].trace == NULL);
                 break;
+            }
         }
         if (i < HOTPY_POLYMORPHIC_LIMIT) {
             assert(poly_exit->entries[i].value == value);
                 if (exit_trace) {
                     poly_exit->entries[i].trace = exit_trace;
                     exit_trace->execution_count = poly_exit->entries[i].execution_count;
+                    assert(poly_exit->entries[i].trace->poly_value == poly_exit->entries[i].value);
                     goto execute_trace;
                 }
             }

Python/trace_manager.c

     Py_XDECREF(trace->trace_context);
     Py_XDECREF(trace->trace_names);
     Py_XDECREF(trace->trace_guarded_by);
+    Py_XDECREF(trace->poly_value);
     PyObject_GC_Del(trace);
     Py_TRASHCAN_SAFE_END(trace)
 }
     Py_VISIT(trace->trace_context);
     Py_VISIT(trace->trace_names);
     Py_VISIT(trace->trace_guarded_by);
+    Py_VISIT(trace->poly_value);
     return 0;
 }
 
     trace->status = TRACE_INVALID;
     trace->trace_weakrefs = NULL;
     trace->trace_keys = NULL;
+    trace->poly_value = NULL;
     PyObject_GC_Track(trace);
     return trace;
 }
         trace = new_trace_object(ctx);
         if (trace == NULL)
             return NULL;
+        Py_INCREF(value);
+        trace->poly_value = value;
         PyDict_SetItem(tstate->trace_cache, (PyObject *)key, (PyObject *)trace);
         /* Copy execution count */
         trace->execution_count = 0;
             HotPyExitEntry *ep0;
             assert(Py_TYPE(exit) == &HotPyPolyExit_Type);
             ep0 = &poly->entries[0];
-            for (k = 0; k < HOTPY_POLYMORPHIC_LIMIT; k++)
+            for (k = 0; k < HOTPY_POLYMORPHIC_LIMIT; k++) {
+                assert(ep0[k].trace == NULL ||
+                       ep0[k].trace->poly_value == ep0[k].value);
                 if (ep0[k].value == NULL)
                     break;
+            }
             /* Bubble sort entries into decending order of execution count */
             for (i = 0; i < k-1; i++) {
                 for (j = k-1; j > i; j--) {
             for (i = 0; i < HOTPY_POLYMORPHIC_LIMIT-1; i++)
                 assert(ep0[i].execution_count >= ep0[i+1].execution_count);
             for (i = 0; i < HOTPY_POLYMORPHIC_LIMIT; i++) {
+                assert(ep0[i].trace == NULL ||
+                       ep0[i].trace->poly_value == ep0[i].value);
                 if (ep0[i].execution_count) {
                     assert(ep0[i].value);
                 }