Re: Run-time compilation

Discussion in 'Java' started by Stefan Ram, Nov 10, 2008.

  1. Stefan Ram

    Stefan Ram Guest

    Stefan Ram, Nov 10, 2008
    #1
    1. Advertising

  2. Stefan Ram

    Mark Space Guest

    Jon Harrop wrote:

    > I see there is also a ClassLoader. Is there an API to generate classes
    > directly, i.e. without going through Java source code as text?
    >


    I haven't tried any of these libraries myself, but is this along the
    lines of what you're looking for?

    <http://java-source.net/open-source/bytecode-libraries>
    Mark Space, Nov 11, 2008
    #2
    1. Advertising

  3. Stefan Ram

    Stefan Ram Guest

    Stefan Ram, Nov 11, 2008
    #3
  4. Stefan Ram

    Eric Sosman Guest

    Jon Harrop wrote:
    > Stefan Ram wrote:
    >
    >> Jon Harrop <> writes:
    >>> Are there any examples of run-time compilation from the Java
    >>> language anywhere?

    >> http://www.purl.org/stefan_ram/pub/evaluating-expressions-with-java
    >>
    >> (I am using files there, which is not necessary,
    >> it all could also have been compiled in memory.)

    >
    > Ok, so you're generating Java source code in a file and then invoking the
    > Java compiler using the new API.
    >
    > I see there is also a ClassLoader. Is there an API to generate classes
    > directly, i.e. without going through Java source code as text?


    The class file format is documented in the Java Virtual
    Machine Specification. Before friendlier tools came on the
    scene, I used that documentation to write a compiler that
    turned a String like "cos(x) * sin(y)" into an object of a
    freshly-loaded class with an evaluate() method that performed
    the calculation. So I can testify that the task is do-able.
    A bit tedious, but do-able. (The fact that evaluate() would
    always be straight-line code without branches, try blocks,
    loops, and so on helped minimize the tedium; there were big
    chunks of the class file format I could simply ignore.)

    --
    Eric Sosman
    lid
    Eric Sosman, Nov 11, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paul Cook
    Replies:
    0
    Views:
    447
    Paul Cook
    Nov 6, 2003
  2. flamesrock
    Replies:
    8
    Views:
    449
    Hendrik van Rooyen
    Nov 24, 2006
  3. Pierre Yves
    Replies:
    2
    Views:
    481
    Pierre Yves
    Jan 10, 2008
  4. C__chp
    Replies:
    4
    Views:
    501
    Puppet_Sock
    Feb 15, 2008
  5. Arne Vajhøj

    Re: Run-time compilation

    Arne Vajhøj, Nov 10, 2008, in forum: Java
    Replies:
    2
    Views:
    664
    Arne Vajhøj
    Nov 11, 2008
Loading...

Share This Page