Skip to content

Commit

Permalink
Use some time compensation for dynamic classes transformation (#2551)
Browse files Browse the repository at this point in the history
Use some time compensation in dynamic classes transformation
  • Loading branch information
EgorkaKulikov authored Aug 24, 2023
1 parent 0587302 commit 4a75abc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
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

0 comments on commit 4a75abc

Please sign in to comment.