-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
The VM finalizes classes lazily when it needs them. When it decides to finalize a class it will call into the kernel loader to load all fields/functions/... of the (possibly top-level) class.
See runtime/vm/kernel_loader.cc:KernelLoader::FinishClassLoading:
void KernelLoader::FinishLoading(const Class& klass) {
...
KernelLoader kernel_loader(...);
...
This constructor will execute the code in runtime/vm/kernel_loader.cc:KernelLoader::KernelLoader:
KernelLoader::KernelLoader(...) {
...
const Array& scripts = Array::Handle(Z, kernel_program_info_.scripts());
patch_classes_ = Array::New(scripts.Length(), Heap::kOld);
...
}
Now very often the entire application is represented as one KernelProgramInfo
object.
The number of classes is always larger than the number of scripts / library since each script has it's own top-level class.
=> The complexity is O(#number-classes x #number-of-scripts)
=> For large number of libraries this can be very slow (finalization of each class can cause ~ 1MB allocation, causing very frequent GCs)