Author: Armin Rigo <[email protected]>
Branch:
Changeset: r957:65ff01990d5d
Date: 2014-03-05 09:36 +0100
http://bitbucket.org/pypy/stmgc/changeset/65ff01990d5d/
Log: Forgot to add in 8185ee16c279
diff --git a/c7/stm/hash_id.c b/c7/stm/hash_id.c
new file mode 100644
--- /dev/null
+++ b/c7/stm/hash_id.c
@@ -0,0 +1,69 @@
+#ifndef _STM_CORE_H_
+# error "must be compiled via stmgc.c"
+#endif
+
+
+static long mangle_hash(long i)
+{
+ /* To hash pointers in dictionaries. Assumes that i shows some
+ alignment (to 8, 16, maybe 32 bytes), so we use the following
+ formula to avoid the trailing bits being always 0. */
+ return i ^ (i >> 5);
+}
+
+static long id_or_identityhash(object_t *obj, bool is_hash)
+{
+ long result;
+
+ if (obj != NULL) {
+ if (_is_in_nursery(obj)) {
+ abort();//obj = find_shadow(obj);
+ }
+ else if (is_hash) {
+ if (obj->stm_flags & GCFLAG_HAS_SHADOW) {
+
+ /* For identityhash(), we need a special case for some
+ prebuilt objects: their hash must be the same before
+ and after translation. It is stored as an extra word
+ after the object. But we cannot use it for id()
+ because the stored value might clash with a real one.
+ */
+ struct object_s *realobj = (struct object_s *)
+ REAL_ADDRESS(STM_SEGMENT->segment_base, obj);
+ size_t size = stmcb_size_rounded_up(realobj);
+ result = *(long *)(((char *)realobj) + size);
+ /* Important: the returned value is not mangle_hash()ed! */
+ return result;
+ }
+ }
+ }
+
+ result = (long)(uintptr_t)obj;
+ if (is_hash) {
+ result = mangle_hash(result);
+ }
+ return result;
+}
+
+long stm_id(object_t *obj)
+{
+ return id_or_identityhash(obj, false);
+}
+
+long stm_identityhash(object_t *obj)
+{
+ return id_or_identityhash(obj, true);
+}
+
+void stm_set_prebuilt_identityhash(object_t *obj, uint64_t hash)
+{
+ struct object_s *realobj = (struct object_s *)
+ REAL_ADDRESS(stm_object_pages, obj);
+
+ assert(realobj->stm_flags == GCFLAG_WRITE_BARRIER);
+ realobj->stm_flags |= GCFLAG_HAS_SHADOW;
+
+ size_t size = stmcb_size_rounded_up(realobj);
+ assert(*(long *)(((char *)realobj) + size) == 0);
+ *(long *)(((char *)realobj) + size) = hash;
+}
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit