@@ -7,10 +7,8 @@ import com.jetbrains.rd.util.lifetime.LifetimeDefinition
7
7
import com.jetbrains.rd.util.threading.SingleThreadScheduler
8
8
import com.jetbrains.rd.util.threading.SynchronousScheduler
9
9
import kotlinx.coroutines.delay
10
- import org.jacodb.api.jvm.JcClassOrInterface
11
10
import org.jacodb.api.jvm.JcClasspath
12
11
import org.jacodb.api.jvm.cfg.JcInst
13
- import org.jacodb.api.jvm.ext.methods
14
12
import org.usvm.instrumentation.generated.models.*
15
13
import org.usvm.instrumentation.rd.*
16
14
import org.usvm.instrumentation.util.findFieldByFullNameOrNull
@@ -22,7 +20,6 @@ import org.usvm.instrumentation.testcase.api.*
22
20
import org.usvm.instrumentation.testcase.descriptor.UTestExceptionDescriptor
23
21
import java.util.concurrent.CompletableFuture
24
22
import java.util.concurrent.TimeUnit
25
- import kotlin.math.pow
26
23
import kotlin.time.Duration
27
24
import kotlin.time.Duration.Companion.milliseconds
28
25
import kotlin.time.Duration.Companion.seconds
@@ -38,8 +35,7 @@ class RdProcessRunner(
38
35
private val serializationContext = SerializationContext (jcClasspath)
39
36
private val scheduler = SingleThreadScheduler (lifetime, " usvm-executor-scheduler" )
40
37
private val coroutineScope = UsvmRdCoroutineScope (lifetime, scheduler)
41
- private val deserializedInstructionsCache = HashMap <Long , JcInst >()
42
- private val deserializedClassesCache = HashMap <Long , JcClassOrInterface >()
38
+ private val traceDeserializer = TraceDeserializer (jcClasspath)
43
39
lateinit var rdProcess: RdServerProcess
44
40
45
41
@@ -186,25 +182,7 @@ class RdProcessRunner(
186
182
}
187
183
188
184
private fun deserializeTrace (trace : List <Long >, coveredClasses : List <ClassToId >): List <JcInst > =
189
- trace.map { encodedInst ->
190
- deserializedInstructionsCache.getOrPut(encodedInst) {
191
- val classIdOffset = (2.0 .pow(Byte .SIZE_BITS * 3 ).toLong() - 1 ) shl (Byte .SIZE_BITS * 5 - 1 )
192
- val classId = encodedInst and classIdOffset shr (Byte .SIZE_BITS * 5 )
193
- val methodIdOffset = (2.0 .pow(Byte .SIZE_BITS * 2 ).toLong() - 1 ) shl (Byte .SIZE_BITS * 3 - 1 )
194
- val methodId = encodedInst and methodIdOffset shr (Byte .SIZE_BITS * 3 )
195
- val instructionId = (encodedInst and (2.0 .pow(Byte .SIZE_BITS * 3 ).toLong() - 1 )).toInt()
196
- val jcClass =
197
- deserializedClassesCache.getOrPut(classId) {
198
- val className = coveredClasses.find { it.classId == classId }
199
- ? : error(" Deserialization error" )
200
- jcClasspath.findClassOrNull(className.className) ? : error(" Deserialization error" )
201
- }
202
- val jcMethod = jcClass.methods.sortedBy { it.description }[methodId.toInt()]
203
- jcMethod.instList
204
- .find { it.location.index == instructionId }
205
- ? : error(" Deserialization error" )
206
- }
207
- }
185
+ traceDeserializer.deserializeTrace(trace, coveredClasses)
208
186
209
187
fun destroy () {
210
188
lifetime.terminate()
0 commit comments