ART: Move DexCache arrays to native.
This CL has a companion CL in libcore/
https://android-review.googlesource.com/162985
Change-Id: Icbc9e20ad1b565e603195b12714762bb446515fa
diff --git a/runtime/arch/x86_64/quick_entrypoints_x86_64.S b/runtime/arch/x86_64/quick_entrypoints_x86_64.S
index 1498a4b..9303b00 100644
--- a/runtime/arch/x86_64/quick_entrypoints_x86_64.S
+++ b/runtime/arch/x86_64/quick_entrypoints_x86_64.S
@@ -926,7 +926,7 @@
int3
#endif
// Might need a special macro since rsi and edx is 32b/64b mismatched.
- movl ART_METHOD_DEX_CACHE_TYPES_OFFSET(%rsi), %edx // Load dex cache resolved types array
+ movl ART_METHOD_DEX_CACHE_TYPES_OFFSET_64(%rsi), %edx // Load dex cache resolved types array
UNPOISON_HEAP_REF edx
// TODO: Add read barrier when this function is used.
// Might need to break down into multiple instructions to get the base address in a register.
diff --git a/runtime/art_field-inl.h b/runtime/art_field-inl.h
index 5138cc9..4166e22 100644
--- a/runtime/art_field-inl.h
+++ b/runtime/art_field-inl.h
@@ -24,7 +24,7 @@
#include "gc_root-inl.h"
#include "gc/accounting/card_table-inl.h"
#include "jvalue.h"
-#include "mirror/dex_cache.h"
+#include "mirror/dex_cache-inl.h"
#include "mirror/object-inl.h"
#include "primitive.h"
#include "thread-inl.h"
diff --git a/runtime/art_method-inl.h b/runtime/art_method-inl.h
index d38cc56..cfd7fcd 100644
--- a/runtime/art_method-inl.h
+++ b/runtime/art_method-inl.h
@@ -22,11 +22,12 @@
#include "art_field.h"
#include "base/logging.h"
#include "class_linker-inl.h"
+#include "common_throws.h"
#include "dex_file.h"
#include "dex_file-inl.h"
#include "gc_root-inl.h"
#include "mirror/class-inl.h"
-#include "mirror/dex_cache.h"
+#include "mirror/dex_cache-inl.h"
#include "mirror/object-inl.h"
#include "mirror/object_array.h"
#include "oat.h"
@@ -95,14 +96,20 @@
return dex_method_index_;
}
-inline mirror::PointerArray* ArtMethod::GetDexCacheResolvedMethods() {
- GcRootSource gc_root_source(this);
- return dex_cache_resolved_methods_.Read(&gc_root_source);
+inline ArtMethod** ArtMethod::GetDexCacheResolvedMethods(size_t pointer_size) {
+ return GetNativePointer<ArtMethod**>(DexCacheResolvedMethodsOffset(pointer_size),
+ pointer_size);
}
inline ArtMethod* ArtMethod::GetDexCacheResolvedMethod(uint16_t method_index, size_t ptr_size) {
- auto* method = GetDexCacheResolvedMethods()->GetElementPtrSize<ArtMethod*>(
- method_index, ptr_size);
+ // NOTE: Unchecked, i.e. not throwing AIOOB. We don't even know the length here
+ // without accessing the DexCache and we don't want to do that in release build.
+ DCHECK_LT(method_index,
+ GetInterfaceMethodIfProxy(ptr_size)->GetDeclaringClass()
+ ->GetDexCache()->NumResolvedMethods());
+ ArtMethod* method = mirror::DexCache::GetElementPtrSize(GetDexCacheResolvedMethods(ptr_size),
+ method_index,
+ ptr_size);
if (LIKELY(method != nullptr)) {
auto* declaring_class = method->GetDeclaringClass();
if (LIKELY(declaring_class == nullptr || !declaring_class->IsErroneous())) {
@@ -112,52 +119,70 @@
return nullptr;
}
-inline void ArtMethod::SetDexCacheResolvedMethod(uint16_t method_idx, ArtMethod* new_method,
+inline void ArtMethod::SetDexCacheResolvedMethod(uint16_t method_index, ArtMethod* new_method,
size_t ptr_size) {
+ // NOTE: Unchecked, i.e. not throwing AIOOB. We don't even know the length here
+ // without accessing the DexCache and we don't want to do that in release build.
+ DCHECK_LT(method_index,
+ GetInterfaceMethodIfProxy(ptr_size)->GetDeclaringClass()
+ ->GetDexCache()->NumResolvedMethods());
DCHECK(new_method == nullptr || new_method->GetDeclaringClass() != nullptr);
- GetDexCacheResolvedMethods()->SetElementPtrSize(method_idx, new_method, ptr_size);
+ mirror::DexCache::SetElementPtrSize(GetDexCacheResolvedMethods(ptr_size),
+ method_index,
+ new_method,
+ ptr_size);
}
-inline bool ArtMethod::HasDexCacheResolvedMethods() {
- return GetDexCacheResolvedMethods() != nullptr;
+inline bool ArtMethod::HasDexCacheResolvedMethods(size_t pointer_size) {
+ return GetDexCacheResolvedMethods(pointer_size) != nullptr;
}
-inline bool ArtMethod::HasSameDexCacheResolvedMethods(mirror::PointerArray* other_cache) {
- return GetDexCacheResolvedMethods() == other_cache;
+inline bool ArtMethod::HasSameDexCacheResolvedMethods(ArtMethod** other_cache,
+ size_t pointer_size) {
+ return GetDexCacheResolvedMethods(pointer_size) == other_cache;
}
-inline bool ArtMethod::HasSameDexCacheResolvedMethods(ArtMethod* other) {
- return GetDexCacheResolvedMethods() == other->GetDexCacheResolvedMethods();
+inline bool ArtMethod::HasSameDexCacheResolvedMethods(ArtMethod* other, size_t pointer_size) {
+ return GetDexCacheResolvedMethods(pointer_size) ==
+ other->GetDexCacheResolvedMethods(pointer_size);
}
-inline mirror::ObjectArray<mirror::Class>* ArtMethod::GetDexCacheResolvedTypes() {
- GcRootSource gc_root_source(this);
- return dex_cache_resolved_types_.Read(&gc_root_source);
+inline GcRoot<mirror::Class>* ArtMethod::GetDexCacheResolvedTypes(size_t pointer_size) {
+ return GetNativePointer<GcRoot<mirror::Class>*>(DexCacheResolvedTypesOffset(pointer_size),
+ pointer_size);
}
template <bool kWithCheck>
-inline mirror::Class* ArtMethod::GetDexCacheResolvedType(uint32_t type_index) {
- mirror::Class* klass = kWithCheck ?
- GetDexCacheResolvedTypes()->Get(type_index) :
- GetDexCacheResolvedTypes()->GetWithoutChecks(type_index);
+inline mirror::Class* ArtMethod::GetDexCacheResolvedType(uint32_t type_index, size_t ptr_size) {
+ if (kWithCheck) {
+ mirror::DexCache* dex_cache =
+ GetInterfaceMethodIfProxy(ptr_size)->GetDeclaringClass()->GetDexCache();
+ if (UNLIKELY(type_index >= dex_cache->NumResolvedTypes())) {
+ ThrowArrayIndexOutOfBoundsException(type_index, dex_cache->NumResolvedTypes());
+ return nullptr;
+ }
+ }
+ mirror::Class* klass = GetDexCacheResolvedTypes(ptr_size)[type_index].Read();
return (klass != nullptr && !klass->IsErroneous()) ? klass : nullptr;
}
-inline bool ArtMethod::HasDexCacheResolvedTypes() {
- return GetDexCacheResolvedTypes() != nullptr;
+inline bool ArtMethod::HasDexCacheResolvedTypes(size_t pointer_size) {
+ return GetDexCacheResolvedTypes(pointer_size) != nullptr;
}
-inline bool ArtMethod::HasSameDexCacheResolvedTypes(
- mirror::ObjectArray<mirror::Class>* other_cache) {
- return GetDexCacheResolvedTypes() == other_cache;
+inline bool ArtMethod::HasSameDexCacheResolvedTypes(GcRoot<mirror::Class>* other_cache,
+ size_t pointer_size) {
+ return GetDexCacheResolvedTypes(pointer_size) == other_cache;
}
-inline bool ArtMethod::HasSameDexCacheResolvedTypes(ArtMethod* other) {
- return GetDexCacheResolvedTypes() == other->GetDexCacheResolvedTypes();
+inline bool ArtMethod::HasSameDexCacheResolvedTypes(ArtMethod* other, size_t pointer_size) {
+ return GetDexCacheResolvedTypes(pointer_size) == other->GetDexCacheResolvedTypes(pointer_size);
}
-inline mirror::Class* ArtMethod::GetClassFromTypeIndex(uint16_t type_idx, bool resolve) {
- mirror::Class* type = GetDexCacheResolvedType(type_idx);
+inline mirror::Class* ArtMethod::GetClassFromTypeIndex(uint16_t type_idx,
+ bool resolve,
+ size_t ptr_size) {
+ mirror::Class* type = GetDexCacheResolvedType(type_idx, ptr_size);
if (type == nullptr && resolve) {
type = Runtime::Current()->GetClassLinker()->ResolveType(type_idx, this);
CHECK(type != nullptr || Thread::Current()->IsExceptionPending());
@@ -391,9 +416,9 @@
return GetDeclaringClass()->GetDexFile().GetCodeItem(GetCodeItemOffset());
}
-inline bool ArtMethod::IsResolvedTypeIdx(uint16_t type_idx) {
+inline bool ArtMethod::IsResolvedTypeIdx(uint16_t type_idx, size_t ptr_size) {
DCHECK(!IsProxyMethod());
- return GetDexCacheResolvedType(type_idx) != nullptr;
+ return GetDexCacheResolvedType(type_idx, ptr_size) != nullptr;
}
inline int32_t ArtMethod::GetLineNumFromDexPC(uint32_t dex_pc) {
@@ -467,30 +492,33 @@
return this;
}
mirror::Class* klass = GetDeclaringClass();
- auto interface_method = GetDexCacheResolvedMethods()->GetElementPtrSize<ArtMethod*>(
- GetDexMethodIndex(), pointer_size);
+ ArtMethod* interface_method = mirror::DexCache::GetElementPtrSize(
+ GetDexCacheResolvedMethods(pointer_size),
+ GetDexMethodIndex(),
+ pointer_size);
DCHECK(interface_method != nullptr);
DCHECK_EQ(interface_method,
Runtime::Current()->GetClassLinker()->FindMethodForProxy(klass, this));
return interface_method;
}
-inline void ArtMethod::SetDexCacheResolvedMethods(mirror::PointerArray* new_dex_cache_methods) {
- dex_cache_resolved_methods_ = GcRoot<mirror::PointerArray>(new_dex_cache_methods);
+inline void ArtMethod::SetDexCacheResolvedMethods(ArtMethod** new_dex_cache_methods,
+ size_t ptr_size) {
+ SetNativePointer(DexCacheResolvedMethodsOffset(ptr_size), new_dex_cache_methods, ptr_size);
}
-inline void ArtMethod::SetDexCacheResolvedTypes(
- mirror::ObjectArray<mirror::Class>* new_dex_cache_types) {
- dex_cache_resolved_types_ = GcRoot<mirror::ObjectArray<mirror::Class>>(new_dex_cache_types);
+inline void ArtMethod::SetDexCacheResolvedTypes(GcRoot<mirror::Class>* new_dex_cache_types,
+ size_t ptr_size) {
+ SetNativePointer(DexCacheResolvedTypesOffset(ptr_size), new_dex_cache_types, ptr_size);
}
-inline mirror::Class* ArtMethod::GetReturnType(bool resolve) {
+inline mirror::Class* ArtMethod::GetReturnType(bool resolve, size_t ptr_size) {
DCHECK(!IsProxyMethod());
const DexFile* dex_file = GetDexFile();
const DexFile::MethodId& method_id = dex_file->GetMethodId(GetDexMethodIndex());
const DexFile::ProtoId& proto_id = dex_file->GetMethodPrototype(method_id);
uint16_t return_type_idx = proto_id.return_type_idx_;
- mirror::Class* type = GetDexCacheResolvedType(return_type_idx);
+ mirror::Class* type = GetDexCacheResolvedType(return_type_idx, ptr_size);
if (type == nullptr && resolve) {
type = Runtime::Current()->GetClassLinker()->ResolveType(return_type_idx, this);
CHECK(type != nullptr || Thread::Current()->IsExceptionPending());
@@ -500,19 +528,29 @@
template<typename RootVisitorType>
void ArtMethod::VisitRoots(RootVisitorType& visitor) {
+ ArtMethod* interface_method = nullptr;
+ mirror::Class* klass = declaring_class_.Read();
+ if (UNLIKELY(klass != nullptr && klass->IsProxyClass())) {
+ // For normal methods, dex cache shortcuts will be visited through the declaring class.
+ // However, for proxies we need to keep the interface method alive, so we visit its roots.
+ size_t pointer_size = Runtime::Current()->GetClassLinker()->GetImagePointerSize();
+ interface_method = mirror::DexCache::GetElementPtrSize(
+ GetDexCacheResolvedMethods(pointer_size),
+ GetDexMethodIndex(),
+ pointer_size);
+ DCHECK(interface_method != nullptr);
+ DCHECK_EQ(interface_method,
+ Runtime::Current()->GetClassLinker()->FindMethodForProxy(klass, this));
+ interface_method->VisitRoots(visitor);
+ }
+
visitor.VisitRootIfNonNull(declaring_class_.AddressWithoutBarrier());
- visitor.VisitRootIfNonNull(dex_cache_resolved_methods_.AddressWithoutBarrier());
- visitor.VisitRootIfNonNull(dex_cache_resolved_types_.AddressWithoutBarrier());
}
inline void ArtMethod::CopyFrom(const ArtMethod* src, size_t image_pointer_size) {
memcpy(reinterpret_cast<void*>(this), reinterpret_cast<const void*>(src),
Size(image_pointer_size));
declaring_class_ = GcRoot<mirror::Class>(const_cast<ArtMethod*>(src)->GetDeclaringClass());
- dex_cache_resolved_methods_ = GcRoot<mirror::PointerArray>(
- const_cast<ArtMethod*>(src)->GetDexCacheResolvedMethods());
- dex_cache_resolved_types_ = GcRoot<mirror::ObjectArray<mirror::Class>>(
- const_cast<ArtMethod*>(src)->GetDexCacheResolvedTypes());
}
} // namespace art
diff --git a/runtime/art_method.cc b/runtime/art_method.cc
index e46402d..64416d2 100644
--- a/runtime/art_method.cc
+++ b/runtime/art_method.cc
@@ -125,8 +125,9 @@
} else {
// Method didn't override superclass method so search interfaces
if (IsProxyMethod()) {
- result = GetDexCacheResolvedMethods()->GetElementPtrSize<ArtMethod*>(
- GetDexMethodIndex(), pointer_size);
+ result = mirror::DexCache::GetElementPtrSize(GetDexCacheResolvedMethods(pointer_size),
+ GetDexMethodIndex(),
+ pointer_size);
CHECK_EQ(result,
Runtime::Current()->GetClassLinker()->FindMethodForProxy(GetDeclaringClass(), this));
} else {
@@ -261,6 +262,7 @@
// Default to handler not found.
uint32_t found_dex_pc = DexFile::kDexNoIndex;
// Iterate over the catch handlers associated with dex_pc.
+ size_t pointer_size = Runtime::Current()->GetClassLinker()->GetImagePointerSize();
for (CatchHandlerIterator it(*code_item, dex_pc); it.HasNext(); it.Next()) {
uint16_t iter_type_idx = it.GetHandlerTypeIndex();
// Catch all case
@@ -269,7 +271,9 @@
break;
}
// Does this catch exception type apply?
- mirror::Class* iter_exception_type = GetClassFromTypeIndex(iter_type_idx, true);
+ mirror::Class* iter_exception_type = GetClassFromTypeIndex(iter_type_idx,
+ true /* resolve */,
+ pointer_size);
if (UNLIKELY(iter_exception_type == nullptr)) {
// Now have a NoClassDefFoundError as exception. Ignore in case the exception class was
// removed by a pro-guard like tool.
diff --git a/runtime/art_method.h b/runtime/art_method.h
index 6cdc4a6..e0b11d0 100644
--- a/runtime/art_method.h
+++ b/runtime/art_method.h
@@ -17,6 +17,7 @@
#ifndef ART_RUNTIME_ART_METHOD_H_
#define ART_RUNTIME_ART_METHOD_H_
+#include "base/casts.h"
#include "dex_file.h"
#include "gc_root.h"
#include "invoke_type.h"
@@ -212,41 +213,35 @@
dex_method_index_ = new_idx;
}
- static MemberOffset DexCacheResolvedMethodsOffset() {
- return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_methods_);
- }
-
- static MemberOffset DexCacheResolvedTypesOffset() {
- return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_types_);
- }
-
- ALWAYS_INLINE mirror::PointerArray* GetDexCacheResolvedMethods()
+ ALWAYS_INLINE ArtMethod** GetDexCacheResolvedMethods(size_t pointer_size)
SHARED_REQUIRES(Locks::mutator_lock_);
- ALWAYS_INLINE ArtMethod* GetDexCacheResolvedMethod(uint16_t method_idx, size_t ptr_size)
+ ALWAYS_INLINE ArtMethod* GetDexCacheResolvedMethod(uint16_t method_index, size_t ptr_size)
SHARED_REQUIRES(Locks::mutator_lock_);
- ALWAYS_INLINE void SetDexCacheResolvedMethod(uint16_t method_idx, ArtMethod* new_method,
+ ALWAYS_INLINE void SetDexCacheResolvedMethod(uint16_t method_index,
+ ArtMethod* new_method,
size_t ptr_size)
SHARED_REQUIRES(Locks::mutator_lock_);
- ALWAYS_INLINE void SetDexCacheResolvedMethods(mirror::PointerArray* new_dex_cache_methods)
+ ALWAYS_INLINE void SetDexCacheResolvedMethods(ArtMethod** new_dex_cache_methods, size_t ptr_size)
SHARED_REQUIRES(Locks::mutator_lock_);
- bool HasDexCacheResolvedMethods() SHARED_REQUIRES(Locks::mutator_lock_);
- bool HasSameDexCacheResolvedMethods(ArtMethod* other)
+ bool HasDexCacheResolvedMethods(size_t pointer_size) SHARED_REQUIRES(Locks::mutator_lock_);
+ bool HasSameDexCacheResolvedMethods(ArtMethod* other, size_t pointer_size)
SHARED_REQUIRES(Locks::mutator_lock_);
- bool HasSameDexCacheResolvedMethods(mirror::PointerArray* other_cache)
+ bool HasSameDexCacheResolvedMethods(ArtMethod** other_cache, size_t pointer_size)
SHARED_REQUIRES(Locks::mutator_lock_);
template <bool kWithCheck = true>
- mirror::Class* GetDexCacheResolvedType(uint32_t type_idx)
+ mirror::Class* GetDexCacheResolvedType(uint32_t type_idx, size_t ptr_size)
SHARED_REQUIRES(Locks::mutator_lock_);
- void SetDexCacheResolvedTypes(mirror::ObjectArray<mirror::Class>* new_dex_cache_types)
+ void SetDexCacheResolvedTypes(GcRoot<mirror::Class>* new_dex_cache_types, size_t ptr_size)
SHARED_REQUIRES(Locks::mutator_lock_);
- bool HasDexCacheResolvedTypes() SHARED_REQUIRES(Locks::mutator_lock_);
- bool HasSameDexCacheResolvedTypes(ArtMethod* other) SHARED_REQUIRES(Locks::mutator_lock_);
- bool HasSameDexCacheResolvedTypes(mirror::ObjectArray<mirror::Class>* other_cache)
+ bool HasDexCacheResolvedTypes(size_t pointer_size) SHARED_REQUIRES(Locks::mutator_lock_);
+ bool HasSameDexCacheResolvedTypes(ArtMethod* other, size_t pointer_size)
+ SHARED_REQUIRES(Locks::mutator_lock_);
+ bool HasSameDexCacheResolvedTypes(GcRoot<mirror::Class>* other_cache, size_t pointer_size)
SHARED_REQUIRES(Locks::mutator_lock_);
// Get the Class* from the type index into this method's dex cache.
- mirror::Class* GetClassFromTypeIndex(uint16_t type_idx, bool resolve)
+ mirror::Class* GetClassFromTypeIndex(uint16_t type_idx, bool resolve, size_t ptr_size)
SHARED_REQUIRES(Locks::mutator_lock_);
// Find the method that this method overrides.
@@ -267,7 +262,7 @@
return GetEntryPointFromQuickCompiledCodePtrSize(sizeof(void*));
}
ALWAYS_INLINE const void* GetEntryPointFromQuickCompiledCodePtrSize(size_t pointer_size) {
- return GetEntryPoint<const void*>(
+ return GetNativePointer<const void*>(
EntryPointFromQuickCompiledCodeOffset(pointer_size), pointer_size);
}
@@ -277,8 +272,8 @@
}
ALWAYS_INLINE void SetEntryPointFromQuickCompiledCodePtrSize(
const void* entry_point_from_quick_compiled_code, size_t pointer_size) {
- SetEntryPoint(EntryPointFromQuickCompiledCodeOffset(pointer_size),
- entry_point_from_quick_compiled_code, pointer_size);
+ SetNativePointer(EntryPointFromQuickCompiledCodeOffset(pointer_size),
+ entry_point_from_quick_compiled_code, pointer_size);
}
uint32_t GetCodeSize() SHARED_REQUIRES(Locks::mutator_lock_);
@@ -374,6 +369,16 @@
void UnregisterNative() SHARED_REQUIRES(Locks::mutator_lock_);
+ static MemberOffset DexCacheResolvedMethodsOffset(size_t pointer_size) {
+ return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
+ PtrSizedFields, dex_cache_resolved_methods_) / sizeof(void*) * pointer_size);
+ }
+
+ static MemberOffset DexCacheResolvedTypesOffset(size_t pointer_size) {
+ return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
+ PtrSizedFields, dex_cache_resolved_types_) / sizeof(void*) * pointer_size);
+ }
+
static MemberOffset EntryPointFromJniOffset(size_t pointer_size) {
return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
PtrSizedFields, entry_point_from_jni_) / sizeof(void*) * pointer_size);
@@ -388,14 +393,14 @@
return GetEntryPointFromJniPtrSize(sizeof(void*));
}
ALWAYS_INLINE void* GetEntryPointFromJniPtrSize(size_t pointer_size) {
- return GetEntryPoint<void*>(EntryPointFromJniOffset(pointer_size), pointer_size);
+ return GetNativePointer<void*>(EntryPointFromJniOffset(pointer_size), pointer_size);
}
void SetEntryPointFromJni(const void* entrypoint) SHARED_REQUIRES(Locks::mutator_lock_) {
SetEntryPointFromJniPtrSize(entrypoint, sizeof(void*));
}
ALWAYS_INLINE void SetEntryPointFromJniPtrSize(const void* entrypoint, size_t pointer_size) {
- SetEntryPoint(EntryPointFromJniOffset(pointer_size), entrypoint, pointer_size);
+ SetNativePointer(EntryPointFromJniOffset(pointer_size), entrypoint, pointer_size);
}
// Is this a CalleSaveMethod or ResolutionMethod and therefore doesn't adhere to normal
@@ -464,7 +469,7 @@
const DexFile::CodeItem* GetCodeItem() SHARED_REQUIRES(Locks::mutator_lock_);
- bool IsResolvedTypeIdx(uint16_t type_idx) SHARED_REQUIRES(Locks::mutator_lock_);
+ bool IsResolvedTypeIdx(uint16_t type_idx, size_t ptr_size) SHARED_REQUIRES(Locks::mutator_lock_);
int32_t GetLineNumFromDexPC(uint32_t dex_pc) SHARED_REQUIRES(Locks::mutator_lock_);
@@ -485,7 +490,8 @@
// May cause thread suspension due to GetClassFromTypeIdx calling ResolveType this caused a large
// number of bugs at call sites.
- mirror::Class* GetReturnType(bool resolve = true) SHARED_REQUIRES(Locks::mutator_lock_);
+ mirror::Class* GetReturnType(bool resolve, size_t ptr_size)
+ SHARED_REQUIRES(Locks::mutator_lock_);
mirror::ClassLoader* GetClassLoader() SHARED_REQUIRES(Locks::mutator_lock_);
@@ -514,7 +520,7 @@
void CopyFrom(const ArtMethod* src, size_t image_pointer_size)
SHARED_REQUIRES(Locks::mutator_lock_);
- ALWAYS_INLINE mirror::ObjectArray<mirror::Class>* GetDexCacheResolvedTypes()
+ ALWAYS_INLINE GcRoot<mirror::Class>* GetDexCacheResolvedTypes(size_t pointer_size)
SHARED_REQUIRES(Locks::mutator_lock_);
protected:
@@ -522,12 +528,6 @@
// The class we are a part of.
GcRoot<mirror::Class> declaring_class_;
- // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
- GcRoot<mirror::PointerArray> dex_cache_resolved_methods_;
-
- // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
- GcRoot<mirror::ObjectArray<mirror::Class>> dex_cache_resolved_types_;
-
// Access flags; low 16 bits are defined by spec.
uint32_t access_flags_;
@@ -552,6 +552,12 @@
// PACKED(4) is necessary for the correctness of
// RoundUp(OFFSETOF_MEMBER(ArtMethod, ptr_sized_fields_), pointer_size).
struct PACKED(4) PtrSizedFields {
+ // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
+ ArtMethod** dex_cache_resolved_methods_;
+
+ // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
+ GcRoot<mirror::Class>* dex_cache_resolved_types_;
+
// Pointer to JNI function registered to this method, or a function to resolve the JNI function.
void* entry_point_from_jni_;
@@ -567,26 +573,26 @@
}
template<typename T>
- ALWAYS_INLINE T GetEntryPoint(MemberOffset offset, size_t pointer_size) const {
+ ALWAYS_INLINE T GetNativePointer(MemberOffset offset, size_t pointer_size) const {
+ static_assert(std::is_pointer<T>::value, "T must be a pointer type");
DCHECK(ValidPointerSize(pointer_size)) << pointer_size;
const auto addr = reinterpret_cast<uintptr_t>(this) + offset.Uint32Value();
if (pointer_size == sizeof(uint32_t)) {
return reinterpret_cast<T>(*reinterpret_cast<const uint32_t*>(addr));
} else {
auto v = *reinterpret_cast<const uint64_t*>(addr);
- DCHECK_EQ(reinterpret_cast<uint64_t>(reinterpret_cast<T>(v)), v) << "Conversion lost bits";
- return reinterpret_cast<T>(v);
+ return reinterpret_cast<T>(dchecked_integral_cast<uintptr_t>(v));
}
}
template<typename T>
- ALWAYS_INLINE void SetEntryPoint(MemberOffset offset, T new_value, size_t pointer_size) {
+ ALWAYS_INLINE void SetNativePointer(MemberOffset offset, T new_value, size_t pointer_size) {
+ static_assert(std::is_pointer<T>::value, "T must be a pointer type");
DCHECK(ValidPointerSize(pointer_size)) << pointer_size;
const auto addr = reinterpret_cast<uintptr_t>(this) + offset.Uint32Value();
if (pointer_size == sizeof(uint32_t)) {
uintptr_t ptr = reinterpret_cast<uintptr_t>(new_value);
- DCHECK_EQ(static_cast<uint32_t>(ptr), ptr) << "Conversion lost bits";
- *reinterpret_cast<uint32_t*>(addr) = static_cast<uint32_t>(ptr);
+ *reinterpret_cast<uint32_t*>(addr) = dchecked_integral_cast<uint32_t>(ptr);
} else {
*reinterpret_cast<uint64_t*>(addr) = reinterpret_cast<uintptr_t>(new_value);
}
diff --git a/runtime/asm_support.h b/runtime/asm_support.h
index 5c1922e..04ff120 100644
--- a/runtime/asm_support.h
+++ b/runtime/asm_support.h
@@ -138,13 +138,13 @@
#define MIRROR_CLASS_COMPONENT_TYPE_OFFSET (4 + MIRROR_OBJECT_HEADER_SIZE)
ADD_TEST_EQ(MIRROR_CLASS_COMPONENT_TYPE_OFFSET,
art::mirror::Class::ComponentTypeOffset().Int32Value())
-#define MIRROR_CLASS_ACCESS_FLAGS_OFFSET (36 + MIRROR_OBJECT_HEADER_SIZE)
+#define MIRROR_CLASS_ACCESS_FLAGS_OFFSET (72 + MIRROR_OBJECT_HEADER_SIZE)
ADD_TEST_EQ(MIRROR_CLASS_ACCESS_FLAGS_OFFSET,
art::mirror::Class::AccessFlagsOffset().Int32Value())
-#define MIRROR_CLASS_OBJECT_SIZE_OFFSET (100 + MIRROR_OBJECT_HEADER_SIZE)
+#define MIRROR_CLASS_OBJECT_SIZE_OFFSET (104 + MIRROR_OBJECT_HEADER_SIZE)
ADD_TEST_EQ(MIRROR_CLASS_OBJECT_SIZE_OFFSET,
art::mirror::Class::ObjectSizeOffset().Int32Value())
-#define MIRROR_CLASS_STATUS_OFFSET (112 + MIRROR_OBJECT_HEADER_SIZE)
+#define MIRROR_CLASS_STATUS_OFFSET (116 + MIRROR_OBJECT_HEADER_SIZE)
ADD_TEST_EQ(MIRROR_CLASS_STATUS_OFFSET,
art::mirror::Class::StatusOffset().Int32Value())
@@ -184,19 +184,27 @@
ADD_TEST_EQ(MIRROR_STRING_VALUE_OFFSET, art::mirror::String::ValueOffset().Int32Value())
// Offsets within java.lang.reflect.ArtMethod.
-#define ART_METHOD_DEX_CACHE_METHODS_OFFSET 4
-ADD_TEST_EQ(ART_METHOD_DEX_CACHE_METHODS_OFFSET,
- art::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value())
+#define ART_METHOD_DEX_CACHE_METHODS_OFFSET_32 20
+ADD_TEST_EQ(ART_METHOD_DEX_CACHE_METHODS_OFFSET_32,
+ art::ArtMethod::DexCacheResolvedMethodsOffset(4).Int32Value())
-#define ART_METHOD_DEX_CACHE_TYPES_OFFSET 8
-ADD_TEST_EQ(ART_METHOD_DEX_CACHE_TYPES_OFFSET,
- art::ArtMethod::DexCacheResolvedTypesOffset().Int32Value())
+#define ART_METHOD_DEX_CACHE_METHODS_OFFSET_64 24
+ADD_TEST_EQ(ART_METHOD_DEX_CACHE_METHODS_OFFSET_64,
+ art::ArtMethod::DexCacheResolvedMethodsOffset(8).Int32Value())
+
+#define ART_METHOD_DEX_CACHE_TYPES_OFFSET_32 24
+ADD_TEST_EQ(ART_METHOD_DEX_CACHE_TYPES_OFFSET_32,
+ art::ArtMethod::DexCacheResolvedTypesOffset(4).Int32Value())
+
+#define ART_METHOD_DEX_CACHE_TYPES_OFFSET_64 32
+ADD_TEST_EQ(ART_METHOD_DEX_CACHE_TYPES_OFFSET_64,
+ art::ArtMethod::DexCacheResolvedTypesOffset(8).Int32Value())
#define ART_METHOD_QUICK_CODE_OFFSET_32 32
ADD_TEST_EQ(ART_METHOD_QUICK_CODE_OFFSET_32,
art::ArtMethod::EntryPointFromQuickCompiledCodeOffset(4).Int32Value())
-#define ART_METHOD_QUICK_CODE_OFFSET_64 40
+#define ART_METHOD_QUICK_CODE_OFFSET_64 48
ADD_TEST_EQ(ART_METHOD_QUICK_CODE_OFFSET_64,
art::ArtMethod::EntryPointFromQuickCompiledCodeOffset(8).Int32Value())
diff --git a/runtime/class_linker-inl.h b/runtime/class_linker-inl.h
index d2dbff6..6a55c32 100644
--- a/runtime/class_linker-inl.h
+++ b/runtime/class_linker-inl.h
@@ -63,7 +63,9 @@
inline mirror::String* ClassLinker::ResolveString(uint32_t string_idx,
ArtMethod* referrer) {
mirror::Class* declaring_class = referrer->GetDeclaringClass();
- mirror::String* resolved_string = declaring_class->GetDexCacheStrings()->Get(string_idx);
+ // MethodVerifier refuses methods with string_idx out of bounds.
+ DCHECK_LT(string_idx, declaring_class->GetDexCache()->NumStrings());
+ mirror::String* resolved_string = declaring_class->GetDexCacheStrings()[string_idx].Read();
if (UNLIKELY(resolved_string == nullptr)) {
StackHandleScope<1> hs(Thread::Current());
Handle<mirror::DexCache> dex_cache(hs.NewHandle(declaring_class->GetDexCache()));
@@ -76,9 +78,8 @@
return resolved_string;
}
-inline mirror::Class* ClassLinker::ResolveType(uint16_t type_idx,
- ArtMethod* referrer) {
- mirror::Class* resolved_type = referrer->GetDexCacheResolvedType(type_idx);
+inline mirror::Class* ClassLinker::ResolveType(uint16_t type_idx, ArtMethod* referrer) {
+ mirror::Class* resolved_type = referrer->GetDexCacheResolvedType(type_idx, image_pointer_size_);
if (UNLIKELY(resolved_type == nullptr)) {
mirror::Class* declaring_class = referrer->GetDeclaringClass();
StackHandleScope<2> hs(Thread::Current());
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index e78914c..fc1127c 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -80,6 +80,7 @@
#include "handle_scope-inl.h"
#include "thread-inl.h"
#include "utils.h"
+#include "utils/dex_cache_arrays_layout-inl.h"
#include "verifier/method_verifier.h"
#include "well_known_classes.h"
@@ -420,6 +421,7 @@
Handle<mirror::Class> java_lang_DexCache(hs.NewHandle(
AllocClass(self, java_lang_Class.Get(), mirror::DexCache::ClassSize(image_pointer_size_))));
SetClassRoot(kJavaLangDexCache, java_lang_DexCache.Get());
+ java_lang_DexCache->SetDexCacheClass();
java_lang_DexCache->SetObjectSize(mirror::DexCache::InstanceSize());
mirror::Class::SetStatus(java_lang_DexCache, mirror::Class::kStatusResolved, self);
@@ -1059,6 +1061,26 @@
}
}
+static void SanityCheckArtMethodPointerArray(
+ ArtMethod** arr,
+ size_t size,
+ size_t pointer_size,
+ gc::space::ImageSpace* space) SHARED_REQUIRES(Locks::mutator_lock_) {
+ CHECK_EQ(arr != nullptr, size != 0u);
+ if (arr != nullptr) {
+ auto offset = reinterpret_cast<uint8_t*>(arr) - space->Begin();
+ CHECK(space->GetImageHeader().GetImageSection(
+ ImageHeader::kSectionDexCacheArrays).Contains(offset));
+ }
+ for (size_t j = 0; j < size; ++j) {
+ ArtMethod* method = mirror::DexCache::GetElementPtrSize(arr, j, pointer_size);
+ // expected_class == null means we are a dex cache.
+ if (method != nullptr) {
+ SanityCheckArtMethod(method, nullptr, space);
+ }
+ }
+}
+
static void SanityCheckObjectsCallback(mirror::Object* obj, void* arg ATTRIBUTE_UNUSED)
SHARED_REQUIRES(Locks::mutator_lock_) {
DCHECK(obj != nullptr);
@@ -1188,8 +1210,10 @@
}
if (kSanityCheckObjects) {
- SanityCheckArtMethodPointerArray(dex_cache->GetResolvedMethods(), nullptr,
- image_pointer_size_, space);
+ SanityCheckArtMethodPointerArray(dex_cache->GetResolvedMethods(),
+ dex_cache->NumResolvedMethods(),
+ image_pointer_size_,
+ space);
}
CHECK_EQ(dex_file->GetLocationChecksum(), oat_dex_file->GetDexFileLocationChecksum());
@@ -1476,28 +1500,44 @@
self->AssertPendingOOMException();
return nullptr;
}
- auto strings(hs.NewHandle(AllocStringArray(self, dex_file.NumStringIds())));
- if (strings.Get() == nullptr) {
- self->AssertPendingOOMException();
- return nullptr;
+ DexCacheArraysLayout layout(image_pointer_size_, &dex_file);
+ uint8_t* raw_arrays = nullptr;
+ if (dex_file.NumStringIds() != 0u || dex_file.NumTypeIds() != 0u ||
+ dex_file.NumMethodIds() != 0u || dex_file.NumFieldIds() != 0u) {
+ // NOTE: We "leak" the raw_arrays because we never destroy the dex cache.
+ DCHECK(image_pointer_size_ == 4u || image_pointer_size_ == 8u);
+ if (sizeof(void*) == 8u && image_pointer_size_ == 4u) {
+ // When cross-compiling for a 32-bit target on a 64-bit host, we need these arrays
+ // in the low 4GiB address space so that we can store pointers in 32-bit fields.
+ // This is conveniently provided by the linear allocator.
+ raw_arrays = reinterpret_cast<uint8_t*>(
+ Runtime::Current()->GetLinearAlloc()->Alloc(self, layout.Size())); // Zero-initialized.
+ } else {
+ raw_arrays = reinterpret_cast<uint8_t*>(calloc(layout.Size(), 1u)); // Zero-initialized.
+ if (raw_arrays == nullptr) {
+ return nullptr;
+ }
+ }
}
- auto types(hs.NewHandle(AllocClassArray(self, dex_file.NumTypeIds())));
- if (types.Get() == nullptr) {
- self->AssertPendingOOMException();
- return nullptr;
- }
- auto methods(hs.NewHandle(AllocPointerArray(self, dex_file.NumMethodIds())));
- if (methods.Get() == nullptr) {
- self->AssertPendingOOMException();
- return nullptr;
- }
- auto fields(hs.NewHandle(AllocPointerArray(self, dex_file.NumFieldIds())));
- if (fields.Get() == nullptr) {
- self->AssertPendingOOMException();
- return nullptr;
- }
- dex_cache->Init(&dex_file, location.Get(), strings.Get(), types.Get(), methods.Get(),
- fields.Get(), image_pointer_size_);
+ GcRoot<mirror::String>* strings = (dex_file.NumStringIds() == 0u) ? nullptr :
+ reinterpret_cast<GcRoot<mirror::String>*>(raw_arrays + layout.StringsOffset());
+ GcRoot<mirror::Class>* types = (dex_file.NumTypeIds() == 0u) ? nullptr :
+ reinterpret_cast<GcRoot<mirror::Class>*>(raw_arrays + layout.TypesOffset());
+ ArtMethod** methods = (dex_file.NumMethodIds() == 0u) ? nullptr :
+ reinterpret_cast<ArtMethod**>(raw_arrays + layout.MethodsOffset());
+ ArtField** fields = (dex_file.NumFieldIds() == 0u) ? nullptr :
+ reinterpret_cast<ArtField**>(raw_arrays + layout.FieldsOffset());
+ dex_cache->Init(&dex_file,
+ location.Get(),
+ strings,
+ dex_file.NumStringIds(),
+ types,
+ dex_file.NumTypeIds(),
+ methods,
+ dex_file.NumMethodIds(),
+ fields,
+ dex_file.NumFieldIds(),
+ image_pointer_size_);
return dex_cache.Get();
}
@@ -2418,8 +2458,8 @@
dst->SetDeclaringClass(klass.Get());
dst->SetCodeItemOffset(it.GetMethodCodeItemOffset());
- dst->SetDexCacheResolvedMethods(klass->GetDexCache()->GetResolvedMethods());
- dst->SetDexCacheResolvedTypes(klass->GetDexCache()->GetResolvedTypes());
+ dst->SetDexCacheResolvedMethods(klass->GetDexCache()->GetResolvedMethods(), image_pointer_size_);
+ dst->SetDexCacheResolvedTypes(klass->GetDexCache()->GetResolvedTypes(), image_pointer_size_);
uint32_t access_flags = it.GetMethodAccessFlags();
@@ -2895,9 +2935,9 @@
ClassTable* const class_table = InsertClassTableForClassLoader(nullptr);
for (int32_t i = 0; i < dex_caches->GetLength(); i++) {
mirror::DexCache* dex_cache = dex_caches->Get(i);
- mirror::ObjectArray<mirror::Class>* types = dex_cache->GetResolvedTypes();
- for (int32_t j = 0; j < types->GetLength(); j++) {
- mirror::Class* klass = types->Get(j);
+ GcRoot<mirror::Class>* types = dex_cache->GetResolvedTypes();
+ for (int32_t j = 0, num_types = dex_cache->NumResolvedTypes(); j < num_types; j++) {
+ mirror::Class* klass = types[j].Read();
if (klass != nullptr) {
DCHECK(klass->GetClassLoader() == nullptr);
const char* descriptor = klass->GetDescriptor(&temp);
@@ -3418,7 +3458,8 @@
for (jobject weak_root : dex_caches_) {
mirror::DexCache* dex_cache = down_cast<mirror::DexCache*>(self->DecodeJObject(weak_root));
if (dex_cache != nullptr &&
- proxy_method->HasSameDexCacheResolvedTypes(dex_cache->GetResolvedTypes())) {
+ proxy_method->HasSameDexCacheResolvedTypes(dex_cache->GetResolvedTypes(),
+ image_pointer_size_)) {
ArtMethod* resolved_method = dex_cache->GetResolvedMethod(
proxy_method->GetDexMethodIndex(), image_pointer_size_);
CHECK(resolved_method != nullptr);
@@ -3491,8 +3532,8 @@
// The proxy method doesn't have its own dex cache or dex file and so it steals those of its
// interface prototype. The exception to this are Constructors and the Class of the Proxy itself.
- CHECK(prototype->HasSameDexCacheResolvedMethods(method));
- CHECK(prototype->HasSameDexCacheResolvedTypes(method));
+ CHECK(prototype->HasSameDexCacheResolvedMethods(method, image_pointer_size_));
+ CHECK(prototype->HasSameDexCacheResolvedTypes(method, image_pointer_size_));
auto* np = method->GetInterfaceMethodIfProxy(image_pointer_size_);
CHECK_EQ(prototype->GetDeclaringClass()->GetDexCache(), np->GetDexCache());
CHECK_EQ(prototype->GetDexMethodIndex(), method->GetDexMethodIndex());
@@ -3500,7 +3541,8 @@
CHECK_STREQ(np->GetName(), prototype->GetName());
CHECK_STREQ(np->GetShorty(), prototype->GetShorty());
// More complex sanity - via dex cache
- CHECK_EQ(np->GetReturnType(), prototype->GetReturnType());
+ CHECK_EQ(np->GetReturnType(true /* resolve */, image_pointer_size_),
+ prototype->GetReturnType(true /* resolve */, image_pointer_size_));
}
bool ClassLinker::CanWeInitializeClass(mirror::Class* klass, bool can_init_statics,
@@ -3838,6 +3880,7 @@
}
static bool HasSameSignatureWithDifferentClassLoaders(Thread* self,
+ size_t pointer_size,
Handle<mirror::Class> klass,
Handle<mirror::Class> super_klass,
ArtMethod* method1,
@@ -3845,12 +3888,14 @@
SHARED_REQUIRES(Locks::mutator_lock_) {
{
StackHandleScope<1> hs(self);
- Handle<mirror::Class> return_type(hs.NewHandle(method1->GetReturnType()));
+ Handle<mirror::Class> return_type(hs.NewHandle(method1->GetReturnType(true /* resolve */,
+ pointer_size)));
if (UNLIKELY(return_type.Get() == nullptr)) {
ThrowSignatureCheckResolveReturnTypeException(klass, super_klass, method1, method1);
return false;
}
- mirror::Class* other_return_type = method2->GetReturnType();
+ mirror::Class* other_return_type = method2->GetReturnType(true /* resolve */,
+ pointer_size);
if (UNLIKELY(other_return_type == nullptr)) {
ThrowSignatureCheckResolveReturnTypeException(klass, super_klass, method1, method2);
return false;
@@ -3895,7 +3940,7 @@
StackHandleScope<1> hs(self);
uint32_t param_type_idx = types1->GetTypeItem(i).type_idx_;
Handle<mirror::Class> param_type(hs.NewHandle(
- method1->GetClassFromTypeIndex(param_type_idx, true)));
+ method1->GetClassFromTypeIndex(param_type_idx, true /* resolve */, pointer_size)));
if (UNLIKELY(param_type.Get() == nullptr)) {
ThrowSignatureCheckResolveArgException(klass, super_klass, method1,
method1, i, param_type_idx);
@@ -3903,7 +3948,7 @@
}
uint32_t other_param_type_idx = types2->GetTypeItem(i).type_idx_;
mirror::Class* other_param_type =
- method2->GetClassFromTypeIndex(other_param_type_idx, true);
+ method2->GetClassFromTypeIndex(other_param_type_idx, true /* resolve */, pointer_size);
if (UNLIKELY(other_param_type == nullptr)) {
ThrowSignatureCheckResolveArgException(klass, super_klass, method1,
method2, i, other_param_type_idx);
@@ -3939,7 +3984,8 @@
auto* m = klass->GetVTableEntry(i, image_pointer_size_);
auto* super_m = klass->GetSuperClass()->GetVTableEntry(i, image_pointer_size_);
if (m != super_m) {
- if (UNLIKELY(!HasSameSignatureWithDifferentClassLoaders(self, klass, super_klass,
+ if (UNLIKELY(!HasSameSignatureWithDifferentClassLoaders(self, image_pointer_size_,
+ klass, super_klass,
m, super_m))) {
self->AssertPendingException();
return false;
@@ -3956,7 +4002,8 @@
j, image_pointer_size_);
auto* super_m = super_klass->GetVirtualMethod(j, image_pointer_size_);
if (m != super_m) {
- if (UNLIKELY(!HasSameSignatureWithDifferentClassLoaders(self, klass, super_klass,
+ if (UNLIKELY(!HasSameSignatureWithDifferentClassLoaders(self, image_pointer_size_,
+ klass, super_klass,
m, super_m))) {
self->AssertPendingException();
return false;
@@ -5091,8 +5138,8 @@
// Check that there are no stale methods are in the dex cache array.
if (kIsDebugBuild) {
auto* resolved_methods = klass->GetDexCache()->GetResolvedMethods();
- for (size_t i = 0, count = resolved_methods->GetLength(); i < count; ++i) {
- auto* m = resolved_methods->GetElementPtrSize<ArtMethod*>(i, image_pointer_size_);
+ for (size_t i = 0, count = klass->GetDexCache()->NumResolvedMethods(); i < count; ++i) {
+ auto* m = mirror::DexCache::GetElementPtrSize(resolved_methods, i, image_pointer_size_);
CHECK(move_table.find(m) == move_table.end()) << PrettyMethod(m);
}
}
diff --git a/runtime/class_linker_test.cc b/runtime/class_linker_test.cc
index c3191fa..b4ea3b3 100644
--- a/runtime/class_linker_test.cc
+++ b/runtime/class_linker_test.cc
@@ -165,12 +165,14 @@
EXPECT_TRUE(method->GetName() != nullptr);
EXPECT_TRUE(method->GetSignature() != Signature::NoSignature());
- EXPECT_TRUE(method->HasDexCacheResolvedMethods());
- EXPECT_TRUE(method->HasDexCacheResolvedTypes());
+ EXPECT_TRUE(method->HasDexCacheResolvedMethods(sizeof(void*)));
+ EXPECT_TRUE(method->HasDexCacheResolvedTypes(sizeof(void*)));
EXPECT_TRUE(method->HasSameDexCacheResolvedMethods(
- method->GetDeclaringClass()->GetDexCache()->GetResolvedMethods()));
+ method->GetDeclaringClass()->GetDexCache()->GetResolvedMethods(),
+ sizeof(void*)));
EXPECT_TRUE(method->HasSameDexCacheResolvedTypes(
- method->GetDeclaringClass()->GetDexCache()->GetResolvedTypes()));
+ method->GetDeclaringClass()->GetDexCache()->GetResolvedTypes(),
+ sizeof(void*)));
}
void AssertField(mirror::Class* klass, ArtField* field)
@@ -357,8 +359,9 @@
// Verify the dex cache has resolution methods in all resolved method slots
mirror::DexCache* dex_cache = class_linker_->FindDexCache(Thread::Current(), dex);
auto* resolved_methods = dex_cache->GetResolvedMethods();
- for (size_t i = 0; i < static_cast<size_t>(resolved_methods->GetLength()); i++) {
- EXPECT_TRUE(resolved_methods->GetElementPtrSize<ArtMethod*>(i, sizeof(void*)) != nullptr)
+ for (size_t i = 0, num_methods = dex_cache->NumResolvedMethods(); i != num_methods; ++i) {
+ EXPECT_TRUE(
+ mirror::DexCache::GetElementPtrSize(resolved_methods, i, sizeof(void*)) != nullptr)
<< dex.GetLocation() << " i=" << i;
}
}
@@ -565,6 +568,10 @@
addOffset(OFFSETOF_MEMBER(mirror::DexCache, dex_), "dex");
addOffset(OFFSETOF_MEMBER(mirror::DexCache, dex_file_), "dexFile");
addOffset(OFFSETOF_MEMBER(mirror::DexCache, location_), "location");
+ addOffset(OFFSETOF_MEMBER(mirror::DexCache, num_resolved_fields_), "numResolvedFields");
+ addOffset(OFFSETOF_MEMBER(mirror::DexCache, num_resolved_methods_), "numResolvedMethods");
+ addOffset(OFFSETOF_MEMBER(mirror::DexCache, num_resolved_types_), "numResolvedTypes");
+ addOffset(OFFSETOF_MEMBER(mirror::DexCache, num_strings_), "numStrings");
addOffset(OFFSETOF_MEMBER(mirror::DexCache, resolved_fields_), "resolvedFields");
addOffset(OFFSETOF_MEMBER(mirror::DexCache, resolved_methods_), "resolvedMethods");
addOffset(OFFSETOF_MEMBER(mirror::DexCache, resolved_types_), "resolvedTypes");
diff --git a/runtime/debugger.cc b/runtime/debugger.cc
index 8d34f5a..8afb968 100644
--- a/runtime/debugger.cc
+++ b/runtime/debugger.cc
@@ -3821,7 +3821,9 @@
if (shorty[i + 1] == 'L') {
// Did we really get an argument of an appropriate reference type?
mirror::Class* parameter_type =
- m->GetClassFromTypeIndex(types->GetTypeItem(i).type_idx_, true);
+ m->GetClassFromTypeIndex(types->GetTypeItem(i).type_idx_,
+ true /* resolve */,
+ sizeof(void*));
mirror::Object* argument = gRegistry->Get<mirror::Object*>(arg_values[i], &error);
if (error != JDWP::ERR_NONE) {
return JDWP::ERR_INVALID_OBJECT;
diff --git a/runtime/dex_file.cc b/runtime/dex_file.cc
index 213f25d..85274cd 100644
--- a/runtime/dex_file.cc
+++ b/runtime/dex_file.cc
@@ -1227,7 +1227,9 @@
AnnotationValue annotation_value;
StackHandleScope<2> hs(Thread::Current());
Handle<mirror::Class> h_klass(hs.NewHandle(klass));
- Handle<mirror::Class> return_type(hs.NewHandle(method->GetReturnType()));
+ size_t pointer_size = Runtime::Current()->GetClassLinker()->GetImagePointerSize();
+ Handle<mirror::Class> return_type(hs.NewHandle(
+ method->GetReturnType(true /* resolve */, pointer_size)));
if (!ProcessAnnotationValue(h_klass, &annotation, &annotation_value, return_type, kAllObjects)) {
return nullptr;
}
@@ -1343,7 +1345,9 @@
if (annotation_method == nullptr) {
return nullptr;
}
- Handle<mirror::Class> method_return(hs.NewHandle(annotation_method->GetReturnType()));
+ size_t pointer_size = Runtime::Current()->GetClassLinker()->GetImagePointerSize();
+ Handle<mirror::Class> method_return(hs.NewHandle(
+ annotation_method->GetReturnType(true /* resolve */, pointer_size)));
AnnotationValue annotation_value;
if (!ProcessAnnotationValue(klass, annotation, &annotation_value, method_return, kAllObjects)) {
diff --git a/runtime/entrypoints/entrypoint_utils-inl.h b/runtime/entrypoints/entrypoint_utils-inl.h
index 66e88ba..cc3eefe 100644
--- a/runtime/entrypoints/entrypoint_utils-inl.h
+++ b/runtime/entrypoints/entrypoint_utils-inl.h
@@ -120,9 +120,11 @@
inline mirror::Class* CheckObjectAlloc(uint32_t type_idx,
ArtMethod* method,
Thread* self, bool* slow_path) {
- mirror::Class* klass = method->GetDexCacheResolvedType<false>(type_idx);
+ ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
+ size_t pointer_size = class_linker->GetImagePointerSize();
+ mirror::Class* klass = method->GetDexCacheResolvedType<false>(type_idx, pointer_size);
if (UNLIKELY(klass == nullptr)) {
- klass = Runtime::Current()->GetClassLinker()->ResolveType(type_idx, method);
+ klass = class_linker->ResolveType(type_idx, method);
*slow_path = true;
if (klass == nullptr) {
DCHECK(self->IsExceptionPending());
@@ -258,9 +260,11 @@
*slow_path = true;
return nullptr; // Failure
}
- mirror::Class* klass = method->GetDexCacheResolvedType<false>(type_idx);
+ ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
+ size_t pointer_size = class_linker->GetImagePointerSize();
+ mirror::Class* klass = method->GetDexCacheResolvedType<false>(type_idx, pointer_size);
if (UNLIKELY(klass == nullptr)) { // Not in dex cache so try to resolve
- klass = Runtime::Current()->GetClassLinker()->ResolveType(type_idx, method);
+ klass = class_linker->ResolveType(type_idx, method);
*slow_path = true;
if (klass == nullptr) { // Error
DCHECK(Thread::Current()->IsExceptionPending());
diff --git a/runtime/entrypoints/entrypoint_utils.cc b/runtime/entrypoints/entrypoint_utils.cc
index eaf33f6..94aced2 100644
--- a/runtime/entrypoints/entrypoint_utils.cc
+++ b/runtime/entrypoints/entrypoint_utils.cc
@@ -43,9 +43,11 @@
ThrowNegativeArraySizeException(component_count);
return nullptr; // Failure
}
- mirror::Class* klass = referrer->GetDexCacheResolvedType<false>(type_idx);
+ ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
+ size_t pointer_size = class_linker->GetImagePointerSize();
+ mirror::Class* klass = referrer->GetDexCacheResolvedType<false>(type_idx, pointer_size);
if (UNLIKELY(klass == nullptr)) { // Not in dex cache so try to resolve
- klass = Runtime::Current()->GetClassLinker()->ResolveType(type_idx, referrer);
+ klass = class_linker->ResolveType(type_idx, referrer);
if (klass == nullptr) { // Error
DCHECK(self->IsExceptionPending());
return nullptr; // Failure
@@ -214,7 +216,8 @@
return;
}
// Make sure that the result is an instance of the type this method was expected to return.
- mirror::Class* return_type = self->GetCurrentMethod(nullptr)->GetReturnType();
+ mirror::Class* return_type = self->GetCurrentMethod(nullptr)->GetReturnType(true /* resolve */,
+ sizeof(void*));
if (!o->InstanceOf(return_type)) {
Runtime::Current()->GetJavaVM()->JniAbortF(nullptr,
@@ -277,7 +280,9 @@
StackHandleScope<1> hs(soa.Self());
auto h_interface_method(hs.NewHandle(soa.Decode<mirror::Method*>(interface_method_jobj)));
// This can cause thread suspension.
- mirror::Class* result_type = h_interface_method->GetArtMethod()->GetReturnType();
+ size_t pointer_size = Runtime::Current()->GetClassLinker()->GetImagePointerSize();
+ mirror::Class* result_type =
+ h_interface_method->GetArtMethod()->GetReturnType(true /* resolve */, pointer_size);
mirror::Object* result_ref = soa.Decode<mirror::Object*>(result);
JValue result_unboxed;
if (!UnboxPrimitiveForResult(result_ref, result_type, &result_unboxed)) {
diff --git a/runtime/entrypoints/quick/quick_alloc_entrypoints.cc b/runtime/entrypoints/quick/quick_alloc_entrypoints.cc
index 9311791..28c62a8 100644
--- a/runtime/entrypoints/quick/quick_alloc_entrypoints.cc
+++ b/runtime/entrypoints/quick/quick_alloc_entrypoints.cc
@@ -33,7 +33,7 @@
SHARED_REQUIRES(Locks::mutator_lock_) { \
ScopedQuickEntrypointChecks sqec(self); \
if (kUseTlabFastPath && !instrumented_bool && allocator_type == gc::kAllocatorTypeTLAB) { \
- mirror::Class* klass = method->GetDexCacheResolvedType<false>(type_idx); \
+ mirror::Class* klass = method->GetDexCacheResolvedType<false>(type_idx, sizeof(void*)); \
if (LIKELY(klass != nullptr && klass->IsInitialized() && !klass->IsFinalizable())) { \
size_t byte_count = klass->GetObjectSize(); \
byte_count = RoundUp(byte_count, gc::space::BumpPointerSpace::kAlignment); \
diff --git a/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc b/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc
index 0c7caf3..1302c5f 100644
--- a/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc
+++ b/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc
@@ -980,7 +980,7 @@
// FindVirtualMethodFor... This is ok for FindDexMethodIndexInOtherDexFile that only cares
// about the name and signature.
uint32_t update_dex_cache_method_index = called->GetDexMethodIndex();
- if (!called->HasSameDexCacheResolvedMethods(caller)) {
+ if (!called->HasSameDexCacheResolvedMethods(caller, sizeof(void*))) {
// Calling from one dex file to another, need to compute the method index appropriate to
// the caller's dex file. Since we get here only if the original called was a runtime
// method, we've got the correct dex_file and a dex_method_idx from above.
diff --git a/runtime/image.cc b/runtime/image.cc
index 8df17c6..42b348a 100644
--- a/runtime/image.cc
+++ b/runtime/image.cc
@@ -24,7 +24,7 @@
namespace art {
const uint8_t ImageHeader::kImageMagic[] = { 'a', 'r', 't', '\n' };
-const uint8_t ImageHeader::kImageVersion[] = { '0', '2', '0', '\0' };
+const uint8_t ImageHeader::kImageVersion[] = { '0', '2', '1', '\0' };
ImageHeader::ImageHeader(uint32_t image_begin,
uint32_t image_size,
diff --git a/runtime/image.h b/runtime/image.h
index e2d59f9..20e4159 100644
--- a/runtime/image.h
+++ b/runtime/image.h
@@ -168,6 +168,7 @@
kSectionObjects,
kSectionArtFields,
kSectionArtMethods,
+ kSectionDexCacheArrays,
kSectionInternedStrings,
kSectionImageBitmap,
kSectionCount, // Number of elements in enum.
diff --git a/runtime/intern_table.cc b/runtime/intern_table.cc
index 2be570a..6d22fe0 100644
--- a/runtime/intern_table.cc
+++ b/runtime/intern_table.cc
@@ -22,7 +22,7 @@
#include "gc/collector/garbage_collector.h"
#include "gc/space/image_space.h"
#include "gc/weak_root_state.h"
-#include "mirror/dex_cache.h"
+#include "mirror/dex_cache-inl.h"
#include "mirror/object_array-inl.h"
#include "mirror/object-inl.h"
#include "mirror/string-inl.h"
@@ -165,8 +165,7 @@
mirror::ObjectArray<mirror::DexCache>* dex_caches = root->AsObjectArray<mirror::DexCache>();
for (int32_t i = 0; i < dex_caches->GetLength(); ++i) {
mirror::DexCache* dex_cache = dex_caches->Get(i);
- const DexFile* dex_file = dex_cache->GetDexFile();
- const size_t num_strings = dex_file->NumStringIds();
+ const size_t num_strings = dex_cache->NumStrings();
for (size_t j = 0; j < num_strings; ++j) {
mirror::String* image_string = dex_cache->GetResolvedString(j);
if (image_string != nullptr) {
diff --git a/runtime/interpreter/interpreter_common.cc b/runtime/interpreter/interpreter_common.cc
index f923b84..af67379 100644
--- a/runtime/interpreter/interpreter_common.cc
+++ b/runtime/interpreter/interpreter_common.cc
@@ -616,9 +616,10 @@
case 'L': {
Object* o = shadow_frame.GetVRegReference(src_reg);
if (do_assignability_check && o != nullptr) {
+ size_t pointer_size = Runtime::Current()->GetClassLinker()->GetImagePointerSize();
Class* arg_type =
new_shadow_frame->GetMethod()->GetClassFromTypeIndex(
- params->GetTypeItem(shorty_pos).type_idx_, true);
+ params->GetTypeItem(shorty_pos).type_idx_, true /* resolve */, pointer_size);
if (arg_type == nullptr) {
CHECK(self->IsExceptionPending());
return false;
diff --git a/runtime/interpreter/interpreter_common.h b/runtime/interpreter/interpreter_common.h
index 6468659..fdefb9f 100644
--- a/runtime/interpreter/interpreter_common.h
+++ b/runtime/interpreter/interpreter_common.h
@@ -344,7 +344,9 @@
}
ArtMethod* method = shadow_frame.GetMethod();
mirror::Class* declaring_class = method->GetDeclaringClass();
- mirror::String* s = declaring_class->GetDexCacheStrings()->Get(string_idx);
+ // MethodVerifier refuses methods with string_idx out of bounds.
+ DCHECK_LT(string_idx, declaring_class->GetDexCache()->NumStrings());
+ mirror::String* s = declaring_class->GetDexCacheStrings()[string_idx].Read();
if (UNLIKELY(s == nullptr)) {
StackHandleScope<1> hs(self);
Handle<mirror::DexCache> dex_cache(hs.NewHandle(declaring_class->GetDexCache()));
diff --git a/runtime/interpreter/interpreter_goto_table_impl.cc b/runtime/interpreter/interpreter_goto_table_impl.cc
index 7027cbf..72e2ba0 100644
--- a/runtime/interpreter/interpreter_goto_table_impl.cc
+++ b/runtime/interpreter/interpreter_goto_table_impl.cc
@@ -327,7 +327,9 @@
const uint8_t vreg_index = inst->VRegA_11x(inst_data);
Object* obj_result = shadow_frame.GetVRegReference(vreg_index);
if (do_assignability_check && obj_result != nullptr) {
- Class* return_type = shadow_frame.GetMethod()->GetReturnType();
+ size_t pointer_size = Runtime::Current()->GetClassLinker()->GetImagePointerSize();
+ Class* return_type = shadow_frame.GetMethod()->GetReturnType(true /* resolve */,
+ pointer_size);
obj_result = shadow_frame.GetVRegReference(vreg_index);
if (return_type == nullptr) {
// Return the pending exception.
diff --git a/runtime/interpreter/interpreter_switch_impl.cc b/runtime/interpreter/interpreter_switch_impl.cc
index 544f788..b5cc11e 100644
--- a/runtime/interpreter/interpreter_switch_impl.cc
+++ b/runtime/interpreter/interpreter_switch_impl.cc
@@ -225,7 +225,9 @@
const size_t ref_idx = inst->VRegA_11x(inst_data);
Object* obj_result = shadow_frame.GetVRegReference(ref_idx);
if (do_assignability_check && obj_result != nullptr) {
- Class* return_type = shadow_frame.GetMethod()->GetReturnType();
+ size_t pointer_size = Runtime::Current()->GetClassLinker()->GetImagePointerSize();
+ Class* return_type = shadow_frame.GetMethod()->GetReturnType(true /* resolve */,
+ pointer_size);
// Re-load since it might have moved.
obj_result = shadow_frame.GetVRegReference(ref_idx);
if (return_type == nullptr) {
diff --git a/runtime/mirror/class-inl.h b/runtime/mirror/class-inl.h
index b2c6e4d..10b381d 100644
--- a/runtime/mirror/class-inl.h
+++ b/runtime/mirror/class-inl.h
@@ -817,12 +817,12 @@
}
}
-inline void Class::SetDexCacheStrings(ObjectArray<String>* new_dex_cache_strings) {
- SetFieldObject<false>(DexCacheStringsOffset(), new_dex_cache_strings);
+inline void Class::SetDexCacheStrings(GcRoot<String>* new_dex_cache_strings) {
+ SetFieldPtr<false>(DexCacheStringsOffset(), new_dex_cache_strings);
}
-inline ObjectArray<String>* Class::GetDexCacheStrings() {
- return GetFieldObject<ObjectArray<String>>(DexCacheStringsOffset());
+inline GcRoot<String>* Class::GetDexCacheStrings() {
+ return GetFieldPtr<GcRoot<String>*>(DexCacheStringsOffset());
}
template<class Visitor>
diff --git a/runtime/mirror/class.h b/runtime/mirror/class.h
index 1420e5b..9422432 100644
--- a/runtime/mirror/class.h
+++ b/runtime/mirror/class.h
@@ -250,6 +250,14 @@
SetClassFlags(kClassFlagClassLoader);
}
+ ALWAYS_INLINE bool IsDexCacheClass() SHARED_REQUIRES(Locks::mutator_lock_) {
+ return (GetClassFlags() & kClassFlagDexCache) != 0;
+ }
+
+ ALWAYS_INLINE void SetDexCacheClass() SHARED_REQUIRES(Locks::mutator_lock_) {
+ SetClassFlags(GetClassFlags() | kClassFlagDexCache);
+ }
+
// Returns true if the class is abstract.
ALWAYS_INLINE bool IsAbstract() SHARED_REQUIRES(Locks::mutator_lock_) {
return (GetAccessFlags() & kAccAbstract) != 0;
@@ -1077,8 +1085,8 @@
bool GetSlowPathEnabled() SHARED_REQUIRES(Locks::mutator_lock_);
void SetSlowPath(bool enabled) SHARED_REQUIRES(Locks::mutator_lock_);
- ObjectArray<String>* GetDexCacheStrings() SHARED_REQUIRES(Locks::mutator_lock_);
- void SetDexCacheStrings(ObjectArray<String>* new_dex_cache_strings)
+ GcRoot<String>* GetDexCacheStrings() SHARED_REQUIRES(Locks::mutator_lock_);
+ void SetDexCacheStrings(GcRoot<String>* new_dex_cache_strings)
SHARED_REQUIRES(Locks::mutator_lock_);
static MemberOffset DexCacheStringsOffset() {
return OFFSET_OF_OBJECT_MEMBER(Class, dex_cache_strings_);
@@ -1173,9 +1181,6 @@
// runtime such as arrays and primitive classes).
HeapReference<DexCache> dex_cache_;
- // Short cuts to dex_cache_ member for fast compiled code access.
- HeapReference<ObjectArray<String>> dex_cache_strings_;
-
// The interface table (iftable_) contains pairs of a interface class and an array of the
// interface methods. There is one pair per interface supported by this class. That means one
// pair for each interface we support directly, indirectly via superclass, or indirectly via a
@@ -1209,9 +1214,8 @@
// virtual_ methods_ for miranda methods.
HeapReference<PointerArray> vtable_;
- // Access flags; low 16 bits are defined by VM spec.
- // Note: Shuffled back.
- uint32_t access_flags_;
+ // Short cuts to dex_cache_ member for fast compiled code access.
+ uint64_t dex_cache_strings_;
// static, private, and <init> methods. Pointer to an ArtMethod length-prefixed array.
uint64_t direct_methods_;
@@ -1234,6 +1238,9 @@
// length-prefixed array.
uint64_t virtual_methods_;
+ // Access flags; low 16 bits are defined by VM spec.
+ uint32_t access_flags_;
+
// Class flags to help speed up visiting object references.
uint32_t class_flags_;
diff --git a/runtime/mirror/class_flags.h b/runtime/mirror/class_flags.h
index eb2e2eb..139c4cb 100644
--- a/runtime/mirror/class_flags.h
+++ b/runtime/mirror/class_flags.h
@@ -41,17 +41,20 @@
// Class is ClassLoader or one of its subclasses.
static constexpr uint32_t kClassFlagClassLoader = 0x00000020;
+// Class is DexCache.
+static constexpr uint32_t kClassFlagDexCache = 0x00000040;
+
// Class is a soft/weak/phantom class.
-static constexpr uint32_t kClassFlagSoftReference = 0x00000040;
+static constexpr uint32_t kClassFlagSoftReference = 0x00000080;
// Class is a weak reference class.
-static constexpr uint32_t kClassFlagWeakReference = 0x00000080;
+static constexpr uint32_t kClassFlagWeakReference = 0x00000100;
// Class is a finalizer reference class.
-static constexpr uint32_t kClassFlagFinalizerReference = 0x00000100;
+static constexpr uint32_t kClassFlagFinalizerReference = 0x00000200;
// Class is the phantom reference class.
-static constexpr uint32_t kClassFlagPhantomReference = 0x00000200;
+static constexpr uint32_t kClassFlagPhantomReference = 0x00000400;
// Combination of flags to figure out if the class is either the weak/soft/phantom/finalizer
// reference class.
diff --git a/runtime/mirror/dex_cache-inl.h b/runtime/mirror/dex_cache-inl.h
index 4b5063a..f8ccfb1 100644
--- a/runtime/mirror/dex_cache-inl.h
+++ b/runtime/mirror/dex_cache-inl.h
@@ -21,6 +21,7 @@
#include "art_field-inl.h"
#include "art_method-inl.h"
+#include "base/casts.h"
#include "base/logging.h"
#include "mirror/class.h"
#include "runtime.h"
@@ -33,29 +34,53 @@
return Class::ComputeClassSize(true, vtable_entries, 0, 0, 0, 0, 0, pointer_size);
}
-inline void DexCache::SetResolvedType(uint32_t type_idx, Class* resolved) {
- // TODO default transaction support.
- DCHECK(resolved == nullptr || !resolved->IsErroneous());
- GetResolvedTypes()->Set(type_idx, resolved);
+inline String* DexCache::GetResolvedString(uint32_t string_idx) {
+ DCHECK_LT(string_idx, NumStrings());
+ return GetStrings()[string_idx].Read();
}
-inline ArtField* DexCache::GetResolvedField(uint32_t idx, size_t ptr_size) {
+inline void DexCache::SetResolvedString(uint32_t string_idx, String* resolved) {
+ DCHECK_LT(string_idx, NumStrings());
+ // TODO default transaction support.
+ GetStrings()[string_idx] = GcRoot<String>(resolved);
+ // TODO: Fine-grained marking, so that we don't need to go through all arrays in full.
+ Runtime::Current()->GetHeap()->WriteBarrierEveryFieldOf(this);
+}
+
+inline Class* DexCache::GetResolvedType(uint32_t type_idx) {
+ DCHECK_LT(type_idx, NumResolvedTypes());
+ return GetResolvedTypes()[type_idx].Read();
+}
+
+inline void DexCache::SetResolvedType(uint32_t type_idx, Class* resolved) {
+ DCHECK_LT(type_idx, NumResolvedTypes()); // NOTE: Unchecked, i.e. not throwing AIOOB.
+ // TODO default transaction support.
+ DCHECK(resolved == nullptr || !resolved->IsErroneous());
+ GetResolvedTypes()[type_idx] = GcRoot<Class>(resolved);
+ // TODO: Fine-grained marking, so that we don't need to go through all arrays in full.
+ Runtime::Current()->GetHeap()->WriteBarrierEveryFieldOf(this);
+}
+
+inline ArtField* DexCache::GetResolvedField(uint32_t field_idx, size_t ptr_size) {
DCHECK_EQ(Runtime::Current()->GetClassLinker()->GetImagePointerSize(), ptr_size);
- auto* field = GetResolvedFields()->GetElementPtrSize<ArtField*>(idx, ptr_size);
+ DCHECK_LT(field_idx, NumResolvedFields()); // NOTE: Unchecked, i.e. not throwing AIOOB.
+ ArtField* field = GetElementPtrSize(GetResolvedFields(), field_idx, ptr_size);
if (field == nullptr || field->GetDeclaringClass()->IsErroneous()) {
return nullptr;
}
return field;
}
-inline void DexCache::SetResolvedField(uint32_t idx, ArtField* field, size_t ptr_size) {
+inline void DexCache::SetResolvedField(uint32_t field_idx, ArtField* field, size_t ptr_size) {
DCHECK_EQ(Runtime::Current()->GetClassLinker()->GetImagePointerSize(), ptr_size);
- GetResolvedFields()->SetElementPtrSize(idx, field, ptr_size);
+ DCHECK_LT(field_idx, NumResolvedFields()); // NOTE: Unchecked, i.e. not throwing AIOOB.
+ SetElementPtrSize(GetResolvedFields(), field_idx, field, ptr_size);
}
inline ArtMethod* DexCache::GetResolvedMethod(uint32_t method_idx, size_t ptr_size) {
DCHECK_EQ(Runtime::Current()->GetClassLinker()->GetImagePointerSize(), ptr_size);
- auto* method = GetResolvedMethods()->GetElementPtrSize<ArtMethod*>(method_idx, ptr_size);
+ DCHECK_LT(method_idx, NumResolvedMethods()); // NOTE: Unchecked, i.e. not throwing AIOOB.
+ ArtMethod* method = GetElementPtrSize<ArtMethod*>(GetResolvedMethods(), method_idx, ptr_size);
// Hide resolution trampoline methods from the caller
if (method != nullptr && method->IsRuntimeMethod()) {
DCHECK_EQ(method, Runtime::Current()->GetResolutionMethod());
@@ -64,9 +89,52 @@
return method;
}
-inline void DexCache::SetResolvedMethod(uint32_t idx, ArtMethod* method, size_t ptr_size) {
+inline void DexCache::SetResolvedMethod(uint32_t method_idx, ArtMethod* method, size_t ptr_size) {
DCHECK_EQ(Runtime::Current()->GetClassLinker()->GetImagePointerSize(), ptr_size);
- GetResolvedMethods()->SetElementPtrSize(idx, method, ptr_size);
+ DCHECK_LT(method_idx, NumResolvedMethods()); // NOTE: Unchecked, i.e. not throwing AIOOB.
+ SetElementPtrSize(GetResolvedMethods(), method_idx, method, ptr_size);
+}
+
+template <typename PtrType>
+inline PtrType DexCache::GetElementPtrSize(PtrType* ptr_array, size_t idx, size_t ptr_size) {
+ if (ptr_size == 8u) {
+ uint64_t element = reinterpret_cast<const uint64_t*>(ptr_array)[idx];
+ return reinterpret_cast<PtrType>(dchecked_integral_cast<uintptr_t>(element));
+ } else {
+ DCHECK_EQ(ptr_size, 4u);
+ uint32_t element = reinterpret_cast<const uint32_t*>(ptr_array)[idx];
+ return reinterpret_cast<PtrType>(dchecked_integral_cast<uintptr_t>(element));
+ }
+}
+
+template <typename PtrType>
+inline void DexCache::SetElementPtrSize(PtrType* ptr_array,
+ size_t idx,
+ PtrType ptr,
+ size_t ptr_size) {
+ if (ptr_size == 8u) {
+ reinterpret_cast<uint64_t*>(ptr_array)[idx] =
+ dchecked_integral_cast<uint64_t>(reinterpret_cast<uintptr_t>(ptr));
+ } else {
+ DCHECK_EQ(ptr_size, 4u);
+ reinterpret_cast<uint32_t*>(ptr_array)[idx] =
+ dchecked_integral_cast<uint32_t>(reinterpret_cast<uintptr_t>(ptr));
+ }
+}
+
+template <VerifyObjectFlags kVerifyFlags, typename Visitor>
+inline void DexCache::VisitReferences(mirror::Class* klass, const Visitor& visitor) {
+ // Visit instance fields first.
+ VisitInstanceFieldsReferences(klass, visitor);
+ // Visit arrays after.
+ GcRoot<mirror::String>* strings = GetStrings();
+ for (size_t i = 0, num_strings = NumStrings(); i != num_strings; ++i) {
+ visitor.VisitRootIfNonNull(strings[i].AddressWithoutBarrier());
+ }
+ GcRoot<mirror::Class>* resolved_types = GetResolvedTypes();
+ for (size_t i = 0, num_types = NumResolvedTypes(); i != num_types; ++i) {
+ visitor.VisitRootIfNonNull(resolved_types[i].AddressWithoutBarrier());
+ }
}
} // namespace mirror
diff --git a/runtime/mirror/dex_cache.cc b/runtime/mirror/dex_cache.cc
index 630faee..349a319 100644
--- a/runtime/mirror/dex_cache.cc
+++ b/runtime/mirror/dex_cache.cc
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-#include "dex_cache.h"
+#include "dex_cache-inl.h"
#include "art_method-inl.h"
#include "base/logging.h"
@@ -31,22 +31,34 @@
namespace art {
namespace mirror {
-void DexCache::Init(const DexFile* dex_file, String* location, ObjectArray<String>* strings,
- ObjectArray<Class>* resolved_types, PointerArray* resolved_methods,
- PointerArray* resolved_fields, size_t pointer_size) {
+void DexCache::Init(const DexFile* dex_file,
+ String* location,
+ GcRoot<String>* strings,
+ uint32_t num_strings,
+ GcRoot<Class>* resolved_types,
+ uint32_t num_resolved_types,
+ ArtMethod** resolved_methods,
+ uint32_t num_resolved_methods,
+ ArtField** resolved_fields,
+ uint32_t num_resolved_fields,
+ size_t pointer_size) {
CHECK(dex_file != nullptr);
CHECK(location != nullptr);
- CHECK(strings != nullptr);
- CHECK(resolved_types != nullptr);
- CHECK(resolved_methods != nullptr);
- CHECK(resolved_fields != nullptr);
+ CHECK_EQ(num_strings != 0u, strings != nullptr);
+ CHECK_EQ(num_resolved_types != 0u, resolved_types != nullptr);
+ CHECK_EQ(num_resolved_methods != 0u, resolved_methods != nullptr);
+ CHECK_EQ(num_resolved_fields != 0u, resolved_fields != nullptr);
SetDexFile(dex_file);
SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(DexCache, location_), location);
- SetFieldObject<false>(StringsOffset(), strings);
- SetFieldObject<false>(ResolvedFieldsOffset(), resolved_fields);
- SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(DexCache, resolved_types_), resolved_types);
- SetFieldObject<false>(ResolvedMethodsOffset(), resolved_methods);
+ SetField64<false>(StringsOffset(), reinterpret_cast<uintptr_t>(strings));
+ SetField64<false>(ResolvedTypesOffset(), reinterpret_cast<uintptr_t>(resolved_types));
+ SetField64<false>(ResolvedMethodsOffset(), reinterpret_cast<uintptr_t>(resolved_methods));
+ SetField64<false>(ResolvedFieldsOffset(), reinterpret_cast<uintptr_t>(resolved_fields));
+ SetField32<false>(NumStringsOffset(), num_strings);
+ SetField32<false>(NumResolvedTypesOffset(), num_resolved_types);
+ SetField32<false>(NumResolvedMethodsOffset(), num_resolved_methods);
+ SetField32<false>(NumResolvedFieldsOffset(), num_resolved_fields);
Runtime* const runtime = Runtime::Current();
if (runtime->HasResolutionMethod()) {
@@ -60,9 +72,9 @@
CHECK(trampoline != nullptr);
CHECK(trampoline->IsRuntimeMethod());
auto* resolved_methods = GetResolvedMethods();
- for (size_t i = 0, length = resolved_methods->GetLength(); i < length; i++) {
- if (resolved_methods->GetElementPtrSize<ArtMethod*>(i, pointer_size) == nullptr) {
- resolved_methods->SetElementPtrSize(i, trampoline, pointer_size);
+ for (size_t i = 0, length = NumResolvedMethods(); i < length; i++) {
+ if (GetElementPtrSize<ArtMethod*>(resolved_methods, i, pointer_size) == nullptr) {
+ SetElementPtrSize(resolved_methods, i, trampoline, pointer_size);
}
}
}
diff --git a/runtime/mirror/dex_cache.h b/runtime/mirror/dex_cache.h
index ba49a15..3144553 100644
--- a/runtime/mirror/dex_cache.h
+++ b/runtime/mirror/dex_cache.h
@@ -46,8 +46,16 @@
return sizeof(DexCache);
}
- void Init(const DexFile* dex_file, String* location, ObjectArray<String>* strings,
- ObjectArray<Class>* types, PointerArray* methods, PointerArray* fields,
+ void Init(const DexFile* dex_file,
+ String* location,
+ GcRoot<String>* strings,
+ uint32_t num_strings,
+ GcRoot<Class>* resolved_types,
+ uint32_t num_resolved_types,
+ ArtMethod** resolved_methods,
+ uint32_t num_resolved_methods,
+ ArtField** resolved_fields,
+ uint32_t num_resolved_fields,
size_t pointer_size) SHARED_REQUIRES(Locks::mutator_lock_);
void Fixup(ArtMethod* trampoline, size_t pointer_size)
@@ -65,6 +73,10 @@
return OFFSET_OF_OBJECT_MEMBER(DexCache, strings_);
}
+ static MemberOffset ResolvedTypesOffset() {
+ return OFFSET_OF_OBJECT_MEMBER(DexCache, resolved_types_);
+ }
+
static MemberOffset ResolvedFieldsOffset() {
return OFFSET_OF_OBJECT_MEMBER(DexCache, resolved_fields_);
}
@@ -73,40 +85,32 @@
return OFFSET_OF_OBJECT_MEMBER(DexCache, resolved_methods_);
}
- size_t NumStrings() SHARED_REQUIRES(Locks::mutator_lock_) {
- return GetStrings()->GetLength();
+ static MemberOffset NumStringsOffset() {
+ return OFFSET_OF_OBJECT_MEMBER(DexCache, num_strings_);
}
- size_t NumResolvedTypes() SHARED_REQUIRES(Locks::mutator_lock_) {
- return GetResolvedTypes()->GetLength();
+ static MemberOffset NumResolvedTypesOffset() {
+ return OFFSET_OF_OBJECT_MEMBER(DexCache, num_resolved_types_);
}
- size_t NumResolvedMethods() SHARED_REQUIRES(Locks::mutator_lock_) {
- return GetResolvedMethods()->GetLength();
+ static MemberOffset NumResolvedFieldsOffset() {
+ return OFFSET_OF_OBJECT_MEMBER(DexCache, num_resolved_fields_);
}
- size_t NumResolvedFields() SHARED_REQUIRES(Locks::mutator_lock_) {
- return GetResolvedFields()->GetLength();
+ static MemberOffset NumResolvedMethodsOffset() {
+ return OFFSET_OF_OBJECT_MEMBER(DexCache, num_resolved_methods_);
}
- String* GetResolvedString(uint32_t string_idx) SHARED_REQUIRES(Locks::mutator_lock_) {
- return GetStrings()->Get(string_idx);
- }
+ String* GetResolvedString(uint32_t string_idx) ALWAYS_INLINE
+ SHARED_REQUIRES(Locks::mutator_lock_);
void SetResolvedString(uint32_t string_idx, String* resolved) ALWAYS_INLINE
- SHARED_REQUIRES(Locks::mutator_lock_) {
- // TODO default transaction support.
- GetStrings()->Set(string_idx, resolved);
- }
-
- Class* GetResolvedType(uint32_t type_idx) ALWAYS_INLINE
- SHARED_REQUIRES(Locks::mutator_lock_) {
- return GetResolvedTypes()->Get(type_idx);
- }
-
- void SetResolvedType(uint32_t type_idx, Class* resolved)
SHARED_REQUIRES(Locks::mutator_lock_);
+ Class* GetResolvedType(uint32_t type_idx) SHARED_REQUIRES(Locks::mutator_lock_);
+
+ void SetResolvedType(uint32_t type_idx, Class* resolved) SHARED_REQUIRES(Locks::mutator_lock_);
+
ALWAYS_INLINE ArtMethod* GetResolvedMethod(uint32_t method_idx, size_t ptr_size)
SHARED_REQUIRES(Locks::mutator_lock_);
@@ -121,21 +125,36 @@
ALWAYS_INLINE void SetResolvedField(uint32_t idx, ArtField* field, size_t ptr_size)
SHARED_REQUIRES(Locks::mutator_lock_);
- ObjectArray<String>* GetStrings() ALWAYS_INLINE SHARED_REQUIRES(Locks::mutator_lock_) {
- return GetFieldObject<ObjectArray<String>>(StringsOffset());
+ GcRoot<String>* GetStrings() ALWAYS_INLINE SHARED_REQUIRES(Locks::mutator_lock_) {
+ return GetFieldPtr<GcRoot<String>*>(StringsOffset());
}
- ObjectArray<Class>* GetResolvedTypes() ALWAYS_INLINE SHARED_REQUIRES(Locks::mutator_lock_) {
- return GetFieldObject<ObjectArray<Class>>(
- OFFSET_OF_OBJECT_MEMBER(DexCache, resolved_types_));
+ GcRoot<Class>* GetResolvedTypes() ALWAYS_INLINE SHARED_REQUIRES(Locks::mutator_lock_) {
+ return GetFieldPtr<GcRoot<Class>*>(ResolvedTypesOffset());
}
- PointerArray* GetResolvedMethods() ALWAYS_INLINE SHARED_REQUIRES(Locks::mutator_lock_) {
- return GetFieldObject<PointerArray>(ResolvedMethodsOffset());
+ ArtMethod** GetResolvedMethods() ALWAYS_INLINE SHARED_REQUIRES(Locks::mutator_lock_) {
+ return GetFieldPtr<ArtMethod**>(ResolvedMethodsOffset());
}
- PointerArray* GetResolvedFields() ALWAYS_INLINE SHARED_REQUIRES(Locks::mutator_lock_) {
- return GetFieldObject<PointerArray>(ResolvedFieldsOffset());
+ ArtField** GetResolvedFields() ALWAYS_INLINE SHARED_REQUIRES(Locks::mutator_lock_) {
+ return GetFieldPtr<ArtField**>(ResolvedFieldsOffset());
+ }
+
+ size_t NumStrings() SHARED_REQUIRES(Locks::mutator_lock_) {
+ return GetField32(NumStringsOffset());
+ }
+
+ size_t NumResolvedTypes() SHARED_REQUIRES(Locks::mutator_lock_) {
+ return GetField32(NumResolvedTypesOffset());
+ }
+
+ size_t NumResolvedMethods() SHARED_REQUIRES(Locks::mutator_lock_) {
+ return GetField32(NumResolvedMethodsOffset());
+ }
+
+ size_t NumResolvedFields() SHARED_REQUIRES(Locks::mutator_lock_) {
+ return GetField32(NumResolvedFieldsOffset());
}
const DexFile* GetDexFile() ALWAYS_INLINE SHARED_REQUIRES(Locks::mutator_lock_) {
@@ -147,17 +166,36 @@
return SetFieldPtr<false>(OFFSET_OF_OBJECT_MEMBER(DexCache, dex_file_), dex_file);
}
+ // NOTE: Get/SetElementPtrSize() are intended for working with ArtMethod** and ArtField**
+ // provided by GetResolvedMethods/Fields() and ArtMethod::GetDexCacheResolvedMethods(),
+ // so they need to be public.
+
+ template <typename PtrType>
+ static PtrType GetElementPtrSize(PtrType* ptr_array, size_t idx, size_t ptr_size);
+
+ template <typename PtrType>
+ static void SetElementPtrSize(PtrType* ptr_array, size_t idx, PtrType ptr, size_t ptr_size);
+
private:
+ // Visit instance fields of the dex cache as well as its associated arrays.
+ template <VerifyObjectFlags kVerifyFlags, typename Visitor>
+ void VisitReferences(mirror::Class* klass, const Visitor& visitor)
+ SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(Locks::heap_bitmap_lock_);
+
HeapReference<Object> dex_;
HeapReference<String> location_;
- // Either an int array or long array based on runtime ISA since these arrays hold pointers.
- HeapReference<PointerArray> resolved_fields_;
- HeapReference<PointerArray> resolved_methods_;
- HeapReference<ObjectArray<Class>> resolved_types_;
- HeapReference<ObjectArray<String>> strings_;
- uint64_t dex_file_;
+ uint64_t dex_file_; // const DexFile*
+ uint64_t resolved_fields_; // ArtField*, array with num_resolved_fields_ elements.
+ uint64_t resolved_methods_; // ArtMethod*, array with num_resolved_methods_ elements.
+ uint64_t resolved_types_; // GcRoot<Class>*, array with num_resolved_types_ elements.
+ uint64_t strings_; // GcRoot<String>*, array with num_strings_ elements.
+ uint32_t num_resolved_fields_; // Number of elements in the resolved_fields_ array.
+ uint32_t num_resolved_methods_; // Number of elements in the resolved_methods_ array.
+ uint32_t num_resolved_types_; // Number of elements in the resolved_types_ array.
+ uint32_t num_strings_; // Number of elements in the strings_ array.
friend struct art::DexCacheOffsets; // for verifying offset information
+ friend class Object; // For VisitReferences
DISALLOW_IMPLICIT_CONSTRUCTORS(DexCache);
};
diff --git a/runtime/mirror/dex_cache_test.cc b/runtime/mirror/dex_cache_test.cc
index 228fce5..8fb860f 100644
--- a/runtime/mirror/dex_cache_test.cc
+++ b/runtime/mirror/dex_cache_test.cc
@@ -43,19 +43,6 @@
EXPECT_EQ(java_lang_dex_file_->NumTypeIds(), dex_cache->NumResolvedTypes());
EXPECT_EQ(java_lang_dex_file_->NumMethodIds(), dex_cache->NumResolvedMethods());
EXPECT_EQ(java_lang_dex_file_->NumFieldIds(), dex_cache->NumResolvedFields());
-
- EXPECT_LE(0, dex_cache->GetStrings()->GetLength());
- EXPECT_LE(0, dex_cache->GetResolvedTypes()->GetLength());
- EXPECT_LE(0, dex_cache->GetResolvedMethods()->GetLength());
- EXPECT_LE(0u, dex_cache->NumResolvedFields());
-
- EXPECT_EQ(java_lang_dex_file_->NumStringIds(),
- static_cast<uint32_t>(dex_cache->GetStrings()->GetLength()));
- EXPECT_EQ(java_lang_dex_file_->NumTypeIds(),
- static_cast<uint32_t>(dex_cache->GetResolvedTypes()->GetLength()));
- EXPECT_EQ(java_lang_dex_file_->NumMethodIds(),
- static_cast<uint32_t>(dex_cache->GetResolvedMethods()->GetLength()));
- EXPECT_EQ(java_lang_dex_file_->NumFieldIds(), dex_cache->NumResolvedFields());
}
} // namespace mirror
diff --git a/runtime/mirror/object-inl.h b/runtime/mirror/object-inl.h
index e35ddcc..90180c5 100644
--- a/runtime/mirror/object-inl.h
+++ b/runtime/mirror/object-inl.h
@@ -27,6 +27,7 @@
#include "class_flags.h"
#include "class_linker.h"
#include "class_loader-inl.h"
+#include "dex_cache-inl.h"
#include "lock_word-inl.h"
#include "monitor.h"
#include "object_array-inl.h"
@@ -1006,6 +1007,17 @@
return down_cast<mirror::ClassLoader*>(this);
}
+template<VerifyObjectFlags kVerifyFlags>
+inline bool Object::IsDexCache() {
+ return GetClass<kVerifyFlags>()->IsDexCacheClass();
+}
+
+template<VerifyObjectFlags kVerifyFlags>
+inline mirror::DexCache* Object::AsDexCache() {
+ DCHECK(IsDexCache<kVerifyFlags>());
+ return down_cast<mirror::DexCache*>(this);
+}
+
template <VerifyObjectFlags kVerifyFlags, typename Visitor, typename JavaLangRefVisitor>
inline void Object::VisitReferences(const Visitor& visitor,
const JavaLangRefVisitor& ref_visitor) {
@@ -1031,6 +1043,9 @@
} else if ((class_flags & kClassFlagReference) != 0) {
VisitInstanceFieldsReferences(klass, visitor);
ref_visitor(klass, AsReference());
+ } else if (class_flags == kClassFlagDexCache) {
+ mirror::DexCache* const dex_cache = AsDexCache<kVerifyFlags>();
+ dex_cache->VisitReferences<kVerifyFlags>(klass, visitor);
} else {
mirror::ClassLoader* const class_loader = AsClassLoader<kVerifyFlags>();
class_loader->VisitReferences<kVerifyFlags>(klass, visitor);
diff --git a/runtime/mirror/object.h b/runtime/mirror/object.h
index 3cec29c..50490bb 100644
--- a/runtime/mirror/object.h
+++ b/runtime/mirror/object.h
@@ -38,6 +38,7 @@
class Array;
class Class;
class ClassLoader;
+class DexCache;
class FinalizerReference;
template<class T> class ObjectArray;
template<class T> class PrimitiveArray;
@@ -162,6 +163,11 @@
template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
ClassLoader* AsClassLoader() SHARED_REQUIRES(Locks::mutator_lock_);
+ template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
+ bool IsDexCache() SHARED_REQUIRES(Locks::mutator_lock_);
+ template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
+ DexCache* AsDexCache() SHARED_REQUIRES(Locks::mutator_lock_);
+
template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
bool IsArrayInstance() SHARED_REQUIRES(Locks::mutator_lock_);
diff --git a/runtime/native/java_lang_DexCache.cc b/runtime/native/java_lang_DexCache.cc
index a2d9797..994ccb1 100644
--- a/runtime/native/java_lang_DexCache.cc
+++ b/runtime/native/java_lang_DexCache.cc
@@ -52,12 +52,14 @@
static jobject DexCache_getResolvedType(JNIEnv* env, jobject javaDexCache, jint type_index) {
ScopedFastNativeObjectAccess soa(env);
mirror::DexCache* dex_cache = soa.Decode<mirror::DexCache*>(javaDexCache);
+ CHECK_LT(static_cast<size_t>(type_index), dex_cache->NumResolvedTypes());
return soa.AddLocalReference<jobject>(dex_cache->GetResolvedType(type_index));
}
static jobject DexCache_getResolvedString(JNIEnv* env, jobject javaDexCache, jint string_index) {
ScopedFastNativeObjectAccess soa(env);
mirror::DexCache* dex_cache = soa.Decode<mirror::DexCache*>(javaDexCache);
+ CHECK_LT(static_cast<size_t>(string_index), dex_cache->NumStrings());
return soa.AddLocalReference<jobject>(dex_cache->GetResolvedString(string_index));
}
@@ -65,6 +67,7 @@
jobject type) {
ScopedFastNativeObjectAccess soa(env);
mirror::DexCache* dex_cache = soa.Decode<mirror::DexCache*>(javaDexCache);
+ CHECK_LT(static_cast<size_t>(type_index), dex_cache->NumResolvedTypes());
dex_cache->SetResolvedType(type_index, soa.Decode<mirror::Class*>(type));
}
@@ -72,6 +75,7 @@
jobject string) {
ScopedFastNativeObjectAccess soa(env);
mirror::DexCache* dex_cache = soa.Decode<mirror::DexCache*>(javaDexCache);
+ CHECK_LT(static_cast<size_t>(string_index), dex_cache->NumStrings());
dex_cache->SetResolvedString(string_index, soa.Decode<mirror::String*>(string));
}
diff --git a/runtime/reflection.cc b/runtime/reflection.cc
index 2fe1e64..019917c 100644
--- a/runtime/reflection.cc
+++ b/runtime/reflection.cc
@@ -223,8 +223,11 @@
for (size_t i = 1, args_offset = 0; i < shorty_len_; ++i, ++args_offset) {
mirror::Object* arg = args->Get(args_offset);
if (((shorty_[i] == 'L') && (arg != nullptr)) || ((arg == nullptr && shorty_[i] != 'L'))) {
+ size_t pointer_size = Runtime::Current()->GetClassLinker()->GetImagePointerSize();
mirror::Class* dst_class =
- m->GetClassFromTypeIndex(classes->GetTypeItem(args_offset).type_idx_, true);
+ m->GetClassFromTypeIndex(classes->GetTypeItem(args_offset).type_idx_,
+ true /* resolve */,
+ pointer_size);
if (UNLIKELY(arg == nullptr || !arg->InstanceOf(dst_class))) {
ThrowIllegalArgumentException(
StringPrintf("method %s argument %zd has type %s, got %s",
@@ -356,9 +359,12 @@
}
// TODO: If args contain object references, it may cause problems.
Thread* const self = Thread::Current();
+ size_t pointer_size = Runtime::Current()->GetClassLinker()->GetImagePointerSize();
for (uint32_t i = 0; i < num_params; i++) {
uint16_t type_idx = params->GetTypeItem(i).type_idx_;
- mirror::Class* param_type = m->GetClassFromTypeIndex(type_idx, true);
+ mirror::Class* param_type = m->GetClassFromTypeIndex(type_idx,
+ true /* resolve*/,
+ pointer_size);
if (param_type == nullptr) {
CHECK(self->IsExceptionPending());
LOG(ERROR) << "Internal error: unresolvable type for argument type in JNI invoke: "
diff --git a/runtime/utils/dex_cache_arrays_layout-inl.h b/runtime/utils/dex_cache_arrays_layout-inl.h
new file mode 100644
index 0000000..4f662d5
--- /dev/null
+++ b/runtime/utils/dex_cache_arrays_layout-inl.h
@@ -0,0 +1,111 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ART_RUNTIME_UTILS_DEX_CACHE_ARRAYS_LAYOUT_INL_H_
+#define ART_RUNTIME_UTILS_DEX_CACHE_ARRAYS_LAYOUT_INL_H_
+
+#include "dex_cache_arrays_layout.h"
+
+#include "base/bit_utils.h"
+#include "base/logging.h"
+#include "gc_root.h"
+#include "globals.h"
+#include "primitive.h"
+
+namespace art {
+
+inline DexCacheArraysLayout::DexCacheArraysLayout(size_t pointer_size, const DexFile* dex_file)
+ : pointer_size_(pointer_size),
+ /* types_offset_ is always 0u, so it's constexpr */
+ methods_offset_(types_offset_ +
+ RoundUp(TypesSize(dex_file->NumTypeIds()), MethodsAlignment())),
+ strings_offset_(methods_offset_ +
+ RoundUp(MethodsSize(dex_file->NumMethodIds()), StringsAlignment())),
+ fields_offset_(strings_offset_ +
+ RoundUp(StringsSize(dex_file->NumStringIds()), FieldsAlignment())),
+ size_(fields_offset_ +
+ RoundUp(FieldsSize(dex_file->NumFieldIds()), Alignment())) {
+ DCHECK(ValidPointerSize(pointer_size)) << pointer_size;
+}
+
+inline size_t DexCacheArraysLayout::Alignment() const {
+ // GcRoot<> alignment is 4, i.e. lower than or equal to the pointer alignment.
+ static_assert(alignof(GcRoot<mirror::Class>) == 4, "Expecting alignof(GcRoot<>) == 4");
+ static_assert(alignof(GcRoot<mirror::String>) == 4, "Expecting alignof(GcRoot<>) == 4");
+ DCHECK(pointer_size_ == 4u || pointer_size_ == 8u);
+ // Pointer alignment is the same as pointer size.
+ return pointer_size_;
+}
+
+inline size_t DexCacheArraysLayout::TypeOffset(uint32_t type_idx) const {
+ return types_offset_ + ElementOffset(sizeof(GcRoot<mirror::Class>), type_idx);
+}
+
+inline size_t DexCacheArraysLayout::TypesSize(size_t num_elements) const {
+ return ArraySize(sizeof(GcRoot<mirror::Class>), num_elements);
+}
+
+inline size_t DexCacheArraysLayout::TypesAlignment() const {
+ return alignof(GcRoot<mirror::Class>);
+}
+
+inline size_t DexCacheArraysLayout::MethodOffset(uint32_t method_idx) const {
+ return methods_offset_ + ElementOffset(pointer_size_, method_idx);
+}
+
+inline size_t DexCacheArraysLayout::MethodsSize(size_t num_elements) const {
+ return ArraySize(pointer_size_, num_elements);
+}
+
+inline size_t DexCacheArraysLayout::MethodsAlignment() const {
+ return pointer_size_;
+}
+
+inline size_t DexCacheArraysLayout::StringOffset(uint32_t string_idx) const {
+ return strings_offset_ + ElementOffset(sizeof(GcRoot<mirror::String>), string_idx);
+}
+
+inline size_t DexCacheArraysLayout::StringsSize(size_t num_elements) const {
+ return ArraySize(sizeof(GcRoot<mirror::String>), num_elements);
+}
+
+inline size_t DexCacheArraysLayout::StringsAlignment() const {
+ return alignof(GcRoot<mirror::String>);
+}
+
+inline size_t DexCacheArraysLayout::FieldOffset(uint32_t field_idx) const {
+ return fields_offset_ + ElementOffset(pointer_size_, field_idx);
+}
+
+inline size_t DexCacheArraysLayout::FieldsSize(size_t num_elements) const {
+ return ArraySize(pointer_size_, num_elements);
+}
+
+inline size_t DexCacheArraysLayout::FieldsAlignment() const {
+ return pointer_size_;
+}
+
+inline size_t DexCacheArraysLayout::ElementOffset(size_t element_size, uint32_t idx) {
+ return element_size * idx;
+}
+
+inline size_t DexCacheArraysLayout::ArraySize(size_t element_size, uint32_t num_elements) {
+ return element_size * num_elements;
+}
+
+} // namespace art
+
+#endif // ART_RUNTIME_UTILS_DEX_CACHE_ARRAYS_LAYOUT_INL_H_
diff --git a/runtime/utils/dex_cache_arrays_layout.h b/runtime/utils/dex_cache_arrays_layout.h
new file mode 100644
index 0000000..d50be5a
--- /dev/null
+++ b/runtime/utils/dex_cache_arrays_layout.h
@@ -0,0 +1,109 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ART_RUNTIME_UTILS_DEX_CACHE_ARRAYS_LAYOUT_H_
+#define ART_RUNTIME_UTILS_DEX_CACHE_ARRAYS_LAYOUT_H_
+
+namespace art {
+
+/**
+ * @class DexCacheArraysLayout
+ * @details This class provides the layout information for the type, method, field and
+ * string arrays for a DexCache with a fixed arrays' layout (such as in the boot image),
+ */
+class DexCacheArraysLayout {
+ public:
+ // Construct an invalid layout.
+ DexCacheArraysLayout()
+ : /* types_offset_ is always 0u */
+ pointer_size_(0u),
+ methods_offset_(0u),
+ strings_offset_(0u),
+ fields_offset_(0u),
+ size_(0u) {
+ }
+
+ // Construct a layout for a particular dex file.
+ DexCacheArraysLayout(size_t pointer_size, const DexFile* dex_file);
+
+ bool Valid() const {
+ return Size() != 0u;
+ }
+
+ size_t Size() const {
+ return size_;
+ }
+
+ size_t Alignment() const;
+
+ size_t TypesOffset() const {
+ return types_offset_;
+ }
+
+ size_t TypeOffset(uint32_t type_idx) const;
+
+ size_t TypesSize(size_t num_elements) const;
+
+ size_t TypesAlignment() const;
+
+ size_t MethodsOffset() const {
+ return methods_offset_;
+ }
+
+ size_t MethodOffset(uint32_t method_idx) const;
+
+ size_t MethodsSize(size_t num_elements) const;
+
+ size_t MethodsAlignment() const;
+
+ size_t StringsOffset() const {
+ return strings_offset_;
+ }
+
+ size_t StringOffset(uint32_t string_idx) const;
+
+ size_t StringsSize(size_t num_elements) const;
+
+ size_t StringsAlignment() const;
+
+ size_t FieldsOffset() const {
+ return fields_offset_;
+ }
+
+ size_t FieldOffset(uint32_t field_idx) const;
+
+ size_t FieldsSize(size_t num_elements) const;
+
+ size_t FieldsAlignment() const;
+
+ private:
+ static constexpr size_t types_offset_ = 0u;
+ const size_t pointer_size_; // Must be first for construction initialization order.
+ const size_t methods_offset_;
+ const size_t strings_offset_;
+ const size_t fields_offset_;
+ const size_t size_;
+
+ static size_t Alignment(size_t pointer_size);
+
+ static size_t ElementOffset(size_t element_size, uint32_t idx);
+
+ static size_t ArraySize(size_t element_size, uint32_t num_elements);
+};
+
+} // namespace art
+
+#endif // ART_RUNTIME_UTILS_DEX_CACHE_ARRAYS_LAYOUT_H_
diff --git a/runtime/verifier/method_verifier.cc b/runtime/verifier/method_verifier.cc
index 4f921bd..35cc4e3 100644
--- a/runtime/verifier/method_verifier.cc
+++ b/runtime/verifier/method_verifier.cc
@@ -2541,8 +2541,9 @@
ArtMethod* called_method = VerifyInvocationArgs(inst, METHOD_VIRTUAL, is_range, is_super);
const RegType* return_type = nullptr;
if (called_method != nullptr) {
- StackHandleScope<1> hs(self_);
- mirror::Class* return_type_class = called_method->GetReturnType(can_load_classes_);
+ size_t pointer_size = Runtime::Current()->GetClassLinker()->GetImagePointerSize();
+ mirror::Class* return_type_class = called_method->GetReturnType(can_load_classes_,
+ pointer_size);
if (return_type_class != nullptr) {
return_type = &FromClass(called_method->GetReturnTypeDescriptor(),
return_type_class,
@@ -2583,8 +2584,9 @@
} else {
is_constructor = called_method->IsConstructor();
return_type_descriptor = called_method->GetReturnTypeDescriptor();
- StackHandleScope<1> hs(self_);
- mirror::Class* return_type_class = called_method->GetReturnType(can_load_classes_);
+ size_t pointer_size = Runtime::Current()->GetClassLinker()->GetImagePointerSize();
+ mirror::Class* return_type_class = called_method->GetReturnType(can_load_classes_,
+ pointer_size);
if (return_type_class != nullptr) {
return_type = &FromClass(return_type_descriptor,
return_type_class,
@@ -4494,7 +4496,9 @@
const RegType& MethodVerifier::GetMethodReturnType() {
if (return_type_ == nullptr) {
if (mirror_method_ != nullptr) {
- mirror::Class* return_type_class = mirror_method_->GetReturnType(can_load_classes_);
+ size_t pointer_size = Runtime::Current()->GetClassLinker()->GetImagePointerSize();
+ mirror::Class* return_type_class = mirror_method_->GetReturnType(can_load_classes_,
+ pointer_size);
if (return_type_class != nullptr) {
return_type_ = &FromClass(mirror_method_->GetReturnTypeDescriptor(),
return_type_class,