4

im aware that j2se 6 has introduced the JavaCompiler API; however, it's cumbersome to use and require a JDK not JRE.

Is it possible to do dynamic compilation without a JDK? (im very interested in all-in-memory compilation.)

additionally, i expect the performance to be close to raw java code, so i don't want to use a scripting language like BeanShell or Groovy.

thank you.

3
  • Have you benchmarked any of the scripting languages? How do you know if they aren't fast enough? Commented Jun 30, 2010 at 7:43
  • BeanShell and Groovy are quite different. Groovy compiles to regular Java class files. Commented Jun 30, 2010 at 7:51
  • that's the confusing part regarding the fact it compiles into byte code. i've seen many benchmarks comparing groovy with raw java, and the resulting difference is substantial (though they are not meant to be accurate, the slowness is indeed very obvious). I'm currently using beanshell, it's very slow in practice. So im seeking for better solutions. Commented Jun 30, 2010 at 7:58

1 Answer 1

4

You might be interested in Janino, particularly SimpleCompiler. For in-memory compilation, you can use the Reader constructor, and a StringReader.

Sign up to request clarification or add additional context in comments.

2 Comments

+1 it's really handy. i still dont know why groovy is slower.
Just a guess, but Groovy might be held back by doing type-checks at runtime (the cost of dynamic typing). Compiling to bytecode would make it faster to step through the lines of code (which are no longer "lines"), but the type checks still need to be done.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.