[pypy-commit] lang-smalltalk storage: Added support for loading weak objects from an image. Important.
anton_gulenko
noreply at buildbot.pypy.org
Tue Apr 1 09:41:49 CEST 2014
Author: Anton Gulenko <anton.gulenko at googlemail.com>
Branch: storage
Changeset: r733:9f145aa73461
Date: 2014-03-31 21:18 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/9f145aa73461/
Log: Added support for loading weak objects from an image. Important.
--strategy-stats can be used to see how many weak objects are loaded.
Extended the test for weak pointers.
diff --git a/spyvm/model.py b/spyvm/model.py
--- a/spyvm/model.py
+++ b/spyvm/model.py
@@ -571,7 +571,7 @@
pointers = g_self.get_pointers()
# TODO -- Also handle weak objects loaded from images.
from spyvm.shadow import find_storage_for_objects
- storage = find_storage_for_objects(space, pointers)(space, self, len(pointers))
+ storage = find_storage_for_objects(space, pointers, g_self.isweak())(space, self, len(pointers))
self.store_shadow(storage)
self.store_all(space, pointers)
self.log_storage("Filledin", log_classname=False)
diff --git a/spyvm/shadow.py b/spyvm/shadow.py
--- a/spyvm/shadow.py
+++ b/spyvm/shadow.py
@@ -170,13 +170,13 @@
def empty_storage(space, w_self, size, weak=False):
if weak:
return WeakListStorageShadow(space, w_self, size)
- else:
- if no_specialized_storage:
- return ListStorageShadow(space, w_self, size)
- else:
- return AllNilStorageShadow(space, w_self, size)
+ if no_specialized_storage:
+ return ListStorageShadow(space, w_self, size)
+ return AllNilStorageShadow(space, w_self, size)
-def find_storage_for_objects(space, vars):
+def find_storage_for_objects(space, vars, weak=False):
+ if weak:
+ return WeakListStorageShadow
if no_specialized_storage:
return ListStorageShadow
specialized_strategies = 3
diff --git a/spyvm/squeakimage.py b/spyvm/squeakimage.py
--- a/spyvm/squeakimage.py
+++ b/spyvm/squeakimage.py
@@ -503,8 +503,11 @@
return self.iswords() and self.space.w_Float.is_same_object(self.g_class.w_object)
def ispointers(self):
- return self.format < 5 #TODO, what about compiled methods?
+ return self.format < 5
+ def isweak(self):
+ return self.format == 4
+
def iscompiledmethod(self):
return 12 <= self.format <= 15
@@ -528,7 +531,6 @@
# the instantiate call circumvents the constructors
# and makes empty objects
if self.ispointers():
- # XXX self.format == 4 is weak
self.w_object = objectmodel.instantiate(model.W_PointersObject)
elif self.format == 5:
raise CorruptImageError("Unknown format 5")
diff --git a/spyvm/test/test_model.py b/spyvm/test/test_model.py
--- a/spyvm/test/test_model.py
+++ b/spyvm/test/test_model.py
@@ -419,13 +419,15 @@
@py.test.mark.skipif("socket.gethostname() == 'precise32'")
def test_weak_pointers():
- w_cls = bootstrap_class(1)
+ w_cls = bootstrap_class(2)
s_cls = w_cls.as_class_get_shadow(space)
s_cls.instance_kind = WEAK_POINTERS
weak_object = s_cls.new()
referenced = model.W_SmallInteger(10)
+ referenced2 = model.W_SmallInteger(20)
weak_object.store(space, 0, referenced)
+ weak_object.store(space, 1, referenced2)
assert weak_object.fetch(space, 0) is referenced
del referenced
@@ -433,3 +435,4 @@
# Thus the reference may linger until the next gc...
import gc; gc.collect()
assert weak_object.fetch(space, 0).is_nil(space)
+ assert weak_object.fetch(space, 1).value == 20
More information about the pypy-commit
mailing list