@@ -56,8 +56,7 @@ class ProcessedSerializedVarsState(
56
56
data class ProcessedDescriptorsState (
57
57
val processedSerializedVarsToJavaProperties : MutableMap <SerializedVariablesState , PropertiesData ?> = mutableMapOf(),
58
58
val processedSerializedVarsToKTProperties : MutableMap <SerializedVariablesState , KPropertiesData ?> = mutableMapOf(),
59
- val instancesPerState : MutableMap <SerializedVariablesState , Any ?> = mutableMapOf(),
60
- val parent : ProcessedDescriptorsState ? = null
59
+ val instancesPerState : MutableMap <SerializedVariablesState , Any ?> = mutableMapOf()
61
60
)
62
61
63
62
data class RuntimeObjectWrapper (
@@ -73,6 +72,7 @@ data class RuntimeObjectWrapper(
73
72
return objectInstance == = other
74
73
}
75
74
75
+ // TODO: it's not changing after recreation
76
76
override fun hashCode (): Int {
77
77
return if (isRecursive) Random .nextInt() else objectInstance?.hashCode() ? : 0
78
78
}
@@ -93,7 +93,7 @@ fun Any?.getToStringValue(isRecursive: Boolean = false): String {
93
93
}
94
94
95
95
fun Any?.getUniqueID (isRecursive : Boolean = false): String {
96
- return if (this != null ) {
96
+ return if (this != null && this !is Map . Entry < * , * > ) {
97
97
val hashCode = if (isRecursive) {
98
98
Random .nextLong()
99
99
} else {
@@ -197,8 +197,9 @@ class VariablesSerializer(
197
197
val isRecursive = stringedValue.contains(" : recursive structure" )
198
198
if (! isRecursive && simpleTypeName == " LinkedEntrySet" ) {
199
199
getProperEntrySetRepresentation(value)
200
- } else
201
- value.getUniqueID(isRecursive)
200
+ } else {
201
+ value.getUniqueID(isRecursive)
202
+ }
202
203
} else {
203
204
" "
204
205
}
@@ -285,12 +286,12 @@ class VariablesSerializer(
285
286
}
286
287
287
288
/* *
288
- * Map of Map of seen objects.
289
- * First Key: cellId
289
+ * Map of Map of seen objects related to a particular variable serialization
290
+ * First Key: topLevel variable Name
290
291
* Second Key: actual value
291
292
* Value: serialized VariableState
292
293
*/
293
- private val seenObjectsPerCell : MutableMap <Int , MutableMap <RuntimeObjectWrapper , SerializedVariablesState >> = mutableMapOf ()
294
+ private val seenObjectsPerVariable : MutableMap <String , MutableMap <RuntimeObjectWrapper , SerializedVariablesState >> = mutableMapOf ()
294
295
295
296
private var currentSerializeCount: Int = 0
296
297
@@ -355,18 +356,19 @@ class VariablesSerializer(
355
356
356
357
override suspend fun clearStateInfo (currentState : Int ) {
357
358
computedDescriptorsPerCell.remove(currentState)
358
- seenObjectsPerCell .remove(currentState)
359
+ // seenObjectsPerVariable .remove(currentState)
359
360
}
360
361
361
362
suspend fun tryValidateCache (currentCellId : Int , cellVariables : Map <Int , Set <String >>) {
362
363
if (! isShouldRemove(currentCellId)) return
363
364
clearOldData(currentCellId, cellVariables)
364
365
}
365
366
366
- fun serializeVariables (cellId : Int , variablesState : Map <String , VariableState >, variablesCells : Map <String , Int >, unchangedVariables : Set <String >): Map <String , SerializedVariablesState > {
367
+ fun serializeVariables (cellId : Int , variablesState : Map <String , VariableState >, oldDeclarations : Map < String , Int >, variablesCells : Map <String , Int >, unchangedVariables : Set <String >): Map <String , SerializedVariablesState > {
367
368
fun removeNonExistingEntries () {
368
369
val toRemoveSet = mutableSetOf<String >()
369
370
serializedVariablesCache.forEach { (name, _) ->
371
+ // seems like this never gonna happen
370
372
if (! variablesState.containsKey(name)) {
371
373
toRemoveSet.add(name)
372
374
}
@@ -376,9 +378,6 @@ class VariablesSerializer(
376
378
377
379
if (! isSerializationActive) return emptyMap()
378
380
379
- if (seenObjectsPerCell.containsKey(cellId)) {
380
- seenObjectsPerCell[cellId]!! .clear()
381
- }
382
381
if (variablesState.isEmpty()) {
383
382
return emptyMap()
384
383
}
@@ -388,21 +387,26 @@ class VariablesSerializer(
388
387
if (wasRedeclared) {
389
388
removedFromSightVariables.remove(it)
390
389
}
391
- // todo : might consider self-recursive elements always to recompute since it's non comparable via strings
390
+ // TODO : might consider self-recursive elements always to recompute since it's non comparable via strings
392
391
if (serializedVariablesCache.isEmpty()) {
393
392
true
394
- } else
395
- (! unchangedVariables.contains(it) || serializedVariablesCache[it]?.value != variablesState[it]?.stringValue) &&
396
- ! removedFromSightVariables.contains(it)
393
+ } else {
394
+ (! unchangedVariables.contains(it) || serializedVariablesCache[it]?.value != variablesState[it]?.stringValue) &&
395
+ ! removedFromSightVariables.contains(it)
396
+ }
397
397
}
398
398
log.debug(" Variables state as is: $variablesState " )
399
399
log.debug(" Serializing variables after filter: $neededEntries " )
400
400
log.debug(" Unchanged variables: ${unchangedVariables - neededEntries.keys} " )
401
401
402
402
// remove previous data
403
- // computedDescriptorsPerCell[cellId]?.instancesPerState?.clear()
404
403
val serializedData = neededEntries.mapValues {
405
404
val actualCell = variablesCells[it.key] ? : cellId
405
+ if (oldDeclarations.containsKey(it.key)) {
406
+ val oldCell = oldDeclarations[it.key]!!
407
+ computedDescriptorsPerCell[oldCell]?.remove(it.key)
408
+ seenObjectsPerVariable.remove(it.key)
409
+ }
406
410
serializeVariableState(actualCell, it.key, it.value)
407
411
}
408
412
@@ -467,10 +471,13 @@ class VariablesSerializer(
467
471
return doActualSerialization(cellId, topLevelName, processedData, wrapper, isRecursive, isOverride)
468
472
}
469
473
470
- private fun doActualSerialization (cellId : Int , topLevelName : String , processedData : ProcessedSerializedVarsState , value : RuntimeObjectWrapper , isRecursive : Boolean , isOverride : Boolean = true): SerializedVariablesState {
474
+ private fun doActualSerialization (cellId : Int , topLevelName : String , processedData : ProcessedSerializedVarsState , value : RuntimeObjectWrapper , isRecursive : Boolean , isOverride : Boolean = true): SerializedVariablesState {
475
+ fun checkIsNotStandardDescriptor (descriptor : MutableMap <String , SerializedVariablesState ?>): Boolean {
476
+ return descriptor.isNotEmpty() && ! descriptor.containsKey(" size" ) && ! descriptor.containsKey(" data" )
477
+ }
471
478
val serializedVersion = processedData.serializedVariablesState
472
479
473
- seenObjectsPerCell .putIfAbsent(cellId , mutableMapOf ())
480
+ seenObjectsPerVariable .putIfAbsent(topLevelName , mutableMapOf ())
474
481
computedDescriptorsPerCell.putIfAbsent(cellId, mutableMapOf ())
475
482
476
483
if (isOverride) {
@@ -482,17 +489,21 @@ class VariablesSerializer(
482
489
}
483
490
val currentCellDescriptors = computedDescriptorsPerCell[cellId]?.get(topLevelName)
484
491
// TODO should we stack?
492
+ // i guess, not
485
493
currentCellDescriptors!! .processedSerializedVarsToJavaProperties[serializedVersion] = processedData.propertiesData
486
494
currentCellDescriptors.processedSerializedVarsToKTProperties[serializedVersion] = processedData.kPropertiesData
487
495
488
496
if (value.objectInstance != null ) {
489
- seenObjectsPerCell[cellId ]!! .putIfAbsent(value, serializedVersion)
497
+ seenObjectsPerVariable[topLevelName ]!! .putIfAbsent(value, serializedVersion)
490
498
}
491
499
if (serializedVersion.isContainer) {
492
500
// check for seen
493
- if (seenObjectsPerCell[cellId ]!! .containsKey(value)) {
494
- val previouslySerializedState = seenObjectsPerCell[cellId ]!! [value] ? : return processedData.serializedVariablesState
501
+ if (seenObjectsPerVariable[topLevelName ]!! .containsKey(value)) {
502
+ val previouslySerializedState = seenObjectsPerVariable[topLevelName ]!! [value] ? : return processedData.serializedVariablesState
495
503
serializedVersion.fieldDescriptor + = previouslySerializedState.fieldDescriptor
504
+ if (checkIsNotStandardDescriptor(serializedVersion.fieldDescriptor)) {
505
+ return serializedVersion
506
+ }
496
507
}
497
508
val type = processedData.propertiesType
498
509
if (type == PropertiesType .KOTLIN ) {
@@ -535,8 +546,8 @@ class VariablesSerializer(
535
546
536
547
val serializedIteration = mutableMapOf<String , ProcessedSerializedVarsState >()
537
548
538
- seenObjectsPerCell .putIfAbsent(cellId , mutableMapOf ())
539
- val seenObjectsPerCell = seenObjectsPerCell[cellId ]
549
+ seenObjectsPerVariable .putIfAbsent(topLevelName , mutableMapOf ())
550
+ val seenObjectsPerCell = seenObjectsPerVariable[topLevelName ]
540
551
val currentCellDescriptors = computedDescriptorsPerCell[cellId]!! [topLevelName]!!
541
552
// ok, it's a copy on the left for some reason
542
553
val instancesPerState = currentCellDescriptors.instancesPerState
@@ -645,7 +656,7 @@ class VariablesSerializer(
645
656
getSimpleTypeNameFrom(elem, value.objectInstance) ? : " null"
646
657
}
647
658
serializedIteration[name] = if (standardContainersUtilizer.isStandardType(simpleType)) {
648
- // todo might add isRecursive
659
+ // TODO might add isRecursive
649
660
standardContainersUtilizer.serializeContainer(simpleType, value.objectInstance, true )
650
661
} else {
651
662
createSerializeVariableState(name, simpleType, value)
0 commit comments