diff options
Diffstat (limited to 'compiler/exception_test.cc')
| -rw-r--r-- | compiler/exception_test.cc | 75 |
1 files changed, 34 insertions, 41 deletions
diff --git a/compiler/exception_test.cc b/compiler/exception_test.cc index f582341b18..633e124d07 100644 --- a/compiler/exception_test.cc +++ b/compiler/exception_test.cc @@ -15,11 +15,13 @@ */ #include <memory> +#include <type_traits> #include "base/arena_allocator.h" #include "base/callee_save_type.h" #include "base/enums.h" #include "base/leb128.h" +#include "base/malloc_arena_pool.h" #include "class_linker.h" #include "common_runtime_test.h" #include "dex/code_item_accessors-inl.h" @@ -31,8 +33,9 @@ #include "mirror/class-inl.h" #include "mirror/object-inl.h" #include "mirror/object_array-inl.h" -#include "mirror/stack_trace_element.h" +#include "mirror/stack_trace_element-inl.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" @@ -47,7 +50,7 @@ class ExceptionTest : public CommonRuntimeTest { // which always points to the first source statement. static constexpr const uint32_t kDexPc = 0; - virtual void SetUp() { + void SetUp() override { CommonRuntimeTest::SetUp(); ScopedObjectAccess soa(Thread::Current()); @@ -67,47 +70,37 @@ class ExceptionTest : public CommonRuntimeTest { fake_code_.push_back(0x70 | i); } - ArenaPool pool; + const uint32_t native_pc_offset = 4u; + CHECK_ALIGNED_PARAM(native_pc_offset, GetInstructionSetInstructionAlignment(kRuntimeISA)); + + MallocArenaPool pool; ArenaStack arena_stack(&pool); ScopedArenaAllocator allocator(&arena_stack); StackMapStream stack_maps(&allocator, kRuntimeISA); - stack_maps.BeginStackMapEntry(kDexPc, - /* native_pc_offset */ 3u, - /* register_mask */ 0u, - /* sp_mask */ nullptr, - /* num_dex_registers */ 0u, - /* inlining_depth */ 0u); + stack_maps.BeginMethod(4 * sizeof(void*), 0u, 0u, 0u); + stack_maps.BeginStackMapEntry(kDexPc, native_pc_offset); stack_maps.EndStackMapEntry(); - size_t stack_maps_size = stack_maps.PrepareForFillIn(); - size_t stack_maps_offset = stack_maps_size + sizeof(OatQuickMethodHeader); - - fake_header_code_and_maps_.resize(stack_maps_offset + fake_code_.size()); - MemoryRegion stack_maps_region(&fake_header_code_and_maps_[0], stack_maps_size); - stack_maps.FillInCodeInfo(stack_maps_region); - OatQuickMethodHeader method_header(stack_maps_offset, 0u, 4 * sizeof(void*), 0u, 0u, code_size); - memcpy(&fake_header_code_and_maps_[stack_maps_size], &method_header, sizeof(method_header)); - std::copy(fake_code_.begin(), - fake_code_.end(), - fake_header_code_and_maps_.begin() + stack_maps_offset); - - // Align the code. - const size_t alignment = GetInstructionSetAlignment(kRuntimeISA); - fake_header_code_and_maps_.reserve(fake_header_code_and_maps_.size() + alignment); - const void* unaligned_code_ptr = - fake_header_code_and_maps_.data() + (fake_header_code_and_maps_.size() - code_size); - size_t offset = dchecked_integral_cast<size_t>(reinterpret_cast<uintptr_t>(unaligned_code_ptr)); - size_t padding = RoundUp(offset, alignment) - offset; - // Make sure no resizing takes place. - CHECK_GE(fake_header_code_and_maps_.capacity(), fake_header_code_and_maps_.size() + padding); - fake_header_code_and_maps_.insert(fake_header_code_and_maps_.begin(), padding, 0); - const void* code_ptr = reinterpret_cast<const uint8_t*>(unaligned_code_ptr) + padding; - CHECK_EQ(code_ptr, - static_cast<const void*>(fake_header_code_and_maps_.data() + - (fake_header_code_and_maps_.size() - code_size))); + stack_maps.EndMethod(); + ScopedArenaVector<uint8_t> stack_map = stack_maps.Encode(); + + const size_t stack_maps_size = stack_map.size(); + const size_t header_size = sizeof(OatQuickMethodHeader); + const size_t code_alignment = GetInstructionSetAlignment(kRuntimeISA); + + fake_header_code_and_maps_.resize(stack_maps_size + header_size + code_size + code_alignment); + // NB: The start of the vector might not have been allocated the desired alignment. + uint8_t* code_ptr = + AlignUp(&fake_header_code_and_maps_[stack_maps_size + header_size], code_alignment); + + memcpy(&fake_header_code_and_maps_[0], stack_map.data(), stack_maps_size); + OatQuickMethodHeader method_header(code_ptr - fake_header_code_and_maps_.data(), code_size); + static_assert(std::is_trivially_copyable<OatQuickMethodHeader>::value, "Cannot use memcpy"); + memcpy(code_ptr - header_size, &method_header, header_size); + memcpy(code_ptr, fake_code_.data(), fake_code_.size()); if (kRuntimeISA == InstructionSet::kArm) { // Check that the Thumb2 adjustment will be a NOP, see EntryPointToCodePointer(). - CHECK_ALIGNED(stack_maps_offset, 2); + CHECK_ALIGNED(code_ptr, 2); } method_f_ = my_klass_->FindClassMethod("f", "()I", kRuntimePointerSize); @@ -130,7 +123,7 @@ class ExceptionTest : public CommonRuntimeTest { ArtMethod* method_g_; private: - mirror::Class* my_klass_; + ObjPtr<mirror::Class> my_klass_; }; TEST_F(ExceptionTest, FindCatchHandler) { @@ -142,8 +135,8 @@ TEST_F(ExceptionTest, FindCatchHandler) { ASSERT_EQ(2u, accessor.TriesSize()); ASSERT_NE(0u, accessor.InsnsSizeInCodeUnits()); - const DexFile::TryItem& t0 = accessor.TryItems().begin()[0]; - const DexFile::TryItem& t1 = accessor.TryItems().begin()[1]; + const dex::TryItem& t0 = accessor.TryItems().begin()[0]; + const dex::TryItem& t1 = accessor.TryItems().begin()[1]; EXPECT_LE(t0.start_addr_, t1.start_addr_); { CatchHandlerIterator iter(accessor, 4 /* Dex PC in the first try block */); @@ -194,14 +187,14 @@ TEST_F(ExceptionTest, StackTraceElement) { } fake_stack.push_back(method_g_->GetOatQuickMethodHeader(0)->ToNativeQuickPc( - method_g_, kDexPc, /* is_catch_handler */ false)); // return pc + method_g_, kDexPc, /* is_for_catch_handler= */ false)); // return pc // Create/push fake 16byte stack frame for method g fake_stack.push_back(reinterpret_cast<uintptr_t>(method_g_)); fake_stack.push_back(0); fake_stack.push_back(0); fake_stack.push_back(method_g_->GetOatQuickMethodHeader(0)->ToNativeQuickPc( - method_g_, kDexPc, /* is_catch_handler */ false)); // return pc + method_g_, kDexPc, /* is_for_catch_handler= */ false)); // return pc // Create/push fake 16byte stack frame for method f fake_stack.push_back(reinterpret_cast<uintptr_t>(method_f_)); |