コード例 #1
0
 def _make_layoutbuilder(self):
     # make a TransformerLayoutBuilder and save it on the translator
     # where it can be fished and reused by the FrameworkGCTransformer
     from pypy.rpython.memory.gctransform import framework
     translator = self.translator
     self.layoutbuilder = framework.TransformerLayoutBuilder(translator)
     self.layoutbuilder.delay_encoding()
     translator._jit2gc = {'layoutbuilder': self.layoutbuilder}
     self.gcrootmap.add_jit2gc_hooks(translator._jit2gc)
コード例 #2
0
 def ensure_layoutbuilder(cls, translator):
     jit2gc = getattr(translator, '_jit2gc', None)
     if jit2gc:
         return jit2gc['layoutbuilder']
     GCClass = cls.gcpolicy.transformerclass.GCClass
     layoutbuilder = framework.TransformerLayoutBuilder(translator, GCClass)
     layoutbuilder.delay_encoding()
     translator._jit2gc = {
         'layoutbuilder': layoutbuilder,
     }
     return layoutbuilder
コード例 #3
0
ファイル: gc.py プロジェクト: xx312022850/pypy
    def __init__(self, gcdescr, translator, llop1=llop):
        from pypy.rpython.memory.gctypelayout import _check_typeid
        from pypy.rpython.memory.gcheader import GCHeaderBuilder
        from pypy.rpython.memory.gctransform import framework
        GcLLDescription.__init__(self, gcdescr, translator)
        assert self.translate_support_code, "required with the framework GC"
        self.translator = translator
        self.llop1 = llop1

        # we need the hybrid GC for GcRefList.alloc_gcref_list() to work
        if gcdescr.config.translation.gc != 'hybrid':
            raise NotImplementedError("--gc=%s not implemented with the JIT" %
                                      (gcdescr.config.translation.gc, ))

        # to find roots in the assembler, make a GcRootMap
        name = gcdescr.config.translation.gcrootfinder
        try:
            cls = globals()['GcRootMap_' + name]
        except KeyError:
            raise NotImplementedError("--gcrootfinder=%s not implemented"
                                      " with the JIT" % (name, ))
        gcrootmap = cls()
        self.gcrootmap = gcrootmap
        self.gcrefs = GcRefList()
        self.single_gcref_descr = GcPtrFieldDescr(0)

        # make a TransformerLayoutBuilder and save it on the translator
        # where it can be fished and reused by the FrameworkGCTransformer
        self.layoutbuilder = framework.TransformerLayoutBuilder(translator)
        self.layoutbuilder.delay_encoding()
        self.translator._jit2gc = {
            'layoutbuilder': self.layoutbuilder,
            'gcmapstart': lambda: gcrootmap.gcmapstart(),
            'gcmapend': lambda: gcrootmap.gcmapend(),
        }
        self.GCClass = self.layoutbuilder.GCClass
        self.moving_gc = self.GCClass.moving_gc
        self.HDRPTR = lltype.Ptr(self.GCClass.HDR)
        self.gcheaderbuilder = GCHeaderBuilder(self.HDRPTR.TO)
        (self.array_basesize, _, self.array_length_ofs) = \
             symbolic.get_array_token(lltype.GcArray(lltype.Signed), True)
        min_ns = self.GCClass.TRANSLATION_PARAMS['min_nursery_size']
        self.max_size_of_young_obj = self.GCClass.get_young_fixedsize(min_ns)

        # make a malloc function, with three arguments
        def malloc_basic(size, tid):
            type_id = llop.extract_ushort(rffi.USHORT, tid)
            has_finalizer = bool(tid & (1 << 16))
            _check_typeid(type_id)
            try:
                res = llop1.do_malloc_fixedsize_clear(llmemory.GCREF, type_id,
                                                      size, True,
                                                      has_finalizer, False)
            except MemoryError:
                fatalerror("out of memory (from JITted code)")
                res = lltype.nullptr(llmemory.GCREF.TO)
            #llop.debug_print(lltype.Void, "\tmalloc_basic", size, type_id,
            #                 "-->", res)
            return res

        self.malloc_basic = malloc_basic
        self.GC_MALLOC_BASIC = lltype.Ptr(
            lltype.FuncType([lltype.Signed, lltype.Signed], llmemory.GCREF))
        self.WB_FUNCPTR = lltype.Ptr(
            lltype.FuncType([llmemory.Address, llmemory.Address], lltype.Void))
        self.write_barrier_descr = WriteBarrierDescr(self)

        #
        def malloc_array(itemsize, tid, num_elem):
            type_id = llop.extract_ushort(rffi.USHORT, tid)
            _check_typeid(type_id)
            try:
                return llop1.do_malloc_varsize_clear(
                    llmemory.GCREF, type_id, num_elem, self.array_basesize,
                    itemsize, self.array_length_ofs, True)
            except MemoryError:
                fatalerror("out of memory (from JITted code)")
                return lltype.nullptr(llmemory.GCREF.TO)

        self.malloc_array = malloc_array
        self.GC_MALLOC_ARRAY = lltype.Ptr(
            lltype.FuncType([lltype.Signed] * 3, llmemory.GCREF))
        #
        (str_basesize, str_itemsize,
         str_ofs_length) = symbolic.get_array_token(rstr.STR, True)
        (unicode_basesize, unicode_itemsize,
         unicode_ofs_length) = symbolic.get_array_token(rstr.UNICODE, True)
        str_type_id = self.layoutbuilder.get_type_id(rstr.STR)
        unicode_type_id = self.layoutbuilder.get_type_id(rstr.UNICODE)

        #
        def malloc_str(length):
            try:
                return llop1.do_malloc_varsize_clear(llmemory.GCREF,
                                                     str_type_id, length,
                                                     str_basesize,
                                                     str_itemsize,
                                                     str_ofs_length, True)
            except MemoryError:
                fatalerror("out of memory (from JITted code)")
                return lltype.nullptr(llmemory.GCREF.TO)

        def malloc_unicode(length):
            try:
                return llop1.do_malloc_varsize_clear(llmemory.GCREF,
                                                     unicode_type_id, length,
                                                     unicode_basesize,
                                                     unicode_itemsize,
                                                     unicode_ofs_length, True)
            except MemoryError:
                fatalerror("out of memory (from JITted code)")
                return lltype.nullptr(llmemory.GCREF.TO)

        self.malloc_str = malloc_str
        self.malloc_unicode = malloc_unicode
        self.GC_MALLOC_STR_UNICODE = lltype.Ptr(
            lltype.FuncType([lltype.Signed], llmemory.GCREF))

        def malloc_fixedsize_slowpath(size):
            try:
                gcref = llop1.do_malloc_fixedsize_clear(
                    llmemory.GCREF, 0, size, True, False, False)
            except MemoryError:
                fatalerror("out of memory (from JITted code)")
                return r_ulonglong(0)
            res = rffi.cast(lltype.Signed, gcref)
            nurs_free = llop1.gc_adr_of_nursery_free(
                llmemory.Address).signed[0]
            return r_ulonglong(nurs_free) << 32 | r_ulonglong(r_uint(res))

        self.malloc_fixedsize_slowpath = malloc_fixedsize_slowpath
        self.MALLOC_FIXEDSIZE_SLOWPATH = lltype.FuncType(
            [lltype.Signed], lltype.UnsignedLongLong)