From 179b7c61ea6769b99f70c80a7a89cbb212423ec2 Mon Sep 17 00:00:00 2001 From: Vladimir Marko Date: Fri, 22 Mar 2019 13:38:57 +0000 Subject: ObjPtr<>-ify String allocations, fix stale refs. ObjPtr<>-ify String allocation functions and related code and remove some unnecessary calls to ObjPtr<>::Ptr(). Fix stale reference uses in reference_table_test and stub_test. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Bug: 31113334 Change-Id: I42927fb8b7240e5132188f73318b2ccb218748fd --- runtime/mirror/string-alloc-inl.h | 56 +++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 29 deletions(-) (limited to 'runtime/mirror/string-alloc-inl.h') diff --git a/runtime/mirror/string-alloc-inl.h b/runtime/mirror/string-alloc-inl.h index 4c4e2af3e7..4330235dd9 100644 --- a/runtime/mirror/string-alloc-inl.h +++ b/runtime/mirror/string-alloc-inl.h @@ -25,6 +25,7 @@ #include "class.h" #include "class_root.h" #include "gc/heap-inl.h" +#include "obj_ptr.h" #include "runtime.h" #include "runtime_globals.h" #include "thread.h" @@ -154,10 +155,10 @@ class SetStringCountAndValueVisitorFromString { }; template -inline String* String::Alloc(Thread* self, - int32_t utf16_length_with_flag, - gc::AllocatorType allocator_type, - const PreFenceVisitor& pre_fence_visitor) { +inline ObjPtr String::Alloc(Thread* self, + int32_t utf16_length_with_flag, + gc::AllocatorType allocator_type, + const PreFenceVisitor& pre_fence_visitor) { constexpr size_t header_size = sizeof(String); const bool compressible = kUseStringCompression && String::IsCompressed(utf16_length_with_flag); const size_t block_size = (compressible) ? sizeof(uint8_t) : sizeof(uint16_t); @@ -189,67 +190,64 @@ inline String* String::Alloc(Thread* self, } gc::Heap* heap = runtime->GetHeap(); - return down_cast( + return ObjPtr::DownCast(MakeObjPtr( heap->AllocObjectWithAllocator(self, string_class, alloc_size, allocator_type, - pre_fence_visitor)); + pre_fence_visitor))); } template -inline String* String::AllocEmptyString(Thread* self, gc::AllocatorType allocator_type) { +inline ObjPtr String::AllocEmptyString(Thread* self, gc::AllocatorType allocator_type) { const int32_t length_with_flag = String::GetFlaggedCount(0, /* compressible= */ true); SetStringCountVisitor visitor(length_with_flag); return Alloc(self, length_with_flag, allocator_type, visitor); } template -inline String* String::AllocFromByteArray(Thread* self, - int32_t byte_length, - Handle array, - int32_t offset, - int32_t high_byte, - gc::AllocatorType allocator_type) { +inline ObjPtr String::AllocFromByteArray(Thread* self, + int32_t byte_length, + Handle array, + int32_t offset, + int32_t high_byte, + gc::AllocatorType allocator_type) { const uint8_t* const src = reinterpret_cast(array->GetData()) + offset; high_byte &= 0xff; // Extract the relevant bits before determining `compressible`. const bool compressible = kUseStringCompression && String::AllASCII(src, byte_length) && (high_byte == 0); const int32_t length_with_flag = String::GetFlaggedCount(byte_length, compressible); SetStringCountAndBytesVisitor visitor(length_with_flag, array, offset, high_byte << 8); - String* string = Alloc(self, length_with_flag, allocator_type, visitor); - return string; + return Alloc(self, length_with_flag, allocator_type, visitor); } template -inline String* String::AllocFromCharArray(Thread* self, - int32_t count, - Handle array, - int32_t offset, - gc::AllocatorType allocator_type) { +inline ObjPtr String::AllocFromCharArray(Thread* self, + int32_t count, + Handle array, + int32_t offset, + gc::AllocatorType allocator_type) { // It is a caller error to have a count less than the actual array's size. DCHECK_GE(array->GetLength(), count); const bool compressible = kUseStringCompression && String::AllASCII(array->GetData() + offset, count); const int32_t length_with_flag = String::GetFlaggedCount(count, compressible); SetStringCountAndValueVisitorFromCharArray visitor(length_with_flag, array, offset); - String* new_string = Alloc(self, length_with_flag, allocator_type, visitor); - return new_string; + return Alloc(self, length_with_flag, allocator_type, visitor); } template -inline String* String::AllocFromString(Thread* self, - int32_t string_length, - Handle string, - int32_t offset, - gc::AllocatorType allocator_type) { +inline ObjPtr String::AllocFromString(Thread* self, + int32_t string_length, + Handle string, + int32_t offset, + gc::AllocatorType allocator_type) { const bool compressible = kUseStringCompression && ((string->IsCompressed()) ? true : String::AllASCII(string->GetValue() + offset, string_length)); const int32_t length_with_flag = String::GetFlaggedCount(string_length, compressible); SetStringCountAndValueVisitorFromString visitor(length_with_flag, string, offset); - String* new_string = Alloc(self, length_with_flag, allocator_type, visitor); - return new_string; + return Alloc(self, length_with_flag, allocator_type, visitor); } } // namespace mirror -- cgit v1.2.3-59-g8ed1b