[pypy-svn] r68646 - in pypy/branch/gc-arena/pypy/rpython: lltypesystem memory/gc

arigo at codespeak.net arigo at codespeak.net
Mon Oct 19 18:26:18 CEST 2009


Author: arigo
Date: Mon Oct 19 18:26:18 2009
New Revision: 68646

Modified:
   pypy/branch/gc-arena/pypy/rpython/lltypesystem/llarena.py
   pypy/branch/gc-arena/pypy/rpython/lltypesystem/llarena_generic.py
   pypy/branch/gc-arena/pypy/rpython/lltypesystem/llarena_nt.py
   pypy/branch/gc-arena/pypy/rpython/lltypesystem/llarena_posix.py
   pypy/branch/gc-arena/pypy/rpython/memory/gc/semispace.py
Log:
Clarify the out-of-memory behavior of the llarena functions.  For now it
seems saner to say that they all raise OutOfMemoryError instead of doing
something like returning NULL, because arena_reset(Z_ACCESSIBLE) can
also raise OutOfMemoryError.


Modified: pypy/branch/gc-arena/pypy/rpython/lltypesystem/llarena.py
==============================================================================
--- pypy/branch/gc-arena/pypy/rpython/lltypesystem/llarena.py	(original)
+++ pypy/branch/gc-arena/pypy/rpython/lltypesystem/llarena.py	Mon Oct 19 18:26:18 2009
@@ -27,6 +27,7 @@
 
 implements_inaccessible = llarena_impl.implements_inaccessible
 getpagesize = llarena_impl.getpagesize
+OutOfMemoryError = llarena_impl.OutOfMemoryError
 
 register_external(arena_malloc, [int, int], llmemory.Address,
                   'll_arena.arena_malloc',

Modified: pypy/branch/gc-arena/pypy/rpython/lltypesystem/llarena_generic.py
==============================================================================
--- pypy/branch/gc-arena/pypy/rpython/lltypesystem/llarena_generic.py	(original)
+++ pypy/branch/gc-arena/pypy/rpython/lltypesystem/llarena_generic.py	Mon Oct 19 18:26:18 2009
@@ -5,6 +5,9 @@
 
 implements_inaccessible = False
 
+class OutOfMemoryError(Exception):
+    pass
+
 # a random value, but nothing really depends on it
 def getpagesize():
     return 4096
@@ -12,8 +15,9 @@
 # llimpl_arena_*() functions based on raw_malloc
 def llimpl_arena_malloc(nbytes, zero):
     addr = llmemory.raw_malloc(nbytes)
-    if bool(addr):
-        llimpl_arena_reset(addr, nbytes, zero)
+    if not addr:
+        raise OutOfMemoryError
+    llimpl_arena_reset(addr, nbytes, zero)
     return addr
 
 def llimpl_arena_free(arena_addr, nbytes):

Modified: pypy/branch/gc-arena/pypy/rpython/lltypesystem/llarena_nt.py
==============================================================================
--- pypy/branch/gc-arena/pypy/rpython/lltypesystem/llarena_nt.py	(original)
+++ pypy/branch/gc-arena/pypy/rpython/lltypesystem/llarena_nt.py	Mon Oct 19 18:26:18 2009
@@ -9,6 +9,12 @@
 
 implements_inaccessible = True
 
+class OutOfMemoryError(Exception):
+    pass
+
+class VirtualFreeInternalError(Exception):
+    pass
+
 # ____________________________________________________________
 
 class CConfig:
@@ -76,7 +82,7 @@
                           rffi.cast(DWORD, flags),
                           rffi.cast(DWORD, protect))
     if result == llmemory.NULL:
-        raise VirtualAllocMemoryError
+        raise OutOfMemoryError
     return result
 
 def _virtual_free(arena_addr, nbytes, flags):
@@ -84,7 +90,7 @@
                          rffi.cast(rffi.SIZE_T, nbytes),
                          rffi.cast(DWORD, flags))
     if rffi.cast(lltype.Signed, result) == 0:
-        raise VirtualAllocMemoryError
+        raise VirtualFreeInternalError
 
 def llimpl_arena_malloc(nbytes, zero):
     flAllocationType = MEM_RESERVE

Modified: pypy/branch/gc-arena/pypy/rpython/lltypesystem/llarena_posix.py
==============================================================================
--- pypy/branch/gc-arena/pypy/rpython/lltypesystem/llarena_posix.py	(original)
+++ pypy/branch/gc-arena/pypy/rpython/lltypesystem/llarena_posix.py	Mon Oct 19 18:26:18 2009
@@ -7,6 +7,12 @@
 
 implements_inaccessible = True
 
+class OutOfMemoryError(Exception):
+    pass
+
+class MMapInternalError(Exception):
+    pass
+
 # ____________________________________________________________
 
 posix_getpagesize = rffi.llexternal('getpagesize', [], rffi.INT,
@@ -122,9 +128,6 @@
                                  rffi.INT,
                                  sandboxsafe=True, _nowrapper=True)
 
-class MMapMemoryError(Exception):
-    pass
-
 def llimpl_arena_malloc(nbytes, zero):
     flags = MAP_PRIVATE | MAP_ANONYMOUS
     if zero == Z_INACCESSIBLE:
@@ -140,20 +143,20 @@
                         rffi.cast(rffi.INT, -1),
                         rffi.cast(off_t, 0))
     if rffi.cast(lltype.Signed, result) == -1:
-        raise MMapMemoryError
+        raise OutOfMemoryError
     return result
 
 def llimpl_arena_free(arena_addr, nbytes):
     result = posix_munmap(arena_addr, rffi.cast(rffi.SIZE_T, nbytes))
     if rffi.cast(lltype.Signed, result) == -1:
-        raise MMapMemoryError
+        raise MMapInternalError
 
 def _arena_protect(arena_addr, size, flags):
     res = posix_mprotect(arena_addr,
                          rffi.cast(rffi.SIZE_T, size),
                          rffi.cast(rffi.INT, flags))
     if rffi.cast(lltype.Signed, res) != 0:
-        raise MMapMemoryError
+        raise OutOfMemoryError
 
 def llimpl_arena_reset(arena_addr, size, zero):
     if zero == Z_CLEAR_LARGE_AREA:

Modified: pypy/branch/gc-arena/pypy/rpython/memory/gc/semispace.py
==============================================================================
--- pypy/branch/gc-arena/pypy/rpython/memory/gc/semispace.py	(original)
+++ pypy/branch/gc-arena/pypy/rpython/memory/gc/semispace.py	Mon Oct 19 18:26:18 2009
@@ -61,11 +61,9 @@
             self.program_start_time = time.time()
         self.tospace = llarena.arena_malloc(self.space_size,
                                             llarena.Z_CLEAR_LARGE_AREA)
-        ll_assert(bool(self.tospace), "couldn't allocate tospace")
         self.top_of_space = self.tospace + self.space_size
         self.fromspace = llarena.arena_malloc(self.space_size,
                                               llarena.Z_CLEAR_LARGE_AREA)
-        ll_assert(bool(self.fromspace), "couldn't allocate fromspace")
         self.free = self.tospace
         MovingGCBase.setup(self)
         self.objects_with_finalizers = self.AddressDeque()
@@ -155,8 +153,10 @@
         old_fromspace = self.fromspace
         oldsize = self.space_size
         newsize = self.space_size * 2
-        newspace = llarena.arena_malloc(newsize, llarena.Z_CLEAR_LARGE_AREA)
-        if not newspace:
+        try:
+            newspace = llarena.arena_malloc(newsize,
+                                            llarena.Z_CLEAR_LARGE_AREA)
+        except llarena.OutOfMemoryError:
             return False    # out of memory
         llarena.arena_free(old_fromspace, oldsize)
         self.fromspace = newspace
@@ -169,8 +169,10 @@
         # and self.fromspace is the old smaller space, now empty
         llarena.arena_free(self.fromspace, oldsize)
 
-        newspace = llarena.arena_malloc(newsize, llarena.Z_CLEAR_LARGE_AREA)
-        if not newspace:
+        try:
+            newspace = llarena.arena_malloc(newsize,
+                                            llarena.Z_CLEAR_LARGE_AREA)
+        except llarena.OutOfMemoryError:
             # Complex failure case: we have in self.tospace a big chunk
             # of memory, and the two smaller original spaces are already gone.
             # Unsure if it's worth these efforts, but we can artificially



More information about the Pypy-commit mailing list