Skip to content

Commit

Permalink
Add minor performance improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrii-artuhov committed Dec 12, 2024
1 parent b0d83e0 commit 2fd1a05
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
8 changes: 0 additions & 8 deletions bootstrap/src/sun/nio/ch/lincheck/Injections.java
Original file line number Diff line number Diff line change
Expand Up @@ -319,14 +319,6 @@ public static void afterNewObjectCreation(Object obj) {
getEventTracker().afterNewObjectCreation(obj);
}

public static void updateSnapshotOnFieldAccess(Object obj, String className, String fieldName, int codeLocation) {
getEventTracker().updateSnapshotOnFieldAccess(obj, className, fieldName, codeLocation);
}

public static void updateSnapshotOnArrayElementAccess(Object array, int index, int codeLocation) {
getEventTracker().updateSnapshotOnArrayElementAccess(array, index, codeLocation);
}

/**
* Called from instrumented code before constructors' invocations,
* where passed objects are subtypes of the constructor class type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,6 @@ abstract class Strategy protected constructor(
override fun close() {
runner.close()
}

/**
* Restores recorded values of all memory reachable from static state.
*/
open fun restoreStaticMemorySnapshot() {}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ abstract class ManagedStrategy(
* or one this objects which contains it is already stored.
*/
fun updateSnapshotOnFieldAccess(obj: Any?, className: String, fieldName: String) = runInIgnoredSection {
staticMemorySnapshot.trackField(obj, Class.forName(className), fieldName)
staticMemorySnapshot.trackField(obj, className, fieldName)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,23 @@ class SnapshotTracker {

fun trackField(obj: Any?, accessClass: Class<*>, fieldName: String) {
if (obj != null && obj !in trackedObjects) return
trackFieldImpl(
obj = obj,
clazz = getDeclaringClass(obj, accessClass, fieldName),
fieldName = fieldName
)
}

fun trackField(obj: Any?, accessClassName: String, fieldName: String) {
if (obj != null && obj !in trackedObjects) return
trackFieldImpl(
obj = obj,
clazz = getDeclaringClass(obj, Class.forName(accessClassName), fieldName),
fieldName = fieldName
)
}

val clazz: Class<*> = getDeclaringClass(obj, accessClass, fieldName)
private fun trackFieldImpl(obj: Any?, clazz: Class<*>, fieldName: String) {
val field = clazz.findField(fieldName)
val readResult = readFieldSafely(obj, field)

Expand Down

0 comments on commit 2fd1a05

Please sign in to comment.