diff options
author | Ian Rogers <irogers@google.com> | 2014-01-06 12:55:46 -0800 |
---|---|---|
committer | Ian Rogers <irogers@google.com> | 2014-02-06 23:20:27 -0800 |
commit | ef7d42fca18c16fbaf103822ad16f23246e2905d (patch) | |
tree | c67eea52a349c2ea7f2c3bdda8e73933c05531a8 /runtime/base | |
parent | 822115a225185d2896607eb08d70ce5c7099adef (diff) | |
download | android_art-ef7d42fca18c16fbaf103822ad16f23246e2905d.tar.gz android_art-ef7d42fca18c16fbaf103822ad16f23246e2905d.tar.bz2 android_art-ef7d42fca18c16fbaf103822ad16f23246e2905d.zip |
Object model changes to support 64bit.
Modify mirror objects so that references between them use an ObjectReference
value type rather than an Object* so that functionality to compress larger
references can be captured in the ObjectRefererence implementation.
ObjectReferences are 32bit and all other aspects of object layout remain as
they are currently.
Expand fields in objects holding pointers so they can hold 64bit pointers. Its
expected the size of these will come down by improving where we hold compiler
meta-data.
Stub out x86_64 architecture specific runtime implementation.
Modify OutputStream so that reads and writes are of unsigned quantities.
Make the use of portable or quick code more explicit.
Templatize AtomicInteger to support more than just int32_t as a type.
Add missing, and fix issues relating to, missing annotalysis information on the
mutator lock.
Refactor and share implementations for array copy between System and uses
elsewhere in the runtime.
Fix numerous 64bit build issues.
Change-Id: I1a5694c251a42c9eff71084dfdd4b51fff716822
Diffstat (limited to 'runtime/base')
-rw-r--r-- | runtime/base/bit_vector_test.cc | 4 | ||||
-rw-r--r-- | runtime/base/mutex.cc | 6 | ||||
-rw-r--r-- | runtime/base/mutex.h | 2 | ||||
-rw-r--r-- | runtime/base/unix_file/fd_file.cc | 16 | ||||
-rw-r--r-- | runtime/base/unix_file/fd_file.h | 4 | ||||
-rw-r--r-- | runtime/base/unix_file/mapped_file.cc | 6 | ||||
-rw-r--r-- | runtime/base/unix_file/mapped_file_test.cc | 13 | ||||
-rw-r--r-- | runtime/base/unix_file/null_file_test.cc | 6 | ||||
-rw-r--r-- | runtime/base/unix_file/random_access_file_test.h | 24 |
9 files changed, 42 insertions, 39 deletions
diff --git a/runtime/base/bit_vector_test.cc b/runtime/base/bit_vector_test.cc index d99d059e0f..3fc9b8604b 100644 --- a/runtime/base/bit_vector_test.cc +++ b/runtime/base/bit_vector_test.cc @@ -25,7 +25,7 @@ TEST(BitVector, Test) { BitVector bv(kBits, false, Allocator::GetMallocAllocator()); EXPECT_EQ(1U, bv.GetStorageSize()); - EXPECT_EQ(kWordSize, bv.GetSizeOf()); + EXPECT_EQ(sizeof(uint32_t), bv.GetSizeOf()); EXPECT_FALSE(bv.IsExpandable()); EXPECT_EQ(0U, bv.NumSetBits()); @@ -70,7 +70,7 @@ TEST(BitVector, NoopAllocator) { BitVector bv(0U, false, Allocator::GetNoopAllocator(), kWords, bits); EXPECT_EQ(kWords, bv.GetStorageSize()); - EXPECT_EQ(kWords * kWordSize, bv.GetSizeOf()); + EXPECT_EQ(kWords * sizeof(uint32_t), bv.GetSizeOf()); EXPECT_EQ(bits, bv.GetRawStorage()); EXPECT_EQ(0U, bv.NumSetBits()); diff --git a/runtime/base/mutex.cc b/runtime/base/mutex.cc index 05e3a8327e..ff72d16908 100644 --- a/runtime/base/mutex.cc +++ b/runtime/base/mutex.cc @@ -47,7 +47,7 @@ static bool ComputeRelativeTimeSpec(timespec* result_ts, const timespec& lhs, co struct AllMutexData { // A guard for all_mutexes_ that's not a mutex (Mutexes must CAS to acquire and busy wait). - AtomicInteger all_mutexes_guard; + Atomic<const BaseMutex*> all_mutexes_guard; // All created mutexes guarded by all_mutexes_guard_. std::set<BaseMutex*>* all_mutexes; AllMutexData() : all_mutexes(NULL) {} @@ -57,12 +57,12 @@ static struct AllMutexData gAllMutexData[kAllMutexDataSize]; class ScopedAllMutexesLock { public: explicit ScopedAllMutexesLock(const BaseMutex* mutex) : mutex_(mutex) { - while (!gAllMutexData->all_mutexes_guard.CompareAndSwap(0, reinterpret_cast<int32_t>(mutex))) { + while (!gAllMutexData->all_mutexes_guard.CompareAndSwap(0, mutex)) { NanoSleep(100); } } ~ScopedAllMutexesLock() { - while (!gAllMutexData->all_mutexes_guard.CompareAndSwap(reinterpret_cast<int32_t>(mutex_), 0)) { + while (!gAllMutexData->all_mutexes_guard.CompareAndSwap(mutex_, 0)) { NanoSleep(100); } } diff --git a/runtime/base/mutex.h b/runtime/base/mutex.h index 1c1dcaf43f..63ed6cbe2f 100644 --- a/runtime/base/mutex.h +++ b/runtime/base/mutex.h @@ -23,7 +23,7 @@ #include <iosfwd> #include <string> -#include "atomic_integer.h" +#include "atomic.h" #include "base/logging.h" #include "base/macros.h" #include "globals.h" diff --git a/runtime/base/unix_file/fd_file.cc b/runtime/base/unix_file/fd_file.cc index f48c76db23..87d1c0655d 100644 --- a/runtime/base/unix_file/fd_file.cc +++ b/runtime/base/unix_file/fd_file.cc @@ -102,11 +102,11 @@ bool FdFile::IsOpened() const { return fd_ >= 0; } -bool FdFile::ReadFully(void* buffer, int64_t byte_count) { +bool FdFile::ReadFully(void* buffer, size_t byte_count) { char* ptr = static_cast<char*>(buffer); while (byte_count > 0) { - int bytes_read = TEMP_FAILURE_RETRY(read(fd_, ptr, byte_count)); - if (bytes_read <= 0) { + ssize_t bytes_read = TEMP_FAILURE_RETRY(read(fd_, ptr, byte_count)); + if (bytes_read == -1) { return false; } byte_count -= bytes_read; // Reduce the number of remaining bytes. @@ -115,15 +115,15 @@ bool FdFile::ReadFully(void* buffer, int64_t byte_count) { return true; } -bool FdFile::WriteFully(const void* buffer, int64_t byte_count) { +bool FdFile::WriteFully(const void* buffer, size_t byte_count) { const char* ptr = static_cast<const char*>(buffer); while (byte_count > 0) { - int bytes_read = TEMP_FAILURE_RETRY(write(fd_, ptr, byte_count)); - if (bytes_read < 0) { + ssize_t bytes_written = TEMP_FAILURE_RETRY(write(fd_, ptr, byte_count)); + if (bytes_written == -1) { return false; } - byte_count -= bytes_read; // Reduce the number of remaining bytes. - ptr += bytes_read; // Move the buffer forward. + byte_count -= bytes_written; // Reduce the number of remaining bytes. + ptr += bytes_written; // Move the buffer forward. } return true; } diff --git a/runtime/base/unix_file/fd_file.h b/runtime/base/unix_file/fd_file.h index 19e3511eb4..01f4ca2819 100644 --- a/runtime/base/unix_file/fd_file.h +++ b/runtime/base/unix_file/fd_file.h @@ -61,8 +61,8 @@ class FdFile : public RandomAccessFile { return file_path_; } void DisableAutoClose(); - bool ReadFully(void* buffer, int64_t byte_count); - bool WriteFully(const void* buffer, int64_t byte_count); + bool ReadFully(void* buffer, size_t byte_count); + bool WriteFully(const void* buffer, size_t byte_count); private: int fd_; diff --git a/runtime/base/unix_file/mapped_file.cc b/runtime/base/unix_file/mapped_file.cc index b63fdd3bef..bc23a745c9 100644 --- a/runtime/base/unix_file/mapped_file.cc +++ b/runtime/base/unix_file/mapped_file.cc @@ -101,7 +101,8 @@ int64_t MappedFile::Read(char* buf, int64_t byte_count, int64_t offset) const { errno = EINVAL; return -errno; } - int64_t read_size = std::max(0LL, std::min(byte_count, file_size_ - offset)); + int64_t read_size = std::max(static_cast<int64_t>(0), + std::min(byte_count, file_size_ - offset)); if (read_size > 0) { memcpy(buf, data() + offset, read_size); } @@ -136,7 +137,8 @@ int64_t MappedFile::Write(const char* buf, int64_t byte_count, int64_t offset) { errno = EINVAL; return -errno; } - int64_t write_size = std::max(0LL, std::min(byte_count, file_size_ - offset)); + int64_t write_size = std::max(static_cast<int64_t>(0), + std::min(byte_count, file_size_ - offset)); if (write_size > 0) { memcpy(data() + offset, buf, write_size); } diff --git a/runtime/base/unix_file/mapped_file_test.cc b/runtime/base/unix_file/mapped_file_test.cc index 3dda02f59f..49750f446d 100644 --- a/runtime/base/unix_file/mapped_file_test.cc +++ b/runtime/base/unix_file/mapped_file_test.cc @@ -65,7 +65,7 @@ TEST_F(MappedFileTest, OpenClose) { ASSERT_TRUE(file.Open(good_path_, MappedFile::kReadOnlyMode)); EXPECT_GE(file.Fd(), 0); EXPECT_TRUE(file.IsOpened()); - EXPECT_EQ(kContent.size(), file.size()); + EXPECT_EQ(kContent.size(), static_cast<uint64_t>(file.size())); EXPECT_EQ(0, file.Close()); EXPECT_EQ(-1, file.Fd()); EXPECT_FALSE(file.IsOpened()); @@ -86,7 +86,7 @@ TEST_F(MappedFileTest, CanUseAfterMapReadOnly) { EXPECT_FALSE(file.IsMapped()); EXPECT_TRUE(file.MapReadOnly()); EXPECT_TRUE(file.IsMapped()); - EXPECT_EQ(kContent.size(), file.size()); + EXPECT_EQ(kContent.size(), static_cast<uint64_t>(file.size())); ASSERT_TRUE(file.data()); EXPECT_EQ(0, memcmp(kContent.c_str(), file.data(), file.size())); EXPECT_EQ(0, file.Flush()); @@ -113,7 +113,7 @@ TEST_F(MappedFileTest, CanWriteNewData) { ASSERT_TRUE(file.Open(new_path, MappedFile::kReadWriteMode)); EXPECT_TRUE(file.MapReadWrite(kContent.size())); EXPECT_TRUE(file.IsMapped()); - EXPECT_EQ(kContent.size(), file.size()); + EXPECT_EQ(kContent.size(), static_cast<uint64_t>(file.size())); ASSERT_TRUE(file.data()); memcpy(file.data(), kContent.c_str(), kContent.size()); EXPECT_EQ(0, file.Close()); @@ -200,15 +200,16 @@ TEST_F(MappedFileTest, WriteMappedReadWrite) { // A zero-length write is a no-op. EXPECT_EQ(0, file.Write(kContent.c_str(), 0, 0)); // But the file size is as given when mapped. - EXPECT_EQ(kContent.size(), file.GetLength()); + EXPECT_EQ(kContent.size(), static_cast<uint64_t>(file.GetLength())); // Data written past the end are discarded. EXPECT_EQ(kContent.size() - 1, - file.Write(kContent.c_str(), kContent.size(), 1)); + static_cast<uint64_t>(file.Write(kContent.c_str(), kContent.size(), 1))); EXPECT_EQ(0, memcmp(kContent.c_str(), file.data() + 1, kContent.size() - 1)); // Data can be overwritten. - EXPECT_EQ(kContent.size(), file.Write(kContent.c_str(), kContent.size(), 0)); + EXPECT_EQ(kContent.size(), + static_cast<uint64_t>(file.Write(kContent.c_str(), kContent.size(), 0))); EXPECT_EQ(0, memcmp(kContent.c_str(), file.data(), kContent.size())); } diff --git a/runtime/base/unix_file/null_file_test.cc b/runtime/base/unix_file/null_file_test.cc index 0f20acd825..410fdfc28e 100644 --- a/runtime/base/unix_file/null_file_test.cc +++ b/runtime/base/unix_file/null_file_test.cc @@ -48,7 +48,7 @@ TEST_F(NullFileTest, GetLength) { NullFile f; // The length is always 0. ASSERT_EQ(0, f.GetLength()); - ASSERT_EQ(content.size(), f.Write(content.data(), content.size(), 0)); + ASSERT_EQ(content.size(), static_cast<uint64_t>(f.Write(content.data(), content.size(), 0))); ASSERT_EQ(0, f.GetLength()); } @@ -58,8 +58,8 @@ TEST_F(NullFileTest, Write) { // You can't write at a negative offset... ASSERT_EQ(-EINVAL, f.Write(content.data(), content.size(), -128)); // But you can write anywhere else... - ASSERT_EQ(content.size(), f.Write(content.data(), content.size(), 0)); - ASSERT_EQ(content.size(), f.Write(content.data(), content.size(), 128)); + ASSERT_EQ(content.size(), static_cast<uint64_t>(f.Write(content.data(), content.size(), 0))); + ASSERT_EQ(content.size(), static_cast<uint64_t>(f.Write(content.data(), content.size(), 128))); // ...though the file will remain empty. ASSERT_EQ(0, f.GetLength()); } diff --git a/runtime/base/unix_file/random_access_file_test.h b/runtime/base/unix_file/random_access_file_test.h index 9d8550d6f6..31527888c7 100644 --- a/runtime/base/unix_file/random_access_file_test.h +++ b/runtime/base/unix_file/random_access_file_test.h @@ -71,7 +71,7 @@ class RandomAccessFileTest : public testing::Test { ASSERT_EQ(0, file->Read(buf, 123, 0)); const std::string content("hello"); - ASSERT_EQ(content.size(), file->Write(content.data(), content.size(), 0)); + ASSERT_EQ(content.size(), static_cast<uint64_t>(file->Write(content.data(), content.size(), 0))); TestReadContent(content, file.get()); } @@ -83,21 +83,21 @@ class RandomAccessFileTest : public testing::Test { ASSERT_EQ(-EINVAL, file->Read(buf.get(), 0, -123)); // Reading too much gets us just what's in the file. - ASSERT_EQ(content.size(), file->Read(buf.get(), buf_size, 0)); + ASSERT_EQ(content.size(), static_cast<uint64_t>(file->Read(buf.get(), buf_size, 0))); ASSERT_EQ(std::string(buf.get(), content.size()), content); // We only get as much as we ask for. const size_t short_request = 2; ASSERT_LT(short_request, content.size()); - ASSERT_EQ(short_request, file->Read(buf.get(), short_request, 0)); + ASSERT_EQ(short_request, static_cast<uint64_t>(file->Read(buf.get(), short_request, 0))); ASSERT_EQ(std::string(buf.get(), short_request), content.substr(0, short_request)); // We don't have to start at the beginning. const int non_zero_offset = 2; ASSERT_GT(non_zero_offset, 0); - ASSERT_EQ(short_request, - file->Read(buf.get(), short_request, non_zero_offset)); + ASSERT_EQ(short_request, static_cast<uint64_t>(file->Read(buf.get(), short_request, + non_zero_offset))); ASSERT_EQ(std::string(buf.get(), short_request), content.substr(non_zero_offset, short_request)); @@ -109,8 +109,8 @@ class RandomAccessFileTest : public testing::Test { void TestSetLength() { const std::string content("hello"); UniquePtr<RandomAccessFile> file(MakeTestFile()); - ASSERT_EQ(content.size(), file->Write(content.data(), content.size(), 0)); - ASSERT_EQ(content.size(), file->GetLength()); + ASSERT_EQ(content.size(), static_cast<uint64_t>(file->Write(content.data(), content.size(), 0))); + ASSERT_EQ(content.size(), static_cast<uint64_t>(file->GetLength())); // Can't give a file a negative length. ASSERT_EQ(-EINVAL, file->SetLength(-123)); @@ -143,20 +143,20 @@ class RandomAccessFileTest : public testing::Test { ASSERT_EQ(0, file->GetLength()); // We can write data. - ASSERT_EQ(content.size(), file->Write(content.data(), content.size(), 0)); - ASSERT_EQ(content.size(), file->GetLength()); + ASSERT_EQ(content.size(), static_cast<uint64_t>(file->Write(content.data(), content.size(), 0))); + ASSERT_EQ(content.size(), static_cast<uint64_t>(file->GetLength())); std::string new_content; ASSERT_TRUE(ReadString(file.get(), &new_content)); ASSERT_EQ(new_content, content); // We can read it back. char buf[256]; - ASSERT_EQ(content.size(), file->Read(buf, sizeof(buf), 0)); + ASSERT_EQ(content.size(), static_cast<uint64_t>(file->Read(buf, sizeof(buf), 0))); ASSERT_EQ(std::string(buf, content.size()), content); // We can append data past the end. - ASSERT_EQ(content.size(), - file->Write(content.data(), content.size(), file->GetLength() + 1)); + ASSERT_EQ(content.size(), static_cast<uint64_t>(file->Write(content.data(), content.size(), + file->GetLength() + 1))); int64_t new_length = 2*content.size() + 1; ASSERT_EQ(file->GetLength(), new_length); ASSERT_TRUE(ReadString(file.get(), &new_content)); |