yarv-diff:371
From: ko1 atdot.net
Date: 18 Aug 2006 16:56:18 +0900
Subject: [yarv-diff:371] r538 - in trunk: . benchmark
Author: ko1
Date: 2006-08-18 16:56:17 +0900 (Fri, 18 Aug 2006)
New Revision: 538
Modified:
trunk/
trunk/ChangeLog
trunk/benchmark/bmx_temp.rb
trunk/compile.c
trunk/gc.c
trunk/thread.c
trunk/yarvcore.c
trunk/yarvcore.h
Log:
r840@lermite: ko1 | 2006-08-18 16:55:26 +0900
* yarvcore.h : add a support for cache values per thread
* yarvcore.c : ditto
* gc.c : ditto
* thread.c : move a expression after acquiring lock
* compile.c : add a cast to remove warning
Property changes on: trunk
___________________________________________________________________
Name: svk:merge
- 81cd9672-7512-7e48-ae48-6936450e977d:/local/yarv/trunk:836
+ 81cd9672-7512-7e48-ae48-6936450e977d:/local/yarv/trunk:840
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2006-08-17 17:17:03 UTC (rev 537)
+++ trunk/ChangeLog 2006-08-18 07:56:17 UTC (rev 538)
@@ -4,6 +4,19 @@
# from Mon, 03 May 2004 01:24:19 +0900
#
+2006-08-18(Fri) 16:51:34 +0900 Koichi Sasada <ko1 atdot.net>
+
+ * yarvcore.h : add a support for cache values per thread
+
+ * yarvcore.c : ditto
+
+ * gc.c : ditto
+
+ * thread.c : move a expression after acquiring lock
+
+ * compile.c : add a cast to remove warning
+
+
2006-08-18(Fri) 02:07:45 +0900 Koichi Sasada <ko1 atdot.net>
* compile.c : fix to return rhs value on ATTRASGIN
Modified: trunk/benchmark/bmx_temp.rb
===================================================================
--- trunk/benchmark/bmx_temp.rb 2006-08-17 17:17:03 UTC (rev 537)
+++ trunk/benchmark/bmx_temp.rb 2006-08-18 07:56:17 UTC (rev 538)
@@ -1,4 +1,11 @@
+i=0
+while i<10000000
+ x = "foo"
+ i+=1
+end
+__END__
+
class Range
def each
f = self.first
Modified: trunk/compile.c
===================================================================
--- trunk/compile.c 2006-08-17 17:17:03 UTC (rev 537)
+++ trunk/compile.c 2006-08-18 07:56:17 UTC (rev 538)
@@ -2031,7 +2031,7 @@
COMPILE_POPED(ret, "masgn lhs (NODE_ATTRASGN)", node);
POP_ELEMENT(ret); /* pop pop insn */
- iobj = POP_ELEMENT(ret); /* pop send insn */
+ iobj = (INSN *)POP_ELEMENT(ret); /* pop send insn */
dupidx = iobj->operands[1];
dupidx = INT2FIX(FIX2INT(dupidx) + 1);
Modified: trunk/gc.c
===================================================================
--- trunk/gc.c 2006-08-17 17:17:03 UTC (rev 537)
+++ trunk/gc.c 2006-08-18 07:56:17 UTC (rev 538)
@@ -457,16 +457,20 @@
}
#define RANY(o) ((RVALUE*)(o))
-VALUE
-rb_newobj(void)
+static VALUE
+rb_newobj_from_heap(void)
{
VALUE obj;
- if ((gc_stress || !freelist) && !garbage_collect())
- rb_memerror();
+ if (gc_stress || !freelist) {
+ if(!garbage_collect()) {
+ rb_memerror();
+ }
+ }
obj = (VALUE)freelist;
freelist = freelist->as.free.next;
+
MEMZERO((void*)obj, RVALUE, 1);
#ifdef GC_DEBUG
RANY(obj)->file = ruby_sourcefile;
@@ -475,7 +479,53 @@
return obj;
}
+#if USE_VALUE_CACHE
+static VALUE
+rb_fill_value_cache(yarv_thread_t *th)
+{
+ int i;
+ VALUE rv;
+
+ // LOCK
+ for (i=0; i<YARV_VALUE_CACHE_SIZE; i++) {
+ VALUE v = rb_newobj_from_heap();
+
+ th->value_cache[i] = v;
+ RBASIC(v)->flags = FL_MARK;
+ }
+ // UNLOCK
+ th->value_cache_ptr = &th->value_cache[0];
+ rv = rb_newobj_from_heap();
+ return rv;
+}
+#endif
+
VALUE
+rb_newobj(void)
+{
+#if USE_VALUE_CACHE && 1
+ yarv_thread_t *th = GET_THREAD();
+ VALUE v = *th->value_cache_ptr;
+
+ if (v) {
+ RBASIC(v)->flags = 0;
+ th->value_cache_ptr++;
+ }
+ else {
+ v = rb_fill_value_cache(th);
+ }
+
+#if defined(GC_DEBUG)
+ printf("cache index: %d, v: %p, th: %p\n",
+ th->value_cache_ptr - th->value_cache, v, th);
+#endif
+ return v;
+#else
+ return rb_newobj_from_heap();
+#endif
+}
+
+VALUE
rb_data_object_alloc(VALUE klass, void *datap, RUBY_DATA_FUNC dmark, RUBY_DATA_FUNC dfree)
{
NEWOBJ(data, struct RData);
@@ -1293,6 +1343,8 @@
jmp_buf save_regs_gc_mark;
yarv_thread_t *th = GET_THREAD();
+ // printf("garbage_collect()\n");
+
if (!heaps) {
return Qfalse;
}
Modified: trunk/thread.c
===================================================================
--- trunk/thread.c 2006-08-17 17:17:03 UTC (rev 537)
+++ trunk/thread.c 2006-08-18 07:56:17 UTC (rev 538)
@@ -242,8 +242,6 @@
VALUE args = th->first_args;
yarv_proc_t *proc;
yarv_thread_t *join_th;
- GetProcPtr(th->first_proc, proc);
-
th->machine_stack_start = stack_start;
th->thgroup = th->vm->thgroup_default;
@@ -256,6 +254,7 @@
TH_PUSH_TAG(th);
if ((state = EXEC_TAG()) == 0) {
+ GetProcPtr(th->first_proc, proc);
th->errinfo = Qnil;
th->local_lfp = proc->block.lfp;
th->local_svar = Qnil;
@@ -266,7 +265,7 @@
th->value = Qnil;
}
TH_POP_TAG();
-
+
th->status = THREAD_KILLED;
thread_debug("thread end: %p\n", th);
st_delete_wrap(th->vm->living_threads, th->self);
@@ -294,16 +293,16 @@
/* create thread object */
thval = yarv_thread_alloc(cYarvThread);
GetThreadPtr(thval, th);
-
+
/* setup thread environment */
th->first_args = args;
th->first_proc = rb_block_proc();
-
+
native_mutex_initialize(&th->interrupt_lock);
/* kick thread */
- native_thread_create(th);
st_insert(th->vm->living_threads, thval, (st_data_t) th->thread_id);
+ native_thread_create(th);
return thval;
}
Modified: trunk/yarvcore.c
===================================================================
--- trunk/yarvcore.c 2006-08-17 17:17:03 UTC (rev 537)
+++ trunk/yarvcore.c 2006-08-18 07:56:17 UTC (rev 538)
@@ -252,7 +252,9 @@
GC_INFO("-------------------------------------------------\n");
if (ptr) {
yarv_vm_t *vm = ptr;
- st_foreach(vm->living_threads, vm_mark_each_thread_func, 0);
+ if (vm->living_threads) {
+ st_foreach(vm->living_threads, vm_mark_each_thread_func, 0);
+ }
MARK_UNLESS_NULL(vm->thgroup_default);
MARK_UNLESS_NULL(vm->mark_object_ary);
}
@@ -293,10 +295,23 @@
th = ptr;
FREE_UNLESS_NULL(th->stack);
FREE_UNLESS_NULL(th->top_local_tbl);
+
if (th->local_storage) {
st_free_table(th->local_storage);
}
+#if USE_VALUE_CACHE
+ {
+ VALUE *ptr = th->value_cache_ptr;
+ while (*ptr) {
+ VALUE v = *ptr;
+ RBASIC(v)->flags = 0;
+ RBASIC(v)->klass = 0;
+ ptr++;
+ }
+ }
+#endif
+
if (th->vm->main_thread == th) {
GC_INFO("main thread");
}
@@ -335,7 +350,7 @@
/* mark ruby objects */
MARK_UNLESS_NULL(th->first_proc);
MARK_UNLESS_NULL(th->first_args);
-
+
MARK_UNLESS_NULL(th->thgroup);
MARK_UNLESS_NULL(th->value);
MARK_UNLESS_NULL(th->errinfo);
@@ -361,7 +376,6 @@
{
VALUE volatile obj;
yarv_thread_t *th;
-
obj = Data_Make_Struct(klass, yarv_thread_t,
thread_mark, thread_free, th);
return obj;
@@ -392,6 +406,10 @@
th->status = THREAD_RUNNABLE;
th->errinfo = Qnil;
+
+#if USE_VALUE_CACHE
+ th->value_cache_ptr = &th->value_cache[0];
+#endif
}
void
Modified: trunk/yarvcore.h
===================================================================
--- trunk/yarvcore.h 2006-08-17 17:17:03 UTC (rev 537)
+++ trunk/yarvcore.h 2006-08-18 07:56:17 UTC (rev 538)
@@ -77,8 +77,8 @@
/* likely */
#ifdef __GCC__
-#define LIKELY(x) (__builtin_expect(x, 1))
-#define UNLIKELY(x) (__builtin_expect(x, 0))
+#define LIKELY(x) (__builtin_expect((x), 1))
+#define UNLIKELY(x) (__builtin_expect((x), 0))
#else /* __GCC__ */
#define LIKELY(x) ((x) == 1)
#define UNLIKELY(x) ((x) == 0)
@@ -385,6 +385,9 @@
typedef void yarv_interrupt_function_t(struct yarv_thread_struct *);
+#define YARV_VALUE_CACHE_SIZE 0x1000
+#define USE_VALUE_CACHE 1
+
typedef struct yarv_thread_struct
{
VALUE self;
@@ -434,7 +437,12 @@
int parse_in_eval;
- st_table *local_storage; /* thread local storage */
+ /* strage */
+ st_table *local_storage;
+#if USE_VALUE_CACHE
+ VALUE value_cache[YARV_VALUE_CACHE_SIZE + 1];
+ VALUE *value_cache_ptr;
+#endif
struct yarv_thread_struct *join_list_next;
struct yarv_thread_struct *join_list_head;
--
ML: yarv-diff quickml.atdot.net
Info: http://www.atdot.net/~ko1/quickml