IC: Load one class at a time when snapshotting classpath

Previously, when snapshotting the classpath with
`ClasspathEntrySnapshotTransform`, for each jar we load all classes
in memory at once. This was needed to detect inaccessible classes
(classes that don't impact incremental compilation and therefore
don't need to be snapshotted).

To reduce memory consumption, this commit updates the algorithm such
that we can now load one class at a time while still being able to
detect inaccessible classes.

In addition, we now read jar files with `java.util.zip.ZipFile` API
instead of `java.util.zip.ZipInputStream` to avoid current JDK bugs with
`ZipInputStream` (e.g., https://bugs.openjdk.org/browse/JDK-8298530).

^KT-57757 Fixed
^KT-57767 Fixed
This commit is contained in:
Hung Nguyen
2023-04-20 13:29:47 +01:00
committed by Space Team
parent 8afc8950e6
commit 37d6606852
5 changed files with 161 additions and 142 deletions
@@ -177,12 +177,8 @@ abstract class ClasspathSnapshotTestCommon {
fun ClassFile.snapshot(granularity: ClassSnapshotGranularity? = null): ClassSnapshot = listOf(this).snapshot(granularity).single()
fun List<ClassFile>.snapshot(granularity: ClassSnapshotGranularity? = null): List<ClassSnapshot> {
val classes = map { ClassFileWithContents(it, it.readBytes()) }
return if (granularity == null) {
ClassSnapshotter.snapshot(classes)
} else {
ClassSnapshotter.snapshot(classes, granularity = granularity)
}
val classes = map { ClassFileWithContentsProvider(it) { it.readBytes() } }
return ClassSnapshotter.snapshot(classes, granularity ?: ClassSnapshotGranularity.CLASS_MEMBER_LEVEL)
}
}
}