diff options
author | 2019-03-22 13:38:57 +0000 | |
---|---|---|
committer | 2019-03-25 16:54:37 +0000 | |
commit | 179b7c61ea6769b99f70c80a7a89cbb212423ec2 (patch) | |
tree | 06130898bfb2d8c3f71f4fe181277f20e1942726 /runtime/mirror/string-alloc-inl.h | |
parent | c8b7d445e02b752a68d824e2bc69658dfb76288a (diff) |
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
Diffstat (limited to 'runtime/mirror/string-alloc-inl.h')
-rw-r--r-- | runtime/mirror/string-alloc-inl.h | 56 |
1 files changed, 27 insertions, 29 deletions
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 <bool kIsInstrumented, typename PreFenceVisitor> -inline String* String::Alloc(Thread* self, - int32_t utf16_length_with_flag, - gc::AllocatorType allocator_type, - const PreFenceVisitor& pre_fence_visitor) { +inline ObjPtr<String> 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<String*>( + return ObjPtr<String>::DownCast(MakeObjPtr( heap->AllocObjectWithAllocator<kIsInstrumented, true>(self, string_class, alloc_size, allocator_type, - pre_fence_visitor)); + pre_fence_visitor))); } template <bool kIsInstrumented> -inline String* String::AllocEmptyString(Thread* self, gc::AllocatorType allocator_type) { +inline ObjPtr<String> 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<kIsInstrumented>(self, length_with_flag, allocator_type, visitor); } template <bool kIsInstrumented> -inline String* String::AllocFromByteArray(Thread* self, - int32_t byte_length, - Handle<ByteArray> array, - int32_t offset, - int32_t high_byte, - gc::AllocatorType allocator_type) { +inline ObjPtr<String> String::AllocFromByteArray(Thread* self, + int32_t byte_length, + Handle<ByteArray> array, + int32_t offset, + int32_t high_byte, + gc::AllocatorType allocator_type) { const uint8_t* const src = reinterpret_cast<uint8_t*>(array->GetData()) + offset; high_byte &= 0xff; // Extract the relevant bits before determining `compressible`. const bool compressible = kUseStringCompression && String::AllASCII<uint8_t>(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<kIsInstrumented>(self, length_with_flag, allocator_type, visitor); - return string; + return Alloc<kIsInstrumented>(self, length_with_flag, allocator_type, visitor); } template <bool kIsInstrumented> -inline String* String::AllocFromCharArray(Thread* self, - int32_t count, - Handle<CharArray> array, - int32_t offset, - gc::AllocatorType allocator_type) { +inline ObjPtr<String> String::AllocFromCharArray(Thread* self, + int32_t count, + Handle<CharArray> 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<uint16_t>(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<kIsInstrumented>(self, length_with_flag, allocator_type, visitor); - return new_string; + return Alloc<kIsInstrumented>(self, length_with_flag, allocator_type, visitor); } template <bool kIsInstrumented> -inline String* String::AllocFromString(Thread* self, - int32_t string_length, - Handle<String> string, - int32_t offset, - gc::AllocatorType allocator_type) { +inline ObjPtr<String> String::AllocFromString(Thread* self, + int32_t string_length, + Handle<String> string, + int32_t offset, + gc::AllocatorType allocator_type) { const bool compressible = kUseStringCompression && ((string->IsCompressed()) ? true : String::AllASCII<uint16_t>(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<kIsInstrumented>(self, length_with_flag, allocator_type, visitor); - return new_string; + return Alloc<kIsInstrumented>(self, length_with_flag, allocator_type, visitor); } } // namespace mirror |