Fixing Random Crashes in JNI Code

June 2nd, 2009 at 4:38 pm

Do you have an application that uses JNI to provide a C/C++ interface to a Java library? Are you experiencing random crashes and segmentation faults in seemingly unrelated parts of said application? Have you pulled out all your hair while trying to figure out what the problem is?

The good news is that I may have a solution for you!

I was recently testing Portico with a large, widely deployed C++ application. The Portico C++ interface uses JNI to wrap the core Java library. Other applications then link against this interface and use the library to do whatever it is they need to do.

When testing this large application I noticed a lot of crashes in code that was totally unrelated to Portico. For the life of me I couldn’t figure out what the problem was. This was made even more frustrating by the lack of any help from Google. Eventually however, I stumbled across this post, which discusses something that sounded quite familiar.

My current understanding is that the JNI uses various signals to complete its work, and that if you have an application that puts its own signal handlers in place, they will replace the JNI handlers thus causing problems. You can try starting the JVM with -Xrs to make it reduce signal use, but this doesn’t entirely eliminate it, potentially leaving you with the problem.

Fortunately, Sun ship a signal handler chaining library with the JVM. When I linked against that (no code change required!) everything started to work happily! The libjsig.so library is in the same directory as libjvm.so which you need to link against anyway, so the grand solution is to just as a -ljsig to your compile/linking command. Talk about a simple solution to an incredibly frustrating problem. For full details see the article above.

I’ve decided to post this little discovery here in the hope that Google finds it and saves someone else a whole bunch of pain. Never say I don’t do anything for you Internet.

Useful resources:
If JNI based application is crashing, check signal handling!
Revelations on Java signal handling and termination

Portico v1.0

May 27th, 2009 at 1:21 pm

The first public release of Portico (then jaRTI) was in May of 2006. It was v0.2 and a simple, Java-only affair at the time, providing only basic federation management support. It has since grown to provide support for almost all of the HLA 1.3 specification and parts of the IEEE 1516 specification, in both Java and C++, running on Mac OS X, Linux and Microsoft Windows. Bugs have been fixed, performance dramatically improved, features added and removed. It’s been a long journey.

I have just made available the official Portico v1.0 downloads.

To be honest, I wasn’t quite sure it would ever get this far. There was a point where the project looked like stalling a couple of years ago, but with the involvement of the Australian Defence Simulation Office and my employment through Calytrix, a new lease of life was given and Portico now continues to grow strongly.

The project has been downloaded from Sourceforge almost 5,000 times (quite a lot for something like an RTI) and the monthly averages continue to grow. There are over 70 people on the announcement mailing list. There are almost 100 accounts on the forums, and they have been significantly more active of late. Growth is an addictive drug.

Considerable amounts of praise and thanks should go to all those people who have been testing Portico in the lead up to the v1.0 release and have reported the bugs back. Thanks should also go to everyone who has contributed code to Portico over the years, especially it’s other founder, Michael Fraser.

For the future, there are plans afoot for commercial support, certification, a proper 1516 interface and better support tools.

For now, I need a holiday.

Flashing

April 26th, 2009 at 11:54 pm

Last week, in a stunning act of selflessness and patriotism, I stepped out into the mean streets of Perth and did my bit to pull this country out of recession. The result of this little foray into the barren and empty wastelands of consumerism were a shiny new Canon 17-40L f/4 lens and a Canon 430EX II flash (along with some other associated kit like a new polarizer for the lens and a diffuser for the strobe).

In all honesty, I intended none of these purchases and it all started when I innocently wandered into a local merchant on my way back from buying a baguette. I blame the French.

I’ve been wanting to play with some off-camera lighting for a while. It seems like the C++ of the photography world: difficult to master, harsh and unforgiving, but if done right, pure poetry. I felt like I was somehow less of a man for avoiding it this long, like I was sitting at the kiddy table. Having suffered enough emasculation, I did what all governments do in a time of crisis: plonked down the plastic and spent money I don’t have on something I wasn’t sure I’d ever use.

To really play with off camera flash, you need something to wirelessly trigger the strobe when the shutter opens. I’ve ordered the crappiest, cheapest solution I can find, but it’s going to be at least another week before I have it in my hands. In addition to being susceptible to questions of my manly qualities, I’m also impatient. Tonight I decided enough was enough and began experimenting. Once I was done I decided to take some photos as well.

Without a wireless trigger, the only way I can pop the flash is manually. There is a little button on the back that glows an irresistible red when the flash is on. The label reads “pilot”. Having no idea what this mean, I was drawn to the shiny light and I pressed the button almost as soon as I saw it.

*POP*

When my vision returned I did it again, just incase the flash thought I didn’t mean to blind myself for 2 minutes when I pressed its button the first time. We have come to an understanding with one another now and there is nothing more than needs to be said about that.

Anyway, without the wireless trigger I obviously needed to be holding the flash to fire it. As such I was pretty much restricted to head shots for my first experiments. I really don’t like being on the pointy side of the camera, but when I checked my front door I noticed a distinct lack of models lining up to pose for me. I showered in case it was the smell. It wasn’t.

All joking aside, I’m actually quite happy with how the photos came out. I think they’re not bad for a first time effort and the fact that I don’t hate them, even though they have my mug, must mean something. I’m sure Freud has some thoughts, but he’s dead so that shows how much he knows.

Flash Experiments #3

For those interested, I had to do a couple of things to achieve the look I was after. First, I stopped the aperture right down to restrict the amount of light that got into the camera. I did this in an effort to black out the background as much as possible. I also positioned the camera and myself as far away from anything structural as is possible in my tiny apartment.

Secondly, I set the shutter speed to 2.5 seconds. This gave me long enough to steady myself and then pop the flash before the shutter closed. Because the apartment was virtually pitch black, the fact that the shutter was open so long makes no difference, the only light getting through will have come from the strobe.

I didn’t do all that much to the photos in post (see my comment about being impatient). To eliminate the last remnants of my kitchen in the background I increased the contrast. For the black and white ones I also dropped the saturation down to 0 and increased the black point a little. All this was done in Aperture, so it wasn’t particularly heavy work.

Flash Experiments #2

Having restored my place among the order to men, I’m wondering what I should tackle next. These photos are a good first step, but I’m soliciting suggestions about where to go from here.

Douche++

April 13th, 2009 at 3:28 pm

I’ve been writing a little bit of C++ recently, and as part of this I came to a point where I needed some code that would allow me to measure the time taken to perform some task. As a Java programmer, I was really just looking for some simple analogue to System.currentTimeMillis(). The problem is that there doesn’t seem to be a way to do this in simple, cross-platform C++ if you want a timer resolution any finer than something measured in seconds.

Anyway, this is a pretty common question is seems and while looking around for an answer I stumbled across many forums where someone had posed something similar. What really struck me during my search is the sheer volume of these posts that include follow-up replies that are derogatory or demeaning to the question asker in general. This is something I’ve noticed before, but only it seems when it comes to questions about C++. I’ve rarely seen it when searching for questions relating to Java, Python, Objective-C, etc…

To give you a couple of examples, see here and here.

I guess the main point of this post is to ask a question. Is there some custom of being a douche bag among C++ programmer’s that I don’t know about?

Photo-a-Week - Week … Lost Count

March 25th, 2009 at 11:58 am

I’ve totally lost track of the week, so I’m officially calling and end to the photo-a-week experiment attempt. I’d like to keep going with it, but it has stopped being enjoyable and started to be more of a chore. I still plan to make dedicated trips out with the camera, but I’m not going to force it just because I haven’t done something this week. Let’s see what happens.

I have also just uploaded some photos I took on the weekend after fetching some yummy, more gourmet produce. There were a couple of things I really wanted to try (like the Jamón Ibérico) but had previously avoided because of the expense. Not this time.

Lazy Lunch

Marinated Fetta


price of viagra synthroid without prescription viagra overnight cheap cialis without prescription viagra in us order viagra in us purchase viagra cheap viagra online buy clomid without prescription tablet cialis lasix pharmacy cheap generic lasix order cialis cheap online cialis no online prescription levitra no prescription cialis buy online purchase accutane cialis overnight delivery overnight cialis low cost viagra viagra in australia buy discount cialis online order viagra accutane without a prescription buy discount cialis viagra approved clomid no prescription purchase propecia zithromax prescription buy acomplia cheap synthroid online cheapest cialis price buy no rx viagra buy generic levitra cheap viagra no rx clomid for sale zithromax for sale viagra without a prescription cheap generic clomid where to buy accutane cheap propecia cheap cialis accutane generic buy generic lasix cialis side effects soma sale fda approved cialis cheap viagra pharmacy propecia for sale buy cheap cialis online soma discount cheap clomid online discount lasix acomplia online stores generic lasix cialis information cialis no prescription clomid online where to buy lasix online lasix propecia discount cialis online without prescription cialis online cheap cialis internet generic levitra find discount cialis online levitra prices where to order cialis buy levitra cheap synthroid generic order cheap viagra online cialis india cheap clomid tablets cheap zithromax online buy accutane online acomplia no prescription cialis internet order viagra no prescription viagra vendors buy cheap synthroid viagra prices cheap viagra no prescription