Author: Nicolas Truessel <[email protected]>
Branch: quad-color-gc
Changeset: r86638:a1f8c2584b18
Date: 2016-08-28 11:54 +0200
http://bitbucket.org/pypy/pypy/changeset/a1f8c2584b18/

Log:    Try implementing hash

diff --git a/rpython/memory/gc/qcgc.py b/rpython/memory/gc/qcgc.py
--- a/rpython/memory/gc/qcgc.py
+++ b/rpython/memory/gc/qcgc.py
@@ -1,4 +1,5 @@
 from rpython.memory.gc.base import GCBase
+from rpython.memory.support import mangle_hash
 from rpython.rtyper.lltypesystem import rffi, lltype, llgroup, llmemory, 
llarena
 from rpython.rtyper.lltypesystem.lloperation import llop
 from rpython.rlib.debug import ll_assert
@@ -73,8 +74,21 @@
         #llop.gc_writebarrier(dest_addr)
         #return True
 
+    def id_or_identityhash(self, gcobj, is_hash):
+        i = self.header(llmemory.cast_ptr_to_adr(gcobj)).hash
+        prebuilt = llop.qcgc_is_prebuilt(lltype.Bool, gcobj)
+        #
+        if is_hash:
+            if prebuilt:
+                return i # Do not mangle for prebuilt objects
+            i = mangle_hash(i)
+        return i
+
+    def id(self, gcobje):
+        return self.id_or_identityhash(gcobj, False)
+
     def identityhash(self, gcobj):
-        raise NotImplementedError
+        return self.id_or_identityhash(gcobj, True)
 
     def register_finalizer(self, fq_index, gcobj):
         raise NotImplementedError
diff --git a/rpython/rtyper/lltypesystem/lloperation.py 
b/rpython/rtyper/lltypesystem/lloperation.py
--- a/rpython/rtyper/lltypesystem/lloperation.py
+++ b/rpython/rtyper/lltypesystem/lloperation.py
@@ -517,6 +517,7 @@
     # __________ qcgc operations __________
     'qcgc_allocate':    LLOp(canmallocgc=True),
     'qcgc_collect':     LLOp(canmallocgc=True),
+    'qcgc_is_prebuilt': LLOp(),
 
     # __________ weakrefs __________
 
diff --git a/rpython/translator/c/funcgen.py b/rpython/translator/c/funcgen.py
--- a/rpython/translator/c/funcgen.py
+++ b/rpython/translator/c/funcgen.py
@@ -959,3 +959,9 @@
 
     def OP_QCGC_COLLECT(self, op):
         return 'qcgc_collect();'
+
+    def OP_QCGC_IS_PREBUILT(self, op):
+        obj = self.expr(op.args[0])
+        result = self.expr(op.result)
+        return '%s = (((object_t *) %s)->flags & QCGC_PREBUILT_OBJECT) != 0;' 
% (
+                result, obj)
diff --git a/rpython/translator/c/src/qcgc/object.h 
b/rpython/translator/c/src/qcgc/object.h
--- a/rpython/translator/c/src/qcgc/object.h
+++ b/rpython/translator/c/src/qcgc/object.h
@@ -7,6 +7,7 @@
 #define QCGC_GRAY_FLAG (1<<0)
 #define QCGC_PREBUILT_OBJECT (1<<1)
 #define QCGC_PREBUILT_REGISTERED (1<<2)
+#define QCGC_FIRST_AVAILABLE_FLAG (1<<3)       // The first flag clients may 
use
 
 typedef struct object_s {
        uint32_t flags;
diff --git a/rpython/translator/c/src/qcgc/qcgc.c 
b/rpython/translator/c/src/qcgc/qcgc.c
--- a/rpython/translator/c/src/qcgc/qcgc.c
+++ b/rpython/translator/c/src/qcgc/qcgc.c
@@ -43,9 +43,6 @@
  * Shadow stack
  */
 void qcgc_shadowstack_push(object_t *object) {
-#if CHECKED
-       assert((object->flags & QCGC_PREBUILT_OBJECT) == 0);
-#endif
        if (qcgc_state.phase != GC_PAUSE) {
                qcgc_state.phase = GC_MARK;
                qcgc_push_object(object);
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to