Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor byte-code transformation #285

Merged
merged 56 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
a921c2d
New transformation implemented as a part of javaagents
Mar 4, 2024
411ca48
Merge branch 'develop' into transformation
Mar 4, 2024
f92784c
Test logging enabled to find ConcurrentModification bug
Mar 5, 2024
4562867
Test logging enabled to find ConcurrentModification bug
Mar 5, 2024
649d4cb
Some more logging...
Mar 5, 2024
b305dfc
Fix collectTrace
ndkoval Mar 5, 2024
6904cd5
Avoid undesired effects by previous runner in the trace collection.
Mar 6, 2024
5bfc47c
Java 21 random transformation bug fixed
Mar 7, 2024
95fb495
Coroutines bug fixed
Mar 14, 2024
b81de56
Output fixes
Mar 14, 2024
8f35d2c
Redundant final field checks removed
Mar 14, 2024
a62648f
Review fixes
Mar 14, 2024
11ab86f
Merge branch 'develop' into transformation
Mar 14, 2024
e48d2d8
Merge with develop
Mar 14, 2024
488c6ba
Review fixes
Mar 14, 2024
6c1a8fb
Review fixes
Mar 14, 2024
50aa14d
Review fixes
Mar 14, 2024
a31db20
Review fixes
Mar 14, 2024
61e3f04
ConcurrentModification bug fix attempt 2
Mar 15, 2024
1246649
Output fix
Mar 15, 2024
88258a5
Output fix
Mar 15, 2024
9516e34
Review fixes
Mar 15, 2024
ffd8ef8
Documentation added
Mar 15, 2024
66315ad
Review fixes
Mar 15, 2024
8526733
Review fixes
Mar 16, 2024
bfc0960
Review fixes
Mar 16, 2024
4c88880
Review fixes
Mar 17, 2024
fdec41d
Documentation added
Mar 18, 2024
4618ec5
Refactoring
Mar 18, 2024
0f5db96
Refactoring
Mar 18, 2024
6167b77
Non-determenism fix attempt
Mar 18, 2024
7d70e51
Review
ndkoval Mar 18, 2024
aa4fbe0
Fix Random support
ndkoval Mar 18, 2024
ffc2583
Review fixes
Mar 18, 2024
399520a
Merge remote-tracking branch 'origin/transformation' into transformation
Mar 18, 2024
8c8b4c5
Fix OperationsInAbstractClassTest
ndkoval Mar 18, 2024
2ab9fd0
Merge remote-tracking branch 'origin/transformation' into transformation
Mar 19, 2024
c40f9f1
Review fixes
Mar 19, 2024
a11de54
Review fixes
Mar 19, 2024
8a0a5f8
Review + refactoring
ndkoval Mar 19, 2024
771af8e
Review + refactoring
ndkoval Mar 19, 2024
076f7bd
Review + refactoring
ndkoval Mar 19, 2024
83937b1
Review + refactoring
ndkoval Mar 19, 2024
2c9da61
Review + refactoring
ndkoval Mar 19, 2024
c51ab93
Review + refactoring
ndkoval Mar 19, 2024
98e9385
Documentation
ndkoval Mar 19, 2024
0e1b891
Attempt to fix the representation of atomic constructs
ndkoval Mar 19, 2024
bda1166
Attempt to fix the representation of atomic constructs
ndkoval Mar 19, 2024
63663de
Small refactoring
ndkoval Mar 19, 2024
0fb7ba8
Refactoring
ndkoval Mar 19, 2024
66a5039
Small renaming
ndkoval Mar 19, 2024
d1fa745
Review fixes
Mar 19, 2024
6d3fb40
Review fixes
Mar 19, 2024
03b4506
Review fixes
Mar 19, 2024
f96995f
Do not run JdkUnsafeTraceRepresentationTest on java <13
ndkoval Mar 19, 2024
a4b099d
Merge branch 'transformation' of github.com:JetBrains/lincheck into t…
ndkoval Mar 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Lincheck
*
* Copyright (C) 2019 - 2024 JetBrains s.r.o.
*
* This Source Code Form is subject to the terms of the
* Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed
* with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

package org.jetbrains.kotlinx.lincheck

import sun.misc.Unsafe
import java.lang.reflect.Modifier
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater
import java.util.concurrent.atomic.AtomicLongFieldUpdater
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater

/**
* [AtomicFieldUpdaterNames] is used to map atomic objects to their names (usually, the corresponding field names)
* and class owners. The weak identity hash map ensures that atomic objects are compared using reference
* equality and does not prevent them from being garbage collected.
*/
internal object AtomicFieldUpdaterNames {
private val unsafe: Unsafe = try {
val unsafeField = Unsafe::class.java.getDeclaredField("theUnsafe")
unsafeField.isAccessible = true
unsafeField.get(null) as Unsafe
} catch (ex: Exception) {
throw RuntimeException("Can't get the Unsafe instance, please report it to the Lincheck team", ex)
}

fun getName(updater: Any): String? {
if (updater !is AtomicIntegerFieldUpdater<*> && updater !is AtomicLongFieldUpdater<*> && updater !is AtomicReferenceFieldUpdater<*, *>) {
throw IllegalArgumentException("Provided object is not a recognized Atomic*FieldUpdater type.")
}
// Extract the private offset value and find the matching field.
try {
// Cannot use neither reflection not MethodHandles.Lookup, as they lead to a warning.
val tclassField = updater.javaClass.getDeclaredField("tclass")
val targetType = unsafe.getObject(updater, unsafe.objectFieldOffset(tclassField)) as Class<*>

val offsetField = updater.javaClass.getDeclaredField("offset")
val offset = unsafe.getLong(updater, unsafe.objectFieldOffset(offsetField))

for (field in targetType.declaredFields) {
try {
if (Modifier.isNative(field.modifiers)) continue
val fieldOffset = if (Modifier.isStatic(field.modifiers)) unsafe.staticFieldOffset(field)
else unsafe.objectFieldOffset(field)
if (fieldOffset == offset) return field.name
} catch (t: Throwable) {
t.printStackTrace()
}
}
} catch (t: Throwable) {
t.printStackTrace()
}

return null // Field not found
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import org.jetbrains.kotlinx.lincheck.CTestConfiguration.Companion.DEFAULT_TIMEO
import org.jetbrains.kotlinx.lincheck.execution.*
import org.jetbrains.kotlinx.lincheck.strategy.*
import org.jetbrains.kotlinx.lincheck.strategy.managed.*
import org.jetbrains.kotlinx.lincheck.strategy.managed.ManagedCTestConfiguration.Companion.DEFAULT_ELIMINATE_LOCAL_OBJECTS
import org.jetbrains.kotlinx.lincheck.strategy.managed.modelchecking.*
import org.jetbrains.kotlinx.lincheck.strategy.stress.*
import org.jetbrains.kotlinx.lincheck.verifier.*
Expand Down Expand Up @@ -96,7 +95,6 @@ internal fun createFromTestClassAnnotations(testClass: Class<*>): List<CTestConf
testClass
),
timeoutMs = DEFAULT_TIMEOUT_MS,
eliminateLocalObjects = DEFAULT_ELIMINATE_LOCAL_OBJECTS,
customScenarios = emptyList()
)
}
Expand Down

This file was deleted.

49 changes: 49 additions & 0 deletions src/jvm/main/org/jetbrains/kotlinx/lincheck/EventTracker.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Lincheck
*
* Copyright (C) 2019 - 2024 JetBrains s.r.o.
*
* This Source Code Form is subject to the terms of the
* Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed
* with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

package org.jetbrains.kotlinx.lincheck

import java.util.*

/**
* Methods of this interface are called from the instrumented tested code during model-checking.
* See [Injections] for the documentation.
*/
internal interface EventTracker {
fun lock(monitor: Any, codeLocation: Int)
fun unlock(monitor: Any, codeLocation: Int)

fun park(codeLocation: Int)
fun unpark(thread: Thread, codeLocation: Int)

fun wait(monitor: Any, codeLocation: Int, withTimeout: Boolean)
fun notify(monitor: Any, codeLocation: Int, notifyAll: Boolean)

fun beforeReadField(obj: Any, className: String, fieldName: String, codeLocation: Int)
fun beforeReadFieldStatic(className: String, fieldName: String, codeLocation: Int)
fun beforeReadArrayElement(array: Any, index: Int, codeLocation: Int)
fun afterRead(value: Any?)

fun beforeWriteField(obj: Any, className: String, fieldName: String, value: Any?, codeLocation: Int)
fun beforeWriteFieldStatic(className: String, fieldName: String, value: Any?, codeLocation: Int)
fun beforeWriteArrayElement(array: Any, index: Int, value: Any?, codeLocation: Int)
fun afterWrite()

fun beforeMethodCall(owner: Any?, className: String, methodName: String, codeLocation: Int, params: Array<Any?>)
fun beforeAtomicMethodCall(owner: Any?, methodName: String, codeLocation: Int, params: Array<Any?>)
fun onMethodCallFinishedSuccessfully(result: Any?)
fun onMethodCallThrewException(t: Throwable)

fun getThreadLocalRandom(): Random
fun randomNextInt(): Int

fun onNewObjectCreation(obj: Any)
fun onWriteToObjectFieldOrArrayCell(obj: Any, fieldOrArrayCellValue: Any?)
}

This file was deleted.

Loading