[pypy-commit] pypy nogil-unsafe-2: (arigo, remi) add lock to slowpath of write barrier
Raemi
pypy.commits at gmail.com
Sat Mar 4 06:59:37 EST 2017
Author: Remi Meier <remi.meier at gmail.com>
Branch: nogil-unsafe-2
Changeset: r90531:27908e5859b8
Date: 2017-03-04 12:59 +0100
http://bitbucket.org/pypy/pypy/changeset/27908e5859b8/
Log: (arigo, remi) add lock to slowpath of write barrier
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
@@ -438,11 +438,11 @@
self.old_objects_pointing_to_pinned = self.AddressStack()
self.updated_old_objects_pointing_to_pinned = False
#
- # # Allocate lock(s)
- # ll_lock = lltype.malloc(rthread.TLOCKP.TO, flavor='raw',
- # track_allocation=False)
- # rthread.c_thread_lock_init(ll_lock)
- # self.ll_lock = ll_lock
+ # Allocate lock(s)
+ wb_slowpath_lock = lltype.malloc(rthread.TLOCKP.TO, flavor='raw',
+ track_allocation=False)
+ rthread.c_thread_lock_init(wb_slowpath_lock)
+ self.wb_slowpath_lock = wb_slowpath_lock
#
# Allocate a nursery. In case of auto_nursery_size, start by
# allocating a very small nursery, enough to do things like look
@@ -860,7 +860,7 @@
major collection, and finally reserve totalsize bytes.
"""
- # rthread.acquire_NOAUTO(self.ll_lock, 1)
+ # rthread.acquire_NOAUTO(self.wb_slowpath_lock, 1)
rgil.enter_master_section()
minor_collection_count = 0
@@ -947,7 +947,7 @@
self.debug_tiny_nursery)
#
rgil.leave_master_section()
- # rthread.release_NOAUTO(self.ll_lock)
+ # rthread.release_NOAUTO(self.wb_slowpath_lock)
return result
collect_and_reserve._dont_inline_ = True
@@ -1476,6 +1476,12 @@
# make the code in write_barrier() marginally smaller
# (which is important because it is inlined *everywhere*).
def remember_young_pointer(addr_struct):
+ rthread.acquire_NOAUTO(self.wb_slowpath_lock, True)
+ if not llop.gc_bit(lltype.Signed, self.header(addr_struct),
+ GCFLAG_TRACK_YOUNG_PTRS):
+ rthread.release_NOAUTO(self.wb_slowpath_lock)
+ return
+ #
# 'addr_struct' is the address of the object in which we write.
# We know that 'addr_struct' has GCFLAG_TRACK_YOUNG_PTRS so far.
#
@@ -1507,6 +1513,8 @@
if objhdr.tid & GCFLAG_NO_HEAP_PTRS:
objhdr.tid &= ~GCFLAG_NO_HEAP_PTRS
self.prebuilt_root_objects.append(addr_struct)
+ #
+ rthread.release_NOAUTO(self.wb_slowpath_lock)
remember_young_pointer._dont_inline_ = True
self.remember_young_pointer = remember_young_pointer
@@ -1518,6 +1526,12 @@
def _init_writebarrier_with_card_marker(self):
DEBUG = self.DEBUG
def remember_young_pointer_from_array2(addr_array, index):
+ rthread.acquire_NOAUTO(self.wb_slowpath_lock, True)
+ if not llop.gc_bit(lltype.Signed, self.header(addr_array),
+ GCFLAG_TRACK_YOUNG_PTRS):
+ rthread.release_NOAUTO(self.wb_slowpath_lock)
+ return
+ #
# 'addr_array' is the address of the object in which we write,
# which must have an array part; 'index' is the index of the
# item that is (or contains) the pointer that we write.
@@ -1536,6 +1550,7 @@
if objhdr.tid & GCFLAG_NO_HEAP_PTRS:
objhdr.tid &= ~GCFLAG_NO_HEAP_PTRS
self.prebuilt_root_objects.append(addr_array)
+ rthread.release_NOAUTO(self.wb_slowpath_lock)
return
#
# 'addr_array' is a raw_malloc'ed array with card markers
@@ -1548,6 +1563,7 @@
addr_byte = self.get_card(addr_array, byteindex)
byte = ord(addr_byte.char[0])
if byte & bitmask:
+ rthread.release_NOAUTO(self.wb_slowpath_lock)
return
#
# We set the flag (even if the newly written address does not
@@ -1559,6 +1575,7 @@
if objhdr.tid & GCFLAG_CARDS_SET == 0:
self.old_objects_with_cards_set.append(addr_array)
objhdr.tid |= GCFLAG_CARDS_SET
+ rthread.release_NOAUTO(self.wb_slowpath_lock)
remember_young_pointer_from_array2._dont_inline_ = True
ll_assert(self.card_page_indices > 0,
diff --git a/rpython/rlib/rthread.py b/rpython/rlib/rthread.py
--- a/rpython/rlib/rthread.py
+++ b/rpython/rlib/rthread.py
@@ -4,6 +4,7 @@
import py, sys
from rpython.rlib import jit, rgc
from rpython.rlib.debug import ll_assert
+from rpython.rlib.objectmodel import enforceargs
from rpython.rlib.objectmodel import we_are_translated, specialize
from rpython.rlib.objectmodel import CDefinedIntSymbolic, not_rpython
from rpython.rtyper.lltypesystem.lloperation import llop
@@ -253,6 +254,7 @@
c_thread_lock_dealloc_NOAUTO(ll_lock)
lltype.free(ll_lock, flavor='raw', track_allocation=False)
+ at enforceargs(None, bool)
def acquire_NOAUTO(ll_lock, flag):
flag = rffi.cast(rffi.INT, int(flag))
res = c_thread_acquirelock_NOAUTO(ll_lock, flag)
More information about the pypy-commit
mailing list