Optimize aput-object in interpreter.
Inline ObjectArray::Set test about valid index and valid object. Adding
ObjectArray::IsValidObject method to check for ArrayStoreException and
call it from interpreter.
Change-Id: I99beeb531455049fc189f9b8e8f4f020591f7bab
diff --git a/src/mirror/object_array-inl.h b/src/mirror/object_array-inl.h
index d981428..05bce95 100644
--- a/src/mirror/object_array-inl.h
+++ b/src/mirror/object_array-inl.h
@@ -23,6 +23,7 @@
#include "mirror/class.h"
#include "mirror/field.h"
#include "runtime.h"
+#include "thread.h"
namespace art {
namespace mirror {
@@ -47,17 +48,24 @@
}
template<class T>
-inline void ObjectArray<T>::Set(int32_t i, T* object) {
- if (LIKELY(IsValidIndex(i))) {
- if (object != NULL) {
- Class* element_class = GetClass()->GetComponentType();
- if (UNLIKELY(!object->InstanceOf(element_class))) {
- ThrowArrayStoreException(object);
- return;
- }
+inline bool ObjectArray<T>::CheckAssignable(T* object) {
+ if (object != NULL) {
+ Class* element_class = GetClass()->GetComponentType();
+ if (UNLIKELY(!object->InstanceOf(element_class))) {
+ ThrowArrayStoreException(object);
+ return false;
}
+ }
+ return true;
+}
+
+template<class T>
+inline void ObjectArray<T>::Set(int32_t i, T* object) {
+ if (LIKELY(IsValidIndex(i) && CheckAssignable(object))) {
MemberOffset data_offset(DataOffset(sizeof(Object*)).Int32Value() + i * sizeof(Object*));
SetFieldObject(data_offset, object, false);
+ } else {
+ DCHECK(Thread::Current()->IsExceptionPending());
}
}