What is meant by “fast-path” uncontended synchronization?

前端 未结 3 893
清歌不尽
清歌不尽 2021-02-14 05:18

From the Performance and Scalability chapter of the JCIP book:

The synchronized mechanism is optimized for the uncontended case(volatile is alw

3条回答
  •  半阙折子戏
    2021-02-14 05:46

    There are two distinct concepts here.

    1. Fast-path and Slow-path code
    2. Uncontended and Contended synchronization

    Slow-path vs Fast-path code

    This is another way to identify the producer of the machine specific binary code.

    With HotSpot VM, slow-path code is binary code produced by a C++ implementation, where fast-path code means code produced by JIT compiler.

    In general sense, fast-path code is a lot more optimised. To fully understand JIT compilers wikipedia is a good place to start.

    Uncontended and Contended synchronization

    Java's synchronization construct (Monitors) have the concept of ownership. When a thread tries to lock (gain the ownership of) the monitor, it can either be locked (owned by another thread) or unlocked.

    Uncontended synchronization happens in two different scenarios:

    1. Unlocked Monitor (ownership gained strait away)
    2. Monitor already owned by the same thread

    Contended synchronization, on the other hand, means the thread will be blocked until the owner thread release the monitor lock.

    Answering the question

    By fast-path uncontended synchronization the author means, the fastest bytecode translation (fast-path) in the cheapest scenario (uncontended synchronization).

提交回复
热议问题