<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" gd:etag="W/&quot;D0ENSXk4fCp7ImA9WhZQFE8.&quot;"><id>tag:blogger.com,1999:blog-29039672</id><updated>2011-04-21T15:41:38.734-07:00</updated><category term="JNI" /><category term="Other" /><category term="Java" /><category term="News" /><category term="Linux" /><category term="C/C++" /><title>Learn it</title><subtitle type="html" /><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://learn-from-the-guru.blogspot.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://learn-from-the-guru.blogspot.com/" /><author><name>Emo</name><uri>http://www.blogger.com/profile/16976929775234907073</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>9</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/LearnIt" /><feedburner:info uri="learnit" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry gd:etag="W/&quot;CUcFQn05fSp7ImA9WxZQF04.&quot;"><id>tag:blogger.com,1999:blog-29039672.post-6712199124644504518</id><published>2008-02-19T15:06:00.000-08:00</published><updated>2008-02-22T18:16:53.325-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-02-22T18:16:53.325-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Linux" /><category scheme="http://www.blogger.com/atom/ns#" term="C/C++" /><category scheme="http://www.blogger.com/atom/ns#" term="JNI" /><title>Large File Support in Linux for C/C++ operations</title><content type="html">&lt;div style="text-align: center;"&gt;&lt;span style="font-weight: bold;"&gt;Overview&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div style="text-align: left;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;My current project deals with high definition movies that are encrypted and used for IPTV. The problem occurred when I tried to encrypt a real world 4.8GB movie. The application server (OC4J) crashed with the error:&lt;br /&gt;&lt;code&gt;File size limit exceeded$JAVA_HOME/bin/java $JVMARGS -jar $OC4J_JAR $CMDARGS &lt;/code&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;Limitations&lt;/span&gt;&lt;br /&gt;&lt;/div&gt; In a C/C++ application the file operations can be handled using the &lt;code style="font-style: italic;"&gt;&lt;a href="http://www.ncsa.uiuc.edu/UserInfo/Resources/Hardware/IBMp690/IBM/usr/share/man/info/en_US/a_doc_lib/files/aixfiles/fcntl.h.htm"&gt;fcntl.h&lt;/a&gt; &lt;/code&gt; header file. It provides operations for opening, writing to a file and many more. The size of every file is stored in a variable of type &lt;tt&gt;off_t&lt;/tt&gt;. For 32-bit systems the maximum value for &lt;tt&gt;off_t &lt;/tt&gt;is 2&lt;sup&gt;31 &lt;/sup&gt;thus limiting the maximal file size to 2&lt;sup&gt;31&lt;/sup&gt; bytes (2 GiB). For 64 bit systems  like x86-64 this maximum value is much greater and they have support for large files with size up to 2&lt;sup&gt;63&lt;/sup&gt; bytes.  &lt;p class="line867"&gt; &lt;/p&gt;&lt;div style="text-align: center;"&gt;&lt;span style="font-weight: bold;"&gt;Prerequisites&lt;/span&gt;&lt;br /&gt;&lt;/div&gt; &lt;span class="anchor" id="line-9"&gt;&lt;/span&gt;&lt;span class="anchor" id="line-10"&gt;&lt;/span&gt;&lt;p class="line874"&gt;The LFS support is done by the Linux kernel and the GNU C library (glibc) and is implemented since version 2.4.0 of the Linux kernel and glibc 2.2.3 (e.g. SuSE 7.2, Red Hat 7.1). The file system is also important - ext2/ext3 have full support for LFS.&lt;br /&gt;&lt;/p&gt;&lt;p style="text-align: center;" class="line874"&gt;&lt;span style="font-weight: bold;"&gt;OS Configuration&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p class="line874"&gt;The current configuration of the OS should also be checked. All resource and process limitations can be examined and changed using  the Linux command &lt;a href="http://bloggerdigest.blogspot.com/2006/10/purpose-of-ulimit-linux-command.html"&gt;&lt;span style="font-style: italic;"&gt;ulimit&lt;/span&gt;&lt;/a&gt; e.g.:&lt;/p&gt;&lt;p class="line874"&gt;&lt;code&gt;$ulimit -a&lt;/code&gt;&lt;/p&gt;&lt;p class="line874"&gt;&lt;code&gt;...&lt;br /&gt;&lt;/code&gt;&lt;/p&gt;&lt;p class="line874"&gt;&lt;code&gt;file size               (blocks, -f) unlimited&lt;br /&gt;&lt;/code&gt;&lt;/p&gt;&lt;p class="line867"&gt; &lt;/p&gt;&lt;p class="line867"&gt; &lt;/p&gt;&lt;div style="text-align: center;"&gt;&lt;div style="text-align: left;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt; The "file size" property shows the maximum size of a file in bytes that you can manipulate - probably a very large number or unlimited. If it's not use the same command to change it to any number (e.g. 5000000 bytes) or unlimited:&lt;br /&gt;&lt;code&gt;$ulimit -S -f unlimited&lt;/code&gt;&lt;br /&gt;After that you can create a large file for a test. This creates around 5GB file:&lt;br /&gt;&lt;code&gt;$dd if=/dev/zero of=outputfile bs=1M count=5&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="font-weight: bold;"&gt;Resolutions&lt;/span&gt;&lt;br /&gt;&lt;/div&gt; &lt;span class="anchor" id="line-19"&gt;&lt;/span&gt;&lt;ul&gt;&lt;li&gt;Compile your programs with "gcc -D_FILE_OFFSET_BITS=64" or "g++ -D_FILE_OFFSET_BITS=64" for C++ code. This forces all file access calls to use the 64 bit variants. It's important to always use the correct data types and to not use e.g. int that is 32 bit instead of off_t (file size). For portability with other platforms you should use getconf LFS_CFLAGS which will return -D_FILE_OFFSET_BITS=64 on Linux platforms but might return something else on e.g. Solaris. For linking, you should use the link flags that are reported via getconf LFS_LDFLAGS. On Linux systems, you do not need special link flags. &lt;/li&gt;&lt;li&gt;Define _LARGEFILE_SOURCE and _LARGEFILE64_SOURCE. With these defines you can use the LFS functions like open64 directly. &lt;span class="anchor" id="line-21"&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;Use the O_LARGEFILE flag with open to operate on large files. &lt;span class="anchor" id="line-22"&gt;&lt;/span&gt;&lt;span class="anchor" id="line-23"&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p class="line867"&gt; &lt;/p&gt; &lt;span class="anchor" id="line-24"&gt;&lt;/span&gt;&lt;p class="line874"&gt;I chose the first solution and changed the build script that compiles all components (to links them into a shared binary library later) :&lt;span class="anchor" id="line-25"&gt;&lt;/span&gt;&lt;span class="anchor" id="line-26"&gt;&lt;/span&gt;&lt;/p&gt;&lt;pre&gt;g++  -D_FILE_OFFSET_BITS=64 ...&lt;br /&gt;&lt;span class="anchor" id="line-27"&gt;&lt;/span&gt;&lt;/pre&gt;&lt;span class="anchor" id="line-28"&gt;&lt;/span&gt;&lt;p class="line862"&gt;No flag is needed during the linkage phase. &lt;strong&gt;This approach do not require code changes!&lt;/strong&gt; &lt;span class="anchor" id="line-29"&gt;&lt;/span&gt;&lt;span class="anchor" id="line-30"&gt;&lt;/span&gt;&lt;span class="anchor" id="line-31"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="line867"&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="text-align: center;"&gt;&lt;span style="font-weight: bold;"&gt;Implemetation&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;p class="line867"&gt;A sample C/C++ implementation follows:&lt;br /&gt; - Import required headers:&lt;br /&gt;&lt;code&gt;#include "fcntl.h"&lt;/code&gt;&lt;br /&gt; - Open file with name outputFileName for create/write:&lt;br /&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;&lt;pre&gt;int hOutputMovie = open(outputFileName, O_CREAT | O_WRONLY, S_IRWXU);&lt;br /&gt;if (-1 == hOutputMovie)&lt;br /&gt;{&lt;br /&gt; loggerVpr.log("Problem opening file %s", outputFileNameChars);&lt;br /&gt; ...&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt; - Write to the file some buffer of data (unsigned char *buffer) with specified length (int len):&lt;br /&gt;&lt;code&gt;&lt;/code&gt;&lt;pre&gt;if (len != write(hOutputMovie, buffer, len))&lt;br /&gt;{&lt;br /&gt; loggerVpr.log("\nUnable to write data to file with fd %d", hOutputMovie);&lt;br /&gt; return false;&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;div style="text-align: center;"&gt;&lt;span style="font-weight: bold;"&gt;References&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;a class="http" href="http://www.ncsa.uiuc.edu/UserInfo/Resources/Hardware/IBMp690/IBM/usr/share/man/info/en_US/a_doc_lib/files/aixfiles/fcntl.h.htm"&gt;fcntl.h&lt;/a&gt;&lt;br /&gt;&lt;span class="anchor" id="line-57"&gt;&lt;/span&gt;&lt;span class="anchor" id="line-58"&gt;&lt;/span&gt;&lt;a class="http" href="http://www.suse.de/%7Eaj/linux_lfs.html"&gt;Suse OS&lt;/a&gt;&lt;br /&gt;&lt;a class="http" href="http://publib.boulder.ibm.com/infocenter/systems/index.jsp?topic=/com.ibm.aix.genprogc/doc/genprogc/prg_lrg_files.htm"&gt;AIX OS&lt;/a&gt;&lt;br /&gt;&lt;a class="http" href="http://www.suse.de/%7Eaj/linux_lfs.html"&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/29039672-6712199124644504518?l=learn-from-the-guru.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/LearnIt/~4/1Sv2pnmxlK8" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://learn-from-the-guru.blogspot.com/feeds/6712199124644504518/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=29039672&amp;postID=6712199124644504518" title="6 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/29039672/posts/default/6712199124644504518?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/29039672/posts/default/6712199124644504518?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/LearnIt/~3/1Sv2pnmxlK8/large-file-support-in-linux-for-cc.html" title="Large File Support in Linux for C/C++ operations" /><author><name>Emo</name><uri>http://www.blogger.com/profile/16976929775234907073</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>6</thr:total><feedburner:origLink>http://learn-from-the-guru.blogspot.com/2008/02/large-file-support-in-linux-for-cc.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEENQHk9eSp7ImA9WxZTFU4.&quot;"><id>tag:blogger.com,1999:blog-29039672.post-8386571694850726854</id><published>2008-01-16T17:11:00.000-08:00</published><updated>2008-01-16T17:18:11.761-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-01-16T17:18:11.761-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Java" /><category scheme="http://www.blogger.com/atom/ns#" term="C/C++" /><category scheme="http://www.blogger.com/atom/ns#" term="JNI" /><title>Functions with a Variable Argument List II</title><content type="html">After using functions with a variable argument list to implement &lt;a href="http://learn-from-the-guru.blogspot.com/2007/10/functions-with-variable-argument-list.html"&gt;a simple logging sollution&lt;/a&gt; I found out that those functions do a great job also in the &lt;span style="font-weight: bold;"&gt;exception handling&lt;/span&gt;.&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;When you want to throw an exception you usually implement a utility method like this:&lt;br /&gt;&lt;i&gt;&lt;span style="font-style: italic;"&gt;&lt;/span&gt;&lt;/i&gt;&lt;i&gt;&lt;span style="font-style: italic;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/i&gt;&lt;code&gt;void &lt;span style="font-weight: bold;"&gt;throwByName&lt;/span&gt;(JNIEnv *env, const char *name, const char *msg)&lt;br /&gt;{&lt;br /&gt;env-&gt;ExceptionDescribe();&lt;br /&gt;env-&gt;ExceptionClear();&lt;br /&gt;&lt;br /&gt;jclass cls = env-&gt;FindClass(name);&lt;br /&gt;/* if cls is NULL, an exception has already been thrown */&lt;br /&gt;if (cls != NULL)&lt;br /&gt;{&lt;br /&gt;env-&gt;ThrowNew(cls, msg);&lt;br /&gt;}&lt;br /&gt;/* free the local ref */&lt;br /&gt;env-&gt;DeleteLocalRef(cls);&lt;br /&gt;}&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;This method can be invoked in such a way:&lt;br /&gt;&lt;code&gt;char buffer[128];&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;throwByName&lt;/span&gt;(env, "com/exceptions/MyException", buffer); &lt;/code&gt;&lt;br /&gt;The problem is that if you have a lot of methods and exception condition you have to copy/paste every time the exception class that is inconvenient. Also after the first refactoring you'll probably have to change the exception class on so much places.&lt;br /&gt;To avoid those problems you can implement utility methods for all the exceptions that are used (or maybe the most often used) to store the exception class:&lt;br /&gt;&lt;code&gt;void &lt;span style="font-weight: bold;"&gt;throwMyException&lt;/span&gt;(JNIEnv * env, const char * errorMessage, ...)&lt;br /&gt;{&lt;br /&gt;char buffer[STACK_TRACE_SIZE];&lt;br /&gt;va_list args;&lt;br /&gt;va_start(args, errorMessage);&lt;br /&gt;vsnprintf(buffer, sizeof(buffer), errorMessage, args);&lt;br /&gt;&lt;br /&gt;throwByName(env, "com/exceptions/MyException", buffer);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;The benefit is that you can throw that particular exception very easy and without much copy/paste:&lt;br /&gt;&lt;code&gt;&lt;span style="font-weight: bold;"&gt;throwMyException&lt;/span&gt;(env, "Error finishing encryption!");&lt;br /&gt;&lt;br /&gt;You can also take a look at &lt;a href="http://learn-from-the-guru.blogspot.com/2007/12/java-native-interface-jni-tutorial-hell.html"&gt;this post&lt;/a&gt; for more tips&amp;amp;trick for JNI.&lt;br /&gt;&lt;/code&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/29039672-8386571694850726854?l=learn-from-the-guru.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/LearnIt/~4/6uJdmAkCxH0" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://learn-from-the-guru.blogspot.com/feeds/8386571694850726854/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=29039672&amp;postID=8386571694850726854" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/29039672/posts/default/8386571694850726854?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/29039672/posts/default/8386571694850726854?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/LearnIt/~3/6uJdmAkCxH0/functions-with-variable-argument-list.html" title="Functions with a Variable Argument List II" /><author><name>Emo</name><uri>http://www.blogger.com/profile/16976929775234907073</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://learn-from-the-guru.blogspot.com/2008/01/functions-with-variable-argument-list.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEAGRX06eSp7ImA9WxZTFU4.&quot;"><id>tag:blogger.com,1999:blog-29039672.post-164167297901942521</id><published>2008-01-16T08:12:00.000-08:00</published><updated>2008-01-16T17:18:44.311-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-01-16T17:18:44.311-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Java" /><category scheme="http://www.blogger.com/atom/ns#" term="C/C++" /><category scheme="http://www.blogger.com/atom/ns#" term="JNI" /><title>Functions with a Variable Argument List</title><content type="html">My current project is a JNI application -  invokes C++ code from Java. I began  implementation of a Logger component for   the C++ part. As usually I wanted to integrate it very easy with just replacing the previous printing to &lt;a href="http://www.cplusplus.com/reference/clibrary/cstdio/stdout.html"&gt;&lt;i&gt;&lt;i&gt;stdout&lt;/i&gt;&lt;/i&gt;&lt;/a&gt; (&lt;i&gt;printf)&lt;/i&gt; with a utility method (&lt;i&gt;log) eg:&lt;br /&gt;&lt;/i&gt; &lt;i&gt;  replace&lt;/i&gt;: &lt;code&gt; &lt;a href="http://www.cplusplus.com/reference/clibrary/cstdio/printf.html"&gt;printf&lt;/a&gt;("Error = %d (%s)", error, errorMessage);&lt;/code&gt;&lt;br /&gt;&lt;i&gt;  &lt;/i&gt;  with     : &lt;code&gt;&lt;i&gt;log&lt;/i&gt;("Error = %d (%s)", error, errorMessage); &lt;/code&gt;&lt;br /&gt;The signature of the log method is: &lt;code&gt;log(const char * message, ...) &lt;/code&gt; that should print the log message  to a file with: &lt;code&gt;&lt;a href="http://www.cplusplus.com/reference/clibrary/cstdio/fprintf.html"&gt;fprintf&lt;/a&gt; (file, messageString).&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;The big problem&lt;/strong&gt; turned out to be     - how to pass all the arguments from &lt;strong&gt;log&lt;/strong&gt; to &lt;strong&gt;fprintf&lt;/strong&gt;  - both methods with variable argument list ...&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Some ideas:&lt;/strong&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;All the &lt;a href="http://gethelp.devx.com/techtips/cpp_pro/10min/2001/feb/10min0201-3.asp"&gt;tutorials&lt;/a&gt; learn you how to &lt;strong&gt;iterate&lt;/strong&gt; those variable arguments and manipulate them separately - time consuming&lt;/li&gt;&lt;li&gt;Overloade operator &lt;strong&gt;&lt;&lt;&lt;/strong&gt; - a lot of refactoring required.&lt;/li&gt;&lt;li&gt;A cool idea was to redirect the System.out from Java to a file with &lt;code&gt;&lt;strong&gt;System.setOut&lt;/strong&gt;(printStream)&lt;/code&gt; - stdout is not the same as System.out&lt;/li&gt;&lt;/ol&gt;A possible sollution is to redirect the stdout from the C++ code to a file and skip the whole Logger component - the &lt;strong&gt;printf&lt;/strong&gt; will append to the log file:&lt;br /&gt;std::&lt;a href="http://www.cplusplus.com/reference/clibrary/cstdio/freopen.html"&gt;freopen&lt;/a&gt;(LOG_FILE, "a", stdout);&lt;br /&gt;The big side effect is that the Java System.out stream is also redirected and writes to the file.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;And the winner is&lt;/strong&gt;:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;#include "stdio.h"&lt;br /&gt;#include "stdarg.h"&lt;br /&gt;log(const char * message, ...) {&lt;br /&gt;char buffer[512]&lt;br /&gt;va_list args;&lt;br /&gt;va_start(args, message);&lt;br /&gt;// Returns the size of the created message&lt;br /&gt;&lt;a href="http://www.opengroup.org/onlinepubs/000095399/functions/vprintf.html"&gt;&lt;strong&gt;vsnprintf&lt;/strong&gt;&lt;/a&gt;(buffer, sizeof(buffer), message, args);&lt;br /&gt;&lt;strong&gt;    &lt;/strong&gt;fprintf (file, buffer);&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;strong&gt;vsnprintf&lt;/strong&gt; formats the message with the argument list and writes it to the &lt;strong&gt;buffer &lt;/strong&gt; that is easily logged.&lt;br /&gt;&lt;br /&gt;Clean sollution but far from my Java-stuffed brain.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;A solution for exception handling in JNI is in: &lt;a href="http://learn-from-the-guru.blogspot.com/2008/01/functions-with-variable-argument-list.html"&gt;Functions with a Variable Argument List II&lt;/a&gt;&lt;br /&gt;You can also take a look at &lt;a href="http://learn-from-the-guru.blogspot.com/2007/12/java-native-interface-jni-tutorial-hell.html"&gt;this post&lt;/a&gt; for more tips&amp;amp;trick for JNI.&lt;br /&gt;&lt;/code&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/29039672-164167297901942521?l=learn-from-the-guru.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/LearnIt/~4/nvzRQtPwqOg" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://learn-from-the-guru.blogspot.com/feeds/164167297901942521/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=29039672&amp;postID=164167297901942521" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/29039672/posts/default/164167297901942521?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/29039672/posts/default/164167297901942521?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/LearnIt/~3/nvzRQtPwqOg/functions-with-variable-argument-list.html" title="Functions with a Variable Argument List" /><author><name>Emo</name><uri>http://www.blogger.com/profile/16976929775234907073</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>1</thr:total><feedburner:origLink>http://learn-from-the-guru.blogspot.com/2007/10/functions-with-variable-argument-list.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEAARHY8eyp7ImA9WxZTFEs.&quot;"><id>tag:blogger.com,1999:blog-29039672.post-254508795714030298</id><published>2007-12-13T06:19:00.000-08:00</published><updated>2008-01-15T22:59:05.873-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-01-15T22:59:05.873-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Java" /><category scheme="http://www.blogger.com/atom/ns#" term="C/C++" /><category scheme="http://www.blogger.com/atom/ns#" term="JNI" /><title>Java Native Interface (JNI) Tutorial - Hell on Stage</title><content type="html">&lt;p align="center"&gt;&lt;strong&gt;Intro&lt;/strong&gt;&lt;/p&gt;&lt;p align="left"&gt;There are &lt;a href="http://java.sun.com/docs/books/jni/html/jniTOC.html"&gt;so&lt;/a&gt; &lt;a href="http://www.javaworld.com/javaworld/jw-10-1999/jw-10-jni.html"&gt;many&lt;/a&gt; &lt;a href="http://www.acm.org/crossroads/xrds4-2/jni.html"&gt;tutorials&lt;/a&gt; about using JNI to access C/C++ code from Java so I don't want to write the next ... but to share some tips &amp;amp; tricks with a very short overview.&lt;/p&gt;&lt;p align="center"&gt;&lt;strong&gt;Java and C together! Why?&lt;/strong&gt;&lt;/p&gt;&lt;ol&gt;&lt;li&gt;Implement time-critical code &lt;/li&gt;&lt;li&gt;Access legacy code or code libraries from Java programs &lt;/li&gt;&lt;li&gt;Need of platform-dependent features not supported in Java (not covered) &lt;/li&gt;&lt;/ol&gt;&lt;div style="text-align: center;"&gt;&lt;strong&gt;Calling C/C++ code from Java programs&lt;/strong&gt;&lt;/div&gt;&lt;p align="left"&gt;Six steps to do this with  Java Native Interface:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;Write Java code&lt;br /&gt;&lt;code&gt;public class Sample{&lt;br /&gt;public native String stringMethod(String text);&lt;br /&gt;public static void main(String[] args) {&lt;br /&gt;System.loadLibrary("sample");&lt;br /&gt;Sample sample = new Sample();&lt;br /&gt;String text = sample.stringMethod("java");&lt;br /&gt;System.out.println("stringMethod: " + text)&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/li&gt;&lt;li&gt;Compile the Java code&lt;br /&gt;&lt;code&gt;javac Sample.java&lt;/code&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Generate C/C++ header file&lt;br /&gt;Generate Sample.h from the java class file: &lt;code&gt;$javah -jni Sample&lt;/code&gt;. The result uses a pointer to a table of function pointers (JNIEnv parameter) and a parameter refers to the current invoking Java object or this pointer (jobject) :&lt;br /&gt;&lt;code&gt;#include&lt;br /&gt;extern "C" {&lt;br /&gt;JNIEXPORT jstring JNICALL Java_Sample_stringMethod&lt;br /&gt;(JNIEnv *, jobject, jstring);&lt;br /&gt;}&lt;/code&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Write C/C++ code&lt;br /&gt;Implement the methods from the generated header files:&lt;br /&gt;&lt;code&gt;JNIEXPORT jstring JNICALL Java_Sample_stringMethod(JNIEnv *env, jobject obj, jstring string) {&lt;br /&gt;const char *str = env-&gt;GetStringUTFChars(string, 0);&lt;br /&gt;char cap[128];&lt;br /&gt;strcpy(cap, str);&lt;br /&gt;env-&gt;ReleaseStringUTFChars(string, str);&lt;br /&gt;return env-&gt;NewStringUTF(strupr(cap));&lt;br /&gt;}&lt;/code&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Create shared library file&lt;br /&gt;The naming convension for the output shared library is different depending on the OS and must be followed: sample.dll (Windows) or libsample.so (*NIX).&lt;br /&gt;&lt;code&gt;$g++ -I /usr/lib/jvm/java-1.5.0-sun/include sample.cpp -L ~/resources/verimatrix -shared -o libsample.so -lcrypto&lt;/code&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Run the Java application&lt;br /&gt;&lt;code&gt;java Sample&lt;/code&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p align="center"&gt;&lt;strong&gt;Access shared libraries&lt;/strong&gt;&lt;/p&gt;&lt;strong&gt;Prerequisites&lt;/strong&gt;&lt;br /&gt;Usually you have some shared libraries that provide some functionality. For example two dynamic linux shared libraries (libvpr.so and libringdll.so).&lt;br /&gt;&lt;strong&gt;Problems&lt;/strong&gt;&lt;ol&gt;&lt;li&gt;Difference between the provided method names in the libraries and the naming convension used by JNI - you cannot invoke one of the methods directly unless it is designed with JNI in mind. JNI requires some prefixes as shown above with the method name "Java_Sample_stringMethod"&lt;/li&gt;&lt;li&gt;Not all JNI data types can be mapped to C/C++ data types and vice versa:&lt;br /&gt;jint == int, jbyte == jbyte&lt;br /&gt;jbyteArray != byte *, jstring != string, jclass != class&lt;/li&gt;&lt;li align="left"&gt;Freeing Native Resources - some resources cannot be freed by the GC like strings and global references.&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;&lt;strong&gt;Access C/C++ methods provided by the libraries&lt;/strong&gt;&lt;br /&gt;The solution that handles the above problems is to implement a proxy library that follows the JNI naming convention and proxies all method calls to the functional shared library:&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Implement Java code with all required native methods:&lt;br /&gt;&lt;code&gt;private native boolean VprEncryptMovie(EncryptMovieSettings encryptionSettings);&lt;/code&gt;&lt;/li&gt;&lt;li&gt;Design C/C++ shared library that implement the interface of the methods as proxy:&lt;br /&gt;&lt;code&gt;jboolean Java_jni_VerimatrixClient_VprEncryptMovie(EncryptMovieSettings jobject);&lt;/code&gt;&lt;/li&gt;&lt;li&gt;Implement data conversion from the JNI data types to standard C/C++ data types&lt;/li&gt;&lt;li&gt;Proxy all method calls to the corresponding methods in functional libraries&lt;/li&gt;&lt;li&gt;Implement exception handling&lt;br /&gt;&lt;code&gt;jclass newExc=env-&gt;FindClass("java/lang/IllegalArgumentException");&lt;br /&gt;env-&gt;ThrowNew(newExc, "thrown from C code");&lt;/code&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p align="center"&gt;&lt;strong&gt;Tips and tricks&lt;/strong&gt;&lt;/p&gt;&lt;ol&gt;&lt;li&gt;Use Apache Harmony VM for trouble shooting or the patched version as described  &lt;a href="http://softwarecommunity.intel.com/articles/eng/1435.htm"&gt;here&lt;/a&gt; - it generates a JNI stack trace instead of just crashing the VM as JDK5 or JDM6 eg:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;SIGSEGV in VM code.&lt;br /&gt;Stack trace:&lt;br /&gt;0: memcpy (??:-1)&lt;br /&gt;1: VprRpcEncryptMovieWithKey(rpc_handle_s_t*, void*, unsigned char*, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, unsigned char*, long, long, long*, long*) (??:-1)&lt;br /&gt;2: VprEncryptMovieWithKey (??:-1)&lt;br /&gt;3: Java_com_minerva_edc_vig_verimatrix_vcas_VprClient_VprEncryptMovieWithKey (/home/emo/perforce/3ML/SB/VideoIngest/src/com/minerva/edc/vig/verimatrix/proxy/VprProxy.cpp:100)&lt;br /&gt;4: 0xA591A50B&lt;br /&gt;5: com/minerva/edc/vig/verimatrix/vcas/VprClient.createEncryptSession(Lcom/minerva/edc/vig/verimatrix/vcas/model/VprServerRegisterResponse;Lcom/minerva/edc/vig/verimatrix/vcas/model/EncryptMovieSettings;Lcom/minerva/edc/vig/verimatrix/vcas/model/MovieInfo;Lcom/minerva/edc/vig/core/data/DTO;)J (VprClient.java:73)&lt;br /&gt;...&lt;br /&gt;23: _start (/usr/src/packages/BUILD/glibc-2.3/csu/../sysdeps/i386/elf/start.S:105)&lt;/code&gt;&lt;li&gt;&lt;/li&gt;&lt;li&gt;Eclipse plugin for C/C++ development - CDT&lt;/li&gt;&lt;li&gt;Do not store local variables in the C++ classes if more that one simultaneous client to the proxy is planned - only one instance of this class from the library is loaded by the JVM.&lt;/li&gt;&lt;li&gt;You can implement a Java class to pass multiple parameters to a JNI function and extract them with reflection but remmember that every reflection call has big performance hit. Also if this input parameter is "converted" into a C/C++ structure or class, the constructed objects cannot be cached (see the previos tip). If the parametes are not so many - pass them all.&lt;br /&gt;&lt;li&gt;A Java class can be returned as out parameter by reference. It is better to create the instance in the Java and just fill the properties in the C++ proxy. This eliminates the need to call the constructor of the response object and to hardcode its package and class name in the proxy class. Only the method names are required.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;A setter method can be invoked in such a way:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;// Create the encryption settings class&lt;br /&gt;jclass vprResponseClass = env-&gt;GetObjectClass(vprResponseObj);&lt;br /&gt;// Allocates memory for an array of one long long output parameter&lt;br /&gt;jvalue* args = (jvalue*)malloc(sizeof(jlong)); way:&lt;br /&gt;// Create the encryption settings class&lt;br /&gt;jclass vprResponseClass = env-&gt;GetObjectClass(vprResponseObj);&lt;br /&gt;// Allocates memory for an array of one long long output parameter&lt;br /&gt;jvalue* args = (jvalue*)malloc(sizeof(jlong));&lt;br /&gt;&lt;br /&gt;args[0].j=input_file_size;&lt;br /&gt;jmethodID setInputFileSizeID =env-&gt;GetMethodID(vprResponseClass,"setInputFileSize", "(J)V");&lt;br /&gt;env-&gt;CallLongMethodA(vprResponseObj, setInputFileSizeID, args);&lt;br /&gt; // Cleanup&lt;br /&gt; free((jvalue*) args);&lt;br /&gt;&lt;/code&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;A thrown exception in a C++ method do not stops its execution so all allocated resources in the method can be freed first before the return clause.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Passing Invalid Arguments to JNI Functions - most often JVM crashes. Use JVM option -Xcheck:jni to detect errors like passing passing NULL or (jobject)0xFFFFFFFF in place of reference. This option degrates the performance.&lt;/li&gt;&lt;/ol&gt;&lt;p align="center"&gt;&lt;strong&gt;Troubleshooting&lt;/strong&gt;&lt;/p&gt;&lt;lo&gt;&lt;li&gt;&lt;code&gt;java.lang.UnsatisfiedLinkError: no sample in java.library.path&lt;/code&gt;&lt;br /&gt;The library name in Java (System.loadLibrary)is wrong - chech the prefix or extension&lt;br /&gt;Could not find the library - set the directory locations as a JVM parameter: &lt;code&gt;-Djava.library.path=/home/lib:/opt/lib/ &lt;/code&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;code&gt;java.lang.UnsatisfiedLinkError: /libverimatrixproxy.so: libvpr.so: cannot open shared object file: No such file or directory&lt;/code&gt;&lt;br /&gt;A library dependency cannot be found. Add the location of the missing library e.g. ~/lib/ in "/etc/ld.so.conf". Then reconfigure linker bindings &lt;code&gt;$ldconfig&lt;/code&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;code&gt;java.lang.UnsatisfiedLinkError: /libverimatrix.so: /libverimatrix.so: undefined symbol: VprDestroyContext&lt;/code&gt;&lt;br /&gt;Check the shared library for all undefined symbols in the list of its dependences&lt;br /&gt;&lt;code&gt;$ldd -d ~/lib/libverimatrix.so&lt;/code&gt;&lt;br /&gt;Place the missing library that provides those methods, structres, enumerations or ... in the libraries dependency search path.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;code&gt;java.lang.UnsatisfiedLinkError: /libverimatrix.so: Can't load IA 32-bit .so on a IA 32-bit platform&lt;/code&gt;&lt;br /&gt;Bug in JDK5 - wrong error message. Use another VM (JDK6, Harmony) to get the correct stack trace.&lt;li&gt;&lt;br /&gt;&lt;li&gt;&lt;code&gt;[Too many errors, abort]&lt;/code&gt;&lt;br /&gt;Infinite error message dump:&lt;br /&gt;&lt;code&gt;Many times: [error occurred during error reporting, step 270, id 0xb]&lt;/code&gt;&lt;br /&gt;Then infinite: &lt;code&gt;[Too many errors, abort]&lt;/code&gt;&lt;br /&gt;This occurs when the JDK detects an error in called C++ code but does not crash imediate. See the first tip about the Apache Harmony JVM.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;code&gt;error: redefinition of ‘struct EncryptMovieSettings’&lt;/code&gt;&lt;br /&gt;This type of C++ compile error may happpen if a header file is called or included more than once. Try to precede and end it like that to avoid that:&lt;br /&gt;&lt;code&gt;#ifndef __yourheader_h&lt;br /&gt;#define __yourheader_h (1)&lt;br /&gt;// Put here the body of your ".h" file including the class&lt;br /&gt;#endif&lt;/code&gt;&lt;br /&gt;&lt;p align="center"&gt;&lt;strong&gt;Debug JNI&lt;/strong&gt;&lt;/p&gt;&lt;strong&gt;&lt;a href="http://softwarecommunity.intel.com/articles/eng/1435.htm"&gt;Integrated Debugger for JNI Environments&lt;/a&gt;&lt;/strong&gt;&lt;br /&gt;Eclipse version 3.2 (not a newer) can be used to debug both the Java and C++ code of JNI. Apache Harmony JVM provides interface for agent which could manage and handle events in debug session.&lt;br /&gt;&lt;a href="http://www.kineteksystems.com/white-papers/mixedjavaandc.html"&gt;&lt;strong&gt;Synchronized Sollution&lt;/strong&gt;&lt;/a&gt;&lt;br /&gt;Solution with two debuggers that attach to a running Java or C++ process and cooperate -  a Java debugger eg. Eclipse and a C/C++ debugger eg. Insight - GUI frondend to GDB&lt;br /&gt;&lt;p align="center"&gt;&lt;strong&gt;References&lt;/strong&gt;&lt;/p&gt;Java Native Interface 1999.pdf&lt;br /&gt;Java programming with JNI.pdf&lt;br /&gt;&lt;/li&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/29039672-254508795714030298?l=learn-from-the-guru.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/LearnIt/~4/B91EGPOkyMg" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://learn-from-the-guru.blogspot.com/feeds/254508795714030298/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=29039672&amp;postID=254508795714030298" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/29039672/posts/default/254508795714030298?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/29039672/posts/default/254508795714030298?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/LearnIt/~3/B91EGPOkyMg/java-native-interface-jni-tutorial-hell.html" title="Java Native Interface (JNI) Tutorial - Hell on Stage" /><author><name>Emo</name><uri>http://www.blogger.com/profile/16976929775234907073</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>2</thr:total><feedburner:origLink>http://learn-from-the-guru.blogspot.com/2007/12/java-native-interface-jni-tutorial-hell.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0EEQX86eCp7ImA9WB9QE00.&quot;"><id>tag:blogger.com,1999:blog-29039672.post-2657319081561967516</id><published>2007-10-25T01:57:00.000-07:00</published><updated>2007-10-25T02:46:40.110-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2007-10-25T02:46:40.110-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="News" /><category scheme="http://www.blogger.com/atom/ns#" term="Other" /><title>GMAIL over IMAP! The battle is over!</title><content type="html">&lt;div align="left"&gt;     Finally GMAIL will have &lt;a href="http://www.downloadsquad.com/2007/10/23/gmail-gets-imap/"&gt;IMAP support&lt;/a&gt;! &lt;br /&gt;I'm so tired of this battle with the POP3 access. And the best is that all win :)&lt;br /&gt;&lt;br /&gt;     I started using GMAIL some years ago but lately the need to check all my three accounts through the web interface with the enormous loading time almost made me give up these mails.&lt;br /&gt;I tried the &lt;a href="http://www.mikeindustries.com/blog/archive/2006/04/how-to-use-gmail-over-imap"&gt;POP forwarding&lt;/a&gt; to another mail account with IMAP support but could not find such proper mail service. &lt;br /&gt;&lt;div align="justify"&gt;&lt;div align="right"&gt;&lt;div align="justify"&gt;&lt;div align="right"&gt;&lt;div align="left"&gt;     The winner was &lt;a href="http://www.aol.com/"&gt;AOL mail&lt;/a&gt;  with unlimited space but after some doubt I found that the mails are kept for 28 days only before &lt;a href="http://members.aol.com/adamkb/aol/mailfaq/imap/"&gt;complete deletion&lt;/a&gt;. At second place was &lt;a href="http://www.bluebottle.com/"&gt;www.bluebottle.com&lt;/a&gt; with 250MB space but I couldn't register receiving some  error with wrong message:&lt;i&gt;There have been too many signups from your IP address in the last 24 hours. &lt;/i&gt;All other mail servers offered for free only no more than 20-30MB of space ~= 5-6 mails with attachments and I returned to the old painful POP3 access.&lt;i&gt;&lt;br /&gt;&lt;br /&gt;&lt;/i&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/29039672-2657319081561967516?l=learn-from-the-guru.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/LearnIt/~4/e0j1rWLjilE" height="1" width="1"/&gt;</content><link rel="related" href="http://www.downloadsquad.com/2007/10/23/gmail-gets-imap/" title="GMAIL over IMAP! The battle is over!" /><link rel="replies" type="application/atom+xml" href="http://learn-from-the-guru.blogspot.com/feeds/2657319081561967516/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=29039672&amp;postID=2657319081561967516" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/29039672/posts/default/2657319081561967516?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/29039672/posts/default/2657319081561967516?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/LearnIt/~3/e0j1rWLjilE/gmail-over-imap-battle-is-over.html" title="GMAIL over IMAP! The battle is over!" /><author><name>Emo</name><uri>http://www.blogger.com/profile/16976929775234907073</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://learn-from-the-guru.blogspot.com/2007/10/gmail-over-imap-battle-is-over.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEIERnszeCp7ImA9WB9QEUk.&quot;"><id>tag:blogger.com,1999:blog-29039672.post-1505884161685585574</id><published>2007-10-09T06:38:00.000-07:00</published><updated>2007-10-23T06:35:07.580-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2007-10-23T06:35:07.580-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Java" /><category scheme="http://www.blogger.com/atom/ns#" term="Linux" /><title>Tools for every day from JDK 6</title><content type="html">&lt;strong&gt;JDK 6&lt;/strong&gt; introduced some usefull tools:&lt;br /&gt;&lt;br /&gt;1. &lt;strong&gt;JPS&lt;/strong&gt; - (Also incuded in JDK 5) lists all running JVMs (also those loaded from JNI !!!) with information for them as passed arguments and the  name of the application's main class with its arguments:&lt;br /&gt;&lt;strong&gt;$jps -mlvV&lt;/strong&gt;&lt;br /&gt;3370 sun.tools.jps.Jps -mlvV -Dapplication.home=/usr/lib/jvm/java-6-sun-1.6.0.00 -Xms8m&lt;br /&gt;&lt;strong&gt;30707&lt;/strong&gt;  -Xms512m -Xmx512m -XX:PermSize=128m -XX:MaxPermSize=128m&lt;br /&gt;3327 tcpmon.MainWindow&lt;br /&gt;&lt;br /&gt;2. &lt;strong&gt;JINFO&lt;/strong&gt; - prints Java configuration information for a given Java process. The most usefull info as &lt;i&gt;sun.boot.library.path&lt;/i&gt;, &lt;i&gt;java.library.path&lt;/i&gt; and &lt;i&gt;java.class.path&lt;/i&gt; can be filtered:&lt;br /&gt;&lt;strong&gt;$jinfo 30707| grep -E "(java.class.path|library.path)"&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;Those tools can be combined to expract the most usefull information for all JDK6 in a BASH script ( jpall.sh)  skipping the JPS process itself :&lt;br /&gt;#!/bin/bash&lt;br /&gt;for i in $( jps | grep -v Jps | awk -F " " '{print $1}' ) ; &lt;br /&gt;do&lt;br /&gt;        echo&lt;br /&gt;        jinfo $i | grep -E "(java.class.path|library.path)"&lt;br /&gt;        jps -mlvV | grep $i&lt;br /&gt;done&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/29039672-1505884161685585574?l=learn-from-the-guru.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/LearnIt/~4/97hc_kmv_WE" height="1" width="1"/&gt;</content><link rel="related" href="http://www.ibm.com/developerworks/java/library/j-java6perfmon/?ca=dgr-lnxw07jvse6rls&amp;S_TACT=105AGX59&amp;S_CMP=GR" title="Tools for every day from JDK 6" /><link rel="replies" type="application/atom+xml" href="http://learn-from-the-guru.blogspot.com/feeds/1505884161685585574/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=29039672&amp;postID=1505884161685585574" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/29039672/posts/default/1505884161685585574?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/29039672/posts/default/1505884161685585574?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/LearnIt/~3/97hc_kmv_WE/tools-for-every-day-from-jdk-6.html" title="Tools for every day from JDK 6" /><author><name>Emo</name><uri>http://www.blogger.com/profile/16976929775234907073</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://learn-from-the-guru.blogspot.com/2007/10/tools-for-every-day-from-jdk-6.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEENQHY-fip7ImA9WB9REE0.&quot;"><id>tag:blogger.com,1999:blog-29039672.post-115253149607975407</id><published>2006-07-10T04:38:00.000-07:00</published><updated>2007-10-10T01:58:11.856-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2007-10-10T01:58:11.856-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Java" /><title>The Five Rules of Compilation</title><content type="html">The complete rules for a compilator based on &lt;a href="http://www.onjava.com/pub/a/onjava/2006/06/28/whats-new-in-eclipse-3-2-java-development-tools.html"&gt;these&lt;/a&gt;    three rules:&lt;br /&gt;&lt;br /&gt;0. Security: A compiler may not harm any resource or running application.&lt;br /&gt;1. Correctness: A compiler may not harm a source program.&lt;br /&gt;2. Efficiency: A compiler must be fast, except where speed would conflict with the first law.&lt;br /&gt;3. Friendliness: A compiler must assist the user to correct programming errors, as long as such assistance does not conflict with the first and second laws.&lt;br /&gt;4. Informative: A compiler must establish its identiy as   the accurate compiler in all cases.&lt;br /&gt;5. Specificness: A compiler must know it is a compiler&lt;br /&gt;&lt;br /&gt;Asimov's &lt;a href="http://en.wikipedia.org/wiki/Three_Laws_of_Robotics"&gt;rules of robotics.&lt;/a&gt;&lt;br /&gt;&lt;a href="http://en.wikipedia.org/wiki/Three_Laws_of_Robotics"&gt; &lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/29039672-115253149607975407?l=learn-from-the-guru.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/LearnIt/~4/GW-PuIry9qQ" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://learn-from-the-guru.blogspot.com/feeds/115253149607975407/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=29039672&amp;postID=115253149607975407" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/29039672/posts/default/115253149607975407?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/29039672/posts/default/115253149607975407?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/LearnIt/~3/GW-PuIry9qQ/three-rules-of-compilation-by-asimov.html" title="The Five Rules of Compilation" /><author><name>Emo</name><uri>http://www.blogger.com/profile/16976929775234907073</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://learn-from-the-guru.blogspot.com/2006/07/three-rules-of-compilation-by-asimov.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkAMQH89cCp7ImA9WB9REE0.&quot;"><id>tag:blogger.com,1999:blog-29039672.post-114907452004542614</id><published>2006-05-31T04:22:00.000-07:00</published><updated>2007-10-10T01:26:21.168-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2007-10-10T01:26:21.168-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Java" /><title>Java interfaces convention</title><content type="html">&lt;span style="font-style: italic;"&gt;IPortletDefinition or PortletDefinition&lt;/span&gt;.&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Reasons to drop the I's&lt;/span&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;JavaDoc and IDEs like Eclipse differentiate interfaces from classes sufficiently. The Java typing does not also need to be reflected in the type name because our IDEs already give us sufficient visual clues.&lt;/li&gt;&lt;li&gt;Follow the Sun conventions with the goal of minimizing the "impedance mismatch" between our code-base and the JDK, i.e., our APIs should look like they could be in the JDK. This strategy is helpful pedagogically.&lt;/li&gt;&lt;li&gt;Keeping with the norm of other open source and java projects.&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-weight: bold;"&gt;Reasons to keep the I's&lt;br /&gt;&lt;/span&gt;&lt;ul&gt;&lt;li&gt;For the sake of consistency between different versions&lt;/li&gt;&lt;li&gt;To make it easier to tell which files represent java interfaces when viewing files in a list outside of JavaDoc or an IDE like Eclipse, or in Eclipse views which do not illustrate the difference with icons.&lt;/li&gt;&lt;li&gt;To make it easier to identify java interfaces when looking at java code itself.&lt;/li&gt;&lt;li&gt;Having the extra I doesn't present a real burden.&lt;/li&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/29039672-114907452004542614?l=learn-from-the-guru.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/LearnIt/~4/k3Cn97va_6A" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://learn-from-the-guru.blogspot.com/feeds/114907452004542614/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=29039672&amp;postID=114907452004542614" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/29039672/posts/default/114907452004542614?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/29039672/posts/default/114907452004542614?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/LearnIt/~3/k3Cn97va_6A/java-interfaces-convention.html" title="Java interfaces convention" /><author><name>Emo</name><uri>http://www.blogger.com/profile/16976929775234907073</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>1</thr:total><feedburner:origLink>http://learn-from-the-guru.blogspot.com/2006/05/java-interfaces-convention.html</feedburner:origLink></entry><entry gd:etag="W/&quot;Dk4CR3s6fCp7ImA9WB9REE0.&quot;"><id>tag:blogger.com,1999:blog-29039672.post-114907381960882213</id><published>2006-05-31T04:10:00.000-07:00</published><updated>2007-10-10T01:29:26.514-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2007-10-10T01:29:26.514-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Other" /><title>The ideot's mission</title><content type="html">Knowledge is power - learn it and become a powerman.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/29039672-114907381960882213?l=learn-from-the-guru.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/LearnIt/~4/bwPfL_i2gL0" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://learn-from-the-guru.blogspot.com/feeds/114907381960882213/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=29039672&amp;postID=114907381960882213" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/29039672/posts/default/114907381960882213?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/29039672/posts/default/114907381960882213?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/LearnIt/~3/bwPfL_i2gL0/ideots-mission.html" title="The ideot's mission" /><author><name>Emo</name><uri>http://www.blogger.com/profile/16976929775234907073</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://learn-from-the-guru.blogspot.com/2006/05/ideots-mission.html</feedburner:origLink></entry></feed>

