Pattern Patter
ContextLanguage implementation.Forces
ResolutionBuild an interpreter first, and then integrate a just-in-time (JIT) compiler. The JIT can either compile the code all at once when it's first ready to "interpret", or it can compile classes or methods on an as-needed basis.DiscussionIt's easier to implement an interpreter than a compiler. Providing the interpreter first gives us early access to a language implementation. (For many languages, it is desirable to write the compiler in that language itself, so an interpreter provides a way to bootstrap that process.)You can develop an intermediate language that is customized to the programming language - space-efficient and portable. (Java uses "JVM" code for just such a reason: Java code should be small when shipped across the network, and portable because there are many machines on the net.) Once the interpreter framework is in place, you can build the compiler around it. (Perhaps even one construct at a time, if you like.) The resulting system will not have code as fast as a pure compiler (which has more time and usually more code to look at while compiling). The system will usually beat a pure interpreter though. Instead of n * interpret_time(x)for n statements, you pay compile_time(x) + n * run_time(x)(Note that if compile_time(x)+run_time(x) is longer than interpret_time(x), the JIT can actually run slower than an interpreter: there must be enough executions of the run-time to amortize the cost of the compile-time.) Examples
CaveatsProcessors have rules about creating code in an existing process. They may require that an instruction cache be flushed before the generated code is executed. (Failure to do this may result in strange errors.) Unfortunately, this adds "hidden" slow-downs before new code is first executed.[Written 7-20-98] |
|
Copyright 1994-2010, William C. Wake - William.Wake@acm.org |