JetBrains / lincheck

Framework for testing concurrent data structures
Mozilla Public License 2.0
572 stars 33 forks source link

Java 9+ instrumentation without VM options #136

Closed ndkoval closed 4 months ago

ndkoval commented 1 year ago

The current model checking implementation requires the following VM options to be added:

--add-opens java.base/jdk.internal.misc=ALL-UNNAMED
--add-exports java.base/jdk.internal.util=ALL-UNNAMED

We can overcome this restriction by transforming classes via a dynamically attached Java agent. See #249.

Subtasks to do:

ndkoval commented 1 year ago

The best option (if it works) would be transforming classes via a special java agent.

jifang commented 9 months ago

Hello, I am still getting the error when running with model check, even with the JVM options set. I was using the sample code from the official doc.

class Counter<T> {
    // The following line will generate the error
    private val size = AtomicInteger(0)
    @Volatile
    private var value = 0

    fun inc(): Int = ++value
    fun get() = value
}

class BasicCounterTest {
    private val c = Counter<Int>() // Initial state

    // Operations on the Counter
    @Operation
    fun inc() = c.inc()

    @Operation
    fun get() = c.get()

    @Test // JUnit
    fun modelCheckingTest() = ModelCheckingOptions().check(this::class)
}

error.log

ndkoval commented 4 months ago

Fixed under #285 and #296