3

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.

Defd
  • 470
  • 3
  • 16
  • Have you benchmarked any of the scripting languages? How do you know if they aren't fast enough? – skaffman Jun 30 '10 at 07:43
  • BeanShell and Groovy are quite different. Groovy compiles to regular Java class files. – Matthew Flaschen Jun 30 '10 at 07: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. – Defd Jun 30 '10 at 07:58

1 Answers1

3

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

Matthew Flaschen
  • 278,309
  • 50
  • 514
  • 539
  • +1 it's really handy. i still dont know why groovy is slower. – Defd Jul 01 '10 at 13:19
  • 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. – Jim Pivarski Aug 19 '13 at 18:20