4 Replies Latest reply: Nov 4, 2010 12:06 PM by 809786 RSS

    javac optimization hints for jvm

    809786
      Does javac provide optimization hints to the jvm in the class files that it generates?

      If so, how? Does it write annotations into the bytecode?

      If not, is this because the HotSpot jvm can analyze the class file quickly and comprehensively enough during class loading? Or is it because including hints in the class file will increase the file size too much? Or is it some other technical reason? Or is it just because no one has gotten around to writing it yet?

      Thanks.
        • 1. Re: javac optimization hints for jvm
          796440
          Ross wrote:
          Does javac provide optimization hints to the jvm in the class files that it generates?
          No. Javac may do a couple of very simple, minor optimizations of its own, but Hotspot is responsible for the meat of the optimizations.
          If not, is this because the HotSpot jvm can analyze the class file quickly and comprehensively enough during class loading?
          The most significant optimizations come at runtime after a section of code has been executed a large number of times.
          Or is it because including hints in the class file will increase the file size too much? Or is it some other technical reason? Or is it just because no one has gotten around to writing it yet?
          Most likely it's because there's no real benefit to putting any such hints in the class file. There's nothing the compiler knows that the JVM can't see by reading the file, but the JVM learns things during runtime that javac can't know. Additionally, class file parsing is s very small fraction of any program of any significant size, and if it's not, then you've got other issues that won't be solved by code optimization.
          • 2. Re: javac optimization hints for jvm
            809786
            @jverd
            Thanks for replying to this, as well as to my previous javac StringBuilder question.

            Do you know of any statistics for how long the various parts of class loading / subsequent class optimizations in the latest Java 7 HotSpot take? Obviously they'll be dependent on the machine on which HotSpot is run, on the HotSpot settings, on the classes being loaded, etc., but general measures should be somewhat indicative of performance, especially the relative performance of different parts of class loading / optimization.

            Thanks again.
            • 3. Re: javac optimization hints for jvm
              796440
              No, I don't know. Don't have the faintest idea. And I don't care. I don't care about class loading time because it's not a significant fraction of the time consumed by any app I've ever worked on. I don't care about how long a given hotspot optimization takes because I don't write code around that time and can't do anything about it.

              Why is it that you care about these values?
              • 4. Re: javac optimization hints for jvm
                809786
                Why is it that you care about these values?
                I'm just interested in understanding how javac & HotSpot work, and am looking for possible improvements. Not for any particular purpose for me, but for the Java community at large.