Fix alignment bug in PreObjectAlloc
We were incorrectly setting the byte-count to a potentially unaligned
value. This could cause CHECK failures in rare situations.
Test: ./test.py --host
Bug: 146436130
Change-Id: Ia8d650b085af875fc45e5408ed7b81f9ce69df1f
diff --git a/openjdkjvmti/alloc_manager.cc b/openjdkjvmti/alloc_manager.cc
index 597ab05..f5e4af6 100644
--- a/openjdkjvmti/alloc_manager.cc
+++ b/openjdkjvmti/alloc_manager.cc
@@ -41,6 +41,7 @@
#include "handle.h"
#include "mirror/class-inl.h"
#include "runtime.h"
+#include "runtime_globals.h"
#include "scoped_thread_state_change-inl.h"
#include "scoped_thread_state_change.h"
#include "thread-current-inl.h"
@@ -104,7 +105,9 @@
return oss.str();
});
if (!type->IsVariableSize()) {
- *byte_count = type->GetObjectSize();
+ *byte_count =
+ std::max(art::RoundUp(static_cast<size_t>(type->GetObjectSize()), art::kObjectAlignment),
+ *byte_count);
}
}