Пример #1
0
 def generate_function(self, funcname, func, ARGS, RESULT=llmemory.GCREF):
     """Generates a variant of malloc with the given name and the given
     arguments.  It should return NULL if out of memory.  If it raises
     anything, it must be an optional MemoryError.
     """
     FUNCPTR = lltype.Ptr(lltype.FuncType(ARGS, RESULT))
     descr = get_call_descr(self, ARGS, RESULT)
     setattr(self, funcname, func)
     setattr(self, funcname + '_FUNCPTR', FUNCPTR)
     setattr(self, funcname + '_descr', descr)
     self._generated_functions.append(funcname)
Пример #2
0
 def generate_function(self, funcname, func, ARGS, RESULT=llmemory.GCREF):
     """Generates a variant of malloc with the given name and the given
     arguments.  It should return NULL if out of memory.  If it raises
     anything, it must be an optional MemoryError.
     """
     FUNCPTR = lltype.Ptr(lltype.FuncType(ARGS, RESULT))
     descr = get_call_descr(self, ARGS, RESULT)
     setattr(self, funcname, func)
     setattr(self, funcname + '_FUNCPTR', FUNCPTR)
     setattr(self, funcname + '_descr', descr)
     self._generated_functions.append(funcname)
Пример #3
0
 def calldescrof(self, FUNC, ARGS, RESULT, extrainfo=None):
     return get_call_descr(self.gc_ll_descr, ARGS, RESULT, extrainfo)
Пример #4
0
 def calldescrof(self, FUNC, ARGS, RESULT, extrainfo):
     return get_call_descr(self.gc_ll_descr, ARGS, RESULT, extrainfo)
Пример #5
0
    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.JITTransformerLayoutBuilder(
            gcdescr.config)
        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.fielddescr_tid = get_field_descr(self, self.GCClass.HDR, 'tid')
        self.c_jit_wb_if_flag = ConstInt(self.GCClass.JIT_WB_IF_FLAG)
        self.calldescr_jit_wb = get_call_descr(
            self, [llmemory.GCREF, llmemory.GCREF], lltype.Void)
        (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)
            res = llop1.do_malloc_fixedsize_clear(llmemory.GCREF, type_id,
                                                  size, True, has_finalizer,
                                                  False)
            #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))

        #
        def malloc_array(itemsize, tid, num_elem):
            type_id = llop.extract_ushort(rffi.USHORT, tid)
            _check_typeid(type_id)
            return llop1.do_malloc_varsize_clear(llmemory.GCREF, type_id,
                                                 num_elem, self.array_basesize,
                                                 itemsize,
                                                 self.array_length_ofs, True)

        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):
            return llop1.do_malloc_varsize_clear(llmemory.GCREF, str_type_id,
                                                 length, str_basesize,
                                                 str_itemsize, str_ofs_length,
                                                 True)

        def malloc_unicode(length):
            return llop1.do_malloc_varsize_clear(llmemory.GCREF,
                                                 unicode_type_id, length,
                                                 unicode_basesize,
                                                 unicode_itemsize,
                                                 unicode_ofs_length, True)

        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):
            gcref = llop1.do_malloc_fixedsize_clear(llmemory.GCREF, 0, size,
                                                    True, False, False)
            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)
Пример #6
0
    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.JITTransformerLayoutBuilder(
            gcdescr.config)
        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.fielddescr_tid = get_field_descr(self, self.GCClass.HDR, 'tid')
        self.c_jit_wb_if_flag = ConstInt(self.GCClass.JIT_WB_IF_FLAG)
        self.calldescr_jit_wb = get_call_descr(self, [llmemory.GCREF,
                                                      llmemory.GCREF],
                                               lltype.Void)
        (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)
            res = llop1.do_malloc_fixedsize_clear(llmemory.GCREF,
                                                  type_id, size, True,
                                                  has_finalizer, False)
            #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))
        #
        def malloc_array(itemsize, tid, num_elem):
            type_id = llop.extract_ushort(rffi.USHORT, tid)
            _check_typeid(type_id)
            return llop1.do_malloc_varsize_clear(
                llmemory.GCREF,
                type_id, num_elem, self.array_basesize, itemsize,
                self.array_length_ofs, True)
        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):
            return llop1.do_malloc_varsize_clear(
                llmemory.GCREF,
                str_type_id, length, str_basesize, str_itemsize,
                str_ofs_length, True)
        def malloc_unicode(length):
            return llop1.do_malloc_varsize_clear(
                llmemory.GCREF,
                unicode_type_id, length, unicode_basesize, unicode_itemsize,
                unicode_ofs_length, True)
        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):
            gcref = llop1.do_malloc_fixedsize_clear(llmemory.GCREF,
                                        0, size, True, False, False)
            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)
Пример #7
0
 def calldescrof(self, FUNC, ARGS, RESULT):
     return get_call_descr(self.gc_ll_descr, ARGS, RESULT)