• Post Reply Bookmark Topic Watch Topic
  • New Topic

Compiling Java to Native Code

 
Leslie Chaim
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello folks,
I have this client/server application all written in Java and we need that the overall application should be AFAP (as fast as possible ).
I have no idea how to do this . I take the idea from Peter Haggar's book Practical Java, from where I took out that: "It may increase performance but don't do it"
What do you think? Will compiling to native code increase performance? By how much? My OS is HP-UX. I can give a brief description of what the application does if that makes difference.
Thanks in advance,
Leslie
[ December 10, 2002: Message edited by: Leslie Chaim ]
 
Jon Strayer
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no way anyone can answer that question. You are going to have to benchmark your program yourself. Of the three Java native compilers that I know of, only two run on HPUX (GNU & TowerJ). You can get GNU for free. I'm sure you can get an evaluation copy of Tower.
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
compiling to native code won't make bad algorithms fast, and in general it won't make bad code run well. I'm not saying that your code is bad, but the place to start would be a profiler. Find out where most of the time is spent in your code, identifying bottlenecks. Work from there, and see if after you fix the bottlenecks, the performance problem still remains.
Jamie
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Will compiling to native code increase performance?
If your app is database driven ( mostly queries, and SQL ) you probably won't notice a difference since most of the time is spent on the network and database processing. And from what I understand, if your application repeatedly executes the same blocks of code, you may not notice a performace increase because the JIT usually compiles it down after the code is executed the first time anyways.
Jamie
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, JIT compilers already compile to Native Code. You just don't see it happen and you still have your bytecode.
Java in and of itself is not really any slower than platform dependent binary code. There are API's in JAVA that can be slower (SWING) but that is another story.
JIT - A bit of information.
 
Leslie Chaim
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for all your replies, let see if I can clarify myself; I hope I will not bore you with my long prose

compiling to native code won't make bad algorithms fast.

I guess I should describe a bit what my application is doing, since you mentioned bad algorithms. Anyway, I think it was/is a very exciting application for me to develop, especially as this was my first real Java program. I learned a lot of things one the way, thanks to books and of course this site. I guess I might as well share it with everyone. Perhaps, there will be someone who will find fun to illustrate this in RMI.
To start, let me just say my app. includes the following:
  • File I/O reading
  • Text parsing
  • Sockets and Streams
  • Client/Server
  • Database and SQL

  • This list is logically ordered as they execute within the app.
    Let me first begin with a brief description:

    This Java application reads/loads data from one text file to one or more relational (Oracle) databases and does transaction processing and maintains synchronization across all data replicas.
    The file is structured and has a SQL section in the first half, followed by the data section, which is in logical blocks that represent transactions to be loaded in the database.

    I give more detail in each link that I provide. I posted many queries here, and did lots of searching here in the ranch as I was going through my journey. I am mostly satisfied with the speed, but we all like to practice Moore's Law and I think there is room for performance in my app. Actually, my very first post was when it all started! I then completed my work as I outlined in my first post, but then I ran into problems and I came back with my Second post on this issue. I then took Michael Ernest's advice and re-wrote my application with the client/server model. I had a couple of issues I will not list them all, the biggest of which was related to Streams.
    My thing works and the speed is acceptable considering the massive updates that it needs to do. Here is a quick outline of how the design.
    The server:
    The multi-threaded server is located on each box as new Clients connects a new Request object is created which is running in its own thread.
    The Request then sets up the input/output streams with the client socket. Then, using Object Serialization, reads a Command object from the client and does its thing according to the (hmm) "protocol". Upon completion of the Command, a Result Object is sent back to the client containing status conditions and/or any Exceptions.
    The Request object creates a local (to the server) Exec object that connects to the local database. The Exec does the SQL operations and commit/rollback as invoked by the Request, which in turn gets the command from the client.
    The Client:
    A DataReader object is created that reads from the file, the two most important methods are getSQLInsrtunctions() and getData(), all the parsing is done in the DataReader.
    The DataReader creates an array of StatementUnit objects, where a StatementUnit represents a single table, num_rows, num_cols, etc.
    A Manager Object (or Boss) is created to handle the synchronization of the remote databases. The Manager creates 'n' Client Objects based on the number of JDBC URLs given on the command line. (Which is sent over and used by the Request and Exec Classes) The Manager gets the info from the DataReader passing it to the Client instances, then waits... using the mutex of the StatementUnit array (object).
    Each Client runs in its own thread, and connects via a Socket to the aforementioned Server. The Client follows the (hmm) "protocol" and sends a Command Object over the wire getting back a Result object. Then the client hits a Barrier and waits using the mutex of 'this'. The Barrier 'knows' how many client there are and when the last Client hits the Barrier it notify()s the Manager. And� the cycle begins again until all data from the file has been read.
    There is no doubt that the Java app. is more complex then the C program. Nevertheless, the brief description should tell you that the end result of both apps should be the same.
    To finish my story and some comparison, the C program is not multi-thread and no client/server thing is involved. I tested 600 transactions executing to 4 database schemas, and it takes about 17 minutes with the C program, and about 4 Minutes with the Java program. However, if I run the same 600 transactions for ONE database the C program runs about 1.5 minutes while the Java thing runs in about the very same 4 minutes.

    but the place to start would be a profiler.

    And where do I get a profiler and how do I start? I would be interested in at least running it. Thanks,

    Also, JIT compilers already compile to Native Code. You just don't see it happen and you still have your bytecode.

    JIT - A bit of information.
    ..

    Thanks for the link Gregg, now some where in that article it says: "When a JIT is present � The JIT will take the bytecodes and compile them into native code �"
    My question to you how do I know if a "JIT is present"?
    Here is all that I can give you:

    How do I get/install setup the JIT. I remember reading 'somewhere' that the JIT is 'somehow' built-in

    Any input is greatly appreciated. BTW, I am thinking of taking the SCJD exam and I would appreciated your thoughts on that as well.
    [ December 11, 2002: Message edited by: Leslie Chaim ]
     
    Gregg Bolinger
    Ranch Hand
    Posts: 15304
    6
    Chrome IntelliJ IDE Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I don't know which version it started with but I know that 1.4.x uses a JIT compiler by default. There is a command option to not use it if you don't want to. So by running your application using the typical java command, the JIT is enabled.
    The JIT that Sun's JDK uses is of course written by the geniuses at Sun.
    There are other JRE's/JDK's that are available that adhere to the JVM Specs. One that I like is JRockit. I can't really say if it is better/faster than Sun's VM though. But I have used it, and it seems to work well.
     
    Jamie Robertson
    Ranch Hand
    Posts: 1879
    MySQL Database Suse
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I tend not to have performance as the number one priority, but generally spend most of my time:
    1. Making the program work properly ( extensive testing )
    2. Making the program user friendly
    3. Making the program code reusable and easily maintained
    4. Make the program perform at an acceptable level for the users ( using a profiler after 1-3 have been accomplished and the user deems the performance as not acceptable )
    I remember when I first started, I concentrated on performance first. I pray that I'm gone when it has to be maintained! In fact, I now add 2-5 seconds at the start of most of my reporting programs to issue a select count(*) so that I can create a progress monitor. Even though it takes longer, it seems like less time to the user because they can see the progress. You'll find that with experience, squeezing every last performance millisecond out of an application will become less important
    Jamie
     
    Leslie Chaim
    Ranch Hand
    Posts: 336
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    I tend not to have performance as the number one priority

    Well, that is exectaly what I did and now that my thing works I am looking for better performance.

    Make the program perform at an acceptable level for the users ( using a profiler ... and the user deems the performance as not acceptable )

    A profiler! Great! Where and how do you get/setup this fruit.
    Thanks,
     
    Barry Gaunt
    Ranch Hand
    Posts: 7729
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    May be this book might help:
    Java Performance Tuning
     
    Jamie Robertson
    Ranch Hand
    Posts: 1879
    MySQL Database Suse
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    list of profilers
    JProfiler
    if search on google, I'm sure you'll find more, and their are also specialized profilers for specific uses ( EJB's, jsp's, jdbc, etc )
    My point that I was trying to make, is better explained by this quote:
    "coding tips and the kinds of gains you can expect for each
    structure
    The architecture and algorithms of your program are much more important than any low-level optimizations you might perform. Bad architecture and algorithms can make any system seem slow. Premature optimization may be the root of all programming evil (says Knuth) but failure to consider performance right from the start can doom a program to uselessness.
    - Tune at the highest level first.
    - Make the common case fast
    ...."
    taken shamelessly from here
    Jamie
     
    Ilja Preuss
    author
    Sheriff
    Posts: 14112
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Originally posted by Leslie Chaim:

    How do I get/install setup the JIT. I remember reading 'somewhere' that the JIT is 'somehow' built-in

    The "HotSpot(TM)" engine is the successor of the early JIT compilers. It will not only compile the critical parts of your application, but also perform different optimizations based on an analysis of the running code.
     
    Gerald Davis
    Ranch Hand
    Posts: 872
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Have you tried to convert the Java application to C or whatever?
     
    Leslie Chaim
    Ranch Hand
    Posts: 336
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Gerald,
    Can you elaborate your question a bit?
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!