[前][次][番号順一覧][スレッド一覧]

ruby-changes:7736

From: nobu <ko1@a...>
Date: Tue, 9 Sep 2008 00:38:22 +0900 (JST)
Subject: [ruby-changes:7736] Ruby:r19257 (mvm): * vm_core.h (struct rb_vm_struct): includes method cache.

nobu	2008-09-09 00:37:48 +0900 (Tue, 09 Sep 2008)

  New Revision: 19257

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=19257

  Log:
    * vm_core.h (struct rb_vm_struct): includes method cache.
    
    * vm.c (vm_init2): initializes method cache.
    
    * vm_eval.c, vm_method.c: use method cache in VM.

  Modified files:
    branches/mvm/ChangeLog
    branches/mvm/vm.c
    branches/mvm/vm_core.h
    branches/mvm/vm_eval.c
    branches/mvm/vm_method.c

Index: mvm/ChangeLog
===================================================================
--- mvm/ChangeLog	(revision 19256)
+++ mvm/ChangeLog	(revision 19257)
@@ -1,5 +1,11 @@
-Tue Sep  9 00:34:47 2008  Nobuyoshi Nakada  <nobu@r...>
+Tue Sep  9 00:37:45 2008  Nobuyoshi Nakada  <nobu@r...>
 
+	* vm_core.h (struct rb_vm_struct): includes method cache.
+
+	* vm.c (vm_init2): initializes method cache.
+
+	* vm_eval.c, vm_method.c: use method cache in VM.
+
 	* mvm.c (specific_key): must be initialized.
 
 	* st.c (st_init_table_with_size, ADD_DIRECT): fixed typo.
Index: mvm/vm_core.h
===================================================================
--- mvm/vm_core.h	(revision 19256)
+++ mvm/vm_core.h	(revision 19257)
@@ -352,6 +352,8 @@
     int argc;
     char **argv;
 
+    struct cache_entry *cache;
+
 #ifdef RUBY_DEBUG_ENV
     int enable_coredump;
 #endif
Index: mvm/vm_eval.c
===================================================================
--- mvm/vm_eval.c	(revision 19256)
+++ mvm/vm_eval.c	(revision 19257)
@@ -204,7 +204,7 @@
 		 rb_id2name(mid), (void *)recv);
     }
     /* is it in the method cache? */
-    ent = cache + EXPR1(klass, mid);
+    ent = GET_VM()->cache + EXPR1(klass, mid);
 
     if (ent->mid == mid && ent->klass == klass) {
 	if (!ent->method)
Index: mvm/vm_method.c
===================================================================
--- mvm/vm_method.c	(revision 19256)
+++ mvm/vm_method.c	(revision 19257)
@@ -22,7 +22,6 @@
     NODE *method;
 };
 
-static struct cache_entry cache[CACHE_SIZE];
 #define ruby_running (GET_VM()->running)
 /* int ruby_running = 0; */
 
@@ -30,12 +29,13 @@
 rb_clear_cache(void)
 {
     struct cache_entry *ent, *end;
+    rb_vm_t *vm = GET_VM();
 
     rb_vm_change_state();
 
-    if (!ruby_running)
+    if (!vm->running)
 	return;
-    ent = cache;
+    ent = vm->cache;
     end = ent + CACHE_SIZE;
     while (ent < end) {
 	ent->mid = 0;
@@ -47,12 +47,13 @@
 rb_clear_cache_for_undef(VALUE klass, ID id)
 {
     struct cache_entry *ent, *end;
+    rb_vm_t *vm = GET_VM();
 
     rb_vm_change_state();
 
-    if (!ruby_running)
+    if (!vm->running)
 	return;
-    ent = cache;
+    ent = vm->cache;
     end = ent + CACHE_SIZE;
     while (ent < end) {
 	if (ent->oklass == klass && ent->mid == id) {
@@ -66,12 +67,13 @@
 rb_clear_cache_by_id(ID id)
 {
     struct cache_entry *ent, *end;
+    rb_vm_t *vm = GET_VM();
 
     rb_vm_change_state();
 
-    if (!ruby_running)
+    if (!vm->running)
 	return;
-    ent = cache;
+    ent = vm->cache;
     end = ent + CACHE_SIZE;
     while (ent < end) {
 	if (ent->mid == id) {
@@ -85,12 +87,13 @@
 rb_clear_cache_by_class(VALUE klass)
 {
     struct cache_entry *ent, *end;
+    rb_vm_t *vm = GET_VM();
 
     rb_vm_change_state();
 
-    if (!ruby_running)
+    if (!vm->running)
 	return;
-    ent = cache;
+    ent = vm->cache;
     end = ent + CACHE_SIZE;
     while (ent < end) {
 	if (ent->klass == klass || ent->oklass == klass) {
@@ -251,11 +254,12 @@
 {
     NODE *volatile fbody, *body;
     NODE *method;
+    rb_vm_t *vm = GET_VM();
 
     if ((fbody = search_method(klass, id, 0)) == 0 || !fbody->nd_body) {
 	/* store empty info in cache */
 	struct cache_entry *ent;
-	ent = cache + EXPR1(klass, id);
+	ent = vm->cache + EXPR1(klass, id);
 	ent->klass = klass;
 	ent->mid = ent->mid0 = id;
 	ent->method = 0;
@@ -265,10 +269,10 @@
 
     method = fbody->nd_body;
 
-    if (ruby_running) {
+    if (vm->running) {
 	/* store in cache */
 	struct cache_entry *ent;
-	ent = cache + EXPR1(klass, id);
+	ent = vm->cache + EXPR1(klass, id);
 	ent->klass = klass;
 	ent->mid = id;
 	ent->mid0 = fbody->nd_oid;
@@ -291,7 +295,7 @@
 {
     struct cache_entry *ent;
 
-    ent = cache + EXPR1(klass, id);
+    ent = GET_VM()->cache + EXPR1(klass, id);
     if (ent->mid == id && ent->klass == klass) {
 	if (ent->method) return ent->method;
 	return 0;
Index: mvm/vm.c
===================================================================
--- mvm/vm.c	(revision 19256)
+++ mvm/vm.c	(revision 19257)
@@ -1410,6 +1410,7 @@
     vm->global_state_version = 1;
     vm->specific_storage.len = rb_vm_key_count();
     vm->specific_storage.ptr = calloc(vm->specific_storage.len, sizeof(VALUE));
+    vm->cache = ALLOC_N(struct cache_entry, CACHE_SIZE);
 }
 
 /* Thread */

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]