<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>It Could Be So Much Better &#187; Mozilla</title>
	<atom:link href="http://itcouldbesomuchbetter.wordpress.com/category/mozilla/feed/" rel="self" type="application/rss+xml" />
	<link>http://itcouldbesomuchbetter.wordpress.com</link>
	<description>Free software hacking and general rumination</description>
	<lastBuildDate>Mon, 16 Jan 2012 20:43:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='itcouldbesomuchbetter.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>It Could Be So Much Better &#187; Mozilla</title>
		<link>http://itcouldbesomuchbetter.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://itcouldbesomuchbetter.wordpress.com/osd.xml" title="It Could Be So Much Better" />
	<atom:link rel='hub' href='http://itcouldbesomuchbetter.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Emacs hacks for Mozilla hackers</title>
		<link>http://itcouldbesomuchbetter.wordpress.com/2011/01/05/emacs-hacks-for-mozilla-hackers/</link>
		<comments>http://itcouldbesomuchbetter.wordpress.com/2011/01/05/emacs-hacks-for-mozilla-hackers/#comments</comments>
		<pubDate>Wed, 05 Jan 2011 20:44:54 +0000</pubDate>
		<dc:creator>jimblandy</dc:creator>
				<category><![CDATA[Mozilla]]></category>

		<guid isPermaLink="false">http://itcouldbesomuchbetter.wordpress.com/?p=78</guid>
		<description><![CDATA[If you use Emacs to work on Mozilla code, you might find something you like in my mozilla-elisp repository. It currently includes: mozilla-c-style.el, a package which defines a C/C++ indentation style named &#8220;Mozilla&#8221;, which you can select with C-c . (c-set-style). This properly handles case labels, long return expressions, and things like that. The comments [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=itcouldbesomuchbetter.wordpress.com&#038;blog=18307235&#038;post=78&#038;subd=itcouldbesomuchbetter&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you use Emacs to work on Mozilla code, you might find something you like in my <a href="http://hg.mozilla.org/users/jblandy_mozilla.com/mozilla-elisp/">mozilla-elisp</a> repository. It currently includes:</p>
<ul>
<li><strong>mozilla-c-style.el</strong>, a package which defines a C/C++ indentation style named &#8220;Mozilla&#8221;, which you can select with <strong>C-c .</strong> (c-set-style). This properly handles <strong>case</strong> labels, long <strong>return</strong> expressions, and things like that. The comments at the top explain how to turn it on by default in Mozilla code. It may have some SpiderMonkey-isms in it; if you send me bug reports, I will split it into &#8220;Mozilla&#8221; and &#8220;SpiderMonkey&#8221; styles.</li>
<li><strong>mercurial-queues.el</strong>, a major mode for editing Mercurial Queues series files, pushing, popping, and refreshing patches, and so on. In particular, the push and pop commands take care of refreshing any buffers visiting modified files. (This is currently slow if you have many buffers open, due to a shortcoming in <strong>vc</strong>&#8216;s Mercurial support that makes refreshing a buffer take a significant fraction of a second. I have an unpolished workaround; if anyone besides me begins to use this and complains to me, then I&#8217;ll certainly finish it up and get it into the code.)</li>
<li><strong>diff-find-mq-file.el</strong>, a quick hack to help &#8216;<strong>diff-goto-source</strong>&#8216; and &#8216;<strong>diff-apply-hunk</strong>&#8216;, commands that jump from a hunk in a patch file to the place where that hunk would apply, find the file to patch when they&#8217;re invoked on a patch in a <strong>.hg/patches</strong> directory.</li>
</ul>
<p>Happy Hacking!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/itcouldbesomuchbetter.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/itcouldbesomuchbetter.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/itcouldbesomuchbetter.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/itcouldbesomuchbetter.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/itcouldbesomuchbetter.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/itcouldbesomuchbetter.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/itcouldbesomuchbetter.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/itcouldbesomuchbetter.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/itcouldbesomuchbetter.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/itcouldbesomuchbetter.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/itcouldbesomuchbetter.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/itcouldbesomuchbetter.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/itcouldbesomuchbetter.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/itcouldbesomuchbetter.wordpress.com/78/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=itcouldbesomuchbetter.wordpress.com&#038;blog=18307235&#038;post=78&#038;subd=itcouldbesomuchbetter&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://itcouldbesomuchbetter.wordpress.com/2011/01/05/emacs-hacks-for-mozilla-hackers/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/25f8ea5948e459788767ca9b08aee824?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jimblandy</media:title>
		</media:content>
	</item>
		<item>
		<title>SpiderMonkey&#8217;s conservative collector still needs some rooting</title>
		<link>http://itcouldbesomuchbetter.wordpress.com/2010/12/20/spidermonkeys-conservative-collector-still-needs-some-rooting/</link>
		<comments>http://itcouldbesomuchbetter.wordpress.com/2010/12/20/spidermonkeys-conservative-collector-still-needs-some-rooting/#comments</comments>
		<pubDate>Mon, 20 Dec 2010 20:02:55 +0000</pubDate>
		<dc:creator>jimblandy</dc:creator>
				<category><![CDATA[Mozilla]]></category>

		<guid isPermaLink="false">http://itcouldbesomuchbetter.wordpress.com/?p=65</guid>
		<description><![CDATA[We&#8217;ve just landed the definition in &#60;jsapi.h&#62; of a new template type, js::Anchor, in TraceMonkey. Developers writing code against the JSAPI will need to understand it to avoid garbage collection hazards. The need for js::Anchor became clear in bug 614138, but I&#8217;ll let the comments from &#60;jsapi.h&#62; tell the story: Protecting non-jsval, non-JSObject&#160;*, non-JSString&#160;* values [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=itcouldbesomuchbetter.wordpress.com&#038;blog=18307235&#038;post=65&#038;subd=itcouldbesomuchbetter&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>We&#8217;ve <a href="http://hg.mozilla.org/tracemonkey/rev/929ed9d5d81b">just landed</a> the definition in <strong>&lt;jsapi.h&gt;</strong> of a new template type, <strong>js::Anchor</strong>, in TraceMonkey. Developers writing code against the JSAPI will need to understand it to avoid garbage collection hazards. The need for <strong>js::Anchor</strong> became clear in <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=614138">bug 614138</a>, but I&#8217;ll let the comments from <strong>&lt;jsapi.h&gt;</strong> tell the story:</p>
<h2>Protecting non-<strong>jsval</strong>, non-<strong>JSObject&nbsp;*</strong>, non-<strong>JSString&nbsp;*</strong> values from collection</h2>
<p>Most of the time, the garbage collector&#8217;s conservative stack scanner works behind the scenes, finding all live values and protecting them from being collected. However, when JSAPI client code obtains a pointer to data the scanner does not know about, owned by an object the scanner does know about, Care Must Be Taken.</p>
<p>The scanner recognizes only a select set of types: pointers to JSObjects and similar things (JSFunctions, and so on), pointers to JSStrings, and jsvals. So while the scanner finds all live <strong>JSString</strong> pointers, it does not notice <strong>jschar</strong> pointers.</p>
<p>So suppose we have:</p>
<p><pre class="brush: plain; light: true;">
  void f(JSString *str) {
    const jschar *ch = JS_GetStringCharsZ(str);
    ... do stuff with ch, but no uses of str ...
  }
</pre></p>
<p>After the call to <strong>JS_GetStringCharsZ</strong>, there are no further uses of <strong>str</strong>, which means that the compiler is within its rights to not store it anywhere. But because the stack scanner will not notice <strong>ch</strong>, there is no longer any live value in this frame that would keep the string alive. If <strong>str</strong> is the last reference to that <strong>JSString</strong>, and the collector runs while we are using <strong>ch</strong>, the string&#8217;s array of <strong>jschar</strong>s may be freed out from under us.</p>
<p>Note that there is only an issue when 1) we extract a thing X the scanner doesn&#8217;t recognize from 2) a thing Y the scanner does recognize, and 3) if Y gets garbage-collected, then X gets freed. If we have code like this:</p>
<p><pre class="brush: plain; light: true;">
  void g(JSObject *obj) {
    jsval x;
    JS_GetProperty(obj, &quot;x&quot;, &amp;x);
    ... do stuff with x ...
  }
</pre></p>
<p>there&#8217;s no problem, because the value we&#8217;ve extracted, x, is a jsval, a type that the conservative scanner recognizes.</p>
<p>Conservative GC frees us from the obligation to explicitly root the types it knows about, but when we work with derived values like <strong>ch</strong>, we must root their owners, as the derived value alone won&#8217;t keep them alive.</p>
<p>A js::Anchor is a kind of GC root that allows us to keep the owners of derived values like <strong>ch</strong> alive throughout the Anchor&#8217;s lifetime. We could fix the above code as follows:</p>
<p><pre class="brush: plain; light: true;">
  void f(JSString *str) {
    js::Anchor&lt;JSString *&gt; a_str(str);
    const jschar *ch = JS_GetStringCharsZ(str);
    ... do stuff with ch, but no uses of str ...
  }
</pre></p>
<p>This simply ensures that <strong>str</strong> will be live until <strong>a_str</strong> goes out of scope. As long as we don&#8217;t retain a pointer to the string&#8217;s characters for longer than that, we have avoided all garbage collection hazards.</p>
<p><em>Update:</em> Of course, this belongs in the JSAPI docs, not a blog post or a header file. I&#8217;ll get it up there shortly; third try&#8217;s a charm.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/itcouldbesomuchbetter.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/itcouldbesomuchbetter.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/itcouldbesomuchbetter.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/itcouldbesomuchbetter.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/itcouldbesomuchbetter.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/itcouldbesomuchbetter.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/itcouldbesomuchbetter.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/itcouldbesomuchbetter.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/itcouldbesomuchbetter.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/itcouldbesomuchbetter.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/itcouldbesomuchbetter.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/itcouldbesomuchbetter.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/itcouldbesomuchbetter.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/itcouldbesomuchbetter.wordpress.com/65/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=itcouldbesomuchbetter.wordpress.com&#038;blog=18307235&#038;post=65&#038;subd=itcouldbesomuchbetter&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://itcouldbesomuchbetter.wordpress.com/2010/12/20/spidermonkeys-conservative-collector-still-needs-some-rooting/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/25f8ea5948e459788767ca9b08aee824?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jimblandy</media:title>
		</media:content>
	</item>
		<item>
		<title>Debugging SpiderMonkey with Archer</title>
		<link>http://itcouldbesomuchbetter.wordpress.com/2010/12/20/debugging-spidermonkey-with-archer-2/</link>
		<comments>http://itcouldbesomuchbetter.wordpress.com/2010/12/20/debugging-spidermonkey-with-archer-2/#comments</comments>
		<pubDate>Mon, 20 Dec 2010 20:01:56 +0000</pubDate>
		<dc:creator>jimblandy</dc:creator>
				<category><![CDATA[Mozilla]]></category>

		<guid isPermaLink="false">http://itcouldbesomuchbetter.wordpress.com/?p=61</guid>
		<description><![CDATA[If you&#8217;re hacking on SpiderMonkey, the JavaScript engine used in Mozilla Firefox, the debugger can be less than helpful when viewing SpiderMonkey&#8217;s data structures: If you know enough magic, you can make it work, but there&#8217;s a lot of clutter, and it&#8217;s a distraction from the task at hand. The Archer Project is a development [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=itcouldbesomuchbetter.wordpress.com&#038;blog=18307235&#038;post=61&#038;subd=itcouldbesomuchbetter&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re hacking on SpiderMonkey, the JavaScript engine used in Mozilla Firefox, the debugger can be less than helpful when viewing SpiderMonkey&#8217;s data structures:</p>
<p><pre class="brush: plain; light: true;">
(gdb) print str
$1 = (JSString *) 0x7ffff680a440
(gdb) print *str
$2 = {mLengthAndFlags = 148, {mChars = 0x7ffff680a450, mLeft = 0x7ffff680a450}, {mInlineStorage = {118, 97, 114, 32}, e = {{mCapacity = 9007688887369846, mParent = 0x20007200610076, mBufferWithInfo = 0x20007200610076}, {mBase = 0x20003d00200078, mRight = 0x20003d00200078}}, externalStringType = 6357110}}
(gdb) print/c str-&gt;mChars[0]@(str-&gt;mLengthAndFlags / 16)
$4 = {118 'v', 97 'a', 114 'r', 32 ' ', 120 'x', 32 ' ', 61 '=', 32 ' ', 53 '5'}
</pre></p>
<p>If you know enough magic, you can make it work, but there&#8217;s a lot of clutter, and it&#8217;s a distraction from the task at hand.</p>
<p>The <a title="Project Archer" href="http://sourceware.org/gdb/wiki/ProjectArcher">Archer Project</a> is a development branch of GDB that you can customize in Python. In particular, you can have Archer automatically call your own Python functions to format particular types of values.  I&#8217;ve written a set of pretty-printers for SpiderMonkey&#8217;s datatypes, so for me the above interaction would go:</p>
<p><pre class="brush: plain; light: true;">
(gdb) print str
$1 = 0x7ffff680a440 &quot;var x=5&quot; ATOMIZED
(gdb) print *str
$2 = {mLengthAndFlags = (7 &lt;&lt; 4)|FLAT|ATOMIZED, mChars = 0x7ffff680a450, externalStringType = 6357110}
</pre></p>
<p>When printing a pointer to a <strong>JSString</strong>, Archer shows the string&#8217;s contents, and any flags (like ATOMIZED). When printing a <strong>JSString</strong> struct value, Archer omits dead union branches &#8212; in this case, most of the members.</p>
<p>Archer applies the pretty-printers whenever it needs to print a value, so, for example, stack traces are legible, too:</p>
<p><pre class="brush: plain; light: true;">
(gdb) where 1
#0  js_SetPropertyHelper (cx=0xa8e550, obj=0x7ffff6803048 [Object global], id=$jsid(&quot;x&quot;), defineHow=1, vp=0x7fffffffc7f0, strict=0) at ../jsobj.cpp:5367
</pre></p>
<p>Here the <strong>JSObject</strong> pointer and the <strong>jsid</strong> have been printed in a more helpful way.</p>
<p>At present, I have pretty-printers for:</p>
<ul>
<li><strong>jsval</strong> and <strong>js::Value</strong></li>
<li><strong>JSString</strong>, <strong>JSString *</strong>, <strong>JSAtom *</strong>, and <strong>jsid</strong></li>
<li><strong>JSObject *</strong>, <strong>JSFunction *</strong>, and <strong>JSFunction</strong></li>
<li><strong>js::PropertyCacheEntry</strong> and <strong>js::PCVal</strong></li>
<li><strong>JSParseNode *</strong>, <strong>JSDefinition *</strong>, <strong>JSParseNode</strong>, <strong>JSDefinition</strong>, and <strong>JSFunctionBox *</strong></li>
<li><strong>js::Shape</strong></li>
</ul>
<p>You can check out a copy of the current sources using <a title="The Mercurial Source Control Management System" href="http://mercurial.selenic.com/">Mercurial</a>:<br />
<pre class="brush: plain; light: true;">
$ hg clone http://hg.mozilla.org/users/jblandy_mozilla.com/archer-mozilla
destination directory: archer-mozilla
requesting all changes
...
22 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ cd archer-mozilla
$ more README
</pre><br />
This creates a directory called <strong>archer-mozilla</strong>; the <strong>README</strong> file there explains how to make Archer use the pretty-printers.</p>
<p>This is very much a work in progress; there are certainly bugs, and while there are regression tests, they don&#8217;t cover all the pretty-printers the package defines. Please let me know if you find a bug, or have suggestions for improvements.</p>
<p>I use Archer on Linux; I don&#8217;t know how well it works on Macintosh OS X or Windows. I hear that these pretty-printers can be used with modern stock GDB releases.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/itcouldbesomuchbetter.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/itcouldbesomuchbetter.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/itcouldbesomuchbetter.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/itcouldbesomuchbetter.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/itcouldbesomuchbetter.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/itcouldbesomuchbetter.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/itcouldbesomuchbetter.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/itcouldbesomuchbetter.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/itcouldbesomuchbetter.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/itcouldbesomuchbetter.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/itcouldbesomuchbetter.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/itcouldbesomuchbetter.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/itcouldbesomuchbetter.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/itcouldbesomuchbetter.wordpress.com/61/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=itcouldbesomuchbetter.wordpress.com&#038;blog=18307235&#038;post=61&#038;subd=itcouldbesomuchbetter&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://itcouldbesomuchbetter.wordpress.com/2010/12/20/debugging-spidermonkey-with-archer-2/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/25f8ea5948e459788767ca9b08aee824?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jimblandy</media:title>
		</media:content>
	</item>
	</channel>
</rss>
