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

ruby-changes:52496

From: normal <ko1@a...>
Date: Thu, 13 Sep 2018 05:49:24 +0900 (JST)
Subject: [ruby-changes:52496] normal:r64705 (trunk): cont.c (fiber_memsize): do not rely on ROOT_FIBER_CONTEXT

normal	2018-09-13 05:49:19 +0900 (Thu, 13 Sep 2018)

  New Revision: 64705

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=64705

  Log:
    cont.c (fiber_memsize): do not rely on ROOT_FIBER_CONTEXT
    
    We can check if the fiber we're interested in is the
    th->root_fiber for the owner thread, so there is no need to use
    ROOT_FIBER_CONTEXT.
    
    Note: there is no guarantee th->ec points to
    &th->root_fiber->cont.saved_ec, thus vm::thread_memsize may not
    account for root fiber correctly (pre-existing bug).
    
    [Bug #15050]

  Modified files:
    trunk/cont.c
Index: cont.c
===================================================================
--- cont.c	(revision 64704)
+++ cont.c	(revision 64705)
@@ -493,12 +493,15 @@ static size_t https://github.com/ruby/ruby/blob/trunk/cont.c#L493
 fiber_memsize(const void *ptr)
 {
     const rb_fiber_t *fib = ptr;
-    size_t size = 0;
+    size_t size = sizeof(*fib);
+    const rb_execution_context_t *saved_ec = &fib->cont.saved_ec;
+    const rb_thread_t *th = rb_ec_thread_ptr(saved_ec);
 
-    size = sizeof(*fib);
-    if (fib->cont.type != ROOT_FIBER_CONTEXT &&
-	fib->cont.saved_ec.local_storage != NULL) {
-	size += st_memsize(fib->cont.saved_ec.local_storage);
+    /*
+     * vm.c::thread_memsize already counts th->ec->local_storage
+     */
+    if (saved_ec->local_storage && fib != th->root_fiber) {
+	size += st_memsize(saved_ec->local_storage);
     }
     size += cont_memsize(&fib->cont);
     return size;

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

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