TEST_F(VerificationTest, IsValidClassInHeap) { // Now that the String class is allocated in the non-moving space when the // runtime is running without a boot image (which is the case in this gtest), // and we run with AddressSanizer, it is possible that the (presumably // invalid) memory location `uint_klass - kObjectAlignment` tested below is // poisoned when running with AddressSanizer. Disable this test in that case.
TEST_DISABLED_FOR_MEMORY_TOOL();
ScopedObjectAccess soa(Thread::Current());
VariableSizedHandleScope hs(soa.Self());
Handle<mirror::String> string(
hs.NewHandle(mirror::String::AllocFromModifiedUtf8(soa.Self(), "test"))); const Verification* const v = Runtime::Current()->GetHeap()->GetVerification();
uintptr_t uint_klass = reinterpret_cast<uintptr_t>(string->GetClass());
EXPECT_FALSE(v->IsValidClass(reinterpret_cast<mirror::Class*>(uint_klass - kObjectAlignment)));
EXPECT_FALSE(v->IsValidClass(reinterpret_cast<mirror::Class*>(&uint_klass)));
}
TEST_F(VerificationTest, DumpValidObjectInfo) { // Now that the String class is allocated in the non-moving space when the // runtime is running without a boot image (which is the case in this gtest), // and we run with AddressSanizer, it is possible that the calls to // Verification::DumpObjectInfo below involving the String class object // (`string->GetClass()`, `uint_klass`, etc.) access poisoned memory when they // call Verification::DumpRAMAroundAddress. Disable this test in that case.
TEST_DISABLED_FOR_MEMORY_TOOL();
ScopedLogSeverity sls(LogSeverity::INFO);
ScopedObjectAccess soa(Thread::Current());
Runtime* const runtime = Runtime::Current();
VariableSizedHandleScope hs(soa.Self());
Handle<mirror::String> string(
hs.NewHandle(mirror::String::AllocFromModifiedUtf8(soa.Self(), "obj")));
Handle<mirror::ObjectArray<mirror::Object>> arr(
hs.NewHandle(AllocObjectArray<mirror::Object>(soa.Self(), 256))); const Verification* const v = runtime->GetHeap()->GetVerification();
LOG(INFO) << v->DumpObjectInfo(string.Get(), "test");
LOG(INFO) << v->DumpObjectInfo(string->GetClass(), "obj"); const uintptr_t uint_klass = reinterpret_cast<uintptr_t>(string->GetClass());
LOG(INFO) << v->DumpObjectInfo(reinterpret_cast<constvoid*>(uint_klass - kObjectAlignment), "obj");
LOG(INFO) << v->DumpObjectInfo(reinterpret_cast<constvoid*>(&uint_klass), "obj");
LOG(INFO) << v->DumpObjectInfo(arr.Get(), "arr");
}
TEST_F(VerificationTest, LogHeapCorruption) { // Now that the String class is allocated in the non-moving space when the // runtime is running without a boot image (which is the case in this gtest), // and we run with AddressSanizer, it is possible that the call to // Verification::LogHeapCorruption below involving the String class object // (`string->GetClass()`) accesses poisoned memory when it calls // Verification::DumpRAMAroundAddress. Disable this test in that case.
TEST_DISABLED_FOR_MEMORY_TOOL();
ScopedLogSeverity sls(LogSeverity::INFO);
ScopedObjectAccess soa(Thread::Current());
Runtime* const runtime = Runtime::Current();
VariableSizedHandleScope hs(soa.Self());
Handle<mirror::String> string(
hs.NewHandle(mirror::String::AllocFromModifiedUtf8(soa.Self(), "obj"))); using ObjArray = mirror::ObjectArray<mirror::Object>;
Handle<ObjArray> arr(
hs.NewHandle(AllocObjectArray<mirror::Object>(soa.Self(), 256))); const Verification* const v = runtime->GetHeap()->GetVerification();
arr->Set(0, string.Get()); // Test normal cases.
v->LogHeapCorruption(arr.Get(), ObjArray::DataOffset(kHeapReferenceSize), string.Get(), false);
v->LogHeapCorruption(string.Get(), mirror::Object::ClassOffset(), string->GetClass(), false); // Test null holder cases.
v->LogHeapCorruption(nullptr, MemberOffset(0), string.Get(), false);
v->LogHeapCorruption(nullptr, MemberOffset(0), arr.Get(), false);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.