Collect memory use for the JIT.
bug:27520994
Change-Id: I67b0c5b822001bfde8738a988c1ade69f1a26e3f
diff --git a/compiler/optimizing/optimizing_compiler.cc b/compiler/optimizing/optimizing_compiler.cc
index 7a82063..53bd38d 100644
--- a/compiler/optimizing/optimizing_compiler.cc
+++ b/compiler/optimizing/optimizing_compiler.cc
@@ -63,6 +63,7 @@
#include "instruction_simplifier_arm.h"
#include "intrinsics.h"
#include "jit/debugger_interface.h"
+#include "jit/jit.h"
#include "jit/jit_code_cache.h"
#include "jni/quick/jni_compiler.h"
#include "licm.h"
@@ -945,6 +946,8 @@
elf_file.size());
}
+ Runtime::Current()->GetJit()->AddMemoryUsage(method, arena.BytesUsed());
+
return true;
}
diff --git a/runtime/base/histogram-inl.h b/runtime/base/histogram-inl.h
index 03980e3..c7a0ba2 100644
--- a/runtime/base/histogram-inl.h
+++ b/runtime/base/histogram-inl.h
@@ -26,6 +26,7 @@
#include "base/bit_utils.h"
#include "base/time_utils.h"
+#include "utils.h"
namespace art {
@@ -200,6 +201,13 @@
}
template <class Value>
+inline void Histogram<Value>::PrintMemoryUse(std::ostream &os) const {
+ os << Name()
+ << ": Avg: " << PrettySize(Mean()) << " Max: "
+ << PrettySize(Max()) << " Min: " << PrettySize(Min()) << "\n";
+}
+
+template <class Value>
inline void Histogram<Value>::CreateHistogram(CumulativeData* out_data) const {
DCHECK_GT(sample_size_, 0ull);
out_data->freq_.clear();
diff --git a/runtime/base/histogram.h b/runtime/base/histogram.h
index ef3a5d7..bcb7b3b 100644
--- a/runtime/base/histogram.h
+++ b/runtime/base/histogram.h
@@ -59,6 +59,7 @@
double Percentile(double per, const CumulativeData& data) const;
void PrintConfidenceIntervals(std::ostream& os, double interval,
const CumulativeData& data) const;
+ void PrintMemoryUse(std::ostream& os) const;
void PrintBins(std::ostream& os, const CumulativeData& data) const;
void DumpBins(std::ostream& os) const;
Value GetRange(size_t bucket_idx) const;
diff --git a/runtime/jit/jit.cc b/runtime/jit/jit.cc
index 5bd9a6b..7e73e5c 100644
--- a/runtime/jit/jit.cc
+++ b/runtime/jit/jit.cc
@@ -83,6 +83,8 @@
void Jit::DumpInfo(std::ostream& os) {
code_cache_->Dump(os);
cumulative_timings_.Dump(os);
+ MutexLock mu(Thread::Current(), lock_);
+ memory_use_.PrintMemoryUse(os);
}
void Jit::AddTimingLogger(const TimingLogger& logger) {
@@ -95,6 +97,8 @@
jit_compile_method_(nullptr),
dump_info_on_shutdown_(false),
cumulative_timings_("JIT timings"),
+ memory_use_("Memory used for compilation", 16),
+ lock_("JIT memory use lock"),
save_profiling_info_(false),
generate_debug_info_(false) {
}
@@ -433,5 +437,16 @@
return true;
}
+void Jit::AddMemoryUsage(ArtMethod* method, size_t bytes) {
+ if (bytes > 4 * MB) {
+ LOG(INFO) << "Compiler allocated "
+ << PrettySize(bytes)
+ << " to compile "
+ << PrettyMethod(method);
+ }
+ MutexLock mu(Thread::Current(), lock_);
+ memory_use_.AddValue(bytes);
+}
+
} // namespace jit
} // namespace art
diff --git a/runtime/jit/jit.h b/runtime/jit/jit.h
index d5c2134..37d0bdb 100644
--- a/runtime/jit/jit.h
+++ b/runtime/jit/jit.h
@@ -17,14 +17,11 @@
#ifndef ART_RUNTIME_JIT_JIT_H_
#define ART_RUNTIME_JIT_JIT_H_
-#include <unordered_map>
-
-#include "atomic.h"
+#include "base/arena_allocator.h"
+#include "base/histogram-inl.h"
#include "base/macros.h"
#include "base/mutex.h"
#include "base/timing_logger.h"
-#include "gc_root.h"
-#include "jni.h"
#include "object_callbacks.h"
#include "offline_profiling_info.h"
#include "thread_pool.h"
@@ -62,9 +59,14 @@
void DeleteThreadPool();
// Dump interesting info: #methods compiled, code vs data size, compile / verify cumulative
// loggers.
- void DumpInfo(std::ostream& os);
+ void DumpInfo(std::ostream& os) REQUIRES(!lock_);
// Add a timing logger to cumulative_timings_.
void AddTimingLogger(const TimingLogger& logger);
+
+ void AddMemoryUsage(ArtMethod* method, size_t bytes)
+ REQUIRES(!lock_)
+ SHARED_REQUIRES(Locks::mutator_lock_);
+
JitInstrumentationCache* GetInstrumentationCache() const {
return instrumentation_cache_.get();
}
@@ -82,7 +84,7 @@
const std::string& app_dir);
void StopProfileSaver();
- void DumpForSigQuit(std::ostream& os) {
+ void DumpForSigQuit(std::ostream& os) REQUIRES(!lock_) {
DumpInfo(os);
}
@@ -125,6 +127,8 @@
// Performance monitoring.
bool dump_info_on_shutdown_;
CumulativeLogger cumulative_timings_;
+ Histogram<uint64_t> memory_use_ GUARDED_BY(lock_);
+ Mutex lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
std::unique_ptr<jit::JitInstrumentationCache> instrumentation_cache_;
std::unique_ptr<jit::JitCodeCache> code_cache_;