Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2006

Tip: Looking for answers? Try searching our database.

JNI application

Thread view: 
suresh.gn@gmail.com - 04 Jul 2006 12:18 GMT
Dear Java experts,

I am working on an image processing application developed using Java.
We have developed good algorithms, but the speed with which it is
processing is very bad. I need to enhance the speed by atleast 50X. I
tried JNI calls to C. But it is not giving any perfomance enhancement.
In addition to that it is crashing very often with crash detail
ntdll.dll error.

1) Experts please give me your suggestions what I can do in this regard
to enhance the application speed?
2) What is the probable reason for hotspot JVM crash? (I am using
windows XP OS)
3) What are the other steps I can take to enhance the speed?

Thanks in advance
lang.java.programmer
Tim Ward - 04 Jul 2006 13:15 GMT
> Dear Java experts,
>
[quoted text clipped - 7 lines]
> 1) Experts please give me your suggestions what I can do in this regard
> to enhance the application speed?

Not worth thinking about until you have fixed the bugs.

> 2) What is the probable reason for hotspot JVM crash? (I am using
> windows XP OS)

Bugs in your DLL.

> 3) What are the other steps I can take to enhance the speed?

Well, you've already profiled the Java, haven't you, otherwise you wouldn't
have known that it was worth trying JNI. Then profiling what's going on in
the DLL will probably be useful; and of course you'll have spotted that
calls into a DLL from JNI are really rather expensive, so you've already
made sure that you aren't making very many.

Er, then all the usual speed optimisation steps - look for changes to data
and algorithms before you try to make the existing algorithms run faster (by
coding them in C or whatever). It sounds to me that these two statements of
yours:

> We have developed good algorithms...
> I need to enhance the speed by atleast 50X....

could be in conflict. In what sense are your algorithms "good" if they fail
to meet your performance requirements?

--
Tim Ward
Brett Ward Limited - www.brettward.co.uk
suresh.gn@gmail.com - 05 Jul 2006 04:42 GMT
> > Dear Java experts,
> >
[quoted text clipped - 33 lines]
> could be in conflict. In what sense are your algorithms "good" if they fail
> to meet your performance requirements?

Ans: I mean, the algorithm is able to produce good quality image but
with very slow processing.Overall I can summarise as it is not time
efficient but providing quality output. I hope I have answered your
doubt.

> --
> Tim Ward
> Brett Ward Limited - www.brettward.co.uk
Gordon Beaton - 04 Jul 2006 13:23 GMT
> I need to enhance the speed by atleast 50X. I tried JNI calls to C.
> But it is not giving any perfomance enhancement. In addition to that
> it is crashing very often with crash detail ntdll.dll error.
>
> 1) Experts please give me your suggestions what I can do in this regard
> to enhance the application speed?

First, JNI is no guarantee that your code will run faster, as you have
discovered.

However if you are determined to use JNI, then you need to make sure
your calls to native methods are as few as possible, because crossing
the Java/C boundary to invoke a native method is expensive.

It can be even more expensive to invoke JNI functions from within
native methods (to look up method or field IDs, to set or get values
in Java obects, etc), so make sure any data you pass to and from your
native methods is in a form that can be used directly by the native
method, as far as this is possible.

> 2) What is the probable reason for hotspot JVM crash? (I am using
> windows XP OS)

Slopping pointer handling, failure to manage memory properly,
uninitialized variables, failure to check return values, and things
like that. More information can be found here:

http://c-faq.com/strangeprob/segv.html
http://c-faq.com/strangeprob/funnybugs.html
http://c-faq.com/malloc/crash.html

/gordon

Signature

[ don't email me support questions or followups ]
g o r d o n  +  n e w s  @  b a l d e r 1 3 . s e

Chris Uppal - 04 Jul 2006 13:28 GMT
> I am working on an image processing application developed using Java.
> We have developed good algorithms, but the speed with which it is
> processing is very bad. I need to enhance the speed by atleast 50X.

You can't get a 50x speedup "for free" whether by re-writing in C (or Fortran)
or by using a different JVM.  You'd better hope that you are doing something
pretty grossly inefficient, or there is no way that you can fix this (assuming
the algorithms themselves are good, which you say they are, and that using a
farm of a hundred or so computers is not feasible).

Some questions:

Why do you think it is possible at all ?  Do you have a good reason to think
that it's even possible on today's hardware ?   E.g. you may have seen another
application which does roughly the same processing at the speed you desire.

Where is the time going with your current code.  E.g. it could mostly be in the
inner loops of the image processing -- in which case you will have to think
hard about how you can redesign those loops.  But it might be that you are
doing pixel-by-pixel access, and that most of your application's time is spent
reading/writing the values of individual pixels.  Until you know where the time
is going, you have no idea what you have to change.  So profile your code.

Related to the previous question: how is your image data represented while you
are working on it ?  If it isn't an array of primitive numeric values (int[],
float[], byte[], ...) or maybe a small number of such arrays (say, one for each
colour channel), then it should be.

BTW, if you are trying to use JNI, then make sure that you are crossing the
boundary between Java and C as few times as possible.  Once per image per
operation should be about right.  If you are crossing the boundary once per
pixel (or even several times per pixel) then your performance will be dreadful.

> 2) What is the probable reason for hotspot JVM crash? (I am using
> windows XP OS)

Almost certainly a bug in your C code, or in the way you handle JNI.

   -- chris


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.