Search code examples
javabytecodeinstrumentationjvm-bytecodequasar

What does AOT instrumentation mean?


I know what bytecode instrumentation is. It is simply changing .class files bytecodes during runtime, which seems to be available since JDK 1.5. However, it's said to be during class loading not exactly runtime.

Now my question is, what is AOT or Ahead of Time instrumentation? What is the opposite procedure? Over Time Instrumentation?

Instrumenting Your Code
Quasar fibers rely on bytecode instrumentation. This can be done at classloading time via a Java Agent, or at compilation time with an Ant task.

Running the Instrumentation
Java Agent Quasar’s lightweight thread implementation relies on bytecode instrumentation. Instrumentation can be performed at compilation time (detailed below) or at runtime using a Java agent. To run the Java agent, the following must be added to the java command line (or use your favorite build tool to add this as a JVM argument):

-javaagent:path-to-quasar-jar.jar

Ahead-of-Time (AOT) Instrumentation
The easy and preferable way to instrument programs using Quasar is with the Java agent, which instruments code at runtime. Sometimes, however, running a Java agent is not an option.

Quasar supports AOT instrumentation with an Ant task. The task is co.paralleluniverse.fibers.instrument.InstrumentationTask found in quasar-core.jar, and it accepts a fileset of classes to instrument. Not all classes will actually be instrumented – only those with suspendable methods (see below) – so simply give the task all of the class files in your program. In fact, Quasar itself is instrumented ahead-of-time.

Source


Solution

  • Ahead-of-time (AOT) compilation/instrumentation is just that, it takes place before running the program.

    The opposite of AOT is Just-in-time, or JIT. It happens during runtime. In Java, class loading is done at runtime, and there are mechanics to fiddle with it.

    In your example, AOT instrumentation is done via an Ant task before running the program, and the changes are written into the .class file.

    The other possible way is doing it JIT, with a Java Agent. in this case, the instrumentation takes place at runtime when the class is loaded, and the result is not written into the file, but instead must be done anew every time the class is loaded.

    See Wikipedia/Ahead-of-time-compilation and Wikipedia/Just-in-time-compilation for more info.