Merge "Polish the lock contention logging." into dalvik-dev
diff --git a/build/Android.gtest.mk b/build/Android.gtest.mk
index ac3b821..498f7ef 100644
--- a/build/Android.gtest.mk
+++ b/build/Android.gtest.mk
@@ -25,6 +25,7 @@
runtime/barrier_test.cc \
runtime/base/histogram_test.cc \
runtime/base/mutex_test.cc \
+ runtime/base/timing_logger_test.cc \
runtime/base/unix_file/fd_file_test.cc \
runtime/base/unix_file/mapped_file_test.cc \
runtime/base/unix_file/null_file_test.cc \
diff --git a/compiler/dex/quick/codegen_util.cc b/compiler/dex/quick/codegen_util.cc
index c9780fa..5f6f3d5 100644
--- a/compiler/dex/quick/codegen_util.cc
+++ b/compiler/dex/quick/codegen_util.cc
@@ -17,6 +17,7 @@
#include "dex/compiler_internals.h"
#include "dex_file-inl.h"
#include "gc_map.h"
+#include "mapping_table.h"
#include "mir_to_lir-inl.h"
#include "verifier/dex_gc_map.h"
#include "verifier/method_verifier.h"
@@ -515,15 +516,35 @@
}
}
if (kIsDebugBuild) {
- DCHECK(VerifyCatchEntries());
+ CHECK(VerifyCatchEntries());
}
- combined_mapping_table_.push_back(pc2dex_mapping_table_.size() +
- dex2pc_mapping_table_.size());
- combined_mapping_table_.push_back(pc2dex_mapping_table_.size());
- combined_mapping_table_.insert(combined_mapping_table_.end(), pc2dex_mapping_table_.begin(),
- pc2dex_mapping_table_.end());
- combined_mapping_table_.insert(combined_mapping_table_.end(), dex2pc_mapping_table_.begin(),
- dex2pc_mapping_table_.end());
+ CHECK_EQ(pc2dex_mapping_table_.size() & 1, 0U);
+ CHECK_EQ(dex2pc_mapping_table_.size() & 1, 0U);
+ uint32_t total_entries = (pc2dex_mapping_table_.size() + dex2pc_mapping_table_.size()) / 2;
+ uint32_t pc2dex_entries = pc2dex_mapping_table_.size() / 2;
+ encoded_mapping_table_.PushBack(total_entries);
+ encoded_mapping_table_.PushBack(pc2dex_entries);
+ encoded_mapping_table_.InsertBack(pc2dex_mapping_table_.begin(), pc2dex_mapping_table_.end());
+ encoded_mapping_table_.InsertBack(dex2pc_mapping_table_.begin(), dex2pc_mapping_table_.end());
+ if (kIsDebugBuild) {
+ // Verify the encoded table holds the expected data.
+ MappingTable table(&encoded_mapping_table_.GetData()[0]);
+ CHECK_EQ(table.TotalSize(), total_entries);
+ CHECK_EQ(table.PcToDexSize(), pc2dex_entries);
+ CHECK_EQ(table.DexToPcSize(), dex2pc_mapping_table_.size() / 2);
+ MappingTable::PcToDexIterator it = table.PcToDexBegin();
+ for (uint32_t i = 0; i < pc2dex_mapping_table_.size(); ++i, ++it) {
+ CHECK_EQ(pc2dex_mapping_table_.at(i), it.NativePcOffset());
+ ++i;
+ CHECK_EQ(pc2dex_mapping_table_.at(i), it.DexPc());
+ }
+ MappingTable::DexToPcIterator it2 = table.DexToPcBegin();
+ for (uint32_t i = 0; i < dex2pc_mapping_table_.size(); ++i, ++it2) {
+ CHECK_EQ(dex2pc_mapping_table_.at(i), it2.NativePcOffset());
+ ++i;
+ CHECK_EQ(dex2pc_mapping_table_.at(i), it2.DexPc());
+ }
+ }
}
class NativePcToReferenceMapBuilder {
@@ -980,28 +1001,35 @@
CompiledMethod* Mir2Lir::GetCompiledMethod() {
// Combine vmap tables - core regs, then fp regs - into vmap_table
- std::vector<uint16_t> vmap_table;
+ std::vector<uint16_t> raw_vmap_table;
// Core regs may have been inserted out of order - sort first
std::sort(core_vmap_table_.begin(), core_vmap_table_.end());
for (size_t i = 0 ; i < core_vmap_table_.size(); i++) {
// Copy, stripping out the phys register sort key
- vmap_table.push_back(~(-1 << VREG_NUM_WIDTH) & core_vmap_table_[i]);
+ raw_vmap_table.push_back(~(-1 << VREG_NUM_WIDTH) & core_vmap_table_[i]);
}
// If we have a frame, push a marker to take place of lr
if (frame_size_ > 0) {
- vmap_table.push_back(INVALID_VREG);
+ raw_vmap_table.push_back(INVALID_VREG);
} else {
DCHECK_EQ(__builtin_popcount(core_spill_mask_), 0);
DCHECK_EQ(__builtin_popcount(fp_spill_mask_), 0);
}
// Combine vmap tables - core regs, then fp regs. fp regs already sorted
for (uint32_t i = 0; i < fp_vmap_table_.size(); i++) {
- vmap_table.push_back(fp_vmap_table_[i]);
+ raw_vmap_table.push_back(fp_vmap_table_[i]);
+ }
+ UnsignedLeb128EncodingVector vmap_encoder;
+ // Prefix the encoded data with its size.
+ vmap_encoder.PushBack(raw_vmap_table.size());
+ typedef std::vector<uint16_t>::const_iterator It;
+ for (It cur = raw_vmap_table.begin(), end = raw_vmap_table.end(); cur != end; ++cur) {
+ vmap_encoder.PushBack(*cur);
}
CompiledMethod* result =
new CompiledMethod(cu_->instruction_set, code_buffer_,
frame_size_, core_spill_mask_, fp_spill_mask_,
- combined_mapping_table_, vmap_table, native_gc_map_);
+ encoded_mapping_table_.GetData(), vmap_encoder.GetData(), native_gc_map_);
return result;
}
diff --git a/compiler/dex/quick/mir_to_lir.h b/compiler/dex/quick/mir_to_lir.h
index 2794bf5..517fc66 100644
--- a/compiler/dex/quick/mir_to_lir.h
+++ b/compiler/dex/quick/mir_to_lir.h
@@ -25,6 +25,7 @@
#include "dex/growable_array.h"
#include "dex/arena_allocator.h"
#include "driver/compiler_driver.h"
+#include "leb128_encoder.h"
#include "safe_map.h"
namespace art {
@@ -760,7 +761,8 @@
*/
int live_sreg_;
CodeBuffer code_buffer_;
- std::vector<uint32_t> combined_mapping_table_;
+ // The encoding mapping table data (dex -> pc offset and pc offset -> dex) with a size prefix.
+ UnsignedLeb128EncodingVector encoded_mapping_table_;
std::vector<uint32_t> core_vmap_table_;
std::vector<uint32_t> fp_vmap_table_;
std::vector<uint8_t> native_gc_map_;
diff --git a/compiler/image_writer.cc b/compiler/image_writer.cc
index 550d642..3432c8c 100644
--- a/compiler/image_writer.cc
+++ b/compiler/image_writer.cc
@@ -547,11 +547,11 @@
// Normal (non-abstract non-native) methods have various tables to relocate.
uint32_t mapping_table_off = orig->GetOatMappingTableOffset();
const byte* mapping_table = GetOatAddress(mapping_table_off);
- copy->SetMappingTable(reinterpret_cast<const uint32_t*>(mapping_table));
+ copy->SetMappingTable(mapping_table);
uint32_t vmap_table_offset = orig->GetOatVmapTableOffset();
const byte* vmap_table = GetOatAddress(vmap_table_offset);
- copy->SetVmapTable(reinterpret_cast<const uint16_t*>(vmap_table));
+ copy->SetVmapTable(vmap_table);
uint32_t native_gc_map_offset = orig->GetOatNativeGcMapOffset();
const byte* native_gc_map = GetOatAddress(native_gc_map_offset);
diff --git a/compiler/leb128_encoder.h b/compiler/leb128_encoder.h
new file mode 100644
index 0000000..e9a1c32
--- /dev/null
+++ b/compiler/leb128_encoder.h
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ART_COMPILER_LEB128_ENCODER_H_
+#define ART_COMPILER_LEB128_ENCODER_H_
+
+#include "base/macros.h"
+
+namespace art {
+
+// An encoder with an API similar to vector<uint32_t> where the data is captured in ULEB128 format.
+class UnsignedLeb128EncodingVector {
+ public:
+ UnsignedLeb128EncodingVector() {
+ }
+
+ void PushBack(uint32_t value) {
+ bool done = false;
+ do {
+ uint8_t out = value & 0x7f;
+ if (out != value) {
+ data_.push_back(out | 0x80);
+ value >>= 7;
+ } else {
+ data_.push_back(out);
+ done = true;
+ }
+ } while (!done);
+ }
+
+ template<typename It>
+ void InsertBack(It cur, It end) {
+ for (; cur != end; ++cur) {
+ PushBack(*cur);
+ }
+ }
+
+ const std::vector<uint8_t>& GetData() const {
+ return data_;
+ }
+
+ private:
+ std::vector<uint8_t> data_;
+
+ DISALLOW_COPY_AND_ASSIGN(UnsignedLeb128EncodingVector);
+};
+
+} // namespace art
+
+#endif // ART_COMPILER_LEB128_ENCODER_H_
diff --git a/compiler/oat_writer.cc b/compiler/oat_writer.cc
index 21c5317..ce88cf6 100644
--- a/compiler/oat_writer.cc
+++ b/compiler/oat_writer.cc
@@ -322,12 +322,12 @@
core_spill_mask = compiled_method->GetCoreSpillMask();
fp_spill_mask = compiled_method->GetFpSpillMask();
- const std::vector<uint32_t>& mapping_table = compiled_method->GetMappingTable();
+ const std::vector<uint8_t>& mapping_table = compiled_method->GetMappingTable();
size_t mapping_table_size = mapping_table.size() * sizeof(mapping_table[0]);
mapping_table_offset = (mapping_table_size == 0) ? 0 : offset;
// Deduplicate mapping tables
- SafeMap<const std::vector<uint32_t>*, uint32_t>::iterator mapping_iter =
+ SafeMap<const std::vector<uint8_t>*, uint32_t>::iterator mapping_iter =
mapping_table_offsets_.find(&mapping_table);
if (mapping_iter != mapping_table_offsets_.end()) {
mapping_table_offset = mapping_iter->second;
@@ -337,12 +337,12 @@
oat_header_->UpdateChecksum(&mapping_table[0], mapping_table_size);
}
- const std::vector<uint16_t>& vmap_table = compiled_method->GetVmapTable();
+ const std::vector<uint8_t>& vmap_table = compiled_method->GetVmapTable();
size_t vmap_table_size = vmap_table.size() * sizeof(vmap_table[0]);
vmap_table_offset = (vmap_table_size == 0) ? 0 : offset;
// Deduplicate vmap tables
- SafeMap<const std::vector<uint16_t>*, uint32_t>::iterator vmap_iter =
+ SafeMap<const std::vector<uint8_t>*, uint32_t>::iterator vmap_iter =
vmap_table_offsets_.find(&vmap_table);
if (vmap_iter != vmap_table_offsets_.end()) {
vmap_table_offset = vmap_iter->second;
@@ -717,11 +717,11 @@
DCHECK_OFFSET();
#endif
- const std::vector<uint32_t>& mapping_table = compiled_method->GetMappingTable();
+ const std::vector<uint8_t>& mapping_table = compiled_method->GetMappingTable();
size_t mapping_table_size = mapping_table.size() * sizeof(mapping_table[0]);
// Deduplicate mapping tables
- SafeMap<const std::vector<uint32_t>*, uint32_t>::iterator mapping_iter =
+ SafeMap<const std::vector<uint8_t>*, uint32_t>::iterator mapping_iter =
mapping_table_offsets_.find(&mapping_table);
if (mapping_iter != mapping_table_offsets_.end() &&
relative_offset != method_offsets.mapping_table_offset_) {
@@ -741,11 +741,11 @@
}
DCHECK_OFFSET();
- const std::vector<uint16_t>& vmap_table = compiled_method->GetVmapTable();
+ const std::vector<uint8_t>& vmap_table = compiled_method->GetVmapTable();
size_t vmap_table_size = vmap_table.size() * sizeof(vmap_table[0]);
// Deduplicate vmap tables
- SafeMap<const std::vector<uint16_t>*, uint32_t>::iterator vmap_iter =
+ SafeMap<const std::vector<uint8_t>*, uint32_t>::iterator vmap_iter =
vmap_table_offsets_.find(&vmap_table);
if (vmap_iter != vmap_table_offsets_.end() &&
relative_offset != method_offsets.vmap_table_offset_) {
diff --git a/compiler/oat_writer.h b/compiler/oat_writer.h
index e6cc0bc..f7801f5 100644
--- a/compiler/oat_writer.h
+++ b/compiler/oat_writer.h
@@ -226,8 +226,8 @@
// code mappings for deduplication
SafeMap<const std::vector<uint8_t>*, uint32_t, MapCompare<std::vector<uint8_t> > > code_offsets_;
- SafeMap<const std::vector<uint16_t>*, uint32_t, MapCompare<std::vector<uint16_t> > > vmap_table_offsets_;
- SafeMap<const std::vector<uint32_t>*, uint32_t, MapCompare<std::vector<uint32_t> > > mapping_table_offsets_;
+ SafeMap<const std::vector<uint8_t>*, uint32_t, MapCompare<std::vector<uint8_t> > > vmap_table_offsets_;
+ SafeMap<const std::vector<uint8_t>*, uint32_t, MapCompare<std::vector<uint8_t> > > mapping_table_offsets_;
SafeMap<const std::vector<uint8_t>*, uint32_t, MapCompare<std::vector<uint8_t> > > gc_map_offsets_;
DISALLOW_COPY_AND_ASSIGN(OatWriter);
diff --git a/oatdump/oatdump.cc b/oatdump/oatdump.cc
index 0a34686..a717f19 100644
--- a/oatdump/oatdump.cc
+++ b/oatdump/oatdump.cc
@@ -35,6 +35,7 @@
#include "gc/space/space-inl.h"
#include "image.h"
#include "indenter.h"
+#include "mapping_table.h"
#include "mirror/abstract_method-inl.h"
#include "mirror/array-inl.h"
#include "mirror/class-inl.h"
@@ -48,6 +49,7 @@
#include "safe_map.h"
#include "scoped_thread_state_change.h"
#include "verifier/method_verifier.h"
+#include "vmap_table.h"
namespace art {
@@ -390,40 +392,39 @@
}
void DumpVmap(std::ostream& os, const OatFile::OatMethod& oat_method) {
- const uint16_t* raw_table = oat_method.GetVmapTable();
- if (raw_table == NULL) {
- return;
- }
- const VmapTable vmap_table(raw_table);
- bool first = true;
- bool processing_fp = false;
- uint32_t spill_mask = oat_method.GetCoreSpillMask();
- for (size_t i = 0; i < vmap_table.size(); i++) {
- uint16_t dex_reg = vmap_table[i];
- uint32_t cpu_reg = vmap_table.ComputeRegister(spill_mask, i,
- processing_fp ? kFloatVReg : kIntVReg);
- os << (first ? "v" : ", v") << dex_reg;
- if (!processing_fp) {
- os << "/r" << cpu_reg;
- } else {
- os << "/fr" << cpu_reg;
+ const uint8_t* raw_table = oat_method.GetVmapTable();
+ if (raw_table != NULL) {
+ const VmapTable vmap_table(raw_table);
+ bool first = true;
+ bool processing_fp = false;
+ uint32_t spill_mask = oat_method.GetCoreSpillMask();
+ for (size_t i = 0; i < vmap_table.Size(); i++) {
+ uint16_t dex_reg = vmap_table[i];
+ uint32_t cpu_reg = vmap_table.ComputeRegister(spill_mask, i,
+ processing_fp ? kFloatVReg : kIntVReg);
+ os << (first ? "v" : ", v") << dex_reg;
+ if (!processing_fp) {
+ os << "/r" << cpu_reg;
+ } else {
+ os << "/fr" << cpu_reg;
+ }
+ first = false;
+ if (!processing_fp && dex_reg == 0xFFFF) {
+ processing_fp = true;
+ spill_mask = oat_method.GetFpSpillMask();
+ }
}
- first = false;
- if (!processing_fp && dex_reg == 0xFFFF) {
- processing_fp = true;
- spill_mask = oat_method.GetFpSpillMask();
- }
+ os << "\n";
}
- os << "\n";
}
void DescribeVReg(std::ostream& os, const OatFile::OatMethod& oat_method,
const DexFile::CodeItem* code_item, size_t reg, VRegKind kind) {
- const uint16_t* raw_table = oat_method.GetVmapTable();
+ const uint8_t* raw_table = oat_method.GetVmapTable();
if (raw_table != NULL) {
const VmapTable vmap_table(raw_table);
uint32_t vmap_offset;
- if (vmap_table.IsInContext(reg, vmap_offset, kind)) {
+ if (vmap_table.IsInContext(reg, kind, &vmap_offset)) {
bool is_float = (kind == kFloatVReg) || (kind == kDoubleLoVReg) || (kind == kDoubleHiVReg);
uint32_t spill_mask = is_float ? oat_method.GetFpSpillMask()
: oat_method.GetCoreSpillMask();
@@ -471,67 +472,50 @@
}
void DumpMappingTable(std::ostream& os, const OatFile::OatMethod& oat_method) {
- const uint32_t* raw_table = oat_method.GetMappingTable();
const void* code = oat_method.GetCode();
- if (raw_table == NULL || code == NULL) {
+ if (code == NULL) {
return;
}
-
- ++raw_table;
- uint32_t length = *raw_table;
- ++raw_table;
- if (length == 0) {
- return;
- }
- uint32_t pc_to_dex_entries = *raw_table;
- ++raw_table;
- if (pc_to_dex_entries != 0) {
- os << "suspend point mappings {\n";
- } else {
- os << "catch entry mappings {\n";
- }
- Indenter indent_filter(os.rdbuf(), kIndentChar, kIndentBy1Count);
- std::ostream indent_os(&indent_filter);
- for (size_t i = 0; i < length; i += 2) {
- const uint8_t* native_pc = reinterpret_cast<const uint8_t*>(code) + raw_table[i];
- uint32_t dex_pc = raw_table[i + 1];
- indent_os << StringPrintf("%p -> 0x%04x\n", native_pc, dex_pc);
- if (i + 2 == pc_to_dex_entries && pc_to_dex_entries != length) {
- // Separate the pc -> dex from dex -> pc sections
- indent_os << std::flush;
- os << "}\ncatch entry mappings {\n";
+ MappingTable table(oat_method.GetMappingTable());
+ if (table.TotalSize() != 0) {
+ Indenter indent_filter(os.rdbuf(), kIndentChar, kIndentBy1Count);
+ std::ostream indent_os(&indent_filter);
+ if (table.PcToDexSize() != 0) {
+ typedef MappingTable::PcToDexIterator It;
+ os << "suspend point mappings {\n";
+ for (It cur = table.PcToDexBegin(), end = table.PcToDexEnd(); cur != end; ++cur) {
+ indent_os << StringPrintf("0x%04x -> 0x%04x\n", cur.NativePcOffset(), cur.DexPc());
+ }
+ os << "}\n";
+ }
+ if (table.DexToPcSize() != 0) {
+ typedef MappingTable::DexToPcIterator It;
+ os << "catch entry mappings {\n";
+ for (It cur = table.DexToPcBegin(), end = table.DexToPcEnd(); cur != end; ++cur) {
+ indent_os << StringPrintf("0x%04x -> 0x%04x\n", cur.NativePcOffset(), cur.DexPc());
+ }
+ os << "}\n";
}
}
- os << "}\n";
}
- uint32_t DumpMappingAtOffset(std::ostream& os, const OatFile::OatMethod& oat_method, size_t offset,
- bool suspend_point_mapping) {
- const uint32_t* raw_table = oat_method.GetMappingTable();
- if (raw_table != NULL) {
- ++raw_table;
- uint32_t length = *raw_table;
- ++raw_table;
- uint32_t pc_to_dex_entries = *raw_table;
- ++raw_table;
- size_t start, end;
- if (suspend_point_mapping) {
- start = 0;
- end = pc_to_dex_entries;
- } else {
- start = pc_to_dex_entries;
- end = length;
+ uint32_t DumpMappingAtOffset(std::ostream& os, const OatFile::OatMethod& oat_method,
+ size_t offset, bool suspend_point_mapping) {
+ MappingTable table(oat_method.GetMappingTable());
+ if (suspend_point_mapping && table.PcToDexSize() > 0) {
+ typedef MappingTable::PcToDexIterator It;
+ for (It cur = table.PcToDexBegin(), end = table.PcToDexEnd(); cur != end; ++cur) {
+ if (offset == cur.NativePcOffset()) {
+ os << "suspend point dex PC: 0x" << cur.DexPc() << "\n";
+ return cur.DexPc();
+ }
}
- for (size_t i = start; i < end; i += 2) {
- if (offset == raw_table[i]) {
- uint32_t dex_pc = raw_table[i + 1];
- if (suspend_point_mapping) {
- os << "suspend point dex PC: 0x";
- } else {
- os << "catch entry dex PC: 0x";
- }
- os << std::hex << dex_pc << std::dec << "\n";
- return dex_pc;
+ } else if (!suspend_point_mapping && table.DexToPcSize() > 0) {
+ typedef MappingTable::DexToPcIterator It;
+ for (It cur = table.DexToPcBegin(), end = table.DexToPcEnd(); cur != end; ++cur) {
+ if (offset == cur.NativePcOffset()) {
+ os << "catch entry dex PC: 0x" << cur.DexPc() << "\n";
+ return cur.DexPc();
}
}
}
@@ -1019,13 +1003,13 @@
}
size_t pc_mapping_table_bytes =
- state->ComputeOatSize(method->GetMappingTableRaw(), &first_occurrence);
+ state->ComputeOatSize(method->GetMappingTable(), &first_occurrence);
if (first_occurrence) {
state->stats_.pc_mapping_table_bytes += pc_mapping_table_bytes;
}
size_t vmap_table_bytes =
- state->ComputeOatSize(method->GetVmapTableRaw(), &first_occurrence);
+ state->ComputeOatSize(method->GetVmapTable(), &first_occurrence);
if (first_occurrence) {
state->stats_.vmap_table_bytes += vmap_table_bytes;
}
diff --git a/runtime/base/macros.h b/runtime/base/macros.h
index 879c10c..6531858 100644
--- a/runtime/base/macros.h
+++ b/runtime/base/macros.h
@@ -142,6 +142,8 @@
#define HOT_ATTR __attribute__ ((hot))
#endif
+#define PURE __attribute__ ((__pure__))
+
// bionic and glibc both have TEMP_FAILURE_RETRY, but Mac OS' libc doesn't.
#ifndef TEMP_FAILURE_RETRY
#define TEMP_FAILURE_RETRY(exp) ({ \
diff --git a/runtime/base/timing_logger.cc b/runtime/base/timing_logger.cc
index b58b0ac..78a6883 100644
--- a/runtime/base/timing_logger.cc
+++ b/runtime/base/timing_logger.cc
@@ -39,7 +39,7 @@
}
CumulativeLogger::~CumulativeLogger() {
- STLDeleteElements(&histograms_);
+ STLDeleteValues(&histograms_);
}
void CumulativeLogger::SetName(const std::string& name) {
@@ -47,18 +47,17 @@
}
void CumulativeLogger::Start() {
- MutexLock mu(Thread::Current(), lock_);
- index_ = 0;
}
void CumulativeLogger::End() {
MutexLock mu(Thread::Current(), lock_);
iterations_++;
}
+
void CumulativeLogger::Reset() {
MutexLock mu(Thread::Current(), lock_);
iterations_ = 0;
- STLDeleteElements(&histograms_);
+ STLDeleteValues(&histograms_);
}
uint64_t CumulativeLogger::GetTotalNs() const {
@@ -68,36 +67,19 @@
uint64_t CumulativeLogger::GetTotalTime() const {
MutexLock mu(Thread::Current(), lock_);
uint64_t total = 0;
- for (size_t i = 0; i < histograms_.size(); ++i) {
- total += histograms_[i]->Sum();
+ for (CumulativeLogger::HistogramsIterator it = histograms_.begin(), end = histograms_.end();
+ it != end; ++it) {
+ total += it->second->Sum();
}
return total;
}
-
void CumulativeLogger::AddLogger(const base::TimingLogger &logger) {
MutexLock mu(Thread::Current(), lock_);
- const std::vector<std::pair<uint64_t, const char*> >& splits = logger.GetSplits();
- typedef std::vector<std::pair<uint64_t, const char*> >::const_iterator It;
- // The first time this is run, the histograms array will be empty.
- if (kIsDebugBuild && !histograms_.empty() && splits.size() != histograms_.size()) {
- LOG(ERROR) << "Mismatch in splits.";
- typedef std::vector<Histogram<uint64_t> *>::const_iterator It2;
- It it = splits.begin();
- It2 it2 = histograms_.begin();
- while ((it != splits.end()) && (it2 != histograms_.end())) {
- if (it != splits.end()) {
- LOG(ERROR) << "\tsplit: " << it->second;
- ++it;
- }
- if (it2 != histograms_.end()) {
- LOG(ERROR) << "\tpreviously record: " << (*it2)->Name();
- ++it2;
- }
- }
- }
- for (It it = splits.begin(), end = splits.end(); it != end; ++it) {
- std::pair<uint64_t, const char*> split = *it;
+ const base::TimingLogger::SplitTimings& splits = logger.GetSplits();
+ for (base::TimingLogger::SplitsIterator it = splits.begin(), end = splits.end();
+ it != end; ++it) {
+ base::TimingLogger::SplitTiming split = *it;
uint64_t split_time = split.first;
const char* split_name = split.second;
AddPair(split_name, split_time);
@@ -112,23 +94,24 @@
void CumulativeLogger::AddPair(const std::string &label, uint64_t delta_time) {
// Convert delta time to microseconds so that we don't overflow our counters.
delta_time /= kAdjust;
- if (histograms_.size() <= index_) {
+
+ if (histograms_.find(label) == histograms_.end()) {
+ // TODO: Shoud this be a defined constant so we we know out of which orifice 16 and 100 were picked?
const size_t max_buckets = Runtime::Current()->GetHeap()->IsLowMemoryMode() ? 16 : 100;
- histograms_.push_back(new Histogram<uint64_t>(label.c_str(), 50, max_buckets));
- DCHECK_GT(histograms_.size(), index_);
+ // TODO: Should this be a defined constant so we know 50 of WTF?
+ histograms_[label] = new Histogram<uint64_t>(label.c_str(), 50, max_buckets);
}
- histograms_[index_]->AddValue(delta_time);
- DCHECK_EQ(label, histograms_[index_]->Name());
- ++index_;
+ histograms_[label]->AddValue(delta_time);
}
void CumulativeLogger::DumpHistogram(std::ostream &os) {
os << "Start Dumping histograms for " << iterations_ << " iterations"
<< " for " << name_ << "\n";
- for (size_t Idx = 0; Idx < histograms_.size(); Idx++) {
+ for (CumulativeLogger::HistogramsIterator it = histograms_.begin(), end = histograms_.end();
+ it != end; ++it) {
Histogram<uint64_t>::CumulativeData cumulative_data;
- histograms_[Idx]->CreateHistogram(cumulative_data);
- histograms_[Idx]->PrintConfidenceIntervals(os, 0.99, cumulative_data);
+ it->second->CreateHistogram(cumulative_data);
+ it->second->PrintConfidenceIntervals(os, 0.99, cumulative_data);
// Reset cumulative values to save memory. We don't expect DumpHistogram to be called often, so
// it is not performance critical.
}
@@ -139,58 +122,42 @@
namespace base {
TimingLogger::TimingLogger(const char* name, bool precise, bool verbose)
- : name_(name), precise_(precise), verbose_(verbose),
- current_split_(NULL), current_split_start_ns_(0) {
+ : name_(name), precise_(precise), verbose_(verbose), current_split_(NULL) {
}
void TimingLogger::Reset() {
current_split_ = NULL;
- current_split_start_ns_ = 0;
splits_.clear();
}
void TimingLogger::StartSplit(const char* new_split_label) {
- DCHECK(current_split_ == NULL);
- if (verbose_) {
- LOG(INFO) << "Begin: " << new_split_label;
- }
- current_split_ = new_split_label;
- ATRACE_BEGIN(current_split_);
- current_split_start_ns_ = NanoTime();
+ DCHECK(new_split_label != NULL) << "Starting split (" << new_split_label << ") with null label.";
+ TimingLogger::ScopedSplit* explicit_scoped_split = new TimingLogger::ScopedSplit(new_split_label, this);
+ explicit_scoped_split->explicit_ = true;
+}
+
+void TimingLogger::EndSplit() {
+ CHECK(current_split_ != NULL) << "Ending a non-existent split.";
+ DCHECK(current_split_->label_ != NULL);
+ DCHECK(current_split_->explicit_ == true) << "Explicitly ending scoped split: " << current_split_->label_;
+
+ delete current_split_;
}
// Ends the current split and starts the one given by the label.
void TimingLogger::NewSplit(const char* new_split_label) {
- DCHECK(current_split_ != NULL);
- uint64_t current_time = NanoTime();
- uint64_t split_time = current_time - current_split_start_ns_;
- ATRACE_END();
- splits_.push_back(std::pair<uint64_t, const char*>(split_time, current_split_));
- if (verbose_) {
- LOG(INFO) << "End: " << current_split_ << " " << PrettyDuration(split_time) << "\n"
- << "Begin: " << new_split_label;
- }
- current_split_ = new_split_label;
- ATRACE_BEGIN(current_split_);
- current_split_start_ns_ = current_time;
-}
+ CHECK(current_split_ != NULL) << "Inserting a new split (" << new_split_label
+ << ") into a non-existent split.";
+ DCHECK(new_split_label != NULL) << "New split (" << new_split_label << ") with null label.";
-void TimingLogger::EndSplit() {
- DCHECK(current_split_ != NULL);
- uint64_t current_time = NanoTime();
- uint64_t split_time = current_time - current_split_start_ns_;
- ATRACE_END();
- if (verbose_) {
- LOG(INFO) << "End: " << current_split_ << " " << PrettyDuration(split_time);
- }
- splits_.push_back(std::pair<uint64_t, const char*>(split_time, current_split_));
+ current_split_->TailInsertSplit(new_split_label);
}
uint64_t TimingLogger::GetTotalNs() const {
uint64_t total_ns = 0;
- typedef std::vector<std::pair<uint64_t, const char*> >::const_iterator It;
- for (It it = splits_.begin(), end = splits_.end(); it != end; ++it) {
- std::pair<uint64_t, const char*> split = *it;
+ for (base::TimingLogger::SplitsIterator it = splits_.begin(), end = splits_.end();
+ it != end; ++it) {
+ base::TimingLogger::SplitTiming split = *it;
total_ns += split.first;
}
return total_ns;
@@ -199,9 +166,9 @@
void TimingLogger::Dump(std::ostream &os) const {
uint64_t longest_split = 0;
uint64_t total_ns = 0;
- typedef std::vector<std::pair<uint64_t, const char*> >::const_iterator It;
- for (It it = splits_.begin(), end = splits_.end(); it != end; ++it) {
- std::pair<uint64_t, const char*> split = *it;
+ for (base::TimingLogger::SplitsIterator it = splits_.begin(), end = splits_.end();
+ it != end; ++it) {
+ base::TimingLogger::SplitTiming split = *it;
uint64_t split_time = split.first;
longest_split = std::max(longest_split, split_time);
total_ns += split_time;
@@ -210,8 +177,9 @@
TimeUnit tu = GetAppropriateTimeUnit(longest_split);
uint64_t divisor = GetNsToTimeUnitDivisor(tu);
// Print formatted splits.
- for (It it = splits_.begin(), end = splits_.end(); it != end; ++it) {
- std::pair<uint64_t, const char*> split = *it;
+ for (base::TimingLogger::SplitsIterator it = splits_.begin(), end = splits_.end();
+ it != end; ++it) {
+ base::TimingLogger::SplitTiming split = *it;
uint64_t split_time = split.first;
if (!precise_ && divisor >= 1000) {
// Make the fractional part 0.
@@ -223,5 +191,102 @@
os << name_ << ": end, " << NsToMs(total_ns) << " ms\n";
}
+
+TimingLogger::ScopedSplit::ScopedSplit(const char* label, TimingLogger* timing_logger) {
+ DCHECK(label != NULL) << "New scoped split (" << label << ") with null label.";
+ CHECK(timing_logger != NULL) << "New scoped split (" << label << ") without TimingLogger.";
+ timing_logger_ = timing_logger;
+ label_ = label;
+ running_ns_ = 0;
+ explicit_ = false;
+
+ // Stash away the current split and pause it.
+ enclosing_split_ = timing_logger->current_split_;
+ if (enclosing_split_ != NULL) {
+ enclosing_split_->Pause();
+ }
+
+ timing_logger_->current_split_ = this;
+
+ ATRACE_BEGIN(label_);
+
+ start_ns_ = NanoTime();
+ if (timing_logger_->verbose_) {
+ LOG(INFO) << "Begin: " << label_;
+ }
+}
+
+TimingLogger::ScopedSplit::~ScopedSplit() {
+ uint64_t current_time = NanoTime();
+ uint64_t split_time = current_time - start_ns_;
+ running_ns_ += split_time;
+ ATRACE_END();
+
+ if (timing_logger_->verbose_) {
+ LOG(INFO) << "End: " << label_ << " " << PrettyDuration(split_time);
+ }
+
+ // If one or more enclosed explcitly started splits are not terminated we can
+ // either fail or "unwind" the stack of splits in the timing logger to 'this'
+ // (by deleting the intervening scoped splits). This implements the latter.
+ TimingLogger::ScopedSplit* current = timing_logger_->current_split_;
+ while ((current != NULL) && (current != this)) {
+ delete current;
+ current = timing_logger_->current_split_;
+ }
+
+ CHECK(current != NULL) << "Missing scoped split (" << this->label_
+ << ") in timing logger (" << timing_logger_->name_ << ").";
+ CHECK(timing_logger_->current_split_ == this);
+
+ timing_logger_->splits_.push_back(SplitTiming(running_ns_, label_));
+
+ timing_logger_->current_split_ = enclosing_split_;
+ if (enclosing_split_ != NULL) {
+ enclosing_split_->UnPause();
+ }
+}
+
+
+void TimingLogger::ScopedSplit::TailInsertSplit(const char* label) {
+ // Sleight of hand here: Rather than embedding a new scoped split, we're updating the current
+ // scoped split in place. Basically, it's one way to make explicit and scoped splits compose
+ // well while maintaining the current semantics of NewSplit. An alternative is to push a new split
+ // since we unwind the stack of scoped splits in the scoped split destructor. However, this implies
+ // that the current split is not ended by NewSplit (which calls TailInsertSplit), which would
+ // be different from what we had before.
+
+ uint64_t current_time = NanoTime();
+ uint64_t split_time = current_time - start_ns_;
+ ATRACE_END();
+ timing_logger_->splits_.push_back(std::pair<uint64_t, const char*>(split_time, label_));
+
+ if (timing_logger_->verbose_) {
+ LOG(INFO) << "End: " << label_ << " " << PrettyDuration(split_time) << "\n"
+ << "Begin: " << label;
+ }
+
+ label_ = label;
+ start_ns_ = current_time;
+ running_ns_ = 0;
+
+ ATRACE_BEGIN(label);
+}
+
+void TimingLogger::ScopedSplit::Pause() {
+ uint64_t current_time = NanoTime();
+ uint64_t split_time = current_time - start_ns_;
+ running_ns_ += split_time;
+ ATRACE_END();
+}
+
+
+void TimingLogger::ScopedSplit::UnPause() {
+ uint64_t current_time = NanoTime();
+
+ start_ns_ = current_time;
+ ATRACE_BEGIN(label_);
+}
+
} // namespace base
} // namespace art
diff --git a/runtime/base/timing_logger.h b/runtime/base/timing_logger.h
index 0998837..8649a96 100644
--- a/runtime/base/timing_logger.h
+++ b/runtime/base/timing_logger.h
@@ -23,6 +23,7 @@
#include <string>
#include <vector>
+#include <map>
namespace art {
@@ -32,6 +33,9 @@
class CumulativeLogger {
public:
+ typedef std::map<std::string, Histogram<uint64_t> *> Histograms;
+ typedef std::map<std::string, Histogram<uint64_t> *>::const_iterator HistogramsIterator;
+
explicit CumulativeLogger(const std::string& name);
void prepare_stats();
~CumulativeLogger();
@@ -51,11 +55,10 @@
void DumpHistogram(std::ostream &os) EXCLUSIVE_LOCKS_REQUIRED(lock_);
uint64_t GetTotalTime() const;
static const uint64_t kAdjust = 1000;
- std::vector<Histogram<uint64_t> *> histograms_ GUARDED_BY(lock_);
+ Histograms histograms_ GUARDED_BY(lock_);
std::string name_;
const std::string lock_name_;
mutable Mutex lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
- size_t index_ GUARDED_BY(lock_);
size_t iterations_ GUARDED_BY(lock_);
DISALLOW_COPY_AND_ASSIGN(CumulativeLogger);
@@ -63,16 +66,22 @@
namespace base {
-// A replacement to timing logger that know when a split starts for the purposes of logging.
+
+// A timing logger that knows when a split starts for the purposes of logging tools, like systrace.
class TimingLogger {
public:
+ // Splits are nanosecond times and split names.
+ typedef std::pair<uint64_t, const char*> SplitTiming;
+ typedef std::vector<SplitTiming> SplitTimings;
+ typedef std::vector<SplitTiming>::const_iterator SplitsIterator;
+
explicit TimingLogger(const char* name, bool precise, bool verbose);
// Clears current splits and labels.
void Reset();
- // Starts a split, a split shouldn't be in progress.
- void StartSplit(const char* new_split_label);
+ // Starts a split
+ void StartSplit(const char* new_split_label);
// Ends the current split and starts the one given by the label.
void NewSplit(const char* new_split_label);
@@ -84,10 +93,53 @@
void Dump(std::ostream& os) const;
- const std::vector<std::pair<uint64_t, const char*> >& GetSplits() const {
+ // Scoped timing splits that can be nested and composed with the explicit split
+ // starts and ends.
+ class ScopedSplit {
+ public:
+ explicit ScopedSplit(const char* label, TimingLogger* timing_logger);
+
+ ~ScopedSplit();
+
+ friend class TimingLogger;
+
+ private:
+ // Pauses timing of the split, usually due to nesting of another split.
+ void Pause();
+
+ // Unpauses timing of the split, usually because a nested split has ended.
+ void UnPause();
+
+ // Used by new split to swap splits in place in a ScopedSplit instance.
+ void TailInsertSplit(const char* label);
+
+ // The scoped split immediately enclosing this split. Essentially, we get a
+ // stack of nested splits through this field.
+ ScopedSplit* enclosing_split_;
+
+ // Was this created via TimingLogger's StartSplit?
+ bool explicit_;
+
+ // The split's name.
+ const char* label_;
+
+ // The current split's latest start time. (It may have been paused and restarted.)
+ uint64_t start_ns_;
+
+ // The running time, outside of pauses.
+ uint64_t running_ns_;
+
+ // The timing logger holding this split.
+ TimingLogger* timing_logger_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScopedSplit);
+ };
+
+ const SplitTimings& GetSplits() const {
return splits_;
}
+ friend class ScopedSplit;
protected:
// The name of the timing logger.
const char* name_;
@@ -99,14 +151,11 @@
// Verbose logging.
const bool verbose_;
- // The name of the current split.
- const char* current_split_;
+ // The current scoped split is also the 'top' of the stack of splits in progress.
+ ScopedSplit* current_split_;
- // The nanosecond time the current split started on.
- uint64_t current_split_start_ns_;
-
- // Splits are nanosecond times and split names.
- std::vector<std::pair<uint64_t, const char*> > splits_;
+ // Splits that have ended.
+ SplitTimings splits_;
private:
DISALLOW_COPY_AND_ASSIGN(TimingLogger);
diff --git a/runtime/base/timing_logger_test.cc b/runtime/base/timing_logger_test.cc
new file mode 100644
index 0000000..8f28e48
--- /dev/null
+++ b/runtime/base/timing_logger_test.cc
@@ -0,0 +1,160 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "timing_logger.h"
+
+#include "common_test.h"
+
+namespace art {
+
+class TimingLoggerTest : public CommonTest {};
+
+// TODO: Negative test cases (improper pairing of EndSplit, etc.)
+
+TEST_F(TimingLoggerTest, StartEnd) {
+ const char* split1name = "First Split";
+ base::TimingLogger timings("StartEnd", true, false);
+
+ timings.StartSplit(split1name);
+
+ timings.EndSplit(); // Ends split1.
+
+ const base::TimingLogger::SplitTimings& splits = timings.GetSplits();
+
+ EXPECT_EQ(1U, splits.size());
+ EXPECT_STREQ(splits[0].second, split1name);
+}
+
+
+TEST_F(TimingLoggerTest, StartNewEnd) {
+ const char* split1name = "First Split";
+ const char* split2name = "Second Split";
+ const char* split3name = "Third Split";
+ base::TimingLogger timings("StartNewEnd", true, false);
+
+ timings.StartSplit(split1name);
+
+ timings.NewSplit(split2name); // Ends split1.
+
+ timings.NewSplit(split3name); // Ends split2.
+
+ timings.EndSplit(); // Ends split3.
+
+ const base::TimingLogger::SplitTimings& splits = timings.GetSplits();
+
+ EXPECT_EQ(3U, splits.size());
+ EXPECT_STREQ(splits[0].second, split1name);
+ EXPECT_STREQ(splits[1].second, split2name);
+ EXPECT_STREQ(splits[2].second, split3name);
+}
+
+TEST_F(TimingLoggerTest, StartNewEndNested) {
+ const char* split1name = "First Split";
+ const char* split2name = "Second Split";
+ const char* split3name = "Third Split";
+ const char* split4name = "Fourth Split";
+ const char* split5name = "Fifth Split";
+ base::TimingLogger timings("StartNewEndNested", true, false);
+
+ timings.StartSplit(split1name);
+
+ timings.NewSplit(split2name); // Ends split1.
+
+ timings.StartSplit(split3name);
+
+ timings.StartSplit(split4name);
+
+ timings.NewSplit(split5name); // Ends split4.
+
+ timings.EndSplit(); // Ends split5.
+
+ timings.EndSplit(); // Ends split3.
+
+ timings.EndSplit(); // Ends split2.
+
+ const base::TimingLogger::SplitTimings& splits = timings.GetSplits();
+
+ EXPECT_EQ(5U, splits.size());
+ EXPECT_STREQ(splits[0].second, split1name);
+ EXPECT_STREQ(splits[1].second, split4name);
+ EXPECT_STREQ(splits[2].second, split5name);
+ EXPECT_STREQ(splits[3].second, split3name);
+ EXPECT_STREQ(splits[4].second, split2name);
+}
+
+
+TEST_F(TimingLoggerTest, Scoped) {
+ const char* outersplit = "Outer Split";
+ const char* innersplit1 = "Inner Split 1";
+ const char* innerinnersplit1 = "Inner Inner Split 1";
+ const char* innersplit2 = "Inner Split 2";
+ base::TimingLogger timings("Scoped", true, false);
+
+ {
+ base::TimingLogger::ScopedSplit outer(outersplit, &timings);
+
+ {
+ base::TimingLogger::ScopedSplit inner1(innersplit1, &timings);
+
+ {
+ base::TimingLogger::ScopedSplit innerinner1(innerinnersplit1, &timings);
+ } // Ends innerinnersplit1.
+ } // Ends innersplit1.
+
+ {
+ base::TimingLogger::ScopedSplit inner2(innersplit2, &timings);
+ } // Ends innersplit2.
+ } // Ends outersplit.
+
+ const base::TimingLogger::SplitTimings& splits = timings.GetSplits();
+
+ EXPECT_EQ(4U, splits.size());
+ EXPECT_STREQ(splits[0].second, innerinnersplit1);
+ EXPECT_STREQ(splits[1].second, innersplit1);
+ EXPECT_STREQ(splits[2].second, innersplit2);
+ EXPECT_STREQ(splits[3].second, outersplit);
+}
+
+
+TEST_F(TimingLoggerTest, ScopedAndExplicit) {
+ const char* outersplit = "Outer Split";
+ const char* innersplit = "Inner Split";
+ const char* innerinnersplit1 = "Inner Inner Split 1";
+ const char* innerinnersplit2 = "Inner Inner Split 2";
+ base::TimingLogger timings("Scoped", true, false);
+
+ timings.StartSplit(outersplit);
+
+ {
+ base::TimingLogger::ScopedSplit inner(innersplit, &timings);
+
+ timings.StartSplit(innerinnersplit1);
+
+ timings.NewSplit(innerinnersplit2); // Ends innerinnersplit1.
+ } // Ends innerinnersplit2, then innersplit.
+
+ timings.EndSplit(); // Ends outersplit.
+
+ const base::TimingLogger::SplitTimings& splits = timings.GetSplits();
+
+ EXPECT_EQ(4U, splits.size());
+ EXPECT_STREQ(splits[0].second, innerinnersplit1);
+ EXPECT_STREQ(splits[1].second, innerinnersplit2);
+ EXPECT_STREQ(splits[2].second, innersplit);
+ EXPECT_STREQ(splits[3].second, outersplit);
+}
+
+} // namespace art
diff --git a/runtime/common_test.h b/runtime/common_test.h
index a543617..7110e11 100644
--- a/runtime/common_test.h
+++ b/runtime/common_test.h
@@ -168,8 +168,8 @@
const size_t frame_size_in_bytes,
const uint32_t core_spill_mask,
const uint32_t fp_spill_mask,
- const uint32_t* mapping_table,
- const uint16_t* vmap_table,
+ const uint8_t* mapping_table,
+ const uint8_t* vmap_table,
const uint8_t* gc_map) {
return OatFile::OatMethod(NULL,
reinterpret_cast<uint32_t>(code),
diff --git a/runtime/compiled_method.cc b/runtime/compiled_method.cc
index c64c71e..4631cb5 100644
--- a/runtime/compiled_method.cc
+++ b/runtime/compiled_method.cc
@@ -112,35 +112,13 @@
const size_t frame_size_in_bytes,
const uint32_t core_spill_mask,
const uint32_t fp_spill_mask,
- const std::vector<uint32_t>& mapping_table,
- const std::vector<uint16_t>& vmap_table,
+ const std::vector<uint8_t>& mapping_table,
+ const std::vector<uint8_t>& vmap_table,
const std::vector<uint8_t>& native_gc_map)
: CompiledCode(instruction_set, code), frame_size_in_bytes_(frame_size_in_bytes),
core_spill_mask_(core_spill_mask), fp_spill_mask_(fp_spill_mask),
+ mapping_table_(mapping_table), vmap_table_(vmap_table),
gc_map_(native_gc_map) {
- DCHECK_EQ(vmap_table.size(),
- static_cast<uint32_t>(__builtin_popcount(core_spill_mask)
- + __builtin_popcount(fp_spill_mask)));
- CHECK_LE(vmap_table.size(), (1U << 16) - 1); // length must fit in 2^16-1
-
- std::vector<uint32_t> length_prefixed_mapping_table;
- length_prefixed_mapping_table.push_back(mapping_table.size());
- length_prefixed_mapping_table.insert(length_prefixed_mapping_table.end(),
- mapping_table.begin(),
- mapping_table.end());
- DCHECK_EQ(mapping_table.size() + 1, length_prefixed_mapping_table.size());
-
- std::vector<uint16_t> length_prefixed_vmap_table;
- length_prefixed_vmap_table.push_back(vmap_table.size());
- length_prefixed_vmap_table.insert(length_prefixed_vmap_table.end(),
- vmap_table.begin(),
- vmap_table.end());
- DCHECK_EQ(vmap_table.size() + 1, length_prefixed_vmap_table.size());
- DCHECK_EQ(vmap_table.size(), length_prefixed_vmap_table[0]);
-
- mapping_table_ = length_prefixed_mapping_table;
- vmap_table_ = length_prefixed_vmap_table;
- DCHECK_EQ(vmap_table_[0], static_cast<uint32_t>(__builtin_popcount(core_spill_mask) + __builtin_popcount(fp_spill_mask)));
}
CompiledMethod::CompiledMethod(InstructionSet instruction_set,
diff --git a/runtime/compiled_method.h b/runtime/compiled_method.h
index 800dde2..b3bb20f 100644
--- a/runtime/compiled_method.h
+++ b/runtime/compiled_method.h
@@ -103,8 +103,8 @@
const size_t frame_size_in_bytes,
const uint32_t core_spill_mask,
const uint32_t fp_spill_mask,
- const std::vector<uint32_t>& mapping_table,
- const std::vector<uint16_t>& vmap_table,
+ const std::vector<uint8_t>& mapping_table,
+ const std::vector<uint8_t>& vmap_table,
const std::vector<uint8_t>& native_gc_map);
// Constructs a CompiledMethod for the JniCompiler.
@@ -147,11 +147,11 @@
return fp_spill_mask_;
}
- const std::vector<uint32_t>& GetMappingTable() const {
+ const std::vector<uint8_t>& GetMappingTable() const {
return mapping_table_;
}
- const std::vector<uint16_t>& GetVmapTable() const {
+ const std::vector<uint8_t>& GetVmapTable() const {
return vmap_table_;
}
@@ -166,10 +166,11 @@
const uint32_t core_spill_mask_;
// For quick code, a bit mask describing spilled FPR callee-save registers.
const uint32_t fp_spill_mask_;
- // For quick code, a map from native PC offset to dex PC.
- std::vector<uint32_t> mapping_table_;
- // For quick code, a map from GPR/FPR register to dex register.
- std::vector<uint16_t> vmap_table_;
+ // For quick code, a uleb128 encoded map from native PC offset to dex PC aswell as dex PC to
+ // native PC offset. Size prefixed.
+ std::vector<uint8_t> mapping_table_;
+ // For quick code, a uleb128 encoded map from GPR/FPR register to dex register. Size prefixed.
+ std::vector<uint8_t> vmap_table_;
// For quick code, a map keyed by native PC indices to bitmaps describing what dalvik registers
// are live. For portable code, the key is a dalvik PC.
std::vector<uint8_t> gc_map_;
diff --git a/runtime/exception_test.cc b/runtime/exception_test.cc
index a7a6d46..933b74a 100644
--- a/runtime/exception_test.cc
+++ b/runtime/exception_test.cc
@@ -18,6 +18,7 @@
#include "common_test.h"
#include "dex_file.h"
#include "gtest/gtest.h"
+#include "leb128_encoder.h"
#include "mirror/class-inl.h"
#include "mirror/object_array-inl.h"
#include "mirror/object-inl.h"
@@ -53,17 +54,17 @@
fake_code_.push_back(0x70 | i);
}
- fake_mapping_data_.push_back(4); // first element is count
- fake_mapping_data_.push_back(4); // total (non-length) elements
- fake_mapping_data_.push_back(2); // count of pc to dex elements
+ fake_mapping_data_.PushBack(4); // first element is count
+ fake_mapping_data_.PushBack(4); // total (non-length) elements
+ fake_mapping_data_.PushBack(2); // count of pc to dex elements
// --- pc to dex table
- fake_mapping_data_.push_back(3); // offset 3
- fake_mapping_data_.push_back(3); // maps to dex offset 3
+ fake_mapping_data_.PushBack(3); // offset 3
+ fake_mapping_data_.PushBack(3); // maps to dex offset 3
// --- dex to pc table
- fake_mapping_data_.push_back(3); // offset 3
- fake_mapping_data_.push_back(3); // maps to dex offset 3
+ fake_mapping_data_.PushBack(3); // offset 3
+ fake_mapping_data_.PushBack(3); // maps to dex offset 3
- fake_vmap_table_data_.push_back(0);
+ fake_vmap_table_data_.PushBack(0);
fake_gc_map_.push_back(0); // 0 bytes to encode references and native pc offsets.
fake_gc_map_.push_back(0);
@@ -74,24 +75,24 @@
ASSERT_TRUE(method_f_ != NULL);
method_f_->SetFrameSizeInBytes(kStackAlignment);
method_f_->SetEntryPointFromCompiledCode(CompiledMethod::CodePointer(&fake_code_[sizeof(code_size)], kThumb2));
- method_f_->SetMappingTable(&fake_mapping_data_[0]);
- method_f_->SetVmapTable(&fake_vmap_table_data_[0]);
+ method_f_->SetMappingTable(&fake_mapping_data_.GetData()[0]);
+ method_f_->SetVmapTable(&fake_vmap_table_data_.GetData()[0]);
method_f_->SetNativeGcMap(&fake_gc_map_[0]);
method_g_ = my_klass_->FindVirtualMethod("g", "(I)V");
ASSERT_TRUE(method_g_ != NULL);
method_g_->SetFrameSizeInBytes(kStackAlignment);
method_g_->SetEntryPointFromCompiledCode(CompiledMethod::CodePointer(&fake_code_[sizeof(code_size)], kThumb2));
- method_g_->SetMappingTable(&fake_mapping_data_[0]);
- method_g_->SetVmapTable(&fake_vmap_table_data_[0]);
+ method_g_->SetMappingTable(&fake_mapping_data_.GetData()[0]);
+ method_g_->SetVmapTable(&fake_vmap_table_data_.GetData()[0]);
method_g_->SetNativeGcMap(&fake_gc_map_[0]);
}
const DexFile* dex_;
std::vector<uint8_t> fake_code_;
- std::vector<uint32_t> fake_mapping_data_;
- std::vector<uint16_t> fake_vmap_table_data_;
+ UnsignedLeb128EncodingVector fake_mapping_data_;
+ UnsignedLeb128EncodingVector fake_vmap_table_data_;
std::vector<uint8_t> fake_gc_map_;
mirror::AbstractMethod* method_f_;
diff --git a/runtime/gc/collector/mark_sweep.cc b/runtime/gc/collector/mark_sweep.cc
index 8a08f08..c1ca55a 100644
--- a/runtime/gc/collector/mark_sweep.cc
+++ b/runtime/gc/collector/mark_sweep.cc
@@ -107,6 +107,7 @@
}
void MarkSweep::BindBitmaps() {
+ timings_.StartSplit("BindBitmaps");
const std::vector<space::ContinuousSpace*>& spaces = GetHeap()->GetContinuousSpaces();
WriterMutexLock mu(Thread::Current(), *Locks::heap_bitmap_lock_);
@@ -118,6 +119,7 @@
ImmuneSpace(space);
}
}
+ timings_.EndSplit();
}
MarkSweep::MarkSweep(Heap* heap, bool is_concurrent, const std::string& name_prefix)
@@ -166,13 +168,17 @@
reference_count_ = 0;
java_lang_Class_ = Class::GetJavaLangClass();
CHECK(java_lang_Class_ != NULL);
+ timings_.EndSplit();
+
FindDefaultMarkBitmap();
- // Do any pre GC verification.
+
+// Do any pre GC verification.
+ timings_.StartSplit("PreGcVerification");
heap_->PreGcVerification(this);
+ timings_.EndSplit();
}
void MarkSweep::ProcessReferences(Thread* self) {
- timings_.NewSplit("ProcessReferences");
WriterMutexLock mu(self, *Locks::heap_bitmap_lock_);
ProcessReferences(&soft_reference_list_, clear_soft_references_, &weak_reference_list_,
&finalizer_reference_list_, &phantom_reference_list_);
@@ -184,7 +190,6 @@
Locks::mutator_lock_->AssertExclusiveHeld(self);
{
- timings_.NewSplit("ReMarkRoots");
WriterMutexLock mu(self, *Locks::heap_bitmap_lock_);
// Re-mark root set.
@@ -214,29 +219,26 @@
Heap* heap = GetHeap();
Thread* self = Thread::Current();
- timings_.NewSplit("BindBitmaps");
BindBitmaps();
FindDefaultMarkBitmap();
+
// Process dirty cards and add dirty cards to mod union tables.
heap->ProcessCards(timings_);
// Need to do this before the checkpoint since we don't want any threads to add references to
// the live stack during the recursive mark.
- timings_.NewSplit("SwapStacks");
+ timings_.StartSplit("SwapStacks");
heap->SwapStacks();
+ timings_.EndSplit();
WriterMutexLock mu(self, *Locks::heap_bitmap_lock_);
if (Locks::mutator_lock_->IsExclusiveHeld(self)) {
// If we exclusively hold the mutator lock, all threads must be suspended.
- timings_.NewSplit("MarkRoots");
MarkRoots();
} else {
- timings_.NewSplit("MarkRootsCheckpoint");
MarkRootsCheckpoint(self);
- timings_.NewSplit("MarkNonThreadRoots");
MarkNonThreadRoots();
}
- timings_.NewSplit("MarkConcurrentRoots");
MarkConcurrentRoots();
heap->UpdateAndMarkModUnion(this, timings_, GetGcType());
@@ -246,12 +248,13 @@
void MarkSweep::MarkReachableObjects() {
// Mark everything allocated since the last as GC live so that we can sweep concurrently,
// knowing that new allocations won't be marked as live.
- timings_.NewSplit("MarkStackAsLive");
+ timings_.StartSplit("MarkStackAsLive");
accounting::ObjectStack* live_stack = heap_->GetLiveStack();
heap_->MarkAllocStack(heap_->alloc_space_->GetLiveBitmap(),
heap_->large_object_space_->GetLiveObjects(),
live_stack);
live_stack->Reset();
+ timings_.EndSplit();
// Recursively mark all the non-image bits set in the mark bitmap.
RecursiveMark();
}
@@ -260,9 +263,10 @@
Thread* self = Thread::Current();
if (!IsConcurrent()) {
+ base::TimingLogger::ScopedSplit split("ProcessReferences", &timings_);
ProcessReferences(self);
} else {
- timings_.NewSplit("UnMarkAllocStack");
+ base::TimingLogger::ScopedSplit split("UnMarkAllocStack", &timings_);
accounting::ObjectStack* allocation_stack = GetHeap()->allocation_stack_.get();
WriterMutexLock mu(self, *Locks::heap_bitmap_lock_);
// The allocation stack contains things allocated since the start of the GC. These may have been
@@ -288,7 +292,9 @@
ReaderMutexLock mu(self, *Locks::heap_bitmap_lock_);
VerifyImageRoots();
}
+ timings_.StartSplit("PreSweepingGcVerification");
heap_->PreSweepingGcVerification(this);
+ timings_.EndSplit();
{
WriterMutexLock mu(self, *Locks::heap_bitmap_lock_);
@@ -299,8 +305,9 @@
// Swap the live and mark bitmaps for each space which we modified space. This is an
// optimization that enables us to not clear live bits inside of the sweep. Only swaps unbound
// bitmaps.
- timings_.NewSplit("SwapBitmaps");
+ timings_.StartSplit("SwapBitmaps");
SwapBitmaps();
+ timings_.EndSplit();
// Unbind the live and mark bitmaps.
UnBindBitmaps();
@@ -313,6 +320,7 @@
}
void MarkSweep::FindDefaultMarkBitmap() {
+ timings_.StartSplit("FindDefaultMarkBitmap");
const std::vector<space::ContinuousSpace*>& spaces = GetHeap()->GetContinuousSpaces();
// TODO: C++0x
typedef std::vector<space::ContinuousSpace*>::const_iterator It;
@@ -321,6 +329,7 @@
if (space->GetGcRetentionPolicy() == space::kGcRetentionPolicyAlwaysCollect) {
current_mark_bitmap_ = (*it)->GetMarkBitmap();
CHECK(current_mark_bitmap_ != NULL);
+ timings_.EndSplit();
return;
}
}
@@ -522,16 +531,22 @@
// Marks all objects in the root set.
void MarkSweep::MarkRoots() {
+ timings_.StartSplit("MarkRoots");
Runtime::Current()->VisitNonConcurrentRoots(MarkObjectCallback, this);
+ timings_.EndSplit();
}
void MarkSweep::MarkNonThreadRoots() {
+ timings_.StartSplit("MarkNonThreadRoots");
Runtime::Current()->VisitNonThreadRoots(MarkObjectCallback, this);
+ timings_.EndSplit();
}
void MarkSweep::MarkConcurrentRoots() {
+ timings_.StartSplit("MarkConcurrentRoots");
// Visit all runtime roots and clear dirty flags.
Runtime::Current()->VisitConcurrentRoots(MarkObjectCallback, this, false, true);
+ timings_.EndSplit();
}
class CheckObjectVisitor {
@@ -601,13 +616,13 @@
space::ContinuousSpace* space = *it;
switch (space->GetGcRetentionPolicy()) {
case space::kGcRetentionPolicyNeverCollect:
- timings_.NewSplit("ScanGrayImageSpaceObjects");
+ timings_.StartSplit("ScanGrayImageSpaceObjects");
break;
case space::kGcRetentionPolicyFullCollect:
- timings_.NewSplit("ScanGrayZygoteSpaceObjects");
+ timings_.StartSplit("ScanGrayZygoteSpaceObjects");
break;
case space::kGcRetentionPolicyAlwaysCollect:
- timings_.NewSplit("ScanGrayAllocSpaceObjects");
+ timings_.StartSplit("ScanGrayAllocSpaceObjects");
break;
}
byte* begin = space->Begin();
@@ -615,6 +630,7 @@
// Image spaces are handled properly since live == marked for them.
accounting::SpaceBitmap* mark_bitmap = space->GetMarkBitmap();
card_table->Scan(mark_bitmap, begin, end, visitor, minimum_age);
+ timings_.EndSplit();
}
}
@@ -638,6 +654,7 @@
// Verify roots ensures that all the references inside the image space point
// objects which are either in the image space or marked objects in the alloc
// space
+ timings_.StartSplit("VerifyImageRoots");
CheckBitmapVisitor visitor(this);
const std::vector<space::ContinuousSpace*>& spaces = GetHeap()->GetContinuousSpaces();
// TODO: C++0x
@@ -652,12 +669,13 @@
live_bitmap->VisitMarkedRange(begin, end, visitor);
}
}
+ timings_.EndSplit();
}
// Populates the mark stack based on the set of marked objects and
// recursively marks until the mark stack is emptied.
void MarkSweep::RecursiveMark() {
- timings_.NewSplit("RecursiveMark");
+ base::TimingLogger::ScopedSplit("RecursiveMark", &timings_);
// RecursiveMark will build the lists of known instances of the Reference classes.
// See DelayReferenceReferent for details.
CHECK(soft_reference_list_ == NULL);
@@ -688,7 +706,6 @@
}
}
}
- timings_.NewSplit("ProcessMarkStack");
ProcessMarkStack();
}
@@ -700,12 +717,13 @@
void MarkSweep::RecursiveMarkDirtyObjects(byte minimum_age) {
ScanGrayObjects(minimum_age);
- timings_.NewSplit("ProcessMarkStack");
ProcessMarkStack();
}
void MarkSweep::ReMarkRoots() {
+ timings_.StartSplit("ReMarkRoots");
Runtime::Current()->VisitRoots(ReMarkObjectVisitor, this, true, true);
+ timings_.EndSplit();
}
void MarkSweep::SweepJniWeakGlobals(IsMarkedTester is_marked, void* arg) {
@@ -744,12 +762,14 @@
// So compute !(!IsMarked && IsLive) which is equal to (IsMarked || !IsLive).
// Or for swapped (IsLive || !IsMarked).
+ timings_.StartSplit("SweepSystemWeaksArray");
ArrayMarkedCheck visitor;
visitor.live_stack = allocations;
visitor.mark_sweep = this;
runtime->GetInternTable()->SweepInternTableWeaks(IsMarkedArrayCallback, &visitor);
runtime->GetMonitorList()->SweepMonitorList(IsMarkedArrayCallback, &visitor);
SweepJniWeakGlobals(IsMarkedArrayCallback, &visitor);
+ timings_.EndSplit();
}
void MarkSweep::SweepSystemWeaks() {
@@ -759,9 +779,11 @@
// !IsMarked && IsLive
// So compute !(!IsMarked && IsLive) which is equal to (IsMarked || !IsLive).
// Or for swapped (IsLive || !IsMarked).
+ timings_.StartSplit("SweepSystemWeaks");
runtime->GetInternTable()->SweepInternTableWeaks(IsMarkedCallback, this);
runtime->GetMonitorList()->SweepMonitorList(IsMarkedCallback, this);
SweepJniWeakGlobals(IsMarkedCallback, this);
+ timings_.EndSplit();
}
bool MarkSweep::VerifyIsLiveCallback(const Object* obj, void* arg) {
@@ -826,6 +848,7 @@
void MarkSweep::MarkRootsCheckpoint(Thread* self) {
CheckpointMarkThreadRoots check_point(this);
+ timings_.StartSplit("MarkRootsCheckpoint");
ThreadList* thread_list = Runtime::Current()->GetThreadList();
// Request the check point is run on all threads returning a count of the threads that must
// run through the barrier including self.
@@ -840,6 +863,7 @@
self->SetState(kWaitingPerformingGc);
Locks::mutator_lock_->SharedLock(self);
Locks::heap_bitmap_lock_->ExclusiveLock(self);
+ timings_.EndSplit();
}
void MarkSweep::SweepCallback(size_t num_ptrs, Object** ptrs, void* arg) {
@@ -878,10 +902,9 @@
// If we don't swap bitmaps then newly allocated Weaks go into the live bitmap but not mark
// bitmap, resulting in occasional frees of Weaks which are still in use.
- timings_.NewSplit("SweepSystemWeaks");
SweepSystemWeaksArray(allocations);
- timings_.NewSplit("Process allocation stack");
+ timings_.StartSplit("Process allocation stack");
// Newly allocated objects MUST be in the alloc space and those are the only objects which we are
// going to free.
accounting::SpaceBitmap* live_bitmap = space->GetLiveBitmap();
@@ -915,8 +938,9 @@
}
}
CHECK_EQ(count, allocations->Size());
- timings_.NewSplit("FreeList");
+ timings_.EndSplit();
+ timings_.StartSplit("FreeList");
size_t freed_objects = out - objects;
freed_bytes += space->FreeList(self, freed_objects, objects);
VLOG(heap) << "Freed " << freed_objects << "/" << count
@@ -924,9 +948,11 @@
heap_->RecordFree(freed_objects + freed_large_objects, freed_bytes);
freed_objects_.fetch_add(freed_objects);
freed_bytes_.fetch_add(freed_bytes);
+ timings_.EndSplit();
- timings_.NewSplit("ResetStack");
+ timings_.StartSplit("ResetStack");
allocations->Reset();
+ timings_.EndSplit();
}
void MarkSweep::Sweep(bool swap_bitmaps) {
@@ -934,7 +960,6 @@
// If we don't swap bitmaps then newly allocated Weaks go into the live bitmap but not mark
// bitmap, resulting in occasional frees of Weaks which are still in use.
- timings_.NewSplit("SweepSystemWeaks");
SweepSystemWeaks();
const bool partial = (GetGcType() == kGcTypePartial);
@@ -962,22 +987,25 @@
std::swap(live_bitmap, mark_bitmap);
}
if (!space->IsZygoteSpace()) {
- timings_.NewSplit("SweepAllocSpace");
+ timings_.StartSplit("SweepAllocSpace");
// Bitmaps are pre-swapped for optimization which enables sweeping with the heap unlocked.
accounting::SpaceBitmap::SweepWalk(*live_bitmap, *mark_bitmap, begin, end,
&SweepCallback, reinterpret_cast<void*>(&scc));
+ timings_.EndSplit();
} else {
- timings_.NewSplit("SweepZygote");
+ timings_.StartSplit("SweepZygote");
// Zygote sweep takes care of dirtying cards and clearing live bits, does not free actual
// memory.
accounting::SpaceBitmap::SweepWalk(*live_bitmap, *mark_bitmap, begin, end,
&ZygoteSweepCallback, reinterpret_cast<void*>(&scc));
+ timings_.EndSplit();
}
}
}
- timings_.NewSplit("SweepLargeObjects");
+ timings_.StartSplit("SweepLargeObjects");
SweepLargeObjects(swap_bitmaps);
+ timings_.EndSplit();
}
void MarkSweep::SweepLargeObjects(bool swap_bitmaps) {
@@ -1269,8 +1297,10 @@
// Scan anything that's on the mark stack.
void MarkSweep::ProcessMarkStack() {
ThreadPool* thread_pool = GetHeap()->GetThreadPool();
+ timings_.StartSplit("ProcessMarkStack");
if (kParallelMarkStack && thread_pool != NULL && thread_pool->GetThreadCount() > 0) {
ProcessMarkStackParallel();
+ timings_.EndSplit();
return;
}
@@ -1312,6 +1342,7 @@
ScanObject(obj);
}
}
+ timings_.EndSplit();
}
// Walks the reference list marking any references subject to the
@@ -1325,6 +1356,7 @@
DCHECK(mark_stack_->IsEmpty());
+ timings_.StartSplit("PreserveSomeSoftReferences");
while (*list != NULL) {
Object* ref = heap_->DequeuePendingReference(list);
Object* referent = heap_->GetReferenceReferent(ref);
@@ -1344,6 +1376,8 @@
}
}
*list = clear;
+ timings_.EndSplit();
+
// Restart the mark with the newly black references added to the
// root set.
ProcessMarkStack();
@@ -1386,6 +1420,7 @@
// referent field is cleared.
void MarkSweep::EnqueueFinalizerReferences(Object** list) {
DCHECK(list != NULL);
+ timings_.StartSplit("EnqueueFinalizerReferences");
MemberOffset zombie_offset = heap_->GetFinalizerReferenceZombieOffset();
bool has_enqueued = false;
while (*list != NULL) {
@@ -1401,6 +1436,7 @@
has_enqueued = true;
}
}
+ timings_.EndSplit();
if (has_enqueued) {
ProcessMarkStack();
}
@@ -1423,15 +1459,18 @@
PreserveSomeSoftReferences(soft_references);
}
+ timings_.StartSplit("ProcessReferences");
// Clear all remaining soft and weak references with white
// referents.
ClearWhiteReferences(soft_references);
ClearWhiteReferences(weak_references);
+ timings_.EndSplit();
// Preserve all white objects with finalize methods and schedule
// them for finalization.
EnqueueFinalizerReferences(finalizer_references);
+ timings_.StartSplit("ProcessReferences");
// Clear all f-reachable soft and weak references with white
// referents.
ClearWhiteReferences(soft_references);
@@ -1445,9 +1484,11 @@
DCHECK(*weak_references == NULL);
DCHECK(*finalizer_references == NULL);
DCHECK(*phantom_references == NULL);
+ timings_.EndSplit();
}
void MarkSweep::UnBindBitmaps() {
+ timings_.StartSplit("UnBindBitmaps");
const std::vector<space::ContinuousSpace*>& spaces = GetHeap()->GetContinuousSpaces();
// TODO: C++0x
typedef std::vector<space::ContinuousSpace*>::const_iterator It;
@@ -1465,6 +1506,7 @@
}
}
}
+ timings_.EndSplit();
}
void MarkSweep::FinishPhase() {
@@ -1475,11 +1517,13 @@
heap->PostGcVerification(this);
- timings_.NewSplit("GrowForUtilization");
+ timings_.StartSplit("GrowForUtilization");
heap->GrowForUtilization(GetGcType(), GetDurationNs());
+ timings_.EndSplit();
- timings_.NewSplit("RequestHeapTrim");
+ timings_.StartSplit("RequestHeapTrim");
heap->RequestHeapTrim();
+ timings_.EndSplit();
// Update the cumulative statistics
total_time_ns_ += GetDurationNs();
diff --git a/runtime/gc/collector/sticky_mark_sweep.cc b/runtime/gc/collector/sticky_mark_sweep.cc
index 5505336..aad7c29 100644
--- a/runtime/gc/collector/sticky_mark_sweep.cc
+++ b/runtime/gc/collector/sticky_mark_sweep.cc
@@ -55,7 +55,6 @@
}
void StickyMarkSweep::Sweep(bool swap_bitmaps) {
- timings_.NewSplit("SweepArray");
accounting::ObjectStack* live_stack = GetHeap()->GetLiveStack();
SweepArray(live_stack, false);
}
diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc
index 4a894be..6dcdab9 100644
--- a/runtime/gc/heap.cc
+++ b/runtime/gc/heap.cc
@@ -89,6 +89,14 @@
max_allowed_footprint_(initial_size),
native_footprint_gc_watermark_(initial_size),
native_footprint_limit_(2 * initial_size),
+ activity_thread_class_(NULL),
+ application_thread_class_(NULL),
+ activity_thread_(NULL),
+ application_thread_(NULL),
+ last_process_state_id_(NULL),
+ // Initially care about pauses in case we never get notified of process states, or if the JNI
+ // code becomes broken.
+ care_about_pause_times_(true),
concurrent_start_bytes_(concurrent_gc ? initial_size - (kMinConcurrentRemainingBytes)
: std::numeric_limits<size_t>::max()),
total_bytes_freed_ever_(0),
@@ -96,7 +104,6 @@
large_object_threshold_(3 * kPageSize),
num_bytes_allocated_(0),
native_bytes_allocated_(0),
- process_state_(PROCESS_STATE_TOP),
gc_memory_overhead_(0),
verify_missing_card_marks_(false),
verify_system_weaks_(false),
@@ -250,8 +257,122 @@
}
};
-void Heap::UpdateProcessState(ProcessState process_state) {
- process_state_ = process_state;
+static bool ReadStaticInt(JNIEnvExt* env, jclass clz, const char* name, int* out_value) {
+ CHECK(out_value != NULL);
+ jfieldID field = env->GetStaticFieldID(clz, name, "I");
+ if (field == NULL) {
+ env->ExceptionClear();
+ return false;
+ }
+ *out_value = env->GetStaticIntField(clz, field);
+ return true;
+}
+
+void Heap::ListenForProcessStateChange() {
+ VLOG(gc) << "Heap notified of process state change";
+
+ Thread* self = Thread::Current();
+ JNIEnvExt* env = self->GetJniEnv();
+
+ if (!have_zygote_space_) {
+ return;
+ }
+
+ if (activity_thread_class_ == NULL) {
+ jclass clz = env->FindClass("android/app/ActivityThread");
+ if (clz == NULL) {
+ env->ExceptionClear();
+ LOG(WARNING) << "Could not find activity thread class in process state change";
+ return;
+ }
+ activity_thread_class_ = reinterpret_cast<jclass>(env->NewGlobalRef(clz));
+ }
+
+ if (activity_thread_class_ != NULL && activity_thread_ == NULL) {
+ jmethodID current_activity_method = env->GetStaticMethodID(activity_thread_class_,
+ "currentActivityThread",
+ "()Landroid/app/ActivityThread;");
+ if (current_activity_method == NULL) {
+ env->ExceptionClear();
+ LOG(WARNING) << "Could not get method for currentActivityThread";
+ return;
+ }
+
+ jobject obj = env->CallStaticObjectMethod(activity_thread_class_, current_activity_method);
+ if (obj == NULL) {
+ env->ExceptionClear();
+ LOG(WARNING) << "Could not get current activity";
+ return;
+ }
+ activity_thread_ = env->NewGlobalRef(obj);
+ }
+
+ if (process_state_cares_about_pause_time_.empty()) {
+ // Just attempt to do this the first time.
+ jclass clz = env->FindClass("android/app/ActivityManager");
+ if (clz == NULL) {
+ LOG(WARNING) << "Activity manager class is null";
+ return;
+ }
+ ScopedLocalRef<jclass> activity_manager(env, clz);
+ std::vector<const char*> care_about_pauses;
+ care_about_pauses.push_back("PROCESS_STATE_TOP");
+ care_about_pauses.push_back("PROCESS_STATE_IMPORTANT_BACKGROUND");
+ // Attempt to read the constants and classify them as whether or not we care about pause times.
+ for (size_t i = 0; i < care_about_pauses.size(); ++i) {
+ int process_state = 0;
+ if (ReadStaticInt(env, activity_manager.get(), care_about_pauses[i], &process_state)) {
+ process_state_cares_about_pause_time_.insert(process_state);
+ VLOG(gc) << "Adding process state " << process_state
+ << " to set of states which care about pause time";
+ }
+ }
+ }
+
+ if (application_thread_class_ == NULL) {
+ jclass clz = env->FindClass("android/app/ActivityThread$ApplicationThread");
+ if (clz == NULL) {
+ env->ExceptionClear();
+ LOG(WARNING) << "Could not get application thread class";
+ return;
+ }
+ application_thread_class_ = reinterpret_cast<jclass>(env->NewGlobalRef(clz));
+ last_process_state_id_ = env->GetFieldID(application_thread_class_, "mLastProcessState", "I");
+ if (last_process_state_id_ == NULL) {
+ env->ExceptionClear();
+ LOG(WARNING) << "Could not get last process state member";
+ return;
+ }
+ }
+
+ if (application_thread_class_ != NULL && application_thread_ == NULL) {
+ jmethodID get_application_thread =
+ env->GetMethodID(activity_thread_class_, "getApplicationThread",
+ "()Landroid/app/ActivityThread$ApplicationThread;");
+ if (get_application_thread == NULL) {
+ LOG(WARNING) << "Could not get method ID for get application thread";
+ return;
+ }
+
+ jobject obj = env->CallObjectMethod(activity_thread_, get_application_thread);
+ if (obj == NULL) {
+ LOG(WARNING) << "Could not get application thread";
+ return;
+ }
+
+ application_thread_ = env->NewGlobalRef(obj);
+ }
+
+ if (application_thread_ != NULL && last_process_state_id_ != NULL) {
+ int process_state = env->GetIntField(application_thread_, last_process_state_id_);
+ env->ExceptionClear();
+
+ care_about_pause_times_ = process_state_cares_about_pause_time_.find(process_state) !=
+ process_state_cares_about_pause_time_.end();
+
+ VLOG(gc) << "New process state " << process_state
+ << " care about pauses " << care_about_pause_times_;
+ }
}
void Heap::AddContinuousSpace(space::ContinuousSpace* space) {
@@ -1054,17 +1175,6 @@
bool clear_soft_references) {
Thread* self = Thread::Current();
- switch (gc_cause) {
- case kGcCauseForAlloc:
- ATRACE_BEGIN("GC (alloc)");
- break;
- case kGcCauseBackground:
- ATRACE_BEGIN("GC (background)");
- break;
- case kGcCauseExplicit:
- ATRACE_BEGIN("GC (explicit)");
- break;
- }
ScopedThreadStateChange tsc(self, kWaitingPerformingGc);
Locks::mutator_lock_->AssertNotHeld(self);
@@ -1084,7 +1194,9 @@
}
}
if (!start_collect) {
+ // TODO: timinglog this.
WaitForConcurrentGcToComplete(self);
+
// TODO: if another thread beat this one to do the GC, perhaps we should just return here?
// Not doing at the moment to ensure soft references are cleared.
}
@@ -1113,6 +1225,18 @@
gc_type = collector::kGcTypePartial;
}
+ switch (gc_cause) {
+ case kGcCauseForAlloc:
+ ATRACE_BEGIN("GC (alloc)");
+ break;
+ case kGcCauseBackground:
+ ATRACE_BEGIN("GC (background)");
+ break;
+ case kGcCauseExplicit:
+ ATRACE_BEGIN("GC (explicit)");
+ break;
+ }
+
DCHECK_LT(gc_type, collector::kGcTypeMax);
DCHECK_NE(gc_type, collector::kGcTypeNone);
collector::MarkSweep* collector = NULL;
@@ -1128,6 +1252,9 @@
CHECK(collector != NULL)
<< "Could not find garbage collector with concurrent=" << concurrent_gc_
<< " and type=" << gc_type;
+
+ base::TimingLogger& timings = collector->GetTimings();
+
collector->clear_soft_references_ = clear_soft_references;
collector->Run();
total_objects_freed_ever_ += collector->GetFreedObjects();
@@ -1136,42 +1263,43 @@
const size_t duration = collector->GetDurationNs();
std::vector<uint64_t> pauses = collector->GetPauseTimes();
bool was_slow = duration > kSlowGcThreshold ||
- (gc_cause == kGcCauseForAlloc && duration > kLongGcPauseThreshold);
+ (gc_cause == kGcCauseForAlloc && duration > kLongGcPauseThreshold);
for (size_t i = 0; i < pauses.size(); ++i) {
- if (pauses[i] > kLongGcPauseThreshold) {
- was_slow = true;
- }
+ if (pauses[i] > kLongGcPauseThreshold) {
+ was_slow = true;
+ }
}
if (was_slow) {
- const size_t percent_free = GetPercentFree();
- const size_t current_heap_size = GetBytesAllocated();
- const size_t total_memory = GetTotalMemory();
- std::ostringstream pause_string;
- for (size_t i = 0; i < pauses.size(); ++i) {
- pause_string << PrettyDuration((pauses[i] / 1000) * 1000)
- << ((i != pauses.size() - 1) ? ", " : "");
- }
- LOG(INFO) << gc_cause << " " << collector->GetName()
- << "GC freed " << PrettySize(collector->GetFreedBytes()) << ", "
- << percent_free << "% free, " << PrettySize(current_heap_size) << "/"
- << PrettySize(total_memory) << ", " << "paused " << pause_string.str()
- << " total " << PrettyDuration((duration / 1000) * 1000);
- if (VLOG_IS_ON(heap)) {
- LOG(INFO) << Dumpable<base::TimingLogger>(collector->GetTimings());
- }
+ const size_t percent_free = GetPercentFree();
+ const size_t current_heap_size = GetBytesAllocated();
+ const size_t total_memory = GetTotalMemory();
+ std::ostringstream pause_string;
+ for (size_t i = 0; i < pauses.size(); ++i) {
+ pause_string << PrettyDuration((pauses[i] / 1000) * 1000)
+ << ((i != pauses.size() - 1) ? ", " : "");
+ }
+ LOG(INFO) << gc_cause << " " << collector->GetName()
+ << "GC freed " << PrettySize(collector->GetFreedBytes()) << ", "
+ << percent_free << "% free, " << PrettySize(current_heap_size) << "/"
+ << PrettySize(total_memory) << ", " << "paused " << pause_string.str()
+ << " total " << PrettyDuration((duration / 1000) * 1000);
+ if (VLOG_IS_ON(heap)) {
+ LOG(INFO) << Dumpable<base::TimingLogger>(timings);
+ }
}
{
- MutexLock mu(self, *gc_complete_lock_);
- is_gc_running_ = false;
- last_gc_type_ = gc_type;
- // Wake anyone who may have been waiting for the GC to complete.
- gc_complete_cond_->Broadcast(self);
+ MutexLock mu(self, *gc_complete_lock_);
+ is_gc_running_ = false;
+ last_gc_type_ = gc_type;
+ // Wake anyone who may have been waiting for the GC to complete.
+ gc_complete_cond_->Broadcast(self);
}
- // Inform DDMS that a GC completed.
ATRACE_END();
+
+ // Inform DDMS that a GC completed.
Dbg::GcDidFinish();
return gc_type;
}
@@ -1184,9 +1312,10 @@
return;
}
+ base::TimingLogger::ScopedSplit split("UpdateModUnionTable", &timings);
// Update zygote mod union table.
if (gc_type == collector::kGcTypePartial) {
- timings.NewSplit("UpdateZygoteModUnionTable");
+ base::TimingLogger::ScopedSplit split("UpdateZygoteModUnionTable", &timings);
zygote_mod_union_table_->Update();
timings.NewSplit("ZygoteMarkReferences");
@@ -1473,15 +1602,15 @@
for (It it = continuous_spaces_.begin(), end = continuous_spaces_.end(); it != end; ++it) {
space::ContinuousSpace* space = *it;
if (space->IsImageSpace()) {
- timings.NewSplit("ModUnionClearCards");
+ base::TimingLogger::ScopedSplit split("ImageModUnionClearCards", &timings);
image_mod_union_table_->ClearCards(space);
} else if (space->IsZygoteSpace()) {
- timings.NewSplit("ZygoteModUnionClearCards");
+ base::TimingLogger::ScopedSplit split("ZygoteModUnionClearCards", &timings);
zygote_mod_union_table_->ClearCards(space);
} else {
+ base::TimingLogger::ScopedSplit split("AllocSpaceClearCards", &timings);
// No mod union table for the AllocSpace. Age the cards so that the GC knows that these cards
// were dirty before the GC started.
- timings.NewSplit("AllocSpaceClearCards");
card_table_->ModifyCardsAtomic(space->Begin(), space->End(), AgeCardVisitor(), VoidFunctor());
}
}
@@ -1880,20 +2009,18 @@
}
}
- SchedPolicy policy;
- get_sched_policy(self->GetTid(), &policy);
- if (policy == SP_FOREGROUND || policy == SP_AUDIO_APP) {
- // Don't trim the heap if we are a foreground or audio app.
- return;
- }
-
last_trim_time_ms_ = ms_time;
- JNIEnv* env = self->GetJniEnv();
- DCHECK(WellKnownClasses::java_lang_Daemons != NULL);
- DCHECK(WellKnownClasses::java_lang_Daemons_requestHeapTrim != NULL);
- env->CallStaticVoidMethod(WellKnownClasses::java_lang_Daemons,
- WellKnownClasses::java_lang_Daemons_requestHeapTrim);
- CHECK(!env->ExceptionCheck());
+ ListenForProcessStateChange();
+
+ // Trim only if we do not currently care about pause times.
+ if (!care_about_pause_times_) {
+ JNIEnv* env = self->GetJniEnv();
+ DCHECK(WellKnownClasses::java_lang_Daemons != NULL);
+ DCHECK(WellKnownClasses::java_lang_Daemons_requestHeapTrim != NULL);
+ env->CallStaticVoidMethod(WellKnownClasses::java_lang_Daemons,
+ WellKnownClasses::java_lang_Daemons_requestHeapTrim);
+ CHECK(!env->ExceptionCheck());
+ }
}
size_t Heap::Trim() {
diff --git a/runtime/gc/heap.h b/runtime/gc/heap.h
index 54e905b..b3346e8 100644
--- a/runtime/gc/heap.h
+++ b/runtime/gc/heap.h
@@ -28,6 +28,7 @@
#include "gc/collector/gc_type.h"
#include "globals.h"
#include "gtest/gtest.h"
+#include "jni.h"
#include "locks.h"
#include "offsets.h"
#include "safe_map.h"
@@ -100,24 +101,6 @@
};
const HeapVerificationMode kDesiredHeapVerification = kNoHeapVerification;
-// This comes from ActivityManager and needs to be kept in sync.
-enum ProcessState {
- PROCESS_STATE_PERSISTENT = 0,
- PROCESS_STATE_PERSISTENT_UI = 1,
- PROCESS_STATE_TOP = 2,
- PROCESS_STATE_IMPORTANT_FOREGROUND = 3,
- PROCESS_STATE_IMPORTANT_BACKGROUND = 4,
- PROCESS_STATE_BACKUP = 5,
- PROCESS_STATE_HEAVY_WEIGHT = 6,
- PROCESS_STATE_SERVICE = 7,
- PROCESS_STATE_RECEIVER = 8,
- PROCESS_STATE_HOME = 9,
- PROCESS_STATE_LAST_ACTIVITY = 10,
- PROCESS_STATE_CACHED_ACTIVITY = 11,
- PROCESS_STATE_CACHED_ACTIVITY_CLIENT = 12,
- PROCESS_STATE_CACHED_EMPTY = 13,
-};
-
class Heap {
public:
static const size_t kDefaultInitialSize = 2 * MB;
@@ -382,8 +365,8 @@
collector::GcType gc_type)
EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_);
- // Update process state to let the heap know which type of GC to do.
- void UpdateProcessState(ProcessState process_state);
+ // Gets called when we get notified by ActivityThread that the process state has changed.
+ void ListenForProcessStateChange();
// DEPRECATED: Should remove in "near" future when support for multiple image spaces is added.
// Assumes there is only one image space.
@@ -553,6 +536,19 @@
// The watermark at which a GC is performed inside of registerNativeAllocation.
size_t native_footprint_limit_;
+ // Activity manager members.
+ jclass activity_thread_class_;
+ jclass application_thread_class_;
+ jobject activity_thread_;
+ jobject application_thread_;
+ jfieldID last_process_state_id_;
+
+ // Process states which care about pause times.
+ std::set<int> process_state_cares_about_pause_time_;
+
+ // Whether or not we currently care about pause times.
+ bool care_about_pause_times_;
+
// When num_bytes_allocated_ exceeds this amount then a concurrent GC should be requested so that
// it completes ahead of an allocation failing.
size_t concurrent_start_bytes_;
@@ -572,9 +568,6 @@
// Bytes which are allocated and managed by native code but still need to be accounted for.
AtomicInteger native_bytes_allocated_;
- // Current process state, updated by activity manager.
- ProcessState process_state_;
-
// Data structure GC overhead.
AtomicInteger gc_memory_overhead_;
diff --git a/runtime/image_test.cc b/runtime/image_test.cc
index 7f90505..334f7ab 100644
--- a/runtime/image_test.cc
+++ b/runtime/image_test.cc
@@ -49,7 +49,7 @@
#if defined(ART_USE_PORTABLE_COMPILER)
// TODO: we disable this for portable so the test executes in a reasonable amount of time.
// We shouldn't need to do this.
- runtime_->SetSmallMode(true);
+ runtime_->SetCompilerFilter(Runtime::kInterpretOnly);
#endif
compiler_driver_->CompileAll(class_loader, class_linker->GetBootClassPath(), timings);
diff --git a/runtime/leb128.h b/runtime/leb128.h
index ca955b0..6041f8c 100644
--- a/runtime/leb128.h
+++ b/runtime/leb128.h
@@ -24,8 +24,8 @@
// Reads an unsigned LEB128 value, updating the given pointer to point
// just past the end of the read value. This function tolerates
// non-zero high-order bits in the fifth encoded byte.
-static inline uint32_t DecodeUnsignedLeb128(const byte** data) {
- const byte* ptr = *data;
+static inline uint32_t DecodeUnsignedLeb128(const uint8_t** data) {
+ const uint8_t* ptr = *data;
int result = *(ptr++);
if (result > 0x7f) {
int cur = *(ptr++);
@@ -53,15 +53,15 @@
// just past the end of the read value. This function tolerates
// non-zero high-order bits in the fifth encoded byte.
// It is possible for this function to return -1.
-static inline int32_t DecodeUnsignedLeb128P1(const byte** data) {
+static inline int32_t DecodeUnsignedLeb128P1(const uint8_t** data) {
return DecodeUnsignedLeb128(data) - 1;
}
// Reads a signed LEB128 value, updating the given pointer to point
// just past the end of the read value. This function tolerates
// non-zero high-order bits in the fifth encoded byte.
-static inline int32_t DecodeSignedLeb128(const byte** data) {
- const byte* ptr = *data;
+static inline int32_t DecodeSignedLeb128(const uint8_t** data) {
+ const uint8_t* ptr = *data;
int32_t result = *(ptr++);
if (result <= 0x7f) {
result = (result << 25) >> 25;
@@ -103,22 +103,6 @@
return count;
}
-// Writes a 32-bit value in unsigned ULEB128 format.
-// Returns the updated pointer.
-static inline uint8_t* WriteUnsignedLeb128(uint8_t* ptr, uint32_t data) {
- while (true) {
- uint8_t out = data & 0x7f;
- if (out != data) {
- *ptr++ = out | 0x80;
- data >>= 7;
- } else {
- *ptr++ = out;
- break;
- }
- }
- return ptr;
-}
-
} // namespace art
#endif // ART_RUNTIME_LEB128_H_
diff --git a/runtime/mapping_table.h b/runtime/mapping_table.h
new file mode 100644
index 0000000..2162008
--- /dev/null
+++ b/runtime/mapping_table.h
@@ -0,0 +1,196 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ART_RUNTIME_MAPPING_TABLE_H_
+#define ART_RUNTIME_MAPPING_TABLE_H_
+
+#include "base/logging.h"
+#include "leb128.h"
+
+namespace art {
+
+// A utility for processing the raw uleb128 encoded mapping table created by the quick compiler.
+class MappingTable {
+ public:
+ explicit MappingTable(const uint8_t* encoded_map) : encoded_table_(encoded_map) {
+ }
+
+ uint32_t TotalSize() const PURE {
+ const uint8_t* table = encoded_table_;
+ if (table == NULL) {
+ return 0;
+ } else {
+ return DecodeUnsignedLeb128(&table);
+ }
+ }
+
+ uint32_t DexToPcSize() const PURE {
+ const uint8_t* table = encoded_table_;
+ if (table == NULL) {
+ return 0;
+ } else {
+ uint32_t total_size = DecodeUnsignedLeb128(&table);
+ uint32_t pc_to_dex_size = DecodeUnsignedLeb128(&table);
+ return total_size - pc_to_dex_size;
+ }
+ }
+
+ const uint8_t* FirstDexToPcPtr() const {
+ const uint8_t* table = encoded_table_;
+ if (table != NULL) {
+ DecodeUnsignedLeb128(&table); // Total_size, unused.
+ uint32_t pc_to_dex_size = DecodeUnsignedLeb128(&table);
+ for (uint32_t i = 0; i < pc_to_dex_size; ++i) {
+ DecodeUnsignedLeb128(&table); // Move ptr past native PC.
+ DecodeUnsignedLeb128(&table); // Move ptr past dex PC.
+ }
+ }
+ return table;
+ }
+
+ class DexToPcIterator {
+ public:
+ DexToPcIterator(const MappingTable* table, uint32_t element) :
+ table_(table), element_(element), end_(table_->DexToPcSize()), encoded_table_ptr_(NULL),
+ native_pc_offset_(0), dex_pc_(0) {
+ if (element == 0) {
+ encoded_table_ptr_ = table_->FirstDexToPcPtr();
+ native_pc_offset_ = DecodeUnsignedLeb128(&encoded_table_ptr_);
+ dex_pc_ = DecodeUnsignedLeb128(&encoded_table_ptr_);
+ } else {
+ DCHECK_EQ(table_->DexToPcSize(), element);
+ }
+ }
+ uint32_t NativePcOffset() const {
+ return native_pc_offset_;
+ }
+ uint32_t DexPc() const {
+ return dex_pc_;
+ }
+ void operator++() {
+ ++element_;
+ if (element_ != end_) { // Avoid reading beyond the end of the table.
+ native_pc_offset_ = DecodeUnsignedLeb128(&encoded_table_ptr_);
+ dex_pc_ = DecodeUnsignedLeb128(&encoded_table_ptr_);
+ }
+ }
+ bool operator==(const DexToPcIterator& rhs) const {
+ CHECK(table_ == rhs.table_);
+ return element_ == rhs.element_;
+ }
+ bool operator!=(const DexToPcIterator& rhs) const {
+ CHECK(table_ == rhs.table_);
+ return element_ != rhs.element_;
+ }
+
+ private:
+ const MappingTable* const table_; // The original table.
+ uint32_t element_; // A value in the range 0 to end_.
+ const uint32_t end_; // Equal to table_->DexToPcSize().
+ const uint8_t* encoded_table_ptr_; // Either NULL or points to encoded data after this entry.
+ uint32_t native_pc_offset_; // The current value of native pc offset.
+ uint32_t dex_pc_; // The current value of dex pc.
+ };
+
+ DexToPcIterator DexToPcBegin() const {
+ return DexToPcIterator(this, 0);
+ }
+
+ DexToPcIterator DexToPcEnd() const {
+ uint32_t size = DexToPcSize();
+ return DexToPcIterator(this, size);
+ }
+
+ uint32_t PcToDexSize() const PURE {
+ const uint8_t* table = encoded_table_;
+ if (table == NULL) {
+ return 0;
+ } else {
+ DecodeUnsignedLeb128(&table); // Total_size, unused.
+ uint32_t pc_to_dex_size = DecodeUnsignedLeb128(&table);
+ return pc_to_dex_size;
+ }
+ }
+
+ const uint8_t* FirstPcToDexPtr() const {
+ const uint8_t* table = encoded_table_;
+ if (table != NULL) {
+ DecodeUnsignedLeb128(&table); // Total_size, unused.
+ DecodeUnsignedLeb128(&table); // PC to Dex size, unused.
+ }
+ return table;
+ }
+
+ class PcToDexIterator {
+ public:
+ PcToDexIterator(const MappingTable* table, uint32_t element) :
+ table_(table), element_(element), end_(table_->PcToDexSize()), encoded_table_ptr_(NULL),
+ native_pc_offset_(0), dex_pc_(0) {
+ if (element == 0) {
+ encoded_table_ptr_ = table_->FirstPcToDexPtr();
+ native_pc_offset_ = DecodeUnsignedLeb128(&encoded_table_ptr_);
+ dex_pc_ = DecodeUnsignedLeb128(&encoded_table_ptr_);
+ } else {
+ DCHECK_EQ(table_->PcToDexSize(), element);
+ }
+ }
+ uint32_t NativePcOffset() const {
+ return native_pc_offset_;
+ }
+ uint32_t DexPc() const {
+ return dex_pc_;
+ }
+ void operator++() {
+ ++element_;
+ if (element_ != end_) { // Avoid reading beyond the end of the table.
+ native_pc_offset_ = DecodeUnsignedLeb128(&encoded_table_ptr_);
+ dex_pc_ = DecodeUnsignedLeb128(&encoded_table_ptr_);
+ }
+ }
+ bool operator==(const PcToDexIterator& rhs) const {
+ CHECK(table_ == rhs.table_);
+ return element_ == rhs.element_;
+ }
+ bool operator!=(const PcToDexIterator& rhs) const {
+ CHECK(table_ == rhs.table_);
+ return element_ != rhs.element_;
+ }
+
+ private:
+ const MappingTable* const table_; // The original table.
+ uint32_t element_; // A value in the range 0 to PcToDexSize.
+ const uint32_t end_; // Equal to table_->PcToDexSize().
+ const uint8_t* encoded_table_ptr_; // Either NULL or points to encoded data after this entry.
+ uint32_t native_pc_offset_; // The current value of native pc offset.
+ uint32_t dex_pc_; // The current value of dex pc.
+ };
+
+ PcToDexIterator PcToDexBegin() const {
+ return PcToDexIterator(this, 0);
+ }
+
+ PcToDexIterator PcToDexEnd() const {
+ uint32_t size = PcToDexSize();
+ return PcToDexIterator(this, size);
+ }
+
+ private:
+ const uint8_t* const encoded_table_;
+};
+
+} // namespace art
+
+#endif // ART_RUNTIME_MAPPING_TABLE_H_
diff --git a/runtime/mirror/abstract_method-inl.h b/runtime/mirror/abstract_method-inl.h
index 8fde99b..d47b3eb 100644
--- a/runtime/mirror/abstract_method-inl.h
+++ b/runtime/mirror/abstract_method-inl.h
@@ -144,22 +144,22 @@
inline uint32_t AbstractMethod::GetOatMappingTableOffset() const {
DCHECK(!Runtime::Current()->IsStarted());
- return reinterpret_cast<uint32_t>(GetMappingTableRaw());
+ return reinterpret_cast<uint32_t>(GetMappingTable());
}
inline void AbstractMethod::SetOatMappingTableOffset(uint32_t mapping_table_offset) {
DCHECK(!Runtime::Current()->IsStarted());
- SetMappingTable(reinterpret_cast<const uint32_t*>(mapping_table_offset));
+ SetMappingTable(reinterpret_cast<const uint8_t*>(mapping_table_offset));
}
inline uint32_t AbstractMethod::GetOatVmapTableOffset() const {
DCHECK(!Runtime::Current()->IsStarted());
- return reinterpret_cast<uint32_t>(GetVmapTableRaw());
+ return reinterpret_cast<uint32_t>(GetVmapTable());
}
inline void AbstractMethod::SetOatVmapTableOffset(uint32_t vmap_table_offset) {
DCHECK(!Runtime::Current()->IsStarted());
- SetVmapTable(reinterpret_cast<uint16_t*>(vmap_table_offset));
+ SetVmapTable(reinterpret_cast<uint8_t*>(vmap_table_offset));
}
inline void AbstractMethod::SetOatNativeGcMapOffset(uint32_t gc_map_offset) {
diff --git a/runtime/mirror/abstract_method.cc b/runtime/mirror/abstract_method.cc
index 93065e7..b3db5c2 100644
--- a/runtime/mirror/abstract_method.cc
+++ b/runtime/mirror/abstract_method.cc
@@ -24,6 +24,7 @@
#include "gc/accounting/card_table-inl.h"
#include "interpreter/interpreter.h"
#include "jni_internal.h"
+#include "mapping_table.h"
#include "object-inl.h"
#include "object_array.h"
#include "object_array-inl.h"
@@ -157,43 +158,27 @@
return pc - reinterpret_cast<uintptr_t>(code);
}
-// Find the lowest-address native safepoint pc for a given dex pc
-uintptr_t AbstractMethod::ToFirstNativeSafepointPc(const uint32_t dex_pc) const {
-#if !defined(ART_USE_PORTABLE_COMPILER)
- const uint32_t* mapping_table = GetPcToDexMappingTable();
- if (mapping_table == NULL) {
- DCHECK(IsNative() || IsCalleeSaveMethod() || IsProxyMethod()) << PrettyMethod(this);
- return DexFile::kDexNoIndex; // Special no mapping case
- }
- size_t mapping_table_length = GetPcToDexMappingTableLength();
- for (size_t i = 0; i < mapping_table_length; i += 2) {
- if (mapping_table[i + 1] == dex_pc) {
- const void* code = Runtime::Current()->GetInstrumentation()->GetQuickCodeFor(this);
- return mapping_table[i] + reinterpret_cast<uintptr_t>(code);
- }
- }
- LOG(FATAL) << "Failed to find native offset for dex pc 0x" << std::hex << dex_pc
- << " in " << PrettyMethod(this);
- return 0;
-#else
- // Compiler LLVM doesn't use the machine pc, we just use dex pc instead.
- return static_cast<uint32_t>(dex_pc);
-#endif
-}
-
uint32_t AbstractMethod::ToDexPc(const uintptr_t pc) const {
#if !defined(ART_USE_PORTABLE_COMPILER)
- const uint32_t* mapping_table = GetPcToDexMappingTable();
- if (mapping_table == NULL) {
+ MappingTable table(GetMappingTable());
+ if (table.TotalSize() == 0) {
DCHECK(IsNative() || IsCalleeSaveMethod() || IsProxyMethod()) << PrettyMethod(this);
return DexFile::kDexNoIndex; // Special no mapping case
}
- size_t mapping_table_length = GetPcToDexMappingTableLength();
const void* code = Runtime::Current()->GetInstrumentation()->GetQuickCodeFor(this);
uint32_t sought_offset = pc - reinterpret_cast<uintptr_t>(code);
- for (size_t i = 0; i < mapping_table_length; i += 2) {
- if (mapping_table[i] == sought_offset) {
- return mapping_table[i + 1];
+ // Assume the caller wants a pc-to-dex mapping so check here first.
+ typedef MappingTable::PcToDexIterator It;
+ for (It cur = table.PcToDexBegin(), end = table.PcToDexEnd(); cur != end; ++cur) {
+ if (cur.NativePcOffset() == sought_offset) {
+ return cur.DexPc();
+ }
+ }
+ // Now check dex-to-pc mappings.
+ typedef MappingTable::DexToPcIterator It2;
+ for (It2 cur = table.DexToPcBegin(), end = table.DexToPcEnd(); cur != end; ++cur) {
+ if (cur.NativePcOffset() == sought_offset) {
+ return cur.DexPc();
}
}
LOG(FATAL) << "Failed to find Dex offset for PC offset " << reinterpret_cast<void*>(sought_offset)
@@ -207,21 +192,28 @@
}
uintptr_t AbstractMethod::ToNativePc(const uint32_t dex_pc) const {
- const uint32_t* mapping_table = GetDexToPcMappingTable();
- if (mapping_table == NULL) {
+ MappingTable table(GetMappingTable());
+ if (table.TotalSize() == 0) {
DCHECK_EQ(dex_pc, 0U);
return 0; // Special no mapping/pc == 0 case
}
- size_t mapping_table_length = GetDexToPcMappingTableLength();
- for (size_t i = 0; i < mapping_table_length; i += 2) {
- uint32_t map_offset = mapping_table[i];
- uint32_t map_dex_offset = mapping_table[i + 1];
- if (map_dex_offset == dex_pc) {
+ // Assume the caller wants a dex-to-pc mapping so check here first.
+ typedef MappingTable::DexToPcIterator It;
+ for (It cur = table.DexToPcBegin(), end = table.DexToPcEnd(); cur != end; ++cur) {
+ if (cur.DexPc() == dex_pc) {
const void* code = Runtime::Current()->GetInstrumentation()->GetQuickCodeFor(this);
- return reinterpret_cast<uintptr_t>(code) + map_offset;
+ return reinterpret_cast<uintptr_t>(code) + cur.NativePcOffset();
}
}
- LOG(FATAL) << "Looking up Dex PC not contained in method, 0x" << std::hex << dex_pc
+ // Now check pc-to-dex mappings.
+ typedef MappingTable::PcToDexIterator It2;
+ for (It2 cur = table.PcToDexBegin(), end = table.PcToDexEnd(); cur != end; ++cur) {
+ if (cur.DexPc() == dex_pc) {
+ const void* code = Runtime::Current()->GetInstrumentation()->GetQuickCodeFor(this);
+ return reinterpret_cast<uintptr_t>(code) + cur.NativePcOffset();
+ }
+ }
+ LOG(FATAL) << "Failed to find native offset for dex pc 0x" << std::hex << dex_pc
<< " in " << PrettyMethod(this);
return 0;
}
diff --git a/runtime/mirror/abstract_method.h b/runtime/mirror/abstract_method.h
index 2e6e262..5b8c61c 100644
--- a/runtime/mirror/abstract_method.h
+++ b/runtime/mirror/abstract_method.h
@@ -246,54 +246,13 @@
return OFFSET_OF_OBJECT_MEMBER(AbstractMethod, entry_point_from_compiled_code_);
}
- const uint32_t* GetMappingTable() const {
- const uint32_t* map = GetMappingTableRaw();
- if (map == NULL) {
- return map;
- }
- return map + 1;
+ // Callers should wrap the uint8_t* in a MappingTable instance for convenient access.
+ const uint8_t* GetMappingTable() const {
+ return GetFieldPtr<const uint8_t*>(OFFSET_OF_OBJECT_MEMBER(AbstractMethod, mapping_table_), false);
}
- uint32_t GetPcToDexMappingTableLength() const {
- const uint32_t* map = GetMappingTableRaw();
- if (map == NULL) {
- return 0;
- }
- return map[2];
- }
-
- const uint32_t* GetPcToDexMappingTable() const {
- const uint32_t* map = GetMappingTableRaw();
- if (map == NULL) {
- return map;
- }
- return map + 3;
- }
-
-
- uint32_t GetDexToPcMappingTableLength() const {
- const uint32_t* map = GetMappingTableRaw();
- if (map == NULL) {
- return 0;
- }
- return map[1] - map[2];
- }
-
- const uint32_t* GetDexToPcMappingTable() const {
- const uint32_t* map = GetMappingTableRaw();
- if (map == NULL) {
- return map;
- }
- return map + 3 + map[2];
- }
-
-
- const uint32_t* GetMappingTableRaw() const {
- return GetFieldPtr<const uint32_t*>(OFFSET_OF_OBJECT_MEMBER(AbstractMethod, mapping_table_), false);
- }
-
- void SetMappingTable(const uint32_t* mapping_table) {
- SetFieldPtr<const uint32_t*>(OFFSET_OF_OBJECT_MEMBER(AbstractMethod, mapping_table_),
+ void SetMappingTable(const uint8_t* mapping_table) {
+ SetFieldPtr<const uint8_t*>(OFFSET_OF_OBJECT_MEMBER(AbstractMethod, mapping_table_),
mapping_table, false);
}
@@ -301,13 +260,13 @@
void SetOatMappingTableOffset(uint32_t mapping_table_offset);
- // Callers should wrap the uint16_t* in a VmapTable instance for convenient access.
- const uint16_t* GetVmapTableRaw() const {
- return GetFieldPtr<const uint16_t*>(OFFSET_OF_OBJECT_MEMBER(AbstractMethod, vmap_table_), false);
+ // Callers should wrap the uint8_t* in a VmapTable instance for convenient access.
+ const uint8_t* GetVmapTable() const {
+ return GetFieldPtr<const uint8_t*>(OFFSET_OF_OBJECT_MEMBER(AbstractMethod, vmap_table_), false);
}
- void SetVmapTable(const uint16_t* vmap_table) {
- SetFieldPtr<const uint16_t*>(OFFSET_OF_OBJECT_MEMBER(AbstractMethod, vmap_table_), vmap_table, false);
+ void SetVmapTable(const uint8_t* vmap_table) {
+ SetFieldPtr<const uint8_t*>(OFFSET_OF_OBJECT_MEMBER(AbstractMethod, vmap_table_), vmap_table, false);
}
uint32_t GetOatVmapTableOffset() const;
@@ -403,10 +362,6 @@
// Converts a dex PC to a native PC.
uintptr_t ToNativePc(const uint32_t dex_pc) const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
- // Converts a dex PC to the first corresponding safepoint PC.
- uintptr_t ToFirstNativeSafepointPc(const uint32_t dex_pc)
- const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
-
// Find the catch block for the given exception type and dex_pc. When a catch block is found,
// indicates whether the found catch block is responsible for clearing the exception or whether
// a move-exception instruction is present.
diff --git a/runtime/native/dalvik_system_VMRuntime.cc b/runtime/native/dalvik_system_VMRuntime.cc
index dab9cda..5fb53df 100644
--- a/runtime/native/dalvik_system_VMRuntime.cc
+++ b/runtime/native/dalvik_system_VMRuntime.cc
@@ -207,10 +207,6 @@
Runtime::Current()->GetHeap()->ConcurrentGC(self);
}
-static void VMRuntime_updateProcessState(JNIEnv* env, jobject, jint processState) {
- Runtime::Current()->GetHeap()->UpdateProcessState(static_cast<gc::ProcessState>(processState));
-}
-
static JNINativeMethod gMethods[] = {
NATIVE_METHOD(VMRuntime, addressOf, "(Ljava/lang/Object;)J"),
NATIVE_METHOD(VMRuntime, bootClassPath, "()Ljava/lang/String;"),
@@ -230,7 +226,6 @@
NATIVE_METHOD(VMRuntime, trimHeap, "()V"),
NATIVE_METHOD(VMRuntime, vmVersion, "()Ljava/lang/String;"),
NATIVE_METHOD(VMRuntime, vmLibrary, "()Ljava/lang/String;"),
- NATIVE_METHOD(VMRuntime, updateProcessState, "(I)V"),
};
void register_dalvik_system_VMRuntime(JNIEnv* env) {
diff --git a/runtime/oat_file.cc b/runtime/oat_file.cc
index 7bffc8c..93e98ad 100644
--- a/runtime/oat_file.cc
+++ b/runtime/oat_file.cc
@@ -28,6 +28,7 @@
#include "mirror/object-inl.h"
#include "os.h"
#include "utils.h"
+#include "vmap_table.h"
namespace art {
@@ -416,9 +417,10 @@
DCHECK_EQ(0U, static_cast<uint32_t>(__builtin_popcount(core_spill_mask_) +
__builtin_popcount(fp_spill_mask_)));
} else {
- const uint16_t* vmap_table_ = reinterpret_cast<const uint16_t*>(begin_ + vmap_table_offset_);
- DCHECK_EQ(vmap_table_[0], static_cast<uint32_t>(__builtin_popcount(core_spill_mask_) +
- __builtin_popcount(fp_spill_mask_)));
+ VmapTable vmap_table(reinterpret_cast<const uint8_t*>(begin_ + vmap_table_offset_));
+
+ DCHECK_EQ(vmap_table.Size(), static_cast<uint32_t>(__builtin_popcount(core_spill_mask_) +
+ __builtin_popcount(fp_spill_mask_)));
}
} else {
DCHECK_EQ(vmap_table_offset_, 0U);
diff --git a/runtime/oat_file.h b/runtime/oat_file.h
index fff6c8a..6503014 100644
--- a/runtime/oat_file.h
+++ b/runtime/oat_file.h
@@ -97,11 +97,11 @@
const void* GetCode() const;
uint32_t GetCodeSize() const;
- const uint32_t* GetMappingTable() const {
- return GetOatPointer<const uint32_t*>(mapping_table_offset_);
+ const uint8_t* GetMappingTable() const {
+ return GetOatPointer<const uint8_t*>(mapping_table_offset_);
}
- const uint16_t* GetVmapTable() const {
- return GetOatPointer<const uint16_t*>(vmap_table_offset_);
+ const uint8_t* GetVmapTable() const {
+ return GetOatPointer<const uint8_t*>(vmap_table_offset_);
}
const uint8_t* GetNativeGcMap() const {
return GetOatPointer<const uint8_t*>(native_gc_map_offset_);
diff --git a/runtime/stack.cc b/runtime/stack.cc
index 7f3f40c..e1a752a 100644
--- a/runtime/stack.cc
+++ b/runtime/stack.cc
@@ -24,6 +24,7 @@
#include "object_utils.h"
#include "thread_list.h"
#include "throw_location.h"
+#include "vmap_table.h"
namespace art {
@@ -135,10 +136,10 @@
if (cur_quick_frame_ != NULL) {
DCHECK(context_ != NULL); // You can't reliably read registers without a context.
DCHECK(m == GetMethod());
- const VmapTable vmap_table(m->GetVmapTableRaw());
+ const VmapTable vmap_table(m->GetVmapTable());
uint32_t vmap_offset;
// TODO: IsInContext stops before spotting floating point registers.
- if (vmap_table.IsInContext(vreg, vmap_offset, kind)) {
+ if (vmap_table.IsInContext(vreg, kind, &vmap_offset)) {
bool is_float = (kind == kFloatVReg) || (kind == kDoubleLoVReg) || (kind == kDoubleHiVReg);
uint32_t spill_mask = is_float ? m->GetFpSpillMask()
: m->GetCoreSpillMask();
@@ -160,10 +161,10 @@
if (cur_quick_frame_ != NULL) {
DCHECK(context_ != NULL); // You can't reliably write registers without a context.
DCHECK(m == GetMethod());
- const VmapTable vmap_table(m->GetVmapTableRaw());
+ const VmapTable vmap_table(m->GetVmapTable());
uint32_t vmap_offset;
// TODO: IsInContext stops before spotting floating point registers.
- if (vmap_table.IsInContext(vreg, vmap_offset, kind)) {
+ if (vmap_table.IsInContext(vreg, kind, &vmap_offset)) {
bool is_float = (kind == kFloatVReg) || (kind == kDoubleLoVReg) || (kind == kDoubleHiVReg);
uint32_t spill_mask = is_float ? m->GetFpSpillMask() : m->GetCoreSpillMask();
const uint32_t reg = vmap_table.ComputeRegister(spill_mask, vmap_offset, kReferenceVReg);
diff --git a/runtime/stack.h b/runtime/stack.h
index de93846..388e401 100644
--- a/runtime/stack.h
+++ b/runtime/stack.h
@@ -571,78 +571,6 @@
Context* const context_;
};
-class VmapTable {
- public:
- explicit VmapTable(const uint16_t* table) : table_(table) {
- }
-
- uint16_t operator[](size_t i) const {
- return table_[i + 1];
- }
-
- size_t size() const {
- return table_[0];
- }
-
- // Is the dex register 'vreg' in the context or on the stack? Should not be called when the
- // 'kind' is unknown or constant.
- bool IsInContext(size_t vreg, uint32_t& vmap_offset, VRegKind kind) const {
- DCHECK(kind == kReferenceVReg || kind == kIntVReg || kind == kFloatVReg ||
- kind == kLongLoVReg || kind == kLongHiVReg || kind == kDoubleLoVReg ||
- kind == kDoubleHiVReg || kind == kImpreciseConstant);
- vmap_offset = 0xEBAD0FF5;
- // TODO: take advantage of the registers being ordered
- // TODO: we treat kImpreciseConstant as an integer below, need to ensure that such values
- // are never promoted to floating point registers.
- bool is_float = (kind == kFloatVReg) || (kind == kDoubleLoVReg) || (kind == kDoubleHiVReg);
- bool in_floats = false;
- for (size_t i = 0; i < size(); ++i) {
- // Stop if we find what we are are looking for.
- if ((table_[i + 1] == vreg) && (in_floats == is_float)) {
- vmap_offset = i;
- return true;
- }
- // 0xffff is the marker for LR (return PC on x86), following it are spilled float registers.
- if (table_[i + 1] == 0xffff) {
- in_floats = true;
- }
- }
- return false;
- }
-
- // Compute the register number that corresponds to the entry in the vmap (vmap_offset, computed
- // by IsInContext above). If the kind is floating point then the result will be a floating point
- // register number, otherwise it will be an integer register number.
- uint32_t ComputeRegister(uint32_t spill_mask, uint32_t vmap_offset, VRegKind kind) const {
- // Compute the register we need to load from the context.
- DCHECK(kind == kReferenceVReg || kind == kIntVReg || kind == kFloatVReg ||
- kind == kLongLoVReg || kind == kLongHiVReg || kind == kDoubleLoVReg ||
- kind == kDoubleHiVReg || kind == kImpreciseConstant);
- // TODO: we treat kImpreciseConstant as an integer below, need to ensure that such values
- // are never promoted to floating point registers.
- bool is_float = (kind == kFloatVReg) || (kind == kDoubleLoVReg) || (kind == kDoubleHiVReg);
- uint32_t matches = 0;
- if (is_float) {
- while (table_[matches] != 0xffff) {
- matches++;
- }
- }
- CHECK_LT(vmap_offset - matches, static_cast<uint32_t>(__builtin_popcount(spill_mask)));
- uint32_t spill_shifts = 0;
- while (matches != (vmap_offset + 1)) {
- DCHECK_NE(spill_mask, 0u);
- matches += spill_mask & 1; // Add 1 if the low bit is set
- spill_mask >>= 1;
- spill_shifts++;
- }
- spill_shifts--; // wind back one as we want the last match
- return spill_shifts;
- }
-
- private:
- const uint16_t* table_;
-};
-
} // namespace art
#endif // ART_RUNTIME_STACK_H_
diff --git a/runtime/thread.cc b/runtime/thread.cc
index c79caa2..07a003d 100644
--- a/runtime/thread.cc
+++ b/runtime/thread.cc
@@ -66,6 +66,7 @@
#include "utils.h"
#include "verifier/dex_gc_map.h"
#include "verifier/method_verifier.h"
+#include "vmap_table.h"
#include "well_known_classes.h"
namespace art {
@@ -2043,7 +2044,7 @@
if (num_regs > 0) {
const uint8_t* reg_bitmap = map.FindBitMap(GetNativePcOffset());
DCHECK(reg_bitmap != NULL);
- const VmapTable vmap_table(m->GetVmapTableRaw());
+ const VmapTable vmap_table(m->GetVmapTable());
uint32_t core_spills = m->GetCoreSpillMask();
uint32_t fp_spills = m->GetFpSpillMask();
size_t frame_size = m->GetFrameSizeInBytes();
@@ -2055,7 +2056,7 @@
if (TestBitmap(reg, reg_bitmap)) {
uint32_t vmap_offset;
mirror::Object* ref;
- if (vmap_table.IsInContext(reg, vmap_offset, kReferenceVReg)) {
+ if (vmap_table.IsInContext(reg, kReferenceVReg, &vmap_offset)) {
uintptr_t val = GetGPR(vmap_table.ComputeRegister(core_spills, vmap_offset,
kReferenceVReg));
ref = reinterpret_cast<mirror::Object*>(val);
diff --git a/runtime/vmap_table.h b/runtime/vmap_table.h
new file mode 100644
index 0000000..abc50b9
--- /dev/null
+++ b/runtime/vmap_table.h
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ART_RUNTIME_VMAP_TABLE_H_
+#define ART_RUNTIME_VMAP_TABLE_H_
+
+#include "base/logging.h"
+#include "leb128.h"
+#include "stack.h"
+
+namespace art {
+
+class VmapTable {
+ public:
+ explicit VmapTable(const uint8_t* table) : table_(table) {
+ }
+
+ // Look up nth entry, not called from performance critical code.
+ uint16_t operator[](size_t n) const {
+ const uint8_t* table = table_;
+ size_t size = DecodeUnsignedLeb128(&table);
+ CHECK_LT(n, size);
+ uint16_t entry = DecodeUnsignedLeb128(&table);
+ for (size_t i = 0; i < n; ++i) {
+ entry = DecodeUnsignedLeb128(&table);
+ }
+ return entry;
+ }
+
+ size_t Size() const {
+ const uint8_t* table = table_;
+ return DecodeUnsignedLeb128(&table);
+ }
+
+ // Is the dex register 'vreg' in the context or on the stack? Should not be called when the
+ // 'kind' is unknown or constant.
+ bool IsInContext(size_t vreg, VRegKind kind, uint32_t* vmap_offset) const {
+ DCHECK(kind == kReferenceVReg || kind == kIntVReg || kind == kFloatVReg ||
+ kind == kLongLoVReg || kind == kLongHiVReg || kind == kDoubleLoVReg ||
+ kind == kDoubleHiVReg || kind == kImpreciseConstant);
+ *vmap_offset = 0xEBAD0FF5;
+ // TODO: take advantage of the registers being ordered
+ // TODO: we treat kImpreciseConstant as an integer below, need to ensure that such values
+ // are never promoted to floating point registers.
+ bool is_float = (kind == kFloatVReg) || (kind == kDoubleLoVReg) || (kind == kDoubleHiVReg);
+ bool in_floats = false;
+ const uint8_t* table = table_;
+ size_t end = DecodeUnsignedLeb128(&table);
+ for (size_t i = 0; i < end; ++i) {
+ // Stop if we find what we are are looking for.
+ uint16_t entry = DecodeUnsignedLeb128(&table);
+ if ((entry == vreg) && (in_floats == is_float)) {
+ *vmap_offset = i;
+ return true;
+ }
+ // 0xffff is the marker for LR (return PC on x86), following it are spilled float registers.
+ if (entry == 0xffff) {
+ in_floats = true;
+ }
+ }
+ return false;
+ }
+
+ // Compute the register number that corresponds to the entry in the vmap (vmap_offset, computed
+ // by IsInContext above). If the kind is floating point then the result will be a floating point
+ // register number, otherwise it will be an integer register number.
+ uint32_t ComputeRegister(uint32_t spill_mask, uint32_t vmap_offset, VRegKind kind) const {
+ // Compute the register we need to load from the context.
+ DCHECK(kind == kReferenceVReg || kind == kIntVReg || kind == kFloatVReg ||
+ kind == kLongLoVReg || kind == kLongHiVReg || kind == kDoubleLoVReg ||
+ kind == kDoubleHiVReg || kind == kImpreciseConstant);
+ // TODO: we treat kImpreciseConstant as an integer below, need to ensure that such values
+ // are never promoted to floating point registers.
+ bool is_float = (kind == kFloatVReg) || (kind == kDoubleLoVReg) || (kind == kDoubleHiVReg);
+ uint32_t matches = 0;
+ if (UNLIKELY(is_float)) {
+ const uint8_t* table = table_;
+ DecodeUnsignedLeb128(&table); // Skip size.
+ while (DecodeUnsignedLeb128(&table) != 0xffff) {
+ matches++;
+ }
+ matches++;
+ }
+ CHECK_LT(vmap_offset - matches, static_cast<uint32_t>(__builtin_popcount(spill_mask)));
+ uint32_t spill_shifts = 0;
+ while (matches != (vmap_offset + 1)) {
+ DCHECK_NE(spill_mask, 0u);
+ matches += spill_mask & 1; // Add 1 if the low bit is set
+ spill_mask >>= 1;
+ spill_shifts++;
+ }
+ spill_shifts--; // wind back one as we want the last match
+ return spill_shifts;
+ }
+
+ private:
+ const uint8_t* const table_;
+};
+
+} // namespace art
+
+#endif // ART_RUNTIME_VMAP_TABLE_H_
diff --git a/test/ReferenceMap/stack_walk_refmap_jni.cc b/test/ReferenceMap/stack_walk_refmap_jni.cc
index 3b5d80d..84f5f2e 100644
--- a/test/ReferenceMap/stack_walk_refmap_jni.cc
+++ b/test/ReferenceMap/stack_walk_refmap_jni.cc
@@ -73,31 +73,31 @@
// we know the Dex registers with live reference values. Assert that what we
// find is what is expected.
if (m_name.compare("f") == 0) {
- ref_bitmap = map.FindBitMap(m->NativePcOffset(m->ToFirstNativeSafepointPc(0x03U)));
+ ref_bitmap = map.FindBitMap(m->NativePcOffset(m->ToNativePc(0x03U)));
CHECK(ref_bitmap);
CHECK_REGS_CONTAIN_REFS(8); // v8: this
- ref_bitmap = map.FindBitMap(m->NativePcOffset(m->ToFirstNativeSafepointPc(0x06U)));
+ ref_bitmap = map.FindBitMap(m->NativePcOffset(m->ToNativePc(0x06U)));
CHECK(ref_bitmap);
CHECK_REGS_CONTAIN_REFS(8, 1); // v8: this, v1: x
- ref_bitmap = map.FindBitMap(m->NativePcOffset(m->ToFirstNativeSafepointPc(0x08U)));
+ ref_bitmap = map.FindBitMap(m->NativePcOffset(m->ToNativePc(0x08U)));
CHECK(ref_bitmap);
CHECK_REGS_CONTAIN_REFS(8, 3, 1); // v8: this, v3: y, v1: x
- ref_bitmap = map.FindBitMap(m->NativePcOffset(m->ToFirstNativeSafepointPc(0x0cU)));
+ ref_bitmap = map.FindBitMap(m->NativePcOffset(m->ToNativePc(0x0cU)));
CHECK(ref_bitmap);
CHECK_REGS_CONTAIN_REFS(8, 3, 1); // v8: this, v3: y, v1: x
- ref_bitmap = map.FindBitMap(m->NativePcOffset(m->ToFirstNativeSafepointPc(0x0eU)));
+ ref_bitmap = map.FindBitMap(m->NativePcOffset(m->ToNativePc(0x0eU)));
CHECK(ref_bitmap);
CHECK_REGS_CONTAIN_REFS(8, 3, 1); // v8: this, v3: y, v1: x
- ref_bitmap = map.FindBitMap(m->NativePcOffset(m->ToFirstNativeSafepointPc(0x10U)));
+ ref_bitmap = map.FindBitMap(m->NativePcOffset(m->ToNativePc(0x10U)));
CHECK(ref_bitmap);
CHECK_REGS_CONTAIN_REFS(8, 3, 1); // v8: this, v3: y, v1: x
- ref_bitmap = map.FindBitMap(m->NativePcOffset(m->ToFirstNativeSafepointPc(0x13U)));
+ ref_bitmap = map.FindBitMap(m->NativePcOffset(m->ToNativePc(0x13U)));
CHECK(ref_bitmap);
// v2 is added because of the instruction at DexPC 0024. Object merges with 0 is Object. See:
// 0024: move-object v3, v2
@@ -107,45 +107,45 @@
// We eliminate the non-live registers at a return, so only v3 is live:
CHECK_REGS_CONTAIN_REFS(3); // v3: y
- ref_bitmap = map.FindBitMap(m->NativePcOffset(m->ToFirstNativeSafepointPc(0x18U)));
+ ref_bitmap = map.FindBitMap(m->NativePcOffset(m->ToNativePc(0x18U)));
CHECK(ref_bitmap);
CHECK_REGS_CONTAIN_REFS(8, 2, 1, 0); // v8: this, v2: y, v1: x, v0: ex
- ref_bitmap = map.FindBitMap(m->NativePcOffset(m->ToFirstNativeSafepointPc(0x1aU)));
+ ref_bitmap = map.FindBitMap(m->NativePcOffset(m->ToNativePc(0x1aU)));
CHECK(ref_bitmap);
CHECK_REGS_CONTAIN_REFS(8, 5, 2, 1, 0); // v8: this, v5: x[1], v2: y, v1: x, v0: ex
- ref_bitmap = map.FindBitMap(m->NativePcOffset(m->ToFirstNativeSafepointPc(0x1dU)));
+ ref_bitmap = map.FindBitMap(m->NativePcOffset(m->ToNativePc(0x1dU)));
CHECK(ref_bitmap);
CHECK_REGS_CONTAIN_REFS(8, 5, 2, 1, 0); // v8: this, v5: x[1], v2: y, v1: x, v0: ex
- ref_bitmap = map.FindBitMap(m->NativePcOffset(m->ToFirstNativeSafepointPc(0x1fU)));
+ ref_bitmap = map.FindBitMap(m->NativePcOffset(m->ToNativePc(0x1fU)));
CHECK(ref_bitmap);
// v5 is removed from the root set because there is a "merge" operation.
// See 0015: if-nez v2, 001f.
CHECK_REGS_CONTAIN_REFS(8, 2, 1, 0); // v8: this, v2: y, v1: x, v0: ex
- ref_bitmap = map.FindBitMap(m->NativePcOffset(m->ToFirstNativeSafepointPc(0x21U)));
+ ref_bitmap = map.FindBitMap(m->NativePcOffset(m->ToNativePc(0x21U)));
CHECK(ref_bitmap);
CHECK_REGS_CONTAIN_REFS(8, 2, 1, 0); // v8: this, v2: y, v1: x, v0: ex
- ref_bitmap = map.FindBitMap(m->NativePcOffset(m->ToFirstNativeSafepointPc(0x27U)));
+ ref_bitmap = map.FindBitMap(m->NativePcOffset(m->ToNativePc(0x27U)));
CHECK(ref_bitmap);
CHECK_REGS_CONTAIN_REFS(8, 4, 2, 1); // v8: this, v4: ex, v2: y, v1: x
- ref_bitmap = map.FindBitMap(m->NativePcOffset(m->ToFirstNativeSafepointPc(0x29U)));
+ ref_bitmap = map.FindBitMap(m->NativePcOffset(m->ToNativePc(0x29U)));
CHECK(ref_bitmap);
CHECK_REGS_CONTAIN_REFS(8, 4, 2, 1); // v8: this, v4: ex, v2: y, v1: x
- ref_bitmap = map.FindBitMap(m->NativePcOffset(m->ToFirstNativeSafepointPc(0x2cU)));
+ ref_bitmap = map.FindBitMap(m->NativePcOffset(m->ToNativePc(0x2cU)));
CHECK(ref_bitmap);
CHECK_REGS_CONTAIN_REFS(8, 4, 2, 1); // v8: this, v4: ex, v2: y, v1: x
- ref_bitmap = map.FindBitMap(m->NativePcOffset(m->ToFirstNativeSafepointPc(0x2fU)));
+ ref_bitmap = map.FindBitMap(m->NativePcOffset(m->ToNativePc(0x2fU)));
CHECK(ref_bitmap);
CHECK_REGS_CONTAIN_REFS(8, 4, 3, 2, 1); // v8: this, v4: ex, v3: y, v2: y, v1: x
- ref_bitmap = map.FindBitMap(m->NativePcOffset(m->ToFirstNativeSafepointPc(0x32U)));
+ ref_bitmap = map.FindBitMap(m->NativePcOffset(m->ToNativePc(0x32U)));
CHECK(ref_bitmap);
CHECK_REGS_CONTAIN_REFS(8, 3, 2, 1, 0); // v8: this, v3: y, v2: y, v1: x, v0: ex
}