Web Images Videos Maps News Shopping Gmail more »
Recently Visited Groups | Help | Sign in
Google Groups Home
valgrind and embedded ruby
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Heiko Leberer  
View profile  
 More options Nov 21 2005, 3:19 am
Newsgroups: comp.lang.ruby
From: "Heiko Leberer" <ih...@haleb.de>
Date: 21 Nov 2005 00:19:27 -0800
Local: Mon, Nov 21 2005 3:19 am
Subject: valgrind and embedded ruby
Hi all,

I'm currently testing an environment with embedding ruby and found an
issue when allocating a large amount of ruby string objects in external
C calls. Im not sure, whether I misunderstood the correct usage.

The Ruby version used is 1.8.4, own compile on red hat EL update 5.

The C environment is:
---------------------------------
#include "ruby.h"

int main (int argc, char *argv[])
{
    VALUE cModule;
    VALUE message;

    ruby_init();
    cModule = rb_define_module("CModule");

    rb_require("MemCheck.rb");

    for (long long l=0; l<1000LL; l++) {
        // convert C string to Ruby object
        message = rb_str_new2("C says Hello to Ruby."
                              "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                              "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                              "ABCDEFGHIJKLMNOPQRSTUVWXYZ");

        rb_funcall(cModule, rb_intern("sendToRuby"), 1, message);
    }

    return 0;

}

-------------------------
The Ruby script:
-------------------------
print("This is Ruby, required MemCheck.rb\n");

module CModule
  def CModule.sendToRuby(msgFromC)
  end
end
--------------------------

If I use valgrind to check for memory leaks, all is OK. If I now change
the loop count from 1000LL to 10000LL, valgrind throws errors:

==7903== Conditional jump or move depends on uninitialised value(s)
==7903==    at 0x806C904: gc_mark_children (gc.c:758)
==7903==    by 0x806C88F: gc_mark (gc.c:731)
==7903==    by 0x806C6C2: mark_locations_array (gc.c:626)
==7903==    by 0x806C6EF: rb_gc_mark_locations (gc.c:639)

(in total 496 errors from 39 contexts)

Has anybody seen this behavior? Where am I wrong?

Any help is appreciated, best regards

Heiko


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
men...@rydia.net  
View profile  
 More options Nov 21 2005, 12:20 pm
Newsgroups: comp.lang.ruby
From: men...@rydia.net
Date: Tue, 22 Nov 2005 02:20:10 +0900
Local: Mon, Nov 21 2005 12:20 pm
Subject: Re: valgrind and embedded ruby
Quoting Heiko Leberer <ih...@haleb.de>:

> If I use valgrind to check for memory leaks, all is OK. If I now
> change the loop count from 1000LL to 10000LL, valgrind throws
> errors:

> ==7903== Conditional jump or move depends on uninitialised
> value(s)
> ==7903==    at 0x806C904: gc_mark_children (gc.c:758)
> ==7903==    by 0x806C88F: gc_mark (gc.c:731)
> ==7903==    by 0x806C6C2: mark_locations_array (gc.c:626)
> ==7903==    by 0x806C6EF: rb_gc_mark_locations (gc.c:639)

> (in total 496 errors from 39 contexts)

This is probably the consequence of the "conservative" portion of
Ruby's garbage collector, which scans the stack and some other
areas which could be uninitialized.

You'll see similar warnings from valgrind in the presence of other
conservative GCs (for example, the boehm collector for C).

This is a consequence of the fact that a conservative collector must
scan memory without knowing whether it is initialized/valid in
advance or not.  Conservative collectors are designed to be robust
in the face of garbage pointers, however, so this is perfectly
safe.

-mental


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Heiko Leberer  
View profile  
 More options Nov 21 2005, 12:52 pm
Newsgroups: comp.lang.ruby
From: "Heiko Leberer" <ih...@haleb.de>
Date: 21 Nov 2005 09:52:07 -0800
Local: Mon, Nov 21 2005 12:52 pm
Subject: Re: valgrind and embedded ruby
That's great information, thanks.

I was just surprised, that the smaller loop doesn't throw any errors
and as soon as the allocated string objects exceed a given memeory
size, something seems to go wrong. Since Ruby is widely used, that
hinted at an usage error.

Thanks again and best regards,

Heiko


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
men...@rydia.net  
View profile  
 More options Nov 21 2005, 2:53 pm
Newsgroups: comp.lang.ruby
From: men...@rydia.net
Date: Tue, 22 Nov 2005 04:53:28 +0900
Local: Mon, Nov 21 2005 2:53 pm
Subject: Re: valgrind and embedded ruby
Quoting Heiko Leberer <ih...@haleb.de>:

> I was just surprised, that the smaller loop doesn't throw any
> errors and as soon as the allocated string objects exceed a given
> memeory size, something seems to go wrong.

There's a bit of a hysteresis in the garbage collection; probably
there aren't any collection passes being triggered until the
allocated space passes a certain threshold.

-mental


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google