Skip to content

Use some time compensation for dynamic classes transformation #2551

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

Merged
merged 1 commit into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 12 additions & 5 deletions utbot-core/src/main/kotlin/org/utbot/common/StopWatch.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,19 @@ class StopWatch {
startTime = System.currentTimeMillis()
}
}

fun stop() {

/**
* @param compensationMillis the duration in millis that should be subtracted from [elapsedMillis] to compensate
* for stopping and restarting [StopWatch] taking some time, can also be used to compensate for some activities,
* that are hard to directly detect (e.g. class loading).
*
* NOTE: [compensationMillis] will never cause [elapsedMillis] become negative.
*/
fun stop(compensationMillis: Long = 0) {
lock.withLockInterruptibly {
startTime?.let {
elapsedMillis += (System.currentTimeMillis() - it)
startTime = null
startTime?.let { startTime ->
elapsedMillis += ((System.currentTimeMillis() - startTime) - compensationMillis).coerceAtLeast(0)
this.startTime = null
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ class DynamicClassTransformer : ClassFileTransformer {
classfileBuffer: ByteArray
): ByteArray? {
try {
UtContext.currentContext()?.stopWatch?.stop()
// since we got here we have loaded a new class, meaning program is not stuck and some "meaningful"
// non-repeating actions are performed, so we assume that we should not time out for then next 65 ms
UtContext.currentContext()?.stopWatch?.stop(compensationMillis = 65)
val pathToClassfile = protectionDomain.codeSource?.location?.toURI()?.let(Paths::get)?.absolutePathString()
return if (pathToClassfile in pathsToUserClasses ||
packsToAlwaysTransform.any(className::startsWith)
Expand Down