Skip to content

filtering JAVAC.SYNC

Evgeny Mandrikov edited this page Sep 29, 2017 · 5 revisions

This page discusses a not yet available feature!

Description

A Java synchronized block gets compiled into two bytecode instructions: MONITORENTER at the beginning and MONITOREXIT at the end of the block.

To ensure that the the monitor is released in any case an exception handler is installed which points to another MONITOREXIT instruction. This exception handler block typically causes partial line coverage which doesn't make sense from the source code point of view.

Filtering

The exception handler block with the MONITOREXIT instruction should be excluded from analysis.

Source Example

synchronized (lock) {
    ...
}

Bytecode Pattern

ECJ

  ...
label_1:
  ALOAD n
  MONITOREXIT
  ATHROW

Exception Table:
  [pc: label_x, pc: label_y] -> label_1 when : any

JDK

  ...
label_1:
  ASTORE m
  ALOAD n
  MONITOREXIT
  ALOAD M
  ATHROW

Exception Table:
  [pc: label_x, pc: label_y] -> label_1 when : any