[pypy-svn] r76908 - in pypy/branch/gc-module/pypy: rlib rpython/memory/gc rpython/memory/gctransform translator/c/test
arigo at codespeak.net
arigo at codespeak.net
Tue Sep 7 11:13:58 CEST 2010
Author: arigo
Date: Tue Sep 7 11:13:56 2010
New Revision: 76908
Modified:
pypy/branch/gc-module/pypy/rlib/rgc.py
pypy/branch/gc-module/pypy/rpython/memory/gc/base.py
pypy/branch/gc-module/pypy/rpython/memory/gc/markcompact.py
pypy/branch/gc-module/pypy/rpython/memory/gc/semispace.py
pypy/branch/gc-module/pypy/rpython/memory/gctransform/framework.py
pypy/branch/gc-module/pypy/translator/c/test/test_newgc.py
Log:
Translation of get_rpy_memory_usage().
Modified: pypy/branch/gc-module/pypy/rlib/rgc.py
==============================================================================
--- pypy/branch/gc-module/pypy/rlib/rgc.py (original)
+++ pypy/branch/gc-module/pypy/rlib/rgc.py Tue Sep 7 11:13:56 2010
@@ -356,6 +356,12 @@
size += Class.__itemsize__ * len(gcref._x)
return size
+def get_rpy_typeid(gcref):
+ "NOT_RPYTHON"
+ from pypy.rlib.rarithmetic import intmask
+ Class = gcref._x.__class__
+ return intmask(id(Class))
+
def cast_gcref_to_int(gcref):
if we_are_translated():
return cast_ptr_to_int(gcref)
@@ -447,6 +453,26 @@
return hop.genop('gc_get_rpy_referents', vlist,
resulttype = hop.r_result)
+class Entry(ExtRegistryEntry):
+ _about_ = get_rpy_memory_usage
+ def compute_result_annotation(self, s_gcref):
+ from pypy.annotation import model as annmodel
+ return annmodel.SomeInteger()
+ def specialize_call(self, hop):
+ vlist = hop.inputargs(hop.args_r[0])
+ return hop.genop('gc_get_rpy_memory_usage', vlist,
+ resulttype = hop.r_result)
+
+class Entry(ExtRegistryEntry):
+ _about_ = get_rpy_typeid
+ def compute_result_annotation(self, s_gcref):
+ from pypy.annotation import model as annmodel
+ return annmodel.SomeInteger()
+ def specialize_call(self, hop):
+ vlist = hop.inputargs(hop.args_r[0])
+ return hop.genop('gc_get_rpy_typeid', vlist,
+ resulttype = hop.r_result)
+
def _is_rpy_instance(gcref):
"NOT_RPYTHON"
raise NotImplementedError
Modified: pypy/branch/gc-module/pypy/rpython/memory/gc/base.py
==============================================================================
--- pypy/branch/gc-module/pypy/rpython/memory/gc/base.py (original)
+++ pypy/branch/gc-module/pypy/rpython/memory/gc/base.py Tue Sep 7 11:13:56 2010
@@ -337,6 +337,10 @@
# ----------
+ def get_rpy_memory_usage(self, gcref):
+ # overridden in semispace.py and markcompact.py to also count the hash
+ return self.get_size(llmemory.cast_ptr_to_adr(gcref))
+
def is_rpy_instance(self, gcref):
typeid = self.get_type_id(llmemory.cast_ptr_to_adr(gcref))
return self.is_rpython_class(typeid)
Modified: pypy/branch/gc-module/pypy/rpython/memory/gc/markcompact.py
==============================================================================
--- pypy/branch/gc-module/pypy/rpython/memory/gc/markcompact.py (original)
+++ pypy/branch/gc-module/pypy/rpython/memory/gc/markcompact.py Tue Sep 7 11:13:56 2010
@@ -674,6 +674,14 @@
return llmemory.cast_adr_to_int(obj) # not in an arena...
return adr - self.space
+ def get_rpy_memory_usage(self, gcref):
+ obj = llmemory.cast_ptr_to_adr(gcref)
+ size = self.get_size(obj)
+ hdr = self.header(obj)
+ if hdr.tid & GCFLAG_HASHFIELD:
+ size += llmemory.sizeof(lltype.Signed)
+ return size
+
# ____________________________________________________________
class CannotAllocateGCArena(Exception):
Modified: pypy/branch/gc-module/pypy/rpython/memory/gc/semispace.py
==============================================================================
--- pypy/branch/gc-module/pypy/rpython/memory/gc/semispace.py (original)
+++ pypy/branch/gc-module/pypy/rpython/memory/gc/semispace.py Tue Sep 7 11:13:56 2010
@@ -331,6 +331,9 @@
size += llmemory.sizeof(lltype.Signed)
return size
+ def get_rpy_memory_usage(self, gcref):
+ return self.get_size_incl_hash(llmemory.cast_ptr_to_adr(gcref))
+
def scan_copied(self, scan):
while scan < self.free:
curr = scan + self.size_gc_header()
Modified: pypy/branch/gc-module/pypy/rpython/memory/gctransform/framework.py
==============================================================================
--- pypy/branch/gc-module/pypy/rpython/memory/gctransform/framework.py (original)
+++ pypy/branch/gc-module/pypy/rpython/memory/gctransform/framework.py Tue Sep 7 11:13:56 2010
@@ -396,6 +396,11 @@
[s_gc, s_gcref],
rgc.s_list_of_gcrefs(),
minimal_transform=False)
+ self.get_rpy_memory_usage_ptr = getfn(
+ GCClass.get_rpy_memory_usage.im_func,
+ [s_gc, s_gcref],
+ annmodel.SomeInteger(),
+ minimal_transform=False)
self.is_rpy_instance_ptr = getfn(GCClass.is_rpy_instance.im_func,
[s_gc, s_gcref],
annmodel.SomeBool(),
@@ -911,6 +916,14 @@
resultvar=hop.spaceop.result)
self.pop_roots(hop, livevars)
+ def gct_gc_get_rpy_memory_usage(self, hop):
+ livevars = self.push_roots(hop)
+ [v_ptr] = hop.spaceop.args
+ hop.genop("direct_call",
+ [self.get_rpy_memory_usage_ptr, self.c_const_gc, v_ptr],
+ resultvar=hop.spaceop.result)
+ self.pop_roots(hop, livevars)
+
def gct_gc_is_rpy_instance(self, hop):
livevars = self.push_roots(hop)
[v_ptr] = hop.spaceop.args
Modified: pypy/branch/gc-module/pypy/translator/c/test/test_newgc.py
==============================================================================
--- pypy/branch/gc-module/pypy/translator/c/test/test_newgc.py (original)
+++ pypy/branch/gc-module/pypy/translator/c/test/test_newgc.py Tue Sep 7 11:13:56 2010
@@ -1002,6 +1002,38 @@
def test_try_cast_gcref_to_instance(self):
self.run("try_cast_gcref_to_instance")
+ def define_get_rpy_memory_usage(self):
+ U = lltype.GcStruct('U', ('x1', lltype.Signed),
+ ('x2', lltype.Signed),
+ ('x3', lltype.Signed),
+ ('x4', lltype.Signed),
+ ('x5', lltype.Signed),
+ ('x6', lltype.Signed),
+ ('x7', lltype.Signed),
+ ('x8', lltype.Signed))
+ S = lltype.GcStruct('S', ('u', lltype.Ptr(U)))
+ A = lltype.GcArray(lltype.Ptr(S))
+
+ def fn():
+ s = lltype.malloc(S)
+ s.u = lltype.malloc(U)
+ a = lltype.malloc(A, 1000)
+ gcref1 = lltype.cast_opaque_ptr(llmemory.GCREF, s)
+ int1 = rgc.get_rpy_memory_usage(gcref1)
+ assert 8 <= int1 <= 32
+ gcref2 = lltype.cast_opaque_ptr(llmemory.GCREF, s.u)
+ int2 = rgc.get_rpy_memory_usage(gcref2)
+ assert 4*9 <= int2 <= 8*12
+ gcref3 = lltype.cast_opaque_ptr(llmemory.GCREF, a)
+ int3 = rgc.get_rpy_memory_usage(gcref3)
+ assert 4*1001 <= int3 <= 8*1010
+ return 0
+
+ return fn
+
+ def test_get_rpy_memory_usage(self):
+ self.run("get_rpy_memory_usage")
+
class TestSemiSpaceGC(TestUsingFramework, snippet.SemiSpaceGCTestDefines):
gcpolicy = "semispace"
More information about the Pypy-commit
mailing list