help needed to find the compile time

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gsreenathreddy
    New Member
    • Oct 2007
    • 40

    #1

    help needed to find the compile time

    How to know how much time taken by jvm to compile the application
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by gsreenathreddy
    How to know how much time taken by jvm to compile the application
    The JVM does not compile the application. javac does. The JVM runs the .class files.

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      Originally posted by r035198x
      The JVM does not compile the application. javac does. The JVM runs the .class files.
      But Javac itself is entirely written in Java and is run by the JVM as well. As of
      Java 1.6 there's a nice interface available to the user, i.e. you can programmaticall y
      start the Javac compiler and time its performance if you like.

      kind regards,

      Jos

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by JosAH
        But Javac itself is entirely written in Java and is run by the JVM as well. As of
        Java 1.6 there's a nice interface available to the user, i.e. you can programmaticall y
        start the Javac compiler and time its performance if you like.

        kind regards,

        Jos
        That will be the JavaCompilerToo l interface?
        Yep, it's quite nice.

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Originally posted by r035198x
          That will be the JavaCompilerToo l interface?
          Yep, it's quite nice.
          I haven't tried it yet but can we instantiate a compiler object when just the JRE
          is installed on some machine? I guess not but can't prove it.

          It would be nice to have a 'scriptable' Java, i.e. compile from a String or Stream
          to a byte[] array and use that for class loading ... it would make BeanShell
          superfluous ;-)

          kind regards,

          Jos

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by JosAH
            I haven't tried it yet but can we instantiate a compiler object when just the JRE
            is installed on some machine? I guess not but can't prove it.

            It would be nice to have a 'scriptable' Java, i.e. compile from a String or Stream
            to a byte[] array and use that for class loading ... it would make BeanShell
            superfluous ;-)

            kind regards,

            Jos
            I imagine
            [CODE=java]JavaCompiler compiler = ToolProvider.ge tSystemJavaComp iler();[/CODE]

            would return null if only there is no javac tool installed.

            Comment

            • JosAH
              Recognized Expert MVP
              • Mar 2007
              • 11453

              #7
              Originally posted by r035198x
              I imagine
              [CODE=java]JavaCompiler compiler = ToolProvider.ge tSystemJavaComp iler();[/CODE]

              would return null if only there is no javac tool installed.
              This is cute; the following prints "null" on my system; (a JDK 1.6 is installed).

              [code=java]
              System.out.prin tln(ToolProvide r.getSystemJava Compiler());
              [/code]

              kind regards,

              Jos

              Comment

              • r035198x
                MVP
                • Sep 2006
                • 13225

                #8
                Originally posted by JosAH
                This is cute; the following prints "null" on my system; (a JDK 1.6 is installed).

                [code=java]
                System.out.prin tln(ToolProvide r.getSystemJava Compiler());
                [/code]

                kind regards,

                Jos
                I found it
                Code:
                com.sun.tools.javac.api.JavacTool@1ffb8dc
                was the output.

                I've just been looking at the code for the ToolProvider class. It seems to be checking the System java.home property. I have my Java home pointing to my JDK 1.5_3 but I used NB which I setup to run with 1.6 to run that command.
                I wonder which javac it found. The 1.6 or the 1.5 that I use with Eclipse which is also set as my Java home.

                Comment

                • JosAH
                  Recognized Expert MVP
                  • Mar 2007
                  • 11453

                  #9
                  Originally posted by r035198x
                  I found it
                  Code:
                  com.sun.tools.javac.api.JavacTool@1ffb8dc
                  was the output.

                  I've just been looking at the code for the ToolProvider class. It seems to be checking the System java.home property. I have my Java home pointing to my JDK 1.5_3 but I used NB which I setup to run with 1.6 to run that command.
                  I wonder which javac it found. The 1.6 or the 1.5 that I use with Eclipse which is also set as my Java home.
                  I just peeked at the sources of the ToolProvider class too: you're right: it checks
                  the java_home variable; it it points at the jre it assumes that the jdk is next to it.
                  Finally it attempts to find the tools.jar where the compiler can be found.

                  I didn't have any java_home value set, hence the "null" being returned. I find it a bit
                  of a clumsy mechanism but I'm sure Sun uses a fancy and expensive name for it ;-)

                  kind regards,

                  Jos

                  Comment

                  Working...