-
Notifications
You must be signed in to change notification settings - Fork 34
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
Support custom threads #415
base: develop
Are you sure you want to change the base?
Conversation
The only failing CI configuration is "Integration Test with kotlinx.coroutines". |
...vm/test/org/jetbrains/kotlinx/lincheck_test/transformation/KotlinStdlibTransformationTest.kt
Outdated
Show resolved
Hide resolved
0ad50bd
to
25c0c45
Compare
@ndkoval while working on this I discovered a few problems, which are probably should be addressed in separate PRs. One of the problems is related to the local objects tracking --- the current implementation does not work correctly with custom threads (see example below and the comment in class Box(var x: Int)
fun test(): Int {
val box = Box() // <- this object is incorrectly classified as a local object
thread {
box.x = 42 // the local object tracker does not detect here that the `box` object,
// stored in the local variable, escapes into another thread;
// thus it will not insert a switch point before accesses to this object fields
}
return box.x
} I would propose that we can address this problem separately in another PR after we merge this one. Alternatively, we can first perform the necessary refactoring of the local objects tracking algorithm in a separate PR, |
bac6712
to
250236c
Compare
Another small bug fix on which this PR relies on: #426 |
8d548c9
to
9a4fdcd
Compare
…egy` Signed-off-by: Evgeniy Moiseenko <[email protected]>
Signed-off-by: Evgeniy Moiseenko <[email protected]>
Signed-off-by: Evgeniy Moiseenko <[email protected]>
… blocking Signed-off-by: Evgeniy Moiseenko <[email protected]>
Signed-off-by: Evgeniy Moiseenko <[email protected]>
…ead group Signed-off-by: Evgeniy Moiseenko <[email protected]>
Signed-off-by: Evgeniy Moiseenko <[email protected]>
* in preparation of implementing ignored sections for custom threads Signed-off-by: Evgeniy Moiseenko <[email protected]>
Signed-off-by: Evgeniy Moiseenko <[email protected]>
… ignored sections Signed-off-by: Evgeniy Moiseenko <[email protected]>
Signed-off-by: Evgeniy Moiseenko <[email protected]>
Signed-off-by: Evgeniy Moiseenko <[email protected]>
…in `cancelByLincheck` Signed-off-by: Evgeniy Moiseenko <[email protected]>
Signed-off-by: Evgeniy Moiseenko <[email protected]>
…lass Signed-off-by: Evgeniy Moiseenko <[email protected]>
…lass Signed-off-by: Evgeniy Moiseenko <[email protected]>
Signed-off-by: Evgeniy Moiseenko <[email protected]>
Signed-off-by: Evgeniy Moiseenko <[email protected]>
Signed-off-by: Evgeniy Moiseenko <[email protected]>
Signed-off-by: Evgeniy Moiseenko <[email protected]>
Signed-off-by: Evgeniy Moiseenko <[email protected]>
Signed-off-by: Evgeniy Moiseenko <[email protected]>
Signed-off-by: Evgeniy Moiseenko <[email protected]>
…n case of abort Signed-off-by: Evgeniy Moiseenko <[email protected]>
Signed-off-by: Evgeniy Moiseenko <[email protected]>
Signed-off-by: Evgeniy Moiseenko <[email protected]>
…y the output Signed-off-by: Evgeniy Moiseenko <[email protected]>
Signed-off-by: Evgeniy Moiseenko <[email protected]>
Signed-off-by: Evgeniy Moiseenko <[email protected]>
2428b4f
to
469be4f
Compare
…m stack traces) Signed-off-by: Evgeniy Moiseenko <[email protected]>
Signed-off-by: Evgeniy Moiseenko <[email protected]>
return ((TestThread) thread).descriptor; | ||
} | ||
int hashCode = System.identityHashCode(thread); | ||
ArrayList<ThreadDescriptor> threadDescriptors = threadDescriptorsMap.get(hashCode); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use a weak hash map instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am afraid no, because we need concurrent identity hash map with weak keys, and there is no such data structure out-of-the-box in the Java standard library.
Please also have a look at the comment before threadDescriptorsMap
field declaration --- it explains the reason and the proposed solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would using Collections.synchronizedMap(...)
solve the issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Collections.synchronizedMap(...)
would not fully solve the problem. It would make the collection thread-safe, but WeakIdentityHashMap
is still not a thing in Java stdlib (remember we need thread-safe weak identity hash-map).
Also, there is a method to lookup for a descriptor of the given thread:
public static ThreadDescriptor getThreadDescriptor(Thread thread)
which uses threadDescriptorsMap.get
.
Forcing the descriptor lookup function to acquire a lock on each lookup (instead of using concurrent hash map), may in theory have a performance penalty.
src/jvm/test/resources/expected_logs/obstruction_freedom_synchronized.txt
Outdated
Show resolved
Hide resolved
src/jvm/test/resources/expected_logs/custom_threads_deque_trace.txt
Outdated
Show resolved
Hide resolved
@@ -79,7 +79,8 @@ fun shouldReplayInterleaving(): Boolean { | |||
*/ | |||
@Suppress("UNUSED_PARAMETER") | |||
fun beforeEvent(eventId: Int, type: String) { | |||
val strategy = (Thread.currentThread() as? TestThread)?.eventTracker ?: return | |||
val strategy = Injections.getCurrentThreadDescriptor()?.eventTracker |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you checked how custom threads work with the plugin?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it does not currently work.
I found one problem in the plugin code that I've managed to fix by myself, but it still does not work.
There are some other bugs, and I need help from someone on the plugin side to debug the remaining problems.
* with this file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
package org.jetbrains.kotlinx.lincheck.util |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to have to Utils.kt
files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea is to eventually leave only one file, inside the util
subpackage, and move the stuff from the top-level package Utils.kt
file either into util
subpackage or to other more suitable places.
However, I didn't want to clutter this PR with unnecessary changes, thus I haven't modified the top-level Utils.kt
file.
@@ -204,7 +204,7 @@ internal class LoopDetector( | |||
// Has the thread changed? Reset the counters in this case. | |||
check(lastExecutedThread == iThread) { "reset expected!" } | |||
// Ignore coroutine suspension code locations. | |||
if (codeLocation == COROUTINE_SUSPENSION_CODE_LOCATION) return Decision.Idle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why UNKNOWN? The documentation here and of the UNKNOWN_CODE_LOCATION
field says it is the coroutine suspension code location.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was COROUTINE_SUSPENSION_CODE_LOCATION
previously, I renamed it into UNKNOWN_CODE_LOCATION
because I re-used it for in a different context, but with a similar purpose (that is to represent an unknown code location).
I fixed the comments in the code so they now mention UNKNOWN_CODE_LOCATION
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then, I need help understanding the logic. Why does codeLocation == UNKNOWN_CODE_LOCATION
indicate coroutine suspension?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't. The code now looks like this:
// Ignore unknown code locations.
if (codeLocation == UNKNOWN_CODE_LOCATION) return Decision.Idle
From what I can see, there is no significant changes in the time of CI builds between this branch and The reason is that in this PR I strive to preserve the old behavior whenever possible, by adding special treatment of
Thus, all the code interacting with |
Signed-off-by: Evgeniy Moiseenko <[email protected]>
Signed-off-by: Evgeniy Moiseenko <[email protected]>
Signed-off-by: Evgeniy Moiseenko <[email protected]>
Signed-off-by: Evgeniy Moiseenko <[email protected]>
Signed-off-by: Evgeniy Moiseenko <[email protected]>
Signed-off-by: Evgeniy Moiseenko <[email protected]>
Signed-off-by: Evgeniy Moiseenko <[email protected]>
Signed-off-by: Evgeniy Moiseenko <[email protected]>
* do not switch to a thread awaiting thread join until the awaited thread finishes * print the awaited thread id in the thread switch trace point Signed-off-by: Evgeniy Moiseenko <[email protected]>
Signed-off-by: Evgeniy Moiseenko <[email protected]>
…tion Signed-off-by: Evgeniy Moiseenko <[email protected]>
No description provided.