Wednesday, July 08, 2009

Avoiding JNI pitfalls

There is a great new article on developerWorks entitled "Best practices for using the Java Native Interface".

Here is the summary:
The Java™ Native Interface (JNI) is a standard Java API that enables Java code to integrate with code written in other programming languages. JNI can be a key element in your toolkit if you want to leverage existing code assets — for example, in a service-oriented architecture (SOA) or a cloud-based system. But when used without due care, JNI can quickly lead to poorly performing and unstable applications. This article identifies the top 10 JNI programming pitfalls, provides best practices for avoiding them, and introduces the tools available for implementing these practices.


I think my "favorite" pitfall is using the wrong JNIEnv. I've seen many a crash due to this error. Usually, this occurs because someone thought it was a good idea to cache the JNIEnv once and use the cached version. Problem is that the JNIEnv is thread specific and the cached one can end up being used from a thread other than the one the JNIEnv belongs to.

Caching of the JNIEnv is typically attempted when integrating legacy code into a Java application where you would need to change many function signatures to accommodate passing the JNIEnv down to the right function. Instead of caching the JNIEnv, cache the JavaVM; it is not thread specific and can be used to obtain the appropriate JNIEnv using the GetEnv() call.

Friday, June 12, 2009

Troubleshooting Resources

I've gathered below some useful resources when trying to diagnose a Java problem when running IBM Java SDKs.

Troubleshooting InfoCenter
Guided debugging for Java


IBM Guided Activity Assistant
IBM® Guided Activity Assistant is a tool that guides you step-by-step through troubleshooting and configuration tasks. It helps you identify symptoms, collect diagnostic data, analyze the collected data, determine a root cause, and apply a solution to resolve the symptoms. If you cannot resolve the problem, IBM Guided Activity Assistant helps you export the troubleshooting case and send it to IBM so they can investigate the problem.


IBM Monitoring and Diagnostic Tools for Java
IBM provides tooling and documentation to assist in the understanding, monitoring, and problem diagnosis of applications and deployments running IBM Runtime Environments for Java.


Diagnosis documentation
This diagnosis information covers IBM-specific features of IBM's offerings. New or revised material is clearly shown by revision bars to the left of the changes and by red text in online versions.


developerWorks Forum: IBM Java Runtimes and SDKs
The IBM Java Technology Centre (JTC) produces development kits for IBM's most popular platforms. Technical Lead for IBM's Java on Unix Support Chris Bailey and other members of the IBM JTC team invite you to this discussion forum to share knowledge and ask questions about your experiences of using the various IBM runtimes and kits.

Monday, June 08, 2009

Hudson Plugin for Eclipse Project Set Files

We track some of our source code configurations using Eclipse Project Set Files (PSFs). We also use Hudson for portions of our build infrastructure. Making them work together, so far, has required relying on some ant tasks that we have built to handle PSFs.

Not having PSFs fully integrated into Hudson has limited our ability to use some of the nicer features that Hudson has to offer (e.g., Poll SCM, with a PSF as a Source Code Management entry).

I've searched around the web and have been unable to find a Hudson plugin for PSFs.

So I intend to build one myself. I'll post some progress updates here to let you know how I am doing.

Thursday, June 04, 2009

IBM Real Time Application Execution Optimizer for Java

There is a new tool available on alphaWorks: IBM Real Time Application Execution Optimizer for Java

This tool will take a "compiled Java application" (AKA a set of jar files) and will optimize it in various ways.

From alphaWorks:
The tool provides the following functions:


  • Escape analysis of objects per method invocation
  • Control flow analysis that splits an application into archives according to thread accessibility
  • Control flow analysis that detects potential occurrences of real-time java runtime errors MemoryAccessError, IllegalAssignmentError, IllegalThreadStateException
  • Control flow analysis that determines entry points into an application
  • Addition of stackmaps to Java class files
  • Verification of Java class files
  • Auto-generation of classes that will load and initialize all other classes within the same archive
  • Specialized packaging of Java applications into deployable archives by packaging all referenced
  • Classes from a dual class path
  • Removal of unwanted attributes from Java class files



It also does some very nice things when optimizing for Real-time Java (JSR 1).

From alphaWorks:
The tool separates application classes into the following categories:

  • NoHeapRealtimeThread (NHRT) accessible
  • RealtimeThread accessible
  • regular thread accessible
  • inaccessible: classes not accessible to any thread.

Friday, May 29, 2009

Health Center (Tech Preview) Version 0.5

IBM Monitoring and Diagnostic Tools for Java - Health Center v0.5 has recently been released.

I've had a hand helping get this product ready and feel proud to see it now available for use in the wild. Please download it, try it out, and give us your feedback.

Monday, April 27, 2009

IBM "Watson" takes on Jeopardy

Another thing that makes working at IBM cool.

Friday, October 10, 2008

STDT Guinea Pig

Being a member of the J9 Virtual Machine team I have had the opportunity to use Smalltalk in my day to day job. Now, I get to be a guinea pig for a new Smalltalk IDE called STDT (Smalltalk Development Tools).

My first impressions are quite positive. This is a real upgrade in terms of being able to integrate Smalltalk changesets and C changesets together. In the past if you submitted code that needed to ported to another stream or, heaven forbid, backed out due to build or test issues, backing out the Smalltalk portion using ENVY was onerous. Now with the Smalltalk source being mastered in CVS (or any of your other favorite SCMs) it is a piece of cake to pick up a changeset and manipulate it.