diff options
130 files changed, 2098 insertions, 2536 deletions
diff --git a/compiler/driver/compiler_driver.cc b/compiler/driver/compiler_driver.cc index 16f2d0f2cc..653e9edb45 100644 --- a/compiler/driver/compiler_driver.cc +++ b/compiler/driver/compiler_driver.cc @@ -391,7 +391,7 @@ static optimizer::DexToDexCompiler::CompilationLevel GetDexToDexCompilationLevel DCHECK(driver.GetCompilerOptions().IsQuickeningCompilationEnabled()); const char* descriptor = dex_file.GetClassDescriptor(class_def); ClassLinker* class_linker = runtime->GetClassLinker(); - mirror::Class* klass = class_linker->FindClass(self, descriptor, class_loader); + ObjPtr<mirror::Class> klass = class_linker->FindClass(self, descriptor, class_loader); if (klass == nullptr) { CHECK(self->IsExceptionPending()); self->ClearException(); diff --git a/compiler/driver/compiler_driver_test.cc b/compiler/driver/compiler_driver_test.cc index 856cb36266..491e61f9b5 100644 --- a/compiler/driver/compiler_driver_test.cc +++ b/compiler/driver/compiler_driver_test.cc @@ -88,7 +88,7 @@ class CompilerDriverTest : public CommonCompilerTest { StackHandleScope<1> hs(soa.Self()); Handle<mirror::ClassLoader> loader( hs.NewHandle(soa.Decode<mirror::ClassLoader>(class_loader))); - mirror::Class* c = class_linker->FindClass(soa.Self(), descriptor, loader); + ObjPtr<mirror::Class> c = class_linker->FindClass(soa.Self(), descriptor, loader); CHECK(c != nullptr); const auto pointer_size = class_linker->GetImagePointerSize(); for (auto& m : c->GetMethods(pointer_size)) { @@ -115,14 +115,14 @@ TEST_F(CompilerDriverTest, DISABLED_LARGE_CompileDexLibCore) { ObjPtr<mirror::DexCache> dex_cache = class_linker_->FindDexCache(soa.Self(), dex); EXPECT_EQ(dex.NumStringIds(), dex_cache->NumStrings()); for (size_t i = 0; i < dex_cache->NumStrings(); i++) { - const mirror::String* string = dex_cache->GetResolvedString(dex::StringIndex(i)); + const ObjPtr<mirror::String> string = dex_cache->GetResolvedString(dex::StringIndex(i)); EXPECT_TRUE(string != nullptr) << "string_idx=" << i; } EXPECT_EQ(dex.NumTypeIds(), dex_cache->NumResolvedTypes()); for (size_t i = 0; i < dex_cache->NumResolvedTypes(); i++) { - mirror::Class* type = dex_cache->GetResolvedType(dex::TypeIndex(i)); - EXPECT_TRUE(type != nullptr) << "type_idx=" << i - << " " << dex.GetTypeDescriptor(dex.GetTypeId(dex::TypeIndex(i))); + const ObjPtr<mirror::Class> type = dex_cache->GetResolvedType(dex::TypeIndex(i)); + EXPECT_TRUE(type != nullptr) + << "type_idx=" << i << " " << dex.GetTypeDescriptor(dex.GetTypeId(dex::TypeIndex(i))); } EXPECT_TRUE(dex_cache->StaticMethodSize() == dex_cache->NumResolvedMethods() || dex.NumMethodIds() == dex_cache->NumResolvedMethods()); @@ -228,7 +228,7 @@ class CompilerDriverProfileTest : public CompilerDriverTest { StackHandleScope<1> hs(self); Handle<mirror::ClassLoader> h_loader( hs.NewHandle(soa.Decode<mirror::ClassLoader>(class_loader))); - mirror::Class* klass = class_linker->FindClass(self, clazz.c_str(), h_loader); + ObjPtr<mirror::Class> klass = class_linker->FindClass(self, clazz.c_str(), h_loader); ASSERT_NE(klass, nullptr); const auto pointer_size = class_linker->GetImagePointerSize(); @@ -289,7 +289,7 @@ class CompilerDriverVerifyTest : public CompilerDriverTest { StackHandleScope<1> hs(self); Handle<mirror::ClassLoader> h_loader( hs.NewHandle(soa.Decode<mirror::ClassLoader>(class_loader))); - mirror::Class* klass = class_linker->FindClass(self, clazz.c_str(), h_loader); + ObjPtr<mirror::Class> klass = class_linker->FindClass(self, clazz.c_str(), h_loader); ASSERT_NE(klass, nullptr); EXPECT_TRUE(klass->IsVerified()); diff --git a/compiler/exception_test.cc b/compiler/exception_test.cc index da1db4593b..15c07870a1 100644 --- a/compiler/exception_test.cc +++ b/compiler/exception_test.cc @@ -34,6 +34,7 @@ #include "mirror/object_array-inl.h" #include "mirror/stack_trace_element.h" #include "oat_quick_method_header.h" +#include "obj_ptr-inl.h" #include "optimizing/stack_map_stream.h" #include "runtime-inl.h" #include "scoped_thread_state_change-inl.h" @@ -122,7 +123,7 @@ class ExceptionTest : public CommonRuntimeTest { ArtMethod* method_g_; private: - mirror::Class* my_klass_; + ObjPtr<mirror::Class> my_klass_; }; TEST_F(ExceptionTest, FindCatchHandler) { diff --git a/compiler/optimizing/code_generator.cc b/compiler/optimizing/code_generator.cc index b358bfabe0..4791fa3fba 100644 --- a/compiler/optimizing/code_generator.cc +++ b/compiler/optimizing/code_generator.cc @@ -63,6 +63,7 @@ #include "parallel_move_resolver.h" #include "scoped_thread_state_change-inl.h" #include "ssa_liveness_analysis.h" +#include "stack_map.h" #include "stack_map_stream.h" #include "thread-current-inl.h" #include "utils/assembler.h" diff --git a/compiler/optimizing/intrinsics.cc b/compiler/optimizing/intrinsics.cc index dfe6d791c6..056f533398 100644 --- a/compiler/optimizing/intrinsics.cc +++ b/compiler/optimizing/intrinsics.cc @@ -272,7 +272,8 @@ IntrinsicVisitor::IntegerValueOfInfo IntrinsicVisitor::ComputeIntegerValueOfInfo ClassLinker* class_linker = runtime->GetClassLinker(); gc::Heap* heap = runtime->GetHeap(); IntegerValueOfInfo info; - info.integer_cache = class_linker->FindSystemClass(self, "Ljava/lang/Integer$IntegerCache;"); + info.integer_cache = + class_linker->FindSystemClass(self, "Ljava/lang/Integer$IntegerCache;").Ptr(); if (info.integer_cache == nullptr) { self->ClearException(); return info; @@ -281,7 +282,7 @@ IntrinsicVisitor::IntegerValueOfInfo IntrinsicVisitor::ComputeIntegerValueOfInfo // Optimization only works if the class is initialized and in the boot image. return info; } - info.integer = class_linker->FindSystemClass(self, "Ljava/lang/Integer;"); + info.integer = class_linker->FindSystemClass(self, "Ljava/lang/Integer;").Ptr(); if (info.integer == nullptr) { self->ClearException(); return info; diff --git a/compiler/optimizing/stack_map_stream.cc b/compiler/optimizing/stack_map_stream.cc index b1dcb68415..fad0d7be1b 100644 --- a/compiler/optimizing/stack_map_stream.cc +++ b/compiler/optimizing/stack_map_stream.cc @@ -22,6 +22,7 @@ #include "optimizing/optimizing_compiler.h" #include "runtime.h" #include "scoped_thread_state_change-inl.h" +#include "stack_map.h" namespace art { @@ -36,404 +37,234 @@ void StackMapStream::SetStackMapNativePcOffset(size_t i, uint32_t native_pc_offs void StackMapStream::BeginStackMapEntry(uint32_t dex_pc, uint32_t native_pc_offset, uint32_t register_mask, - BitVector* sp_mask, + BitVector* stack_mask, uint32_t num_dex_registers, - uint8_t inlining_depth) { - DCHECK_EQ(0u, current_entry_.dex_pc) << "EndStackMapEntry not called after BeginStackMapEntry"; - current_entry_.dex_pc = dex_pc; - current_entry_.packed_native_pc = StackMap::PackNativePc(native_pc_offset, instruction_set_); - current_entry_.register_mask = register_mask; - current_entry_.sp_mask = sp_mask; - current_entry_.inlining_depth = inlining_depth; - current_entry_.inline_infos_start_index = inline_infos_.size(); - current_entry_.stack_mask_index = 0; - current_entry_.dex_method_index = dex::kDexNoIndex; - current_entry_.dex_register_entry.num_dex_registers = num_dex_registers; - current_entry_.dex_register_entry.locations_start_index = dex_register_locations_.size(); - current_entry_.dex_register_entry.live_dex_registers_mask = nullptr; - if (num_dex_registers != 0u) { - current_entry_.dex_register_entry.live_dex_registers_mask = - ArenaBitVector::Create(allocator_, num_dex_registers, true, kArenaAllocStackMapStream); - current_entry_.dex_register_entry.live_dex_registers_mask->ClearAllBits(); + uint8_t inlining_depth ATTRIBUTE_UNUSED) { + DCHECK(!in_stack_map_) << "Mismatched Begin/End calls"; + in_stack_map_ = true; + + current_stack_map_ = StackMapEntry { + .packed_native_pc = StackMap::PackNativePc(native_pc_offset, instruction_set_), + .dex_pc = dex_pc, + .register_mask_index = kNoValue, + .stack_mask_index = kNoValue, + .inline_info_index = kNoValue, + .dex_register_mask_index = kNoValue, + .dex_register_map_index = kNoValue, + }; + if (register_mask != 0) { + uint32_t shift = LeastSignificantBit(register_mask); + RegisterMaskEntry entry = { register_mask >> shift, shift }; + current_stack_map_.register_mask_index = register_masks_.Dedup(&entry); + } + // The compiler assumes the bit vector will be read during PrepareForFillIn(), + // and it might modify the data before that. Therefore, just store the pointer. + // See ClearSpillSlotsFromLoopPhisInStackMap in code_generator.h. + lazy_stack_masks_.push_back(stack_mask); + current_inline_infos_ = 0; + current_dex_registers_.clear(); + expected_num_dex_registers_ = num_dex_registers; + + if (kIsDebugBuild) { + dcheck_num_dex_registers_.push_back(num_dex_registers); } - current_dex_register_ = 0; } void StackMapStream::EndStackMapEntry() { - current_entry_.dex_register_map_index = AddDexRegisterMapEntry(current_entry_.dex_register_entry); - stack_maps_.push_back(current_entry_); - current_entry_ = StackMapEntry(); + DCHECK(in_stack_map_) << "Mismatched Begin/End calls"; + in_stack_map_ = false; + DCHECK_EQ(expected_num_dex_registers_, current_dex_registers_.size()); + + // Mark the last inline info as last in the list for the stack map. + if (current_inline_infos_ > 0) { + inline_infos_[inline_infos_.size() - 1].is_last = InlineInfo::kLast; + } + + stack_maps_.Add(current_stack_map_); } void StackMapStream::AddDexRegisterEntry(DexRegisterLocation::Kind kind, int32_t value) { - if (kind != DexRegisterLocation::Kind::kNone) { - // Ensure we only use non-compressed location kind at this stage. - DCHECK(DexRegisterLocation::IsShortLocationKind(kind)) << kind; - DexRegisterLocation location(kind, value); - - // Look for Dex register `location` in the location catalog (using the - // companion hash map of locations to indices). Use its index if it - // is already in the location catalog. If not, insert it (in the - // location catalog and the hash map) and use the newly created index. - auto it = location_catalog_entries_indices_.Find(location); - if (it != location_catalog_entries_indices_.end()) { - // Retrieve the index from the hash map. - dex_register_locations_.push_back(it->second); - } else { - // Create a new entry in the location catalog and the hash map. - size_t index = location_catalog_entries_.size(); - location_catalog_entries_.push_back(location); - dex_register_locations_.push_back(index); - location_catalog_entries_indices_.Insert(std::make_pair(location, index)); - } - DexRegisterMapEntry* const entry = in_inline_frame_ - ? ¤t_inline_info_.dex_register_entry - : ¤t_entry_.dex_register_entry; - DCHECK_LT(current_dex_register_, entry->num_dex_registers); - entry->live_dex_registers_mask->SetBit(current_dex_register_); - entry->hash += (1 << - (current_dex_register_ % (sizeof(DexRegisterMapEntry::hash) * kBitsPerByte))); - entry->hash += static_cast<uint32_t>(value); - entry->hash += static_cast<uint32_t>(kind); + current_dex_registers_.push_back(DexRegisterLocation(kind, value)); + + // We have collected all the dex registers for StackMap/InlineInfo - create the map. + if (current_dex_registers_.size() == expected_num_dex_registers_) { + CreateDexRegisterMap(); } - current_dex_register_++; } void StackMapStream::AddInvoke(InvokeType invoke_type, uint32_t dex_method_index) { - current_entry_.invoke_type = invoke_type; - current_entry_.dex_method_index = dex_method_index; + uint32_t packed_native_pc = current_stack_map_.packed_native_pc; + invoke_infos_.Add(InvokeInfoEntry { + .packed_native_pc = packed_native_pc, + .invoke_type = invoke_type, + .method_info_index = method_infos_.Dedup(&dex_method_index), + }); } void StackMapStream::BeginInlineInfoEntry(ArtMethod* method, uint32_t dex_pc, uint32_t num_dex_registers, const DexFile* outer_dex_file) { - DCHECK(!in_inline_frame_); - in_inline_frame_ = true; + DCHECK(!in_inline_info_) << "Mismatched Begin/End calls"; + in_inline_info_ = true; + DCHECK_EQ(expected_num_dex_registers_, current_dex_registers_.size()); + + InlineInfoEntry entry = { + .is_last = InlineInfo::kMore, + .dex_pc = dex_pc, + .method_info_index = kNoValue, + .art_method_hi = kNoValue, + .art_method_lo = kNoValue, + .dex_register_mask_index = kNoValue, + .dex_register_map_index = kNoValue, + }; if (EncodeArtMethodInInlineInfo(method)) { - current_inline_info_.method = method; + entry.art_method_hi = High32Bits(reinterpret_cast<uintptr_t>(method)); + entry.art_method_lo = Low32Bits(reinterpret_cast<uintptr_t>(method)); } else { if (dex_pc != static_cast<uint32_t>(-1) && kIsDebugBuild) { ScopedObjectAccess soa(Thread::Current()); DCHECK(IsSameDexFile(*outer_dex_file, *method->GetDexFile())); } - current_inline_info_.method_index = method->GetDexMethodIndexUnchecked(); + uint32_t dex_method_index = method->GetDexMethodIndexUnchecked(); + entry.method_info_index = method_infos_.Dedup(&dex_method_index); } - current_inline_info_.dex_pc = dex_pc; - current_inline_info_.dex_register_entry.num_dex_registers = num_dex_registers; - current_inline_info_.dex_register_entry.locations_start_index = dex_register_locations_.size(); - current_inline_info_.dex_register_entry.live_dex_registers_mask = nullptr; - if (num_dex_registers != 0) { - current_inline_info_.dex_register_entry.live_dex_registers_mask = - ArenaBitVector::Create(allocator_, num_dex_registers, true, kArenaAllocStackMapStream); - current_inline_info_.dex_register_entry.live_dex_registers_mask->ClearAllBits(); + if (current_inline_infos_++ == 0) { + current_stack_map_.inline_info_index = inline_infos_.size(); + } + inline_infos_.Add(entry); + + current_dex_registers_.clear(); + expected_num_dex_registers_ = num_dex_registers; + + if (kIsDebugBuild) { + dcheck_num_dex_registers_.push_back(num_dex_registers); } - current_dex_register_ = 0; } void StackMapStream::EndInlineInfoEntry() { - current_inline_info_.dex_register_map_index = - AddDexRegisterMapEntry(current_inline_info_.dex_register_entry); - DCHECK(in_inline_frame_); - DCHECK_EQ(current_dex_register_, current_inline_info_.dex_register_entry.num_dex_registers) - << "Inline information contains less registers than expected"; - in_inline_frame_ = false; - inline_infos_.push_back(current_inline_info_); - current_inline_info_ = InlineInfoEntry(); + DCHECK(in_inline_info_) << "Mismatched Begin/End calls"; + in_inline_info_ = false; + DCHECK_EQ(expected_num_dex_registers_, current_dex_registers_.size()); } -size_t StackMapStream::ComputeDexRegisterLocationCatalogSize() const { - size_t size = DexRegisterLocationCatalog::kFixedSize; - for (const DexRegisterLocation& dex_register_location : location_catalog_entries_) { - size += DexRegisterLocationCatalog::EntrySize(dex_register_location); +// Create dex register map (bitmap + indices + catalogue entries) +// based on the currently accumulated list of DexRegisterLocations. +void StackMapStream::CreateDexRegisterMap() { + // Create mask and map based on current registers. + temp_dex_register_mask_.ClearAllBits(); + temp_dex_register_map_.clear(); + for (size_t i = 0; i < current_dex_registers_.size(); i++) { + DexRegisterLocation reg = current_dex_registers_[i]; + if (reg.IsLive()) { + DexRegisterEntry entry = DexRegisterEntry { + .kind = static_cast<uint32_t>(reg.GetKind()), + .packed_value = DexRegisterInfo::PackValue(reg.GetKind(), reg.GetValue()), + }; + temp_dex_register_mask_.SetBit(i); + temp_dex_register_map_.push_back(dex_register_catalog_.Dedup(&entry)); + } } - return size; -} -size_t StackMapStream::DexRegisterMapEntry::ComputeSize(size_t catalog_size) const { - // For num_dex_registers == 0u live_dex_registers_mask may be null. - if (num_dex_registers == 0u) { - return 0u; // No register map will be emitted. + // Set the mask and map for the current StackMap/InlineInfo. + uint32_t mask_index = StackMap::kNoValue; // Represents mask with all zero bits. + if (temp_dex_register_mask_.GetNumberOfBits() != 0) { + mask_index = dex_register_masks_.Dedup(temp_dex_register_mask_.GetRawStorage(), + temp_dex_register_mask_.GetNumberOfBits()); } - size_t number_of_live_dex_registers = live_dex_registers_mask->NumSetBits(); - if (live_dex_registers_mask->NumSetBits() == 0) { - return 0u; // No register map will be emitted. + uint32_t map_index = dex_register_maps_.Dedup(temp_dex_register_map_.data(), + temp_dex_register_map_.size()); + if (current_inline_infos_ > 0) { + inline_infos_[inline_infos_.size() - 1].dex_register_mask_index = mask_index; + inline_infos_[inline_infos_.size() - 1].dex_register_map_index = map_index; + } else { + current_stack_map_.dex_register_mask_index = mask_index; + current_stack_map_.dex_register_map_index = map_index; } - DCHECK(live_dex_registers_mask != nullptr); - - // Size of the map in bytes. - size_t size = DexRegisterMap::kFixedSize; - // Add the live bit mask for the Dex register liveness. - size += DexRegisterMap::GetLiveBitMaskSize(num_dex_registers); - // Compute the size of the set of live Dex register entries. - size_t map_entries_size_in_bits = - DexRegisterMap::SingleEntrySizeInBits(catalog_size) * number_of_live_dex_registers; - size_t map_entries_size_in_bytes = - RoundUp(map_entries_size_in_bits, kBitsPerByte) / kBitsPerByte; - size += map_entries_size_in_bytes; - return size; } void StackMapStream::FillInMethodInfo(MemoryRegion region) { { - MethodInfo info(region.begin(), method_indices_.size()); - for (size_t i = 0; i < method_indices_.size(); ++i) { - info.SetMethodIndex(i, method_indices_[i]); + MethodInfo info(region.begin(), method_infos_.size()); + for (size_t i = 0; i < method_infos_.size(); ++i) { + info.SetMethodIndex(i, method_infos_[i]); } } if (kIsDebugBuild) { // Check the data matches. MethodInfo info(region.begin()); const size_t count = info.NumMethodIndices(); - DCHECK_EQ(count, method_indices_.size()); + DCHECK_EQ(count, method_infos_.size()); for (size_t i = 0; i < count; ++i) { - DCHECK_EQ(info.GetMethodIndex(i), method_indices_[i]); + DCHECK_EQ(info.GetMethodIndex(i), method_infos_[i]); } } } -template<typename Vector> -static MemoryRegion EncodeMemoryRegion(Vector* out, size_t* bit_offset, uint32_t bit_length) { - uint32_t byte_length = BitsToBytesRoundUp(bit_length); - EncodeVarintBits(out, bit_offset, byte_length); - *bit_offset = RoundUp(*bit_offset, kBitsPerByte); - out->resize(out->size() + byte_length); - MemoryRegion region(out->data() + *bit_offset / kBitsPerByte, byte_length); - *bit_offset += kBitsPerByte * byte_length; - return region; -} - size_t StackMapStream::PrepareForFillIn() { - size_t bit_offset = 0; - out_.clear(); - - // Decide the offsets of dex register map entries, but do not write them out yet. - // Needs to be done first as it modifies the stack map entry. - size_t dex_register_map_bytes = 0; - for (DexRegisterMapEntry& entry : dex_register_entries_) { - size_t size = entry.ComputeSize(location_catalog_entries_.size()); - entry.offset = size == 0 ? DexRegisterMapEntry::kOffsetUnassigned : dex_register_map_bytes; - dex_register_map_bytes += size; - } - - // Must be done before calling ComputeInlineInfoEncoding since ComputeInlineInfoEncoding requires - // dex_method_index_idx to be filled in. - PrepareMethodIndices(); - - // Dedup stack masks. Needs to be done first as it modifies the stack map entry. - BitmapTableBuilder stack_mask_builder(allocator_); - for (StackMapEntry& stack_map : stack_maps_) { - BitVector* mask = stack_map.sp_mask; - size_t num_bits = (mask != nullptr) ? mask->GetNumberOfBits() : 0; - if (num_bits != 0) { - stack_map.stack_mask_index = stack_mask_builder.Dedup(mask->GetRawStorage(), num_bits); - } else { - stack_map.stack_mask_index = StackMap::kNoValue; - } - } - - // Dedup register masks. Needs to be done first as it modifies the stack map entry. - BitTableBuilder<std::array<uint32_t, RegisterMask::kCount>> register_mask_builder(allocator_); - for (StackMapEntry& stack_map : stack_maps_) { - uint32_t register_mask = stack_map.register_mask; - if (register_mask != 0) { - uint32_t shift = LeastSignificantBit(register_mask); - std::array<uint32_t, RegisterMask::kCount> entry = { - register_mask >> shift, - shift, - }; - stack_map.register_mask_index = register_mask_builder.Dedup(&entry); - } else { - stack_map.register_mask_index = StackMap::kNoValue; + static_assert(sizeof(StackMapEntry) == StackMap::kCount * sizeof(uint32_t), "Layout"); + static_assert(sizeof(InvokeInfoEntry) == InvokeInfo::kCount * sizeof(uint32_t), "Layout"); + static_assert(sizeof(InlineInfoEntry) == InlineInfo::kCount * sizeof(uint32_t), "Layout"); + static_assert(sizeof(DexRegisterEntry) == DexRegisterInfo::kCount * sizeof(uint32_t), "Layout"); + DCHECK_EQ(out_.size(), 0u); + + // Read the stack masks now. The compiler might have updated them. + for (size_t i = 0; i < lazy_stack_masks_.size(); i++) { + BitVector* stack_mask = lazy_stack_masks_[i]; + if (stack_mask != nullptr && stack_mask->GetNumberOfBits() != 0) { + stack_maps_[i].stack_mask_index = + stack_masks_.Dedup(stack_mask->GetRawStorage(), stack_mask->GetNumberOfBits()); } } - // Allocate space for dex register maps. - EncodeMemoryRegion(&out_, &bit_offset, dex_register_map_bytes * kBitsPerByte); - - // Write dex register catalog. - EncodeVarintBits(&out_, &bit_offset, location_catalog_entries_.size()); - size_t location_catalog_bytes = ComputeDexRegisterLocationCatalogSize(); - MemoryRegion dex_register_location_catalog_region = - EncodeMemoryRegion(&out_, &bit_offset, location_catalog_bytes * kBitsPerByte); - DexRegisterLocationCatalog dex_register_location_catalog(dex_register_location_catalog_region); - // Offset in `dex_register_location_catalog` where to store the next - // register location. - size_t location_catalog_offset = DexRegisterLocationCatalog::kFixedSize; - for (DexRegisterLocation dex_register_location : location_catalog_entries_) { - dex_register_location_catalog.SetRegisterInfo(location_catalog_offset, dex_register_location); - location_catalog_offset += DexRegisterLocationCatalog::EntrySize(dex_register_location); - } - // Ensure we reached the end of the Dex registers location_catalog. - DCHECK_EQ(location_catalog_offset, dex_register_location_catalog_region.size()); - - // Write stack maps. - BitTableBuilder<std::array<uint32_t, StackMap::kCount>> stack_map_builder(allocator_); - BitTableBuilder<std::array<uint32_t, InvokeInfo::kCount>> invoke_info_builder(allocator_); - BitTableBuilder<std::array<uint32_t, InlineInfo::kCount>> inline_info_builder(allocator_); - for (const StackMapEntry& entry : stack_maps_) { - if (entry.dex_method_index != dex::kDexNoIndex) { - std::array<uint32_t, InvokeInfo::kCount> invoke_info_entry { - entry.packed_native_pc, - entry.invoke_type, - entry.dex_method_index_idx - }; - invoke_info_builder.Add(invoke_info_entry); - } - - // Set the inlining info. - uint32_t inline_info_index = inline_info_builder.size(); - DCHECK_LE(entry.inline_infos_start_index + entry.inlining_depth, inline_infos_.size()); - for (size_t depth = 0; depth < entry.inlining_depth; ++depth) { - InlineInfoEntry inline_entry = inline_infos_[depth + entry.inline_infos_start_index]; - uint32_t method_index_idx = inline_entry.dex_method_index_idx; - uint32_t extra_data = 1; - if (inline_entry.method != nullptr) { - method_index_idx = High32Bits(reinterpret_cast<uintptr_t>(inline_entry.method)); - extra_data = Low32Bits(reinterpret_cast<uintptr_t>(inline_entry.method)); - } - std::array<uint32_t, InlineInfo::kCount> inline_info_entry { - (depth == entry.inlining_depth - 1) ? InlineInfo::kLast : InlineInfo::kMore, - method_index_idx, - inline_entry.dex_pc, - extra_data, - dex_register_entries_[inline_entry.dex_register_map_index].offset, - }; - inline_info_builder.Add(inline_info_entry); - } - std::array<uint32_t, StackMap::kCount> stack_map_entry { - entry.packed_native_pc, - entry.dex_pc, - dex_register_entries_[entry.dex_register_map_index].offset, - entry.inlining_depth != 0 ? inline_info_index : InlineInfo::kNoValue, - entry.register_mask_index, - entry.stack_mask_index, - }; - stack_map_builder.Add(stack_map_entry); - } - stack_map_builder.Encode(&out_, &bit_offset); - invoke_info_builder.Encode(&out_, &bit_offset); - inline_info_builder.Encode(&out_, &bit_offset); - register_mask_builder.Encode(&out_, &bit_offset); - stack_mask_builder.Encode(&out_, &bit_offset); + size_t bit_offset = 0; + stack_maps_.Encode(&out_, &bit_offset); + register_masks_.Encode(&out_, &bit_offset); + stack_masks_.Encode(&out_, &bit_offset); + invoke_infos_.Encode(&out_, &bit_offset); + inline_infos_.Encode(&out_, &bit_offset); + dex_register_masks_.Encode(&out_, &bit_offset); + dex_register_maps_.Encode(&out_, &bit_offset); + dex_register_catalog_.Encode(&out_, &bit_offset); return UnsignedLeb128Size(out_.size()) + out_.size(); } void StackMapStream::FillInCodeInfo(MemoryRegion region) { - DCHECK_EQ(0u, current_entry_.dex_pc) << "EndStackMapEntry not called after BeginStackMapEntry"; + DCHECK(in_stack_map_ == false) << "Mismatched Begin/End calls"; + DCHECK(in_inline_info_ == false) << "Mismatched Begin/End calls"; DCHECK_NE(0u, out_.size()) << "PrepareForFillIn not called before FillIn"; DCHECK_EQ(region.size(), UnsignedLeb128Size(out_.size()) + out_.size()); uint8_t* ptr = EncodeUnsignedLeb128(region.begin(), out_.size()); region.CopyFromVector(ptr - region.begin(), out_); - // Write dex register maps. - CodeInfo code_info(region); - for (DexRegisterMapEntry& entry : dex_register_entries_) { - size_t entry_size = entry.ComputeSize(location_catalog_entries_.size()); - if (entry_size != 0) { - DexRegisterMap dex_register_map( - code_info.dex_register_maps_.Subregion(entry.offset, entry_size), - entry.num_dex_registers, - code_info); - FillInDexRegisterMap(dex_register_map, - entry.num_dex_registers, - *entry.live_dex_registers_mask, - entry.locations_start_index); - } - } - // Verify all written data in debug build. if (kIsDebugBuild) { CheckCodeInfo(region); } } -void StackMapStream::FillInDexRegisterMap(DexRegisterMap dex_register_map, - uint32_t num_dex_registers, - const BitVector& live_dex_registers_mask, - uint32_t start_index_in_dex_register_locations) const { - dex_register_map.SetLiveBitMask(num_dex_registers, live_dex_registers_mask); - // Set the dex register location mapping data. - size_t number_of_live_dex_registers = live_dex_registers_mask.NumSetBits(); - DCHECK_LE(number_of_live_dex_registers, dex_register_locations_.size()); - DCHECK_LE(start_index_in_dex_register_locations, - dex_register_locations_.size() - number_of_live_dex_registers); - for (size_t index_in_dex_register_locations = 0; - index_in_dex_register_locations != number_of_live_dex_registers; - ++index_in_dex_register_locations) { - size_t location_catalog_entry_index = dex_register_locations_[ - start_index_in_dex_register_locations + index_in_dex_register_locations]; - dex_register_map.SetLocationCatalogEntryIndex( - index_in_dex_register_locations, - location_catalog_entry_index, - location_catalog_entries_.size()); - } -} - -size_t StackMapStream::AddDexRegisterMapEntry(const DexRegisterMapEntry& entry) { - const size_t current_entry_index = dex_register_entries_.size(); - auto entries_it = dex_map_hash_to_stack_map_indices_.find(entry.hash); - if (entries_it == dex_map_hash_to_stack_map_indices_.end()) { - // We don't have a perfect hash functions so we need a list to collect all stack maps - // which might have the same dex register map. - ScopedArenaVector<uint32_t> stack_map_indices(allocator_->Adapter(kArenaAllocStackMapStream)); - stack_map_indices.push_back(current_entry_index); - dex_map_hash_to_stack_map_indices_.Put(entry.hash, std::move(stack_map_indices)); - } else { - // We might have collisions, so we need to check whether or not we really have a match. - for (uint32_t test_entry_index : entries_it->second) { - if (DexRegisterMapEntryEquals(dex_register_entries_[test_entry_index], entry)) { - return test_entry_index; - } - } - entries_it->second.push_back(current_entry_index); - } - dex_register_entries_.push_back(entry); - return current_entry_index; -} - -bool StackMapStream::DexRegisterMapEntryEquals(const DexRegisterMapEntry& a, - const DexRegisterMapEntry& b) const { - if ((a.live_dex_registers_mask == nullptr) != (b.live_dex_registers_mask == nullptr)) { - return false; - } - if (a.num_dex_registers != b.num_dex_registers) { - return false; - } - if (a.num_dex_registers != 0u) { - DCHECK(a.live_dex_registers_mask != nullptr); - DCHECK(b.live_dex_registers_mask != nullptr); - if (!a.live_dex_registers_mask->Equal(b.live_dex_registers_mask)) { - return false; - } - size_t number_of_live_dex_registers = a.live_dex_registers_mask->NumSetBits(); - DCHECK_LE(number_of_live_dex_registers, dex_register_locations_.size()); - DCHECK_LE(a.locations_start_index, - dex_register_locations_.size() - number_of_live_dex_registers); - DCHECK_LE(b.locations_start_index, - dex_register_locations_.size() - number_of_live_dex_registers); - auto a_begin = dex_register_locations_.begin() + a.locations_start_index; - auto b_begin = dex_register_locations_.begin() + b.locations_start_index; - if (!std::equal(a_begin, a_begin + number_of_live_dex_registers, b_begin)) { - return false; - } - } - return true; -} - // Helper for CheckCodeInfo - check that register map has the expected content. void StackMapStream::CheckDexRegisterMap(const DexRegisterMap& dex_register_map, - size_t num_dex_registers, - BitVector* live_dex_registers_mask, - size_t dex_register_locations_index) const { - for (size_t reg = 0; reg < num_dex_registers; reg++) { + size_t dex_register_mask_index, + size_t dex_register_map_index) const { + if (dex_register_map_index == kNoValue) { + DCHECK(!dex_register_map.IsValid()); + return; + } + BitMemoryRegion live_dex_registers_mask = (dex_register_mask_index == kNoValue) + ? BitMemoryRegion() + : BitMemoryRegion(dex_register_masks_[dex_register_mask_index]); + for (size_t reg = 0; reg < dex_register_map.size(); reg++) { // Find the location we tried to encode. DexRegisterLocation expected = DexRegisterLocation::None(); - if (live_dex_registers_mask->IsBitSet(reg)) { - size_t catalog_index = dex_register_locations_[dex_register_locations_index++]; - expected = location_catalog_entries_[catalog_index]; + if (reg < live_dex_registers_mask.size_in_bits() && live_dex_registers_mask.LoadBit(reg)) { + size_t catalog_index = dex_register_maps_[dex_register_map_index++]; + DexRegisterLocation::Kind kind = + static_cast<DexRegisterLocation::Kind>(dex_register_catalog_[catalog_index].kind); + uint32_t packed_value = dex_register_catalog_[catalog_index].packed_value; + expected = DexRegisterLocation(kind, DexRegisterInfo::UnpackValue(kind, packed_value)); } // Compare to the seen location. if (expected.GetKind() == DexRegisterLocation::Kind::kNone) { @@ -446,108 +277,75 @@ void StackMapStream::CheckDexRegisterMap(const DexRegisterMap& dex_register_map, DCHECK_EQ(expected.GetValue(), seen.GetValue()); } } - if (num_dex_registers == 0) { - DCHECK(!dex_register_map.IsValid()); - } -} - -void StackMapStream::PrepareMethodIndices() { - CHECK(method_indices_.empty()); - method_indices_.resize(stack_maps_.size() + inline_infos_.size()); - ScopedArenaUnorderedMap<uint32_t, size_t> dedupe(allocator_->Adapter(kArenaAllocStackMapStream)); - for (StackMapEntry& stack_map : stack_maps_) { - const size_t index = dedupe.size(); - const uint32_t method_index = stack_map.dex_method_index; - if (method_index != dex::kDexNoIndex) { - stack_map.dex_method_index_idx = dedupe.emplace(method_index, index).first->second; - method_indices_[index] = method_index; - } - } - for (InlineInfoEntry& inline_info : inline_infos_) { - const size_t index = dedupe.size(); - const uint32_t method_index = inline_info.method_index; - CHECK_NE(method_index, dex::kDexNoIndex); - inline_info.dex_method_index_idx = dedupe.emplace(method_index, index).first->second; - method_indices_[index] = method_index; - } - method_indices_.resize(dedupe.size()); } // Check that all StackMapStream inputs are correctly encoded by trying to read them back. void StackMapStream::CheckCodeInfo(MemoryRegion region) const { CodeInfo code_info(region); DCHECK_EQ(code_info.GetNumberOfStackMaps(), stack_maps_.size()); - DCHECK_EQ(code_info.GetNumberOfLocationCatalogEntries(), location_catalog_entries_.size()); - size_t invoke_info_index = 0; + const uint32_t* num_dex_registers = dcheck_num_dex_registers_.data(); for (size_t s = 0; s < stack_maps_.size(); ++s) { const StackMap stack_map = code_info.GetStackMapAt(s); - StackMapEntry entry = stack_maps_[s]; + const StackMapEntry& entry = stack_maps_[s]; // Check main stack map fields. DCHECK_EQ(stack_map.GetNativePcOffset(instruction_set_), StackMap::UnpackNativePc(entry.packed_native_pc, instruction_set_)); DCHECK_EQ(stack_map.GetDexPc(), entry.dex_pc); DCHECK_EQ(stack_map.GetRegisterMaskIndex(), entry.register_mask_index); - DCHECK_EQ(code_info.GetRegisterMaskOf(stack_map), entry.register_mask); + RegisterMaskEntry expected_register_mask = (entry.register_mask_index == kNoValue) + ? RegisterMaskEntry{} + : register_masks_[entry.register_mask_index]; + DCHECK_EQ(code_info.GetRegisterMaskOf(stack_map), + expected_register_mask.value << expected_register_mask.shift); DCHECK_EQ(stack_map.GetStackMaskIndex(), entry.stack_mask_index); + BitMemoryRegion expected_stack_mask = (entry.stack_mask_index == kNoValue) + ? BitMemoryRegion() + : BitMemoryRegion(stack_masks_[entry.stack_mask_index]); BitMemoryRegion stack_mask = code_info.GetStackMaskOf(stack_map); - if (entry.sp_mask != nullptr) { - DCHECK_GE(stack_mask.size_in_bits(), entry.sp_mask->GetNumberOfBits()); - for (size_t b = 0; b < stack_mask.size_in_bits(); b++) { - DCHECK_EQ(stack_mask.LoadBit(b), entry.sp_mask->IsBitSet(b)) << b; - } - } else { - DCHECK_EQ(stack_mask.size_in_bits(), 0u); + for (size_t b = 0; b < expected_stack_mask.size_in_bits(); b++) { + bool seen = b < stack_mask.size_in_bits() && stack_mask.LoadBit(b); + DCHECK_EQ(expected_stack_mask.LoadBit(b), seen); } - if (entry.dex_method_index != dex::kDexNoIndex) { - InvokeInfo invoke_info = code_info.GetInvokeInfo(invoke_info_index); - DCHECK_EQ(invoke_info.GetNativePcOffset(instruction_set_), - StackMap::UnpackNativePc(entry.packed_native_pc, instruction_set_)); - DCHECK_EQ(invoke_info.GetInvokeType(), entry.invoke_type); - DCHECK_EQ(invoke_info.GetMethodIndexIdx(), entry.dex_method_index_idx); - invoke_info_index++; - } - CheckDexRegisterMap(code_info.GetDexRegisterMapOf( - stack_map, entry.dex_register_entry.num_dex_registers), - entry.dex_register_entry.num_dex_registers, - entry.dex_register_entry.live_dex_registers_mask, - entry.dex_register_entry.locations_start_index); + CheckDexRegisterMap(code_info.GetDexRegisterMapOf(stack_map, *(num_dex_registers++)), + entry.dex_register_mask_index, + entry.dex_register_map_index); // Check inline info. - DCHECK_EQ(stack_map.HasInlineInfo(), (entry.inlining_depth != 0)); - if (entry.inlining_depth != 0) { + DCHECK_EQ(stack_map.HasInlineInfo(), (entry.inline_info_index != kNoValue)); + if (stack_map.HasInlineInfo()) { InlineInfo inline_info = code_info.GetInlineInfoOf(stack_map); - DCHECK_EQ(inline_info.GetDepth(), entry.inlining_depth); - for (size_t d = 0; d < entry.inlining_depth; ++d) { - size_t inline_info_index = entry.inline_infos_start_index + d; + size_t inlining_depth = inline_info.GetDepth(); + for (size_t d = 0; d < inlining_depth; ++d) { + size_t inline_info_index = entry.inline_info_index + d; DCHECK_LT(inline_info_index, inline_infos_.size()); - InlineInfoEntry inline_entry = inline_infos_[inline_info_index]; + const InlineInfoEntry& inline_entry = inline_infos_[inline_info_index]; DCHECK_EQ(inline_info.GetDexPcAtDepth(d), inline_entry.dex_pc); - if (inline_info.EncodesArtMethodAtDepth(d)) { - DCHECK_EQ(inline_info.GetArtMethodAtDepth(d), - inline_entry.method); - } else { + if (!inline_info.EncodesArtMethodAtDepth(d)) { const size_t method_index_idx = inline_info.GetMethodIndexIdxAtDepth(d); - DCHECK_EQ(method_index_idx, inline_entry.dex_method_index_idx); - DCHECK_EQ(method_indices_[method_index_idx], inline_entry.method_index); + DCHECK_EQ(method_index_idx, inline_entry.method_info_index); } - CheckDexRegisterMap(code_info.GetDexRegisterMapAtDepth( - d, - inline_info, - inline_entry.dex_register_entry.num_dex_registers), - inline_entry.dex_register_entry.num_dex_registers, - inline_entry.dex_register_entry.live_dex_registers_mask, - inline_entry.dex_register_entry.locations_start_index); + d, inline_info, *(num_dex_registers++)), + inline_entry.dex_register_mask_index, + inline_entry.dex_register_map_index); } } } + for (size_t i = 0; i < invoke_infos_.size(); i++) { + InvokeInfo invoke_info = code_info.GetInvokeInfo(i); + const InvokeInfoEntry& entry = invoke_infos_[i]; + DCHECK_EQ(invoke_info.GetNativePcOffset(instruction_set_), + StackMap::UnpackNativePc(entry.packed_native_pc, instruction_set_)); + DCHECK_EQ(invoke_info.GetInvokeType(), entry.invoke_type); + DCHECK_EQ(invoke_info.GetMethodIndexIdx(), entry.method_info_index); + } } size_t StackMapStream::ComputeMethodInfoSize() const { DCHECK_NE(0u, out_.size()) << "PrepareForFillIn not called before " << __FUNCTION__; - return MethodInfo::ComputeSize(method_indices_.size()); + return MethodInfo::ComputeSize(method_infos_.size()); } } // namespace art diff --git a/compiler/optimizing/stack_map_stream.h b/compiler/optimizing/stack_map_stream.h index 6d505b95db..cefe165a67 100644 --- a/compiler/optimizing/stack_map_stream.h +++ b/compiler/optimizing/stack_map_stream.h @@ -17,42 +17,20 @@ #ifndef ART_COMPILER_OPTIMIZING_STACK_MAP_STREAM_H_ #define ART_COMPILER_OPTIMIZING_STACK_MAP_STREAM_H_ +#include "base/allocator.h" +#include "base/arena_bit_vector.h" +#include "base/bit_table.h" #include "base/bit_vector-inl.h" -#include "base/hash_map.h" #include "base/memory_region.h" #include "base/scoped_arena_containers.h" #include "base/value_object.h" +#include "dex_register_location.h" #include "method_info.h" #include "nodes.h" -#include "stack_map.h" namespace art { -// Helper to build art::StackMapStream::LocationCatalogEntriesIndices. -class LocationCatalogEntriesIndicesEmptyFn { - public: - void MakeEmpty(std::pair<DexRegisterLocation, size_t>& item) const { - item.first = DexRegisterLocation::None(); - } - bool IsEmpty(const std::pair<DexRegisterLocation, size_t>& item) const { - return item.first == DexRegisterLocation::None(); - } -}; - -// Hash function for art::StackMapStream::LocationCatalogEntriesIndices. -// This hash function does not create collisions. -class DexRegisterLocationHashFn { - public: - size_t operator()(DexRegisterLocation key) const { - // Concatenate `key`s fields to create a 64-bit value to be hashed. - int64_t kind_and_value = - (static_cast<int64_t>(key.kind_) << 32) | static_cast<int64_t>(key.value_); - return inner_hash_fn_(kind_and_value); - } - private: - std::hash<int64_t> inner_hash_fn_; -}; - +class DexRegisterMap; /** * Collects and builds stack maps for a method. All the stack maps @@ -61,71 +39,26 @@ class DexRegisterLocationHashFn { class StackMapStream : public ValueObject { public: explicit StackMapStream(ScopedArenaAllocator* allocator, InstructionSet instruction_set) - : allocator_(allocator), - instruction_set_(instruction_set), - stack_maps_(allocator->Adapter(kArenaAllocStackMapStream)), - location_catalog_entries_(allocator->Adapter(kArenaAllocStackMapStream)), - location_catalog_entries_indices_(allocator->Adapter(kArenaAllocStackMapStream)), - dex_register_locations_(allocator->Adapter(kArenaAllocStackMapStream)), - inline_infos_(allocator->Adapter(kArenaAllocStackMapStream)), - method_indices_(allocator->Adapter(kArenaAllocStackMapStream)), - dex_register_entries_(allocator->Adapter(kArenaAllocStackMapStream)), + : instruction_set_(instruction_set), + stack_maps_(allocator), + register_masks_(allocator), + stack_masks_(allocator), + invoke_infos_(allocator), + inline_infos_(allocator), + dex_register_masks_(allocator), + dex_register_maps_(allocator), + dex_register_catalog_(allocator), out_(allocator->Adapter(kArenaAllocStackMapStream)), - dex_map_hash_to_stack_map_indices_(std::less<uint32_t>(), - allocator->Adapter(kArenaAllocStackMapStream)), - current_entry_(), - current_inline_info_(), - current_dex_register_(0), - in_inline_frame_(false) { - stack_maps_.reserve(10); - out_.reserve(64); - location_catalog_entries_.reserve(4); - dex_register_locations_.reserve(10 * 4); - inline_infos_.reserve(2); + method_infos_(allocator), + lazy_stack_masks_(allocator->Adapter(kArenaAllocStackMapStream)), + in_stack_map_(false), + in_inline_info_(false), + current_inline_infos_(0), + current_dex_registers_(allocator->Adapter(kArenaAllocStackMapStream)), + temp_dex_register_mask_(allocator, 32, true, kArenaAllocStackMapStream), + temp_dex_register_map_(allocator->Adapter(kArenaAllocStackMapStream)) { } - // A dex register map entry for a single stack map entry, contains what registers are live as - // well as indices into the location catalog. - class DexRegisterMapEntry { - public: - static const uint32_t kOffsetUnassigned = -1; - - BitVector* live_dex_registers_mask; - uint32_t num_dex_registers; - size_t locations_start_index; - // Computed fields - size_t hash = 0; - uint32_t offset = kOffsetUnassigned; - - size_t ComputeSize(size_t catalog_size) const; - }; - - // See runtime/stack_map.h to know what these fields contain. - struct StackMapEntry { - uint32_t dex_pc; - uint32_t packed_native_pc; - uint32_t register_mask; - BitVector* sp_mask; - uint32_t inlining_depth; - size_t inline_infos_start_index; - uint32_t stack_mask_index; - uint32_t register_mask_index; - DexRegisterMapEntry dex_register_entry; - size_t dex_register_map_index; - InvokeType invoke_type; - uint32_t dex_method_index; - uint32_t dex_method_index_idx; // Index into dex method index table. - }; - - struct InlineInfoEntry { - uint32_t dex_pc; // dex::kDexNoIndex for intrinsified native methods. - ArtMethod* method; - uint32_t method_index; - DexRegisterMapEntry dex_register_entry; - size_t dex_register_map_index; - uint32_t dex_method_index_idx; // Index into the dex method index table. - }; - void BeginStackMapEntry(uint32_t dex_pc, uint32_t native_pc_offset, uint32_t register_mask, @@ -160,58 +93,87 @@ class StackMapStream : public ValueObject { size_t ComputeMethodInfoSize() const; private: - size_t ComputeDexRegisterLocationCatalogSize() const; + static constexpr uint32_t kNoValue = -1; + + // The fields must be uint32_t and mirror the StackMap accessor in stack_map.h! + struct StackMapEntry { + uint32_t packed_native_pc; + uint32_t dex_pc; + uint32_t register_mask_index; + uint32_t stack_mask_index; + uint32_t inline_info_index; + uint32_t dex_register_mask_index; + uint32_t dex_register_map_index; + }; + + // The fields must be uint32_t and mirror the InlineInfo accessor in stack_map.h! + struct InlineInfoEntry { + uint32_t is_last; + uint32_t dex_pc; + uint32_t method_info_index; + uint32_t art_method_hi; + uint32_t art_method_lo; + uint32_t dex_register_mask_index; + uint32_t dex_register_map_index; + }; - // Prepare and deduplicate method indices. - void PrepareMethodIndices(); + // The fields must be uint32_t and mirror the InvokeInfo accessor in stack_map.h! + struct InvokeInfoEntry { + uint32_t packed_native_pc; + uint32_t invoke_type; + uint32_t method_info_index; + }; - // Deduplicate entry if possible and return the corresponding index into dex_register_entries_ - // array. If entry is not a duplicate, a new entry is added to dex_register_entries_. - size_t AddDexRegisterMapEntry(const DexRegisterMapEntry& entry); + // The fields must be uint32_t and mirror the DexRegisterInfo accessor in stack_map.h! + struct DexRegisterEntry { + uint32_t kind; + uint32_t packed_value; + }; - // Return true if the two dex register map entries are equal. - bool DexRegisterMapEntryEquals(const DexRegisterMapEntry& a, const DexRegisterMapEntry& b) const; + // The fields must be uint32_t and mirror the RegisterMask accessor in stack_map.h! + struct RegisterMaskEntry { + uint32_t value; + uint32_t shift; + }; - // Fill in the corresponding entries of a register map. - void FillInDexRegisterMap(DexRegisterMap dex_register_map, - uint32_t num_dex_registers, - const BitVector& live_dex_registers_mask, - uint32_t start_index_in_dex_register_locations) const; + void CreateDexRegisterMap(); void CheckDexRegisterMap(const DexRegisterMap& dex_register_map, - size_t num_dex_registers, - BitVector* live_dex_registers_mask, - size_t dex_register_locations_index) const; + size_t dex_register_mask_index, + size_t dex_register_map_index) const; void CheckCodeInfo(MemoryRegion region) const; - ScopedArenaAllocator* const allocator_; const InstructionSet instruction_set_; - ScopedArenaVector<StackMapEntry> stack_maps_; - - // A catalog of unique [location_kind, register_value] pairs (per method). - ScopedArenaVector<DexRegisterLocation> location_catalog_entries_; - // Map from Dex register location catalog entries to their indices in the - // location catalog. - using LocationCatalogEntriesIndices = ScopedArenaHashMap<DexRegisterLocation, - size_t, - LocationCatalogEntriesIndicesEmptyFn, - DexRegisterLocationHashFn>; - LocationCatalogEntriesIndices location_catalog_entries_indices_; - - // A set of concatenated maps of Dex register locations indices to `location_catalog_entries_`. - ScopedArenaVector<size_t> dex_register_locations_; - ScopedArenaVector<InlineInfoEntry> inline_infos_; - ScopedArenaVector<uint32_t> method_indices_; - ScopedArenaVector<DexRegisterMapEntry> dex_register_entries_; - + BitTableBuilder<StackMapEntry> stack_maps_; + BitTableBuilder<RegisterMaskEntry> register_masks_; + BitmapTableBuilder stack_masks_; + BitTableBuilder<InvokeInfoEntry> invoke_infos_; + BitTableBuilder<InlineInfoEntry> inline_infos_; + BitmapTableBuilder dex_register_masks_; + BitTableBuilder<uint32_t> dex_register_maps_; + BitTableBuilder<DexRegisterEntry> dex_register_catalog_; ScopedArenaVector<uint8_t> out_; - ScopedArenaSafeMap<uint32_t, ScopedArenaVector<uint32_t>> dex_map_hash_to_stack_map_indices_; + BitTableBuilder<uint32_t> method_infos_; + + ScopedArenaVector<BitVector*> lazy_stack_masks_; + + // Variables which track the current state between Begin/End calls; + bool in_stack_map_; + bool in_inline_info_; + StackMapEntry current_stack_map_; + uint32_t current_inline_infos_; + ScopedArenaVector<DexRegisterLocation> current_dex_registers_; + size_t expected_num_dex_registers_; + + // Temporary variables used in CreateDexRegisterMap. + // They are here so that we can reuse the reserved memory. + ArenaBitVector temp_dex_register_mask_; + ScopedArenaVector<uint32_t> temp_dex_register_map_; - StackMapEntry current_entry_; - InlineInfoEntry current_inline_info_; - uint32_t current_dex_register_; - bool in_inline_frame_; + // Records num_dex_registers for every StackMapEntry and InlineInfoEntry. + // Only used in debug builds to verify the dex registers at the end. + std::vector<uint32_t> dcheck_num_dex_registers_; DISALLOW_COPY_AND_ASSIGN(StackMapStream); }; diff --git a/compiler/optimizing/stack_map_test.cc b/compiler/optimizing/stack_map_test.cc index 112771847c..262c240bc7 100644 --- a/compiler/optimizing/stack_map_test.cc +++ b/compiler/optimizing/stack_map_test.cc @@ -45,6 +45,8 @@ static bool CheckStackMask( using Kind = DexRegisterLocation::Kind; +constexpr static uint32_t kPcAlign = GetInstructionSetInstructionAlignment(kRuntimeISA); + TEST(StackMapTest, Test1) { MallocArenaPool pool; ArenaStack arena_stack(&pool); @@ -53,7 +55,7 @@ TEST(StackMapTest, Test1) { ArenaBitVector sp_mask(&allocator, 0, false); size_t number_of_dex_registers = 2; - stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask, number_of_dex_registers, 0); + stream.BeginStackMapEntry(0, 64 * kPcAlign, 0x3, &sp_mask, number_of_dex_registers, 0); stream.AddDexRegisterEntry(Kind::kInStack, 0); // Short location. stream.AddDexRegisterEntry(Kind::kConstant, -2); // Short location. stream.EndStackMapEntry(); @@ -68,18 +70,12 @@ TEST(StackMapTest, Test1) { uint32_t number_of_catalog_entries = code_info.GetNumberOfLocationCatalogEntries(); ASSERT_EQ(2u, number_of_catalog_entries); - DexRegisterLocationCatalog location_catalog = code_info.GetDexRegisterLocationCatalog(); - // The Dex register location catalog contains: - // - one 1-byte short Dex register location, and - // - one 5-byte large Dex register location. - size_t expected_location_catalog_size = 1u + 5u; - ASSERT_EQ(expected_location_catalog_size, location_catalog.Size()); StackMap stack_map = code_info.GetStackMapAt(0); ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForDexPc(0))); - ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForNativePcOffset(64))); + ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForNativePcOffset(64 * kPcAlign))); ASSERT_EQ(0u, stack_map.GetDexPc()); - ASSERT_EQ(64u, stack_map.GetNativePcOffset(kRuntimeISA)); + ASSERT_EQ(64u * kPcAlign, stack_map.GetNativePcOffset(kRuntimeISA)); ASSERT_EQ(0x3u, code_info.GetRegisterMaskOf(stack_map)); ASSERT_TRUE(CheckStackMask(code_info, stack_map, sp_mask)); @@ -89,30 +85,17 @@ TEST(StackMapTest, Test1) { code_info.GetDexRegisterMapOf(stack_map, number_of_dex_registers); ASSERT_TRUE(dex_register_map.IsDexRegisterLive(0)); ASSERT_TRUE(dex_register_map.IsDexRegisterLive(1)); - ASSERT_EQ(2u, dex_register_map.GetNumberOfLiveDexRegisters(number_of_dex_registers)); - // The Dex register map contains: - // - one 1-byte live bit mask, and - // - one 1-byte set of location catalog entry indices composed of two 2-bit values. - size_t expected_dex_register_map_size = 1u + 1u; - ASSERT_EQ(expected_dex_register_map_size, dex_register_map.Size()); + ASSERT_EQ(2u, dex_register_map.GetNumberOfLiveDexRegisters()); ASSERT_EQ(Kind::kInStack, dex_register_map.GetLocationKind(0)); ASSERT_EQ(Kind::kConstant, dex_register_map.GetLocationKind(1)); - ASSERT_EQ(Kind::kInStack, dex_register_map.GetLocationInternalKind(0)); - ASSERT_EQ(Kind::kConstantLargeValue, dex_register_map.GetLocationInternalKind(1)); ASSERT_EQ(0, dex_register_map.GetStackOffsetInBytes(0)); ASSERT_EQ(-2, dex_register_map.GetConstant(1)); - size_t index0 = dex_register_map.GetLocationCatalogEntryIndex(0, number_of_catalog_entries); - size_t index1 = dex_register_map.GetLocationCatalogEntryIndex(1, number_of_catalog_entries); - ASSERT_EQ(0u, index0); - ASSERT_EQ(1u, index1); - DexRegisterLocation location0 = location_catalog.GetDexRegisterLocation(index0); - DexRegisterLocation location1 = location_catalog.GetDexRegisterLocation(index1); + DexRegisterLocation location0 = code_info.GetDexRegisterCatalogEntry(0); + DexRegisterLocation location1 = code_info.GetDexRegisterCatalogEntry(1); ASSERT_EQ(Kind::kInStack, location0.GetKind()); ASSERT_EQ(Kind::kConstant, location1.GetKind()); - ASSERT_EQ(Kind::kInStack, location0.GetInternalKind()); - ASSERT_EQ(Kind::kConstantLargeValue, location1.GetInternalKind()); ASSERT_EQ(0, location0.GetValue()); ASSERT_EQ(-2, location1.GetValue()); @@ -131,7 +114,7 @@ TEST(StackMapTest, Test2) { sp_mask1.SetBit(4); size_t number_of_dex_registers = 2; size_t number_of_dex_registers_in_inline_info = 0; - stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask1, number_of_dex_registers, 2); + stream.BeginStackMapEntry(0, 64 * kPcAlign, 0x3, &sp_mask1, number_of_dex_registers, 2); stream.AddDexRegisterEntry(Kind::kInStack, 0); // Short location. stream.AddDexRegisterEntry(Kind::kConstant, -2); // Large location. stream.BeginInlineInfoEntry(&art_method, 3, number_of_dex_registers_in_inline_info); @@ -143,7 +126,7 @@ TEST(StackMapTest, Test2) { ArenaBitVector sp_mask2(&allocator, 0, true); sp_mask2.SetBit(3); sp_mask2.SetBit(8); - stream.BeginStackMapEntry(1, 128, 0xFF, &sp_mask2, number_of_dex_registers, 0); + stream.BeginStackMapEntry(1, 128 * kPcAlign, 0xFF, &sp_mask2, number_of_dex_registers, 0); stream.AddDexRegisterEntry(Kind::kInRegister, 18); // Short location. stream.AddDexRegisterEntry(Kind::kInFpuRegister, 3); // Short location. stream.EndStackMapEntry(); @@ -151,7 +134,7 @@ TEST(StackMapTest, Test2) { ArenaBitVector sp_mask3(&allocator, 0, true); sp_mask3.SetBit(1); sp_mask3.SetBit(5); - stream.BeginStackMapEntry(2, 192, 0xAB, &sp_mask3, number_of_dex_registers, 0); + stream.BeginStackMapEntry(2, 192 * kPcAlign, 0xAB, &sp_mask3, number_of_dex_registers, 0); stream.AddDexRegisterEntry(Kind::kInRegister, 6); // Short location. stream.AddDexRegisterEntry(Kind::kInRegisterHigh, 8); // Short location. stream.EndStackMapEntry(); @@ -159,7 +142,7 @@ TEST(StackMapTest, Test2) { ArenaBitVector sp_mask4(&allocator, 0, true); sp_mask4.SetBit(6); sp_mask4.SetBit(7); - stream.BeginStackMapEntry(3, 256, 0xCD, &sp_mask4, number_of_dex_registers, 0); + stream.BeginStackMapEntry(3, 256 * kPcAlign, 0xCD, &sp_mask4, number_of_dex_registers, 0); stream.AddDexRegisterEntry(Kind::kInFpuRegister, 3); // Short location, same in stack map 2. stream.AddDexRegisterEntry(Kind::kInFpuRegisterHigh, 1); // Short location. stream.EndStackMapEntry(); @@ -174,20 +157,14 @@ TEST(StackMapTest, Test2) { uint32_t number_of_catalog_entries = code_info.GetNumberOfLocationCatalogEntries(); ASSERT_EQ(7u, number_of_catalog_entries); - DexRegisterLocationCatalog location_catalog = code_info.GetDexRegisterLocationCatalog(); - // The Dex register location catalog contains: - // - six 1-byte short Dex register locations, and - // - one 5-byte large Dex register location. - size_t expected_location_catalog_size = 6u * 1u + 5u; - ASSERT_EQ(expected_location_catalog_size, location_catalog.Size()); // First stack map. { StackMap stack_map = code_info.GetStackMapAt(0); ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForDexPc(0))); - ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForNativePcOffset(64))); + ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForNativePcOffset(64 * kPcAlign))); ASSERT_EQ(0u, stack_map.GetDexPc()); - ASSERT_EQ(64u, stack_map.GetNativePcOffset(kRuntimeISA)); + ASSERT_EQ(64u * kPcAlign, stack_map.GetNativePcOffset(kRuntimeISA)); ASSERT_EQ(0x3u, code_info.GetRegisterMaskOf(stack_map)); ASSERT_TRUE(CheckStackMask(code_info, stack_map, sp_mask1)); @@ -197,30 +174,17 @@ TEST(StackMapTest, Test2) { code_info.GetDexRegisterMapOf(stack_map, number_of_dex_registers); ASSERT_TRUE(dex_register_map.IsDexRegisterLive(0)); ASSERT_TRUE(dex_register_map.IsDexRegisterLive(1)); - ASSERT_EQ(2u, dex_register_map.GetNumberOfLiveDexRegisters(number_of_dex_registers)); - // The Dex register map contains: - // - one 1-byte live bit mask, and - // - one 1-byte set of location catalog entry indices composed of two 2-bit values. - size_t expected_dex_register_map_size = 1u + 1u; - ASSERT_EQ(expected_dex_register_map_size, dex_register_map.Size()); + ASSERT_EQ(2u, dex_register_map.GetNumberOfLiveDexRegisters()); ASSERT_EQ(Kind::kInStack, dex_register_map.GetLocationKind(0)); ASSERT_EQ(Kind::kConstant, dex_register_map.GetLocationKind(1)); - ASSERT_EQ(Kind::kInStack, dex_register_map.GetLocationInternalKind(0)); - ASSERT_EQ(Kind::kConstantLargeValue, dex_register_map.GetLocationInternalKind(1)); ASSERT_EQ(0, dex_register_map.GetStackOffsetInBytes(0)); ASSERT_EQ(-2, dex_register_map.GetConstant(1)); - size_t index0 = dex_register_map.GetLocationCatalogEntryIndex(0, number_of_catalog_entries); - size_t index1 = dex_register_map.GetLocationCatalogEntryIndex(1, number_of_catalog_entries); - ASSERT_EQ(0u, index0); - ASSERT_EQ(1u, index1); - DexRegisterLocation location0 = location_catalog.GetDexRegisterLocation(index0); - DexRegisterLocation location1 = location_catalog.GetDexRegisterLocation(index1); + DexRegisterLocation location0 = code_info.GetDexRegisterCatalogEntry(0); + DexRegisterLocation location1 = code_info.GetDexRegisterCatalogEntry(1); ASSERT_EQ(Kind::kInStack, location0.GetKind()); ASSERT_EQ(Kind::kConstant, location1.GetKind()); - ASSERT_EQ(Kind::kInStack, location0.GetInternalKind()); - ASSERT_EQ(Kind::kConstantLargeValue, location1.GetInternalKind()); ASSERT_EQ(0, location0.GetValue()); ASSERT_EQ(-2, location1.GetValue()); @@ -237,9 +201,9 @@ TEST(StackMapTest, Test2) { { StackMap stack_map = code_info.GetStackMapAt(1); ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForDexPc(1u))); - ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForNativePcOffset(128u))); + ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForNativePcOffset(128u * kPcAlign))); ASSERT_EQ(1u, stack_map.GetDexPc()); - ASSERT_EQ(128u, stack_map.GetNativePcOffset(kRuntimeISA)); + ASSERT_EQ(128u * kPcAlign, stack_map.GetNativePcOffset(kRuntimeISA)); ASSERT_EQ(0xFFu, code_info.GetRegisterMaskOf(stack_map)); ASSERT_TRUE(CheckStackMask(code_info, stack_map, sp_mask2)); @@ -249,30 +213,17 @@ TEST(StackMapTest, Test2) { code_info.GetDexRegisterMapOf(stack_map, number_of_dex_registers); ASSERT_TRUE(dex_register_map.IsDexRegisterLive(0)); ASSERT_TRUE(dex_register_map.IsDexRegisterLive(1)); - ASSERT_EQ(2u, dex_register_map.GetNumberOfLiveDexRegisters(number_of_dex_registers)); - // The Dex register map contains: - // - one 1-byte live bit mask, and - // - one 1-byte set of location catalog entry indices composed of two 2-bit values. - size_t expected_dex_register_map_size = 1u + 1u; - ASSERT_EQ(expected_dex_register_map_size, dex_register_map.Size()); + ASSERT_EQ(2u, dex_register_map.GetNumberOfLiveDexRegisters()); ASSERT_EQ(Kind::kInRegister, dex_register_map.GetLocationKind(0)); ASSERT_EQ(Kind::kInFpuRegister, dex_register_map.GetLocationKind(1)); - ASSERT_EQ(Kind::kInRegister, dex_register_map.GetLocationInternalKind(0)); - ASSERT_EQ(Kind::kInFpuRegister, dex_register_map.GetLocationInternalKind(1)); ASSERT_EQ(18, dex_register_map.GetMachineRegister(0)); ASSERT_EQ(3, dex_register_map.GetMachineRegister(1)); - size_t index0 = dex_register_map.GetLocationCatalogEntryIndex(0, number_of_catalog_entries); - size_t index1 = dex_register_map.GetLocationCatalogEntryIndex(1, number_of_catalog_entries); - ASSERT_EQ(2u, index0); - ASSERT_EQ(3u, index1); - DexRegisterLocation location0 = location_catalog.GetDexRegisterLocation(index0); - DexRegisterLocation location1 = location_catalog.GetDexRegisterLocation(index1); + DexRegisterLocation location0 = code_info.GetDexRegisterCatalogEntry(2); + DexRegisterLocation location1 = code_info.GetDexRegisterCatalogEntry(3); ASSERT_EQ(Kind::kInRegister, location0.GetKind()); ASSERT_EQ(Kind::kInFpuRegister, location1.GetKind()); - ASSERT_EQ(Kind::kInRegister, location0.GetInternalKind()); - ASSERT_EQ(Kind::kInFpuRegister, location1.GetInternalKind()); ASSERT_EQ(18, location0.GetValue()); ASSERT_EQ(3, location1.GetValue()); @@ -283,9 +234,9 @@ TEST(StackMapTest, Test2) { { StackMap stack_map = code_info.GetStackMapAt(2); ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForDexPc(2u))); - ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForNativePcOffset(192u))); + ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForNativePcOffset(192u * kPcAlign))); ASSERT_EQ(2u, stack_map.GetDexPc()); - ASSERT_EQ(192u, stack_map.GetNativePcOffset(kRuntimeISA)); + ASSERT_EQ(192u * kPcAlign, stack_map.GetNativePcOffset(kRuntimeISA)); ASSERT_EQ(0xABu, code_info.GetRegisterMaskOf(stack_map)); ASSERT_TRUE(CheckStackMask(code_info, stack_map, sp_mask3)); @@ -295,30 +246,17 @@ TEST(StackMapTest, Test2) { code_info.GetDexRegisterMapOf(stack_map, number_of_dex_registers); ASSERT_TRUE(dex_register_map.IsDexRegisterLive(0)); ASSERT_TRUE(dex_register_map.IsDexRegisterLive(1)); - ASSERT_EQ(2u, dex_register_map.GetNumberOfLiveDexRegisters(number_of_dex_registers)); - // The Dex register map contains: - // - one 1-byte live bit mask, and - // - one 1-byte set of location catalog entry indices composed of two 2-bit values. - size_t expected_dex_register_map_size = 1u + 1u; - ASSERT_EQ(expected_dex_register_map_size, dex_register_map.Size()); + ASSERT_EQ(2u, dex_register_map.GetNumberOfLiveDexRegisters()); ASSERT_EQ(Kind::kInRegister, dex_register_map.GetLocationKind(0)); ASSERT_EQ(Kind::kInRegisterHigh, dex_register_map.GetLocationKind(1)); - ASSERT_EQ(Kind::kInRegister, dex_register_map.GetLocationInternalKind(0)); - ASSERT_EQ(Kind::kInRegisterHigh, dex_register_map.GetLocationInternalKind(1)); ASSERT_EQ(6, dex_register_map.GetMachineRegister(0)); ASSERT_EQ(8, dex_register_map.GetMachineRegister(1)); - size_t index0 = dex_register_map.GetLocationCatalogEntryIndex(0, number_of_catalog_entries); - size_t index1 = dex_register_map.GetLocationCatalogEntryIndex(1, number_of_catalog_entries); - ASSERT_EQ(4u, index0); - ASSERT_EQ(5u, index1); - DexRegisterLocation location0 = location_catalog.GetDexRegisterLocation(index0); - DexRegisterLocation location1 = location_catalog.GetDexRegisterLocation(index1); + DexRegisterLocation location0 = code_info.GetDexRegisterCatalogEntry(4); + DexRegisterLocation location1 = code_info.GetDexRegisterCatalogEntry(5); ASSERT_EQ(Kind::kInRegister, location0.GetKind()); ASSERT_EQ(Kind::kInRegisterHigh, location1.GetKind()); - ASSERT_EQ(Kind::kInRegister, location0.GetInternalKind()); - ASSERT_EQ(Kind::kInRegisterHigh, location1.GetInternalKind()); ASSERT_EQ(6, location0.GetValue()); ASSERT_EQ(8, location1.GetValue()); @@ -329,9 +267,9 @@ TEST(StackMapTest, Test2) { { StackMap stack_map = code_info.GetStackMapAt(3); ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForDexPc(3u))); - ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForNativePcOffset(256u))); + ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForNativePcOffset(256u * kPcAlign))); ASSERT_EQ(3u, stack_map.GetDexPc()); - ASSERT_EQ(256u, stack_map.GetNativePcOffset(kRuntimeISA)); + ASSERT_EQ(256u * kPcAlign, stack_map.GetNativePcOffset(kRuntimeISA)); ASSERT_EQ(0xCDu, code_info.GetRegisterMaskOf(stack_map)); ASSERT_TRUE(CheckStackMask(code_info, stack_map, sp_mask4)); @@ -341,30 +279,17 @@ TEST(StackMapTest, Test2) { code_info.GetDexRegisterMapOf(stack_map, number_of_dex_registers); ASSERT_TRUE(dex_register_map.IsDexRegisterLive(0)); ASSERT_TRUE(dex_register_map.IsDexRegisterLive(1)); - ASSERT_EQ(2u, dex_register_map.GetNumberOfLiveDexRegisters(number_of_dex_registers)); - // The Dex register map contains: - // - one 1-byte live bit mask, and - // - one 1-byte set of location catalog entry indices composed of two 2-bit values. - size_t expected_dex_register_map_size = 1u + 1u; - ASSERT_EQ(expected_dex_register_map_size, dex_register_map.Size()); + ASSERT_EQ(2u, dex_register_map.GetNumberOfLiveDexRegisters()); ASSERT_EQ(Kind::kInFpuRegister, dex_register_map.GetLocationKind(0)); ASSERT_EQ(Kind::kInFpuRegisterHigh, dex_register_map.GetLocationKind(1)); - ASSERT_EQ(Kind::kInFpuRegister, dex_register_map.GetLocationInternalKind(0)); - ASSERT_EQ(Kind::kInFpuRegisterHigh, dex_register_map.GetLocationInternalKind(1)); ASSERT_EQ(3, dex_register_map.GetMachineRegister(0)); ASSERT_EQ(1, dex_register_map.GetMachineRegister(1)); - size_t index0 = dex_register_map.GetLocationCatalogEntryIndex(0, number_of_catalog_entries); - size_t index1 = dex_register_map.GetLocationCatalogEntryIndex(1, number_of_catalog_entries); - ASSERT_EQ(3u, index0); // Shared with second stack map. - ASSERT_EQ(6u, index1); - DexRegisterLocation location0 = location_catalog.GetDexRegisterLocation(index0); - DexRegisterLocation location1 = location_catalog.GetDexRegisterLocation(index1); + DexRegisterLocation location0 = code_info.GetDexRegisterCatalogEntry(3); + DexRegisterLocation location1 = code_info.GetDexRegisterCatalogEntry(6); ASSERT_EQ(Kind::kInFpuRegister, location0.GetKind()); ASSERT_EQ(Kind::kInFpuRegisterHigh, location1.GetKind()); - ASSERT_EQ(Kind::kInFpuRegister, location0.GetInternalKind()); - ASSERT_EQ(Kind::kInFpuRegisterHigh, location1.GetInternalKind()); ASSERT_EQ(3, location0.GetValue()); ASSERT_EQ(1, location1.GetValue()); @@ -384,7 +309,7 @@ TEST(StackMapTest, TestDeduplicateInlineInfoDexRegisterMap) { sp_mask1.SetBit(4); const size_t number_of_dex_registers = 2; const size_t number_of_dex_registers_in_inline_info = 2; - stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask1, number_of_dex_registers, 1); + stream.BeginStackMapEntry(0, 64 * kPcAlign, 0x3, &sp_mask1, number_of_dex_registers, 1); stream.AddDexRegisterEntry(Kind::kInStack, 0); // Short location. stream.AddDexRegisterEntry(Kind::kConstant, -2); // Large location. stream.BeginInlineInfoEntry(&art_method, 3, number_of_dex_registers_in_inline_info); @@ -403,20 +328,14 @@ TEST(StackMapTest, TestDeduplicateInlineInfoDexRegisterMap) { uint32_t number_of_catalog_entries = code_info.GetNumberOfLocationCatalogEntries(); ASSERT_EQ(2u, number_of_catalog_entries); - DexRegisterLocationCatalog location_catalog = code_info.GetDexRegisterLocationCatalog(); - // The Dex register location catalog contains: - // - one 1-byte short Dex register locations, and - // - one 5-byte large Dex register location. - const size_t expected_location_catalog_size = 1u + 5u; - ASSERT_EQ(expected_location_catalog_size, location_catalog.Size()); // First stack map. { StackMap stack_map = code_info.GetStackMapAt(0); ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForDexPc(0))); - ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForNativePcOffset(64))); + ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForNativePcOffset(64 * kPcAlign))); ASSERT_EQ(0u, stack_map.GetDexPc()); - ASSERT_EQ(64u, stack_map.GetNativePcOffset(kRuntimeISA)); + ASSERT_EQ(64u * kPcAlign, stack_map.GetNativePcOffset(kRuntimeISA)); ASSERT_EQ(0x3u, code_info.GetRegisterMaskOf(stack_map)); ASSERT_TRUE(CheckStackMask(code_info, stack_map, sp_mask1)); @@ -425,30 +344,17 @@ TEST(StackMapTest, TestDeduplicateInlineInfoDexRegisterMap) { DexRegisterMap map(code_info.GetDexRegisterMapOf(stack_map, number_of_dex_registers)); ASSERT_TRUE(map.IsDexRegisterLive(0)); ASSERT_TRUE(map.IsDexRegisterLive(1)); - ASSERT_EQ(2u, map.GetNumberOfLiveDexRegisters(number_of_dex_registers)); - // The Dex register map contains: - // - one 1-byte live bit mask, and - // - one 1-byte set of location catalog entry indices composed of two 2-bit values. - size_t expected_map_size = 1u + 1u; - ASSERT_EQ(expected_map_size, map.Size()); + ASSERT_EQ(2u, map.GetNumberOfLiveDexRegisters()); ASSERT_EQ(Kind::kInStack, map.GetLocationKind(0)); ASSERT_EQ(Kind::kConstant, map.GetLocationKind(1)); - ASSERT_EQ(Kind::kInStack, map.GetLocationInternalKind(0)); - ASSERT_EQ(Kind::kConstantLargeValue, map.GetLocationInternalKind(1)); ASSERT_EQ(0, map.GetStackOffsetInBytes(0)); ASSERT_EQ(-2, map.GetConstant(1)); - const size_t index0 = map.GetLocationCatalogEntryIndex(0, number_of_catalog_entries); - const size_t index1 = map.GetLocationCatalogEntryIndex(1, number_of_catalog_entries); - ASSERT_EQ(0u, index0); - ASSERT_EQ(1u, index1); - DexRegisterLocation location0 = location_catalog.GetDexRegisterLocation(index0); - DexRegisterLocation location1 = location_catalog.GetDexRegisterLocation(index1); + DexRegisterLocation location0 = code_info.GetDexRegisterCatalogEntry(0); + DexRegisterLocation location1 = code_info.GetDexRegisterCatalogEntry(1); ASSERT_EQ(Kind::kInStack, location0.GetKind()); ASSERT_EQ(Kind::kConstant, location1.GetKind()); - ASSERT_EQ(Kind::kInStack, location0.GetInternalKind()); - ASSERT_EQ(Kind::kConstantLargeValue, location1.GetInternalKind()); ASSERT_EQ(0, location0.GetValue()); ASSERT_EQ(-2, location1.GetValue()); @@ -456,8 +362,8 @@ TEST(StackMapTest, TestDeduplicateInlineInfoDexRegisterMap) { // one. ASSERT_TRUE(stack_map.HasInlineInfo()); InlineInfo inline_info = code_info.GetInlineInfoOf(stack_map); - EXPECT_EQ(inline_info.GetDexRegisterMapOffsetAtDepth(0), - stack_map.GetDexRegisterMapOffset()); + EXPECT_EQ(inline_info.GetDexRegisterMapIndexAtDepth(0), + stack_map.GetDexRegisterMapIndex()); } } @@ -469,7 +375,7 @@ TEST(StackMapTest, TestNonLiveDexRegisters) { ArenaBitVector sp_mask(&allocator, 0, false); uint32_t number_of_dex_registers = 2; - stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask, number_of_dex_registers, 0); + stream.BeginStackMapEntry(0, 64 * kPcAlign, 0x3, &sp_mask, number_of_dex_registers, 0); stream.AddDexRegisterEntry(Kind::kNone, 0); // No location. stream.AddDexRegisterEntry(Kind::kConstant, -2); // Large location. stream.EndStackMapEntry(); @@ -484,17 +390,12 @@ TEST(StackMapTest, TestNonLiveDexRegisters) { uint32_t number_of_catalog_entries = code_info.GetNumberOfLocationCatalogEntries(); ASSERT_EQ(1u, number_of_catalog_entries); - DexRegisterLocationCatalog location_catalog = code_info.GetDexRegisterLocationCatalog(); - // The Dex register location catalog contains: - // - one 5-byte large Dex register location. - size_t expected_location_catalog_size = 5u; - ASSERT_EQ(expected_location_catalog_size, location_catalog.Size()); StackMap stack_map = code_info.GetStackMapAt(0); ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForDexPc(0))); - ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForNativePcOffset(64))); + ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForNativePcOffset(64 * kPcAlign))); ASSERT_EQ(0u, stack_map.GetDexPc()); - ASSERT_EQ(64u, stack_map.GetNativePcOffset(kRuntimeISA)); + ASSERT_EQ(64u * kPcAlign, stack_map.GetNativePcOffset(kRuntimeISA)); ASSERT_EQ(0x3u, code_info.GetRegisterMaskOf(stack_map)); ASSERT_TRUE(stack_map.HasDexRegisterMap()); @@ -502,100 +403,19 @@ TEST(StackMapTest, TestNonLiveDexRegisters) { code_info.GetDexRegisterMapOf(stack_map, number_of_dex_registers); ASSERT_FALSE(dex_register_map.IsDexRegisterLive(0)); ASSERT_TRUE(dex_register_map.IsDexRegisterLive(1)); - ASSERT_EQ(1u, dex_register_map.GetNumberOfLiveDexRegisters(number_of_dex_registers)); - // The Dex register map contains: - // - one 1-byte live bit mask. - // No space is allocated for the sole location catalog entry index, as it is useless. - size_t expected_dex_register_map_size = 1u + 0u; - ASSERT_EQ(expected_dex_register_map_size, dex_register_map.Size()); + ASSERT_EQ(1u, dex_register_map.GetNumberOfLiveDexRegisters()); ASSERT_EQ(Kind::kNone, dex_register_map.GetLocationKind(0)); ASSERT_EQ(Kind::kConstant, dex_register_map.GetLocationKind(1)); - ASSERT_EQ(Kind::kNone, dex_register_map.GetLocationInternalKind(0)); - ASSERT_EQ(Kind::kConstantLargeValue, dex_register_map.GetLocationInternalKind(1)); ASSERT_EQ(-2, dex_register_map.GetConstant(1)); - size_t index0 = dex_register_map.GetLocationCatalogEntryIndex(0, number_of_catalog_entries); - size_t index1 = dex_register_map.GetLocationCatalogEntryIndex(1, number_of_catalog_entries); - ASSERT_EQ(DexRegisterLocationCatalog::kNoLocationEntryIndex, index0); - ASSERT_EQ(0u, index1); - DexRegisterLocation location0 = location_catalog.GetDexRegisterLocation(index0); - DexRegisterLocation location1 = location_catalog.GetDexRegisterLocation(index1); - ASSERT_EQ(Kind::kNone, location0.GetKind()); + DexRegisterLocation location1 = code_info.GetDexRegisterCatalogEntry(0); ASSERT_EQ(Kind::kConstant, location1.GetKind()); - ASSERT_EQ(Kind::kNone, location0.GetInternalKind()); - ASSERT_EQ(Kind::kConstantLargeValue, location1.GetInternalKind()); - ASSERT_EQ(0, location0.GetValue()); ASSERT_EQ(-2, location1.GetValue()); ASSERT_FALSE(stack_map.HasInlineInfo()); } -// Generate a stack map whose dex register offset is -// StackMap::kNoDexRegisterMapSmallEncoding, and ensure we do -// not treat it as kNoDexRegisterMap. -TEST(StackMapTest, DexRegisterMapOffsetOverflow) { - MallocArenaPool pool; - ArenaStack arena_stack(&pool); - ScopedArenaAllocator allocator(&arena_stack); - StackMapStream stream(&allocator, kRuntimeISA); - - ArenaBitVector sp_mask(&allocator, 0, false); - uint32_t number_of_dex_registers = 1024; - // Create the first stack map (and its Dex register map). - stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask, number_of_dex_registers, 0); - uint32_t number_of_dex_live_registers_in_dex_register_map_0 = number_of_dex_registers - 8; - for (uint32_t i = 0; i < number_of_dex_live_registers_in_dex_register_map_0; ++i) { - // Use two different Dex register locations to populate this map, - // as using a single value (in the whole CodeInfo object) would - // make this Dex register mapping data empty (see - // art::DexRegisterMap::SingleEntrySizeInBits). - stream.AddDexRegisterEntry(Kind::kConstant, i % 2); // Short location. - } - stream.EndStackMapEntry(); - // Create the second stack map (and its Dex register map). - stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask, number_of_dex_registers, 0); - for (uint32_t i = 0; i < number_of_dex_registers; ++i) { - stream.AddDexRegisterEntry(Kind::kConstant, 0); // Short location. - } - stream.EndStackMapEntry(); - - size_t size = stream.PrepareForFillIn(); - void* memory = allocator.Alloc(size, kArenaAllocMisc); - MemoryRegion region(memory, size); - stream.FillInCodeInfo(region); - - CodeInfo code_info(region); - // The location catalog contains two entries (DexRegisterLocation(kConstant, 0) - // and DexRegisterLocation(kConstant, 1)), therefore the location catalog index - // has a size of 1 bit. - uint32_t number_of_catalog_entries = code_info.GetNumberOfLocationCatalogEntries(); - ASSERT_EQ(2u, number_of_catalog_entries); - ASSERT_EQ(1u, DexRegisterMap::SingleEntrySizeInBits(number_of_catalog_entries)); - - // The first Dex register map contains: - // - a live register bit mask for 1024 registers (that is, 128 bytes of - // data); and - // - Dex register mapping information for 1016 1-bit Dex (live) register - // locations (that is, 127 bytes of data). - // Hence it has a size of 255 bytes, and therefore... - ASSERT_EQ(128u, DexRegisterMap::GetLiveBitMaskSize(number_of_dex_registers)); - StackMap stack_map0 = code_info.GetStackMapAt(0); - DexRegisterMap dex_register_map0 = - code_info.GetDexRegisterMapOf(stack_map0, number_of_dex_registers); - ASSERT_EQ(127u, dex_register_map0.GetLocationMappingDataSize(number_of_catalog_entries)); - ASSERT_EQ(255u, dex_register_map0.Size()); - - StackMap stack_map1 = code_info.GetStackMapAt(1); - ASSERT_TRUE(stack_map1.HasDexRegisterMap()); - // ...the offset of the second Dex register map (relative to the - // beginning of the Dex register maps region) is 255 (i.e., - // kNoDexRegisterMapSmallEncoding). - ASSERT_NE(stack_map1.GetDexRegisterMapOffset(), - StackMap::kNoValue); - ASSERT_EQ(stack_map1.GetDexRegisterMapOffset(), 0xFFu); -} - TEST(StackMapTest, TestShareDexRegisterMap) { MallocArenaPool pool; ArenaStack arena_stack(&pool); @@ -605,17 +425,17 @@ TEST(StackMapTest, TestShareDexRegisterMap) { ArenaBitVector sp_mask(&allocator, 0, false); uint32_t number_of_dex_registers = 2; // First stack map. - stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask, number_of_dex_registers, 0); + stream.BeginStackMapEntry(0, 64 * kPcAlign, 0x3, &sp_mask, number_of_dex_registers, 0); stream.AddDexRegisterEntry(Kind::kInRegister, 0); // Short location. stream.AddDexRegisterEntry(Kind::kConstant, -2); // Large location. stream.EndStackMapEntry(); // Second stack map, which should share the same dex register map. - stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask, number_of_dex_registers, 0); + stream.BeginStackMapEntry(0, 64 * kPcAlign, 0x3, &sp_mask, number_of_dex_registers, 0); stream.AddDexRegisterEntry(Kind::kInRegister, 0); // Short location. stream.AddDexRegisterEntry(Kind::kConstant, -2); // Large location. stream.EndStackMapEntry(); // Third stack map (doesn't share the dex register map). - stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask, number_of_dex_registers, 0); + stream.BeginStackMapEntry(0, 64 * kPcAlign, 0x3, &sp_mask, number_of_dex_registers, 0); stream.AddDexRegisterEntry(Kind::kInRegister, 2); // Short location. stream.AddDexRegisterEntry(Kind::kConstant, -2); // Large location. stream.EndStackMapEntry(); @@ -646,12 +466,12 @@ TEST(StackMapTest, TestShareDexRegisterMap) { ASSERT_EQ(-2, dex_registers2.GetConstant(1)); // Verify dex register map offsets. - ASSERT_EQ(sm0.GetDexRegisterMapOffset(), - sm1.GetDexRegisterMapOffset()); - ASSERT_NE(sm0.GetDexRegisterMapOffset(), - sm2.GetDexRegisterMapOffset()); - ASSERT_NE(sm1.GetDexRegisterMapOffset(), - sm2.GetDexRegisterMapOffset()); + ASSERT_EQ(sm0.GetDexRegisterMapIndex(), + sm1.GetDexRegisterMapIndex()); + ASSERT_NE(sm0.GetDexRegisterMapIndex(), + sm2.GetDexRegisterMapIndex()); + ASSERT_NE(sm1.GetDexRegisterMapIndex(), + sm2.GetDexRegisterMapIndex()); } TEST(StackMapTest, TestNoDexRegisterMap) { @@ -662,11 +482,12 @@ TEST(StackMapTest, TestNoDexRegisterMap) { ArenaBitVector sp_mask(&allocator, 0, false); uint32_t number_of_dex_registers = 0; - stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask, number_of_dex_registers, 0); + stream.BeginStackMapEntry(0, 64 * kPcAlign, 0x3, &sp_mask, number_of_dex_registers, 0); stream.EndStackMapEntry(); number_of_dex_registers = 1; - stream.BeginStackMapEntry(1, 68, 0x4, &sp_mask, number_of_dex_registers, 0); + stream.BeginStackMapEntry(1, 68 * kPcAlign, 0x4, &sp_mask, number_of_dex_registers, 0); + stream.AddDexRegisterEntry(Kind::kNone, 0); stream.EndStackMapEntry(); size_t size = stream.PrepareForFillIn(); @@ -679,14 +500,12 @@ TEST(StackMapTest, TestNoDexRegisterMap) { uint32_t number_of_catalog_entries = code_info.GetNumberOfLocationCatalogEntries(); ASSERT_EQ(0u, number_of_catalog_entries); - DexRegisterLocationCatalog location_catalog = code_info.GetDexRegisterLocationCatalog(); - ASSERT_EQ(0u, location_catalog.Size()); StackMap stack_map = code_info.GetStackMapAt(0); ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForDexPc(0))); - ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForNativePcOffset(64))); + ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForNativePcOffset(64 * kPcAlign))); ASSERT_EQ(0u, stack_map.GetDexPc()); - ASSERT_EQ(64u, stack_map.GetNativePcOffset(kRuntimeISA)); + ASSERT_EQ(64u * kPcAlign, stack_map.GetNativePcOffset(kRuntimeISA)); ASSERT_EQ(0x3u, code_info.GetRegisterMaskOf(stack_map)); ASSERT_FALSE(stack_map.HasDexRegisterMap()); @@ -694,12 +513,12 @@ TEST(StackMapTest, TestNoDexRegisterMap) { stack_map = code_info.GetStackMapAt(1); ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForDexPc(1))); - ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForNativePcOffset(68))); + ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForNativePcOffset(68 * kPcAlign))); ASSERT_EQ(1u, stack_map.GetDexPc()); - ASSERT_EQ(68u, stack_map.GetNativePcOffset(kRuntimeISA)); + ASSERT_EQ(68u * kPcAlign, stack_map.GetNativePcOffset(kRuntimeISA)); ASSERT_EQ(0x4u, code_info.GetRegisterMaskOf(stack_map)); - ASSERT_FALSE(stack_map.HasDexRegisterMap()); + ASSERT_TRUE(stack_map.HasDexRegisterMap()); ASSERT_FALSE(stack_map.HasInlineInfo()); } @@ -715,7 +534,7 @@ TEST(StackMapTest, InlineTest) { sp_mask1.SetBit(4); // First stack map. - stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask1, 2, 2); + stream.BeginStackMapEntry(0, 64 * kPcAlign, 0x3, &sp_mask1, 2, 2); stream.AddDexRegisterEntry(Kind::kInStack, 0); stream.AddDexRegisterEntry(Kind::kConstant, 4); @@ -731,7 +550,7 @@ TEST(StackMapTest, InlineTest) { stream.EndStackMapEntry(); // Second stack map. - stream.BeginStackMapEntry(2, 22, 0x3, &sp_mask1, 2, 3); + stream.BeginStackMapEntry(2, 22 * kPcAlign, 0x3, &sp_mask1, 2, 3); stream.AddDexRegisterEntry(Kind::kInStack, 56); stream.AddDexRegisterEntry(Kind::kConstant, 0); @@ -749,13 +568,13 @@ TEST(StackMapTest, InlineTest) { stream.EndStackMapEntry(); // Third stack map. - stream.BeginStackMapEntry(4, 56, 0x3, &sp_mask1, 2, 0); + stream.BeginStackMapEntry(4, 56 * kPcAlign, 0x3, &sp_mask1, 2, 0); stream.AddDexRegisterEntry(Kind::kNone, 0); stream.AddDexRegisterEntry(Kind::kConstant, 4); stream.EndStackMapEntry(); // Fourth stack map. - stream.BeginStackMapEntry(6, 78, 0x3, &sp_mask1, 2, 3); + stream.BeginStackMapEntry(6, 78 * kPcAlign, 0x3, &sp_mask1, 2, 3); stream.AddDexRegisterEntry(Kind::kInStack, 56); stream.AddDexRegisterEntry(Kind::kConstant, 0); @@ -869,6 +688,7 @@ TEST(StackMapTest, InlineTest) { } TEST(StackMapTest, PackedNativePcTest) { + // Test minimum alignments, and decoding. uint32_t packed_thumb2 = StackMap::PackNativePc(kThumb2InstructionAlignment, InstructionSet::kThumb2); uint32_t packed_arm64 = @@ -904,9 +724,9 @@ TEST(StackMapTest, TestDeduplicateStackMask) { ArenaBitVector sp_mask(&allocator, 0, true); sp_mask.SetBit(1); sp_mask.SetBit(4); - stream.BeginStackMapEntry(0, 4, 0x3, &sp_mask, 0, 0); + stream.BeginStackMapEntry(0, 4 * kPcAlign, 0x3, &sp_mask, 0, 0); stream.EndStackMapEntry(); - stream.BeginStackMapEntry(0, 8, 0x3, &sp_mask, 0, 0); + stream.BeginStackMapEntry(0, 8 * kPcAlign, 0x3, &sp_mask, 0, 0); stream.EndStackMapEntry(); size_t size = stream.PrepareForFillIn(); @@ -917,8 +737,8 @@ TEST(StackMapTest, TestDeduplicateStackMask) { CodeInfo code_info(region); ASSERT_EQ(2u, code_info.GetNumberOfStackMaps()); - StackMap stack_map1 = code_info.GetStackMapForNativePcOffset(4); - StackMap stack_map2 = code_info.GetStackMapForNativePcOffset(8); + StackMap stack_map1 = code_info.GetStackMapForNativePcOffset(4 * kPcAlign); + StackMap stack_map2 = code_info.GetStackMapForNativePcOffset(8 * kPcAlign); EXPECT_EQ(stack_map1.GetStackMaskIndex(), stack_map2.GetStackMaskIndex()); } @@ -931,13 +751,13 @@ TEST(StackMapTest, TestInvokeInfo) { ArenaBitVector sp_mask(&allocator, 0, true); sp_mask.SetBit(1); - stream.BeginStackMapEntry(0, 4, 0x3, &sp_mask, 0, 0); + stream.BeginStackMapEntry(0, 4 * kPcAlign, 0x3, &sp_mask, 0, 0); stream.AddInvoke(kSuper, 1); stream.EndStackMapEntry(); - stream.BeginStackMapEntry(0, 8, 0x3, &sp_mask, 0, 0); + stream.BeginStackMapEntry(0, 8 * kPcAlign, 0x3, &sp_mask, 0, 0); stream.AddInvoke(kStatic, 3); stream.EndStackMapEntry(); - stream.BeginStackMapEntry(0, 16, 0x3, &sp_mask, 0, 0); + stream.BeginStackMapEntry(0, 16 * kPcAlign, 0x3, &sp_mask, 0, 0); stream.AddInvoke(kDirect, 65535); stream.EndStackMapEntry(); @@ -954,9 +774,9 @@ TEST(StackMapTest, TestInvokeInfo) { MethodInfo method_info(method_info_region.begin()); ASSERT_EQ(3u, code_info.GetNumberOfStackMaps()); - InvokeInfo invoke1(code_info.GetInvokeInfoForNativePcOffset(4)); - InvokeInfo invoke2(code_info.GetInvokeInfoForNativePcOffset(8)); - InvokeInfo invoke3(code_info.GetInvokeInfoForNativePcOffset(16)); + InvokeInfo invoke1(code_info.GetInvokeInfoForNativePcOffset(4 * kPcAlign)); + InvokeInfo invoke2(code_info.GetInvokeInfoForNativePcOffset(8 * kPcAlign)); + InvokeInfo invoke3(code_info.GetInvokeInfoForNativePcOffset(16 * kPcAlign)); InvokeInfo invoke_invalid(code_info.GetInvokeInfoForNativePcOffset(12)); EXPECT_FALSE(invoke_invalid.IsValid()); // No entry for that index. EXPECT_TRUE(invoke1.IsValid()); @@ -964,13 +784,13 @@ TEST(StackMapTest, TestInvokeInfo) { EXPECT_TRUE(invoke3.IsValid()); EXPECT_EQ(invoke1.GetInvokeType(), kSuper); EXPECT_EQ(invoke1.GetMethodIndex(method_info), 1u); - EXPECT_EQ(invoke1.GetNativePcOffset(kRuntimeISA), 4u); + EXPECT_EQ(invoke1.GetNativePcOffset(kRuntimeISA), 4u * kPcAlign); EXPECT_EQ(invoke2.GetInvokeType(), kStatic); EXPECT_EQ(invoke2.GetMethodIndex(method_info), 3u); - EXPECT_EQ(invoke2.GetNativePcOffset(kRuntimeISA), 8u); + EXPECT_EQ(invoke2.GetNativePcOffset(kRuntimeISA), 8u * kPcAlign); EXPECT_EQ(invoke3.GetInvokeType(), kDirect); EXPECT_EQ(invoke3.GetMethodIndex(method_info), 65535u); - EXPECT_EQ(invoke3.GetNativePcOffset(kRuntimeISA), 16u); + EXPECT_EQ(invoke3.GetNativePcOffset(kRuntimeISA), 16u * kPcAlign); } } // namespace art diff --git a/compiler/verifier_deps_test.cc b/compiler/verifier_deps_test.cc index c0892ff466..3fe2ec0ac0 100644 --- a/compiler/verifier_deps_test.cc +++ b/compiler/verifier_deps_test.cc @@ -65,17 +65,16 @@ class VerifierDepsTest : public CommonCompilerTest { callbacks_.reset(new VerifierDepsCompilerCallbacks()); } - mirror::Class* FindClassByName(const std::string& name, ScopedObjectAccess* soa) + ObjPtr<mirror::Class> FindClassByName(ScopedObjectAccess& soa, const std::string& name) REQUIRES_SHARED(Locks::mutator_lock_) { - StackHandleScope<1> hs(Thread::Current()); + StackHandleScope<1> hs(soa.Self()); Handle<mirror::ClassLoader> class_loader_handle( - hs.NewHandle(soa->Decode<mirror::ClassLoader>(class_loader_))); - mirror::Class* klass = class_linker_->FindClass(Thread::Current(), - name.c_str(), - class_loader_handle); + hs.NewHandle(soa.Decode<mirror::ClassLoader>(class_loader_))); + ObjPtr<mirror::Class> klass = + class_linker_->FindClass(soa.Self(), name.c_str(), class_loader_handle); if (klass == nullptr) { - DCHECK(Thread::Current()->IsExceptionPending()); - Thread::Current()->ClearException(); + DCHECK(soa.Self()->IsExceptionPending()); + soa.Self()->ClearException(); } return klass; } @@ -114,16 +113,16 @@ class VerifierDepsTest : public CommonCompilerTest { callbacks->SetVerifierDeps(verifier_deps_.get()); } - void LoadDexFile(ScopedObjectAccess* soa, const char* name1, const char* name2 = nullptr) + void LoadDexFile(ScopedObjectAccess& soa, const char* name1, const char* name2 = nullptr) REQUIRES_SHARED(Locks::mutator_lock_) { class_loader_ = (name2 == nullptr) ? LoadDex(name1) : LoadMultiDex(name1, name2); dex_files_ = GetDexFiles(class_loader_); primary_dex_file_ = dex_files_.front(); SetVerifierDeps(dex_files_); - StackHandleScope<1> hs(soa->Self()); + StackHandleScope<1> hs(soa.Self()); Handle<mirror::ClassLoader> loader = - hs.NewHandle(soa->Decode<mirror::ClassLoader>(class_loader_)); + hs.NewHandle(soa.Decode<mirror::ClassLoader>(class_loader_)); for (const DexFile* dex_file : dex_files_) { class_linker_->RegisterDexFile(*dex_file, loader.Get()); } @@ -133,16 +132,16 @@ class VerifierDepsTest : public CommonCompilerTest { compiler_driver_->SetDexFilesForOatFile(dex_files_); } - void LoadDexFile(ScopedObjectAccess* soa) REQUIRES_SHARED(Locks::mutator_lock_) { + void LoadDexFile(ScopedObjectAccess& soa) REQUIRES_SHARED(Locks::mutator_lock_) { LoadDexFile(soa, "VerifierDeps"); CHECK_EQ(dex_files_.size(), 1u); - klass_Main_ = FindClassByName("LMain;", soa); + klass_Main_ = FindClassByName(soa, "LMain;"); CHECK(klass_Main_ != nullptr); } bool VerifyMethod(const std::string& method_name) { ScopedObjectAccess soa(Thread::Current()); - LoadDexFile(&soa); + LoadDexFile(soa); StackHandleScope<2> hs(soa.Self()); Handle<mirror::ClassLoader> class_loader_handle( @@ -193,7 +192,7 @@ class VerifierDepsTest : public CommonCompilerTest { void VerifyDexFile(const char* multidex = nullptr) { { ScopedObjectAccess soa(Thread::Current()); - LoadDexFile(&soa, "VerifierDeps", multidex); + LoadDexFile(soa, "VerifierDeps", multidex); } SetupCompilerDriver(); VerifyWithCompilerDriver(/* verifier_deps */ nullptr); @@ -204,13 +203,14 @@ class VerifierDepsTest : public CommonCompilerTest { bool is_strict, bool is_assignable) { ScopedObjectAccess soa(Thread::Current()); - LoadDexFile(&soa); - mirror::Class* klass_dst = FindClassByName(dst, &soa); + LoadDexFile(soa); + StackHandleScope<1> hs(soa.Self()); + Handle<mirror::Class> klass_dst = hs.NewHandle(FindClassByName(soa, dst)); DCHECK(klass_dst != nullptr) << dst; - mirror::Class* klass_src = FindClassByName(src, &soa); + ObjPtr<mirror::Class> klass_src = FindClassByName(soa, src); DCHECK(klass_src != nullptr) << src; verifier_deps_->AddAssignability(*primary_dex_file_, - klass_dst, + klass_dst.Get(), klass_src, is_strict, is_assignable); @@ -453,12 +453,12 @@ class VerifierDepsTest : public CommonCompilerTest { std::vector<const DexFile*> dex_files_; const DexFile* primary_dex_file_; jobject class_loader_; - mirror::Class* klass_Main_; + ObjPtr<mirror::Class> klass_Main_; }; TEST_F(VerifierDepsTest, StringToId) { ScopedObjectAccess soa(Thread::Current()); - LoadDexFile(&soa); + LoadDexFile(soa); dex::StringIndex id_Main1 = verifier_deps_->GetIdFromString(*primary_dex_file_, "LMain;"); ASSERT_LT(id_Main1.index_, primary_dex_file_->NumStringIds()); @@ -1441,7 +1441,7 @@ TEST_F(VerifierDepsTest, CompilerDriver) { for (bool verify_failure : { false, true }) { { ScopedObjectAccess soa(Thread::Current()); - LoadDexFile(&soa, "VerifierDeps", multi); + LoadDexFile(soa, "VerifierDeps", multi); } VerifyWithCompilerDriver(/* verifier_deps */ nullptr); @@ -1450,7 +1450,7 @@ TEST_F(VerifierDepsTest, CompilerDriver) { { ScopedObjectAccess soa(Thread::Current()); - LoadDexFile(&soa, "VerifierDeps", multi); + LoadDexFile(soa, "VerifierDeps", multi); } verifier::VerifierDeps decoded_deps(dex_files_, ArrayRef<const uint8_t>(buffer)); if (verify_failure) { diff --git a/dex2oat/linker/image_test.cc b/dex2oat/linker/image_test.cc index ab6e7a875a..96c48b8798 100644 --- a/dex2oat/linker/image_test.cc +++ b/dex2oat/linker/image_test.cc @@ -111,18 +111,18 @@ TEST_F(ImageTest, TestDefaultMethods) { // Test the pointer to quick code is the same in origin method // and in the copied method form the same oat file. - mirror::Class* iface_klass = class_linker_->LookupClass( - self, "LIface;", ObjPtr<mirror::ClassLoader>()); + ObjPtr<mirror::Class> iface_klass = + class_linker_->LookupClass(self, "LIface;", /* class_loader */ nullptr); ASSERT_NE(nullptr, iface_klass); ArtMethod* origin = iface_klass->FindInterfaceMethod("defaultMethod", "()V", pointer_size); ASSERT_NE(nullptr, origin); - ASSERT_TRUE(origin->GetDeclaringClass() == iface_klass); + ASSERT_OBJ_PTR_EQ(origin->GetDeclaringClass(), iface_klass); const void* code = origin->GetEntryPointFromQuickCompiledCodePtrSize(pointer_size); // The origin method should have a pointer to quick code ASSERT_NE(nullptr, code); ASSERT_FALSE(class_linker_->IsQuickToInterpreterBridge(code)); - mirror::Class* impl_klass = class_linker_->LookupClass( - self, "LImpl;", ObjPtr<mirror::ClassLoader>()); + ObjPtr<mirror::Class> impl_klass = + class_linker_->LookupClass(self, "LImpl;", /* class_loader */ nullptr); ASSERT_NE(nullptr, impl_klass); ArtMethod* copied = FindCopiedMethod(origin, impl_klass); ASSERT_NE(nullptr, copied); @@ -132,20 +132,20 @@ TEST_F(ImageTest, TestDefaultMethods) { // Test the origin method has pointer to quick code // but the copied method has pointer to interpreter // because these methods are in different oat files. - mirror::Class* iterable_klass = class_linker_->LookupClass( - self, "Ljava/lang/Iterable;", ObjPtr<mirror::ClassLoader>()); + ObjPtr<mirror::Class> iterable_klass = + class_linker_->LookupClass(self, "Ljava/lang/Iterable;", /* class_loader */ nullptr); ASSERT_NE(nullptr, iterable_klass); origin = iterable_klass->FindClassMethod( "forEach", "(Ljava/util/function/Consumer;)V", pointer_size); ASSERT_NE(nullptr, origin); ASSERT_FALSE(origin->IsDirect()); - ASSERT_TRUE(origin->GetDeclaringClass() == iterable_klass); + ASSERT_OBJ_PTR_EQ(origin->GetDeclaringClass(), iterable_klass); code = origin->GetEntryPointFromQuickCompiledCodePtrSize(pointer_size); // the origin method should have a pointer to quick code ASSERT_NE(nullptr, code); ASSERT_FALSE(class_linker_->IsQuickToInterpreterBridge(code)); - mirror::Class* iterablebase_klass = class_linker_->LookupClass( - self, "LIterableBase;", ObjPtr<mirror::ClassLoader>()); + ObjPtr<mirror::Class> iterablebase_klass = + class_linker_->LookupClass(self, "LIterableBase;", /* class_loader */ nullptr); ASSERT_NE(nullptr, iterablebase_klass); copied = FindCopiedMethod(origin, iterablebase_klass); ASSERT_NE(nullptr, copied); diff --git a/dex2oat/linker/image_test.h b/dex2oat/linker/image_test.h index 4b231ed35c..f0daf69850 100644 --- a/dex2oat/linker/image_test.h +++ b/dex2oat/linker/image_test.h @@ -97,7 +97,7 @@ class ImageTest : public CommonCompilerTest { return new std::unordered_set<std::string>(image_classes_); } - ArtMethod* FindCopiedMethod(ArtMethod* origin, mirror::Class* klass) + ArtMethod* FindCopiedMethod(ArtMethod* origin, ObjPtr<mirror::Class> klass) REQUIRES_SHARED(Locks::mutator_lock_) { PointerSize pointer_size = class_linker_->GetImagePointerSize(); for (ArtMethod& m : klass->GetCopiedMethods(pointer_size)) { diff --git a/libartbase/base/bit_table.h b/libartbase/base/bit_table.h index 8cfd044703..bf3d3b032c 100644 --- a/libartbase/base/bit_table.h +++ b/libartbase/base/bit_table.h @@ -194,7 +194,7 @@ class BitTableBuilder { if (count <= size() - index && std::equal(values, values + count, - &rows_[index], + rows_.begin() + index, [](const T& lhs, const T& rhs) { return memcmp(&lhs, &rhs, sizeof(T)) == 0; })) { diff --git a/oatdump/oatdump.cc b/oatdump/oatdump.cc index 1f197b81f5..7ac9e984ff 100644 --- a/oatdump/oatdump.cc +++ b/oatdump/oatdump.cc @@ -41,6 +41,7 @@ #include "base/unix_file/fd_file.h" #include "class_linker-inl.h" #include "class_linker.h" +#include "class_root.h" #include "compiled_method.h" #include "debug/debug_info.h" #include "debug/elf_debug_writer.h" @@ -737,6 +738,7 @@ class OatDumper { kByteKindCode, kByteKindQuickMethodHeader, kByteKindCodeInfoLocationCatalog, + kByteKindCodeInfoDexRegisterMask, kByteKindCodeInfoDexRegisterMap, kByteKindCodeInfo, kByteKindCodeInfoInvokeInfo, @@ -750,7 +752,7 @@ class OatDumper { kByteKindStackMapStackMaskIndex, kByteKindInlineInfoMethodIndexIdx, kByteKindInlineInfoDexPc, - kByteKindInlineInfoExtraData, + kByteKindInlineInfoArtMethod, kByteKindInlineInfoDexRegisterMap, kByteKindInlineInfoIsLast, kByteKindCount, @@ -787,6 +789,7 @@ class OatDumper { Dump(os, "QuickMethodHeader ", bits[kByteKindQuickMethodHeader], sum); Dump(os, "CodeInfo ", bits[kByteKindCodeInfo], sum); Dump(os, "CodeInfoLocationCatalog ", bits[kByteKindCodeInfoLocationCatalog], sum); + Dump(os, "CodeInfoDexRegisterMask ", bits[kByteKindCodeInfoDexRegisterMask], sum); Dump(os, "CodeInfoDexRegisterMap ", bits[kByteKindCodeInfoDexRegisterMap], sum); Dump(os, "CodeInfoStackMasks ", bits[kByteKindCodeInfoStackMasks], sum); Dump(os, "CodeInfoRegisterMasks ", bits[kByteKindCodeInfoRegisterMasks], sum); @@ -847,8 +850,8 @@ class OatDumper { inline_info_bits, "inline info"); Dump(os, - "InlineInfoExtraData ", - bits[kByteKindInlineInfoExtraData], + "InlineInfoArtMethod ", + bits[kByteKindInlineInfoArtMethod], inline_info_bits, "inline info"); Dump(os, @@ -1705,7 +1708,7 @@ class OatDumper { stack_maps.NumColumnBits(StackMap::kDexPc) * num_stack_maps); stats_.AddBits( Stats::kByteKindStackMapDexRegisterMap, - stack_maps.NumColumnBits(StackMap::kDexRegisterMapOffset) * num_stack_maps); + stack_maps.NumColumnBits(StackMap::kDexRegisterMapIndex) * num_stack_maps); stats_.AddBits( Stats::kByteKindStackMapInlineInfoIndex, stack_maps.NumColumnBits(StackMap::kInlineInfoIndex) * num_stack_maps); @@ -1732,16 +1735,12 @@ class OatDumper { code_info.invoke_infos_.DataBitSize()); // Location catalog - const size_t location_catalog_bytes = - helper.GetCodeInfo().GetDexRegisterLocationCatalogSize(); stats_.AddBits(Stats::kByteKindCodeInfoLocationCatalog, - kBitsPerByte * location_catalog_bytes); - // Dex register bytes. - const size_t dex_register_bytes = - helper.GetCodeInfo().GetDexRegisterMapsSize(code_item_accessor.RegistersSize()); - stats_.AddBits( - Stats::kByteKindCodeInfoDexRegisterMap, - kBitsPerByte * dex_register_bytes); + code_info.dex_register_catalog_.DataBitSize()); + stats_.AddBits(Stats::kByteKindCodeInfoDexRegisterMask, + code_info.dex_register_masks_.DataBitSize()); + stats_.AddBits(Stats::kByteKindCodeInfoDexRegisterMap, + code_info.dex_register_maps_.DataBitSize()); // Inline infos. const BitTable<InlineInfo::kCount>& inline_infos = code_info.inline_infos_; @@ -1754,11 +1753,12 @@ class OatDumper { Stats::kByteKindInlineInfoDexPc, inline_infos.NumColumnBits(InlineInfo::kDexPc) * num_inline_infos); stats_.AddBits( - Stats::kByteKindInlineInfoExtraData, - inline_infos.NumColumnBits(InlineInfo::kExtraData) * num_inline_infos); + Stats::kByteKindInlineInfoArtMethod, + inline_infos.NumColumnBits(InlineInfo::kArtMethodHi) * num_inline_infos + + inline_infos.NumColumnBits(InlineInfo::kArtMethodLo) * num_inline_infos); stats_.AddBits( Stats::kByteKindInlineInfoDexRegisterMap, - inline_infos.NumColumnBits(InlineInfo::kDexRegisterMapOffset) * num_inline_infos); + inline_infos.NumColumnBits(InlineInfo::kDexRegisterMapIndex) * num_inline_infos); stats_.AddBits(Stats::kByteKindInlineInfoIsLast, num_inline_infos); } } @@ -3253,7 +3253,7 @@ class IMTDumper { PrepareClass(runtime, klass, prepared); } - mirror::Class* object_class = mirror::Class::GetJavaLangClass()->GetSuperClass(); + ObjPtr<mirror::Class> object_class = GetClassRoot<mirror::Object>(); DCHECK(object_class->IsObjectClass()); bool result = klass->GetImt(pointer_size) == object_class->GetImt(pointer_size); @@ -3287,8 +3287,8 @@ class IMTDumper { Handle<mirror::ClassLoader> h_loader, const std::string& class_name, const PointerSize pointer_size, - mirror::Class** klass_out, - std::unordered_set<std::string>* prepared) + /*out*/ ObjPtr<mirror::Class>* klass_out, + /*inout*/ std::unordered_set<std::string>* prepared) REQUIRES_SHARED(Locks::mutator_lock_) { if (class_name.empty()) { return nullptr; @@ -3301,7 +3301,8 @@ class IMTDumper { descriptor = DotToDescriptor(class_name.c_str()); } - mirror::Class* klass = runtime->GetClassLinker()->FindClass(self, descriptor.c_str(), h_loader); + ObjPtr<mirror::Class> klass = + runtime->GetClassLinker()->FindClass(self, descriptor.c_str(), h_loader); if (klass == nullptr) { self->ClearException(); @@ -3321,7 +3322,7 @@ class IMTDumper { static ImTable* PrepareAndGetImTable(Runtime* runtime, Handle<mirror::Class> h_klass, const PointerSize pointer_size, - std::unordered_set<std::string>* prepared) + /*inout*/ std::unordered_set<std::string>* prepared) REQUIRES_SHARED(Locks::mutator_lock_) { PrepareClass(runtime, h_klass, prepared); return h_klass->GetImt(pointer_size); @@ -3333,7 +3334,7 @@ class IMTDumper { std::unordered_set<std::string>* prepared) REQUIRES_SHARED(Locks::mutator_lock_) { const PointerSize pointer_size = runtime->GetClassLinker()->GetImagePointerSize(); - mirror::Class* klass; + ObjPtr<mirror::Class> klass; ImTable* imt = PrepareAndGetImTable(runtime, Thread::Current(), h_loader, @@ -3389,10 +3390,10 @@ class IMTDumper { const std::string& class_name, const std::string& method, Handle<mirror::ClassLoader> h_loader, - std::unordered_set<std::string>* prepared) + /*inout*/ std::unordered_set<std::string>* prepared) REQUIRES_SHARED(Locks::mutator_lock_) { const PointerSize pointer_size = runtime->GetClassLinker()->GetImagePointerSize(); - mirror::Class* klass; + ObjPtr<mirror::Class> klass; ImTable* imt = PrepareAndGetImTable(runtime, Thread::Current(), h_loader, @@ -3495,7 +3496,7 @@ class IMTDumper { // and note in the given set that the work was done. static void PrepareClass(Runtime* runtime, Handle<mirror::Class> h_klass, - std::unordered_set<std::string>* done) + /*inout*/ std::unordered_set<std::string>* done) REQUIRES_SHARED(Locks::mutator_lock_) { if (!h_klass->ShouldHaveImt()) { return; diff --git a/profman/profile_assistant_test.cc b/profman/profile_assistant_test.cc index bd44e491b0..370f59dc8a 100644 --- a/profman/profile_assistant_test.cc +++ b/profman/profile_assistant_test.cc @@ -22,6 +22,7 @@ #include "base/utils.h" #include "common_runtime_test.h" #include "dex/descriptors_names.h" +#include "dex/type_reference.h" #include "exec_utils.h" #include "linear_alloc.h" #include "mirror/class-inl.h" @@ -33,6 +34,7 @@ namespace art { using Hotness = ProfileCompilationInfo::MethodHotness; +using TypeReferenceSet = std::set<TypeReference, TypeReferenceValueComparator>; static constexpr size_t kMaxMethodIds = 65535; @@ -308,25 +310,24 @@ class ProfileAssistantTest : public CommonRuntimeTest { return true; } - mirror::Class* GetClass(jobject class_loader, const std::string& clazz) { + ObjPtr<mirror::Class> GetClass(ScopedObjectAccess& soa, + jobject class_loader, + const std::string& clazz) REQUIRES_SHARED(Locks::mutator_lock_) { ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); - Thread* self = Thread::Current(); - ScopedObjectAccess soa(self); - StackHandleScope<1> hs(self); - Handle<mirror::ClassLoader> h_loader( - hs.NewHandle(ObjPtr<mirror::ClassLoader>::DownCast(self->DecodeJObject(class_loader)))); - return class_linker->FindClass(self, clazz.c_str(), h_loader); + StackHandleScope<1> hs(soa.Self()); + Handle<mirror::ClassLoader> h_loader(hs.NewHandle( + ObjPtr<mirror::ClassLoader>::DownCast(soa.Self()->DecodeJObject(class_loader)))); + return class_linker->FindClass(soa.Self(), clazz.c_str(), h_loader); } ArtMethod* GetVirtualMethod(jobject class_loader, const std::string& clazz, const std::string& name) { - mirror::Class* klass = GetClass(class_loader, clazz); + ScopedObjectAccess soa(Thread::Current()); + ObjPtr<mirror::Class> klass = GetClass(soa, class_loader, clazz); ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); const auto pointer_size = class_linker->GetImagePointerSize(); ArtMethod* method = nullptr; - Thread* self = Thread::Current(); - ScopedObjectAccess soa(self); for (auto& m : klass->GetVirtualMethods(pointer_size)) { if (name == m.GetName()) { EXPECT_TRUE(method == nullptr); @@ -336,9 +337,14 @@ class ProfileAssistantTest : public CommonRuntimeTest { return method; } + static TypeReference MakeTypeReference(ObjPtr<mirror::Class> klass) + REQUIRES_SHARED(Locks::mutator_lock_) { + return TypeReference(&klass->GetDexFile(), klass->GetDexTypeIndex()); + } + // Verify that given method has the expected inline caches and nothing else. void AssertInlineCaches(ArtMethod* method, - const std::set<mirror::Class*>& expected_clases, + const TypeReferenceSet& expected_clases, const ProfileCompilationInfo& info, bool is_megamorphic, bool is_missing_types) @@ -355,12 +361,11 @@ class ProfileAssistantTest : public CommonRuntimeTest { ASSERT_EQ(dex_pc_data.is_missing_types, is_missing_types); ASSERT_EQ(expected_clases.size(), dex_pc_data.classes.size()); size_t found = 0; - for (mirror::Class* it : expected_clases) { + for (const TypeReference& type_ref : expected_clases) { for (const auto& class_ref : dex_pc_data.classes) { ProfileCompilationInfo::DexReference dex_ref = pmi->dex_references[class_ref.dex_profile_index]; - if (dex_ref.MatchesDex(&(it->GetDexFile())) && - class_ref.type_index == it->GetDexTypeIndex()) { + if (dex_ref.MatchesDex(type_ref.dex_file) && class_ref.type_index == type_ref.TypeIndex()) { found++; } } @@ -715,7 +720,7 @@ TEST_F(ProfileAssistantTest, TestProfileCreationGenerateMethods) { ASSERT_TRUE(info.Load(GetFd(profile_file))); // Verify that the profile has matching methods. ScopedObjectAccess soa(Thread::Current()); - ObjPtr<mirror::Class> klass = GetClass(nullptr, "Ljava/lang/Math;"); + ObjPtr<mirror::Class> klass = GetClass(soa, /* class_loader */ nullptr, "Ljava/lang/Math;"); ASSERT_TRUE(klass != nullptr); size_t method_count = 0; for (ArtMethod& method : klass->GetMethods(kRuntimePointerSize)) { @@ -907,9 +912,10 @@ TEST_F(ProfileAssistantTest, TestProfileCreateInlineCache) { jobject class_loader = LoadDex("ProfileTestMultiDex"); ASSERT_NE(class_loader, nullptr); - mirror::Class* sub_a = GetClass(class_loader, "LSubA;"); - mirror::Class* sub_b = GetClass(class_loader, "LSubB;"); - mirror::Class* sub_c = GetClass(class_loader, "LSubC;"); + StackHandleScope<3> hs(soa.Self()); + Handle<mirror::Class> sub_a = hs.NewHandle(GetClass(soa, class_loader, "LSubA;")); + Handle<mirror::Class> sub_b = hs.NewHandle(GetClass(soa, class_loader, "LSubB;")); + Handle<mirror::Class> sub_c = hs.NewHandle(GetClass(soa, class_loader, "LSubC;")); ASSERT_TRUE(sub_a != nullptr); ASSERT_TRUE(sub_b != nullptr); @@ -921,8 +927,8 @@ TEST_F(ProfileAssistantTest, TestProfileCreateInlineCache) { "LTestInline;", "inlineMonomorphic"); ASSERT_TRUE(inline_monomorphic != nullptr); - std::set<mirror::Class*> expected_monomorphic; - expected_monomorphic.insert(sub_a); + TypeReferenceSet expected_monomorphic; + expected_monomorphic.insert(MakeTypeReference(sub_a.Get())); AssertInlineCaches(inline_monomorphic, expected_monomorphic, info, @@ -936,10 +942,10 @@ TEST_F(ProfileAssistantTest, TestProfileCreateInlineCache) { "LTestInline;", "inlinePolymorphic"); ASSERT_TRUE(inline_polymorhic != nullptr); - std::set<mirror::Class*> expected_polymorphic; - expected_polymorphic.insert(sub_a); - expected_polymorphic.insert(sub_b); - expected_polymorphic.insert(sub_c); + TypeReferenceSet expected_polymorphic; + expected_polymorphic.insert(MakeTypeReference(sub_a.Get())); + expected_polymorphic.insert(MakeTypeReference(sub_b.Get())); + expected_polymorphic.insert(MakeTypeReference(sub_c.Get())); AssertInlineCaches(inline_polymorhic, expected_polymorphic, info, @@ -953,7 +959,7 @@ TEST_F(ProfileAssistantTest, TestProfileCreateInlineCache) { "LTestInline;", "inlineMegamorphic"); ASSERT_TRUE(inline_megamorphic != nullptr); - std::set<mirror::Class*> expected_megamorphic; + TypeReferenceSet expected_megamorphic; AssertInlineCaches(inline_megamorphic, expected_megamorphic, info, @@ -967,7 +973,7 @@ TEST_F(ProfileAssistantTest, TestProfileCreateInlineCache) { "LTestInline;", "inlineMissingTypes"); ASSERT_TRUE(inline_missing_types != nullptr); - std::set<mirror::Class*> expected_missing_Types; + TypeReferenceSet expected_missing_Types; AssertInlineCaches(inline_missing_types, expected_missing_Types, info, diff --git a/runtime/art_field-inl.h b/runtime/art_field-inl.h index 384581fc4f..baa5102f5d 100644 --- a/runtime/art_field-inl.h +++ b/runtime/art_field-inl.h @@ -34,12 +34,16 @@ namespace art { +inline bool ArtField::IsProxyField() { + return GetDeclaringClass<kWithoutReadBarrier>()->IsProxyClass<kVerifyNone>(); +} + template<ReadBarrierOption kReadBarrierOption> inline ObjPtr<mirror::Class> ArtField::GetDeclaringClass() { GcRootSource gc_root_source(this); ObjPtr<mirror::Class> result = declaring_class_.Read<kReadBarrierOption>(&gc_root_source); DCHECK(result != nullptr); - DCHECK(result->IsLoaded() || result->IsErroneous()) << result->GetStatus(); + DCHECK(result->IsIdxLoaded() || result->IsErroneous()) << result->GetStatus(); return result; } @@ -302,25 +306,21 @@ inline bool ArtField::IsPrimitiveType() REQUIRES_SHARED(Locks::mutator_lock_) { inline ObjPtr<mirror::Class> ArtField::LookupResolvedType() { ScopedAssertNoThreadSuspension ants(__FUNCTION__); - const uint32_t field_index = GetDexFieldIndex(); - ObjPtr<mirror::Class> declaring_class = GetDeclaringClass(); - if (UNLIKELY(declaring_class->IsProxyClass())) { + if (UNLIKELY(IsProxyField())) { return ProxyFindSystemClass(GetTypeDescriptor()); } ObjPtr<mirror::Class> type = Runtime::Current()->GetClassLinker()->LookupResolvedType( - declaring_class->GetDexFile().GetFieldId(field_index).type_idx_, declaring_class); + GetDexFile()->GetFieldId(GetDexFieldIndex()).type_idx_, this); DCHECK(!Thread::Current()->IsExceptionPending()); return type; } inline ObjPtr<mirror::Class> ArtField::ResolveType() { - const uint32_t field_index = GetDexFieldIndex(); - ObjPtr<mirror::Class> declaring_class = GetDeclaringClass(); - if (UNLIKELY(declaring_class->IsProxyClass())) { + if (UNLIKELY(IsProxyField())) { return ProxyFindSystemClass(GetTypeDescriptor()); } ObjPtr<mirror::Class> type = Runtime::Current()->GetClassLinker()->ResolveType( - declaring_class->GetDexFile().GetFieldId(field_index).type_idx_, declaring_class); + GetDexFile()->GetFieldId(GetDexFieldIndex()).type_idx_, this); DCHECK_EQ(type == nullptr, Thread::Current()->IsExceptionPending()); return type; } @@ -329,12 +329,14 @@ inline size_t ArtField::FieldSize() REQUIRES_SHARED(Locks::mutator_lock_) { return Primitive::ComponentSize(GetTypeAsPrimitiveType()); } +template <ReadBarrierOption kReadBarrierOption> inline ObjPtr<mirror::DexCache> ArtField::GetDexCache() REQUIRES_SHARED(Locks::mutator_lock_) { - return GetDeclaringClass()->GetDexCache(); + ObjPtr<mirror::Class> klass = GetDeclaringClass<kReadBarrierOption>(); + return klass->GetDexCache<kDefaultVerifyFlags, kReadBarrierOption>(); } inline const DexFile* ArtField::GetDexFile() REQUIRES_SHARED(Locks::mutator_lock_) { - return GetDexCache()->GetDexFile(); + return GetDexCache<kWithoutReadBarrier>()->GetDexFile(); } inline ObjPtr<mirror::String> ArtField::GetStringName(Thread* self, bool resolve) { diff --git a/runtime/art_field.h b/runtime/art_field.h index f39af3900c..784a862425 100644 --- a/runtime/art_field.h +++ b/runtime/art_field.h @@ -215,6 +215,7 @@ class ArtField FINAL { size_t FieldSize() REQUIRES_SHARED(Locks::mutator_lock_); + template <ReadBarrierOption kReadBarrierOption = kWithReadBarrier> ObjPtr<mirror::DexCache> GetDexCache() REQUIRES_SHARED(Locks::mutator_lock_); const DexFile* GetDexFile() REQUIRES_SHARED(Locks::mutator_lock_); @@ -236,6 +237,8 @@ class ArtField FINAL { REQUIRES_SHARED(Locks::mutator_lock_); private: + bool IsProxyField() REQUIRES_SHARED(Locks::mutator_lock_); + ObjPtr<mirror::Class> ProxyFindSystemClass(const char* descriptor) REQUIRES_SHARED(Locks::mutator_lock_); ObjPtr<mirror::String> ResolveGetStringName(Thread* self, diff --git a/runtime/art_method-inl.h b/runtime/art_method-inl.h index c1fac364bb..ec66966869 100644 --- a/runtime/art_method-inl.h +++ b/runtime/art_method-inl.h @@ -324,7 +324,7 @@ inline mirror::ClassLoader* ArtMethod::GetClassLoader() { template <ReadBarrierOption kReadBarrierOption> inline mirror::DexCache* ArtMethod::GetDexCache() { if (LIKELY(!IsObsolete<kReadBarrierOption>())) { - mirror::Class* klass = GetDeclaringClass<kReadBarrierOption>(); + ObjPtr<mirror::Class> klass = GetDeclaringClass<kReadBarrierOption>(); return klass->GetDexCache<kDefaultVerifyFlags, kReadBarrierOption>(); } else { DCHECK(!IsProxyMethod()); diff --git a/runtime/class_linker-inl.h b/runtime/class_linker-inl.h index 7a99d3dc5e..888f713d8f 100644 --- a/runtime/class_linker-inl.h +++ b/runtime/class_linker-inl.h @@ -17,7 +17,10 @@ #ifndef ART_RUNTIME_CLASS_LINKER_INL_H_ #define ART_RUNTIME_CLASS_LINKER_INL_H_ -#include "art_field.h" +#include <atomic> + +#include "art_field-inl.h" +#include "art_method-inl.h" #include "class_linker.h" #include "gc/heap-inl.h" #include "gc_root-inl.h" @@ -29,12 +32,10 @@ #include "obj_ptr-inl.h" #include "scoped_thread_state_change-inl.h" -#include <atomic> - namespace art { -inline mirror::Class* ClassLinker::FindArrayClass(Thread* self, - ObjPtr<mirror::Class>* element_class) { +inline ObjPtr<mirror::Class> ClassLinker::FindArrayClass(Thread* self, + ObjPtr<mirror::Class>* element_class) { for (size_t i = 0; i < kFindArrayCacheSize; ++i) { // Read the cached array class once to avoid races with other threads setting it. ObjPtr<mirror::Class> array_class = find_array_class_cache_[i].Read(); @@ -68,38 +69,41 @@ inline ObjPtr<mirror::Class> ClassLinker::ResolveType(dex::TypeIndex type_idx, HandleWrapperObjPtr<mirror::Class> referrer_wrapper = hs.NewHandleWrapper(&referrer); Thread::Current()->PoisonObjectPointers(); } - if (kIsDebugBuild) { - Thread::Current()->AssertNoPendingException(); - } + DCHECK(!Thread::Current()->IsExceptionPending()); // We do not need the read barrier for getting the DexCache for the initial resolved type // lookup as both from-space and to-space copies point to the same native resolved types array. ObjPtr<mirror::Class> resolved_type = referrer->GetDexCache<kDefaultVerifyFlags, kWithoutReadBarrier>()->GetResolvedType(type_idx); if (resolved_type == nullptr) { - StackHandleScope<2> hs(Thread::Current()); - Handle<mirror::DexCache> h_dex_cache(hs.NewHandle(referrer->GetDexCache())); - Handle<mirror::ClassLoader> class_loader(hs.NewHandle(referrer->GetClassLoader())); - resolved_type = DoResolveType(type_idx, h_dex_cache, class_loader); + resolved_type = DoResolveType(type_idx, referrer); } return resolved_type; } inline ObjPtr<mirror::Class> ClassLinker::ResolveType(dex::TypeIndex type_idx, - ArtMethod* referrer) { + ArtField* referrer) { Thread::PoisonObjectPointersIfDebug(); - if (kIsDebugBuild) { - Thread::Current()->AssertNoPendingException(); + DCHECK(!Thread::Current()->IsExceptionPending()); + // We do not need the read barrier for getting the DexCache for the initial resolved type + // lookup as both from-space and to-space copies point to the same native resolved types array. + ObjPtr<mirror::Class> resolved_type = + referrer->GetDexCache<kWithoutReadBarrier>()->GetResolvedType(type_idx); + if (UNLIKELY(resolved_type == nullptr)) { + resolved_type = DoResolveType(type_idx, referrer->GetDeclaringClass()); } + return resolved_type; +} + +inline ObjPtr<mirror::Class> ClassLinker::ResolveType(dex::TypeIndex type_idx, + ArtMethod* referrer) { + Thread::PoisonObjectPointersIfDebug(); + DCHECK(!Thread::Current()->IsExceptionPending()); // We do not need the read barrier for getting the DexCache for the initial resolved type // lookup as both from-space and to-space copies point to the same native resolved types array. ObjPtr<mirror::Class> resolved_type = referrer->GetDexCache<kWithoutReadBarrier>()->GetResolvedType(type_idx); if (UNLIKELY(resolved_type == nullptr)) { - StackHandleScope<2> hs(Thread::Current()); - ObjPtr<mirror::Class> referring_class = referrer->GetDeclaringClass(); - Handle<mirror::DexCache> dex_cache(hs.NewHandle(referrer->GetDexCache())); - Handle<mirror::ClassLoader> class_loader(hs.NewHandle(referring_class->GetClassLoader())); - resolved_type = DoResolveType(type_idx, dex_cache, class_loader); + resolved_type = DoResolveType(type_idx, referrer->GetDeclaringClass()); } return resolved_type; } @@ -123,7 +127,19 @@ inline ObjPtr<mirror::Class> ClassLinker::LookupResolvedType(dex::TypeIndex type ObjPtr<mirror::Class> type = referrer->GetDexCache<kDefaultVerifyFlags, kWithoutReadBarrier>()->GetResolvedType(type_idx); if (type == nullptr) { - type = DoLookupResolvedType(type_idx, referrer->GetDexCache(), referrer->GetClassLoader()); + type = DoLookupResolvedType(type_idx, referrer); + } + return type; +} + +inline ObjPtr<mirror::Class> ClassLinker::LookupResolvedType(dex::TypeIndex type_idx, + ArtField* referrer) { + // We do not need the read barrier for getting the DexCache for the initial resolved type + // lookup as both from-space and to-space copies point to the same native resolved types array. + ObjPtr<mirror::Class> type = + referrer->GetDexCache<kWithoutReadBarrier>()->GetResolvedType(type_idx); + if (type == nullptr) { + type = DoLookupResolvedType(type_idx, referrer->GetDeclaringClass()); } return type; } @@ -135,7 +151,7 @@ inline ObjPtr<mirror::Class> ClassLinker::LookupResolvedType(dex::TypeIndex type ObjPtr<mirror::Class> type = referrer->GetDexCache<kWithoutReadBarrier>()->GetResolvedType(type_idx); if (type == nullptr) { - type = DoLookupResolvedType(type_idx, referrer->GetDexCache(), referrer->GetClassLoader()); + type = DoLookupResolvedType(type_idx, referrer->GetDeclaringClass()); } return type; } diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc index 095272394a..dccdff0a5d 100644 --- a/runtime/class_linker.cc +++ b/runtime/class_linker.cc @@ -435,7 +435,7 @@ bool ClassLinker::InitWithoutImage(std::vector<std::unique_ptr<const DexFile>> b Handle<mirror::Class> java_lang_Class(hs.NewHandle(down_cast<mirror::Class*>( heap->AllocNonMovableObject<true>(self, nullptr, class_class_size, VoidFunctor())))); CHECK(java_lang_Class != nullptr); - mirror::Class::SetClassClass(java_lang_Class.Get()); + java_lang_Class->SetClassFlags(mirror::kClassFlagClass); java_lang_Class->SetClass(java_lang_Class.Get()); if (kUseBakerReadBarrier) { java_lang_Class->AssertReadBarrierState(); @@ -553,7 +553,6 @@ bool ClassLinker::InitWithoutImage(std::vector<std::unique_ptr<const DexFile>> b Handle<mirror::Class> dalvik_system_ClassExt(hs.NewHandle( AllocClass(self, java_lang_Class.Get(), mirror::ClassExt::ClassSize(image_pointer_size_)))); SetClassRoot(ClassRoot::kDalvikSystemClassExt, dalvik_system_ClassExt.Get()); - mirror::ClassExt::SetClass(dalvik_system_ClassExt.Get()); mirror::Class::SetStatus(dalvik_system_ClassExt, ClassStatus::kResolved, self); // Set up array classes for string, field, method @@ -991,7 +990,8 @@ bool ClassLinker::InitFromBootImage(std::string* error_msg) { class_roots_ = GcRoot<mirror::ObjectArray<mirror::Class>>( down_cast<mirror::ObjectArray<mirror::Class>*>( spaces[0]->GetImageHeader().GetImageRoot(ImageHeader::kClassRoots))); - mirror::Class::SetClassClass(GetClassRoot(ClassRoot::kJavaLangClass, this)); + DCHECK_EQ(GetClassRoot(ClassRoot::kJavaLangClass, this)->GetClassFlags(), + mirror::kClassFlagClass); ObjPtr<mirror::Class> java_lang_Object = GetClassRoot<mirror::Object>(this); java_lang_Object->SetObjectSize(sizeof(mirror::Object)); @@ -1004,8 +1004,6 @@ bool ClassLinker::InitFromBootImage(std::string* error_msg) { array_iftable_ = GcRoot<mirror::IfTable>(GetClassRoot(ClassRoot::kObjectArrayClass, this)->GetIfTable()); DCHECK_EQ(array_iftable_.Read(), GetClassRoot(ClassRoot::kBooleanArrayClass, this)->GetIfTable()); - // String class root was set above - mirror::ClassExt::SetClass(GetClassRoot(ClassRoot::kDalvikSystemClassExt, this)); for (gc::space::ImageSpace* image_space : spaces) { // Boot class loader, use a null handle. @@ -2059,8 +2057,7 @@ void ClassLinker::VisitClassesWithoutClassesLock(ClassVisitor* visitor) { // Add 100 in case new classes get loaded when we are filling in the object array. class_table_size = NumZygoteClasses() + NumNonZygoteClasses() + 100; } - ObjPtr<mirror::Class> class_type = mirror::Class::GetJavaLangClass(); - ObjPtr<mirror::Class> array_of_class = FindArrayClass(self, &class_type); + ObjPtr<mirror::Class> array_of_class = GetClassRoot<mirror::ObjectArray<mirror::Class>>(this); classes.Assign( mirror::ObjectArray<mirror::Class>::Alloc(self, array_of_class, class_table_size)); CHECK(classes != nullptr); // OOME. @@ -2083,7 +2080,6 @@ void ClassLinker::VisitClassesWithoutClassesLock(ClassVisitor* visitor) { } ClassLinker::~ClassLinker() { - mirror::Class::ResetClass(); Thread* const self = Thread::Current(); for (const ClassLoaderData& data : class_loaders_) { // CHA unloading analysis is not needed. No negative consequences are expected because @@ -2163,9 +2159,9 @@ mirror::DexCache* ClassLinker::AllocAndInitializeDexCache(Thread* self, return dex_cache.Ptr(); } -mirror::Class* ClassLinker::AllocClass(Thread* self, - ObjPtr<mirror::Class> java_lang_Class, - uint32_t class_size) { +ObjPtr<mirror::Class> ClassLinker::AllocClass(Thread* self, + ObjPtr<mirror::Class> java_lang_Class, + uint32_t class_size) { DCHECK_GE(class_size, sizeof(mirror::Class)); gc::Heap* heap = Runtime::Current()->GetHeap(); mirror::Class::InitializeClassVisitor visitor(class_size); @@ -2179,7 +2175,7 @@ mirror::Class* ClassLinker::AllocClass(Thread* self, return k->AsClass(); } -mirror::Class* ClassLinker::AllocClass(Thread* self, uint32_t class_size) { +ObjPtr<mirror::Class> ClassLinker::AllocClass(Thread* self, uint32_t class_size) { return AllocClass(self, GetClassRoot<mirror::Class>(this), class_size); } @@ -2190,9 +2186,9 @@ mirror::ObjectArray<mirror::StackTraceElement>* ClassLinker::AllocStackTraceElem self, GetClassRoot<mirror::ObjectArray<mirror::StackTraceElement>>(this), length); } -mirror::Class* ClassLinker::EnsureResolved(Thread* self, - const char* descriptor, - ObjPtr<mirror::Class> klass) { +ObjPtr<mirror::Class> ClassLinker::EnsureResolved(Thread* self, + const char* descriptor, + ObjPtr<mirror::Class> klass) { DCHECK(klass != nullptr); if (kIsDebugBuild) { StackHandleScope<1> hs(self); @@ -2400,9 +2396,9 @@ ObjPtr<mirror::Class> ClassLinker::FindClassInBaseDexClassLoaderClassPath( return ret; } -mirror::Class* ClassLinker::FindClass(Thread* self, - const char* descriptor, - Handle<mirror::ClassLoader> class_loader) { +ObjPtr<mirror::Class> ClassLinker::FindClass(Thread* self, + const char* descriptor, + Handle<mirror::ClassLoader> class_loader) { DCHECK_NE(*descriptor, '\0') << "descriptor is empty string"; DCHECK(self != nullptr); self->AssertNoPendingException(); @@ -2571,12 +2567,12 @@ mirror::Class* ClassLinker::FindClass(Thread* self, return result_ptr.Ptr(); } -mirror::Class* ClassLinker::DefineClass(Thread* self, - const char* descriptor, - size_t hash, - Handle<mirror::ClassLoader> class_loader, - const DexFile& dex_file, - const DexFile::ClassDef& dex_class_def) { +ObjPtr<mirror::Class> ClassLinker::DefineClass(Thread* self, + const char* descriptor, + size_t hash, + Handle<mirror::ClassLoader> class_loader, + const DexFile& dex_file, + const DexFile::ClassDef& dex_class_def) { StackHandleScope<3> hs(self); auto klass = hs.NewHandle<mirror::Class>(nullptr); @@ -3534,7 +3530,7 @@ ClassLinker::DexCacheData ClassLinker::FindDexCacheDataLocked(const DexFile& dex return DexCacheData(); } -mirror::Class* ClassLinker::CreatePrimitiveClass(Thread* self, Primitive::Type type) { +ObjPtr<mirror::Class> ClassLinker::CreatePrimitiveClass(Thread* self, Primitive::Type type) { ObjPtr<mirror::Class> primitive_class = AllocClass(self, mirror::Class::PrimitiveClassSize(image_pointer_size_)); if (UNLIKELY(primitive_class == nullptr)) { @@ -3570,8 +3566,10 @@ mirror::Class* ClassLinker::CreatePrimitiveClass(Thread* self, Primitive::Type t // array class; that always comes from the base element class. // // Returns null with an exception raised on failure. -mirror::Class* ClassLinker::CreateArrayClass(Thread* self, const char* descriptor, size_t hash, - Handle<mirror::ClassLoader> class_loader) { +ObjPtr<mirror::Class> ClassLinker::CreateArrayClass(Thread* self, + const char* descriptor, + size_t hash, + Handle<mirror::ClassLoader> class_loader) { // Identify the underlying component type CHECK_EQ('[', descriptor[0]); StackHandleScope<2> hs(self); @@ -3718,27 +3716,27 @@ mirror::Class* ClassLinker::CreateArrayClass(Thread* self, const char* descripto return existing.Ptr(); } -mirror::Class* ClassLinker::FindPrimitiveClass(char type) { +ObjPtr<mirror::Class> ClassLinker::FindPrimitiveClass(char type) { ObjPtr<mirror::ObjectArray<mirror::Class>> class_roots = GetClassRoots(); switch (type) { case 'B': - return GetClassRoot(ClassRoot::kPrimitiveByte, class_roots).Ptr(); + return GetClassRoot(ClassRoot::kPrimitiveByte, class_roots); case 'C': - return GetClassRoot(ClassRoot::kPrimitiveChar, class_roots).Ptr(); + return GetClassRoot(ClassRoot::kPrimitiveChar, class_roots); case 'D': - return GetClassRoot(ClassRoot::kPrimitiveDouble, class_roots).Ptr(); + return GetClassRoot(ClassRoot::kPrimitiveDouble, class_roots); case 'F': - return GetClassRoot(ClassRoot::kPrimitiveFloat, class_roots).Ptr(); + return GetClassRoot(ClassRoot::kPrimitiveFloat, class_roots); case 'I': - return GetClassRoot(ClassRoot::kPrimitiveInt, class_roots).Ptr(); + return GetClassRoot(ClassRoot::kPrimitiveInt, class_roots); case 'J': - return GetClassRoot(ClassRoot::kPrimitiveLong, class_roots).Ptr(); + return GetClassRoot(ClassRoot::kPrimitiveLong, class_roots); case 'S': - return GetClassRoot(ClassRoot::kPrimitiveShort, class_roots).Ptr(); + return GetClassRoot(ClassRoot::kPrimitiveShort, class_roots); case 'Z': - return GetClassRoot(ClassRoot::kPrimitiveBoolean, class_roots).Ptr(); + return GetClassRoot(ClassRoot::kPrimitiveBoolean, class_roots); case 'V': - return GetClassRoot(ClassRoot::kPrimitiveVoid, class_roots).Ptr(); + return GetClassRoot(ClassRoot::kPrimitiveVoid, class_roots); default: break; } @@ -3747,7 +3745,9 @@ mirror::Class* ClassLinker::FindPrimitiveClass(char type) { return nullptr; } -mirror::Class* ClassLinker::InsertClass(const char* descriptor, ObjPtr<mirror::Class> klass, size_t hash) { +ObjPtr<mirror::Class> ClassLinker::InsertClass(const char* descriptor, + ObjPtr<mirror::Class> klass, + size_t hash) { if (VLOG_IS_ON(class_linker)) { ObjPtr<mirror::DexCache> dex_cache = klass->GetDexCache(); std::string source; @@ -3802,16 +3802,16 @@ void ClassLinker::UpdateClassMethods(ObjPtr<mirror::Class> klass, Runtime::Current()->GetHeap()->WriteBarrierEveryFieldOf(klass); } -mirror::Class* ClassLinker::LookupClass(Thread* self, - const char* descriptor, - ObjPtr<mirror::ClassLoader> class_loader) { +ObjPtr<mirror::Class> ClassLinker::LookupClass(Thread* self, + const char* descriptor, + ObjPtr<mirror::ClassLoader> class_loader) { return LookupClass(self, descriptor, ComputeModifiedUtf8Hash(descriptor), class_loader); } -mirror::Class* ClassLinker::LookupClass(Thread* self, - const char* descriptor, - size_t hash, - ObjPtr<mirror::ClassLoader> class_loader) { +ObjPtr<mirror::Class> ClassLinker::LookupClass(Thread* self, + const char* descriptor, + size_t hash, + ObjPtr<mirror::ClassLoader> class_loader) { ReaderMutexLock mu(self, *Locks::classlinker_classes_lock_); ClassTable* const class_table = ClassTableForClassLoader(class_loader); if (class_table != nullptr) { @@ -4264,12 +4264,12 @@ void ClassLinker::ResolveMethodExceptionHandlerTypes(ArtMethod* method) { } } -mirror::Class* ClassLinker::CreateProxyClass(ScopedObjectAccessAlreadyRunnable& soa, - jstring name, - jobjectArray interfaces, - jobject loader, - jobjectArray methods, - jobjectArray throws) { +ObjPtr<mirror::Class> ClassLinker::CreateProxyClass(ScopedObjectAccessAlreadyRunnable& soa, + jstring name, + jobjectArray interfaces, + jobject loader, + jobjectArray methods, + jobjectArray throws) { Thread* self = soa.Self(); StackHandleScope<10> hs(self); MutableHandle<mirror::Class> temp_klass(hs.NewHandle( @@ -7701,6 +7701,11 @@ ObjPtr<mirror::String> ClassLinker::LookupString(dex::StringIndex string_idx, } ObjPtr<mirror::Class> ClassLinker::DoLookupResolvedType(dex::TypeIndex type_idx, + ObjPtr<mirror::Class> referrer) { + return DoLookupResolvedType(type_idx, referrer->GetDexCache(), referrer->GetClassLoader()); +} + +ObjPtr<mirror::Class> ClassLinker::DoLookupResolvedType(dex::TypeIndex type_idx, ObjPtr<mirror::DexCache> dex_cache, ObjPtr<mirror::ClassLoader> class_loader) { const DexFile& dex_file = *dex_cache->GetDexFile(); @@ -7729,6 +7734,14 @@ ObjPtr<mirror::Class> ClassLinker::DoLookupResolvedType(dex::TypeIndex type_idx, } ObjPtr<mirror::Class> ClassLinker::DoResolveType(dex::TypeIndex type_idx, + ObjPtr<mirror::Class> referrer) { + StackHandleScope<2> hs(Thread::Current()); + Handle<mirror::DexCache> dex_cache(hs.NewHandle(referrer->GetDexCache())); + Handle<mirror::ClassLoader> class_loader(hs.NewHandle(referrer->GetClassLoader())); + return DoResolveType(type_idx, dex_cache, class_loader); +} + +ObjPtr<mirror::Class> ClassLinker::DoResolveType(dex::TypeIndex type_idx, Handle<mirror::DexCache> dex_cache, Handle<mirror::ClassLoader> class_loader) { Thread* self = Thread::Current(); @@ -8112,8 +8125,7 @@ ObjPtr<mirror::MethodType> ClassLinker::ResolveMethodType( // other than by looking at the shorty ? const size_t num_method_args = strlen(dex_file.StringDataByIdx(proto_id.shorty_idx_)) - 1; - ObjPtr<mirror::Class> class_type = mirror::Class::GetJavaLangClass(); - ObjPtr<mirror::Class> array_of_class = FindArrayClass(self, &class_type); + ObjPtr<mirror::Class> array_of_class = GetClassRoot<mirror::ObjectArray<mirror::Class>>(this); Handle<mirror::ObjectArray<mirror::Class>> method_params(hs.NewHandle( mirror::ObjectArray<mirror::Class>::Alloc(self, array_of_class, num_method_args))); if (method_params == nullptr) { @@ -8219,11 +8231,10 @@ mirror::MethodHandle* ClassLinker::ResolveMethodHandleForField( } StackHandleScope<4> hs(self); - ObjPtr<mirror::Class> class_type = mirror::Class::GetJavaLangClass(); - ObjPtr<mirror::Class> array_of_class = FindArrayClass(self, &class_type); + ObjPtr<mirror::Class> array_of_class = GetClassRoot<mirror::ObjectArray<mirror::Class>>(this); Handle<mirror::ObjectArray<mirror::Class>> method_params(hs.NewHandle( mirror::ObjectArray<mirror::Class>::Alloc(self, array_of_class, num_params))); - if (UNLIKELY(method_params.Get() == nullptr)) { + if (UNLIKELY(method_params == nullptr)) { DCHECK(self->IsExceptionPending()); return nullptr; } @@ -8398,8 +8409,7 @@ mirror::MethodHandle* ClassLinker::ResolveMethodHandleForMethod( int32_t num_params = static_cast<int32_t>(shorty_length + receiver_count - 1); StackHandleScope<7> hs(self); - ObjPtr<mirror::Class> class_type = mirror::Class::GetJavaLangClass(); - ObjPtr<mirror::Class> array_of_class = FindArrayClass(self, &class_type); + ObjPtr<mirror::Class> array_of_class = GetClassRoot<mirror::ObjectArray<mirror::Class>>(this); Handle<mirror::ObjectArray<mirror::Class>> method_params(hs.NewHandle( mirror::ObjectArray<mirror::Class>::Alloc(self, array_of_class, num_params))); if (method_params.Get() == nullptr) { @@ -8897,19 +8907,19 @@ class ClassLinker::FindVirtualMethodHolderVisitor : public ClassVisitor { const PointerSize pointer_size_; }; -mirror::Class* ClassLinker::GetHoldingClassOfCopiedMethod(ArtMethod* method) { +ObjPtr<mirror::Class> ClassLinker::GetHoldingClassOfCopiedMethod(ArtMethod* method) { ScopedTrace trace(__FUNCTION__); // Since this function is slow, have a trace to notify people. CHECK(method->IsCopied()); FindVirtualMethodHolderVisitor visitor(method, image_pointer_size_); VisitClasses(&visitor); - return visitor.holder_.Ptr(); + return visitor.holder_; } -mirror::IfTable* ClassLinker::AllocIfTable(Thread* self, size_t ifcount) { - return down_cast<mirror::IfTable*>( +ObjPtr<mirror::IfTable> ClassLinker::AllocIfTable(Thread* self, size_t ifcount) { + return ObjPtr<mirror::IfTable>::DownCast(ObjPtr<mirror::ObjectArray<mirror::Object>>( mirror::IfTable::Alloc(self, GetClassRoot<mirror::ObjectArray<mirror::Object>>(this), - ifcount * mirror::IfTable::kMax)); + ifcount * mirror::IfTable::kMax))); } // Instantiate ResolveMethod. diff --git a/runtime/class_linker.h b/runtime/class_linker.h index 1f94c43408..32016fa12a 100644 --- a/runtime/class_linker.h +++ b/runtime/class_linker.h @@ -67,6 +67,8 @@ using MethodDexCachePair = NativeDexCachePair<ArtMethod>; using MethodDexCacheType = std::atomic<MethodDexCachePair>; } // namespace mirror +class ArtField; +class ArtMethod; class ClassHierarchyAnalysis; enum class ClassRoot : uint32_t; class ClassTable; @@ -146,22 +148,22 @@ class ClassLinker { // Finds a class by its descriptor, loading it if necessary. // If class_loader is null, searches boot_class_path_. - mirror::Class* FindClass(Thread* self, - const char* descriptor, - Handle<mirror::ClassLoader> class_loader) + ObjPtr<mirror::Class> FindClass(Thread* self, + const char* descriptor, + Handle<mirror::ClassLoader> class_loader) REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::dex_lock_); // Finds a class by its descriptor using the "system" class loader, ie by searching the // boot_class_path_. - mirror::Class* FindSystemClass(Thread* self, const char* descriptor) + ObjPtr<mirror::Class> FindSystemClass(Thread* self, const char* descriptor) REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::dex_lock_) { return FindClass(self, descriptor, ScopedNullHandle<mirror::ClassLoader>()); } // Finds the array class given for the element class. - mirror::Class* FindArrayClass(Thread* self, ObjPtr<mirror::Class>* element_class) + ObjPtr<mirror::Class> FindArrayClass(Thread* self, ObjPtr<mirror::Class>* element_class) REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::dex_lock_); @@ -171,20 +173,20 @@ class ClassLinker { } // Define a new a class based on a ClassDef from a DexFile - mirror::Class* DefineClass(Thread* self, - const char* descriptor, - size_t hash, - Handle<mirror::ClassLoader> class_loader, - const DexFile& dex_file, - const DexFile::ClassDef& dex_class_def) + ObjPtr<mirror::Class> DefineClass(Thread* self, + const char* descriptor, + size_t hash, + Handle<mirror::ClassLoader> class_loader, + const DexFile& dex_file, + const DexFile::ClassDef& dex_class_def) REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::dex_lock_); // Finds a class by its descriptor, returning null if it isn't wasn't loaded // by the given 'class_loader'. - mirror::Class* LookupClass(Thread* self, - const char* descriptor, - ObjPtr<mirror::ClassLoader> class_loader) + ObjPtr<mirror::Class> LookupClass(Thread* self, + const char* descriptor, + ObjPtr<mirror::ClassLoader> class_loader) REQUIRES(!Locks::classlinker_classes_lock_) REQUIRES_SHARED(Locks::mutator_lock_); @@ -193,7 +195,7 @@ class ClassLinker { REQUIRES(!Locks::classlinker_classes_lock_) REQUIRES_SHARED(Locks::mutator_lock_); - mirror::Class* FindPrimitiveClass(char type) REQUIRES_SHARED(Locks::mutator_lock_); + ObjPtr<mirror::Class> FindPrimitiveClass(char type) REQUIRES_SHARED(Locks::mutator_lock_); void DumpForSigQuit(std::ostream& os) REQUIRES(!Locks::classlinker_classes_lock_); @@ -219,10 +221,9 @@ class ClassLinker { ObjPtr<mirror::Class> ResolveType(dex::TypeIndex type_idx, ObjPtr<mirror::Class> referrer) REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); - - // Resolve a type with the given index from the DexFile associated with the given `referrer`, - // storing the result in the DexCache. The `referrer` is used to identify the target DexCache - // and ClassLoader to use for resolution. + ObjPtr<mirror::Class> ResolveType(dex::TypeIndex type_idx, ArtField* referrer) + REQUIRES_SHARED(Locks::mutator_lock_) + REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); ObjPtr<mirror::Class> ResolveType(dex::TypeIndex type_idx, ArtMethod* referrer) REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); @@ -242,10 +243,8 @@ class ClassLinker { ObjPtr<mirror::Class> LookupResolvedType(dex::TypeIndex type_idx, ObjPtr<mirror::Class> referrer) REQUIRES_SHARED(Locks::mutator_lock_); - - // Look up a resolved type with the given index from the DexFile associated with the given - // `referrer`, storing the result in the DexCache. The `referrer` is used to identify the - // target DexCache and ClassLoader to use for lookup. + ObjPtr<mirror::Class> LookupResolvedType(dex::TypeIndex type_idx, ArtField* referrer) + REQUIRES_SHARED(Locks::mutator_lock_); ObjPtr<mirror::Class> LookupResolvedType(dex::TypeIndex type_idx, ArtMethod* referrer) REQUIRES_SHARED(Locks::mutator_lock_); @@ -456,7 +455,7 @@ class ClassLinker { REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_); - mirror::IfTable* AllocIfTable(Thread* self, size_t ifcount) + ObjPtr<mirror::IfTable> AllocIfTable(Thread* self, size_t ifcount) REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_); @@ -483,12 +482,12 @@ class ClassLinker { REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::dex_lock_); - mirror::Class* CreateProxyClass(ScopedObjectAccessAlreadyRunnable& soa, - jstring name, - jobjectArray interfaces, - jobject loader, - jobjectArray methods, - jobjectArray throws) + ObjPtr<mirror::Class> CreateProxyClass(ScopedObjectAccessAlreadyRunnable& soa, + jstring name, + jobjectArray interfaces, + jobject loader, + jobjectArray methods, + jobjectArray throws) REQUIRES_SHARED(Locks::mutator_lock_); std::string GetDescriptorForProxy(ObjPtr<mirror::Class> proxy_class) REQUIRES_SHARED(Locks::mutator_lock_); @@ -531,7 +530,9 @@ class ClassLinker { // Attempts to insert a class into a class table. Returns null if // the class was inserted, otherwise returns an existing class with // the same descriptor and ClassLoader. - mirror::Class* InsertClass(const char* descriptor, ObjPtr<mirror::Class> klass, size_t hash) + ObjPtr<mirror::Class> InsertClass(const char* descriptor, + ObjPtr<mirror::Class> klass, + size_t hash) REQUIRES(!Locks::classlinker_classes_lock_) REQUIRES_SHARED(Locks::mutator_lock_); @@ -659,7 +660,7 @@ class ClassLinker { REQUIRES(!Locks::dex_lock_); // Get the actual holding class for a copied method. Pretty slow, don't call often. - mirror::Class* GetHoldingClassOfCopiedMethod(ArtMethod* method) + ObjPtr<mirror::Class> GetHoldingClassOfCopiedMethod(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_); // Returns null if not found. @@ -763,16 +764,16 @@ class ClassLinker { REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); // For early bootstrapping by Init - mirror::Class* AllocClass(Thread* self, - ObjPtr<mirror::Class> java_lang_Class, - uint32_t class_size) + ObjPtr<mirror::Class> AllocClass(Thread* self, + ObjPtr<mirror::Class> java_lang_Class, + uint32_t class_size) REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_); - // Alloc* convenience functions to avoid needing to pass in mirror::Class* - // values that are known to the ClassLinker such as - // kObjectArrayClass and kJavaLangString etc. - mirror::Class* AllocClass(Thread* self, uint32_t class_size) + // Alloc* convenience functions to avoid needing to pass in ObjPtr<mirror::Class> + // values that are known to the ClassLinker such as classes corresponding to + // ClassRoot::kObjectArrayClass and ClassRoot::kJavaLangString etc. + ObjPtr<mirror::Class> AllocClass(Thread* self, uint32_t class_size) REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_); @@ -790,14 +791,14 @@ class ClassLinker { REQUIRES(!Locks::dex_lock_) REQUIRES(!Roles::uninterruptible_); - mirror::Class* CreatePrimitiveClass(Thread* self, Primitive::Type type) + ObjPtr<mirror::Class> CreatePrimitiveClass(Thread* self, Primitive::Type type) REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_); - mirror::Class* CreateArrayClass(Thread* self, - const char* descriptor, - size_t hash, - Handle<mirror::ClassLoader> class_loader) + ObjPtr<mirror::Class> CreateArrayClass(Thread* self, + const char* descriptor, + size_t hash, + Handle<mirror::ClassLoader> class_loader) REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); @@ -876,12 +877,19 @@ class ClassLinker { // Implementation of LookupResolvedType() called when the type was not found in the dex cache. ObjPtr<mirror::Class> DoLookupResolvedType(dex::TypeIndex type_idx, + ObjPtr<mirror::Class> referrer) + REQUIRES_SHARED(Locks::mutator_lock_); + ObjPtr<mirror::Class> DoLookupResolvedType(dex::TypeIndex type_idx, ObjPtr<mirror::DexCache> dex_cache, ObjPtr<mirror::ClassLoader> class_loader) REQUIRES_SHARED(Locks::mutator_lock_); // Implementation of ResolveType() called when the type was not found in the dex cache. ObjPtr<mirror::Class> DoResolveType(dex::TypeIndex type_idx, + ObjPtr<mirror::Class> referrer) + REQUIRES_SHARED(Locks::mutator_lock_) + REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); + ObjPtr<mirror::Class> DoResolveType(dex::TypeIndex type_idx, Handle<mirror::DexCache> dex_cache, Handle<mirror::ClassLoader> class_loader) REQUIRES_SHARED(Locks::mutator_lock_) @@ -889,10 +897,10 @@ class ClassLinker { // Finds a class by its descriptor, returning NULL if it isn't wasn't loaded // by the given 'class_loader'. Uses the provided hash for the descriptor. - mirror::Class* LookupClass(Thread* self, - const char* descriptor, - size_t hash, - ObjPtr<mirror::ClassLoader> class_loader) + ObjPtr<mirror::Class> LookupClass(Thread* self, + const char* descriptor, + size_t hash, + ObjPtr<mirror::ClassLoader> class_loader) REQUIRES(!Locks::classlinker_classes_lock_) REQUIRES_SHARED(Locks::mutator_lock_); @@ -1163,7 +1171,9 @@ class ClassLinker { // when resolution has occurred. This happens in mirror::Class::SetStatus. As resolution may // retire a class, the version of the class in the table is returned and this may differ from // the class passed in. - mirror::Class* EnsureResolved(Thread* self, const char* descriptor, ObjPtr<mirror::Class> klass) + ObjPtr<mirror::Class> EnsureResolved(Thread* self, + const char* descriptor, + ObjPtr<mirror::Class> klass) WARN_UNUSED REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::dex_lock_); diff --git a/runtime/class_linker_test.cc b/runtime/class_linker_test.cc index 48ec6b6c27..5d420aae04 100644 --- a/runtime/class_linker_test.cc +++ b/runtime/class_linker_test.cc @@ -198,7 +198,8 @@ class ClassLinkerTest : public CommonRuntimeTest { ASSERT_STREQ(array_descriptor.c_str(), array->GetDescriptor(&temp)); EXPECT_TRUE(array->GetSuperClass() != nullptr); Thread* self = Thread::Current(); - EXPECT_EQ(class_linker_->FindSystemClass(self, "Ljava/lang/Object;"), array->GetSuperClass()); + EXPECT_OBJ_PTR_EQ(class_linker_->FindSystemClass(self, "Ljava/lang/Object;"), + array->GetSuperClass()); EXPECT_TRUE(array->HasSuperClass()); ASSERT_TRUE(array->GetComponentType() != nullptr); ASSERT_GT(strlen(array->GetComponentType()->GetDescriptor(&temp)), 0U); @@ -1079,27 +1080,27 @@ TEST_F(ClassLinkerTest, ValidatePrimitiveArrayElementsOffset) { ScopedObjectAccess soa(Thread::Current()); StackHandleScope<5> hs(soa.Self()); Handle<mirror::LongArray> long_array(hs.NewHandle(mirror::LongArray::Alloc(soa.Self(), 0))); - EXPECT_EQ(class_linker_->FindSystemClass(soa.Self(), "[J"), long_array->GetClass()); + EXPECT_OBJ_PTR_EQ(class_linker_->FindSystemClass(soa.Self(), "[J"), long_array->GetClass()); uintptr_t data_offset = reinterpret_cast<uintptr_t>(long_array->GetData()); EXPECT_TRUE(IsAligned<8>(data_offset)); // Longs require 8 byte alignment Handle<mirror::DoubleArray> double_array(hs.NewHandle(mirror::DoubleArray::Alloc(soa.Self(), 0))); - EXPECT_EQ(class_linker_->FindSystemClass(soa.Self(), "[D"), double_array->GetClass()); + EXPECT_OBJ_PTR_EQ(class_linker_->FindSystemClass(soa.Self(), "[D"), double_array->GetClass()); data_offset = reinterpret_cast<uintptr_t>(double_array->GetData()); EXPECT_TRUE(IsAligned<8>(data_offset)); // Doubles require 8 byte alignment Handle<mirror::IntArray> int_array(hs.NewHandle(mirror::IntArray::Alloc(soa.Self(), 0))); - EXPECT_EQ(class_linker_->FindSystemClass(soa.Self(), "[I"), int_array->GetClass()); + EXPECT_OBJ_PTR_EQ(class_linker_->FindSystemClass(soa.Self(), "[I"), int_array->GetClass()); data_offset = reinterpret_cast<uintptr_t>(int_array->GetData()); EXPECT_TRUE(IsAligned<4>(data_offset)); // Ints require 4 byte alignment Handle<mirror::CharArray> char_array(hs.NewHandle(mirror::CharArray::Alloc(soa.Self(), 0))); - EXPECT_EQ(class_linker_->FindSystemClass(soa.Self(), "[C"), char_array->GetClass()); + EXPECT_OBJ_PTR_EQ(class_linker_->FindSystemClass(soa.Self(), "[C"), char_array->GetClass()); data_offset = reinterpret_cast<uintptr_t>(char_array->GetData()); EXPECT_TRUE(IsAligned<2>(data_offset)); // Chars require 2 byte alignment Handle<mirror::ShortArray> short_array(hs.NewHandle(mirror::ShortArray::Alloc(soa.Self(), 0))); - EXPECT_EQ(class_linker_->FindSystemClass(soa.Self(), "[S"), short_array->GetClass()); + EXPECT_OBJ_PTR_EQ(class_linker_->FindSystemClass(soa.Self(), "[S"), short_array->GetClass()); data_offset = reinterpret_cast<uintptr_t>(short_array->GetData()); EXPECT_TRUE(IsAligned<2>(data_offset)); // Shorts require 2 byte alignment diff --git a/runtime/dex_register_location.h b/runtime/dex_register_location.h new file mode 100644 index 0000000000..c6d4ad2feb --- /dev/null +++ b/runtime/dex_register_location.h @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2018 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_DEX_REGISTER_LOCATION_H_ +#define ART_RUNTIME_DEX_REGISTER_LOCATION_H_ + +#include <array> +#include <cstdint> + +#include "base/dchecked_vector.h" +#include "base/memory_region.h" + +namespace art { + +// Dex register location container used by DexRegisterMap and StackMapStream. +class DexRegisterLocation { + public: + enum class Kind : int32_t { + kNone = -1, // vreg has not been set. + kInStack, // vreg is on the stack, value holds the stack offset. + kConstant, // vreg is a constant value. + kInRegister, // vreg is in low 32 bits of a core physical register. + kInRegisterHigh, // vreg is in high 32 bits of a core physical register. + kInFpuRegister, // vreg is in low 32 bits of an FPU register. + kInFpuRegisterHigh, // vreg is in high 32 bits of an FPU register. + }; + + DexRegisterLocation(Kind kind, int32_t value) : kind_(kind), value_(value) {} + + static DexRegisterLocation None() { + return DexRegisterLocation(Kind::kNone, 0); + } + + bool IsLive() const { return kind_ != Kind::kNone; } + + Kind GetKind() const { return kind_; } + + // TODO: Remove. + Kind GetInternalKind() const { return kind_; } + + int32_t GetValue() const { return value_; } + + bool operator==(DexRegisterLocation other) const { + return kind_ == other.kind_ && value_ == other.value_; + } + + bool operator!=(DexRegisterLocation other) const { + return !(*this == other); + } + + private: + DexRegisterLocation() {} + + Kind kind_; + int32_t value_; + + friend class DexRegisterMap; // Allow creation of uninitialized array of locations. +}; + +static inline std::ostream& operator<<(std::ostream& stream, DexRegisterLocation::Kind kind) { + return stream << "Kind<" << static_cast<int32_t>(kind) << ">"; +} + +} // namespace art + +#endif // ART_RUNTIME_DEX_REGISTER_LOCATION_H_ diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc index b004566ed1..25ed652b41 100644 --- a/runtime/gc/heap.cc +++ b/runtime/gc/heap.cc @@ -3913,9 +3913,9 @@ void Heap::BroadcastForNewAllocationRecords() const { } void Heap::CheckGcStressMode(Thread* self, ObjPtr<mirror::Object>* obj) { + DCHECK(gc_stress_mode_); auto* const runtime = Runtime::Current(); - if (gc_stress_mode_ && runtime->GetClassLinker()->IsInitialized() && - !runtime->IsActiveTransaction() && mirror::Class::HasJavaLangClass()) { + if (runtime->GetClassLinker()->IsInitialized() && !runtime->IsActiveTransaction()) { // Check if we should GC. bool new_backtrace = false; { diff --git a/runtime/gc/space/space_test.h b/runtime/gc/space/space_test.h index d5861ed5d8..c94b666695 100644 --- a/runtime/gc/space/space_test.h +++ b/runtime/gc/space/space_test.h @@ -53,13 +53,11 @@ class SpaceTest : public Super { } mirror::Class* GetByteArrayClass(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_) { - StackHandleScope<1> hs(self); - auto null_loader(hs.NewHandle<mirror::ClassLoader>(nullptr)); if (byte_array_class_ == nullptr) { - mirror::Class* byte_array_class = - Runtime::Current()->GetClassLinker()->FindClass(self, "[B", null_loader); + ObjPtr<mirror::Class> byte_array_class = + Runtime::Current()->GetClassLinker()->FindSystemClass(self, "[B"); EXPECT_TRUE(byte_array_class != nullptr); - byte_array_class_ = self->GetJniEnv()->NewLocalRef(byte_array_class); + byte_array_class_ = self->GetJniEnv()->NewLocalRef(byte_array_class.Ptr()); EXPECT_TRUE(byte_array_class_ != nullptr); } return self->DecodeJObject(byte_array_class_)->AsClass(); diff --git a/runtime/hidden_api_test.cc b/runtime/hidden_api_test.cc index ab0c2901ff..a41d28492d 100644 --- a/runtime/hidden_api_test.cc +++ b/runtime/hidden_api_test.cc @@ -325,8 +325,8 @@ TEST_F(HiddenApiTest, CheckMemberSignatureForProxyClass) { ASSERT_TRUE(h_iface != nullptr); // Create the proxy class. - std::vector<mirror::Class*> interfaces; - interfaces.push_back(h_iface.Get()); + std::vector<Handle<mirror::Class>> interfaces; + interfaces.push_back(h_iface); Handle<mirror::Class> proxyClass = hs.NewHandle(proxy_test::GenerateProxyClass( soa, jclass_loader_, runtime_->GetClassLinker(), "$Proxy1234", interfaces)); ASSERT_TRUE(proxyClass != nullptr); diff --git a/runtime/interpreter/interpreter_common.cc b/runtime/interpreter/interpreter_common.cc index fab350942a..90e89cf3db 100644 --- a/runtime/interpreter/interpreter_common.cc +++ b/runtime/interpreter/interpreter_common.cc @@ -958,12 +958,9 @@ static bool GetArgumentForBootstrapMethod(Thread* self, return true; } case EncodedArrayValueIterator::ValueType::kType: { - StackHandleScope<2> hs(self); - Handle<mirror::ClassLoader> class_loader(hs.NewHandle(referrer->GetClassLoader())); - Handle<mirror::DexCache> dex_cache(hs.NewHandle(referrer->GetDexCache())); dex::TypeIndex index(static_cast<uint32_t>(encoded_value->GetI())); ClassLinker* cl = Runtime::Current()->GetClassLinker(); - ObjPtr<mirror::Class> o = cl->ResolveType(index, dex_cache, class_loader); + ObjPtr<mirror::Class> o = cl->ResolveType(index, referrer); if (UNLIKELY(o.IsNull())) { DCHECK(self->IsExceptionPending()); return false; @@ -1128,9 +1125,9 @@ static ObjPtr<mirror::MethodType> BuildCallSiteForBootstrapMethod(Thread* self, StackHandleScope<2> hs(self); // Create array for parameter types. - ObjPtr<mirror::Class> class_type = mirror::Class::GetJavaLangClass(); ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); - ObjPtr<mirror::Class> class_array_type = class_linker->FindArrayClass(self, &class_type); + ObjPtr<mirror::Class> class_array_type = + GetClassRoot<mirror::ObjectArray<mirror::Class>>(class_linker); Handle<mirror::ObjectArray<mirror::Class>> ptypes = hs.NewHandle( mirror::ObjectArray<mirror::Class>::Alloc(self, class_array_type, diff --git a/runtime/interpreter/mterp/arm/instruction_end.S b/runtime/interpreter/mterp/arm/instruction_end.S new file mode 100644 index 0000000000..32c725c7d9 --- /dev/null +++ b/runtime/interpreter/mterp/arm/instruction_end.S @@ -0,0 +1,3 @@ + + .global artMterpAsmInstructionEnd +artMterpAsmInstructionEnd: diff --git a/runtime/interpreter/mterp/arm/instruction_end_alt.S b/runtime/interpreter/mterp/arm/instruction_end_alt.S new file mode 100644 index 0000000000..f90916fc02 --- /dev/null +++ b/runtime/interpreter/mterp/arm/instruction_end_alt.S @@ -0,0 +1,3 @@ + + .global artMterpAsmAltInstructionEnd +artMterpAsmAltInstructionEnd: diff --git a/runtime/interpreter/mterp/arm/instruction_end_sister.S b/runtime/interpreter/mterp/arm/instruction_end_sister.S new file mode 100644 index 0000000000..c5f4886697 --- /dev/null +++ b/runtime/interpreter/mterp/arm/instruction_end_sister.S @@ -0,0 +1,3 @@ + + .global artMterpAsmSisterEnd +artMterpAsmSisterEnd: diff --git a/runtime/interpreter/mterp/arm/instruction_start.S b/runtime/interpreter/mterp/arm/instruction_start.S new file mode 100644 index 0000000000..8874c20540 --- /dev/null +++ b/runtime/interpreter/mterp/arm/instruction_start.S @@ -0,0 +1,4 @@ + + .global artMterpAsmInstructionStart +artMterpAsmInstructionStart = .L_op_nop + .text diff --git a/runtime/interpreter/mterp/arm/instruction_start_alt.S b/runtime/interpreter/mterp/arm/instruction_start_alt.S new file mode 100644 index 0000000000..0c9ffdb7d6 --- /dev/null +++ b/runtime/interpreter/mterp/arm/instruction_start_alt.S @@ -0,0 +1,4 @@ + + .global artMterpAsmAltInstructionStart +artMterpAsmAltInstructionStart = .L_ALT_op_nop + .text diff --git a/runtime/interpreter/mterp/arm/instruction_start_sister.S b/runtime/interpreter/mterp/arm/instruction_start_sister.S new file mode 100644 index 0000000000..2ec51f7261 --- /dev/null +++ b/runtime/interpreter/mterp/arm/instruction_start_sister.S @@ -0,0 +1,5 @@ + + .global artMterpAsmSisterStart + .text + .balign 4 +artMterpAsmSisterStart: diff --git a/runtime/interpreter/mterp/arm64/instruction_end.S b/runtime/interpreter/mterp/arm64/instruction_end.S new file mode 100644 index 0000000000..32c725c7d9 --- /dev/null +++ b/runtime/interpreter/mterp/arm64/instruction_end.S @@ -0,0 +1,3 @@ + + .global artMterpAsmInstructionEnd +artMterpAsmInstructionEnd: diff --git a/runtime/interpreter/mterp/arm64/instruction_end_alt.S b/runtime/interpreter/mterp/arm64/instruction_end_alt.S new file mode 100644 index 0000000000..f90916fc02 --- /dev/null +++ b/runtime/interpreter/mterp/arm64/instruction_end_alt.S @@ -0,0 +1,3 @@ + + .global artMterpAsmAltInstructionEnd +artMterpAsmAltInstructionEnd: diff --git a/runtime/interpreter/mterp/arm64/instruction_end_sister.S b/runtime/interpreter/mterp/arm64/instruction_end_sister.S new file mode 100644 index 0000000000..c5f4886697 --- /dev/null +++ b/runtime/interpreter/mterp/arm64/instruction_end_sister.S @@ -0,0 +1,3 @@ + + .global artMterpAsmSisterEnd +artMterpAsmSisterEnd: diff --git a/runtime/interpreter/mterp/arm64/instruction_start.S b/runtime/interpreter/mterp/arm64/instruction_start.S new file mode 100644 index 0000000000..8874c20540 --- /dev/null +++ b/runtime/interpreter/mterp/arm64/instruction_start.S @@ -0,0 +1,4 @@ + + .global artMterpAsmInstructionStart +artMterpAsmInstructionStart = .L_op_nop + .text diff --git a/runtime/interpreter/mterp/arm64/instruction_start_alt.S b/runtime/interpreter/mterp/arm64/instruction_start_alt.S new file mode 100644 index 0000000000..0c9ffdb7d6 --- /dev/null +++ b/runtime/interpreter/mterp/arm64/instruction_start_alt.S @@ -0,0 +1,4 @@ + + .global artMterpAsmAltInstructionStart +artMterpAsmAltInstructionStart = .L_ALT_op_nop + .text diff --git a/runtime/interpreter/mterp/arm64/instruction_start_sister.S b/runtime/interpreter/mterp/arm64/instruction_start_sister.S new file mode 100644 index 0000000000..2ec51f7261 --- /dev/null +++ b/runtime/interpreter/mterp/arm64/instruction_start_sister.S @@ -0,0 +1,5 @@ + + .global artMterpAsmSisterStart + .text + .balign 4 +artMterpAsmSisterStart: diff --git a/runtime/interpreter/mterp/gen_mterp.py b/runtime/interpreter/mterp/gen_mterp.py index 64114d747a..75c5174bcb 100755 --- a/runtime/interpreter/mterp/gen_mterp.py +++ b/runtime/interpreter/mterp/gen_mterp.py @@ -279,13 +279,8 @@ def loadAndEmitOpcodes(): sister_list = [] assert len(opcodes) == kNumPackedOpcodes need_dummy_start = False - start_label = global_name_format % "artMterpAsmInstructionStart" - end_label = global_name_format % "artMterpAsmInstructionEnd" - # point MterpAsmInstructionStart at the first handler or stub - asm_fp.write("\n .global %s\n" % start_label) - asm_fp.write("%s = " % start_label + label_prefix + "_op_nop\n") - asm_fp.write(" .text\n\n") + loadAndEmitGenericAsm("instruction_start") for i in xrange(kNumPackedOpcodes): op = opcodes[i] @@ -309,20 +304,14 @@ def loadAndEmitOpcodes(): asm_fp.write(label_prefix + "_op_nop: /* dummy */\n"); emitAlign() - asm_fp.write(" .global %s\n" % end_label) - asm_fp.write("%s:\n" % end_label) + + loadAndEmitGenericAsm("instruction_end") if style == "computed-goto": - start_sister_label = global_name_format % "artMterpAsmSisterStart" - end_sister_label = global_name_format % "artMterpAsmSisterEnd" emitSectionComment("Sister implementations", asm_fp) - asm_fp.write(" .global %s\n" % start_sister_label) - asm_fp.write(" .text\n") - asm_fp.write(" .balign 4\n") - asm_fp.write("%s:\n" % start_sister_label) + loadAndEmitGenericAsm("instruction_start_sister") asm_fp.writelines(sister_list) - asm_fp.write(" .global %s\n" % end_sister_label) - asm_fp.write("%s:\n\n" % end_sister_label) + loadAndEmitGenericAsm("instruction_end_sister") # # Load an alternate entry stub @@ -345,10 +334,7 @@ def loadAndEmitAltOpcodes(): start_label = global_name_format % "artMterpAsmAltInstructionStart" end_label = global_name_format % "artMterpAsmAltInstructionEnd" - # point MterpAsmInstructionStart at the first handler or stub - asm_fp.write("\n .global %s\n" % start_label) - asm_fp.write(" .text\n\n") - asm_fp.write("%s = " % start_label + label_prefix + "_ALT_op_nop\n") + loadAndEmitGenericAsm("instruction_start_alt") for i in xrange(kNumPackedOpcodes): op = opcodes[i] @@ -359,8 +345,8 @@ def loadAndEmitAltOpcodes(): loadAndEmitAltStub(source, i) emitAlign() - asm_fp.write(" .global %s\n" % end_label) - asm_fp.write("%s:\n" % end_label) + + loadAndEmitGenericAsm("instruction_end_alt") # # Load an assembly fragment and emit it. @@ -377,6 +363,14 @@ def loadAndEmitAsm(location, opindex, sister_list): appendSourceFile(source, dict, asm_fp, sister_list) # +# Load a non-handler assembly fragment and emit it. +# +def loadAndEmitGenericAsm(name): + source = "%s/%s.S" % (default_op_dir, name) + dict = getGlobalSubDict() + appendSourceFile(source, dict, asm_fp, None) + +# # Emit fallback fragment # def emitFallback(opindex): diff --git a/runtime/interpreter/mterp/mips/instruction_end.S b/runtime/interpreter/mterp/mips/instruction_end.S new file mode 100644 index 0000000000..32c725c7d9 --- /dev/null +++ b/runtime/interpreter/mterp/mips/instruction_end.S @@ -0,0 +1,3 @@ + + .global artMterpAsmInstructionEnd +artMterpAsmInstructionEnd: diff --git a/runtime/interpreter/mterp/mips/instruction_end_alt.S b/runtime/interpreter/mterp/mips/instruction_end_alt.S new file mode 100644 index 0000000000..f90916fc02 --- /dev/null +++ b/runtime/interpreter/mterp/mips/instruction_end_alt.S @@ -0,0 +1,3 @@ + + .global artMterpAsmAltInstructionEnd +artMterpAsmAltInstructionEnd: diff --git a/runtime/interpreter/mterp/mips/instruction_end_sister.S b/runtime/interpreter/mterp/mips/instruction_end_sister.S new file mode 100644 index 0000000000..c5f4886697 --- /dev/null +++ b/runtime/interpreter/mterp/mips/instruction_end_sister.S @@ -0,0 +1,3 @@ + + .global artMterpAsmSisterEnd +artMterpAsmSisterEnd: diff --git a/runtime/interpreter/mterp/mips/instruction_start.S b/runtime/interpreter/mterp/mips/instruction_start.S new file mode 100644 index 0000000000..8874c20540 --- /dev/null +++ b/runtime/interpreter/mterp/mips/instruction_start.S @@ -0,0 +1,4 @@ + + .global artMterpAsmInstructionStart +artMterpAsmInstructionStart = .L_op_nop + .text diff --git a/runtime/interpreter/mterp/mips/instruction_start_alt.S b/runtime/interpreter/mterp/mips/instruction_start_alt.S new file mode 100644 index 0000000000..0c9ffdb7d6 --- /dev/null +++ b/runtime/interpreter/mterp/mips/instruction_start_alt.S @@ -0,0 +1,4 @@ + + .global artMterpAsmAltInstructionStart +artMterpAsmAltInstructionStart = .L_ALT_op_nop + .text diff --git a/runtime/interpreter/mterp/mips/instruction_start_sister.S b/runtime/interpreter/mterp/mips/instruction_start_sister.S new file mode 100644 index 0000000000..2ec51f7261 --- /dev/null +++ b/runtime/interpreter/mterp/mips/instruction_start_sister.S @@ -0,0 +1,5 @@ + + .global artMterpAsmSisterStart + .text + .balign 4 +artMterpAsmSisterStart: diff --git a/runtime/interpreter/mterp/mips64/instruction_end.S b/runtime/interpreter/mterp/mips64/instruction_end.S new file mode 100644 index 0000000000..32c725c7d9 --- /dev/null +++ b/runtime/interpreter/mterp/mips64/instruction_end.S @@ -0,0 +1,3 @@ + + .global artMterpAsmInstructionEnd +artMterpAsmInstructionEnd: diff --git a/runtime/interpreter/mterp/mips64/instruction_end_alt.S b/runtime/interpreter/mterp/mips64/instruction_end_alt.S new file mode 100644 index 0000000000..f90916fc02 --- /dev/null +++ b/runtime/interpreter/mterp/mips64/instruction_end_alt.S @@ -0,0 +1,3 @@ + + .global artMterpAsmAltInstructionEnd +artMterpAsmAltInstructionEnd: diff --git a/runtime/interpreter/mterp/mips64/instruction_end_sister.S b/runtime/interpreter/mterp/mips64/instruction_end_sister.S new file mode 100644 index 0000000000..c5f4886697 --- /dev/null +++ b/runtime/interpreter/mterp/mips64/instruction_end_sister.S @@ -0,0 +1,3 @@ + + .global artMterpAsmSisterEnd +artMterpAsmSisterEnd: diff --git a/runtime/interpreter/mterp/mips64/instruction_start.S b/runtime/interpreter/mterp/mips64/instruction_start.S new file mode 100644 index 0000000000..8874c20540 --- /dev/null +++ b/runtime/interpreter/mterp/mips64/instruction_start.S @@ -0,0 +1,4 @@ + + .global artMterpAsmInstructionStart +artMterpAsmInstructionStart = .L_op_nop + .text diff --git a/runtime/interpreter/mterp/mips64/instruction_start_alt.S b/runtime/interpreter/mterp/mips64/instruction_start_alt.S new file mode 100644 index 0000000000..0c9ffdb7d6 --- /dev/null +++ b/runtime/interpreter/mterp/mips64/instruction_start_alt.S @@ -0,0 +1,4 @@ + + .global artMterpAsmAltInstructionStart +artMterpAsmAltInstructionStart = .L_ALT_op_nop + .text diff --git a/runtime/interpreter/mterp/mips64/instruction_start_sister.S b/runtime/interpreter/mterp/mips64/instruction_start_sister.S new file mode 100644 index 0000000000..2ec51f7261 --- /dev/null +++ b/runtime/interpreter/mterp/mips64/instruction_start_sister.S @@ -0,0 +1,5 @@ + + .global artMterpAsmSisterStart + .text + .balign 4 +artMterpAsmSisterStart: diff --git a/runtime/interpreter/mterp/out/mterp_arm.S b/runtime/interpreter/mterp/out/mterp_arm.S index 7ea79821b4..b2702a9ffc 100644 --- a/runtime/interpreter/mterp/out/mterp_arm.S +++ b/runtime/interpreter/mterp/out/mterp_arm.S @@ -396,6 +396,7 @@ ENTRY ExecuteMterpImpl GOTO_OPCODE ip @ jump to next instruction /* NOTE: no fallthrough */ +/* File: arm/instruction_start.S */ .global artMterpAsmInstructionStart artMterpAsmInstructionStart = .L_op_nop @@ -7509,19 +7510,25 @@ constvalop_long_to_double: .balign 128 +/* File: arm/instruction_end.S */ + .global artMterpAsmInstructionEnd artMterpAsmInstructionEnd: + /* * =========================================================================== * Sister implementations * =========================================================================== */ +/* File: arm/instruction_start_sister.S */ + .global artMterpAsmSisterStart .text .balign 4 artMterpAsmSisterStart: + /* continuation for op_float_to_long */ /* * Convert the float in r0 to a long in r0/r1. @@ -7583,14 +7590,17 @@ d2l_maybeNaN: mov r0, #0 mov r1, #0 bx lr @ return 0 for NaN +/* File: arm/instruction_end_sister.S */ + .global artMterpAsmSisterEnd artMterpAsmSisterEnd: +/* File: arm/instruction_start_alt.S */ .global artMterpAsmAltInstructionStart +artMterpAsmAltInstructionStart = .L_ALT_op_nop .text -artMterpAsmAltInstructionStart = .L_ALT_op_nop /* ------------------------------ */ .balign 128 .L_ALT_op_nop: /* 0x00 */ @@ -11944,8 +11954,11 @@ artMterpAsmAltInstructionStart = .L_ALT_op_nop b MterpCheckBefore @ (self, shadow_frame, dex_pc_ptr) @ Tail call. .balign 128 +/* File: arm/instruction_end_alt.S */ + .global artMterpAsmAltInstructionEnd artMterpAsmAltInstructionEnd: + /* File: arm/footer.S */ /* * =========================================================================== diff --git a/runtime/interpreter/mterp/out/mterp_arm64.S b/runtime/interpreter/mterp/out/mterp_arm64.S index 70f71ff2bc..2a0c4df3e2 100644 --- a/runtime/interpreter/mterp/out/mterp_arm64.S +++ b/runtime/interpreter/mterp/out/mterp_arm64.S @@ -427,6 +427,7 @@ ENTRY ExecuteMterpImpl GOTO_OPCODE ip // jump to next instruction /* NOTE: no fallthrough */ +/* File: arm64/instruction_start.S */ .global artMterpAsmInstructionStart artMterpAsmInstructionStart = .L_op_nop @@ -7075,18 +7076,26 @@ artMterpAsmInstructionStart = .L_op_nop .balign 128 +/* File: arm64/instruction_end.S */ + .global artMterpAsmInstructionEnd artMterpAsmInstructionEnd: + /* * =========================================================================== * Sister implementations * =========================================================================== */ +/* File: arm64/instruction_start_sister.S */ + .global artMterpAsmSisterStart .text .balign 4 artMterpAsmSisterStart: + +/* File: arm64/instruction_end_sister.S */ + .global artMterpAsmSisterEnd artMterpAsmSisterEnd: @@ -7398,11 +7407,12 @@ MterpProfileActive: ret +/* File: arm64/instruction_start_alt.S */ .global artMterpAsmAltInstructionStart +artMterpAsmAltInstructionStart = .L_ALT_op_nop .text -artMterpAsmAltInstructionStart = .L_ALT_op_nop /* ------------------------------ */ .balign 128 .L_ALT_op_nop: /* 0x00 */ @@ -11756,8 +11766,11 @@ artMterpAsmAltInstructionStart = .L_ALT_op_nop b MterpCheckBefore // (self, shadow_frame, dex_pc_ptr) Note: tail call. .balign 128 +/* File: arm64/instruction_end_alt.S */ + .global artMterpAsmAltInstructionEnd artMterpAsmAltInstructionEnd: + /* File: arm64/close_cfi.S */ // Close out the cfi info. We're treating mterp as a single function. diff --git a/runtime/interpreter/mterp/out/mterp_mips.S b/runtime/interpreter/mterp/out/mterp_mips.S index 69568eaf44..3b86279b47 100644 --- a/runtime/interpreter/mterp/out/mterp_mips.S +++ b/runtime/interpreter/mterp/out/mterp_mips.S @@ -810,6 +810,7 @@ ExecuteMterpImpl: GOTO_OPCODE(t0) # jump to next instruction /* NOTE: no fallthrough */ +/* File: mips/instruction_start.S */ .global artMterpAsmInstructionStart artMterpAsmInstructionStart = .L_op_nop @@ -7873,19 +7874,25 @@ artMterpAsmInstructionStart = .L_op_nop .balign 128 +/* File: mips/instruction_end.S */ + .global artMterpAsmInstructionEnd artMterpAsmInstructionEnd: + /* * =========================================================================== * Sister implementations * =========================================================================== */ +/* File: mips/instruction_start_sister.S */ + .global artMterpAsmSisterStart .text .balign 4 artMterpAsmSisterStart: + /* continuation for op_float_to_long */ #ifndef MIPS32REVGE6 @@ -7941,14 +7948,17 @@ artMterpAsmSisterStart: .Lop_ushr_long_2addr_finish: SET_VREG64_GOTO(v1, zero, t3, t0) # vA/vA+1 <- rlo/rhi +/* File: mips/instruction_end_sister.S */ + .global artMterpAsmSisterEnd artMterpAsmSisterEnd: +/* File: mips/instruction_start_alt.S */ .global artMterpAsmAltInstructionStart +artMterpAsmAltInstructionStart = .L_ALT_op_nop .text -artMterpAsmAltInstructionStart = .L_ALT_op_nop /* ------------------------------ */ .balign 128 .L_ALT_op_nop: /* 0x00 */ @@ -12558,8 +12568,11 @@ artMterpAsmAltInstructionStart = .L_ALT_op_nop jalr zero, t9 # Tail call to Mterp(self, shadow_frame, dex_pc_ptr) .balign 128 +/* File: mips/instruction_end_alt.S */ + .global artMterpAsmAltInstructionEnd artMterpAsmAltInstructionEnd: + /* File: mips/footer.S */ /* * =========================================================================== diff --git a/runtime/interpreter/mterp/out/mterp_mips64.S b/runtime/interpreter/mterp/out/mterp_mips64.S index 83a6613e37..58f98dfabb 100644 --- a/runtime/interpreter/mterp/out/mterp_mips64.S +++ b/runtime/interpreter/mterp/out/mterp_mips64.S @@ -430,6 +430,7 @@ ExecuteMterpImpl: /* NOTE: no fallthrough */ +/* File: mips64/instruction_start.S */ .global artMterpAsmInstructionStart artMterpAsmInstructionStart = .L_op_nop @@ -7299,26 +7300,35 @@ artMterpAsmInstructionStart = .L_op_nop .balign 128 +/* File: mips64/instruction_end.S */ + .global artMterpAsmInstructionEnd artMterpAsmInstructionEnd: + /* * =========================================================================== * Sister implementations * =========================================================================== */ +/* File: mips64/instruction_start_sister.S */ + .global artMterpAsmSisterStart .text .balign 4 artMterpAsmSisterStart: + +/* File: mips64/instruction_end_sister.S */ + .global artMterpAsmSisterEnd artMterpAsmSisterEnd: +/* File: mips64/instruction_start_alt.S */ .global artMterpAsmAltInstructionStart +artMterpAsmAltInstructionStart = .L_ALT_op_nop .text -artMterpAsmAltInstructionStart = .L_ALT_op_nop /* ------------------------------ */ .balign 128 .L_ALT_op_nop: /* 0x00 */ @@ -12184,8 +12194,11 @@ artMterpAsmAltInstructionStart = .L_ALT_op_nop jalr zero, t9 # (self, shadow_frame, dex_pc_ptr) Note: tail call. .balign 128 +/* File: mips64/instruction_end_alt.S */ + .global artMterpAsmAltInstructionEnd artMterpAsmAltInstructionEnd: + /* File: mips64/footer.S */ /* * We've detected a condition that will result in an exception, but the exception diff --git a/runtime/interpreter/mterp/out/mterp_x86.S b/runtime/interpreter/mterp/out/mterp_x86.S index 1eacfe8736..6be70cce4c 100644 --- a/runtime/interpreter/mterp/out/mterp_x86.S +++ b/runtime/interpreter/mterp/out/mterp_x86.S @@ -405,6 +405,7 @@ SYMBOL(ExecuteMterpImpl): GOTO_NEXT /* NOTE: no fallthrough */ +/* File: x86/instruction_start.S */ .global SYMBOL(artMterpAsmInstructionStart) SYMBOL(artMterpAsmInstructionStart) = .L_op_nop @@ -6470,26 +6471,35 @@ SYMBOL(artMterpAsmInstructionStart) = .L_op_nop .balign 128 +/* File: x86/instruction_end.S */ + .global SYMBOL(artMterpAsmInstructionEnd) SYMBOL(artMterpAsmInstructionEnd): + /* * =========================================================================== * Sister implementations * =========================================================================== */ +/* File: x86/instruction_start_sister.S */ + .global SYMBOL(artMterpAsmSisterStart) .text .balign 4 SYMBOL(artMterpAsmSisterStart): + +/* File: x86/instruction_end_sister.S */ + .global SYMBOL(artMterpAsmSisterEnd) SYMBOL(artMterpAsmSisterEnd): +/* File: x86/instruction_start_alt.S */ .global SYMBOL(artMterpAsmAltInstructionStart) .text - SYMBOL(artMterpAsmAltInstructionStart) = .L_ALT_op_nop + /* ------------------------------ */ .balign 128 .L_ALT_op_nop: /* 0x00 */ @@ -12635,8 +12645,11 @@ SYMBOL(artMterpAsmAltInstructionStart) = .L_ALT_op_nop jmp .L_op_nop+(255*128) .balign 128 +/* File: x86/instruction_end_alt.S */ + .global SYMBOL(artMterpAsmAltInstructionEnd) SYMBOL(artMterpAsmAltInstructionEnd): + /* File: x86/footer.S */ /* * =========================================================================== diff --git a/runtime/interpreter/mterp/out/mterp_x86_64.S b/runtime/interpreter/mterp/out/mterp_x86_64.S index ea8f483e95..562cf7ceb6 100644 --- a/runtime/interpreter/mterp/out/mterp_x86_64.S +++ b/runtime/interpreter/mterp/out/mterp_x86_64.S @@ -387,6 +387,7 @@ SYMBOL(ExecuteMterpImpl): GOTO_NEXT /* NOTE: no fallthrough */ +/* File: x86_64/instruction_start.S */ .global SYMBOL(artMterpAsmInstructionStart) SYMBOL(artMterpAsmInstructionStart) = .L_op_nop @@ -6217,26 +6218,35 @@ movswl %ax, %eax .balign 128 +/* File: x86_64/instruction_end.S */ + .global SYMBOL(artMterpAsmInstructionEnd) SYMBOL(artMterpAsmInstructionEnd): + /* * =========================================================================== * Sister implementations * =========================================================================== */ +/* File: x86_64/instruction_start_sister.S */ + .global SYMBOL(artMterpAsmSisterStart) .text .balign 4 SYMBOL(artMterpAsmSisterStart): + +/* File: x86_64/instruction_end_sister.S */ + .global SYMBOL(artMterpAsmSisterEnd) SYMBOL(artMterpAsmSisterEnd): +/* File: x86_64/instruction_start_alt.S */ .global SYMBOL(artMterpAsmAltInstructionStart) .text - SYMBOL(artMterpAsmAltInstructionStart) = .L_ALT_op_nop + /* ------------------------------ */ .balign 128 .L_ALT_op_nop: /* 0x00 */ @@ -11870,8 +11880,11 @@ SYMBOL(artMterpAsmAltInstructionStart) = .L_ALT_op_nop jmp .L_op_nop+(255*128) .balign 128 +/* File: x86_64/instruction_end_alt.S */ + .global SYMBOL(artMterpAsmAltInstructionEnd) SYMBOL(artMterpAsmAltInstructionEnd): + /* File: x86_64/footer.S */ /* * =========================================================================== diff --git a/runtime/interpreter/mterp/x86/instruction_end.S b/runtime/interpreter/mterp/x86/instruction_end.S new file mode 100644 index 0000000000..3a02a212e6 --- /dev/null +++ b/runtime/interpreter/mterp/x86/instruction_end.S @@ -0,0 +1,3 @@ + + .global SYMBOL(artMterpAsmInstructionEnd) +SYMBOL(artMterpAsmInstructionEnd): diff --git a/runtime/interpreter/mterp/x86/instruction_end_alt.S b/runtime/interpreter/mterp/x86/instruction_end_alt.S new file mode 100644 index 0000000000..33c2b8e2a0 --- /dev/null +++ b/runtime/interpreter/mterp/x86/instruction_end_alt.S @@ -0,0 +1,3 @@ + + .global SYMBOL(artMterpAsmAltInstructionEnd) +SYMBOL(artMterpAsmAltInstructionEnd): diff --git a/runtime/interpreter/mterp/x86/instruction_end_sister.S b/runtime/interpreter/mterp/x86/instruction_end_sister.S new file mode 100644 index 0000000000..ea14b11ede --- /dev/null +++ b/runtime/interpreter/mterp/x86/instruction_end_sister.S @@ -0,0 +1,3 @@ + + .global SYMBOL(artMterpAsmSisterEnd) +SYMBOL(artMterpAsmSisterEnd): diff --git a/runtime/interpreter/mterp/x86/instruction_start.S b/runtime/interpreter/mterp/x86/instruction_start.S new file mode 100644 index 0000000000..ca711de00c --- /dev/null +++ b/runtime/interpreter/mterp/x86/instruction_start.S @@ -0,0 +1,4 @@ + + .global SYMBOL(artMterpAsmInstructionStart) +SYMBOL(artMterpAsmInstructionStart) = .L_op_nop + .text diff --git a/runtime/interpreter/mterp/x86/instruction_start_alt.S b/runtime/interpreter/mterp/x86/instruction_start_alt.S new file mode 100644 index 0000000000..9272a6a7b0 --- /dev/null +++ b/runtime/interpreter/mterp/x86/instruction_start_alt.S @@ -0,0 +1,4 @@ + + .global SYMBOL(artMterpAsmAltInstructionStart) + .text +SYMBOL(artMterpAsmAltInstructionStart) = .L_ALT_op_nop diff --git a/runtime/interpreter/mterp/x86/instruction_start_sister.S b/runtime/interpreter/mterp/x86/instruction_start_sister.S new file mode 100644 index 0000000000..b9ac994d32 --- /dev/null +++ b/runtime/interpreter/mterp/x86/instruction_start_sister.S @@ -0,0 +1,5 @@ + + .global SYMBOL(artMterpAsmSisterStart) + .text + .balign 4 +SYMBOL(artMterpAsmSisterStart): diff --git a/runtime/interpreter/mterp/x86_64/instruction_end.S b/runtime/interpreter/mterp/x86_64/instruction_end.S new file mode 100644 index 0000000000..3a02a212e6 --- /dev/null +++ b/runtime/interpreter/mterp/x86_64/instruction_end.S @@ -0,0 +1,3 @@ + + .global SYMBOL(artMterpAsmInstructionEnd) +SYMBOL(artMterpAsmInstructionEnd): diff --git a/runtime/interpreter/mterp/x86_64/instruction_end_alt.S b/runtime/interpreter/mterp/x86_64/instruction_end_alt.S new file mode 100644 index 0000000000..33c2b8e2a0 --- /dev/null +++ b/runtime/interpreter/mterp/x86_64/instruction_end_alt.S @@ -0,0 +1,3 @@ + + .global SYMBOL(artMterpAsmAltInstructionEnd) +SYMBOL(artMterpAsmAltInstructionEnd): diff --git a/runtime/interpreter/mterp/x86_64/instruction_end_sister.S b/runtime/interpreter/mterp/x86_64/instruction_end_sister.S new file mode 100644 index 0000000000..ea14b11ede --- /dev/null +++ b/runtime/interpreter/mterp/x86_64/instruction_end_sister.S @@ -0,0 +1,3 @@ + + .global SYMBOL(artMterpAsmSisterEnd) +SYMBOL(artMterpAsmSisterEnd): diff --git a/runtime/interpreter/mterp/x86_64/instruction_start.S b/runtime/interpreter/mterp/x86_64/instruction_start.S new file mode 100644 index 0000000000..ca711de00c --- /dev/null +++ b/runtime/interpreter/mterp/x86_64/instruction_start.S @@ -0,0 +1,4 @@ + + .global SYMBOL(artMterpAsmInstructionStart) +SYMBOL(artMterpAsmInstructionStart) = .L_op_nop + .text diff --git a/runtime/interpreter/mterp/x86_64/instruction_start_alt.S b/runtime/interpreter/mterp/x86_64/instruction_start_alt.S new file mode 100644 index 0000000000..9272a6a7b0 --- /dev/null +++ b/runtime/interpreter/mterp/x86_64/instruction_start_alt.S @@ -0,0 +1,4 @@ + + .global SYMBOL(artMterpAsmAltInstructionStart) + .text +SYMBOL(artMterpAsmAltInstructionStart) = .L_ALT_op_nop diff --git a/runtime/interpreter/mterp/x86_64/instruction_start_sister.S b/runtime/interpreter/mterp/x86_64/instruction_start_sister.S new file mode 100644 index 0000000000..b9ac994d32 --- /dev/null +++ b/runtime/interpreter/mterp/x86_64/instruction_start_sister.S @@ -0,0 +1,5 @@ + + .global SYMBOL(artMterpAsmSisterStart) + .text + .balign 4 +SYMBOL(artMterpAsmSisterStart): diff --git a/runtime/interpreter/unstarted_runtime_test.cc b/runtime/interpreter/unstarted_runtime_test.cc index 88cfafba47..449458ce6f 100644 --- a/runtime/interpreter/unstarted_runtime_test.cc +++ b/runtime/interpreter/unstarted_runtime_test.cc @@ -196,7 +196,7 @@ class UnstartedRuntimeTest : public CommonRuntimeTest { // Prepare for aborts. Aborts assume that the exception class is already resolved, as the // loading code doesn't work under transactions. void PrepareForAborts() REQUIRES_SHARED(Locks::mutator_lock_) { - mirror::Object* result = Runtime::Current()->GetClassLinker()->FindClass( + ObjPtr<mirror::Object> result = Runtime::Current()->GetClassLinker()->FindClass( Thread::Current(), Transaction::kAbortExceptionSignature, ScopedNullHandle<mirror::ClassLoader>()); @@ -448,8 +448,7 @@ TEST_F(UnstartedRuntimeTest, SystemArrayCopyObjectArrayTestExceptions) { // Note: all tests are not GC safe. Assume there's no GC running here with the few objects we // allocate. StackHandleScope<3> hs_misc(self); - Handle<mirror::Class> object_class( - hs_misc.NewHandle(mirror::Class::GetJavaLangClass()->GetSuperClass())); + Handle<mirror::Class> object_class(hs_misc.NewHandle(GetClassRoot<mirror::Object>())); StackHandleScope<3> hs_data(self); hs_data.NewHandle(mirror::String::AllocFromModifiedUtf8(self, "1")); @@ -481,8 +480,7 @@ TEST_F(UnstartedRuntimeTest, SystemArrayCopyObjectArrayTest) { ShadowFrame* tmp = ShadowFrame::CreateDeoptimizedFrame(10, nullptr, nullptr, 0); StackHandleScope<1> hs_object(self); - Handle<mirror::Class> object_class( - hs_object.NewHandle(mirror::Class::GetJavaLangClass()->GetSuperClass())); + Handle<mirror::Class> object_class(hs_object.NewHandle(GetClassRoot<mirror::Object>())); // Simple test: // [1,2,3]{1 @ 2} into [4,5,6] = [4,2,6] @@ -902,7 +900,7 @@ TEST_F(UnstartedRuntimeTest, IsAnonymousClass) { JValue result; ShadowFrame* shadow_frame = ShadowFrame::CreateDeoptimizedFrame(10, nullptr, nullptr, 0); - ObjPtr<mirror::Class> class_klass = mirror::Class::GetJavaLangClass(); + ObjPtr<mirror::Class> class_klass = GetClassRoot<mirror::Class>(); shadow_frame->SetVRegReference(0, class_klass); UnstartedClassIsAnonymousClass(self, shadow_frame, &result, 0); EXPECT_EQ(result.GetZ(), 0); @@ -996,7 +994,7 @@ TEST_F(UnstartedRuntimeTest, ThreadLocalGet) { { // Just use a method in Class. - ObjPtr<mirror::Class> class_class = mirror::Class::GetJavaLangClass(); + ObjPtr<mirror::Class> class_class = GetClassRoot<mirror::Class>(); ArtMethod* caller_method = &*class_class->GetDeclaredMethods(class_linker->GetImagePointerSize()).begin(); ShadowFrame* caller_frame = ShadowFrame::CreateDeoptimizedFrame(10, nullptr, caller_method, 0); @@ -1111,7 +1109,7 @@ class UnstartedClassForNameTest : public UnstartedRuntimeTest { { ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); StackHandleScope<1> hs(self); - Handle<mirror::Class> h_class = hs.NewHandle(mirror::Class::GetJavaLangClass()); + Handle<mirror::Class> h_class = hs.NewHandle(GetClassRoot<mirror::Class>()); CHECK(class_linker->EnsureInitialized(self, h_class, true, true)); } diff --git a/runtime/method_handles_test.cc b/runtime/method_handles_test.cc index a9473421cb..0db9551265 100644 --- a/runtime/method_handles_test.cc +++ b/runtime/method_handles_test.cc @@ -17,6 +17,7 @@ #include "method_handles.h" #include "class_linker-inl.h" +#include "class_root.h" #include "common_runtime_test.h" #include "handle_scope-inl.h" #include "jvalue-inl.h" @@ -49,12 +50,11 @@ namespace { REQUIRES_SHARED(Locks::mutator_lock_) { ClassLinker* cl = Runtime::Current()->GetClassLinker(); StackHandleScope<2> hs(self); - ObjPtr<mirror::Class> class_type = mirror::Class::GetJavaLangClass(); - ObjPtr<mirror::Class> class_array_type = cl->FindArrayClass(self, &class_type); + ObjPtr<mirror::Class> class_array_type = GetClassRoot<mirror::ObjectArray<mirror::Class>>(cl); auto parameter_types = hs.NewHandle( mirror::ObjectArray<mirror::Class>::Alloc(self, class_array_type, 1)); parameter_types->Set(0, parameter_type.Get()); - Handle<mirror::Class> void_class = hs.NewHandle(cl->FindPrimitiveClass('V')); + Handle<mirror::Class> void_class = hs.NewHandle(GetClassRoot(ClassRoot::kPrimitiveVoid, cl)); return mirror::MethodType::Create(self, void_class, parameter_types); } diff --git a/runtime/mirror/call_site.cc b/runtime/mirror/call_site.cc index 808f77cde1..738106c0e4 100644 --- a/runtime/mirror/call_site.cc +++ b/runtime/mirror/call_site.cc @@ -18,18 +18,17 @@ #include "class-inl.h" #include "class_root.h" -#include "gc_root-inl.h" +#include "obj_ptr-inl.h" namespace art { namespace mirror { mirror::CallSite* CallSite::Create(Thread* const self, Handle<MethodHandle> target) { - StackHandleScope<1> hs(self); - Handle<mirror::CallSite> cs( - hs.NewHandle(ObjPtr<CallSite>::DownCast(GetClassRoot<CallSite>()->AllocObject(self)))); + ObjPtr<mirror::CallSite> cs = + ObjPtr<CallSite>::DownCast(GetClassRoot<CallSite>()->AllocObject(self)); CHECK(!Runtime::Current()->IsActiveTransaction()); cs->SetFieldObject<false>(TargetOffset(), target.Get()); - return cs.Get(); + return cs.Ptr(); } } // namespace mirror diff --git a/runtime/mirror/class-inl.h b/runtime/mirror/class-inl.h index ab50973e89..5328ad979f 100644 --- a/runtime/mirror/class-inl.h +++ b/runtime/mirror/class-inl.h @@ -145,6 +145,7 @@ inline ArraySlice<ArtMethod> Class::GetDeclaredMethodsSliceUnchecked(PointerSize GetDirectMethodsStartOffset(), GetCopiedMethodsStartOffset()); } + template<VerifyObjectFlags kVerifyFlags> inline ArraySlice<ArtMethod> Class::GetDeclaredVirtualMethodsSlice(PointerSize pointer_size) { DCHECK(IsLoaded() || IsErroneous()); @@ -281,8 +282,7 @@ inline ArtMethod* Class::GetVirtualMethodUnchecked(size_t i, PointerSize pointer return &GetVirtualMethodsSliceUnchecked(pointer_size)[i]; } -template<VerifyObjectFlags kVerifyFlags, - ReadBarrierOption kReadBarrierOption> +template<VerifyObjectFlags kVerifyFlags, ReadBarrierOption kReadBarrierOption> inline PointerArray* Class::GetVTable() { DCHECK(IsLoaded<kVerifyFlags>() || IsErroneous<kVerifyFlags>()); return GetFieldObject<PointerArray, kVerifyFlags, kReadBarrierOption>( @@ -302,8 +302,7 @@ inline bool Class::HasVTable() { return GetVTable() != nullptr || ShouldHaveEmbeddedVTable(); } - template<VerifyObjectFlags kVerifyFlags, - ReadBarrierOption kReadBarrierOption> +template<VerifyObjectFlags kVerifyFlags, ReadBarrierOption kReadBarrierOption> inline int32_t Class::GetVTableLength() { if (ShouldHaveEmbeddedVTable<kVerifyFlags, kReadBarrierOption>()) { return GetEmbeddedVTableLength(); @@ -312,15 +311,15 @@ inline int32_t Class::GetVTableLength() { GetVTable<kVerifyFlags, kReadBarrierOption>()->GetLength() : 0; } - template<VerifyObjectFlags kVerifyFlags, - ReadBarrierOption kReadBarrierOption> +template<VerifyObjectFlags kVerifyFlags, ReadBarrierOption kReadBarrierOption> inline ArtMethod* Class::GetVTableEntry(uint32_t i, PointerSize pointer_size) { if (ShouldHaveEmbeddedVTable<kVerifyFlags, kReadBarrierOption>()) { return GetEmbeddedVTableEntry(i, pointer_size); } auto* vtable = GetVTable<kVerifyFlags, kReadBarrierOption>(); DCHECK(vtable != nullptr); - return vtable->template GetElementPtrSize<ArtMethod*, kVerifyFlags, kReadBarrierOption>(i, pointer_size); + return vtable->template GetElementPtrSize<ArtMethod*, kVerifyFlags, kReadBarrierOption>( + i, pointer_size); } inline int32_t Class::GetEmbeddedVTableLength() { @@ -410,7 +409,7 @@ inline void Class::SetObjectSize(uint32_t new_object_size) { // Object[] = int[] --> false // inline bool Class::IsArrayAssignableFromArray(ObjPtr<Class> src) { - DCHECK(IsArrayClass()) << PrettyClass(); + DCHECK(IsArrayClass()) << PrettyClass(); DCHECK(src->IsArrayClass()) << src->PrettyClass(); return GetComponentType()->IsAssignableFrom(src->GetComponentType()); } @@ -622,16 +621,14 @@ inline ArtMethod* Class::FindVirtualMethodForVirtualOrInterface(ArtMethod* metho return FindVirtualMethodForVirtual(method, pointer_size); } -template<VerifyObjectFlags kVerifyFlags, - ReadBarrierOption kReadBarrierOption> +template<VerifyObjectFlags kVerifyFlags, ReadBarrierOption kReadBarrierOption> inline IfTable* Class::GetIfTable() { ObjPtr<IfTable> ret = GetFieldObject<IfTable, kVerifyFlags, kReadBarrierOption>(IfTableOffset()); DCHECK(ret != nullptr) << PrettyClass(this); return ret.Ptr(); } -template<VerifyObjectFlags kVerifyFlags, - ReadBarrierOption kReadBarrierOption> +template<VerifyObjectFlags kVerifyFlags, ReadBarrierOption kReadBarrierOption> inline int32_t Class::GetIfTableCount() { return GetIfTable<kVerifyFlags, kReadBarrierOption>()->Count(); } @@ -734,7 +731,7 @@ inline String* Class::GetName() { } inline void Class::SetName(ObjPtr<String> name) { - SetFieldObjectTransaction(OFFSET_OF_OBJECT_MEMBER(Class, name_), name); + SetFieldObjectTransaction(OFFSET_OF_OBJECT_MEMBER(Class, name_), name); } template<VerifyObjectFlags kVerifyFlags> @@ -887,8 +884,8 @@ inline bool Class::DescriptorEquals(const char* match) { inline void Class::AssertInitializedOrInitializingInThread(Thread* self) { if (kIsDebugBuild && !IsInitialized()) { CHECK(IsInitializing()) << PrettyClass() << " is not initializing: " << GetStatus(); - CHECK_EQ(GetClinitThreadId(), self->GetTid()) << PrettyClass() - << " is initializing in a different thread"; + CHECK_EQ(GetClinitThreadId(), self->GetTid()) + << PrettyClass() << " is initializing in a different thread"; } } @@ -964,18 +961,15 @@ inline ArraySlice<ArtMethod> Class::GetDirectMethods(PointerSize pointer_size) { return GetDirectMethodsSliceUnchecked(pointer_size); } -inline ArraySlice<ArtMethod> Class::GetDeclaredMethods( - PointerSize pointer_size) { +inline ArraySlice<ArtMethod> Class::GetDeclaredMethods(PointerSize pointer_size) { return GetDeclaredMethodsSliceUnchecked(pointer_size); } -inline ArraySlice<ArtMethod> Class::GetDeclaredVirtualMethods( - PointerSize pointer_size) { +inline ArraySlice<ArtMethod> Class::GetDeclaredVirtualMethods(PointerSize pointer_size) { return GetDeclaredVirtualMethodsSliceUnchecked(pointer_size); } -inline ArraySlice<ArtMethod> Class::GetVirtualMethods( - PointerSize pointer_size) { +inline ArraySlice<ArtMethod> Class::GetVirtualMethods(PointerSize pointer_size) { CheckPointerSize(pointer_size); return GetVirtualMethodsSliceUnchecked(pointer_size); } diff --git a/runtime/mirror/class.cc b/runtime/mirror/class.cc index cb2708d0cb..31a83f8e48 100644 --- a/runtime/mirror/class.cc +++ b/runtime/mirror/class.cc @@ -55,26 +55,6 @@ namespace mirror { using android::base::StringPrintf; -GcRoot<Class> Class::java_lang_Class_; - -void Class::SetClassClass(ObjPtr<Class> java_lang_Class) { - CHECK(java_lang_Class_.IsNull()) - << java_lang_Class_.Read() - << " " << java_lang_Class; - CHECK(java_lang_Class != nullptr); - java_lang_Class->SetClassFlags(kClassFlagClass); - java_lang_Class_ = GcRoot<Class>(java_lang_Class); -} - -void Class::ResetClass() { - CHECK(!java_lang_Class_.IsNull()); - java_lang_Class_ = GcRoot<Class>(nullptr); -} - -void Class::VisitRoots(RootVisitor* visitor) { - java_lang_Class_.VisitRootIfNonNull(visitor, RootInfo(kRootStickyClass)); -} - ObjPtr<mirror::Class> Class::GetPrimitiveClass(ObjPtr<mirror::String> name) { const char* expected_name = nullptr; ClassRoot class_root = ClassRoot::kJavaLangObject; // Invalid. @@ -1211,13 +1191,15 @@ Class* Class::CopyOf(Thread* self, int32_t new_length, ImTable* imt, PointerSize // We may get copied by a compacting GC. StackHandleScope<1> hs(self); Handle<Class> h_this(hs.NewHandle(this)); - gc::Heap* heap = Runtime::Current()->GetHeap(); + Runtime* runtime = Runtime::Current(); + gc::Heap* heap = runtime->GetHeap(); // The num_bytes (3rd param) is sizeof(Class) as opposed to SizeOf() // to skip copying the tail part that we will overwrite here. CopyClassVisitor visitor(self, &h_this, new_length, sizeof(Class), imt, pointer_size); + ObjPtr<mirror::Class> java_lang_Class = GetClassRoot<mirror::Class>(runtime->GetClassLinker()); ObjPtr<Object> new_class = kMovingClasses ? - heap->AllocObject<true>(self, java_lang_Class_.Read(), new_length, visitor) : - heap->AllocNonMovableObject<true>(self, java_lang_Class_.Read(), new_length, visitor); + heap->AllocObject<true>(self, java_lang_Class, new_length, visitor) : + heap->AllocNonMovableObject<true>(self, java_lang_Class, new_length, visitor); if (UNLIKELY(new_class == nullptr)) { self->AssertPendingOOMException(); return nullptr; @@ -1251,7 +1233,7 @@ ArtMethod* Class::GetDeclaredConstructor( uint32_t Class::Depth() { uint32_t depth = 0; - for (ObjPtr<Class> klass = this; klass->GetSuperClass() != nullptr; klass = klass->GetSuperClass()) { + for (ObjPtr<Class> cls = this; cls->GetSuperClass() != nullptr; cls = cls->GetSuperClass()) { depth++; } return depth; diff --git a/runtime/mirror/class.h b/runtime/mirror/class.h index 7d5f539576..6feaa9cd74 100644 --- a/runtime/mirror/class.h +++ b/runtime/mirror/class.h @@ -30,7 +30,6 @@ #include "dex/modifiers.h" #include "dex/primitive.h" #include "gc/allocator_type.h" -#include "gc_root.h" #include "imtable.h" #include "object.h" #include "object_array.h" @@ -933,12 +932,10 @@ class MANAGED Class FINAL : public Object { ArtMethod* FindConstructor(const StringPiece& signature, PointerSize pointer_size) REQUIRES_SHARED(Locks::mutator_lock_); - ArtMethod* FindDeclaredVirtualMethodByName(const StringPiece& name, - PointerSize pointer_size) + ArtMethod* FindDeclaredVirtualMethodByName(const StringPiece& name, PointerSize pointer_size) REQUIRES_SHARED(Locks::mutator_lock_); - ArtMethod* FindDeclaredDirectMethodByName(const StringPiece& name, - PointerSize pointer_size) + ArtMethod* FindDeclaredDirectMethodByName(const StringPiece& name, PointerSize pointer_size) REQUIRES_SHARED(Locks::mutator_lock_); ArtMethod* FindClassInitializer(PointerSize pointer_size) REQUIRES_SHARED(Locks::mutator_lock_); @@ -1130,21 +1127,6 @@ class MANAGED Class FINAL : public Object { dex::TypeIndex FindTypeIndexInOtherDexFile(const DexFile& dex_file) REQUIRES_SHARED(Locks::mutator_lock_); - static Class* GetJavaLangClass() REQUIRES_SHARED(Locks::mutator_lock_) { - DCHECK(HasJavaLangClass()); - return java_lang_Class_.Read(); - } - - static bool HasJavaLangClass() REQUIRES_SHARED(Locks::mutator_lock_) { - return !java_lang_Class_.IsNull(); - } - - // Can't call this SetClass or else gets called instead of Object::SetClass in places. - static void SetClassClass(ObjPtr<Class> java_lang_Class) REQUIRES_SHARED(Locks::mutator_lock_); - static void ResetClass(); - static void VisitRoots(RootVisitor* visitor) - REQUIRES_SHARED(Locks::mutator_lock_); - // Visit native roots visits roots which are keyed off the native pointers such as ArtFields and // ArtMethods. template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier, class Visitor> @@ -1197,10 +1179,7 @@ class MANAGED Class FINAL : public Object { void AssertInitializedOrInitializingInThread(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_); - Class* CopyOf(Thread* self, - int32_t new_length, - ImTable* imt, - PointerSize pointer_size) + Class* CopyOf(Thread* self, int32_t new_length, ImTable* imt, PointerSize pointer_size) REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_); // For proxy class only. @@ -1504,9 +1483,6 @@ class MANAGED Class FINAL : public Object { // Static fields, variable size. // uint32_t fields_[0]; - // java.lang.Class - static GcRoot<Class> java_lang_Class_; - ART_FRIEND_TEST(DexCacheTest, TestResolvedFieldAccess); // For ResolvedFieldAccessTest friend struct art::ClassOffsets; // for verifying offset information friend class Object; // For VisitReferences diff --git a/runtime/mirror/class_ext.cc b/runtime/mirror/class_ext.cc index 081957964c..7214620c93 100644 --- a/runtime/mirror/class_ext.cc +++ b/runtime/mirror/class_ext.cc @@ -21,6 +21,7 @@ #include "base/enums.h" #include "base/utils.h" #include "class-inl.h" +#include "class_root.h" #include "dex/dex_file-inl.h" #include "gc/accounting/card_table-inl.h" #include "object-inl.h" @@ -31,8 +32,6 @@ namespace art { namespace mirror { -GcRoot<Class> ClassExt::dalvik_system_ClassExt_; - uint32_t ClassExt::ClassSize(PointerSize pointer_size) { uint32_t vtable_entries = Object::kVTableLength; return Class::ComputeClassSize(true, vtable_entries, 0, 0, 0, 0, 0, pointer_size); @@ -102,8 +101,7 @@ bool ClassExt::ExtendObsoleteArrays(Thread* self, uint32_t increase) { } ClassExt* ClassExt::Alloc(Thread* self) { - DCHECK(dalvik_system_ClassExt_.Read() != nullptr); - return down_cast<ClassExt*>(dalvik_system_ClassExt_.Read()->AllocObject(self).Ptr()); + return down_cast<ClassExt*>(GetClassRoot<ClassExt>()->AllocObject(self).Ptr()); } void ClassExt::SetVerifyError(ObjPtr<Object> err) { @@ -119,19 +117,5 @@ void ClassExt::SetOriginalDexFile(ObjPtr<Object> bytes) { SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(ClassExt, original_dex_file_), bytes); } -void ClassExt::SetClass(ObjPtr<Class> dalvik_system_ClassExt) { - CHECK(dalvik_system_ClassExt != nullptr); - dalvik_system_ClassExt_ = GcRoot<Class>(dalvik_system_ClassExt); -} - -void ClassExt::ResetClass() { - CHECK(!dalvik_system_ClassExt_.IsNull()); - dalvik_system_ClassExt_ = GcRoot<Class>(nullptr); -} - -void ClassExt::VisitRoots(RootVisitor* visitor) { - dalvik_system_ClassExt_.VisitRootIfNonNull(visitor, RootInfo(kRootStickyClass)); -} - } // namespace mirror } // namespace art diff --git a/runtime/mirror/class_ext.h b/runtime/mirror/class_ext.h index 75a3800989..612fd0f256 100644 --- a/runtime/mirror/class_ext.h +++ b/runtime/mirror/class_ext.h @@ -20,7 +20,6 @@ #include "array.h" #include "class.h" #include "dex_cache.h" -#include "gc_root.h" #include "object.h" #include "object_array.h" #include "string.h" @@ -72,10 +71,6 @@ class MANAGED ClassExt : public Object { bool ExtendObsoleteArrays(Thread* self, uint32_t increase) REQUIRES_SHARED(Locks::mutator_lock_); - static void SetClass(ObjPtr<Class> dalvik_system_ClassExt); - static void ResetClass(); - static void VisitRoots(RootVisitor* visitor) REQUIRES_SHARED(Locks::mutator_lock_); - template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier, class Visitor> inline void VisitNativeRoots(Visitor& visitor, PointerSize pointer_size) REQUIRES_SHARED(Locks::mutator_lock_); @@ -93,8 +88,6 @@ class MANAGED ClassExt : public Object { // The saved verification error of this class. HeapReference<Object> verify_error_; - static GcRoot<Class> dalvik_system_ClassExt_; - friend struct art::ClassExtOffsets; // for verifying offset information DISALLOW_IMPLICIT_CONSTRUCTORS(ClassExt); }; diff --git a/runtime/mirror/dex_cache-inl.h b/runtime/mirror/dex_cache-inl.h index 72f1443dfa..96778aa98d 100644 --- a/runtime/mirror/dex_cache-inl.h +++ b/runtime/mirror/dex_cache-inl.h @@ -28,7 +28,7 @@ #include "class_linker.h" #include "dex/dex_file.h" #include "gc/heap-inl.h" -#include "gc_root.h" +#include "gc_root-inl.h" #include "mirror/call_site.h" #include "mirror/class.h" #include "mirror/method_type.h" diff --git a/runtime/mirror/emulated_stack_frame.cc b/runtime/mirror/emulated_stack_frame.cc index 5595102866..ce39049e11 100644 --- a/runtime/mirror/emulated_stack_frame.cc +++ b/runtime/mirror/emulated_stack_frame.cc @@ -18,7 +18,6 @@ #include "class-inl.h" #include "class_root.h" -#include "gc_root-inl.h" #include "jvalue-inl.h" #include "method_handles-inl.h" #include "method_handles.h" diff --git a/runtime/mirror/executable.h b/runtime/mirror/executable.h index 8a28f66868..23dd787c80 100644 --- a/runtime/mirror/executable.h +++ b/runtime/mirror/executable.h @@ -18,7 +18,6 @@ #define ART_RUNTIME_MIRROR_EXECUTABLE_H_ #include "accessible_object.h" -#include "gc_root.h" #include "object.h" #include "read_barrier_option.h" diff --git a/runtime/mirror/method.cc b/runtime/mirror/method.cc index e5d3403107..cf03b95d5e 100644 --- a/runtime/mirror/method.cc +++ b/runtime/mirror/method.cc @@ -18,7 +18,6 @@ #include "art_method.h" #include "class_root.h" -#include "gc_root-inl.h" #include "mirror/class-inl.h" #include "mirror/object-inl.h" diff --git a/runtime/mirror/method_handle_impl.cc b/runtime/mirror/method_handle_impl.cc index a6c1609d01..88ccbc947d 100644 --- a/runtime/mirror/method_handle_impl.cc +++ b/runtime/mirror/method_handle_impl.cc @@ -18,7 +18,6 @@ #include "class-inl.h" #include "class_root.h" -#include "gc_root-inl.h" namespace art { namespace mirror { diff --git a/runtime/mirror/method_handles_lookup.cc b/runtime/mirror/method_handles_lookup.cc index 1ac38dad24..d1e7a6dbfa 100644 --- a/runtime/mirror/method_handles_lookup.cc +++ b/runtime/mirror/method_handles_lookup.cc @@ -19,7 +19,6 @@ #include "class-inl.h" #include "class_root.h" #include "dex/modifiers.h" -#include "gc_root-inl.h" #include "handle_scope.h" #include "jni/jni_internal.h" #include "mirror/method_handle_impl.h" diff --git a/runtime/mirror/method_handles_lookup.h b/runtime/mirror/method_handles_lookup.h index aa94f95ae0..56261eca67 100644 --- a/runtime/mirror/method_handles_lookup.h +++ b/runtime/mirror/method_handles_lookup.h @@ -18,7 +18,6 @@ #define ART_RUNTIME_MIRROR_METHOD_HANDLES_LOOKUP_H_ #include "base/utils.h" -#include "gc_root.h" #include "handle.h" #include "obj_ptr.h" #include "object.h" diff --git a/runtime/mirror/method_type.cc b/runtime/mirror/method_type.cc index a8be8b7019..bc62ebdc8b 100644 --- a/runtime/mirror/method_type.cc +++ b/runtime/mirror/method_type.cc @@ -18,7 +18,6 @@ #include "class-inl.h" #include "class_root.h" -#include "gc_root-inl.h" #include "method_handles.h" namespace art { @@ -28,9 +27,7 @@ namespace { ObjPtr<ObjectArray<Class>> AllocatePTypesArray(Thread* self, int count) REQUIRES_SHARED(Locks::mutator_lock_) { - ObjPtr<Class> class_type = Class::GetJavaLangClass(); - ObjPtr<Class> class_array_type = - Runtime::Current()->GetClassLinker()->FindArrayClass(self, &class_type); + ObjPtr<Class> class_array_type = GetClassRoot<mirror::ObjectArray<mirror::Class>>(); return ObjectArray<Class>::Alloc(self, class_array_type, count); } diff --git a/runtime/mirror/method_type_test.cc b/runtime/mirror/method_type_test.cc index 16bfc73e04..2bdea72f14 100644 --- a/runtime/mirror/method_type_test.cc +++ b/runtime/mirror/method_type_test.cc @@ -22,6 +22,7 @@ #include "class-inl.h" #include "class_linker-inl.h" #include "class_loader.h" +#include "class_root.h" #include "common_runtime_test.h" #include "handle_scope-inl.h" #include "object_array-inl.h" @@ -53,8 +54,8 @@ static mirror::MethodType* CreateMethodType(const std::string& return_type, soa.Self(), FullyQualifiedType(return_type).c_str(), boot_class_loader)); CHECK(return_clazz != nullptr); - ObjPtr<mirror::Class> class_type = mirror::Class::GetJavaLangClass(); - ObjPtr<mirror::Class> class_array_type = class_linker->FindArrayClass(self, &class_type); + ObjPtr<mirror::Class> class_array_type = + GetClassRoot<mirror::ObjectArray<mirror::Class>>(class_linker); Handle<mirror::ObjectArray<mirror::Class>> param_classes = hs.NewHandle( mirror::ObjectArray<mirror::Class>::Alloc(self, class_array_type, param_types.size())); diff --git a/runtime/mirror/object-inl.h b/runtime/mirror/object-inl.h index bfebd5d365..cd822c244e 100644 --- a/runtime/mirror/object-inl.h +++ b/runtime/mirror/object-inl.h @@ -412,17 +412,21 @@ inline int8_t Object::GetFieldByteVolatile(MemberOffset field_offset) { return GetFieldByte<kVerifyFlags, true>(field_offset); } -template<bool kTransactionActive, bool kCheckTransaction, VerifyObjectFlags kVerifyFlags, - bool kIsVolatile> +template<bool kTransactionActive, + bool kCheckTransaction, + VerifyObjectFlags kVerifyFlags, + bool kIsVolatile> inline void Object::SetFieldBoolean(MemberOffset field_offset, uint8_t new_value) REQUIRES_SHARED(Locks::mutator_lock_) { if (kCheckTransaction) { DCHECK_EQ(kTransactionActive, Runtime::Current()->IsActiveTransaction()); } if (kTransactionActive) { - Runtime::Current()->RecordWriteFieldBoolean(this, field_offset, - GetFieldBoolean<kVerifyFlags, kIsVolatile>(field_offset), - kIsVolatile); + Runtime::Current()->RecordWriteFieldBoolean( + this, + field_offset, + GetFieldBoolean<kVerifyFlags, kIsVolatile>(field_offset), + kIsVolatile); } if (kVerifyFlags & kVerifyThis) { VerifyObject(this); @@ -430,17 +434,20 @@ inline void Object::SetFieldBoolean(MemberOffset field_offset, uint8_t new_value SetField<uint8_t, kIsVolatile>(field_offset, new_value); } -template<bool kTransactionActive, bool kCheckTransaction, VerifyObjectFlags kVerifyFlags, - bool kIsVolatile> +template<bool kTransactionActive, + bool kCheckTransaction, + VerifyObjectFlags kVerifyFlags, + bool kIsVolatile> inline void Object::SetFieldByte(MemberOffset field_offset, int8_t new_value) REQUIRES_SHARED(Locks::mutator_lock_) { if (kCheckTransaction) { DCHECK_EQ(kTransactionActive, Runtime::Current()->IsActiveTransaction()); } if (kTransactionActive) { - Runtime::Current()->RecordWriteFieldByte(this, field_offset, - GetFieldByte<kVerifyFlags, kIsVolatile>(field_offset), - kIsVolatile); + Runtime::Current()->RecordWriteFieldByte(this, + field_offset, + GetFieldByte<kVerifyFlags, kIsVolatile>(field_offset), + kIsVolatile); } if (kVerifyFlags & kVerifyThis) { VerifyObject(this); @@ -486,16 +493,19 @@ inline int16_t Object::GetFieldShortVolatile(MemberOffset field_offset) { return GetFieldShort<kVerifyFlags, true>(field_offset); } -template<bool kTransactionActive, bool kCheckTransaction, VerifyObjectFlags kVerifyFlags, - bool kIsVolatile> +template<bool kTransactionActive, + bool kCheckTransaction, + VerifyObjectFlags kVerifyFlags, + bool kIsVolatile> inline void Object::SetFieldChar(MemberOffset field_offset, uint16_t new_value) { if (kCheckTransaction) { DCHECK_EQ(kTransactionActive, Runtime::Current()->IsActiveTransaction()); } if (kTransactionActive) { - Runtime::Current()->RecordWriteFieldChar(this, field_offset, - GetFieldChar<kVerifyFlags, kIsVolatile>(field_offset), - kIsVolatile); + Runtime::Current()->RecordWriteFieldChar(this, + field_offset, + GetFieldChar<kVerifyFlags, kIsVolatile>(field_offset), + kIsVolatile); } if (kVerifyFlags & kVerifyThis) { VerifyObject(this); @@ -503,16 +513,19 @@ inline void Object::SetFieldChar(MemberOffset field_offset, uint16_t new_value) SetField<uint16_t, kIsVolatile>(field_offset, new_value); } -template<bool kTransactionActive, bool kCheckTransaction, VerifyObjectFlags kVerifyFlags, - bool kIsVolatile> +template<bool kTransactionActive, + bool kCheckTransaction, + VerifyObjectFlags kVerifyFlags, + bool kIsVolatile> inline void Object::SetFieldShort(MemberOffset field_offset, int16_t new_value) { if (kCheckTransaction) { DCHECK_EQ(kTransactionActive, Runtime::Current()->IsActiveTransaction()); } if (kTransactionActive) { - Runtime::Current()->RecordWriteFieldChar(this, field_offset, - GetFieldShort<kVerifyFlags, kIsVolatile>(field_offset), - kIsVolatile); + Runtime::Current()->RecordWriteFieldChar(this, + field_offset, + GetFieldShort<kVerifyFlags, kIsVolatile>(field_offset), + kIsVolatile); } if (kVerifyFlags & kVerifyThis) { VerifyObject(this); @@ -532,14 +545,17 @@ inline void Object::SetFieldShortVolatile(MemberOffset field_offset, int16_t new field_offset, new_value); } -template<bool kTransactionActive, bool kCheckTransaction, VerifyObjectFlags kVerifyFlags, - bool kIsVolatile> +template<bool kTransactionActive, + bool kCheckTransaction, + VerifyObjectFlags kVerifyFlags, + bool kIsVolatile> inline void Object::SetField32(MemberOffset field_offset, int32_t new_value) { if (kCheckTransaction) { DCHECK_EQ(kTransactionActive, Runtime::Current()->IsActiveTransaction()); } if (kTransactionActive) { - Runtime::Current()->RecordWriteField32(this, field_offset, + Runtime::Current()->RecordWriteField32(this, + field_offset, GetField32<kVerifyFlags, kIsVolatile>(field_offset), kIsVolatile); } @@ -567,7 +583,8 @@ inline void Object::SetField32Transaction(MemberOffset field_offset, int32_t new template<bool kTransactionActive, bool kCheckTransaction, VerifyObjectFlags kVerifyFlags> inline bool Object::CasFieldWeakSequentiallyConsistent32(MemberOffset field_offset, - int32_t old_value, int32_t new_value) { + int32_t old_value, + int32_t new_value) { if (kCheckTransaction) { DCHECK_EQ(kTransactionActive, Runtime::Current()->IsActiveTransaction()); } @@ -585,7 +602,8 @@ inline bool Object::CasFieldWeakSequentiallyConsistent32(MemberOffset field_offs template<bool kTransactionActive, bool kCheckTransaction, VerifyObjectFlags kVerifyFlags> inline bool Object::CasFieldWeakAcquire32(MemberOffset field_offset, - int32_t old_value, int32_t new_value) { + int32_t old_value, + int32_t new_value) { if (kCheckTransaction) { DCHECK_EQ(kTransactionActive, Runtime::Current()->IsActiveTransaction()); } @@ -603,7 +621,8 @@ inline bool Object::CasFieldWeakAcquire32(MemberOffset field_offset, template<bool kTransactionActive, bool kCheckTransaction, VerifyObjectFlags kVerifyFlags> inline bool Object::CasFieldWeakRelease32(MemberOffset field_offset, - int32_t old_value, int32_t new_value) { + int32_t old_value, + int32_t new_value) { if (kCheckTransaction) { DCHECK_EQ(kTransactionActive, Runtime::Current()->IsActiveTransaction()); } @@ -621,7 +640,8 @@ inline bool Object::CasFieldWeakRelease32(MemberOffset field_offset, template<bool kTransactionActive, bool kCheckTransaction, VerifyObjectFlags kVerifyFlags> inline bool Object::CasFieldStrongSequentiallyConsistent32(MemberOffset field_offset, - int32_t old_value, int32_t new_value) { + int32_t old_value, + int32_t new_value) { if (kCheckTransaction) { DCHECK_EQ(kTransactionActive, Runtime::Current()->IsActiveTransaction()); } @@ -637,14 +657,17 @@ inline bool Object::CasFieldStrongSequentiallyConsistent32(MemberOffset field_of return atomic_addr->CompareAndSetStrongSequentiallyConsistent(old_value, new_value); } -template<bool kTransactionActive, bool kCheckTransaction, VerifyObjectFlags kVerifyFlags, - bool kIsVolatile> +template<bool kTransactionActive, + bool kCheckTransaction, + VerifyObjectFlags kVerifyFlags, + bool kIsVolatile> inline void Object::SetField64(MemberOffset field_offset, int64_t new_value) { if (kCheckTransaction) { DCHECK_EQ(kTransactionActive, Runtime::Current()->IsActiveTransaction()); } if (kTransactionActive) { - Runtime::Current()->RecordWriteField64(this, field_offset, + Runtime::Current()->RecordWriteField64(this, + field_offset, GetField64<kVerifyFlags, kIsVolatile>(field_offset), kIsVolatile); } @@ -678,7 +701,8 @@ inline kSize Object::GetFieldAcquire(MemberOffset field_offset) { template<bool kTransactionActive, bool kCheckTransaction, VerifyObjectFlags kVerifyFlags> inline bool Object::CasFieldWeakSequentiallyConsistent64(MemberOffset field_offset, - int64_t old_value, int64_t new_value) { + int64_t old_value, + int64_t new_value) { if (kCheckTransaction) { DCHECK_EQ(kTransactionActive, Runtime::Current()->IsActiveTransaction()); } @@ -695,7 +719,8 @@ inline bool Object::CasFieldWeakSequentiallyConsistent64(MemberOffset field_offs template<bool kTransactionActive, bool kCheckTransaction, VerifyObjectFlags kVerifyFlags> inline bool Object::CasFieldStrongSequentiallyConsistent64(MemberOffset field_offset, - int64_t old_value, int64_t new_value) { + int64_t old_value, + int64_t new_value) { if (kCheckTransaction) { DCHECK_EQ(kTransactionActive, Runtime::Current()->IsActiveTransaction()); } @@ -710,7 +735,9 @@ inline bool Object::CasFieldStrongSequentiallyConsistent64(MemberOffset field_of return atomic_addr->CompareAndSetStrongSequentiallyConsistent(old_value, new_value); } -template<class T, VerifyObjectFlags kVerifyFlags, ReadBarrierOption kReadBarrierOption, +template<class T, + VerifyObjectFlags kVerifyFlags, + ReadBarrierOption kReadBarrierOption, bool kIsVolatile> inline T* Object::GetFieldObject(MemberOffset field_offset) { if (kVerifyFlags & kVerifyThis) { @@ -733,8 +760,10 @@ inline T* Object::GetFieldObjectVolatile(MemberOffset field_offset) { return GetFieldObject<T, kVerifyFlags, kReadBarrierOption, true>(field_offset); } -template<bool kTransactionActive, bool kCheckTransaction, VerifyObjectFlags kVerifyFlags, - bool kIsVolatile> +template<bool kTransactionActive, + bool kCheckTransaction, + VerifyObjectFlags kVerifyFlags, + bool kIsVolatile> inline void Object::SetFieldObjectWithoutWriteBarrier(MemberOffset field_offset, ObjPtr<Object> new_value) { if (kCheckTransaction) { @@ -760,8 +789,10 @@ inline void Object::SetFieldObjectWithoutWriteBarrier(MemberOffset field_offset, objref_addr->Assign<kIsVolatile>(new_value.Ptr()); } -template<bool kTransactionActive, bool kCheckTransaction, VerifyObjectFlags kVerifyFlags, - bool kIsVolatile> +template<bool kTransactionActive, + bool kCheckTransaction, + VerifyObjectFlags kVerifyFlags, + bool kIsVolatile> inline void Object::SetFieldObject(MemberOffset field_offset, ObjPtr<Object> new_value) { SetFieldObjectWithoutWriteBarrier<kTransactionActive, kCheckTransaction, kVerifyFlags, kIsVolatile>(field_offset, new_value); diff --git a/runtime/mirror/object.cc b/runtime/mirror/object.cc index 0e03e3741c..4240e702b5 100644 --- a/runtime/mirror/object.cc +++ b/runtime/mirror/object.cc @@ -271,7 +271,7 @@ void Object::CheckFieldAssignmentImpl(MemberOffset field_offset, ObjPtr<Object> } } LOG(FATAL) << "Failed to find field for assignment to " << reinterpret_cast<void*>(this) - << " of type " << c->PrettyDescriptor() << " at offset " << field_offset; + << " of type " << c->PrettyDescriptor() << " at offset " << field_offset; UNREACHABLE(); } diff --git a/runtime/mirror/object.h b/runtime/mirror/object.h index 82045c7b66..8584b8a56f 100644 --- a/runtime/mirror/object.h +++ b/runtime/mirror/object.h @@ -282,13 +282,16 @@ class MANAGED LOCKABLE Object { bool IsPhantomReferenceInstance() REQUIRES_SHARED(Locks::mutator_lock_); // Accessor for Java type fields. - template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, - ReadBarrierOption kReadBarrierOption = kWithReadBarrier, bool kIsVolatile = false> + template<class T, + VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, + ReadBarrierOption kReadBarrierOption = kWithReadBarrier, + bool kIsVolatile = false> ALWAYS_INLINE T* GetFieldObject(MemberOffset field_offset) REQUIRES_SHARED(Locks::mutator_lock_); - template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, - ReadBarrierOption kReadBarrierOption = kWithReadBarrier> + template<class T, + VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, + ReadBarrierOption kReadBarrierOption = kWithReadBarrier> ALWAYS_INLINE T* GetFieldObjectVolatile(MemberOffset field_offset) REQUIRES_SHARED(Locks::mutator_lock_); @@ -310,11 +313,11 @@ class MANAGED LOCKABLE Object { template<bool kTransactionActive, bool kCheckTransaction = true, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> - ALWAYS_INLINE void SetFieldObjectVolatile(MemberOffset field_offset, - ObjPtr<Object> new_value) + ALWAYS_INLINE void SetFieldObjectVolatile(MemberOffset field_offset, ObjPtr<Object> new_value) REQUIRES_SHARED(Locks::mutator_lock_); - template<bool kCheckTransaction = true, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, + template<bool kCheckTransaction = true, + VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false> ALWAYS_INLINE void SetFieldObjectTransaction(MemberOffset field_offset, ObjPtr<Object> new_value) REQUIRES_SHARED(Locks::mutator_lock_); @@ -416,23 +419,29 @@ class MANAGED LOCKABLE Object { ALWAYS_INLINE int8_t GetFieldByteVolatile(MemberOffset field_offset) REQUIRES_SHARED(Locks::mutator_lock_); - template<bool kTransactionActive, bool kCheckTransaction = true, - VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false> + template<bool kTransactionActive, + bool kCheckTransaction = true, + VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, + bool kIsVolatile = false> ALWAYS_INLINE void SetFieldBoolean(MemberOffset field_offset, uint8_t new_value) REQUIRES_SHARED(Locks::mutator_lock_); - template<bool kTransactionActive, bool kCheckTransaction = true, - VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false> + template<bool kTransactionActive, + bool kCheckTransaction = true, + VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, + bool kIsVolatile = false> ALWAYS_INLINE void SetFieldByte(MemberOffset field_offset, int8_t new_value) REQUIRES_SHARED(Locks::mutator_lock_); - template<bool kTransactionActive, bool kCheckTransaction = true, - VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> + template<bool kTransactionActive, + bool kCheckTransaction = true, + VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> ALWAYS_INLINE void SetFieldBooleanVolatile(MemberOffset field_offset, uint8_t new_value) REQUIRES_SHARED(Locks::mutator_lock_); - template<bool kTransactionActive, bool kCheckTransaction = true, - VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> + template<bool kTransactionActive, + bool kCheckTransaction = true, + VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> ALWAYS_INLINE void SetFieldByteVolatile(MemberOffset field_offset, int8_t new_value) REQUIRES_SHARED(Locks::mutator_lock_); @@ -452,23 +461,29 @@ class MANAGED LOCKABLE Object { ALWAYS_INLINE int16_t GetFieldShortVolatile(MemberOffset field_offset) REQUIRES_SHARED(Locks::mutator_lock_); - template<bool kTransactionActive, bool kCheckTransaction = true, - VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false> + template<bool kTransactionActive, + bool kCheckTransaction = true, + VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, + bool kIsVolatile = false> ALWAYS_INLINE void SetFieldChar(MemberOffset field_offset, uint16_t new_value) REQUIRES_SHARED(Locks::mutator_lock_); - template<bool kTransactionActive, bool kCheckTransaction = true, - VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false> + template<bool kTransactionActive, + bool kCheckTransaction = true, + VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, + bool kIsVolatile = false> ALWAYS_INLINE void SetFieldShort(MemberOffset field_offset, int16_t new_value) REQUIRES_SHARED(Locks::mutator_lock_); - template<bool kTransactionActive, bool kCheckTransaction = true, - VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> + template<bool kTransactionActive, + bool kCheckTransaction = true, + VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> ALWAYS_INLINE void SetFieldCharVolatile(MemberOffset field_offset, uint16_t new_value) REQUIRES_SHARED(Locks::mutator_lock_); - template<bool kTransactionActive, bool kCheckTransaction = true, - VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> + template<bool kTransactionActive, + bool kCheckTransaction = true, + VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> ALWAYS_INLINE void SetFieldShortVolatile(MemberOffset field_offset, int16_t new_value) REQUIRES_SHARED(Locks::mutator_lock_); @@ -487,13 +502,16 @@ class MANAGED LOCKABLE Object { return GetField32<kVerifyFlags, true>(field_offset); } - template<bool kTransactionActive, bool kCheckTransaction = true, - VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false> + template<bool kTransactionActive, + bool kCheckTransaction = true, + VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, + bool kIsVolatile = false> ALWAYS_INLINE void SetField32(MemberOffset field_offset, int32_t new_value) REQUIRES_SHARED(Locks::mutator_lock_); - template<bool kTransactionActive, bool kCheckTransaction = true, - VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> + template<bool kTransactionActive, + bool kCheckTransaction = true, + VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> ALWAYS_INLINE void SetField32Volatile(MemberOffset field_offset, int32_t new_value) REQUIRES_SHARED(Locks::mutator_lock_); @@ -503,34 +521,44 @@ class MANAGED LOCKABLE Object { ALWAYS_INLINE void SetField32Transaction(MemberOffset field_offset, int32_t new_value) REQUIRES_SHARED(Locks::mutator_lock_); - template<bool kTransactionActive, bool kCheckTransaction = true, - VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> + template<bool kTransactionActive, + bool kCheckTransaction = true, + VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> ALWAYS_INLINE bool CasFieldWeakSequentiallyConsistent32(MemberOffset field_offset, - int32_t old_value, int32_t new_value) + int32_t old_value, + int32_t new_value) REQUIRES_SHARED(Locks::mutator_lock_); - template<bool kTransactionActive, bool kCheckTransaction = true, - VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> - bool CasFieldWeakRelaxed32(MemberOffset field_offset, int32_t old_value, - int32_t new_value) ALWAYS_INLINE + template<bool kTransactionActive, + bool kCheckTransaction = true, + VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> + ALWAYS_INLINE bool CasFieldWeakRelaxed32(MemberOffset field_offset, + int32_t old_value, + int32_t new_value) REQUIRES_SHARED(Locks::mutator_lock_); - template<bool kTransactionActive, bool kCheckTransaction = true, - VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> - bool CasFieldWeakAcquire32(MemberOffset field_offset, int32_t old_value, - int32_t new_value) ALWAYS_INLINE + template<bool kTransactionActive, + bool kCheckTransaction = true, + VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> + ALWAYS_INLINE bool CasFieldWeakAcquire32(MemberOffset field_offset, + int32_t old_value, + int32_t new_value) REQUIRES_SHARED(Locks::mutator_lock_); - template<bool kTransactionActive, bool kCheckTransaction = true, - VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> - bool CasFieldWeakRelease32(MemberOffset field_offset, int32_t old_value, - int32_t new_value) ALWAYS_INLINE + template<bool kTransactionActive, + bool kCheckTransaction = true, + VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> + ALWAYS_INLINE bool CasFieldWeakRelease32(MemberOffset field_offset, + int32_t old_value, + int32_t new_value) REQUIRES_SHARED(Locks::mutator_lock_); - template<bool kTransactionActive, bool kCheckTransaction = true, - VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> - bool CasFieldStrongSequentiallyConsistent32(MemberOffset field_offset, int32_t old_value, - int32_t new_value) ALWAYS_INLINE + template<bool kTransactionActive, + bool kCheckTransaction = true, + VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> + ALWAYS_INLINE bool CasFieldStrongSequentiallyConsistent32(MemberOffset field_offset, + int32_t old_value, + int32_t new_value) REQUIRES_SHARED(Locks::mutator_lock_); template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false> @@ -548,13 +576,16 @@ class MANAGED LOCKABLE Object { return GetField64<kVerifyFlags, true>(field_offset); } - template<bool kTransactionActive, bool kCheckTransaction = true, - VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false> + template<bool kTransactionActive, + bool kCheckTransaction = true, + VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, + bool kIsVolatile = false> ALWAYS_INLINE void SetField64(MemberOffset field_offset, int64_t new_value) REQUIRES_SHARED(Locks::mutator_lock_); - template<bool kTransactionActive, bool kCheckTransaction = true, - VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> + template<bool kTransactionActive, + bool kCheckTransaction = true, + VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> ALWAYS_INLINE void SetField64Volatile(MemberOffset field_offset, int64_t new_value) REQUIRES_SHARED(Locks::mutator_lock_); @@ -564,35 +595,45 @@ class MANAGED LOCKABLE Object { ALWAYS_INLINE void SetField64Transaction(MemberOffset field_offset, int32_t new_value) REQUIRES_SHARED(Locks::mutator_lock_); - template<bool kTransactionActive, bool kCheckTransaction = true, - VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> - bool CasFieldWeakSequentiallyConsistent64(MemberOffset field_offset, int64_t old_value, + template<bool kTransactionActive, + bool kCheckTransaction = true, + VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> + bool CasFieldWeakSequentiallyConsistent64(MemberOffset field_offset, + int64_t old_value, int64_t new_value) REQUIRES_SHARED(Locks::mutator_lock_); - template<bool kTransactionActive, bool kCheckTransaction = true, - VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> - bool CasFieldStrongSequentiallyConsistent64(MemberOffset field_offset, int64_t old_value, + template<bool kTransactionActive, + bool kCheckTransaction = true, + VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> + bool CasFieldStrongSequentiallyConsistent64(MemberOffset field_offset, + int64_t old_value, int64_t new_value) REQUIRES_SHARED(Locks::mutator_lock_); - template<bool kTransactionActive, bool kCheckTransaction = true, - VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, typename T> + template<bool kTransactionActive, + bool kCheckTransaction = true, + VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, + typename T> void SetFieldPtr(MemberOffset field_offset, T new_value) REQUIRES_SHARED(Locks::mutator_lock_) { SetFieldPtrWithSize<kTransactionActive, kCheckTransaction, kVerifyFlags>( field_offset, new_value, kRuntimePointerSize); } - template<bool kTransactionActive, bool kCheckTransaction = true, - VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, typename T> + template<bool kTransactionActive, + bool kCheckTransaction = true, + VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, + typename T> void SetFieldPtr64(MemberOffset field_offset, T new_value) REQUIRES_SHARED(Locks::mutator_lock_) { SetFieldPtrWithSize<kTransactionActive, kCheckTransaction, kVerifyFlags>( field_offset, new_value, 8u); } - template<bool kTransactionActive, bool kCheckTransaction = true, - VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, typename T> + template<bool kTransactionActive, + bool kCheckTransaction = true, + VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, + typename T> ALWAYS_INLINE void SetFieldPtrWithSize(MemberOffset field_offset, T new_value, PointerSize pointer_size) @@ -628,28 +669,34 @@ class MANAGED LOCKABLE Object { // Update methods that expose the raw address of a primitive value-type to an Accessor instance // that will attempt to update the field. These are used by VarHandle accessor methods to // atomically update fields with a wider range of memory orderings than usually required. - template<bool kTransactionActive, bool kCheckTransaction = true, - VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> + template<bool kTransactionActive, + bool kCheckTransaction = true, + VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> void UpdateFieldBooleanViaAccessor(MemberOffset field_offset, Accessor<uint8_t>* accessor) REQUIRES_SHARED(Locks::mutator_lock_); - template<bool kTransactionActive, bool kCheckTransaction = true, - VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> + template<bool kTransactionActive, + bool kCheckTransaction = true, + VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> void UpdateFieldByteViaAccessor(MemberOffset field_offset, Accessor<int8_t>* accessor) REQUIRES_SHARED(Locks::mutator_lock_); - template<bool kTransactionActive, bool kCheckTransaction = true, - VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> + template<bool kTransactionActive, + bool kCheckTransaction = true, + VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> void UpdateFieldCharViaAccessor(MemberOffset field_offset, Accessor<uint16_t>* accessor) REQUIRES_SHARED(Locks::mutator_lock_); - template<bool kTransactionActive, bool kCheckTransaction = true, - VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> + template<bool kTransactionActive, + bool kCheckTransaction = true, + VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> void UpdateFieldShortViaAccessor(MemberOffset field_offset, Accessor<int16_t>* accessor) REQUIRES_SHARED(Locks::mutator_lock_); - template<bool kTransactionActive, bool kCheckTransaction = true, - VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> + template<bool kTransactionActive, + bool kCheckTransaction = true, + VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> void UpdateField32ViaAccessor(MemberOffset field_offset, Accessor<int32_t>* accessor) REQUIRES_SHARED(Locks::mutator_lock_); - template<bool kTransactionActive, bool kCheckTransaction = true, - VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> + template<bool kTransactionActive, + bool kCheckTransaction = true, + VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> void UpdateField64ViaAccessor(MemberOffset field_offset, Accessor<int64_t>* accessor) REQUIRES_SHARED(Locks::mutator_lock_); diff --git a/runtime/mirror/reference-inl.h b/runtime/mirror/reference-inl.h index c65f740a78..f8de6e6d90 100644 --- a/runtime/mirror/reference-inl.h +++ b/runtime/mirror/reference-inl.h @@ -19,7 +19,6 @@ #include "reference.h" -#include "gc_root-inl.h" #include "obj_ptr-inl.h" #include "runtime.h" diff --git a/runtime/mirror/stack_trace_element.cc b/runtime/mirror/stack_trace_element.cc index ff353d8939..5a7575a027 100644 --- a/runtime/mirror/stack_trace_element.cc +++ b/runtime/mirror/stack_trace_element.cc @@ -20,7 +20,6 @@ #include "class.h" #include "class_root.h" #include "gc/accounting/card_table-inl.h" -#include "gc_root-inl.h" #include "handle_scope-inl.h" #include "object-inl.h" #include "string.h" diff --git a/runtime/mirror/stack_trace_element.h b/runtime/mirror/stack_trace_element.h index f25211c397..55a2ef0b49 100644 --- a/runtime/mirror/stack_trace_element.h +++ b/runtime/mirror/stack_trace_element.h @@ -17,7 +17,6 @@ #ifndef ART_RUNTIME_MIRROR_STACK_TRACE_ELEMENT_H_ #define ART_RUNTIME_MIRROR_STACK_TRACE_ELEMENT_H_ -#include "gc_root.h" #include "object.h" namespace art { diff --git a/runtime/mirror/string.cc b/runtime/mirror/string.cc index b76ca1968a..d5ef039273 100644 --- a/runtime/mirror/string.cc +++ b/runtime/mirror/string.cc @@ -24,7 +24,6 @@ #include "dex/descriptors_names.h" #include "dex/utf-inl.h" #include "gc/accounting/card_table-inl.h" -#include "gc_root-inl.h" #include "handle_scope-inl.h" #include "intern_table.h" #include "object-inl.h" diff --git a/runtime/mirror/string.h b/runtime/mirror/string.h index 598175b749..0e2fc903b5 100644 --- a/runtime/mirror/string.h +++ b/runtime/mirror/string.h @@ -20,7 +20,6 @@ #include "base/bit_utils.h" #include "base/globals.h" #include "gc/allocator_type.h" -#include "gc_root-inl.h" #include "class.h" #include "object.h" diff --git a/runtime/mirror/throwable.h b/runtime/mirror/throwable.h index 42c612f8b6..a9e5d1a30b 100644 --- a/runtime/mirror/throwable.h +++ b/runtime/mirror/throwable.h @@ -17,7 +17,6 @@ #ifndef ART_RUNTIME_MIRROR_THROWABLE_H_ #define ART_RUNTIME_MIRROR_THROWABLE_H_ -#include "gc_root.h" #include "object.h" namespace art { diff --git a/runtime/mirror/var_handle.cc b/runtime/mirror/var_handle.cc index 8311d911cc..4319c5df25 100644 --- a/runtime/mirror/var_handle.cc +++ b/runtime/mirror/var_handle.cc @@ -21,12 +21,12 @@ #include "class-inl.h" #include "class_linker.h" #include "class_root.h" -#include "gc_root-inl.h" #include "intrinsics_enum.h" #include "jni/jni_internal.h" #include "jvalue-inl.h" #include "method_handles-inl.h" #include "method_type.h" +#include "obj_ptr-inl.h" #include "well_known_classes.h" namespace art { @@ -266,31 +266,22 @@ int32_t BuildParameterArray(ObjPtr<Class> (¶meters)[VarHandle::kMaxAccessorP // Returns the return type associated with an AccessModeTemplate based // on the template and the variable type specified. -Class* GetReturnType(AccessModeTemplate access_mode_template, ObjPtr<Class> varType) +static ObjPtr<Class> GetReturnType(AccessModeTemplate access_mode_template, ObjPtr<Class> varType) REQUIRES_SHARED(Locks::mutator_lock_) { DCHECK(varType != nullptr); switch (access_mode_template) { case AccessModeTemplate::kCompareAndSet: - return Runtime::Current()->GetClassLinker()->FindPrimitiveClass('Z'); + return GetClassRoot(ClassRoot::kPrimitiveBoolean); case AccessModeTemplate::kCompareAndExchange: case AccessModeTemplate::kGet: case AccessModeTemplate::kGetAndUpdate: - return varType.Ptr(); + return varType; case AccessModeTemplate::kSet: - return Runtime::Current()->GetClassLinker()->FindPrimitiveClass('V'); + return GetClassRoot(ClassRoot::kPrimitiveVoid); } return nullptr; } -ObjectArray<Class>* NewArrayOfClasses(Thread* self, int count) - REQUIRES_SHARED(Locks::mutator_lock_) { - Runtime* const runtime = Runtime::Current(); - ClassLinker* const class_linker = runtime->GetClassLinker(); - ObjPtr<mirror::Class> class_type = mirror::Class::GetJavaLangClass(); - ObjPtr<mirror::Class> array_of_class = class_linker->FindArrayClass(self, &class_type); - return ObjectArray<Class>::Alloc(Thread::Current(), array_of_class, count); -} - // Method to insert a read barrier for accessors to reference fields. inline void ReadBarrierForVarHandleAccess(ObjPtr<Object> obj, MemberOffset field_offset) REQUIRES_SHARED(Locks::mutator_lock_) { @@ -1410,15 +1401,15 @@ class ByteArrayViewAccessor { } // namespace -Class* VarHandle::GetVarType() { +ObjPtr<Class> VarHandle::GetVarType() { return GetFieldObject<Class>(VarTypeOffset()); } -Class* VarHandle::GetCoordinateType0() { +ObjPtr<Class> VarHandle::GetCoordinateType0() { return GetFieldObject<Class>(CoordinateType0Offset()); } -Class* VarHandle::GetCoordinateType1() { +ObjPtr<Class> VarHandle::GetCoordinateType1() { return GetFieldObject<Class>(CoordinateType1Offset()); } @@ -1438,7 +1429,7 @@ VarHandle::MatchKind VarHandle::GetMethodTypeMatchForAccessMode(AccessMode acces // Check return type first. If the return type of the method // of the VarHandle is immaterial. if (mt_rtype->GetPrimitiveType() != Primitive::Type::kPrimVoid) { - ObjPtr<Class> vh_rtype = GetReturnType(access_mode_template, var_type.Ptr()); + ObjPtr<Class> vh_rtype = GetReturnType(access_mode_template, var_type); if (vh_rtype != mt_rtype) { if (!IsReturnTypeConvertible(vh_rtype, mt_rtype)) { return MatchKind::kNone; @@ -1513,9 +1504,9 @@ bool VarHandle::IsInvokerMethodTypeCompatible(AccessMode access_mode, return true; } -MethodType* VarHandle::GetMethodTypeForAccessMode(Thread* self, - ObjPtr<VarHandle> var_handle, - AccessMode access_mode) { +ObjPtr<MethodType> VarHandle::GetMethodTypeForAccessMode(Thread* self, + ObjPtr<VarHandle> var_handle, + AccessMode access_mode) { // This is a static method as the var_handle might be moved by the GC during it's execution. AccessModeTemplate access_mode_template = GetAccessModeTemplate(access_mode); @@ -1525,7 +1516,9 @@ MethodType* VarHandle::GetMethodTypeForAccessMode(Thread* self, const int32_t ptypes_count = GetNumberOfParameters(access_mode_template, vh->GetCoordinateType0(), vh->GetCoordinateType1()); - Handle<ObjectArray<Class>> ptypes = hs.NewHandle(NewArrayOfClasses(self, ptypes_count)); + ObjPtr<Class> array_of_class = GetClassRoot<ObjectArray<Class>>(); + Handle<ObjectArray<Class>> ptypes = + hs.NewHandle(ObjectArray<Class>::Alloc(Thread::Current(), array_of_class, ptypes_count)); if (ptypes == nullptr) { return nullptr; } @@ -1537,12 +1530,12 @@ MethodType* VarHandle::GetMethodTypeForAccessMode(Thread* self, vh->GetCoordinateType0(), vh->GetCoordinateType1()); for (int32_t i = 0; i < ptypes_count; ++i) { - ptypes->Set(i, ptypes_array[i].Ptr()); + ptypes->Set(i, ptypes_array[i]); } return MethodType::Create(self, rtype, ptypes); } -MethodType* VarHandle::GetMethodTypeForAccessMode(Thread* self, AccessMode access_mode) { +ObjPtr<MethodType> VarHandle::GetMethodTypeForAccessMode(Thread* self, AccessMode access_mode) { return GetMethodTypeForAccessMode(self, this, access_mode); } diff --git a/runtime/mirror/var_handle.h b/runtime/mirror/var_handle.h index 9829456854..48c9d74e30 100644 --- a/runtime/mirror/var_handle.h +++ b/runtime/mirror/var_handle.h @@ -26,6 +26,7 @@ namespace art { template<class T> class Handle; class InstructionOperands; +template<class T> class ObjPtr; enum class Intrinsics; @@ -120,7 +121,7 @@ class MANAGED VarHandle : public Object { // AccessMode. No check is made for whether the AccessMode is a // supported operation so the MethodType can be used when raising a // WrongMethodTypeException exception. - MethodType* GetMethodTypeForAccessMode(Thread* self, AccessMode accessMode) + ObjPtr<MethodType> GetMethodTypeForAccessMode(Thread* self, AccessMode accessMode) REQUIRES_SHARED(Locks::mutator_lock_); // Returns a string representing the descriptor of the MethodType associated with @@ -135,7 +136,7 @@ class MANAGED VarHandle : public Object { REQUIRES_SHARED(Locks::mutator_lock_); // Gets the variable type that is operated on by this VarHandle instance. - Class* GetVarType() REQUIRES_SHARED(Locks::mutator_lock_); + ObjPtr<Class> GetVarType() REQUIRES_SHARED(Locks::mutator_lock_); // Gets the return type descriptor for a named accessor method, // nullptr if accessor_method is not supported. @@ -149,13 +150,13 @@ class MANAGED VarHandle : public Object { static bool GetAccessModeByMethodName(const char* method_name, AccessMode* access_mode); private: - Class* GetCoordinateType0() REQUIRES_SHARED(Locks::mutator_lock_); - Class* GetCoordinateType1() REQUIRES_SHARED(Locks::mutator_lock_); + ObjPtr<Class> GetCoordinateType0() REQUIRES_SHARED(Locks::mutator_lock_); + ObjPtr<Class> GetCoordinateType1() REQUIRES_SHARED(Locks::mutator_lock_); int32_t GetAccessModesBitMask() REQUIRES_SHARED(Locks::mutator_lock_); - static MethodType* GetMethodTypeForAccessMode(Thread* self, - ObjPtr<VarHandle> var_handle, - AccessMode access_mode) + static ObjPtr<MethodType> GetMethodTypeForAccessMode(Thread* self, + ObjPtr<VarHandle> var_handle, + AccessMode access_mode) REQUIRES_SHARED(Locks::mutator_lock_); static MemberOffset VarTypeOffset() { diff --git a/runtime/mirror/var_handle_test.cc b/runtime/mirror/var_handle_test.cc index cb2d628b5b..9df96ddbd1 100644 --- a/runtime/mirror/var_handle_test.cc +++ b/runtime/mirror/var_handle_test.cc @@ -130,17 +130,17 @@ class VarHandleTest : public CommonRuntimeTest { } // Helper to get the VarType of a VarHandle. - static Class* GetVarType(VarHandle* vh) REQUIRES_SHARED(Locks::mutator_lock_) { + static ObjPtr<Class> GetVarType(VarHandle* vh) REQUIRES_SHARED(Locks::mutator_lock_) { return vh->GetVarType(); } // Helper to get the CoordinateType0 of a VarHandle. - static Class* GetCoordinateType0(VarHandle* vh) REQUIRES_SHARED(Locks::mutator_lock_) { + static ObjPtr<Class> GetCoordinateType0(VarHandle* vh) REQUIRES_SHARED(Locks::mutator_lock_) { return vh->GetCoordinateType0(); } // Helper to get the CoordinateType1 of a VarHandle. - static Class* GetCoordinateType1(VarHandle* vh) REQUIRES_SHARED(Locks::mutator_lock_) { + static ObjPtr<Class> GetCoordinateType1(VarHandle* vh) REQUIRES_SHARED(Locks::mutator_lock_) { return vh->GetCoordinateType1(); } @@ -150,7 +150,7 @@ class VarHandleTest : public CommonRuntimeTest { } private: - static void InitializeVarHandle(VarHandle* vh, + static void InitializeVarHandle(ObjPtr<VarHandle> vh, Handle<Class> var_type, int32_t access_modes_bit_mask) REQUIRES_SHARED(Locks::mutator_lock_) { @@ -158,7 +158,7 @@ class VarHandleTest : public CommonRuntimeTest { vh->SetField32<false>(VarHandle::AccessModesBitMaskOffset(), access_modes_bit_mask); } - static void InitializeVarHandle(VarHandle* vh, + static void InitializeVarHandle(ObjPtr<VarHandle> vh, Handle<Class> var_type, Handle<Class> coordinate_type0, int32_t access_modes_bit_mask) @@ -167,7 +167,7 @@ class VarHandleTest : public CommonRuntimeTest { vh->SetFieldObject<false>(VarHandle::CoordinateType0Offset(), coordinate_type0.Get()); } - static void InitializeVarHandle(VarHandle* vh, + static void InitializeVarHandle(ObjPtr<VarHandle> vh, Handle<Class> var_type, Handle<Class> coordinate_type0, Handle<Class> coordinate_type1, diff --git a/runtime/native/java_lang_Class.cc b/runtime/native/java_lang_Class.cc index 261178b0ee..c6bdfa10c6 100644 --- a/runtime/native/java_lang_Class.cc +++ b/runtime/native/java_lang_Class.cc @@ -215,17 +215,9 @@ static jstring Class_getNameNative(JNIEnv* env, jobject javaThis) { return soa.AddLocalReference<jstring>(mirror::Class::ComputeName(hs.NewHandle(c))); } -// TODO: Move this to mirror::Class ? Other mirror types that commonly appear -// as arrays have a GetArrayClass() method. -static ObjPtr<mirror::Class> GetClassArrayClass(Thread* self) - REQUIRES_SHARED(Locks::mutator_lock_) { - ObjPtr<mirror::Class> class_class = mirror::Class::GetJavaLangClass(); - return Runtime::Current()->GetClassLinker()->FindArrayClass(self, &class_class); -} - static jobjectArray Class_getInterfacesInternal(JNIEnv* env, jobject javaThis) { ScopedFastNativeObjectAccess soa(env); - StackHandleScope<4> hs(soa.Self()); + StackHandleScope<1> hs(soa.Self()); Handle<mirror::Class> klass = hs.NewHandle(DecodeClass(soa, javaThis)); if (klass->IsProxyClass()) { @@ -237,10 +229,12 @@ static jobjectArray Class_getInterfacesInternal(JNIEnv* env, jobject javaThis) { return nullptr; } + ClassLinker* linker = Runtime::Current()->GetClassLinker(); const uint32_t num_ifaces = iface_list->Size(); - Handle<mirror::Class> class_array_class = hs.NewHandle(GetClassArrayClass(soa.Self())); - Handle<mirror::ObjectArray<mirror::Class>> ifaces = hs.NewHandle( - mirror::ObjectArray<mirror::Class>::Alloc(soa.Self(), class_array_class.Get(), num_ifaces)); + ObjPtr<mirror::Class> class_array_class = + GetClassRoot<mirror::ObjectArray<mirror::Class>>(linker); + ObjPtr<mirror::ObjectArray<mirror::Class>> ifaces = + mirror::ObjectArray<mirror::Class>::Alloc(soa.Self(), class_array_class, num_ifaces); if (ifaces.IsNull()) { DCHECK(soa.Self()->IsExceptionPending()); return nullptr; @@ -250,20 +244,21 @@ static jobjectArray Class_getInterfacesInternal(JNIEnv* env, jobject javaThis) { // with kActiveTransaction == false. DCHECK(!Runtime::Current()->IsActiveTransaction()); - ClassLinker* linker = Runtime::Current()->GetClassLinker(); - MutableHandle<mirror::Class> interface(hs.NewHandle<mirror::Class>(nullptr)); for (uint32_t i = 0; i < num_ifaces; ++i) { const dex::TypeIndex type_idx = iface_list->GetTypeItem(i).type_idx_; - interface.Assign(linker->LookupResolvedType(type_idx, klass.Get())); - ifaces->SetWithoutChecks<false>(i, interface.Get()); + ObjPtr<mirror::Class> interface = linker->LookupResolvedType(type_idx, klass.Get()); + DCHECK(interface != nullptr); + ifaces->SetWithoutChecks<false>(i, interface); } - return soa.AddLocalReference<jobjectArray>(ifaces.Get()); + return soa.AddLocalReference<jobjectArray>(ifaces); } -static mirror::ObjectArray<mirror::Field>* GetDeclaredFields( - Thread* self, ObjPtr<mirror::Class> klass, bool public_only, bool force_resolve) - REQUIRES_SHARED(Locks::mutator_lock_) { +static ObjPtr<mirror::ObjectArray<mirror::Field>> GetDeclaredFields( + Thread* self, + ObjPtr<mirror::Class> klass, + bool public_only, + bool force_resolve) REQUIRES_SHARED(Locks::mutator_lock_) { StackHandleScope<1> hs(self); IterationRange<StrideIterator<ArtField>> ifields = klass->GetIFields(); IterationRange<StrideIterator<ArtField>> sfields = klass->GetSFields(); @@ -672,10 +667,8 @@ static jobjectArray Class_getDeclaredClasses(JNIEnv* env, jobject javaThis) { // Pending exception from GetDeclaredClasses. return nullptr; } - ObjPtr<mirror::Class> class_array_class = GetClassArrayClass(soa.Self()); - if (class_array_class == nullptr) { - return nullptr; - } + ObjPtr<mirror::Class> class_array_class = GetClassRoot<mirror::ObjectArray<mirror::Class>>(); + DCHECK(class_array_class != nullptr); ObjPtr<mirror::ObjectArray<mirror::Class>> empty_array = mirror::ObjectArray<mirror::Class>::Alloc(soa.Self(), class_array_class, 0); return soa.AddLocalReference<jobjectArray>(empty_array); diff --git a/runtime/native/java_lang_VMClassLoader.cc b/runtime/native/java_lang_VMClassLoader.cc index b1511c0d88..42c7ad5650 100644 --- a/runtime/native/java_lang_VMClassLoader.cc +++ b/runtime/native/java_lang_VMClassLoader.cc @@ -37,11 +37,11 @@ namespace art { // A class so we can be friends with ClassLinker and access internal methods. class VMClassLoader { public: - static mirror::Class* LookupClass(ClassLinker* cl, - Thread* self, - const char* descriptor, - size_t hash, - ObjPtr<mirror::ClassLoader> class_loader) + static ObjPtr<mirror::Class> LookupClass(ClassLinker* cl, + Thread* self, + const char* descriptor, + size_t hash, + ObjPtr<mirror::ClassLoader> class_loader) REQUIRES(!Locks::classlinker_classes_lock_) REQUIRES_SHARED(Locks::mutator_lock_) { return cl->LookupClass(self, descriptor, hash, class_loader); diff --git a/runtime/native/java_lang_reflect_Constructor.cc b/runtime/native/java_lang_reflect_Constructor.cc index 13a8d28267..a961cb2597 100644 --- a/runtime/native/java_lang_reflect_Constructor.cc +++ b/runtime/native/java_lang_reflect_Constructor.cc @@ -20,8 +20,8 @@ #include "art_method-inl.h" #include "base/enums.h" -#include "class_linker-inl.h" #include "class_linker.h" +#include "class_root.h" #include "dex/dex_file_annotations.h" #include "jni/jni_internal.h" #include "mirror/class-inl.h" @@ -42,12 +42,8 @@ static jobjectArray Constructor_getExceptionTypes(JNIEnv* env, jobject javaMetho annotations::GetExceptionTypesForMethod(method); if (result_array == nullptr) { // Return an empty array instead of a null pointer. - ObjPtr<mirror::Class> class_class = mirror::Class::GetJavaLangClass(); - ObjPtr<mirror::Class> class_array_class = - Runtime::Current()->GetClassLinker()->FindArrayClass(soa.Self(), &class_class); - if (class_array_class == nullptr) { - return nullptr; - } + ObjPtr<mirror::Class> class_array_class = GetClassRoot<mirror::ObjectArray<mirror::Class>>(); + DCHECK(class_array_class != nullptr); ObjPtr<mirror::ObjectArray<mirror::Class>> empty_array = mirror::ObjectArray<mirror::Class>::Alloc(soa.Self(), class_array_class, 0); return soa.AddLocalReference<jobjectArray>(empty_array); diff --git a/runtime/native/java_lang_reflect_Executable.cc b/runtime/native/java_lang_reflect_Executable.cc index 9a2d3020c0..a40cb9b2e6 100644 --- a/runtime/native/java_lang_reflect_Executable.cc +++ b/runtime/native/java_lang_reflect_Executable.cc @@ -20,6 +20,7 @@ #include "nativehelper/jni_macros.h" #include "art_method-inl.h" +#include "class_root.h" #include "dex/dex_file_annotations.h" #include "handle.h" #include "jni/jni_internal.h" @@ -335,15 +336,6 @@ static jclass Executable_getMethodReturnTypeInternal(JNIEnv* env, jobject javaMe return soa.AddLocalReference<jclass>(return_type); } -// TODO: Move this to mirror::Class ? Other mirror types that commonly appear -// as arrays have a GetArrayClass() method. This is duplicated in -// java_lang_Class.cc as well. -static ObjPtr<mirror::Class> GetClassArrayClass(Thread* self) - REQUIRES_SHARED(Locks::mutator_lock_) { - ObjPtr<mirror::Class> class_class = mirror::Class::GetJavaLangClass(); - return Runtime::Current()->GetClassLinker()->FindArrayClass(self, &class_class); -} - static jobjectArray Executable_getParameterTypesInternal(JNIEnv* env, jobject javaMethod) { ScopedFastNativeObjectAccess soa(env); ArtMethod* method = ArtMethod::FromReflectedMethod(soa, javaMethod); @@ -356,10 +348,10 @@ static jobjectArray Executable_getParameterTypesInternal(JNIEnv* env, jobject ja const uint32_t num_params = params->Size(); - StackHandleScope<3> hs(soa.Self()); - Handle<mirror::Class> class_array_class = hs.NewHandle(GetClassArrayClass(soa.Self())); + StackHandleScope<2> hs(soa.Self()); + ObjPtr<mirror::Class> class_array_class = GetClassRoot<mirror::ObjectArray<mirror::Class>>(); Handle<mirror::ObjectArray<mirror::Class>> ptypes = hs.NewHandle( - mirror::ObjectArray<mirror::Class>::Alloc(soa.Self(), class_array_class.Get(), num_params)); + mirror::ObjectArray<mirror::Class>::Alloc(soa.Self(), class_array_class, num_params)); if (ptypes.IsNull()) { DCHECK(soa.Self()->IsExceptionPending()); return nullptr; diff --git a/runtime/native/java_lang_reflect_Method.cc b/runtime/native/java_lang_reflect_Method.cc index 52e04941c6..34455fe00f 100644 --- a/runtime/native/java_lang_reflect_Method.cc +++ b/runtime/native/java_lang_reflect_Method.cc @@ -22,6 +22,7 @@ #include "base/enums.h" #include "class_linker-inl.h" #include "class_linker.h" +#include "class_root.h" #include "dex/dex_file_annotations.h" #include "jni/jni_internal.h" #include "mirror/class-inl.h" @@ -66,12 +67,8 @@ static jobjectArray Method_getExceptionTypes(JNIEnv* env, jobject javaMethod) { annotations::GetExceptionTypesForMethod(method); if (result_array == nullptr) { // Return an empty array instead of a null pointer - ObjPtr<mirror::Class> class_class = mirror::Class::GetJavaLangClass(); - ObjPtr<mirror::Class> class_array_class = - Runtime::Current()->GetClassLinker()->FindArrayClass(soa.Self(), &class_class); - if (class_array_class == nullptr) { - return nullptr; - } + ObjPtr<mirror::Class> class_array_class = GetClassRoot<mirror::ObjectArray<mirror::Class>>(); + DCHECK(class_array_class != nullptr); mirror::ObjectArray<mirror::Class>* empty_array = mirror::ObjectArray<mirror::Class>::Alloc(soa.Self(), class_array_class, 0); return soa.AddLocalReference<jobjectArray>(empty_array); diff --git a/runtime/oat.h b/runtime/oat.h index 8069a15661..e7e5848dd6 100644 --- a/runtime/oat.h +++ b/runtime/oat.h @@ -32,8 +32,8 @@ class InstructionSetFeatures; class PACKED(4) OatHeader { public: static constexpr uint8_t kOatMagic[] = { 'o', 'a', 't', '\n' }; - // Last oat version changed reason: Optimize masks in stack maps. - static constexpr uint8_t kOatVersion[] = { '1', '4', '5', '\0' }; + // Last oat version changed reason: Rewrite dex register map encoding. + static constexpr uint8_t kOatVersion[] = { '1', '4', '6', '\0' }; static constexpr const char* kImageLocationKey = "image-location"; static constexpr const char* kDex2OatCmdLineKey = "dex2oat-cmdline"; diff --git a/runtime/proxy_test.cc b/runtime/proxy_test.cc index 4e0bf890db..946ea018f3 100644 --- a/runtime/proxy_test.cc +++ b/runtime/proxy_test.cc @@ -44,9 +44,9 @@ TEST_F(ProxyTest, ProxyClassHelper) { ASSERT_TRUE(I != nullptr); ASSERT_TRUE(J != nullptr); - std::vector<mirror::Class*> interfaces; - interfaces.push_back(I.Get()); - interfaces.push_back(J.Get()); + std::vector<Handle<mirror::Class>> interfaces; + interfaces.push_back(I); + interfaces.push_back(J); Handle<mirror::Class> proxy_class(hs.NewHandle( GenerateProxyClass(soa, jclass_loader, class_linker_, "$Proxy1234", interfaces))); interfaces.clear(); // Don't least possibly stale objects in the array as good practice. @@ -80,9 +80,9 @@ TEST_F(ProxyTest, ProxyFieldHelper) { Handle<mirror::Class> proxyClass; { - std::vector<mirror::Class*> interfaces; - interfaces.push_back(I.Get()); - interfaces.push_back(J.Get()); + std::vector<Handle<mirror::Class>> interfaces; + interfaces.push_back(I); + interfaces.push_back(J); proxyClass = hs.NewHandle( GenerateProxyClass(soa, jclass_loader, class_linker_, "$Proxy1234", interfaces)); } @@ -131,7 +131,7 @@ TEST_F(ProxyTest, CheckArtMirrorFieldsOfProxyStaticFields) { Handle<mirror::Class> proxyClass0; Handle<mirror::Class> proxyClass1; { - std::vector<mirror::Class*> interfaces; + std::vector<Handle<mirror::Class>> interfaces; proxyClass0 = hs.NewHandle( GenerateProxyClass(soa, jclass_loader, class_linker_, "$Proxy0", interfaces)); proxyClass1 = hs.NewHandle( diff --git a/runtime/proxy_test.h b/runtime/proxy_test.h index fa5a449e31..411dc7af82 100644 --- a/runtime/proxy_test.h +++ b/runtime/proxy_test.h @@ -25,6 +25,7 @@ #include "class_root.h" #include "mirror/class-inl.h" #include "mirror/method.h" +#include "obj_ptr-inl.h" namespace art { namespace proxy_test { @@ -32,35 +33,36 @@ namespace proxy_test { // Generate a proxy class with the given name and interfaces. This is a simplification from what // libcore does to fit to our test needs. We do not check for duplicated interfaces or methods and // we do not declare exceptions. -mirror::Class* GenerateProxyClass(ScopedObjectAccess& soa, - jobject jclass_loader, - ClassLinker* class_linker, - const char* className, - const std::vector<mirror::Class*>& interfaces) +ObjPtr<mirror::Class> GenerateProxyClass(ScopedObjectAccess& soa, + jobject jclass_loader, + ClassLinker* class_linker, + const char* className, + const std::vector<Handle<mirror::Class>>& interfaces) REQUIRES_SHARED(Locks::mutator_lock_) { StackHandleScope<1> hs(soa.Self()); - Handle<mirror::Class> javaLangObject = hs.NewHandle( - class_linker->FindSystemClass(soa.Self(), "Ljava/lang/Object;")); + Handle<mirror::Class> javaLangObject = hs.NewHandle(GetClassRoot<mirror::Object>()); CHECK(javaLangObject != nullptr); - jclass javaLangClass = soa.AddLocalReference<jclass>(mirror::Class::GetJavaLangClass()); + jclass javaLangClass = soa.AddLocalReference<jclass>(GetClassRoot<mirror::Class>()); // Builds the interfaces array. - jobjectArray proxyClassInterfaces = soa.Env()->NewObjectArray(interfaces.size(), javaLangClass, - nullptr); + jobjectArray proxyClassInterfaces = + soa.Env()->NewObjectArray(interfaces.size(), javaLangClass, /* initialElement */ nullptr); soa.Self()->AssertNoPendingException(); for (size_t i = 0; i < interfaces.size(); ++i) { soa.Env()->SetObjectArrayElement(proxyClassInterfaces, i, - soa.AddLocalReference<jclass>(interfaces[i])); + soa.AddLocalReference<jclass>(interfaces[i].Get())); } // Builds the method array. jsize methods_count = 3; // Object.equals, Object.hashCode and Object.toString. - for (mirror::Class* interface : interfaces) { + for (Handle<mirror::Class> interface : interfaces) { methods_count += interface->NumVirtualMethods(); } jobjectArray proxyClassMethods = soa.Env()->NewObjectArray( - methods_count, soa.AddLocalReference<jclass>(GetClassRoot<mirror::Method>()), nullptr); + methods_count, + soa.AddLocalReference<jclass>(GetClassRoot<mirror::Method>()), + /* initialElement */ nullptr); soa.Self()->AssertNoPendingException(); jsize array_index = 0; @@ -91,7 +93,7 @@ mirror::Class* GenerateProxyClass(ScopedObjectAccess& soa, proxyClassMethods, array_index++, soa.AddLocalReference<jobject>( mirror::Method::CreateFromArtMethod<kRuntimePointerSize, false>(soa.Self(), method))); // Now adds all interfaces virtual methods. - for (mirror::Class* interface : interfaces) { + for (Handle<mirror::Class> interface : interfaces) { for (auto& m : interface->GetDeclaredVirtualMethods(kRuntimePointerSize)) { soa.Env()->SetObjectArrayElement( proxyClassMethods, array_index++, soa.AddLocalReference<jobject>( @@ -104,9 +106,13 @@ mirror::Class* GenerateProxyClass(ScopedObjectAccess& soa, jobjectArray proxyClassThrows = soa.Env()->NewObjectArray(0, javaLangClass, nullptr); soa.Self()->AssertNoPendingException(); - mirror::Class* proxyClass = class_linker->CreateProxyClass( - soa, soa.Env()->NewStringUTF(className), proxyClassInterfaces, jclass_loader, - proxyClassMethods, proxyClassThrows); + ObjPtr<mirror::Class> proxyClass = class_linker->CreateProxyClass( + soa, + soa.Env()->NewStringUTF(className), + proxyClassInterfaces, + jclass_loader, + proxyClassMethods, + proxyClassThrows); soa.Self()->AssertNoPendingException(); return proxyClass; } diff --git a/runtime/quick_exception_handler.cc b/runtime/quick_exception_handler.cc index 63a09f25a4..4f4abf7f7f 100644 --- a/runtime/quick_exception_handler.cc +++ b/runtime/quick_exception_handler.cc @@ -232,7 +232,7 @@ void QuickExceptionHandler::SetCatchEnvironmentForOptimizedHandler(StackVisitor* DCHECK(catch_stack_map.IsValid()); DexRegisterMap catch_vreg_map = code_info.GetDexRegisterMapOf(catch_stack_map, number_of_vregs); - if (!catch_vreg_map.IsValid()) { + if (!catch_vreg_map.IsValid() || !catch_vreg_map.HasAnyLiveDexRegisters()) { return; } diff --git a/runtime/reflection_test.cc b/runtime/reflection_test.cc index d2d720f722..424ee0681a 100644 --- a/runtime/reflection_test.cc +++ b/runtime/reflection_test.cc @@ -80,7 +80,7 @@ class ReflectionTest : public CommonCompilerTest { jclass GetPrimitiveClass(char descriptor) { ScopedObjectAccess soa(env_); - mirror::Class* c = class_linker_->FindPrimitiveClass(descriptor); + ObjPtr<mirror::Class> c = class_linker_->FindPrimitiveClass(descriptor); CHECK(c != nullptr); return soa.AddLocalReference<jclass>(c); } @@ -518,7 +518,7 @@ TEST_F(ReflectionTest, StaticMainMethod) { hs.NewHandle(soa.Decode<mirror::ClassLoader>(jclass_loader))); CompileDirectMethod(class_loader, "Main", "main", "([Ljava/lang/String;)V"); - mirror::Class* klass = class_linker_->FindClass(soa.Self(), "LMain;", class_loader); + ObjPtr<mirror::Class> klass = class_linker_->FindClass(soa.Self(), "LMain;", class_loader); ASSERT_TRUE(klass != nullptr); ArtMethod* method = klass->FindClassMethod("main", diff --git a/runtime/runtime.cc b/runtime/runtime.cc index 6384d01aaf..0d9d16cd01 100644 --- a/runtime/runtime.cc +++ b/runtime/runtime.cc @@ -1976,10 +1976,6 @@ mirror::Throwable* Runtime::GetPreAllocatedNoClassDefFoundError() { } void Runtime::VisitConstantRoots(RootVisitor* visitor) { - // Visit the classes held as static in mirror classes, these can be visited concurrently and only - // need to be visited once per GC since they never change. - mirror::Class::VisitRoots(visitor); - mirror::ClassExt::VisitRoots(visitor); // Visiting the roots of these ArtMethods is not currently required since all the GcRoots are // null. BufferedRootVisitor<16> buffered_visitor(visitor, RootInfo(kRootVMInternal)); diff --git a/runtime/stack_map.cc b/runtime/stack_map.cc index 61fe2e7965..923bb3559a 100644 --- a/runtime/stack_map.cc +++ b/runtime/stack_map.cc @@ -16,6 +16,7 @@ #include "stack_map.h" +#include <iomanip> #include <stdint.h> #include "art_method.h" @@ -24,149 +25,102 @@ namespace art { -constexpr size_t DexRegisterLocationCatalog::kNoLocationEntryIndex; - -std::ostream& operator<<(std::ostream& stream, const DexRegisterLocation::Kind& kind) { +std::ostream& operator<<(std::ostream& stream, const DexRegisterLocation& reg) { using Kind = DexRegisterLocation::Kind; - switch (kind) { + switch (reg.GetKind()) { case Kind::kNone: - return stream << "none"; + return stream << "None"; case Kind::kInStack: - return stream << "in stack"; + return stream << "sp+" << reg.GetValue(); case Kind::kInRegister: - return stream << "in register"; + return stream << "r" << reg.GetValue(); case Kind::kInRegisterHigh: - return stream << "in register high"; + return stream << "r" << reg.GetValue() << "/hi"; case Kind::kInFpuRegister: - return stream << "in fpu register"; + return stream << "f" << reg.GetValue(); case Kind::kInFpuRegisterHigh: - return stream << "in fpu register high"; + return stream << "f" << reg.GetValue() << "/hi"; case Kind::kConstant: - return stream << "as constant"; - case Kind::kInStackLargeOffset: - return stream << "in stack (large offset)"; - case Kind::kConstantLargeValue: - return stream << "as constant (large value)"; + return stream << "#" << reg.GetValue(); + default: + return stream << "DexRegisterLocation(" << static_cast<uint32_t>(reg.GetKind()) + << "," << reg.GetValue() << ")"; } - return stream << "Kind<" << static_cast<uint32_t>(kind) << ">"; -} - -DexRegisterLocation::Kind DexRegisterMap::GetLocationInternalKind( - uint16_t dex_register_number) const { - DexRegisterLocationCatalog dex_register_location_catalog = - code_info_.GetDexRegisterLocationCatalog(); - size_t location_catalog_entry_index = GetLocationCatalogEntryIndex( - dex_register_number, - code_info_.GetNumberOfLocationCatalogEntries()); - return dex_register_location_catalog.GetLocationInternalKind(location_catalog_entry_index); -} - -DexRegisterLocation DexRegisterMap::GetDexRegisterLocation(uint16_t dex_register_number) const { - DexRegisterLocationCatalog dex_register_location_catalog = - code_info_.GetDexRegisterLocationCatalog(); - size_t location_catalog_entry_index = GetLocationCatalogEntryIndex( - dex_register_number, - code_info_.GetNumberOfLocationCatalogEntries()); - return dex_register_location_catalog.GetDexRegisterLocation(location_catalog_entry_index); } -static void DumpRegisterMapping(std::ostream& os, - size_t dex_register_num, - DexRegisterLocation location, - const std::string& prefix = "v", - const std::string& suffix = "") { - os << prefix << dex_register_num << ": " - << location.GetInternalKind() - << " (" << location.GetValue() << ")" << suffix << '\n'; -} - -void StackMap::DumpEncoding(const BitTable<6>& table, - VariableIndentationOutputStream* vios) { - vios->Stream() - << "StackMapEncoding" - << " (PackedNativePcBits=" << table.NumColumnBits(kPackedNativePc) - << ", DexPcBits=" << table.NumColumnBits(kDexPc) - << ", DexRegisterMapOffsetBits=" << table.NumColumnBits(kDexRegisterMapOffset) - << ", InlineInfoIndexBits=" << table.NumColumnBits(kInlineInfoIndex) - << ", RegisterMaskIndexBits=" << table.NumColumnBits(kRegisterMaskIndex) - << ", StackMaskIndexBits=" << table.NumColumnBits(kStackMaskIndex) - << ")\n"; +static void DumpDexRegisterMap(VariableIndentationOutputStream* vios, + const DexRegisterMap& map) { + if (map.IsValid()) { + ScopedIndentation indent1(vios); + for (size_t i = 0; i < map.size(); ++i) { + if (map.IsDexRegisterLive(i)) { + vios->Stream() << "v" << i << ":" << map.Get(i) << " "; + } + } + vios->Stream() << "\n"; + } } -void InlineInfo::DumpEncoding(const BitTable<5>& table, - VariableIndentationOutputStream* vios) { - vios->Stream() - << "InlineInfoEncoding" - << " (IsLastBits=" << table.NumColumnBits(kIsLast) - << ", MethodIndexIdxBits=" << table.NumColumnBits(kMethodIndexIdx) - << ", DexPcBits=" << table.NumColumnBits(kDexPc) - << ", ExtraDataBits=" << table.NumColumnBits(kExtraData) - << ", DexRegisterMapOffsetBits=" << table.NumColumnBits(kDexRegisterMapOffset) - << ")\n"; +template<uint32_t kNumColumns> +static void DumpTable(VariableIndentationOutputStream* vios, + const char* table_name, + const BitTable<kNumColumns>& table, + bool verbose, + bool is_mask = false) { + if (table.NumRows() != 0) { + vios->Stream() << table_name << " BitSize=" << table.NumRows() * table.NumRowBits(); + vios->Stream() << " Rows=" << table.NumRows() << " Bits={"; + for (size_t c = 0; c < table.NumColumns(); c++) { + vios->Stream() << (c != 0 ? " " : ""); + vios->Stream() << table.NumColumnBits(c); + } + vios->Stream() << "}\n"; + if (verbose) { + ScopedIndentation indent1(vios); + for (size_t r = 0; r < table.NumRows(); r++) { + vios->Stream() << "[" << std::right << std::setw(3) << r << "]={"; + for (size_t c = 0; c < table.NumColumns(); c++) { + vios->Stream() << (c != 0 ? " " : ""); + if (is_mask) { + BitMemoryRegion bits = table.GetBitMemoryRegion(r, c); + for (size_t b = 0, e = bits.size_in_bits(); b < e; b++) { + vios->Stream() << bits.LoadBit(e - b - 1); + } + } else { + vios->Stream() << std::right << std::setw(8) << static_cast<int32_t>(table.Get(r, c)); + } + } + vios->Stream() << "}\n"; + } + } + } } void CodeInfo::Dump(VariableIndentationOutputStream* vios, uint32_t code_offset, - uint16_t number_of_dex_registers, - bool dump_stack_maps, + uint16_t num_dex_registers, + bool verbose, InstructionSet instruction_set, const MethodInfo& method_info) const { - size_t number_of_stack_maps = GetNumberOfStackMaps(); vios->Stream() - << "Optimized CodeInfo (number_of_dex_registers=" << number_of_dex_registers - << ", number_of_stack_maps=" << number_of_stack_maps - << ")\n"; + << "CodeInfo" + << " BitSize=" << size_ * kBitsPerByte + << "\n"; ScopedIndentation indent1(vios); - StackMap::DumpEncoding(stack_maps_, vios); - if (HasInlineInfo()) { - InlineInfo::DumpEncoding(inline_infos_, vios); - } - // Display the Dex register location catalog. - GetDexRegisterLocationCatalog().Dump(vios, *this); + DumpTable(vios, "StackMaps", stack_maps_, verbose); + DumpTable(vios, "RegisterMasks", register_masks_, verbose); + DumpTable(vios, "StackMasks", stack_masks_, verbose, true /* is_mask */); + DumpTable(vios, "InvokeInfos", invoke_infos_, verbose); + DumpTable(vios, "InlineInfos", inline_infos_, verbose); + DumpTable(vios, "DexRegisterMasks", dex_register_masks_, verbose, true /* is_mask */); + DumpTable(vios, "DexRegisterMaps", dex_register_maps_, verbose); + DumpTable(vios, "DexRegisterCatalog", dex_register_catalog_, verbose); + // Display stack maps along with (live) Dex register maps. - if (dump_stack_maps) { - for (size_t i = 0; i < number_of_stack_maps; ++i) { + if (verbose) { + for (size_t i = 0; i < GetNumberOfStackMaps(); ++i) { StackMap stack_map = GetStackMapAt(i); - stack_map.Dump(vios, - *this, - method_info, - code_offset, - number_of_dex_registers, - instruction_set, - " " + std::to_string(i)); - } - } - // TODO: Dump the stack map's inline information? We need to know more from the caller: - // we need to know the number of dex registers for each inlined method. -} - -void DexRegisterLocationCatalog::Dump(VariableIndentationOutputStream* vios, - const CodeInfo& code_info) { - size_t number_of_location_catalog_entries = code_info.GetNumberOfLocationCatalogEntries(); - size_t location_catalog_size_in_bytes = code_info.GetDexRegisterLocationCatalogSize(); - vios->Stream() - << "DexRegisterLocationCatalog (number_of_entries=" << number_of_location_catalog_entries - << ", size_in_bytes=" << location_catalog_size_in_bytes << ")\n"; - for (size_t i = 0; i < number_of_location_catalog_entries; ++i) { - DexRegisterLocation location = GetDexRegisterLocation(i); - ScopedIndentation indent1(vios); - DumpRegisterMapping(vios->Stream(), i, location, "entry "); - } -} - -void DexRegisterMap::Dump(VariableIndentationOutputStream* vios) const { - size_t number_of_location_catalog_entries = code_info_.GetNumberOfLocationCatalogEntries(); - // TODO: Display the bit mask of live Dex registers. - for (size_t j = 0; j < number_of_dex_registers_; ++j) { - if (IsDexRegisterLive(j)) { - size_t location_catalog_entry_index = GetLocationCatalogEntryIndex( - j, - number_of_location_catalog_entries); - DexRegisterLocation location = GetDexRegisterLocation(j); - ScopedIndentation indent1(vios); - DumpRegisterMapping( - vios->Stream(), j, location, "v", - "\t[entry " + std::to_string(static_cast<int>(location_catalog_entry_index)) + "]"); + stack_map.Dump(vios, *this, method_info, code_offset, num_dex_registers, instruction_set); } } } @@ -176,17 +130,13 @@ void StackMap::Dump(VariableIndentationOutputStream* vios, const MethodInfo& method_info, uint32_t code_offset, uint16_t number_of_dex_registers, - InstructionSet instruction_set, - const std::string& header_suffix) const { + InstructionSet instruction_set) const { const uint32_t pc_offset = GetNativePcOffset(instruction_set); vios->Stream() - << "StackMap" << header_suffix + << "StackMap[" << Row() << "]" << std::hex - << " [native_pc=0x" << code_offset + pc_offset << "]" - << " (dex_pc=0x" << GetDexPc() - << ", native_pc_offset=0x" << pc_offset - << ", dex_register_map_offset=0x" << GetDexRegisterMapOffset() - << ", inline_info_offset=0x" << GetInlineInfoIndex() + << " (native_pc=0x" << code_offset + pc_offset + << ", dex_pc=0x" << GetDexPc() << ", register_mask=0x" << code_info.GetRegisterMaskOf(*this) << std::dec << ", stack_mask=0b"; @@ -195,11 +145,7 @@ void StackMap::Dump(VariableIndentationOutputStream* vios, vios->Stream() << stack_mask.LoadBit(e - i - 1); } vios->Stream() << ")\n"; - if (HasDexRegisterMap()) { - DexRegisterMap dex_register_map = code_info.GetDexRegisterMapOf( - *this, number_of_dex_registers); - dex_register_map.Dump(vios); - } + DumpDexRegisterMap(vios, code_info.GetDexRegisterMapOf(*this, number_of_dex_registers)); if (HasInlineInfo()) { InlineInfo inline_info = code_info.GetInlineInfoOf(*this); // We do not know the length of the dex register maps of inlined frames @@ -213,15 +159,12 @@ void InlineInfo::Dump(VariableIndentationOutputStream* vios, const CodeInfo& code_info, const MethodInfo& method_info, uint16_t number_of_dex_registers[]) const { - vios->Stream() << "InlineInfo with depth " - << static_cast<uint32_t>(GetDepth()) - << "\n"; - for (size_t i = 0; i < GetDepth(); ++i) { vios->Stream() - << " At depth " << i + << "InlineInfo[" << Row() + i << "]" + << " (depth=" << i << std::hex - << " (dex_pc=0x" << GetDexPcAtDepth(i); + << ", dex_pc=0x" << GetDexPcAtDepth(i); if (EncodesArtMethodAtDepth(i)) { ScopedObjectAccess soa(Thread::Current()); vios->Stream() << ", method=" << GetArtMethodAtDepth(i)->PrettyMethod(); @@ -231,11 +174,9 @@ void InlineInfo::Dump(VariableIndentationOutputStream* vios, << ", method_index=" << GetMethodIndexAtDepth(method_info, i); } vios->Stream() << ")\n"; - if (HasDexRegisterMapAtDepth(i) && (number_of_dex_registers != nullptr)) { - DexRegisterMap dex_register_map = - code_info.GetDexRegisterMapAtDepth(i, *this, number_of_dex_registers[i]); - ScopedIndentation indent1(vios); - dex_register_map.Dump(vios); + if (number_of_dex_registers != nullptr) { + uint16_t vregs = number_of_dex_registers[i]; + DumpDexRegisterMap(vios, code_info.GetDexRegisterMapAtDepth(i, *this, vregs)); } } } diff --git a/runtime/stack_map.h b/runtime/stack_map.h index 9d66b3181c..9aac204e70 100644 --- a/runtime/stack_map.h +++ b/runtime/stack_map.h @@ -26,6 +26,7 @@ #include "base/leb128.h" #include "base/memory_region.h" #include "dex/dex_file_types.h" +#include "dex_register_location.h" #include "method_info.h" #include "oat_quick_method_header.h" @@ -41,522 +42,76 @@ static constexpr ssize_t kFrameSlotSize = 4; class ArtMethod; class CodeInfo; -/** - * Classes in the following file are wrapper on stack map information backed - * by a MemoryRegion. As such they read and write to the region, they don't have - * their own fields. - */ - -// Dex register location container used by DexRegisterMap and StackMapStream. -class DexRegisterLocation { - public: - /* - * The location kind used to populate the Dex register information in a - * StackMapStream can either be: - * - kStack: vreg stored on the stack, value holds the stack offset; - * - kInRegister: vreg stored in low 32 bits of a core physical register, - * value holds the register number; - * - kInRegisterHigh: vreg stored in high 32 bits of a core physical register, - * value holds the register number; - * - kInFpuRegister: vreg stored in low 32 bits of an FPU register, - * value holds the register number; - * - kInFpuRegisterHigh: vreg stored in high 32 bits of an FPU register, - * value holds the register number; - * - kConstant: value holds the constant; - * - * In addition, DexRegisterMap also uses these values: - * - kInStackLargeOffset: value holds a "large" stack offset (greater than - * or equal to 128 bytes); - * - kConstantLargeValue: value holds a "large" constant (lower than 0, or - * or greater than or equal to 32); - * - kNone: the register has no location, meaning it has not been set. - */ - enum class Kind : uint8_t { - // Short location kinds, for entries fitting on one byte (3 bits - // for the kind, 5 bits for the value) in a DexRegisterMap. - kInStack = 0, // 0b000 - kInRegister = 1, // 0b001 - kInRegisterHigh = 2, // 0b010 - kInFpuRegister = 3, // 0b011 - kInFpuRegisterHigh = 4, // 0b100 - kConstant = 5, // 0b101 - - // Large location kinds, requiring a 5-byte encoding (1 byte for the - // kind, 4 bytes for the value). - - // Stack location at a large offset, meaning that the offset value - // divided by the stack frame slot size (4 bytes) cannot fit on a - // 5-bit unsigned integer (i.e., this offset value is greater than - // or equal to 2^5 * 4 = 128 bytes). - kInStackLargeOffset = 6, // 0b110 - - // Large constant, that cannot fit on a 5-bit signed integer (i.e., - // lower than 0, or greater than or equal to 2^5 = 32). - kConstantLargeValue = 7, // 0b111 - - // Entries with no location are not stored and do not need own marker. - kNone = static_cast<uint8_t>(-1), - - kLastLocationKind = kConstantLargeValue - }; - - static_assert( - sizeof(Kind) == 1u, - "art::DexRegisterLocation::Kind has a size different from one byte."); - - static bool IsShortLocationKind(Kind kind) { - switch (kind) { - case Kind::kInStack: - case Kind::kInRegister: - case Kind::kInRegisterHigh: - case Kind::kInFpuRegister: - case Kind::kInFpuRegisterHigh: - case Kind::kConstant: - return true; - - case Kind::kInStackLargeOffset: - case Kind::kConstantLargeValue: - return false; - - case Kind::kNone: - LOG(FATAL) << "Unexpected location kind"; - } - UNREACHABLE(); - } +std::ostream& operator<<(std::ostream& stream, const DexRegisterLocation& reg); - // Convert `kind` to a "surface" kind, i.e. one that doesn't include - // any value with a "large" qualifier. - // TODO: Introduce another enum type for the surface kind? - static Kind ConvertToSurfaceKind(Kind kind) { - switch (kind) { - case Kind::kInStack: - case Kind::kInRegister: - case Kind::kInRegisterHigh: - case Kind::kInFpuRegister: - case Kind::kInFpuRegisterHigh: - case Kind::kConstant: - return kind; - - case Kind::kInStackLargeOffset: - return Kind::kInStack; - - case Kind::kConstantLargeValue: - return Kind::kConstant; - - case Kind::kNone: - return kind; - } - UNREACHABLE(); - } - - // Required by art::StackMapStream::LocationCatalogEntriesIndices. - DexRegisterLocation() : kind_(Kind::kNone), value_(0) {} - - DexRegisterLocation(Kind kind, int32_t value) : kind_(kind), value_(value) {} - - static DexRegisterLocation None() { - return DexRegisterLocation(Kind::kNone, 0); - } - - // Get the "surface" kind of the location, i.e., the one that doesn't - // include any value with a "large" qualifier. - Kind GetKind() const { - return ConvertToSurfaceKind(kind_); - } - - // Get the value of the location. - int32_t GetValue() const { return value_; } - - // Get the actual kind of the location. - Kind GetInternalKind() const { return kind_; } - - bool operator==(DexRegisterLocation other) const { - return kind_ == other.kind_ && value_ == other.value_; - } - - bool operator!=(DexRegisterLocation other) const { - return !(*this == other); - } - - private: - Kind kind_; - int32_t value_; - - friend class DexRegisterLocationHashFn; -}; - -std::ostream& operator<<(std::ostream& stream, const DexRegisterLocation::Kind& kind); - -/** - * Store information on unique Dex register locations used in a method. - * The information is of the form: - * - * [DexRegisterLocation+]. - * - * DexRegisterLocations are either 1- or 5-byte wide (see art::DexRegisterLocation::Kind). - */ -class DexRegisterLocationCatalog { +// Information on Dex register locations for a specific PC. +// Effectively just a convenience wrapper for DexRegisterLocation vector. +// If the size is small enough, it keeps the data on the stack. +class DexRegisterMap { public: - explicit DexRegisterLocationCatalog(MemoryRegion region) : region_(region) {} - - // Short (compressed) location, fitting on one byte. - typedef uint8_t ShortLocation; - - void SetRegisterInfo(size_t offset, const DexRegisterLocation& dex_register_location) { - DexRegisterLocation::Kind kind = ComputeCompressedKind(dex_register_location); - int32_t value = dex_register_location.GetValue(); - if (DexRegisterLocation::IsShortLocationKind(kind)) { - // Short location. Compress the kind and the value as a single byte. - if (kind == DexRegisterLocation::Kind::kInStack) { - // Instead of storing stack offsets expressed in bytes for - // short stack locations, store slot offsets. A stack offset - // is a multiple of 4 (kFrameSlotSize). This means that by - // dividing it by 4, we can fit values from the [0, 128) - // interval in a short stack location, and not just values - // from the [0, 32) interval. - DCHECK_EQ(value % kFrameSlotSize, 0); - value /= kFrameSlotSize; - } - DCHECK(IsShortValue(value)) << value; - region_.StoreUnaligned<ShortLocation>(offset, MakeShortLocation(kind, value)); - } else { - // Large location. Write the location on one byte and the value - // on 4 bytes. - DCHECK(!IsShortValue(value)) << value; - if (kind == DexRegisterLocation::Kind::kInStackLargeOffset) { - // Also divide large stack offsets by 4 for the sake of consistency. - DCHECK_EQ(value % kFrameSlotSize, 0); - value /= kFrameSlotSize; - } - // Data can be unaligned as the written Dex register locations can - // either be 1-byte or 5-byte wide. Use - // art::MemoryRegion::StoreUnaligned instead of - // art::MemoryRegion::Store to prevent unligned word accesses on ARM. - region_.StoreUnaligned<DexRegisterLocation::Kind>(offset, kind); - region_.StoreUnaligned<int32_t>(offset + sizeof(DexRegisterLocation::Kind), value); - } - } - - // Find the offset of the location catalog entry number `location_catalog_entry_index`. - size_t FindLocationOffset(size_t location_catalog_entry_index) const { - size_t offset = kFixedSize; - // Skip the first `location_catalog_entry_index - 1` entries. - for (uint16_t i = 0; i < location_catalog_entry_index; ++i) { - // Read the first next byte and inspect its first 3 bits to decide - // whether it is a short or a large location. - DexRegisterLocation::Kind kind = ExtractKindAtOffset(offset); - if (DexRegisterLocation::IsShortLocationKind(kind)) { - // Short location. Skip the current byte. - offset += SingleShortEntrySize(); - } else { - // Large location. Skip the 5 next bytes. - offset += SingleLargeEntrySize(); - } - } - return offset; - } - - // Get the internal kind of entry at `location_catalog_entry_index`. - DexRegisterLocation::Kind GetLocationInternalKind(size_t location_catalog_entry_index) const { - if (location_catalog_entry_index == kNoLocationEntryIndex) { - return DexRegisterLocation::Kind::kNone; - } - return ExtractKindAtOffset(FindLocationOffset(location_catalog_entry_index)); - } - - // Get the (surface) kind and value of entry at `location_catalog_entry_index`. - DexRegisterLocation GetDexRegisterLocation(size_t location_catalog_entry_index) const { - if (location_catalog_entry_index == kNoLocationEntryIndex) { - return DexRegisterLocation::None(); - } - size_t offset = FindLocationOffset(location_catalog_entry_index); - // Read the first byte and inspect its first 3 bits to get the location. - ShortLocation first_byte = region_.LoadUnaligned<ShortLocation>(offset); - DexRegisterLocation::Kind kind = ExtractKindFromShortLocation(first_byte); - if (DexRegisterLocation::IsShortLocationKind(kind)) { - // Short location. Extract the value from the remaining 5 bits. - int32_t value = ExtractValueFromShortLocation(first_byte); - if (kind == DexRegisterLocation::Kind::kInStack) { - // Convert the stack slot (short) offset to a byte offset value. - value *= kFrameSlotSize; - } - return DexRegisterLocation(kind, value); + // Create map for given number of registers and initialize all locations to None. + explicit DexRegisterMap(size_t count) : count_(count), regs_small_{} { + if (count_ <= kSmallCount) { + std::fill_n(regs_small_.begin(), count, DexRegisterLocation::None()); } else { - // Large location. Read the four next bytes to get the value. - int32_t value = region_.LoadUnaligned<int32_t>(offset + sizeof(DexRegisterLocation::Kind)); - if (kind == DexRegisterLocation::Kind::kInStackLargeOffset) { - // Convert the stack slot (large) offset to a byte offset value. - value *= kFrameSlotSize; - } - return DexRegisterLocation(kind, value); + regs_large_.resize(count, DexRegisterLocation::None()); } } - // Compute the compressed kind of `location`. - static DexRegisterLocation::Kind ComputeCompressedKind(const DexRegisterLocation& location) { - DexRegisterLocation::Kind kind = location.GetInternalKind(); - switch (kind) { - case DexRegisterLocation::Kind::kInStack: - return IsShortStackOffsetValue(location.GetValue()) - ? DexRegisterLocation::Kind::kInStack - : DexRegisterLocation::Kind::kInStackLargeOffset; - - case DexRegisterLocation::Kind::kInRegister: - case DexRegisterLocation::Kind::kInRegisterHigh: - DCHECK_GE(location.GetValue(), 0); - DCHECK_LT(location.GetValue(), 1 << kValueBits); - return kind; - - case DexRegisterLocation::Kind::kInFpuRegister: - case DexRegisterLocation::Kind::kInFpuRegisterHigh: - DCHECK_GE(location.GetValue(), 0); - DCHECK_LT(location.GetValue(), 1 << kValueBits); - return kind; - - case DexRegisterLocation::Kind::kConstant: - return IsShortConstantValue(location.GetValue()) - ? DexRegisterLocation::Kind::kConstant - : DexRegisterLocation::Kind::kConstantLargeValue; - - case DexRegisterLocation::Kind::kConstantLargeValue: - case DexRegisterLocation::Kind::kInStackLargeOffset: - case DexRegisterLocation::Kind::kNone: - LOG(FATAL) << "Unexpected location kind " << kind; - } - UNREACHABLE(); + DexRegisterLocation* data() { + return count_ <= kSmallCount ? regs_small_.data() : regs_large_.data(); } - // Can `location` be turned into a short location? - static bool CanBeEncodedAsShortLocation(const DexRegisterLocation& location) { - DexRegisterLocation::Kind kind = location.GetInternalKind(); - switch (kind) { - case DexRegisterLocation::Kind::kInStack: - return IsShortStackOffsetValue(location.GetValue()); - - case DexRegisterLocation::Kind::kInRegister: - case DexRegisterLocation::Kind::kInRegisterHigh: - case DexRegisterLocation::Kind::kInFpuRegister: - case DexRegisterLocation::Kind::kInFpuRegisterHigh: - return true; - - case DexRegisterLocation::Kind::kConstant: - return IsShortConstantValue(location.GetValue()); + size_t size() const { return count_; } - case DexRegisterLocation::Kind::kConstantLargeValue: - case DexRegisterLocation::Kind::kInStackLargeOffset: - case DexRegisterLocation::Kind::kNone: - LOG(FATAL) << "Unexpected location kind " << kind; - } - UNREACHABLE(); - } + bool IsValid() const { return count_ != 0; } - static size_t EntrySize(const DexRegisterLocation& location) { - return CanBeEncodedAsShortLocation(location) ? SingleShortEntrySize() : SingleLargeEntrySize(); + DexRegisterLocation Get(size_t index) const { + DCHECK_LT(index, count_); + return count_ <= kSmallCount ? regs_small_[index] : regs_large_[index]; } - static size_t SingleShortEntrySize() { - return sizeof(ShortLocation); - } - - static size_t SingleLargeEntrySize() { - return sizeof(DexRegisterLocation::Kind) + sizeof(int32_t); - } - - size_t Size() const { - return region_.size(); - } - - void Dump(VariableIndentationOutputStream* vios, - const CodeInfo& code_info); - - // Special (invalid) Dex register location catalog entry index meaning - // that there is no location for a given Dex register (i.e., it is - // mapped to a DexRegisterLocation::Kind::kNone location). - static constexpr size_t kNoLocationEntryIndex = -1; - - private: - static constexpr int kFixedSize = 0; - - // Width of the kind "field" in a short location, in bits. - static constexpr size_t kKindBits = 3; - // Width of the value "field" in a short location, in bits. - static constexpr size_t kValueBits = 5; - - static constexpr uint8_t kKindMask = (1 << kKindBits) - 1; - static constexpr int32_t kValueMask = (1 << kValueBits) - 1; - static constexpr size_t kKindOffset = 0; - static constexpr size_t kValueOffset = kKindBits; - - static bool IsShortStackOffsetValue(int32_t value) { - DCHECK_EQ(value % kFrameSlotSize, 0); - return IsShortValue(value / kFrameSlotSize); - } - - static bool IsShortConstantValue(int32_t value) { - return IsShortValue(value); - } - - static bool IsShortValue(int32_t value) { - return IsUint<kValueBits>(value); - } - - static ShortLocation MakeShortLocation(DexRegisterLocation::Kind kind, int32_t value) { - uint8_t kind_integer_value = static_cast<uint8_t>(kind); - DCHECK(IsUint<kKindBits>(kind_integer_value)) << kind_integer_value; - DCHECK(IsShortValue(value)) << value; - return (kind_integer_value & kKindMask) << kKindOffset - | (value & kValueMask) << kValueOffset; - } - - static DexRegisterLocation::Kind ExtractKindFromShortLocation(ShortLocation location) { - uint8_t kind = (location >> kKindOffset) & kKindMask; - DCHECK_LE(kind, static_cast<uint8_t>(DexRegisterLocation::Kind::kLastLocationKind)); - // We do not encode kNone locations in the stack map. - DCHECK_NE(kind, static_cast<uint8_t>(DexRegisterLocation::Kind::kNone)); - return static_cast<DexRegisterLocation::Kind>(kind); + DexRegisterLocation::Kind GetLocationKind(uint16_t dex_register_number) const { + return Get(dex_register_number).GetKind(); } - static int32_t ExtractValueFromShortLocation(ShortLocation location) { - return (location >> kValueOffset) & kValueMask; + // TODO: Remove. + DexRegisterLocation::Kind GetLocationInternalKind(uint16_t dex_register_number) const { + return Get(dex_register_number).GetKind(); } - // Extract a location kind from the byte at position `offset`. - DexRegisterLocation::Kind ExtractKindAtOffset(size_t offset) const { - ShortLocation first_byte = region_.LoadUnaligned<ShortLocation>(offset); - return ExtractKindFromShortLocation(first_byte); + DexRegisterLocation GetDexRegisterLocation(uint16_t dex_register_number) const { + return Get(dex_register_number); } - MemoryRegion region_; - - friend class CodeInfo; - friend class StackMapStream; -}; - -/* Information on Dex register locations for a specific PC, mapping a - * stack map's Dex register to a location entry in a DexRegisterLocationCatalog. - * The information is of the form: - * - * [live_bit_mask, entries*] - * - * where entries are concatenated unsigned integer values encoded on a number - * of bits (fixed per DexRegisterMap instances of a CodeInfo object) depending - * on the number of entries in the Dex register location catalog - * (see DexRegisterMap::SingleEntrySizeInBits). The map is 1-byte aligned. - */ -class DexRegisterMap { - public: - DexRegisterMap(MemoryRegion region, uint16_t number_of_dex_registers, const CodeInfo& code_info) - : region_(region), - number_of_dex_registers_(number_of_dex_registers), - code_info_(code_info) {} - - bool IsValid() const { return region_.IsValid(); } - - // Get the surface kind of Dex register `dex_register_number`. - DexRegisterLocation::Kind GetLocationKind(uint16_t dex_register_number) const { - return DexRegisterLocation::ConvertToSurfaceKind(GetLocationInternalKind(dex_register_number)); - } - - // Get the internal kind of Dex register `dex_register_number`. - DexRegisterLocation::Kind GetLocationInternalKind(uint16_t dex_register_number) const; - - // Get the Dex register location `dex_register_number`. - DexRegisterLocation GetDexRegisterLocation(uint16_t dex_register_number) const; - int32_t GetStackOffsetInBytes(uint16_t dex_register_number) const { - DexRegisterLocation location = GetDexRegisterLocation(dex_register_number); + DexRegisterLocation location = Get(dex_register_number); DCHECK(location.GetKind() == DexRegisterLocation::Kind::kInStack); - // GetDexRegisterLocation returns the offset in bytes. return location.GetValue(); } int32_t GetConstant(uint16_t dex_register_number) const { - DexRegisterLocation location = GetDexRegisterLocation(dex_register_number); - DCHECK_EQ(location.GetKind(), DexRegisterLocation::Kind::kConstant); + DexRegisterLocation location = Get(dex_register_number); + DCHECK(location.GetKind() == DexRegisterLocation::Kind::kConstant); return location.GetValue(); } int32_t GetMachineRegister(uint16_t dex_register_number) const { - DexRegisterLocation location = GetDexRegisterLocation(dex_register_number); - DCHECK(location.GetInternalKind() == DexRegisterLocation::Kind::kInRegister || - location.GetInternalKind() == DexRegisterLocation::Kind::kInRegisterHigh || - location.GetInternalKind() == DexRegisterLocation::Kind::kInFpuRegister || - location.GetInternalKind() == DexRegisterLocation::Kind::kInFpuRegisterHigh) - << location.GetInternalKind(); + DexRegisterLocation location = Get(dex_register_number); + DCHECK(location.GetKind() == DexRegisterLocation::Kind::kInRegister || + location.GetKind() == DexRegisterLocation::Kind::kInRegisterHigh || + location.GetKind() == DexRegisterLocation::Kind::kInFpuRegister || + location.GetKind() == DexRegisterLocation::Kind::kInFpuRegisterHigh); return location.GetValue(); } - // Get the index of the entry in the Dex register location catalog - // corresponding to `dex_register_number`. - size_t GetLocationCatalogEntryIndex(uint16_t dex_register_number, - size_t number_of_location_catalog_entries) const { - if (!IsDexRegisterLive(dex_register_number)) { - return DexRegisterLocationCatalog::kNoLocationEntryIndex; - } - - if (number_of_location_catalog_entries == 1) { - // We do not allocate space for location maps in the case of a - // single-entry location catalog, as it is useless. The only valid - // entry index is 0; - return 0; - } - - // The bit offset of the beginning of the map locations. - size_t map_locations_offset_in_bits = - GetLocationMappingDataOffset(number_of_dex_registers_) * kBitsPerByte; - size_t index_in_dex_register_map = GetIndexInDexRegisterMap(dex_register_number); - DCHECK_LT(index_in_dex_register_map, GetNumberOfLiveDexRegisters()); - // The bit size of an entry. - size_t map_entry_size_in_bits = SingleEntrySizeInBits(number_of_location_catalog_entries); - // The bit offset where `index_in_dex_register_map` is located. - size_t entry_offset_in_bits = - map_locations_offset_in_bits + index_in_dex_register_map * map_entry_size_in_bits; - size_t location_catalog_entry_index = - region_.LoadBits(entry_offset_in_bits, map_entry_size_in_bits); - DCHECK_LT(location_catalog_entry_index, number_of_location_catalog_entries); - return location_catalog_entry_index; - } - - // Map entry at `index_in_dex_register_map` to `location_catalog_entry_index`. - void SetLocationCatalogEntryIndex(size_t index_in_dex_register_map, - size_t location_catalog_entry_index, - size_t number_of_location_catalog_entries) { - DCHECK_LT(index_in_dex_register_map, GetNumberOfLiveDexRegisters()); - DCHECK_LT(location_catalog_entry_index, number_of_location_catalog_entries); - - if (number_of_location_catalog_entries == 1) { - // We do not allocate space for location maps in the case of a - // single-entry location catalog, as it is useless. - return; - } - - // The bit offset of the beginning of the map locations. - size_t map_locations_offset_in_bits = - GetLocationMappingDataOffset(number_of_dex_registers_) * kBitsPerByte; - // The bit size of an entry. - size_t map_entry_size_in_bits = SingleEntrySizeInBits(number_of_location_catalog_entries); - // The bit offset where `index_in_dex_register_map` is located. - size_t entry_offset_in_bits = - map_locations_offset_in_bits + index_in_dex_register_map * map_entry_size_in_bits; - region_.StoreBits(entry_offset_in_bits, location_catalog_entry_index, map_entry_size_in_bits); - } - - void SetLiveBitMask(uint16_t number_of_dex_registers, - const BitVector& live_dex_registers_mask) { - size_t live_bit_mask_offset_in_bits = GetLiveBitMaskOffset() * kBitsPerByte; - for (uint16_t i = 0; i < number_of_dex_registers; ++i) { - region_.StoreBit(live_bit_mask_offset_in_bits + i, live_dex_registers_mask.IsBitSet(i)); - } - } - ALWAYS_INLINE bool IsDexRegisterLive(uint16_t dex_register_number) const { - size_t live_bit_mask_offset_in_bits = GetLiveBitMaskOffset() * kBitsPerByte; - return region_.LoadBit(live_bit_mask_offset_in_bits + dex_register_number); + return Get(dex_register_number).IsLive(); } - size_t GetNumberOfLiveDexRegisters(uint16_t number_of_dex_registers) const { + size_t GetNumberOfLiveDexRegisters() const { size_t number_of_live_dex_registers = 0; - for (size_t i = 0; i < number_of_dex_registers; ++i) { + for (size_t i = 0; i < count_; ++i) { if (IsDexRegisterLive(i)) { ++number_of_live_dex_registers; } @@ -564,74 +119,22 @@ class DexRegisterMap { return number_of_live_dex_registers; } - size_t GetNumberOfLiveDexRegisters() const { - return GetNumberOfLiveDexRegisters(number_of_dex_registers_); - } - - static size_t GetLiveBitMaskOffset() { - return kFixedSize; - } - - // Compute the size of the live register bit mask (in bytes), for a - // method having `number_of_dex_registers` Dex registers. - static size_t GetLiveBitMaskSize(uint16_t number_of_dex_registers) { - return RoundUp(number_of_dex_registers, kBitsPerByte) / kBitsPerByte; - } - - static size_t GetLocationMappingDataOffset(uint16_t number_of_dex_registers) { - return GetLiveBitMaskOffset() + GetLiveBitMaskSize(number_of_dex_registers); - } - - size_t GetLocationMappingDataSize(size_t number_of_location_catalog_entries) const { - size_t location_mapping_data_size_in_bits = - GetNumberOfLiveDexRegisters() - * SingleEntrySizeInBits(number_of_location_catalog_entries); - return RoundUp(location_mapping_data_size_in_bits, kBitsPerByte) / kBitsPerByte; - } - - // Return the size of a map entry in bits. Note that if - // `number_of_location_catalog_entries` equals 1, this function returns 0, - // which is fine, as there is no need to allocate a map for a - // single-entry location catalog; the only valid location catalog entry index - // for a live register in this case is 0 and there is no need to - // store it. - static size_t SingleEntrySizeInBits(size_t number_of_location_catalog_entries) { - // Handle the case of 0, as we cannot pass 0 to art::WhichPowerOf2. - return number_of_location_catalog_entries == 0 - ? 0u - : WhichPowerOf2(RoundUpToPowerOfTwo(number_of_location_catalog_entries)); - } - - // Return the size of the DexRegisterMap object, in bytes. - size_t Size() const { - return BitsToBytesRoundUp(region_.size_in_bits()); - } - - void Dump(VariableIndentationOutputStream* vios) const; - - private: - // Return the index in the Dex register map corresponding to the Dex - // register number `dex_register_number`. - size_t GetIndexInDexRegisterMap(uint16_t dex_register_number) const { - if (!IsDexRegisterLive(dex_register_number)) { - return kInvalidIndexInDexRegisterMap; + bool HasAnyLiveDexRegisters() const { + for (size_t i = 0; i < count_; ++i) { + if (IsDexRegisterLive(i)) { + return true; + } } - return GetNumberOfLiveDexRegisters(dex_register_number); + return false; } - // Special (invalid) Dex register map entry index meaning that there - // is no index in the map for a given Dex register (i.e., it must - // have been mapped to a DexRegisterLocation::Kind::kNone location). - static constexpr size_t kInvalidIndexInDexRegisterMap = -1; - - static constexpr int kFixedSize = 0; - - BitMemoryRegion region_; - uint16_t number_of_dex_registers_; - const CodeInfo& code_info_; - - friend class CodeInfo; - friend class StackMapStream; + private: + // Store the data inline if the number of registers is small to avoid memory allocations. + // If count_ <= kSmallCount, we use the regs_small_ array, and regs_large_ otherwise. + static constexpr size_t kSmallCount = 16; + size_t count_; + std::array<DexRegisterLocation, kSmallCount> regs_small_; + dchecked_vector<DexRegisterLocation> regs_large_; }; /** @@ -642,15 +145,16 @@ class DexRegisterMap { * - Knowing the inlining information, * - Knowing the values of dex registers. */ -class StackMap : public BitTable<6>::Accessor { +class StackMap : public BitTable<7>::Accessor { public: enum Field { kPackedNativePc, kDexPc, - kDexRegisterMapOffset, - kInlineInfoIndex, kRegisterMaskIndex, kStackMaskIndex, + kInlineInfoIndex, + kDexRegisterMaskIndex, + kDexRegisterMapIndex, kCount, }; @@ -664,8 +168,10 @@ class StackMap : public BitTable<6>::Accessor { uint32_t GetDexPc() const { return Get<kDexPc>(); } - uint32_t GetDexRegisterMapOffset() const { return Get<kDexRegisterMapOffset>(); } - bool HasDexRegisterMap() const { return GetDexRegisterMapOffset() != kNoValue; } + uint32_t GetDexRegisterMaskIndex() const { return Get<kDexRegisterMaskIndex>(); } + + uint32_t GetDexRegisterMapIndex() const { return Get<kDexRegisterMapIndex>(); } + bool HasDexRegisterMap() const { return GetDexRegisterMapIndex() != kNoValue; } uint32_t GetInlineInfoIndex() const { return Get<kInlineInfoIndex>(); } bool HasInlineInfo() const { return GetInlineInfoIndex() != kNoValue; } @@ -675,7 +181,7 @@ class StackMap : public BitTable<6>::Accessor { uint32_t GetStackMaskIndex() const { return Get<kStackMaskIndex>(); } static uint32_t PackNativePc(uint32_t native_pc, InstructionSet isa) { - // TODO: DCHECK_ALIGNED_PARAM(native_pc, GetInstructionSetInstructionAlignment(isa)); + DCHECK_ALIGNED_PARAM(native_pc, GetInstructionSetInstructionAlignment(isa)); return native_pc / GetInstructionSetInstructionAlignment(isa); } @@ -685,14 +191,12 @@ class StackMap : public BitTable<6>::Accessor { return native_pc; } - static void DumpEncoding(const BitTable<6>& table, VariableIndentationOutputStream* vios); void Dump(VariableIndentationOutputStream* vios, const CodeInfo& code_info, const MethodInfo& method_info, uint32_t code_offset, uint16_t number_of_dex_registers, - InstructionSet instruction_set, - const std::string& header_suffix = "") const; + InstructionSet instruction_set) const; }; /** @@ -700,14 +204,16 @@ class StackMap : public BitTable<6>::Accessor { * The row referenced from the StackMap holds information at depth 0. * Following rows hold information for further depths. */ -class InlineInfo : public BitTable<5>::Accessor { +class InlineInfo : public BitTable<7>::Accessor { public: enum Field { kIsLast, // Determines if there are further rows for further depths. - kMethodIndexIdx, // Method index or ArtMethod high bits. kDexPc, - kExtraData, // ArtMethod low bits or 1. - kDexRegisterMapOffset, + kMethodIndexIdx, + kArtMethodHi, // High bits of ArtMethod*. + kArtMethodLo, // Low bits of ArtMethod*. + kDexRegisterMaskIndex, + kDexRegisterMapIndex, kCount, }; static constexpr uint32_t kLast = -1; @@ -740,30 +246,26 @@ class InlineInfo : public BitTable<5>::Accessor { } bool EncodesArtMethodAtDepth(uint32_t depth) const { - return (AtDepth(depth).Get<kExtraData>() & 1) == 0; + return AtDepth(depth).Get<kArtMethodLo>() != kNoValue; } ArtMethod* GetArtMethodAtDepth(uint32_t depth) const { - uint32_t low_bits = AtDepth(depth).Get<kExtraData>(); - uint32_t high_bits = AtDepth(depth).Get<kMethodIndexIdx>(); - if (high_bits == 0) { - return reinterpret_cast<ArtMethod*>(low_bits); - } else { - uint64_t address = high_bits; - address = address << 32; - return reinterpret_cast<ArtMethod*>(address | low_bits); - } + uint64_t lo = AtDepth(depth).Get<kArtMethodLo>(); + uint64_t hi = AtDepth(depth).Get<kArtMethodHi>(); + return reinterpret_cast<ArtMethod*>((hi << 32) | lo); } - uint32_t GetDexRegisterMapOffsetAtDepth(uint32_t depth) const { - return AtDepth(depth).Get<kDexRegisterMapOffset>(); + uint32_t GetDexRegisterMaskIndexAtDepth(uint32_t depth) const { + return AtDepth(depth).Get<kDexRegisterMaskIndex>(); } + uint32_t GetDexRegisterMapIndexAtDepth(uint32_t depth) const { + return AtDepth(depth).Get<kDexRegisterMapIndex>(); + } bool HasDexRegisterMapAtDepth(uint32_t depth) const { - return GetDexRegisterMapOffsetAtDepth(depth) != StackMap::kNoValue; + return GetDexRegisterMapIndexAtDepth(depth) != kNoValue; } - static void DumpEncoding(const BitTable<5>& table, VariableIndentationOutputStream* vios); void Dump(VariableIndentationOutputStream* vios, const CodeInfo& info, const MethodInfo& method_info, @@ -795,6 +297,40 @@ class InvokeInfo : public BitTable<3>::Accessor { } }; +class DexRegisterInfo : public BitTable<2>::Accessor { + public: + enum Field { + kKind, + kPackedValue, + kCount, + }; + + DexRegisterInfo(const BitTable<kCount>* table, uint32_t row) + : BitTable<kCount>::Accessor(table, row) {} + + ALWAYS_INLINE DexRegisterLocation GetLocation() const { + DexRegisterLocation::Kind kind = static_cast<DexRegisterLocation::Kind>(Get<kKind>()); + return DexRegisterLocation(kind, UnpackValue(kind, Get<kPackedValue>())); + } + + static uint32_t PackValue(DexRegisterLocation::Kind kind, uint32_t value) { + uint32_t packed_value = value; + if (kind == DexRegisterLocation::Kind::kInStack) { + DCHECK(IsAligned<kFrameSlotSize>(packed_value)); + packed_value /= kFrameSlotSize; + } + return packed_value; + } + + static uint32_t UnpackValue(DexRegisterLocation::Kind kind, uint32_t packed_value) { + uint32_t value = packed_value; + if (kind == DexRegisterLocation::Kind::kInStack) { + value *= kFrameSlotSize; + } + return value; + } +}; + // Register masks tend to have many trailing zero bits (caller-saves are usually not encoded), // therefore it is worth encoding the mask as value+shift. class RegisterMask : public BitTable<2>::Accessor { @@ -815,11 +351,7 @@ class RegisterMask : public BitTable<2>::Accessor { /** * Wrapper around all compiler information collected for a method. - * The information is of the form: - * - * [BitTable<Header>, BitTable<StackMap>, BitTable<RegisterMask>, BitTable<InlineInfo>, - * BitTable<InvokeInfo>, BitTable<StackMask>, DexRegisterMap, DexLocationCatalog] - * + * See the Decode method at the end for the precise binary format. */ class CodeInfo { public: @@ -840,11 +372,7 @@ class CodeInfo { } bool HasInlineInfo() const { - return stack_maps_.NumColumnBits(StackMap::kInlineInfoIndex) != 0; - } - - DexRegisterLocationCatalog GetDexRegisterLocationCatalog() const { - return DexRegisterLocationCatalog(location_catalog_); + return inline_infos_.NumRows() > 0; } ALWAYS_INLINE StackMap GetStackMapAt(size_t index) const { @@ -866,11 +394,11 @@ class CodeInfo { } uint32_t GetNumberOfLocationCatalogEntries() const { - return location_catalog_entries_; + return dex_register_catalog_.NumRows(); } - uint32_t GetDexRegisterLocationCatalogSize() const { - return location_catalog_.size(); + ALWAYS_INLINE DexRegisterLocation GetDexRegisterCatalogEntry(size_t index) const { + return DexRegisterInfo(&dex_register_catalog_, index).GetLocation(); } uint32_t GetNumberOfStackMaps() const { @@ -881,41 +409,19 @@ class CodeInfo { return InvokeInfo(&invoke_infos_, index); } - DexRegisterMap GetDexRegisterMapOf(StackMap stack_map, - size_t number_of_dex_registers) const { - if (!stack_map.HasDexRegisterMap()) { - return DexRegisterMap(MemoryRegion(), 0, *this); - } - const uint32_t offset = stack_map.GetDexRegisterMapOffset(); - size_t size = ComputeDexRegisterMapSizeOf(offset, number_of_dex_registers); - return DexRegisterMap(dex_register_maps_.Subregion(offset, size), - number_of_dex_registers, - *this); - } - - size_t GetDexRegisterMapsSize(uint32_t number_of_dex_registers) const { - size_t total = 0; - for (size_t i = 0, e = GetNumberOfStackMaps(); i < e; ++i) { - StackMap stack_map = GetStackMapAt(i); - DexRegisterMap map(GetDexRegisterMapOf(stack_map, number_of_dex_registers)); - total += map.Size(); - } - return total; + ALWAYS_INLINE DexRegisterMap GetDexRegisterMapOf(StackMap stack_map, + size_t num_dex_registers) const { + return DecodeDexRegisterMap(stack_map.GetDexRegisterMaskIndex(), + stack_map.GetDexRegisterMapIndex(), + num_dex_registers); } - // Return the `DexRegisterMap` pointed by `inline_info` at depth `depth`. - DexRegisterMap GetDexRegisterMapAtDepth(uint8_t depth, - InlineInfo inline_info, - uint32_t number_of_dex_registers) const { - if (!inline_info.HasDexRegisterMapAtDepth(depth)) { - return DexRegisterMap(MemoryRegion(), 0, *this); - } else { - uint32_t offset = inline_info.GetDexRegisterMapOffsetAtDepth(depth); - size_t size = ComputeDexRegisterMapSizeOf(offset, number_of_dex_registers); - return DexRegisterMap(dex_register_maps_.Subregion(offset, size), - number_of_dex_registers, - *this); - } + ALWAYS_INLINE DexRegisterMap GetDexRegisterMapAtDepth(uint8_t depth, + InlineInfo inline_info, + size_t num_dex_registers) const { + return DecodeDexRegisterMap(inline_info.GetDexRegisterMaskIndexAtDepth(depth), + inline_info.GetDexRegisterMapIndexAtDepth(depth), + num_dex_registers); } InlineInfo GetInlineInfo(size_t index) const { @@ -965,8 +471,8 @@ class CodeInfo { if (other.GetDexPc() == dex_pc && other.GetNativePcOffset(kRuntimeISA) == stack_map.GetNativePcOffset(kRuntimeISA)) { - DCHECK_EQ(other.GetDexRegisterMapOffset(), - stack_map.GetDexRegisterMapOffset()); + DCHECK_EQ(other.GetDexRegisterMapIndex(), + stack_map.GetDexRegisterMapIndex()); DCHECK(!stack_map.HasInlineInfo()); if (i < e - 2) { // Make sure there are not three identical stack maps following each other. @@ -1004,81 +510,61 @@ class CodeInfo { return InvokeInfo(&invoke_infos_, -1); } - // Dump this CodeInfo object on `os`. `code_offset` is the (absolute) - // native PC of the compiled method and `number_of_dex_registers` the - // number of Dex virtual registers used in this method. If - // `dump_stack_maps` is true, also dump the stack maps and the - // associated Dex register maps. + // Dump this CodeInfo object on `vios`. + // `code_offset` is the (absolute) native PC of the compiled method. void Dump(VariableIndentationOutputStream* vios, uint32_t code_offset, uint16_t number_of_dex_registers, - bool dump_stack_maps, + bool verbose, InstructionSet instruction_set, const MethodInfo& method_info) const; private: - // Compute the size of the Dex register map associated to the stack map at - // `dex_register_map_offset_in_code_info`. - size_t ComputeDexRegisterMapSizeOf(uint32_t dex_register_map_offset, - uint16_t number_of_dex_registers) const { - // Offset where the actual mapping data starts within art::DexRegisterMap. - size_t location_mapping_data_offset_in_dex_register_map = - DexRegisterMap::GetLocationMappingDataOffset(number_of_dex_registers); - // Create a temporary art::DexRegisterMap to be able to call - // art::DexRegisterMap::GetNumberOfLiveDexRegisters and - DexRegisterMap dex_register_map_without_locations( - MemoryRegion(dex_register_maps_.Subregion(dex_register_map_offset, - location_mapping_data_offset_in_dex_register_map)), - number_of_dex_registers, - *this); - size_t number_of_live_dex_registers = - dex_register_map_without_locations.GetNumberOfLiveDexRegisters(); - size_t location_mapping_data_size_in_bits = - DexRegisterMap::SingleEntrySizeInBits(GetNumberOfLocationCatalogEntries()) - * number_of_live_dex_registers; - size_t location_mapping_data_size_in_bytes = - RoundUp(location_mapping_data_size_in_bits, kBitsPerByte) / kBitsPerByte; - size_t dex_register_map_size = - location_mapping_data_offset_in_dex_register_map + location_mapping_data_size_in_bytes; - return dex_register_map_size; - } - - MemoryRegion DecodeMemoryRegion(MemoryRegion& region, size_t* bit_offset) { - size_t length = DecodeVarintBits(BitMemoryRegion(region), bit_offset); - size_t offset = BitsToBytesRoundUp(*bit_offset);; - *bit_offset = (offset + length) * kBitsPerByte; - return region.Subregion(offset, length); + ALWAYS_INLINE DexRegisterMap DecodeDexRegisterMap(uint32_t mask_index, + uint32_t map_index, + uint32_t num_dex_registers) const { + DexRegisterMap map(map_index == StackMap::kNoValue ? 0 : num_dex_registers); + if (mask_index != StackMap::kNoValue) { + BitMemoryRegion mask = dex_register_masks_.GetBitMemoryRegion(mask_index); + num_dex_registers = std::min<uint32_t>(num_dex_registers, mask.size_in_bits()); + DexRegisterLocation* regs = map.data(); + for (uint32_t r = 0; r < mask.size_in_bits(); r++) { + if (mask.LoadBit(r) /* is_live */) { + DCHECK_LT(r, map.size()); + regs[r] = GetDexRegisterCatalogEntry(dex_register_maps_.Get(map_index++)); + } + } + } + return map; } void Decode(const uint8_t* data) { size_t non_header_size = DecodeUnsignedLeb128(&data); - MemoryRegion region(const_cast<uint8_t*>(data), non_header_size); - BitMemoryRegion bit_region(region); + BitMemoryRegion region(MemoryRegion(const_cast<uint8_t*>(data), non_header_size)); size_t bit_offset = 0; size_ = UnsignedLeb128Size(non_header_size) + non_header_size; - dex_register_maps_ = DecodeMemoryRegion(region, &bit_offset); - location_catalog_entries_ = DecodeVarintBits(bit_region, &bit_offset); - location_catalog_ = DecodeMemoryRegion(region, &bit_offset); - stack_maps_.Decode(bit_region, &bit_offset); - invoke_infos_.Decode(bit_region, &bit_offset); - inline_infos_.Decode(bit_region, &bit_offset); - register_masks_.Decode(bit_region, &bit_offset); - stack_masks_.Decode(bit_region, &bit_offset); - CHECK_EQ(BitsToBytesRoundUp(bit_offset), non_header_size); + stack_maps_.Decode(region, &bit_offset); + register_masks_.Decode(region, &bit_offset); + stack_masks_.Decode(region, &bit_offset); + invoke_infos_.Decode(region, &bit_offset); + inline_infos_.Decode(region, &bit_offset); + dex_register_masks_.Decode(region, &bit_offset); + dex_register_maps_.Decode(region, &bit_offset); + dex_register_catalog_.Decode(region, &bit_offset); + CHECK_EQ(non_header_size, BitsToBytesRoundUp(bit_offset)) << "Invalid CodeInfo"; } size_t size_; - MemoryRegion dex_register_maps_; - uint32_t location_catalog_entries_; - MemoryRegion location_catalog_; BitTable<StackMap::Field::kCount> stack_maps_; - BitTable<InvokeInfo::Field::kCount> invoke_infos_; - BitTable<InlineInfo::Field::kCount> inline_infos_; BitTable<RegisterMask::Field::kCount> register_masks_; BitTable<1> stack_masks_; + BitTable<InvokeInfo::Field::kCount> invoke_infos_; + BitTable<InlineInfo::Field::kCount> inline_infos_; + BitTable<1> dex_register_masks_; + BitTable<1> dex_register_maps_; + BitTable<DexRegisterInfo::Field::kCount> dex_register_catalog_; friend class OatDumper; - friend class StackMapStream; }; #undef ELEMENT_BYTE_OFFSET_AFTER diff --git a/runtime/thread.cc b/runtime/thread.cc index ab1a4bba6c..b59606a06b 100644 --- a/runtime/thread.cc +++ b/runtime/thread.cc @@ -2862,27 +2862,18 @@ jobjectArray Thread::CreateAnnotatedStackTrace(const ScopedObjectAccessAlreadyRu ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); StackHandleScope<6> hs(soa.Self()); - mirror::Class* aste_array_class = class_linker->FindClass( + Handle<mirror::Class> h_aste_array_class = hs.NewHandle(class_linker->FindSystemClass( soa.Self(), - "[Ldalvik/system/AnnotatedStackTraceElement;", - ScopedNullHandle<mirror::ClassLoader>()); - if (aste_array_class == nullptr) { + "[Ldalvik/system/AnnotatedStackTraceElement;")); + if (h_aste_array_class == nullptr) { return nullptr; } - Handle<mirror::Class> h_aste_array_class(hs.NewHandle<mirror::Class>(aste_array_class)); + Handle<mirror::Class> h_aste_class = hs.NewHandle(h_aste_array_class->GetComponentType()); - mirror::Class* o_array_class = class_linker->FindClass(soa.Self(), - "[Ljava/lang/Object;", - ScopedNullHandle<mirror::ClassLoader>()); - if (o_array_class == nullptr) { - // This should not fail in a healthy runtime. - soa.Self()->AssertPendingException(); - return nullptr; - } - Handle<mirror::Class> h_o_array_class(hs.NewHandle<mirror::Class>(o_array_class)); + Handle<mirror::Class> h_o_array_class = + hs.NewHandle(GetClassRoot<mirror::ObjectArray<mirror::Object>>(class_linker)); + DCHECK(h_o_array_class != nullptr); // Class roots must be already initialized. - Handle<mirror::Class> h_aste_class(hs.NewHandle<mirror::Class>( - h_aste_array_class->GetComponentType())); // Make sure the AnnotatedStackTraceElement.class is initialized, b/76208924 . class_linker->EnsureInitialized(soa.Self(), @@ -2906,7 +2897,7 @@ jobjectArray Thread::CreateAnnotatedStackTrace(const ScopedObjectAccessAlreadyRu size_t length = dumper.stack_trace_elements_.size(); ObjPtr<mirror::ObjectArray<mirror::Object>> array = - mirror::ObjectArray<mirror::Object>::Alloc(soa.Self(), aste_array_class, length); + mirror::ObjectArray<mirror::Object>::Alloc(soa.Self(), h_aste_array_class.Get(), length); if (array == nullptr) { soa.Self()->AssertPendingOOMException(); return nullptr; diff --git a/runtime/verifier/method_verifier.cc b/runtime/verifier/method_verifier.cc index cc71dc5f84..2e3a6590e4 100644 --- a/runtime/verifier/method_verifier.cc +++ b/runtime/verifier/method_verifier.cc @@ -144,7 +144,7 @@ static void SafelyMarkAllRegistersAsConflicts(MethodVerifier* verifier, Register } FailureKind MethodVerifier::VerifyClass(Thread* self, - mirror::Class* klass, + ObjPtr<mirror::Class> klass, CompilerCallbacks* callbacks, bool allow_soft_failures, HardFailLogMode log_level, diff --git a/runtime/verifier/method_verifier.h b/runtime/verifier/method_verifier.h index b2adc62a97..ae7481c6b1 100644 --- a/runtime/verifier/method_verifier.h +++ b/runtime/verifier/method_verifier.h @@ -96,7 +96,7 @@ class MethodVerifier { public: // Verify a class. Returns "kNoFailure" on success. static FailureKind VerifyClass(Thread* self, - mirror::Class* klass, + ObjPtr<mirror::Class> klass, CompilerCallbacks* callbacks, bool allow_soft_failures, HardFailLogMode log_level, diff --git a/runtime/verifier/method_verifier_test.cc b/runtime/verifier/method_verifier_test.cc index db3f093905..d1be9fa6f8 100644 --- a/runtime/verifier/method_verifier_test.cc +++ b/runtime/verifier/method_verifier_test.cc @@ -37,7 +37,7 @@ class MethodVerifierTest : public CommonRuntimeTest { REQUIRES_SHARED(Locks::mutator_lock_) { ASSERT_TRUE(descriptor != nullptr); Thread* self = Thread::Current(); - mirror::Class* klass = class_linker_->FindSystemClass(self, descriptor.c_str()); + ObjPtr<mirror::Class> klass = class_linker_->FindSystemClass(self, descriptor.c_str()); // Verify the class std::string error_msg; diff --git a/runtime/well_known_classes.cc b/runtime/well_known_classes.cc index f7cdf3920a..c64e7bbca1 100644 --- a/runtime/well_known_classes.cc +++ b/runtime/well_known_classes.cc @@ -55,8 +55,6 @@ jclass WellKnownClasses::java_lang_ClassLoader; jclass WellKnownClasses::java_lang_ClassNotFoundException; jclass WellKnownClasses::java_lang_Daemons; jclass WellKnownClasses::java_lang_Error; -jclass WellKnownClasses::java_lang_invoke_MethodHandle; -jclass WellKnownClasses::java_lang_invoke_VarHandle; jclass WellKnownClasses::java_lang_IllegalAccessError; jclass WellKnownClasses::java_lang_NoClassDefFoundError; jclass WellKnownClasses::java_lang_Object; @@ -74,7 +72,6 @@ jclass WellKnownClasses::java_lang_ThreadGroup; jclass WellKnownClasses::java_lang_Throwable; jclass WellKnownClasses::java_nio_ByteBuffer; jclass WellKnownClasses::java_nio_DirectByteBuffer; -jclass WellKnownClasses::java_util_ArrayList; jclass WellKnownClasses::java_util_Collections; jclass WellKnownClasses::java_util_function_Consumer; jclass WellKnownClasses::libcore_reflect_AnnotationFactory; @@ -90,14 +87,11 @@ jmethodID WellKnownClasses::java_lang_Byte_valueOf; jmethodID WellKnownClasses::java_lang_Character_valueOf; jmethodID WellKnownClasses::java_lang_ClassLoader_loadClass; jmethodID WellKnownClasses::java_lang_ClassNotFoundException_init; -jmethodID WellKnownClasses::java_lang_Daemons_requestHeapTrim; jmethodID WellKnownClasses::java_lang_Daemons_start; jmethodID WellKnownClasses::java_lang_Daemons_stop; jmethodID WellKnownClasses::java_lang_Double_valueOf; jmethodID WellKnownClasses::java_lang_Float_valueOf; jmethodID WellKnownClasses::java_lang_Integer_valueOf; -jmethodID WellKnownClasses::java_lang_invoke_MethodHandle_invoke; -jmethodID WellKnownClasses::java_lang_invoke_MethodHandle_invokeExact; jmethodID WellKnownClasses::java_lang_invoke_MethodHandles_lookup; jmethodID WellKnownClasses::java_lang_invoke_MethodHandles_Lookup_findConstructor; jmethodID WellKnownClasses::java_lang_Long_valueOf; @@ -108,7 +102,6 @@ jmethodID WellKnownClasses::java_lang_reflect_Proxy_invoke; jmethodID WellKnownClasses::java_lang_Runtime_nativeLoad; jmethodID WellKnownClasses::java_lang_Short_valueOf; jmethodID WellKnownClasses::java_lang_String_charAt; -jmethodID WellKnownClasses::java_lang_System_runFinalization = nullptr; jmethodID WellKnownClasses::java_lang_Thread_dispatchUncaughtException; jmethodID WellKnownClasses::java_lang_Thread_init; jmethodID WellKnownClasses::java_lang_Thread_run; @@ -144,7 +137,6 @@ jfieldID WellKnownClasses::java_lang_Throwable_detailMessage; jfieldID WellKnownClasses::java_lang_Throwable_stackTrace; jfieldID WellKnownClasses::java_lang_Throwable_stackState; jfieldID WellKnownClasses::java_lang_Throwable_suppressedExceptions; -jfieldID WellKnownClasses::java_lang_reflect_Proxy_h; jfieldID WellKnownClasses::java_nio_ByteBuffer_address; jfieldID WellKnownClasses::java_nio_ByteBuffer_hb; jfieldID WellKnownClasses::java_nio_ByteBuffer_isReadOnly; @@ -152,8 +144,6 @@ jfieldID WellKnownClasses::java_nio_ByteBuffer_limit; jfieldID WellKnownClasses::java_nio_ByteBuffer_offset; jfieldID WellKnownClasses::java_nio_DirectByteBuffer_capacity; jfieldID WellKnownClasses::java_nio_DirectByteBuffer_effectiveDirectAddress; -jfieldID WellKnownClasses::java_util_ArrayList_array; -jfieldID WellKnownClasses::java_util_ArrayList_size; jfieldID WellKnownClasses::java_util_Collections_EMPTY_LIST; jfieldID WellKnownClasses::libcore_util_EmptyArray_STACK_TRACE_ELEMENT; jfieldID WellKnownClasses::org_apache_harmony_dalvik_ddmc_Chunk_data; @@ -323,8 +313,6 @@ void WellKnownClasses::Init(JNIEnv* env) { java_lang_OutOfMemoryError = CacheClass(env, "java/lang/OutOfMemoryError"); java_lang_Error = CacheClass(env, "java/lang/Error"); java_lang_IllegalAccessError = CacheClass(env, "java/lang/IllegalAccessError"); - java_lang_invoke_MethodHandle = CacheClass(env, "java/lang/invoke/MethodHandle"); - java_lang_invoke_VarHandle = CacheClass(env, "java/lang/invoke/VarHandle"); java_lang_NoClassDefFoundError = CacheClass(env, "java/lang/NoClassDefFoundError"); java_lang_reflect_Parameter = CacheClass(env, "java/lang/reflect/Parameter"); java_lang_reflect_Parameter__array = CacheClass(env, "[Ljava/lang/reflect/Parameter;"); @@ -339,7 +327,6 @@ void WellKnownClasses::Init(JNIEnv* env) { java_lang_Throwable = CacheClass(env, "java/lang/Throwable"); java_nio_ByteBuffer = CacheClass(env, "java/nio/ByteBuffer"); java_nio_DirectByteBuffer = CacheClass(env, "java/nio/DirectByteBuffer"); - java_util_ArrayList = CacheClass(env, "java/util/ArrayList"); java_util_Collections = CacheClass(env, "java/util/Collections"); java_util_function_Consumer = CacheClass(env, "java/util/function/Consumer"); libcore_reflect_AnnotationFactory = CacheClass(env, "libcore/reflect/AnnotationFactory"); @@ -353,11 +340,8 @@ void WellKnownClasses::Init(JNIEnv* env) { java_lang_ClassNotFoundException_init = CacheMethod(env, java_lang_ClassNotFoundException, false, "<init>", "(Ljava/lang/String;Ljava/lang/Throwable;)V"); java_lang_ClassLoader_loadClass = CacheMethod(env, java_lang_ClassLoader, false, "loadClass", "(Ljava/lang/String;)Ljava/lang/Class;"); - java_lang_Daemons_requestHeapTrim = CacheMethod(env, java_lang_Daemons, true, "requestHeapTrim", "()V"); java_lang_Daemons_start = CacheMethod(env, java_lang_Daemons, true, "start", "()V"); java_lang_Daemons_stop = CacheMethod(env, java_lang_Daemons, true, "stop", "()V"); - java_lang_invoke_MethodHandle_invoke = CacheMethod(env, java_lang_invoke_MethodHandle, false, "invoke", "([Ljava/lang/Object;)Ljava/lang/Object;"); - java_lang_invoke_MethodHandle_invokeExact = CacheMethod(env, java_lang_invoke_MethodHandle, false, "invokeExact", "([Ljava/lang/Object;)Ljava/lang/Object;"); java_lang_invoke_MethodHandles_lookup = CacheMethod(env, "java/lang/invoke/MethodHandles", true, "lookup", "()Ljava/lang/invoke/MethodHandles$Lookup;"); java_lang_invoke_MethodHandles_Lookup_findConstructor = CacheMethod(env, "java/lang/invoke/MethodHandles$Lookup", false, "findConstructor", "(Ljava/lang/Class;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/MethodHandle;"); @@ -408,8 +392,6 @@ void WellKnownClasses::Init(JNIEnv* env) { java_nio_ByteBuffer_offset = CacheField(env, java_nio_ByteBuffer, false, "offset", "I"); java_nio_DirectByteBuffer_capacity = CacheField(env, java_nio_DirectByteBuffer, false, "capacity", "I"); java_nio_DirectByteBuffer_effectiveDirectAddress = CacheField(env, java_nio_DirectByteBuffer, false, "address", "J"); - java_util_ArrayList_array = CacheField(env, java_util_ArrayList, false, "elementData", "[Ljava/lang/Object;"); - java_util_ArrayList_size = CacheField(env, java_util_ArrayList, false, "size", "I"); java_util_Collections_EMPTY_LIST = CacheField(env, java_util_Collections, true, "EMPTY_LIST", "Ljava/util/List;"); libcore_util_EmptyArray_STACK_TRACE_ELEMENT = CacheField(env, libcore_util_EmptyArray, true, "STACK_TRACE_ELEMENT", "[Ljava/lang/StackTraceElement;"); org_apache_harmony_dalvik_ddmc_Chunk_data = CacheField(env, org_apache_harmony_dalvik_ddmc_Chunk, false, "data", "[B"); @@ -440,9 +422,6 @@ void WellKnownClasses::LateInit(JNIEnv* env) { CacheMethod(env, java_lang_reflect_Proxy, true, "invoke", "(Ljava/lang/reflect/Proxy;Ljava/lang/reflect/Method;" "[Ljava/lang/Object;)Ljava/lang/Object;"); - java_lang_reflect_Proxy_h = - CacheField(env, java_lang_reflect_Proxy, false, "h", - "Ljava/lang/reflect/InvocationHandler;"); } void WellKnownClasses::Clear() { @@ -464,8 +443,6 @@ void WellKnownClasses::Clear() { java_lang_Daemons = nullptr; java_lang_Error = nullptr; java_lang_IllegalAccessError = nullptr; - java_lang_invoke_MethodHandle = nullptr; - java_lang_invoke_VarHandle = nullptr; java_lang_NoClassDefFoundError = nullptr; java_lang_Object = nullptr; java_lang_OutOfMemoryError = nullptr; @@ -480,7 +457,6 @@ void WellKnownClasses::Clear() { java_lang_Thread = nullptr; java_lang_ThreadGroup = nullptr; java_lang_Throwable = nullptr; - java_util_ArrayList = nullptr; java_util_Collections = nullptr; java_nio_ByteBuffer = nullptr; java_nio_DirectByteBuffer = nullptr; @@ -497,14 +473,11 @@ void WellKnownClasses::Clear() { java_lang_Character_valueOf = nullptr; java_lang_ClassLoader_loadClass = nullptr; java_lang_ClassNotFoundException_init = nullptr; - java_lang_Daemons_requestHeapTrim = nullptr; java_lang_Daemons_start = nullptr; java_lang_Daemons_stop = nullptr; java_lang_Double_valueOf = nullptr; java_lang_Float_valueOf = nullptr; java_lang_Integer_valueOf = nullptr; - java_lang_invoke_MethodHandle_invoke = nullptr; - java_lang_invoke_MethodHandle_invokeExact = nullptr; java_lang_invoke_MethodHandles_lookup = nullptr; java_lang_invoke_MethodHandles_Lookup_findConstructor = nullptr; java_lang_Long_valueOf = nullptr; @@ -515,7 +488,6 @@ void WellKnownClasses::Clear() { java_lang_Runtime_nativeLoad = nullptr; java_lang_Short_valueOf = nullptr; java_lang_String_charAt = nullptr; - java_lang_System_runFinalization = nullptr; java_lang_Thread_dispatchUncaughtException = nullptr; java_lang_Thread_init = nullptr; java_lang_Thread_run = nullptr; @@ -533,7 +505,6 @@ void WellKnownClasses::Clear() { dalvik_system_DexPathList_dexElements = nullptr; dalvik_system_DexPathList__Element_dexFile = nullptr; dalvik_system_VMRuntime_nonSdkApiUsageConsumer = nullptr; - java_lang_reflect_Proxy_h = nullptr; java_lang_Thread_daemon = nullptr; java_lang_Thread_group = nullptr; java_lang_Thread_lock = nullptr; @@ -558,8 +529,6 @@ void WellKnownClasses::Clear() { java_nio_ByteBuffer_offset = nullptr; java_nio_DirectByteBuffer_capacity = nullptr; java_nio_DirectByteBuffer_effectiveDirectAddress = nullptr; - java_util_ArrayList_array = nullptr; - java_util_ArrayList_size = nullptr; java_util_Collections_EMPTY_LIST = nullptr; libcore_util_EmptyArray_STACK_TRACE_ELEMENT = nullptr; org_apache_harmony_dalvik_ddmc_Chunk_data = nullptr; diff --git a/runtime/well_known_classes.h b/runtime/well_known_classes.h index c06e4a71ce..c81062f594 100644 --- a/runtime/well_known_classes.h +++ b/runtime/well_known_classes.h @@ -66,8 +66,6 @@ struct WellKnownClasses { static jclass java_lang_Daemons; static jclass java_lang_Error; static jclass java_lang_IllegalAccessError; - static jclass java_lang_invoke_MethodHandle; - static jclass java_lang_invoke_VarHandle; static jclass java_lang_NoClassDefFoundError; static jclass java_lang_Object; static jclass java_lang_OutOfMemoryError; @@ -82,7 +80,6 @@ struct WellKnownClasses { static jclass java_lang_Thread; static jclass java_lang_ThreadGroup; static jclass java_lang_Throwable; - static jclass java_util_ArrayList; static jclass java_util_Collections; static jclass java_util_function_Consumer; static jclass java_nio_ByteBuffer; @@ -100,14 +97,11 @@ struct WellKnownClasses { static jmethodID java_lang_Character_valueOf; static jmethodID java_lang_ClassLoader_loadClass; static jmethodID java_lang_ClassNotFoundException_init; - static jmethodID java_lang_Daemons_requestHeapTrim; static jmethodID java_lang_Daemons_start; static jmethodID java_lang_Daemons_stop; static jmethodID java_lang_Double_valueOf; static jmethodID java_lang_Float_valueOf; static jmethodID java_lang_Integer_valueOf; - static jmethodID java_lang_invoke_MethodHandle_invoke; - static jmethodID java_lang_invoke_MethodHandle_invokeExact; static jmethodID java_lang_invoke_MethodHandles_lookup; static jmethodID java_lang_invoke_MethodHandles_Lookup_findConstructor; static jmethodID java_lang_Long_valueOf; @@ -118,7 +112,6 @@ struct WellKnownClasses { static jmethodID java_lang_Runtime_nativeLoad; static jmethodID java_lang_Short_valueOf; static jmethodID java_lang_String_charAt; - static jmethodID java_lang_System_runFinalization; static jmethodID java_lang_Thread_dispatchUncaughtException; static jmethodID java_lang_Thread_init; static jmethodID java_lang_Thread_run; @@ -137,7 +130,6 @@ struct WellKnownClasses { static jfieldID dalvik_system_DexPathList_dexElements; static jfieldID dalvik_system_DexPathList__Element_dexFile; static jfieldID dalvik_system_VMRuntime_nonSdkApiUsageConsumer; - static jfieldID java_lang_reflect_Proxy_h; static jfieldID java_lang_Thread_daemon; static jfieldID java_lang_Thread_group; static jfieldID java_lang_Thread_lock; @@ -163,8 +155,6 @@ struct WellKnownClasses { static jfieldID java_nio_DirectByteBuffer_capacity; static jfieldID java_nio_DirectByteBuffer_effectiveDirectAddress; - static jfieldID java_util_ArrayList_array; - static jfieldID java_util_ArrayList_size; static jfieldID java_util_Collections_EMPTY_LIST; static jfieldID libcore_util_EmptyArray_STACK_TRACE_ELEMENT; static jfieldID org_apache_harmony_dalvik_ddmc_Chunk_data; diff --git a/test/530-checker-lse/build b/test/530-checker-lse/build deleted file mode 100755 index 10ffcc537d..0000000000 --- a/test/530-checker-lse/build +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash -# -# Copyright 2017 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. - -# See b/65168732 -export USE_D8=false - -./default-build "$@" diff --git a/test/530-checker-lse/smali/Main.smali b/test/530-checker-lse/smali/Main.smali new file mode 100644 index 0000000000..267801760f --- /dev/null +++ b/test/530-checker-lse/smali/Main.smali @@ -0,0 +1,260 @@ +# Copyright (C) 2018 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. + +.class public LMain2; +.super Ljava/lang/Object; +.source "Main.java" + +# direct methods + +## CHECK-START: int Main2.test4(TestClass, boolean) load_store_elimination (before) +## CHECK: InstanceFieldSet +## CHECK: InstanceFieldGet +## CHECK: Return +## CHECK: InstanceFieldSet + +## CHECK-START: int Main2.test4(TestClass, boolean) load_store_elimination (after) +## CHECK: InstanceFieldSet +## CHECK-NOT: NullCheck +## CHECK-NOT: InstanceFieldGet +## CHECK: Return +## CHECK: InstanceFieldSet + +# Set and merge the same value in two branches. + +# Original java source: +# +# static int test4(TestClass obj, boolean b) { +# if (b) { +# obj.i = 1; +# } else { +# obj.i = 1; +# } +# return obj.i; +# } + +.method public static test4(LTestClass;Z)I + .registers 3 + .param p0, "obj" # LTestClass; + .param p1, "b" # Z + + .prologue + const/4 v0, 0x1 + + .line 185 + if-eqz p1, :cond_8 + + .line 186 + iput v0, p0, LTestClass;->i:I + + .line 190 + :goto_5 + iget v0, p0, LTestClass;->i:I + + return v0 + + .line 188 + :cond_8 + iput v0, p0, LTestClass;->i:I + + goto :goto_5 +.end method + +## CHECK-START: int Main2.test5(TestClass, boolean) load_store_elimination (before) +## CHECK: InstanceFieldSet +## CHECK: InstanceFieldGet +## CHECK: Return +## CHECK: InstanceFieldSet + +## CHECK-START: int Main2.test5(TestClass, boolean) load_store_elimination (after) +## CHECK: InstanceFieldSet +## CHECK: InstanceFieldGet +## CHECK: Return +## CHECK: InstanceFieldSet + +# Set and merge different values in two branches. +# Original java source: +# +# static int test5(TestClass obj, boolean b) { +# if (b) { +# obj.i = 1; +# } else { +# obj.i = 2; +# } +# return obj.i; +# } + +.method public static test5(LTestClass;Z)I + .registers 3 + .param p0, "obj" # LTestClass; + .param p1, "b" # Z + + .prologue + .line 207 + if-eqz p1, :cond_8 + + .line 208 + const/4 v0, 0x1 + + iput v0, p0, LTestClass;->i:I + + .line 212 + :goto_5 + iget v0, p0, LTestClass;->i:I + + return v0 + + .line 210 + :cond_8 + const/4 v0, 0x2 + + iput v0, p0, LTestClass;->i:I + + goto :goto_5 +.end method + +## CHECK-START: int Main2.test23(boolean) load_store_elimination (before) +## CHECK: NewInstance +## CHECK: InstanceFieldSet +## CHECK: InstanceFieldGet +## CHECK: InstanceFieldSet +## CHECK: InstanceFieldGet +## CHECK: Return +## CHECK: InstanceFieldGet +## CHECK: InstanceFieldSet + +## CHECK-START: int Main2.test23(boolean) load_store_elimination (after) +## CHECK: NewInstance +## CHECK-NOT: InstanceFieldSet +## CHECK-NOT: InstanceFieldGet +## CHECK: InstanceFieldSet +## CHECK: InstanceFieldGet +## CHECK: Return +## CHECK-NOT: InstanceFieldGet +## CHECK: InstanceFieldSet + +# Test store elimination on merging. + +# Original java source: +# +# static int test23(boolean b) { +# TestClass obj = new TestClass(); +# obj.i = 3; // This store can be eliminated since the value flows into each branch. +# if (b) { +# obj.i += 1; // This store cannot be eliminated due to the merge later. +# } else { +# obj.i += 2; // This store cannot be eliminated due to the merge later. +# } +# return obj.i; +# } + +.method public static test23(Z)I + .registers 3 + .param p0, "b" # Z + + .prologue + .line 582 + new-instance v0, LTestClass; + + invoke-direct {v0}, LTestClass;-><init>()V + + .line 583 + .local v0, "obj":LTestClass; + const/4 v1, 0x3 + + iput v1, v0, LTestClass;->i:I + + .line 584 + if-eqz p0, :cond_13 + + .line 585 + iget v1, v0, LTestClass;->i:I + + add-int/lit8 v1, v1, 0x1 + + iput v1, v0, LTestClass;->i:I + + .line 589 + :goto_10 + iget v1, v0, LTestClass;->i:I + + return v1 + + .line 587 + :cond_13 + iget v1, v0, LTestClass;->i:I + + add-int/lit8 v1, v1, 0x2 + + iput v1, v0, LTestClass;->i:I + + goto :goto_10 +.end method + +## CHECK-START: float Main2.test24() load_store_elimination (before) +## CHECK-DAG: <<True:i\d+>> IntConstant 1 +## CHECK-DAG: <<Float8:f\d+>> FloatConstant 8 +## CHECK-DAG: <<Float42:f\d+>> FloatConstant 42 +## CHECK-DAG: <<Obj:l\d+>> NewInstance +## CHECK-DAG: InstanceFieldSet [<<Obj>>,<<True>>] +## CHECK-DAG: InstanceFieldSet [<<Obj>>,<<Float8>>] +## CHECK-DAG: <<GetTest:z\d+>> InstanceFieldGet [<<Obj>>] +## CHECK-DAG: <<GetField:f\d+>> InstanceFieldGet [<<Obj>>] +## CHECK-DAG: <<Select:f\d+>> Select [<<Float42>>,<<GetField>>,<<GetTest>>] +## CHECK-DAG: Return [<<Select>>] + +## CHECK-START: float Main2.test24() load_store_elimination (after) +## CHECK-DAG: <<True:i\d+>> IntConstant 1 +## CHECK-DAG: <<Float8:f\d+>> FloatConstant 8 +## CHECK-DAG: <<Float42:f\d+>> FloatConstant 42 +## CHECK-DAG: <<Select:f\d+>> Select [<<Float42>>,<<Float8>>,<<True>>] +## CHECK-DAG: Return [<<Select>>] + +# Original java source: +# +# static float test24() { +# float a = 42.0f; +# TestClass3 obj = new TestClass3(); +# if (obj.test1) { +# a = obj.floatField; +# } +# return a; +# } + +.method public static test24()F + .registers 3 + + .prologue + .line 612 + const/high16 v0, 0x42280000 # 42.0f + + .line 613 + .local v0, "a":F + new-instance v1, LTestClass3; + + invoke-direct {v1}, LTestClass3;-><init>()V + + .line 614 + .local v1, "obj":LTestClass3; + iget-boolean v2, v1, LTestClass3;->test1:Z + + if-eqz v2, :cond_d + + .line 615 + iget v0, v1, LTestClass3;->floatField:F + + .line 617 + :cond_d + return v0 +.end method diff --git a/test/530-checker-lse/src/Main.java b/test/530-checker-lse/src/Main.java index 93c153821b..bd1744cc5f 100644 --- a/test/530-checker-lse/src/Main.java +++ b/test/530-checker-lse/src/Main.java @@ -14,6 +14,8 @@ * limitations under the License. */ +import java.lang.reflect.Method; + class Circle { Circle(double radius) { this.radius = radius; @@ -167,51 +169,6 @@ public class Main { return obj.i + obj1.j + obj2.i + obj2.j; } - /// CHECK-START: int Main.test4(TestClass, boolean) load_store_elimination (before) - /// CHECK: InstanceFieldSet - /// CHECK: InstanceFieldGet - /// CHECK: Return - /// CHECK: InstanceFieldSet - - /// CHECK-START: int Main.test4(TestClass, boolean) load_store_elimination (after) - /// CHECK: InstanceFieldSet - /// CHECK-NOT: NullCheck - /// CHECK-NOT: InstanceFieldGet - /// CHECK: Return - /// CHECK: InstanceFieldSet - - // Set and merge the same value in two branches. - static int test4(TestClass obj, boolean b) { - if (b) { - obj.i = 1; - } else { - obj.i = 1; - } - return obj.i; - } - - /// CHECK-START: int Main.test5(TestClass, boolean) load_store_elimination (before) - /// CHECK: InstanceFieldSet - /// CHECK: InstanceFieldGet - /// CHECK: Return - /// CHECK: InstanceFieldSet - - /// CHECK-START: int Main.test5(TestClass, boolean) load_store_elimination (after) - /// CHECK: InstanceFieldSet - /// CHECK: InstanceFieldGet - /// CHECK: Return - /// CHECK: InstanceFieldSet - - // Set and merge different values in two branches. - static int test5(TestClass obj, boolean b) { - if (b) { - obj.i = 1; - } else { - obj.i = 2; - } - return obj.i; - } - /// CHECK-START: int Main.test6(TestClass, TestClass, boolean) load_store_elimination (before) /// CHECK: InstanceFieldSet /// CHECK: InstanceFieldSet @@ -557,66 +514,6 @@ public class Main { return sum; } - /// CHECK-START: int Main.test23(boolean) load_store_elimination (before) - /// CHECK: NewInstance - /// CHECK: InstanceFieldSet - /// CHECK: InstanceFieldGet - /// CHECK: InstanceFieldSet - /// CHECK: InstanceFieldGet - /// CHECK: Return - /// CHECK: InstanceFieldGet - /// CHECK: InstanceFieldSet - - /// CHECK-START: int Main.test23(boolean) load_store_elimination (after) - /// CHECK: NewInstance - /// CHECK-NOT: InstanceFieldSet - /// CHECK-NOT: InstanceFieldGet - /// CHECK: InstanceFieldSet - /// CHECK: InstanceFieldGet - /// CHECK: Return - /// CHECK-NOT: InstanceFieldGet - /// CHECK: InstanceFieldSet - - // Test store elimination on merging. - static int test23(boolean b) { - TestClass obj = new TestClass(); - obj.i = 3; // This store can be eliminated since the value flows into each branch. - if (b) { - obj.i += 1; // This store cannot be eliminated due to the merge later. - } else { - obj.i += 2; // This store cannot be eliminated due to the merge later. - } - return obj.i; - } - - /// CHECK-START: float Main.test24() load_store_elimination (before) - /// CHECK-DAG: <<True:i\d+>> IntConstant 1 - /// CHECK-DAG: <<Float8:f\d+>> FloatConstant 8 - /// CHECK-DAG: <<Float42:f\d+>> FloatConstant 42 - /// CHECK-DAG: <<Obj:l\d+>> NewInstance - /// CHECK-DAG: InstanceFieldSet [<<Obj>>,<<True>>] - /// CHECK-DAG: InstanceFieldSet [<<Obj>>,<<Float8>>] - /// CHECK-DAG: <<GetTest:z\d+>> InstanceFieldGet [<<Obj>>] - /// CHECK-DAG: <<GetField:f\d+>> InstanceFieldGet [<<Obj>>] - /// CHECK-DAG: <<Select:f\d+>> Select [<<Float42>>,<<GetField>>,<<GetTest>>] - /// CHECK-DAG: Return [<<Select>>] - - /// CHECK-START: float Main.test24() load_store_elimination (after) - /// CHECK-DAG: <<True:i\d+>> IntConstant 1 - /// CHECK-DAG: <<Float8:f\d+>> FloatConstant 8 - /// CHECK-DAG: <<Float42:f\d+>> FloatConstant 42 - /// CHECK-DAG: <<Select:f\d+>> Select [<<Float42>>,<<Float8>>,<<True>>] - /// CHECK-DAG: Return [<<Select>>] - - static float test24() { - float a = 42.0f; - TestClass3 obj = new TestClass3(); - if (obj.test1) { - a = obj.floatField; - } - return a; - } - /// CHECK-START: void Main.testFinalizable() load_store_elimination (before) /// CHECK: NewInstance /// CHECK: InstanceFieldSet @@ -1275,7 +1172,14 @@ public class Main { } } - public static void main(String[] args) { + public static void main(String[] args) throws Exception { + + Class main2 = Class.forName("Main2"); + Method test4 = main2.getMethod("test4", TestClass.class, boolean.class); + Method test5 = main2.getMethod("test5", TestClass.class, boolean.class); + Method test23 = main2.getMethod("test23", boolean.class); + Method test24 = main2.getMethod("test24"); + assertDoubleEquals(Math.PI * Math.PI * Math.PI, calcCircleArea(Math.PI)); assertIntEquals(test1(new TestClass(), new TestClass()), 3); assertIntEquals(test2(new TestClass()), 1); @@ -1283,10 +1187,10 @@ public class Main { TestClass obj2 = new TestClass(); obj1.next = obj2; assertIntEquals(test3(obj1), 10); - assertIntEquals(test4(new TestClass(), true), 1); - assertIntEquals(test4(new TestClass(), false), 1); - assertIntEquals(test5(new TestClass(), true), 1); - assertIntEquals(test5(new TestClass(), false), 2); + assertIntEquals((int)test4.invoke(null, new TestClass(), true), 1); + assertIntEquals((int)test4.invoke(null, new TestClass(), false), 1); + assertIntEquals((int)test5.invoke(null, new TestClass(), true), 1); + assertIntEquals((int)test5.invoke(null, new TestClass(), false), 2); assertIntEquals(test6(new TestClass(), new TestClass(), true), 4); assertIntEquals(test6(new TestClass(), new TestClass(), false), 2); assertIntEquals(test7(new TestClass()), 1); @@ -1312,9 +1216,9 @@ public class Main { assertFloatEquals(test20().i, 0); test21(new TestClass()); assertIntEquals(test22(), 13); - assertIntEquals(test23(true), 4); - assertIntEquals(test23(false), 5); - assertFloatEquals(test24(), 8.0f); + assertIntEquals((int)test23.invoke(null, true), 4); + assertIntEquals((int)test23.invoke(null, false), 5); + assertFloatEquals((float)test24.invoke(null), 8.0f); testFinalizableByForcingGc(); assertIntEquals($noinline$testHSelect(true), 0xdead); int[] array = {2, 5, 9, -1, -3, 10, 8, 4}; diff --git a/test/549-checker-types-merge/build b/test/549-checker-types-merge/build deleted file mode 100644 index 10ffcc537d..0000000000 --- a/test/549-checker-types-merge/build +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash -# -# Copyright 2017 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. - -# See b/65168732 -export USE_D8=false - -./default-build "$@" diff --git a/test/567-checker-compare/build b/test/567-checker-compare/build deleted file mode 100644 index 10ffcc537d..0000000000 --- a/test/567-checker-compare/build +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash -# -# Copyright 2017 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. - -# See b/65168732 -export USE_D8=false - -./default-build "$@" diff --git a/test/910-methods/build b/test/910-methods/build deleted file mode 100644 index 10ffcc537d..0000000000 --- a/test/910-methods/build +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash -# -# Copyright 2017 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. - -# See b/65168732 -export USE_D8=false - -./default-build "$@" diff --git a/tools/dexanalyze/dexanalyze.cc b/tools/dexanalyze/dexanalyze.cc index 38725d428b..7d7e5f28b3 100644 --- a/tools/dexanalyze/dexanalyze.cc +++ b/tools/dexanalyze/dexanalyze.cc @@ -49,6 +49,8 @@ class DexAnalyze { << "Usage " << argv[0] << " [options] <dex files>\n" << " [options] is a combination of the following\n" << " -count_indices (Count dex indices accessed from code items)\n" + << " -analyze-strings (Analyze string data)\n" + << " -analyze-debug-info (Analyze debug info)\n" << " -i (Ignore Dex checksum and verification failures)\n" << " -a (Run all experiments)\n" << " -d (Dump on per DEX basis)\n"; @@ -69,6 +71,8 @@ class DexAnalyze { exp_count_indices_ = true; } else if (arg == "-analyze-strings") { exp_analyze_strings_ = true; + } else if (arg == "-analyze-debug-info") { + exp_debug_info_ = true; } else if (arg == "-d") { dump_per_input_dex_ = true; } else if (!arg.empty() && arg[0] == '-') { @@ -90,6 +94,7 @@ class DexAnalyze { bool exp_count_indices_ = false; bool exp_code_metrics_ = false; bool exp_analyze_strings_ = false; + bool exp_debug_info_ = false; bool run_all_experiments_ = false; std::vector<std::string> filenames_; }; @@ -106,6 +111,9 @@ class DexAnalyze { if (options->run_all_experiments_ || options->exp_code_metrics_) { experiments_.emplace_back(new CodeMetrics); } + if (options->run_all_experiments_ || options->exp_debug_info_) { + experiments_.emplace_back(new AnalyzeDebugInfo); + } } bool ProcessDexFile(const DexFile& dex_file) { @@ -120,6 +128,7 @@ class DexAnalyze { void Dump(std::ostream& os) { for (std::unique_ptr<Experiment>& experiment : experiments_) { experiment->Dump(os, total_size_); + os << "\n"; } } diff --git a/tools/dexanalyze/dexanalyze_experiments.cc b/tools/dexanalyze/dexanalyze_experiments.cc index 7006370c0b..1a3b89cbc7 100644 --- a/tools/dexanalyze/dexanalyze_experiments.cc +++ b/tools/dexanalyze/dexanalyze_experiments.cc @@ -75,6 +75,128 @@ static size_t PrefixLen(const std::string& a, const std::string& b) { return len; } +void AnalyzeDebugInfo::ProcessDexFile(const DexFile& dex_file) { + std::set<const uint8_t*> seen; + std::vector<size_t> counts(256, 0u); + std::vector<size_t> opcode_counts(256, 0u); + std::set<std::vector<uint8_t>> unique_non_header; + for (ClassAccessor accessor : dex_file.GetClasses()) { + for (const ClassAccessor::Method& method : accessor.GetMethods()) { + CodeItemDebugInfoAccessor code_item(dex_file, method.GetCodeItem(), method.GetIndex()); + const uint8_t* debug_info = dex_file.GetDebugInfoStream(code_item.DebugInfoOffset()); + if (debug_info != nullptr && seen.insert(debug_info).second) { + const uint8_t* stream = debug_info; + DecodeUnsignedLeb128(&stream); // line_start + uint32_t parameters_size = DecodeUnsignedLeb128(&stream); + for (uint32_t i = 0; i < parameters_size; ++i) { + DecodeUnsignedLeb128P1(&stream); // Parameter name. + } + bool done = false; + const uint8_t* after_header_start = stream; + while (!done) { + const uint8_t* const op_start = stream; + uint8_t opcode = *stream++; + ++opcode_counts[opcode]; + ++total_opcode_bytes_; + switch (opcode) { + case DexFile::DBG_END_SEQUENCE: + ++total_end_seq_bytes_; + done = true; + break; + case DexFile::DBG_ADVANCE_PC: + DecodeUnsignedLeb128(&stream); // addr_diff + total_advance_pc_bytes_ += stream - op_start; + break; + case DexFile::DBG_ADVANCE_LINE: + DecodeSignedLeb128(&stream); // line_diff + total_advance_line_bytes_ += stream - op_start; + break; + case DexFile::DBG_START_LOCAL: + DecodeUnsignedLeb128(&stream); // register_num + DecodeUnsignedLeb128P1(&stream); // name_idx + DecodeUnsignedLeb128P1(&stream); // type_idx + total_start_local_bytes_ += stream - op_start; + break; + case DexFile::DBG_START_LOCAL_EXTENDED: + DecodeUnsignedLeb128(&stream); // register_num + DecodeUnsignedLeb128P1(&stream); // name_idx + DecodeUnsignedLeb128P1(&stream); // type_idx + DecodeUnsignedLeb128P1(&stream); // sig_idx + total_start_local_extended_bytes_ += stream - op_start; + break; + case DexFile::DBG_END_LOCAL: + DecodeUnsignedLeb128(&stream); // register_num + total_end_local_bytes_ += stream - op_start; + break; + case DexFile::DBG_RESTART_LOCAL: + DecodeUnsignedLeb128(&stream); // register_num + total_restart_local_bytes_ += stream - op_start; + break; + case DexFile::DBG_SET_PROLOGUE_END: + case DexFile::DBG_SET_EPILOGUE_BEGIN: + total_epilogue_bytes_ += stream - op_start; + break; + case DexFile::DBG_SET_FILE: { + DecodeUnsignedLeb128P1(&stream); // name_idx + total_set_file_bytes_ += stream - op_start; + break; + } + default: { + total_other_bytes_ += stream - op_start; + break; + } + } + } + const size_t bytes = stream - debug_info; + total_bytes_ += bytes; + total_non_header_bytes_ += stream - after_header_start; + if (unique_non_header.insert(std::vector<uint8_t>(after_header_start, stream)).second) { + total_unique_non_header_bytes_ += stream - after_header_start; + } + for (size_t i = 0; i < bytes; ++i) { + ++counts[debug_info[i]]; + } + } + } + } + auto calc_entropy = [](std::vector<size_t> data) { + size_t total = std::accumulate(data.begin(), data.end(), 0u); + double avg_entropy = 0.0; + for (size_t c : data) { + if (c > 0) { + double ratio = static_cast<double>(c) / static_cast<double>(total); + avg_entropy -= ratio * log(ratio) / log(256.0); + } + } + return avg_entropy * total; + }; + total_entropy_ += calc_entropy(counts); + total_opcode_entropy_ += calc_entropy(opcode_counts); +} + +void AnalyzeDebugInfo::Dump(std::ostream& os, uint64_t total_size) const { + os << "Debug info bytes " << Percent(total_bytes_, total_size) << "\n"; + + os << " DBG_END_SEQUENCE: " << Percent(total_end_seq_bytes_, total_size) << "\n"; + os << " DBG_ADVANCE_PC: " << Percent(total_advance_pc_bytes_, total_size) << "\n"; + os << " DBG_ADVANCE_LINE: " << Percent(total_advance_line_bytes_, total_size) << "\n"; + os << " DBG_START_LOCAL: " << Percent(total_start_local_bytes_, total_size) << "\n"; + os << " DBG_START_LOCAL_EXTENDED: " + << Percent(total_start_local_extended_bytes_, total_size) << "\n"; + os << " DBG_END_LOCAL: " << Percent(total_end_local_bytes_, total_size) << "\n"; + os << " DBG_RESTART_LOCAL: " << Percent(total_restart_local_bytes_, total_size) << "\n"; + os << " DBG_SET_PROLOGUE bytes " << Percent(total_epilogue_bytes_, total_size) << "\n"; + os << " DBG_SET_FILE bytes " << Percent(total_set_file_bytes_, total_size) << "\n"; + os << " special: " + << Percent(total_other_bytes_, total_size) << "\n"; + os << "Debug info entropy " << Percent(total_entropy_, total_size) << "\n"; + os << "Debug info opcode bytes " << Percent(total_opcode_bytes_, total_size) << "\n"; + os << "Debug info opcode entropy " << Percent(total_opcode_entropy_, total_size) << "\n"; + os << "Debug info non header bytes " << Percent(total_non_header_bytes_, total_size) << "\n"; + os << "Debug info deduped non header bytes " + << Percent(total_unique_non_header_bytes_, total_size) << "\n"; +} + void AnalyzeStrings::ProcessDexFile(const DexFile& dex_file) { std::vector<std::string> strings; for (size_t i = 0; i < dex_file.NumStringIds(); ++i) { diff --git a/tools/dexanalyze/dexanalyze_experiments.h b/tools/dexanalyze/dexanalyze_experiments.h index 7ba2a49372..a2621c85ca 100644 --- a/tools/dexanalyze/dexanalyze_experiments.h +++ b/tools/dexanalyze/dexanalyze_experiments.h @@ -51,6 +51,32 @@ class AnalyzeStrings : public Experiment { int64_t total_num_prefixes_ = 0u; }; +// Analyze debug info sizes. +class AnalyzeDebugInfo : public Experiment { + public: + void ProcessDexFile(const DexFile& dex_file); + void Dump(std::ostream& os, uint64_t total_size) const; + + private: + int64_t total_bytes_ = 0u; + int64_t total_entropy_ = 0u; + int64_t total_opcode_bytes_ = 0u; + int64_t total_opcode_entropy_ = 0u; + int64_t total_non_header_bytes_ = 0u; + int64_t total_unique_non_header_bytes_ = 0u; + // Opcode and related data. + int64_t total_end_seq_bytes_ = 0u; + int64_t total_advance_pc_bytes_ = 0u; + int64_t total_advance_line_bytes_ = 0u; + int64_t total_start_local_bytes_ = 0u; + int64_t total_start_local_extended_bytes_ = 0u; + int64_t total_end_local_bytes_ = 0u; + int64_t total_restart_local_bytes_ = 0u; + int64_t total_epilogue_bytes_ = 0u; + int64_t total_set_file_bytes_ = 0u; + int64_t total_other_bytes_ = 0u; +}; + // Count numbers of dex indices. class CountDexIndices : public Experiment { public: diff --git a/tools/teardown-buildbot-device.sh b/tools/teardown-buildbot-device.sh index df239a28bc..bf14ca4f9f 100755 --- a/tools/teardown-buildbot-device.sh +++ b/tools/teardown-buildbot-device.sh @@ -25,6 +25,27 @@ adb root adb wait-for-device if [[ -n "$ART_TEST_CHROOT" ]]; then + + # remove_filesystem_from_chroot DIR-IN-CHROOT FSTYPE REMOVE-DIR-IN-CHROOT + # ----------------------------------------------------------------------- + # Unmount filesystem with type FSTYPE mounted in directory DIR-IN-CHROOT + # under the chroot directory. + # Remove DIR-IN-CHROOT under the chroot if REMOVE-DIR-IN-CHROOT is + # true. + remove_filesystem_from_chroot() { + local dir_in_chroot=$1 + local fstype=$2 + local remove_dir=$3 + local dir="$ART_TEST_CHROOT/$dir_in_chroot" + adb shell test -d "$dir" \ + && adb shell mount | grep -q "^$fstype on $dir type $fstype " \ + && if adb shell umount "$dir"; then + $remove_dir && adb shell rmdir "$dir" + else + adb shell lsof "$dir" + fi + } + # Tear down the chroot dir. echo -e "${green}Tear down the chroot dir in $ART_TEST_CHROOT${nc}" @@ -32,22 +53,17 @@ if [[ -n "$ART_TEST_CHROOT" ]]; then [[ "x$ART_TEST_CHROOT" = x/* ]] || { echo "$ART_TEST_CHROOT is not an absolute path"; exit 1; } # Remove /dev from chroot. - adb shell mount | grep -q "^tmpfs on $ART_TEST_CHROOT/dev type tmpfs " \ - && adb shell umount "$ART_TEST_CHROOT/dev" \ - && adb shell rmdir "$ART_TEST_CHROOT/dev" + remove_filesystem_from_chroot dev tmpfs true # Remove /sys/kernel/debug from chroot. - adb shell mount | grep -q "^debugfs on $ART_TEST_CHROOT/sys/kernel/debug type debugfs " \ - && adb shell umount "$ART_TEST_CHROOT/sys/kernel/debug" + # The /sys/kernel/debug directory under the chroot dir cannot be + # deleted, as it is part of the host device's /sys filesystem. + remove_filesystem_from_chroot sys/kernel/debug debugfs false # Remove /sys from chroot. - adb shell mount | grep -q "^sysfs on $ART_TEST_CHROOT/sys type sysfs " \ - && adb shell umount "$ART_TEST_CHROOT/sys" \ - && adb shell rmdir "$ART_TEST_CHROOT/sys" + remove_filesystem_from_chroot sys sysfs true # Remove /proc from chroot. - adb shell mount | grep -q "^proc on $ART_TEST_CHROOT/proc type proc " \ - && adb shell umount "$ART_TEST_CHROOT/proc" \ - && adb shell rmdir "$ART_TEST_CHROOT/proc" + remove_filesystem_from_chroot proc proc true # Remove /etc from chroot. adb shell rm -f "$ART_TEST_CHROOT/etc" @@ -65,6 +81,6 @@ if [[ -n "$ART_TEST_CHROOT" ]]; then /plat_property_contexts \ /nonplat_property_contexts" for f in $property_context_files; do - adb shell test -f "$f" "&&" rm -f "$ART_TEST_CHROOT$f" + adb shell rm -f "$ART_TEST_CHROOT$f" done fi diff --git a/tools/veridex/Android.bp b/tools/veridex/Android.bp index 5186c43ca2..96d4a094b5 100644 --- a/tools/veridex/Android.bp +++ b/tools/veridex/Android.bp @@ -24,11 +24,16 @@ cc_binary { "veridex.cc", ], cflags: ["-Wall", "-Werror"], - shared_libs: [ + static_libs: [ "libdexfile", "libartbase", "libbase", + "liblog", + "libutils", + "libz", + "libziparchive", ], + stl: "libc++_static", header_libs: [ "art_libartbase_headers", ], diff --git a/tools/veridex/Android.mk b/tools/veridex/Android.mk index 51d924a3c1..f8463c1c33 100644 --- a/tools/veridex/Android.mk +++ b/tools/veridex/Android.mk @@ -16,6 +16,9 @@ LOCAL_PATH := $(call my-dir) +# The veridex tool takes stub dex files as input, so we generate both the system and oahl +# dex stubs. + system_stub_dex := $(TARGET_OUT_COMMON_INTERMEDIATES)/PACKAGING/core_dex_intermediates/classes.dex $(system_stub_dex): PRIVATE_MIN_SDK_VERSION := 1000 $(system_stub_dex): $(call resolve-prebuilt-sdk-jar-path,system_current) | $(ZIP2ZIP) $(DX) @@ -27,9 +30,38 @@ $(oahl_stub_dex): PRIVATE_MIN_SDK_VERSION := 1000 $(oahl_stub_dex): $(call get-prebuilt-sdk-dir,current)/org.apache.http.legacy.jar | $(ZIP2ZIP) $(DX) $(transform-classes-d8.jar-to-dex) +app_compat_lists := \ + $(INTERNAL_PLATFORM_HIDDENAPI_LIGHT_GREYLIST) \ + $(INTERNAL_PLATFORM_HIDDENAPI_DARK_GREYLIST) \ + $(INTERNAL_PLATFORM_HIDDENAPI_BLACKLIST) + +# Phony rule to create all dependencies of the appcompat.sh script. .PHONY: appcompat +appcompat: $(system_stub_dex) $(oahl_stub_dex) $(HOST_OUT_EXECUTABLES)/veridex $(app_compat_lists) + +VERIDEX_FILES_PATH := \ + $(call intermediates-dir-for,PACKAGING,veridex,HOST)/veridex.zip + +VERIDEX_FILES := $(LOCAL_PATH)/appcompat.sh + +$(VERIDEX_FILES_PATH): PRIVATE_VERIDEX_FILES := $(VERIDEX_FILES) +$(VERIDEX_FILES_PATH): PRIVATE_APP_COMPAT_LISTS := $(app_compat_lists) +$(VERIDEX_FILES_PATH): PRIVATE_SYSTEM_STUBS_ZIP := $(dir $(VERIDEX_FILES_PATH))/system-stubs.zip +$(VERIDEX_FILES_PATH): PRIVATE_OAHL_STUBS_ZIP := $(dir $(VERIDEX_FILES_PATH))/org.apache.http.legacy-stubs.zip +$(VERIDEX_FILES_PATH) : $(SOONG_ZIP) $(VERIDEX_FILES) $(app_compat_lists) $(HOST_OUT_EXECUTABLES)/veridex $(system_stub_dex) $(oahl_stub_dex) + $(hide) rm -f $(PRIVATE_SYSTEM_STUBS_ZIP) $(PRIVATE_OAHL_STUBS_ZIP) + $(hide) zip -j $(PRIVATE_SYSTEM_STUBS_ZIP) $(dir $(system_stub_dex))/classes*.dex + $(hide) zip -j $(PRIVATE_OAHL_STUBS_ZIP) $(dir $(oahl_stub_dex))/classes*.dex + $(hide) $(SOONG_ZIP) -o $@ -C art/tools/veridex -f $(PRIVATE_VERIDEX_FILES) \ + -C $(dir $(lastword $(PRIVATE_APP_COMPAT_LISTS))) $(addprefix -f , $(PRIVATE_APP_COMPAT_LISTS)) \ + -C $(HOST_OUT_EXECUTABLES) -f $(HOST_OUT_EXECUTABLES)/veridex \ + -C $(dir $(PRIVATE_SYSTEM_STUBS_ZIP)) -f $(PRIVATE_SYSTEM_STUBS_ZIP) \ + -C $(dir $(PRIVATE_OAHL_STUBS_ZIP)) -f $(PRIVATE_OAHL_STUBS_ZIP) + $(hide) rm -f $(PRIVATE_SYSTEM_STUBS_ZIP) + $(hide) rm -f $(PRIVATE_OAHL_STUBS_ZIP) + +# Make the zip file available for prebuilts. +$(call dist-for-goals,sdk,$(VERIDEX_FILES_PATH)) -appcompat: $(system_stub_dex) $(oahl_stub_dex) $(HOST_OUT_EXECUTABLES)/veridex \ - ${TARGET_OUT_COMMON_INTERMEDIATES}/PACKAGING/hiddenapi-light-greylist.txt \ - ${TARGET_OUT_COMMON_INTERMEDIATES}/PACKAGING/hiddenapi-dark-greylist.txt \ - ${TARGET_OUT_COMMON_INTERMEDIATES}/PACKAGING/hiddenapi-blacklist.txt +VERIDEX_FILES := +app_compat_lists := diff --git a/tools/veridex/appcompat.sh b/tools/veridex/appcompat.sh index 31a8654b58..e7b735d30b 100755 --- a/tools/veridex/appcompat.sh +++ b/tools/veridex/appcompat.sh @@ -14,7 +14,28 @@ # See the License for the specific language governing permissions and # limitations under the License. -# We want to be at the root for simplifying the "out" detection +echo "NOTE: appcompat.sh is still under development. It can report" +echo "API uses that do not execute at runtime, and reflection uses" +echo "that do not exist. It can also miss on reflection uses." + +# First check if the script is invoked from a prebuilts location. +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +if [[ -e ${SCRIPT_DIR}/veridex && \ + -e ${SCRIPT_DIR}/hiddenapi-blacklist.txt && \ + -e ${SCRIPT_DIR}/hiddenapi-light-greylist.txt && \ + -e ${SCRIPT_DIR}/hiddenapi-dark-greylist.txt && \ + -e ${SCRIPT_DIR}/org.apache.http.legacy-stubs.zip && \ + -e ${SCRIPT_DIR}/system-stubs.zip ]]; then + exec ${SCRIPT_DIR}/veridex \ + --core-stubs=${SCRIPT_DIR}/system-stubs.zip:${SCRIPT_DIR}/org.apache.http.legacy-stubs.zip \ + --blacklist=${SCRIPT_DIR}/hiddenapi-blacklist.txt \ + --light-greylist=${SCRIPT_DIR}/hiddenapi-light-greylist.txt \ + --dark-greylist=${SCRIPT_DIR}/hiddenapi-dark-greylist.txt \ + $@ +fi + +# Otherwise, we want to be at the root for simplifying the "out" detection # logic. if [ ! -d art ]; then echo "Script needs to be run at the root of the android tree." @@ -38,10 +59,6 @@ if [ -z "$ANDROID_HOST_OUT" ] ; then ANDROID_HOST_OUT=${OUT}/host/linux-x86 fi -echo "NOTE: appcompat.sh is still under development. It can report" -echo "API uses that do not execute at runtime, and reflection uses" -echo "that do not exist. It can also miss on reflection uses." - ${ANDROID_HOST_OUT}/bin/veridex \ --core-stubs=${PACKAGING}/core_dex_intermediates/classes.dex:${PACKAGING}/oahl_dex_intermediates/classes.dex \ |