Skip to content

Architecture of Microbat Instrumentator

Yun Lin edited this page Oct 26, 2020 · 7 revisions

Goal

Microbat is framework which can dynamically instrument Java bytecode to a target program so that we can keep track of its execution trace. Nevertheless, the instrumentation allows us to both observe and modifying the program runtime behavior. In this stage, we focus more on observing. In the long run, we will move on to modifying and optimizing the runtime execution performance.

Agent Architecture

The design for microbat_instrumentator is close to Observer (Inceptor) Pattern. In this project, we inject agents into the program execution process & listen to favorable events such as when state/execution is reach. To implement this, there are a few types of components need to be identified/defined to do the job. Their relations can be inferred by Fig.1.

  • Observable: the subject in which we can inject our agents.

  • Injector: to inject agents into the program execution process.

  • Observer: There are some observers to listen to different events, but amongst them there is one who does the main job of collecting data from the execution for our specific purpose, let call them Observer Headquarter.

  • Event: sent from our agents to Observer whenever favorable state/execution is reach, it also implicitly indicates where to inject & why. fig1

Instrumentation Detail

We provide three transformers in this project, i.e.,

  • Precheck Transformer (microbat.instrumentation.precheck.PrecheckTransformer),
  • Trace Transformer (microbat.instrumentation.instr.TraceTransformer), and
  • TestRunner Transformer (microbat.instrumentation.instr.TestRunnerTranformer).

Prechecker transformer uses the most lightweight instrumentation to record sequential trace, Trace Transformer uses a "heavy gun" to collect detailed runtime behavior (including the runtime data dependency, method entry/exit event, etc.), while TestRunner Transformer is designed to record branch coverage information. Readers can check doTransform() method for more details. An example can be referred by checking TraceInstrumenter.runMethodInstrumentation() method.

Users can define their own events (e.g., hit a line, read a variable, enter a method, etc.) at microbat.instrumentation.instr.TracerMethods