You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2014/09/16 04:09:28 UTC

[1/3] git commit: Make simulated inline more realistic.

Repository: lucy-clownfish
Updated Branches:
  refs/heads/master 7161001d9 -> ebec05a3e


Make simulated inline more realistic.

Disable optimization using `volatile`.


Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/ebec05a3
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/ebec05a3
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/ebec05a3

Branch: refs/heads/master
Commit: ebec05a3e7afc1aef74a40a868f2425a3cb7d65f
Parents: 8362e4b
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Mon Sep 15 18:41:31 2014 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Mon Sep 15 19:08:45 2014 -0700

----------------------------------------------------------------------
 devel/benchmarks/method_dispatch/exe.c | 2 +-
 devel/benchmarks/method_dispatch/oo.h  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/ebec05a3/devel/benchmarks/method_dispatch/exe.c
----------------------------------------------------------------------
diff --git a/devel/benchmarks/method_dispatch/exe.c b/devel/benchmarks/method_dispatch/exe.c
index 9774387..708124a 100644
--- a/devel/benchmarks/method_dispatch/exe.c
+++ b/devel/benchmarks/method_dispatch/exe.c
@@ -189,6 +189,7 @@ main(int argc, char **argv) {
     bench(loop_with_wrapper, "wrapper loop");
     bench(loop_with_fixed_offset_wrapper, "fixed offset wrapper loop");
     bench(loop_with_interface, "interface loop");
+    bench(loop_with_simulated_inline, "simulated inline");
 #ifdef HAS_ALIAS
     bench(loop_with_thunk, "thunk loop");
     bench(loop_with_thunk_ptr, "thunk ptr loop");
@@ -198,7 +199,6 @@ main(int argc, char **argv) {
     bench(call_with_thunk, "thunk");
     bench(call_with_thunk_ptr, "thunk ptr");
 #endif
-    bench(loop_with_simulated_inline, "simulated inline");
 
     return 0;
 }

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/ebec05a3/devel/benchmarks/method_dispatch/oo.h
----------------------------------------------------------------------
diff --git a/devel/benchmarks/method_dispatch/oo.h b/devel/benchmarks/method_dispatch/oo.h
index 61ebbc3..f12a45a 100644
--- a/devel/benchmarks/method_dispatch/oo.h
+++ b/devel/benchmarks/method_dispatch/oo.h
@@ -26,7 +26,7 @@ typedef struct class_t interface_t;
 typedef struct obj_t {
     size_t    refcount;
     class_t  *klass;
-    uint64_t  value;
+    volatile uint64_t value;
 } obj_t;
 
 typedef void (*method_t)(obj_t *obj);


[2/3] git commit: Add one flavor of interface dispatch.

Posted by ma...@apache.org.
Add one flavor of interface dispatch.

Benchmark interface method dispatch which adds one level of indirection
(to look up an itable).


Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/8362e4bf
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/8362e4bf
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/8362e4bf

Branch: refs/heads/master
Commit: 8362e4bfc94ecd58a29ce4c713fd70c7c0c05327
Parents: e28b811
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Mon Sep 15 16:20:48 2014 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Mon Sep 15 19:08:45 2014 -0700

----------------------------------------------------------------------
 devel/benchmarks/method_dispatch/dso.c |  6 ++++++
 devel/benchmarks/method_dispatch/dso.h |  1 +
 devel/benchmarks/method_dispatch/exe.c | 23 +++++++++++++++++++++++
 devel/benchmarks/method_dispatch/oo.h  | 14 +++++++++++---
 4 files changed, 41 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/8362e4bf/devel/benchmarks/method_dispatch/dso.c
----------------------------------------------------------------------
diff --git a/devel/benchmarks/method_dispatch/dso.c b/devel/benchmarks/method_dispatch/dso.c
index d0f323f..c8706e2 100644
--- a/devel/benchmarks/method_dispatch/dso.c
+++ b/devel/benchmarks/method_dispatch/dso.c
@@ -26,6 +26,7 @@ void thunk3(obj_t *obj);
 class_t *OBJ;
 size_t Obj_Hello_OFFSET;
 method_t Obj_Hello_THUNK_PTR;
+unsigned int Obj_Hello_INTERFACE_OFFSET;
 
 void
 bootstrap() {
@@ -41,6 +42,11 @@ bootstrap() {
                        + METHOD_IDX * sizeof(method_t);
     OBJ->vtable[METHOD_IDX] = Obj_hello;
     Obj_Hello_THUNK_PTR = thunk3;
+
+    // Interface ID 0, slot 0.
+    Obj_Hello_INTERFACE_OFFSET = Obj_Hello_OFFSET;
+    OBJ->itables[0]    = (interface_t**)malloc(sizeof(void*));
+    OBJ->itables[0][0] = (interface_t*)OBJ;
 }
 
 obj_t*

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/8362e4bf/devel/benchmarks/method_dispatch/dso.h
----------------------------------------------------------------------
diff --git a/devel/benchmarks/method_dispatch/dso.h b/devel/benchmarks/method_dispatch/dso.h
index 587a2c4..702057d 100644
--- a/devel/benchmarks/method_dispatch/dso.h
+++ b/devel/benchmarks/method_dispatch/dso.h
@@ -25,6 +25,7 @@ extern method_t Obj_Hello_THUNK_PTR;
 #define METHOD_IDX 3
 #define Obj_Hello_FIXED_OFFSET \
     (offsetof(class_t, vtable) + METHOD_IDX * sizeof(method_t))
+extern unsigned Obj_Hello_INTERFACE_OFFSET;
 
 void bootstrap();
 

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/8362e4bf/devel/benchmarks/method_dispatch/exe.c
----------------------------------------------------------------------
diff --git a/devel/benchmarks/method_dispatch/exe.c b/devel/benchmarks/method_dispatch/exe.c
index 1747386..9774387 100644
--- a/devel/benchmarks/method_dispatch/exe.c
+++ b/devel/benchmarks/method_dispatch/exe.c
@@ -18,6 +18,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/time.h>
+#include <assert.h>
 
 #include "dso.h"
 
@@ -46,6 +47,20 @@ Obj_Hello_FIXED(obj_t *obj) {
     method(obj);
 }
 
+static inline void
+Obj_Hello_INTERFACE(obj_t *obj) {
+    unsigned offset = Obj_Hello_INTERFACE_OFFSET;
+    unsigned itable_array_slot
+        = (offset & ITABLE_ARRAY_MASK) >> ITABLE_ARRAY_SHIFT;
+    interface_t **itables = obj->klass->itables[itable_array_slot];
+    unsigned interface_id
+        = (offset & INTERFACE_ID_MASK) >> INTERFACE_ID_SHIFT;
+    interface_t *interface = itables[interface_id];
+    char *ptr = (char*)interface + (offset & IMETHOD_OFFSET_MASK);
+    method_t method = *(method_t*)ptr;
+    method(obj);
+}
+
 void
 loop_with_method_ptr(obj_t *obj) {
     method_t method = Obj_Hello_PTR(obj);
@@ -69,6 +84,13 @@ loop_with_fixed_offset_wrapper(obj_t *obj) {
     }
 }
 
+void
+loop_with_interface(obj_t *obj) {
+    for (uint64_t i = 0; i < ITERATIONS; ++i) {
+        Obj_Hello_INTERFACE(obj);
+    }
+}
+
 #ifdef HAS_ALIAS
 void
 loop_with_thunk(obj_t *obj) {
@@ -166,6 +188,7 @@ main(int argc, char **argv) {
     bench(loop_with_method_ptr, "method ptr loop");
     bench(loop_with_wrapper, "wrapper loop");
     bench(loop_with_fixed_offset_wrapper, "fixed offset wrapper loop");
+    bench(loop_with_interface, "interface loop");
 #ifdef HAS_ALIAS
     bench(loop_with_thunk, "thunk loop");
     bench(loop_with_thunk_ptr, "thunk ptr loop");

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/8362e4bf/devel/benchmarks/method_dispatch/oo.h
----------------------------------------------------------------------
diff --git a/devel/benchmarks/method_dispatch/oo.h b/devel/benchmarks/method_dispatch/oo.h
index d2d0190..61ebbc3 100644
--- a/devel/benchmarks/method_dispatch/oo.h
+++ b/devel/benchmarks/method_dispatch/oo.h
@@ -21,6 +21,7 @@
 #include <stdint.h>
 
 typedef struct class_t class_t;
+typedef struct class_t interface_t;
 
 typedef struct obj_t {
     size_t    refcount;
@@ -31,10 +32,17 @@ typedef struct obj_t {
 typedef void (*method_t)(obj_t *obj);
 
 struct class_t {
-    char     *name;
-    size_t    class_size;
-    method_t  vtable[1];
+    char         *name;
+    size_t        class_size;
+    interface_t **itables[8];
+    method_t      vtable[1];
 };
 
+#define ITABLE_ARRAY_SHIFT  16
+#define ITABLE_ARRAY_MASK   0xFFFF0000
+#define INTERFACE_ID_SHIFT  8
+#define INTERFACE_ID_MASK   0x0000FF00
+#define IMETHOD_OFFSET_MASK 0x000000FF
+
 #endif /* OO_H */
 


[3/3] git commit: Guard against changes to class_t layout.

Posted by ma...@apache.org.
Guard against changes to class_t layout.


Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/e28b8112
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/e28b8112
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/e28b8112

Branch: refs/heads/master
Commit: e28b81127cbc223ac74d5c1dd42c23f768757bc3
Parents: 7161001
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Mon Sep 15 16:24:37 2014 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Mon Sep 15 19:08:45 2014 -0700

----------------------------------------------------------------------
 devel/benchmarks/method_dispatch/dso.c | 7 +++----
 devel/benchmarks/method_dispatch/dso.h | 4 +++-
 2 files changed, 6 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/e28b8112/devel/benchmarks/method_dispatch/dso.c
----------------------------------------------------------------------
diff --git a/devel/benchmarks/method_dispatch/dso.c b/devel/benchmarks/method_dispatch/dso.c
index 28a30e2..d0f323f 100644
--- a/devel/benchmarks/method_dispatch/dso.c
+++ b/devel/benchmarks/method_dispatch/dso.c
@@ -29,9 +29,8 @@ method_t Obj_Hello_THUNK_PTR;
 
 void
 bootstrap() {
-    size_t method_idx = 3;
     size_t class_size = offsetof(class_t, vtable)
-                        + (method_idx + 1) * sizeof(method_t);
+                        + (METHOD_IDX + 1) * sizeof(method_t);
 
     OBJ = (class_t*)calloc(1, class_size);
 
@@ -39,8 +38,8 @@ bootstrap() {
     OBJ->class_size = class_size;
 
     Obj_Hello_OFFSET = offsetof(class_t, vtable)
-                       + method_idx * sizeof(method_t);
-    OBJ->vtable[method_idx] = Obj_hello;
+                       + METHOD_IDX * sizeof(method_t);
+    OBJ->vtable[METHOD_IDX] = Obj_hello;
     Obj_Hello_THUNK_PTR = thunk3;
 }
 

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/e28b8112/devel/benchmarks/method_dispatch/dso.h
----------------------------------------------------------------------
diff --git a/devel/benchmarks/method_dispatch/dso.h b/devel/benchmarks/method_dispatch/dso.h
index fe1a07f..587a2c4 100644
--- a/devel/benchmarks/method_dispatch/dso.h
+++ b/devel/benchmarks/method_dispatch/dso.h
@@ -22,7 +22,9 @@
 extern class_t *OBJ;
 extern size_t Obj_Hello_OFFSET;
 extern method_t Obj_Hello_THUNK_PTR;
-#define Obj_Hello_FIXED_OFFSET (5 * sizeof(void*))
+#define METHOD_IDX 3
+#define Obj_Hello_FIXED_OFFSET \
+    (offsetof(class_t, vtable) + METHOD_IDX * sizeof(method_t))
 
 void bootstrap();