summaryrefslogtreecommitdiff
path: root/runtime/runtime.cc
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/runtime.cc')
-rw-r--r--runtime/runtime.cc29
1 files changed, 29 insertions, 0 deletions
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index 65ea77ad29..66ec7ccf7a 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -22,6 +22,8 @@
#include <linux/fs.h>
#endif
+#define ATRACE_TAG ATRACE_TAG_DALVIK
+#include <cutils/trace.h>
#include <signal.h>
#include <sys/syscall.h>
#include <valgrind.h>
@@ -400,6 +402,7 @@ void Runtime::SweepSystemWeaks(IsMarkedCallback* visitor, void* arg) {
GetInternTable()->SweepInternTableWeaks(visitor, arg);
GetMonitorList()->SweepMonitorList(visitor, arg);
GetJavaVM()->SweepJniWeakGlobals(visitor, arg);
+ GetHeap()->SweepAllocationRecords(visitor, arg);
}
bool Runtime::Create(const RuntimeOptions& options, bool ignore_unrecognized) {
@@ -492,8 +495,12 @@ bool Runtime::Start() {
ScopedObjectAccess soa(self);
gc::space::ImageSpace* image_space = heap_->GetImageSpace();
if (image_space != nullptr) {
+ ATRACE_BEGIN("AddImageStringsToTable");
GetInternTable()->AddImageStringsToTable(image_space);
+ ATRACE_END();
+ ATRACE_BEGIN("MoveImageClassesToClassTable");
GetClassLinker()->MoveImageClassesToClassTable();
+ ATRACE_END();
}
}
@@ -512,7 +519,9 @@ bool Runtime::Start() {
// InitNativeMethods needs to be after started_ so that the classes
// it touches will have methods linked to the oat file if necessary.
+ ATRACE_BEGIN("InitNativeMethods");
InitNativeMethods();
+ ATRACE_END();
// Initialize well known thread group values that may be accessed threads while attaching.
InitThreadGroups(self);
@@ -533,7 +542,9 @@ bool Runtime::Start() {
GetInstructionSetString(kRuntimeISA));
}
+ ATRACE_BEGIN("StartDaemonThreads");
StartDaemonThreads();
+ ATRACE_END();
{
ScopedObjectAccess soa(self);
@@ -635,6 +646,10 @@ void Runtime::DidForkFromZygote(JNIEnv* env, NativeBridgeAction action, const ch
// Create the thread pools.
heap_->CreateThreadPool();
+ // Reset the gc performance data at zygote fork so that the GCs
+ // before fork aren't attributed to an app.
+ heap_->ResetGcPerformanceInfo();
+
if (jit_.get() == nullptr && jit_options_->UseJIT()) {
// Create the JIT if the flag is set and we haven't already create it (happens for run-tests).
CreateJit();
@@ -763,6 +778,7 @@ static size_t OpenDexFiles(const std::vector<std::string>& dex_filenames,
}
bool Runtime::Init(const RuntimeOptions& raw_options, bool ignore_unrecognized) {
+ ATRACE_BEGIN("Runtime::Init");
CHECK_EQ(sysconf(_SC_PAGE_SIZE), kPageSize);
MemMap::Init();
@@ -773,6 +789,7 @@ bool Runtime::Init(const RuntimeOptions& raw_options, bool ignore_unrecognized)
ParsedOptions::Create(raw_options, ignore_unrecognized, &runtime_options));
if (parsed_options.get() == nullptr) {
LOG(ERROR) << "Failed to parse options";
+ ATRACE_END();
return false;
}
VLOG(startup) << "Runtime::Init -verbose:startup enabled";
@@ -826,6 +843,7 @@ bool Runtime::Init(const RuntimeOptions& raw_options, bool ignore_unrecognized)
zygote_max_failed_boots_ = runtime_options.GetOrDefault(Opt::ZygoteMaxFailedBoots);
XGcOption xgc_option = runtime_options.GetOrDefault(Opt::GcOption);
+ ATRACE_BEGIN("CreateHeap");
heap_ = new gc::Heap(runtime_options.GetOrDefault(Opt::MemoryInitialSize),
runtime_options.GetOrDefault(Opt::HeapGrowthLimit),
runtime_options.GetOrDefault(Opt::HeapMinFree),
@@ -855,9 +873,11 @@ bool Runtime::Init(const RuntimeOptions& raw_options, bool ignore_unrecognized)
xgc_option.verify_post_gc_rosalloc_,
runtime_options.GetOrDefault(Opt::EnableHSpaceCompactForOOM),
runtime_options.GetOrDefault(Opt::HSpaceCompactForOOMMinIntervalsMs));
+ ATRACE_END();
if (heap_->GetImageSpace() == nullptr && !allow_dex_file_fallback_) {
LOG(ERROR) << "Dex file fallback disabled, cannot continue without image.";
+ ATRACE_END();
return false;
}
@@ -957,7 +977,9 @@ bool Runtime::Init(const RuntimeOptions& raw_options, bool ignore_unrecognized)
CHECK_GE(GetHeap()->GetContinuousSpaces().size(), 1U);
class_linker_ = new ClassLinker(intern_table_);
if (GetHeap()->HasImageSpace()) {
+ ATRACE_BEGIN("InitFromImage");
class_linker_->InitFromImage();
+ ATRACE_END();
if (kIsDebugBuild) {
GetHeap()->GetImageSpace()->VerifyImageAllocations();
}
@@ -1090,6 +1112,8 @@ bool Runtime::Init(const RuntimeOptions& raw_options, bool ignore_unrecognized)
VLOG(startup) << "Runtime::Init exiting";
+ ATRACE_END();
+
return true;
}
@@ -1452,6 +1476,11 @@ void Runtime::DisallowNewSystemWeaks() {
monitor_list_->DisallowNewMonitors();
intern_table_->DisallowNewInterns();
java_vm_->DisallowNewWeakGlobals();
+ // TODO: add a similar call for heap.allocation_records_, otherwise some of the newly allocated
+ // objects that are not marked might be swept from the records, making the records incomplete.
+ // It is safe for now since the only effect is that those objects do not have allocation records.
+ // The number of such objects should be small, and current allocation tracker cannot collect
+ // allocation records for all objects anyway.
}
void Runtime::AllowNewSystemWeaks() {