<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Efficient JNI programming, part I</title>
	<atom:link href="http://kennke.org/blog/2007/07/20/efficient-jni-programming-part-i/feed/" rel="self" type="application/rss+xml" />
	<link>http://kennke.org/blog/2007/07/20/efficient-jni-programming-part-i/</link>
	<description>Roman Kennke's ramblings</description>
	<pubDate>Tue, 06 Jan 2009 20:49:48 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5</generator>
		<item>
		<title>By: This note&#8217;s for you &#187; Blog Archive &#187; Efficient JNI programming IV: Wrapping native data objects</title>
		<link>http://kennke.org/blog/2007/07/20/efficient-jni-programming-part-i/#comment-51810</link>
		<dc:creator>This note&#8217;s for you &#187; Blog Archive &#187; Efficient JNI programming IV: Wrapping native data objects</dc:creator>
		<pubDate>Mon, 30 Jul 2007 20:59:55 +0000</pubDate>
		<guid isPermaLink="false">http://kennke.org/blog/2007/07/20/efficient-jni-programming-part-i/#comment-51810</guid>
		<description>[...] check out part I, part II and part III of this series too. Blog this:Digg [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] check out part I, part II and part III of this series too. Blog this:Digg [&#8230;]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: This note&#8217;s for you &#187; Blog Archive &#187; Efficient JNI programming III: Array access</title>
		<link>http://kennke.org/blog/2007/07/20/efficient-jni-programming-part-i/#comment-51698</link>
		<dc:creator>This note&#8217;s for you &#187; Blog Archive &#187; Efficient JNI programming III: Array access</dc:creator>
		<pubDate>Fri, 27 Jul 2007 22:18:29 +0000</pubDate>
		<guid isPermaLink="false">http://kennke.org/blog/2007/07/20/efficient-jni-programming-part-i/#comment-51698</guid>
		<description>[...] last two parts of this small series dealt with considerations when to implement stuff in a native JNI method and how to best implement field and method access in JNI. Now I will take a close look at another [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] last two parts of this small series dealt with considerations when to implement stuff in a native JNI method and how to best implement field and method access in JNI. Now I will take a close look at another [&#8230;]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: This note&#8217;s for you &#187; Blog Archive &#187; Efficient JNI programming II: Field and method access</title>
		<link>http://kennke.org/blog/2007/07/20/efficient-jni-programming-part-i/#comment-51588</link>
		<dc:creator>This note&#8217;s for you &#187; Blog Archive &#187; Efficient JNI programming II: Field and method access</dc:creator>
		<pubDate>Tue, 24 Jul 2007 19:31:36 +0000</pubDate>
		<guid isPermaLink="false">http://kennke.org/blog/2007/07/20/efficient-jni-programming-part-i/#comment-51588</guid>
		<description>[...] This note&#8217;s for you Just another WordPress weblog      &#171; Efficient JNI programming, part I [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] This note&#8217;s for you Just another WordPress weblog      &laquo; Efficient JNI programming, part I [&#8230;]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: roman</title>
		<link>http://kennke.org/blog/2007/07/20/efficient-jni-programming-part-i/#comment-51543</link>
		<dc:creator>roman</dc:creator>
		<pubDate>Mon, 23 Jul 2007 13:39:15 +0000</pubDate>
		<guid isPermaLink="false">http://kennke.org/blog/2007/07/20/efficient-jni-programming-part-i/#comment-51543</guid>
		<description>I wouldn't over-emphasize the 'overhead of a JNI call'. Granted, some VMs aren't really smart with this. On the other hand, many VMs are really damn smart and have no overhead for JNI calls at all. A good JIT for example would inline all the calling stuff into the generated machine code and makes a JNI call exactly as fast as any native function call. Even the less optimized VMs that I know aren't that bad in this regard. I think this is mostly a myth that stems from the other problems with JNI (field access, method access and array access).</description>
		<content:encoded><![CDATA[<p>I wouldn&#8217;t over-emphasize the &#8216;overhead of a JNI call&#8217;. Granted, some VMs aren&#8217;t really smart with this. On the other hand, many VMs are really damn smart and have no overhead for JNI calls at all. A good JIT for example would inline all the calling stuff into the generated machine code and makes a JNI call exactly as fast as any native function call. Even the less optimized VMs that I know aren&#8217;t that bad in this regard. I think this is mostly a myth that stems from the other problems with JNI (field access, method access and array access).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Wayne Meissner</title>
		<link>http://kennke.org/blog/2007/07/20/efficient-jni-programming-part-i/#comment-51539</link>
		<dc:creator>Wayne Meissner</dc:creator>
		<pubDate>Mon, 23 Jul 2007 11:14:12 +0000</pubDate>
		<guid isPermaLink="false">http://kennke.org/blog/2007/07/20/efficient-jni-programming-part-i/#comment-51539</guid>
		<description>Well, you now have more fodder for a "performance myths and fallacies" section :-)

Should be interesting if you benchmark the different use-cases, and the different ways of sending data (primitive vs object with JNI access, etc)

Of course, I suspect that any differences are largely washed away due to the overhead of a JNI call.</description>
		<content:encoded><![CDATA[<p>Well, you now have more fodder for a &#8220;performance myths and fallacies&#8221; section <img src='http://kennke.org/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Should be interesting if you benchmark the different use-cases, and the different ways of sending data (primitive vs object with JNI access, etc)</p>
<p>Of course, I suspect that any differences are largely washed away due to the overhead of a JNI call.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: roman</title>
		<link>http://kennke.org/blog/2007/07/20/efficient-jni-programming-part-i/#comment-51536</link>
		<dc:creator>roman</dc:creator>
		<pubDate>Mon, 23 Jul 2007 09:54:27 +0000</pubDate>
		<guid isPermaLink="false">http://kennke.org/blog/2007/07/20/efficient-jni-programming-part-i/#comment-51536</guid>
		<description>Wayne, thank you for your comments. I'd like to add my notes:

re 2) I don't think it's as easy as that. I doubt that JNI is optimized specifically for this. With JNI you can pass objects just as easily to JNI code as primitives, and it makes no difference (runtime-performance-wise) if you access a field in Java or in JNI. However, it's harder to do in JNI and easier to shoot in your foot (I'll discuss that in part II).

re 3) I don't agree here either. All in all there are 3 or 4 different ways to implement bulk data transfer, each of them has their advantages and disadvantages. None of them is the one perfect solution for all cases (for example, accessing ByteBuffers in Java is relatively slow, compared to Java arrays). It depends a lot on the actual scenario which way to choose. I'll discuss that in part III of this mini series.</description>
		<content:encoded><![CDATA[<p>Wayne, thank you for your comments. I&#8217;d like to add my notes:</p>
<p>re 2) I don&#8217;t think it&#8217;s as easy as that. I doubt that JNI is optimized specifically for this. With JNI you can pass objects just as easily to JNI code as primitives, and it makes no difference (runtime-performance-wise) if you access a field in Java or in JNI. However, it&#8217;s harder to do in JNI and easier to shoot in your foot (I&#8217;ll discuss that in part II).</p>
<p>re 3) I don&#8217;t agree here either. All in all there are 3 or 4 different ways to implement bulk data transfer, each of them has their advantages and disadvantages. None of them is the one perfect solution for all cases (for example, accessing ByteBuffers in Java is relatively slow, compared to Java arrays). It depends a lot on the actual scenario which way to choose. I&#8217;ll discuss that in part III of this mini series.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Wayne Meissner</title>
		<link>http://kennke.org/blog/2007/07/20/efficient-jni-programming-part-i/#comment-51528</link>
		<dc:creator>Wayne Meissner</dc:creator>
		<pubDate>Mon, 23 Jul 2007 03:31:56 +0000</pubDate>
		<guid isPermaLink="false">http://kennke.org/blog/2007/07/20/efficient-jni-programming-part-i/#comment-51528</guid>
		<description>Andrew Cowie covered a bit of JNI performance stuff in his LCA2007 talk as well.  Basically, it boils down to:

1) Do as much work on the other side of the boundary per boundary crossing as possible.  Like you said, if you're going to do a loop that calls a native function, then do it on the native side rather than in java.  This reduces the overhead of JNI calls.

2) Whenever possible, pass primitives (int, long, etc) down to JNI rather than classes.  JNI is optimised to handle these, plus it avoids calling back into java to pull out fields from a class.

3) If you're going to transfer bulk data from JNI to java, use direct ByteBuffers.  Not all arches seem to support pinning of primitive arrays.

For cases 1 + 2 (gaining access to existing libraries/native resources), use one of the JNI wrapper libraries like JNA or nlink  - they allow you to avoid writing any JNI code at all.</description>
		<content:encoded><![CDATA[<p>Andrew Cowie covered a bit of JNI performance stuff in his LCA2007 talk as well.  Basically, it boils down to:</p>
<p>1) Do as much work on the other side of the boundary per boundary crossing as possible.  Like you said, if you&#8217;re going to do a loop that calls a native function, then do it on the native side rather than in java.  This reduces the overhead of JNI calls.</p>
<p>2) Whenever possible, pass primitives (int, long, etc) down to JNI rather than classes.  JNI is optimised to handle these, plus it avoids calling back into java to pull out fields from a class.</p>
<p>3) If you&#8217;re going to transfer bulk data from JNI to java, use direct ByteBuffers.  Not all arches seem to support pinning of primitive arrays.</p>
<p>For cases 1 + 2 (gaining access to existing libraries/native resources), use one of the JNI wrapper libraries like JNA or nlink  - they allow you to avoid writing any JNI code at all.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
