Commits

Maciej Fijalkowski committed 206f4c0 Draft

progress. a 2 day 50 loc function

Comments (0)

Files changed (3)

pypy/jit/metainterp/compile.py

         self.copy_all_attributes_into(res)
         return res
 
-@specialize.arg(2)
-def read_field_from_resume(cpu, token, fieldname):
+@specialize.arg(4)
+def read_field_from_resume(cpu, token, descr, vinst, TP):
     faildescr = cpu.force(token)
     assert isinstance(faildescr, ResumeGuardForcedDescr)
-    return faildescr.handle_async_field_read(token, fieldname)
+    return faildescr.handle_async_field_read(token, descr, vinst, TP)
 
 class ResumeGuardForcedDescr(ResumeGuardDescr):
 
         # future failure of the GUARD_NOT_FORCED
         self.save_data(force_token, all_virtuals)
 
-    @specialize.arg(2)
-    def handle_async_field_read(self, force_token, fieldname):
+    @specialize.arg(4)
+    def handle_async_field_read(self, force_token, descr, vinst, TP):
         from pypy.jit.metainterp.resume import read_field_from_resumedata
         metainterp_sd = self.metainterp_sd
+        vinfo = self.jitdriver_sd.virtualizable_info
         ginfo = self.jitdriver_sd.greenfield_info
-        return read_field_from_resumedata(metainterp_sd, self, ginfo)
+        return read_field_from_resumedata(metainterp_sd, self, vinfo, ginfo,
+                                          descr, vinst, TP)
 
     def save_data(self, key, value):
         globaldata = self.metainterp_sd.globaldata

pypy/jit/metainterp/resume.py

     resumereader.done()
     return resumereader.liveboxes, virtualizable_boxes, virtualref_boxes
 
-def read_field_from_resumedata(metainterp, storage, greenfield_info):
-    xxx
+@specialize.arg(6)
+def read_field_from_resumedata(metainterp_sd, storage, vinfo, greenfield_info,
+                               fielddescr, vinst, RES_TP):
+    cpu = metainterp_sd.cpu
+    numb = storage.rd_numb
+    end = len(numb.nums)
+    vinst = lltype.cast_opaque_ptr(llmemory.GCREF, vinst)
+    for i in range(0, end, 2):
+        # that's a vref
+        num, tag = untag(numb.nums[i + 1])
+        if tag == TAGBOX:
+            inst = cpu.get_latest_value_ref(num)
+            if inst == vinst:
+                # we found the correct vref, now we look for virtuals
+                # that are supposed to be stored in the place.
+                # Note that since we passed the vref to a residual
+                # call, it cannot potentially be virtual
+                num, tag = untag(numb.nums[i])
+                if tag != TAGVIRTUAL:
+                    raise Exception("I'm not sure if this can happen, non-virtual, but not stored in a vref")
+                vinfo = storage.rd_virtuals[num]
+                for j, descr in enumerate(vinfo.fielddescrs):
+                    if descr == fielddescr:
+                        cpunum, tag = untag(vinfo.fieldnums[j])
+                        assert tag in [TAGBOX, TAGCONST, TAGINT]
+                        # no support for virtuals
+                        if descr.is_pointer_field():
+                            xxx
+                        elif descr.is_float_field():
+                            xxx
+                        else:
+                            if tag == TAGINT:
+                                return rffi.cast(RES_TP, cpunum)
+                            xxx
+                else:
+                    assert False, "unreachable code"
+    else:
+        assert False, "cannot find the correct vref"
+
 
 class ResumeDataBoxReader(AbstractResumeDataReader):
     unique_id = lambda: None

pypy/jit/metainterp/virtualref.py

         return inputconst(lltype.typeOf(funcptr), funcptr)
 
     def get_vref_getfield_fnptr(self, name, RES_TP):
+        descr = self.cpu.fielddescrof(self._vref_T.TO, 'inst_' + name)
+        
         def read_virtual_field(inst):
             if inst.typeptr != self.jit_virtual_ref_vtable:
                 inst = lltype.cast_pointer(self._vref_T, inst)
                 # not a virtual at all, just pretending to be one
                 forced = lltype.cast_pointer(self._vref_T, vref.forced)
                 return getattr(forced, 'inst_' + name)
-            else: 
+            else:
                 assert not vref.forced
                 from pypy.jit.metainterp.compile import read_field_from_resume
-                return read_field_from_resume(self.cpu, token, name)
+                return read_field_from_resume(self.cpu, token, descr, vref,
+                                              RES_TP)
                 
         FUNC = lltype.FuncType([rclass.OBJECTPTR], RES_TP)
         funcptr = self.warmrunnerdesc.helper_func(