Commit Graph

349 Commits

Author SHA1 Message Date
Hung Nguyen 08e6eb07c1 [New IC] Reduce memory usage of classpath snapshot cache
- Remove soft references that are too old.
 - Compute memory usage based on Runtime.totalMemory() instead of
   Runtime.maxMemory() as the latter is not reliable.
 - Remove debug logs that haven't proved to be useful.
 - Collect metrics on the number of cache hits (in addition to cache
   misses).

#KT-52329 In Progress

[New IC] Reduce memory usage of classpath snapshot cache

Use object interning for commonly shared objects. These include:
  - supertypes of classes
  - package names of classes

One experiment showed that with the above optimization, memory usage was
reduced from 660 MB down to 280 MB (+ 4 MB for the interning pool).

More aggressive object interning didn't reduce memory usage much
further, but would increase interning overhead and code complexity, so
we didn't do this to more objects.

Note that this commit optimizes the size of classpath snapshots in
memory, not their serialized data on disk. (I attempted the latter,
but the size was only reduced from 160 MB down to 130 MB, while the code
complexity became much higher as multiple interning pools would need to
be stored to disk and later loaded from disk, each per classpath entry
snapshot or shrunk classpath snapshot.)

#KT-52329 Fixed
2022-05-25 12:59:20 +03:00
Georgy Bronnikov ffe1615e9c Fir: simplify IrBuiltInsOverFir 2022-05-19 12:02:42 +02:00
Georgy Bronnikov e0c175bb50 Fir2Ir: remove symbolTable as separate component from FirResult
It's already in components.
2022-05-19 12:02:41 +02:00
Georgy Bronnikov 13d4d60afa Fir2Ir: pass Fir2IrExtensions to backend 2022-05-19 12:02:41 +02:00
nataliya.valtman dcdd1cd14e KT-49780 Do not clean outputs after cache corruption 2022-05-17 08:47:23 +00:00
Simon Ogorodnik 58885a1b07 KT-52217 Rename 'use-fir' to 'use-k2', update message 2022-04-28 15:42:42 +00:00
Hung Nguyen 9eb3c7ed76 [New IC] Optimize Java class snapshotting with ASM ClassWriter
To snapshot a Java class (+ its fields and methods), previously we used
Gson to serialize a class field/method to a string via reflection, and
hash that string.

We now use an ASM ClassWriter to write a placeholder class containing
the field/method of interest and hash the bytecode of that class.

One experiment showed that this new approach is ~10 times faster than
the previous approach (140s down to 16s when snapshotting 600 jars).

Test: Updated expectation files for JavaClassSnapshotterTest unit tests
      + Existing integration tests to prevent regression

^KT-52141 In Progress
2022-04-27 15:26:26 +00:00
Hung Nguyen 6d3e679a59 Implement cache eviction for classpath snapshot cache
Implement an in-memory cache that uses a combination of strong
references and `SoftReference`s so that it adapts to memory
availability.

Cache eviction is currently performed after loading a classpath snapshot
(this can be changed later if necessary).

Evicted cache entries' values will be converted from strong references
into `SoftReference`s so that they can still be used for as long as the
JVM allows them.

There are 2 types of cache eviction:
  - Least recently used: Oldest entries will be evicted
  - Memory usage limit: If memory is limited, all entries will be
    evicted

Test: Added InMemoryCacheWithEvictionTest unit test

^KT-51978 In Progress
2022-04-21 17:34:01 +00:00
Ilya Chernikov c4a29651b0 FIR IC: fix test with behavior different from non-tight cycle variants 2022-03-30 08:34:51 +00:00
Ilya Chernikov f2ddac3ece IC: Adopt IC compilation for case then runCompiler adds some dirty files
as it is the case for Fir IC compilation.
2022-03-30 08:34:44 +00:00
Ilya Chernikov 03cbfea737 FIR LT: Introduce source file abstraction, carry it from parsing to IR
along with source lines mapping, allows to "emulate" usage of the
PSI files which allows to extract source file and line mapping info
on every stage from source element.
It makes sense to use this mapping for the error reporting too.
2022-03-30 08:34:30 +00:00
Ilya Chernikov 973273c6c6 FIR CLI: count lines/files and report events to perfman 2022-03-30 08:33:11 +00:00
Ilya Chernikov f89765eb33 Make JDK classpath roots configuration explicit...
instead of relying on the "configuration files" parameter.
(in the process of migration from KotlinCoreEnvironment).
2022-03-30 08:32:56 +00:00
Ilya Chernikov 5abdf93d3b IC: Add IC test with fix on rename file with only class inside
"fails" on JS and JPS tests - the IC logic there is less precise.
2022-03-30 08:32:17 +00:00
Ilya Chernikov 3220900abe FIR: add tests for IC with LT and new CLI pipeline 2022-03-30 08:32:10 +00:00
Ilya Chernikov a239f02a30 Add cli argumens for FIR "tight" IC and LightTree usage 2022-03-30 08:32:03 +00:00
Ilya Chernikov 9e32188938 FIR LT: add syntax error reporting to LT2Fir
use it in the new pipeline
2022-03-30 08:31:56 +00:00
Ilya Chernikov 275135a1b2 FIR: extend cli pipeline with incremental compilation logic
use it in the IncrementalCompilationRunner
2022-03-30 08:31:10 +00:00
Hung Nguyen bd8f49c5d6 KT-45777: Count cache misses when loading classpath snapshot
to get more insights into the build performance of that step.

^KT-45777 In Progress
2022-03-29 11:36:41 +00:00
Hung Nguyen f23e66a6e2 KT-45777: Replace EmptyICReporter with DoNothingICReporter
to be more consistent (every *Reporter has a DoNothing*Reporter).

^KT-45777 In Progress
2022-03-29 11:36:41 +00:00
Hung Nguyen d70dbf3146 KT-45777: Add debug log messages for classpath snapshot feature
Also clean up classpath snapshot shrinking a bit to make it clearer.

^KT-45777 In Progress
2022-03-29 11:36:40 +00:00
nataliya.valtman c38dd1c004 Fix unstable testIncrementalCompilationAfterCacheHit test 2022-03-14 20:08:14 +03:00
Ilya Chernikov aa0386276d Fix FIR incremental compilation failure with inlines and lambdas
#KT-51546 fixed
2022-03-14 13:37:50 +03:00
Hung Nguyen 5f1cf34c79 KT-45777: Take coarse-grained snapshots of external libraries
to reduce the size of the snapshots.

- Track metrics for Gradle classpath snapshot artifact transform
- Format size metrics so it's more readable

^KT-45777 In Progress
2022-03-11 17:44:25 +01:00
Hung Nguyen aaef41cf64 KT-45777: Clean up handling around LookupSymbols and ProgramSymbols
Make it clearer and more efficient.

^KT-45777 In Progress
2022-03-07 19:05:09 +03:00
Hung Nguyen d2193f3873 KT-45777: Allow 2 levels of granularity when tracking changes
1. CLASS_LEVEL: allows tracking whether a .class file has changed
     without tracking what specific parts of the .class file (e.g.,
     fields or methods) have changed.

  2. CLASS_MEMBER_LEVEL: allows tracking not only whether a .class file
     has changed but also what specific parts of the .class file (e.g.,
     fields or methods) have changed.

 The idea is that for better performance we will use CLASS_LEVEL for
 classpath entries that are usually unchanged, and CLASS_MEMBER_LEVEL
 for classpath entries that are frequently changed. We'll work out the
 specifics in a following commit after some measurements.

Support running kotlinc on Windows in ClasspathSnapshotTestCommon
Also add tests for different Kotlin class kinds.
Add unit tests for CLASS_LEVEL snapshotting and diffing

Test: Updated ClasspathSnapshotterTest + ClasspathChangesComputerTest
Add ClasspathChangesComputerTest.testMixedClassSnapshotGranularities
2022-02-17 10:46:19 +03:00
Hung Nguyen 39b7c6e326 KT-34862: Clean up tests for incremental compilation after cache hit
Make sure that:
  - Compilation with -Pkotlin.incremental.useClasspathSnapshot=true or
    -Dkotlin.incremental.classpath.snapshot.enabled=true is incremental
    after cache hit.
  - Default compilation (using build history files) is non-incremental
    after cache hit.

Also unify the related tests into
BuildCacheRelocationIT.testKotlinIncrementalCompilation*. We don't need
corresponding tests in BuildCacheIT because BuildCacheRelocationIT
already covers it.
2022-02-15 14:05:58 +03:00
nataliya.valtman d4d5c701fe Make statistic more readable 2022-02-11 17:23:38 +03:00
Hung Nguyen d018031cbf KT-45777: Clean up build cache tests for incremental compilation
- Clean up BuildCacheRelocationIT.testKotlinIncrementalCompilation
 - Delete BuildCacheIT.testKotlinCompileIncrementalBuildWithoutRelocation
   as it is already covered by the test in BuildCacheRelocationIT
 - Add BuildCacheRelocationIT.testKotlinIncrementalCompilation_withClasspathSnapshot
- Updated BuildCacheRelocationIT.testKotlinIncrementalCompilation_withClasspathSnapshot
2022-02-08 18:07:38 +03:00
Hung Nguyen 1cb509d529 KT-45777: Remove proto-based approach to compute Java class snapshots
as the ASM-based approach is better, and we have switched to the
ASM-based approach for a while now.
2022-02-01 12:41:53 +03:00
Hung Nguyen 37c6b1c2dc KT-45777: Track build time in nanoseconds instead of milliseconds
to ensure precision (otherwise, rounding errors to milliseconds may
add up and cause unexplainable gaps in the running time).

We can still use milliseconds in the final report after all the precise
sub-build-times have been aggregated.
2022-01-31 19:50:03 +03:00
Nikita Bobko ca716fd226 Regenerate tests 2022-01-12 15:25:16 +01:00
Andrey Uskov 2adc851f1b Don't use global state for keeping incremental compilation state
Previously IC state was stored in System properties. As result parallel
compilation might cause incorrect state of IC, what led to corruption
of kotlin_module files. Now IC state is stored via CompilerArguments
and CompilerConfiguration
#KT-46038 Fixed
2022-01-12 13:37:46 +03:00
Hung Nguyen 78f10d9142 KT-45777: Keep only package facades whose members are looked up
to reduce the size of the shrunk classpath snapshot further.
2021-12-25 00:20:31 +03:00
Hung Nguyen 9b96dbe2d2 KT-45777: Parse classes only once with ASM
to get both constants and inline functions.

Also add BasicClassInfo to ClassFileWithContents to simplify the code.
2021-12-24 18:31:49 +03:00
Hung Nguyen 9a995af0df KT-44741: Improve handling of constants defined in companion objects 2021-12-24 18:31:49 +03:00
Hung Nguyen a900f2b66d KT-45777: Reorganize unit test data for classpath snapshot feature
to make it easier to add more tests in the next commits.

- Add unit tests for constants and inline functions

Also add tests for different kinds of Kotlin classes: CLASS,
FILE_FACADE, MULTIFILE_CLASS.

-Add unit test for nested classes

Also remove the existing integration test for nested classes to keep the
integration tests focused on the key scenarios while unit tests will
cover the corner cases.

Ignore inline functions that are private
2021-12-24 18:31:49 +03:00
Vyacheslav Gerasimov f7a9065b75 Build: Use intellij maven repo instead of downloaded IDEA
#KTI-82
2021-12-16 21:48:23 +03:00
Vyacheslav Gerasimov bc2f0936bd Build: Rename commonDep -> commonDependency 2021-12-16 21:48:19 +03:00
Hung Nguyen 586fa8af64 KT-45777: Shrink classpath snapshot incrementally
Currently, we shrink classpath snapshots at 2 steps:
  - Classpath diffing: Shrink the current classpath snapshot against
    the previous lookup symbols
  - Classpath snapshot saving: Shrink the current classpath snapshot
    against the current lookup symbols

With this commit, the shrinking at the second step is now incremental.
The shrinking at the first step is still non-incremental.
2021-12-14 13:10:08 +03:00
Dmitriy Novozhilov 8fcb525d75 [Test] Add ability to mute IC tests via fail.txt file
If fail.txt is present in root directory of test then exception from
  test will be muted. If there were no exceptions and fail.txt exists
  then test fail with suggestion to remove fail.txt

Content of fail.txt does not matter, so it can be used to store
  information about why this test doesn't pass
2021-12-03 14:17:41 +03:00
Anastasiya Shadrina d47cf315e7 [Metadata] Add context receivers to metadata.proto
[Tests] Add JvmVersionRequirementTest
2021-12-02 20:24:20 +03:00
Denis.Zharkov 6082f0b712 FIR2IR: Postpone binding overrides for lazy classes until sources processed 2021-12-01 08:32:20 +00:00
Hung Nguyen 6ba1b2cc08 KT-45777: Don't include classpath snapshot dir in task output backup
for performance reasons: (1) the snapshots are too big, and (2) they are
usually updated only at the end of the task execution--in a failed task
run, they are usually unchanged and therefore don't need to be restored.
2021-11-30 13:59:19 +03:00
Hung Nguyen 062a8fe56f KT-45777: Ignore Kotlin synthetic classes when computing classpath changes 2021-11-30 13:59:17 +03:00
Hung Nguyen 2b65d673bb KT-45777: Also collect added classes/class members as classpath changes
as they can impact recompilation (examples shown in the code comments).

Test: Updated ClasspathChangesComputerTest
2021-11-30 13:59:17 +03:00
Hung Nguyen 6bee7948e7 KT-45777: Don't compute snapshots for inaccessible classes
Also visit a class file with ASM once to extract all information we need
in advance, instead of visiting the class file each time some piece of
info is needed.
2021-11-30 13:59:14 +03:00
Hung Nguyen f52be5f471 KT-45777: Move classpath diffing to incremental Kotlin compiler (2/2)
as we need access to the lookup tracker to compute classpath changes
more efficiently and reduce the size of the saved classpath snapshot.

The previous commit only changed the files' paths, this
commit actually updates the files' contents.

Note that classpath snapshotting still happens in Gradle artifact
transforms. (However, the previous commit also moved the code for
classpath snapshotting together with the code for classpath diffing as
they are closely related.)
2021-11-30 13:59:13 +03:00
Hung Nguyen dfaf195e1d KT-45777: Move classpath diffing to incremental Kotlin compiler (1/2)
This commit only changes the files' paths, the next commit will update
the files' contents.

See the next commit for more context.
2021-11-30 13:59:12 +03:00
Ilya Chernikov f324a81de7 Implement (failing) test for FIR IC - as in KT-49750 2021-11-19 08:36:15 +01:00