[pypy-commit] pypy nogil-unsafe: Experimental: playing with a no-gil version of RPython

2017-01-07 Thread arigo
Author: Armin Rigo 
Branch: nogil-unsafe
Changeset: r89407:6cea2be6e621
Date: 2017-01-05 15:22 +0100
http://bitbucket.org/pypy/pypy/changeset/6cea2be6e621/

Log:Experimental: playing with a no-gil version of RPython

___
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy nogil-unsafe: Start, mostly just playing around

2017-01-07 Thread arigo
Author: Armin Rigo 
Branch: nogil-unsafe
Changeset: r89408:c17b7079746f
Date: 2017-01-07 10:20 +0100
http://bitbucket.org/pypy/pypy/changeset/c17b7079746f/

Log:Start, mostly just playing around

diff --git a/rpython/memory/gc/incminimark.py b/rpython/memory/gc/incminimark.py
--- a/rpython/memory/gc/incminimark.py
+++ b/rpython/memory/gc/incminimark.py
@@ -190,6 +190,11 @@
 FORWARDSTUBPTR = lltype.Ptr(FORWARDSTUB)
 NURSARRAY = lltype.Array(llmemory.Address)
 
+GCTL = lltype.Struct('GCThreadLocal',
+ ('nursery_free', llmemory.Address),
+ ('nursery_top', llmemory.Address),
+ hints={'thread_local': True})
+
 # 
 
 class IncrementalMiniMarkGC(MovingGCBase):
@@ -269,12 +274,23 @@
 "card_page_indices": 128,
 
 # Objects whose total size is at least 'large_object' bytes are
-# allocated out of the nursery immediately, as old objects.  The
-# minimal allocated size of the nursery is 2x the following
-# number (by default, at least 132KB on 32-bit and 264KB on 64-bit).
-"large_object": (16384+512)*WORD,
+# allocated out of the nursery immediately, as old objects.
+"large_object": 13000,
+
+# Thread-local Block size: the nursery is divided into blocks of
+# at most this size each, and allocations go on in a
+# thread-local manner inside each block.  "large_object" must be
+# significantly smaller, but at the same time the total nursery
+# size must be many times bigger than "tl_block_size"; the minimum
+# allocated nursery size is 2 times "tl_block_size".
+# "cache_line_min" is used to round the actual thread-local
+# blocks to a cache line, to avoid pointless cache conflicts.
+"tl_block_size": 32768,
+"cache_line_min": 256,
 }
 
+tl = lltype.malloc(GCTL, flavor='raw', immortal=True)
+
 def __init__(self, config,
  read_from_env=False,
  nursery_size=32*WORD,
@@ -286,6 +302,8 @@
  growth_rate_max=2.5,   # for tests
  card_page_indices=0,
  large_object=8*WORD,
+ tl_block_size=9*WORD,
+ cache_line_min=1*WORD,
  ArenaCollectionClass=None,
  **kwds):
 "NOT_RPYTHON"
@@ -313,10 +331,12 @@
 # 'large_object' limit how big objects can be in the nursery, so
 # it gives a lower bound on the allowed size of the nursery.
 self.nonlarge_max = large_object - 1
+self.tl_block_size = tl_block_size
+self.cache_line_min = cache_line_min
 #
 self.nursery  = llmemory.NULL
-self.nursery_free = llmemory.NULL
-self.nursery_top  = llmemory.NULL
+self.tl.nursery_free = llmemory.NULL
+self.tl.nursery_top  = llmemory.NULL
 self.debug_tiny_nursery = -1
 self.debug_rotating_nurseries = lltype.nullptr(NURSARRAY)
 self.extra_threshold = 0
@@ -437,7 +457,7 @@
 else:
 #
 defaultsize = self.nursery_size
-minsize = 2 * (self.nonlarge_max + 1)
+minsize = 2 * self.tl_block_size
 self.nursery_size = minsize
 self.allocate_nursery()
 #
@@ -513,6 +533,13 @@
 # Estimate this number conservatively
 bigobj = self.nonlarge_max + 1
 self.max_number_of_pinned_objects = self.nursery_size / (bigobj * 
2)
+#
+# Round up
+ll_assert((self.cache_line_min & (self.cache_line_min - 1)) == 0,
+  "cache_line_min is not a power a two")
+self.tl_block_size = ((self.tl_block_size + self.cache_line_min - 1)
+  & ~(self.cache_line_min - 1))
+
 
 def _nursery_memory_size(self):
 extra = self.nonlarge_max + 1
@@ -532,10 +559,6 @@
 debug_start("gc-set-nursery-size")
 debug_print("nursery size:", self.nursery_size)
 self.nursery = self._alloc_nursery()
-# the current position in the nursery:
-self.nursery_free = self.nursery
-# the end of the nursery:
-self.nursery_top = self.nursery + self.nursery_size
 # initialize the threshold
 self.min_heap_size = max(self.min_heap_size, self.nursery_size *
   self.major_collection_threshold)
@@ -608,7 +631,6 @@
 #
 llarena.arena_protect(newnurs, self._nursery_memory_size(), False)
 self.nursery = newnurs
-self.nursery_top = self.nursery + self.nursery_size
 debug_print("switching from nursery", oldnurs,
 "to nursery", self.nursery,
 "size", self.nursery_size)
@@ -651,10 +673,10 @@
 #
 # Get the memory from the nursery.  If there is not enough sp

[pypy-commit] pypy py3.5: zlib: CPython issue27164

2017-01-07 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r89409:ee9a45377582
Date: 2017-01-07 10:56 +0100
http://bitbucket.org/pypy/pypy/changeset/ee9a45377582/

Log:zlib: CPython issue27164

diff --git a/pypy/module/zlib/interp_zlib.py b/pypy/module/zlib/interp_zlib.py
--- a/pypy/module/zlib/interp_zlib.py
+++ b/pypy/module/zlib/interp_zlib.py
@@ -122,9 +122,7 @@
 ZLibObject.__init__(self, space)
 try:
 self.stream = rzlib.deflateInit(level, method, wbits,
-memLevel, strategy)
-if zdict is not None:
-rzlib.deflateSetDictionary(self.stream, zdict)
+memLevel, strategy, zdict=zdict)
 except rzlib.RZlibError as e:
 raise zlib_error(space, e.msg)
 except ValueError:
@@ -242,7 +240,7 @@
 self.unconsumed_tail = ''
 self.eof = False
 try:
-self.stream = rzlib.inflateInit(wbits)
+self.stream = rzlib.inflateInit(wbits, zdict=zdict)
 except rzlib.RZlibError as e:
 raise zlib_error(space, e.msg)
 except ValueError:
diff --git a/pypy/module/zlib/test/test_zlib.py 
b/pypy/module/zlib/test/test_zlib.py
--- a/pypy/module/zlib/test/test_zlib.py
+++ b/pypy/module/zlib/test/test_zlib.py
@@ -320,3 +320,13 @@
 def test_version(self):
 zlib = self.zlib
 assert zlib.ZLIB_VERSION[0] == zlib.ZLIB_RUNTIME_VERSION[0]
+
+# CPython issue27164
+def test_decompress_raw_with_dictionary(self):
+zlib = self.zlib
+zdict = b'abcdefghijklmnopqrstuvwxyz'
+co = zlib.compressobj(wbits=-zlib.MAX_WBITS, zdict=zdict)
+comp = co.compress(zdict) + co.flush()
+dco = zlib.decompressobj(wbits=-zlib.MAX_WBITS, zdict=zdict)
+uncomp = dco.decompress(comp) + dco.flush()
+assert zdict == uncomp
diff --git a/rpython/rlib/rzlib.py b/rpython/rlib/rzlib.py
--- a/rpython/rlib/rzlib.py
+++ b/rpython/rlib/rzlib.py
@@ -51,6 +51,7 @@
 voidpf = rffi_platform.SimpleType('voidpf', rffi.VOIDP)
 
 ZLIB_VERSION = rffi_platform.DefinedConstantString('ZLIB_VERSION')
+ZLIB_VERNUM = rffi_platform.DefinedConstantInteger('ZLIB_VERNUM')
 
 for _name in constantnames:
 setattr(SimpleCConfig, _name, rffi_platform.ConstantInteger(_name))
@@ -63,6 +64,7 @@
 Bytefp = lltype.Ptr(lltype.Array(Bytef, hints={'nolength': True}))
 
 ZLIB_VERSION = config['ZLIB_VERSION']
+ZLIB_VERNUM = config['ZLIB_VERNUM']
 
 for _name in constantnames:
 globals()[_name] = config[_name]
@@ -261,7 +263,7 @@
 
 def deflateInit(level=Z_DEFAULT_COMPRESSION, method=Z_DEFLATED,
 wbits=MAX_WBITS, memLevel=DEF_MEM_LEVEL,
-strategy=Z_DEFAULT_STRATEGY):
+strategy=Z_DEFAULT_STRATEGY, zdict=None):
 """
 Allocate and return an opaque 'stream' object that can be used to
 compress data.
@@ -270,6 +272,12 @@
 rgc.add_memory_pressure(rffi.sizeof(z_stream))
 err = _deflateInit2(stream, level, method, wbits, memLevel, strategy)
 if err == Z_OK:
+if zdict is not None:
+try:
+deflateSetDictionary(stream, zdict)
+except:
+lltype.free(stream, flavor='raw')
+raise
 return stream
 else:
 try:
@@ -290,7 +298,7 @@
 lltype.free(stream, flavor='raw')
 
 
-def inflateInit(wbits=MAX_WBITS):
+def inflateInit(wbits=MAX_WBITS, zdict=None):
 """
 Allocate and return an opaque 'stream' object that can be used to
 decompress data.
@@ -299,6 +307,17 @@
 rgc.add_memory_pressure(rffi.sizeof(z_stream))
 err = _inflateInit2(stream, wbits)
 if err == Z_OK:
+if zdict is not None and wbits < 0:
+try:
+if ZLIB_VERNUM is None or ZLIB_VERNUM < 0x1221:
+raise RZlibError("zlib version %s does not allow raw "
+ "inflate with dictionary" %
+   ZLIB_VERSION if ZLIB_VERSION is not None
+   else "")
+inflateSetDictionary(stream, zdict)
+except:
+lltype.free(stream, flavor='raw')
+raise
 return stream
 else:
 try:
___
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Backport ee9a45377582

2017-01-07 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r89410:f3abf62ba364
Date: 2017-01-07 10:57 +0100
http://bitbucket.org/pypy/pypy/changeset/f3abf62ba364/

Log:Backport ee9a45377582

diff --git a/rpython/rlib/rzlib.py b/rpython/rlib/rzlib.py
--- a/rpython/rlib/rzlib.py
+++ b/rpython/rlib/rzlib.py
@@ -51,6 +51,7 @@
 voidpf = rffi_platform.SimpleType('voidpf', rffi.VOIDP)
 
 ZLIB_VERSION = rffi_platform.DefinedConstantString('ZLIB_VERSION')
+ZLIB_VERNUM = rffi_platform.DefinedConstantInteger('ZLIB_VERNUM')
 
 for _name in constantnames:
 setattr(SimpleCConfig, _name, rffi_platform.ConstantInteger(_name))
@@ -63,6 +64,7 @@
 Bytefp = lltype.Ptr(lltype.Array(Bytef, hints={'nolength': True}))
 
 ZLIB_VERSION = config['ZLIB_VERSION']
+ZLIB_VERNUM = config['ZLIB_VERNUM']
 
 for _name in constantnames:
 globals()[_name] = config[_name]
@@ -261,7 +263,7 @@
 
 def deflateInit(level=Z_DEFAULT_COMPRESSION, method=Z_DEFLATED,
 wbits=MAX_WBITS, memLevel=DEF_MEM_LEVEL,
-strategy=Z_DEFAULT_STRATEGY):
+strategy=Z_DEFAULT_STRATEGY, zdict=None):
 """
 Allocate and return an opaque 'stream' object that can be used to
 compress data.
@@ -270,6 +272,12 @@
 rgc.add_memory_pressure(rffi.sizeof(z_stream))
 err = _deflateInit2(stream, level, method, wbits, memLevel, strategy)
 if err == Z_OK:
+if zdict is not None:
+try:
+deflateSetDictionary(stream, zdict)
+except:
+lltype.free(stream, flavor='raw')
+raise
 return stream
 else:
 try:
@@ -290,7 +298,7 @@
 lltype.free(stream, flavor='raw')
 
 
-def inflateInit(wbits=MAX_WBITS):
+def inflateInit(wbits=MAX_WBITS, zdict=None):
 """
 Allocate and return an opaque 'stream' object that can be used to
 decompress data.
@@ -299,6 +307,17 @@
 rgc.add_memory_pressure(rffi.sizeof(z_stream))
 err = _inflateInit2(stream, wbits)
 if err == Z_OK:
+if zdict is not None and wbits < 0:
+try:
+if ZLIB_VERNUM is None or ZLIB_VERNUM < 0x1221:
+raise RZlibError("zlib version %s does not allow raw "
+ "inflate with dictionary" %
+   ZLIB_VERSION if ZLIB_VERSION is not None
+   else "")
+inflateSetDictionary(stream, zdict)
+except:
+lltype.free(stream, flavor='raw')
+raise
 return stream
 else:
 try:
___
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit