ObjPtr<>-ify mirror::Field and mirror::Executable.
Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing
Bug: 31113334
Change-Id: Ib536df95543cb7240a5816bef019391bb90e6369
diff --git a/runtime/gc/space/image_space.cc b/runtime/gc/space/image_space.cc
index e488175..657736c 100644
--- a/runtime/gc/space/image_space.cc
+++ b/runtime/gc/space/image_space.cc
@@ -50,7 +50,7 @@
#include "image_space_fs.h"
#include "intern_table-inl.h"
#include "mirror/class-inl.h"
-#include "mirror/executable.h"
+#include "mirror/executable-inl.h"
#include "mirror/object-inl.h"
#include "mirror/object-refvisitor-inl.h"
#include "oat_file.h"
diff --git a/runtime/interpreter/unstarted_runtime.cc b/runtime/interpreter/unstarted_runtime.cc
index 7a1b7eb..46108cf 100644
--- a/runtime/interpreter/unstarted_runtime.cc
+++ b/runtime/interpreter/unstarted_runtime.cc
@@ -47,6 +47,7 @@
#include "mirror/array-alloc-inl.h"
#include "mirror/array-inl.h"
#include "mirror/class-alloc-inl.h"
+#include "mirror/executable-inl.h"
#include "mirror/field-inl.h"
#include "mirror/method.h"
#include "mirror/object-inl.h"
@@ -358,7 +359,7 @@
}
Runtime* runtime = Runtime::Current();
PointerSize pointer_size = runtime->GetClassLinker()->GetImagePointerSize();
- mirror::Field* field;
+ ObjPtr<mirror::Field> field;
if (runtime->IsActiveTransaction()) {
if (pointer_size == PointerSize::k64) {
field = mirror::Field::CreateFromArtField<PointerSize::k64, true>(
diff --git a/runtime/mirror/executable-inl.h b/runtime/mirror/executable-inl.h
new file mode 100644
index 0000000..6d4b46a
--- /dev/null
+++ b/runtime/mirror/executable-inl.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2016 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_MIRROR_EXECUTABLE_INL_H_
+#define ART_RUNTIME_MIRROR_EXECUTABLE_INL_H_
+
+#include "executable.h"
+
+#include "object-inl.h"
+
+namespace art {
+namespace mirror {
+
+template <bool kTransactionActive,
+ bool kCheckTransaction,
+ VerifyObjectFlags kVerifyFlags>
+inline void Executable::SetArtMethod(ArtMethod* method) {
+ SetField64<kTransactionActive, kCheckTransaction, kVerifyFlags>(
+ ArtMethodOffset(), reinterpret_cast64<uint64_t>(method));
+}
+
+inline ObjPtr<mirror::Class> Executable::GetDeclaringClass() {
+ return GetFieldObject<mirror::Class>(DeclaringClassOffset());
+}
+
+} // namespace mirror
+} // namespace art
+
+#endif // ART_RUNTIME_MIRROR_EXECUTABLE_INL_H_
diff --git a/runtime/mirror/executable.cc b/runtime/mirror/executable.cc
index 24e2047..d2a2ec5 100644
--- a/runtime/mirror/executable.cc
+++ b/runtime/mirror/executable.cc
@@ -14,9 +14,10 @@
* limitations under the License.
*/
-#include "executable.h"
+#include "executable-inl.h"
#include "art_method-inl.h"
+#include "object-inl.h"
namespace art {
namespace mirror {
@@ -38,9 +39,5 @@
template bool Executable::CreateFromArtMethod<PointerSize::k64, false>(ArtMethod* method);
template bool Executable::CreateFromArtMethod<PointerSize::k64, true>(ArtMethod* method);
-mirror::Class* Executable::GetDeclaringClass() {
- return GetFieldObject<mirror::Class>(DeclaringClassOffset());
-}
-
} // namespace mirror
} // namespace art
diff --git a/runtime/mirror/executable.h b/runtime/mirror/executable.h
index 14c9d4c..a99c3ec 100644
--- a/runtime/mirror/executable.h
+++ b/runtime/mirror/executable.h
@@ -18,7 +18,7 @@
#define ART_RUNTIME_MIRROR_EXECUTABLE_H_
#include "accessible_object.h"
-#include "object-inl.h"
+#include "object.h"
#include "read_barrier_option.h"
namespace art {
@@ -44,12 +44,9 @@
template <bool kTransactionActive = false,
bool kCheckTransaction = true,
VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
- void SetArtMethod(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_) {
- SetField64<kTransactionActive, kCheckTransaction, kVerifyFlags>(
- ArtMethodOffset(), reinterpret_cast64<uint64_t>(method));
- }
+ void SetArtMethod(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_);
- mirror::Class* GetDeclaringClass() REQUIRES_SHARED(Locks::mutator_lock_);
+ ObjPtr<mirror::Class> GetDeclaringClass() REQUIRES_SHARED(Locks::mutator_lock_);
static MemberOffset ArtMethodOffset() {
return MemberOffset(OFFSETOF_MEMBER(Executable, art_method_));
diff --git a/runtime/mirror/field-inl.h b/runtime/mirror/field-inl.h
index 803b880..ac11be1 100644
--- a/runtime/mirror/field-inl.h
+++ b/runtime/mirror/field-inl.h
@@ -23,13 +23,28 @@
#include "class-alloc-inl.h"
#include "class_root.h"
#include "dex_cache-inl.h"
+#include "object-inl.h"
namespace art {
namespace mirror {
+inline ObjPtr<mirror::Class> Field::GetDeclaringClass() REQUIRES_SHARED(Locks::mutator_lock_) {
+ return GetFieldObject<Class>(OFFSET_OF_OBJECT_MEMBER(Field, declaring_class_));
+}
+
+inline Primitive::Type Field::GetTypeAsPrimitiveType() {
+ return GetType()->GetPrimitiveType();
+}
+
+inline ObjPtr<mirror::Class> Field::GetType() {
+ return GetFieldObject<mirror::Class>(OFFSET_OF_OBJECT_MEMBER(Field, type_));
+}
+
template <PointerSize kPointerSize, bool kTransactionActive>
-inline mirror::Field* Field::CreateFromArtField(Thread* self, ArtField* field, bool force_resolve) {
+inline ObjPtr<mirror::Field> Field::CreateFromArtField(Thread* self,
+ ArtField* field,
+ bool force_resolve) {
StackHandleScope<2> hs(self);
// Try to resolve type before allocating since this is a thread suspension point.
Handle<mirror::Class> type = hs.NewHandle(field->ResolveType());
@@ -89,10 +104,6 @@
SetFieldObject<kTransactionActive>(OFFSET_OF_OBJECT_MEMBER(Field, type_), type);
}
-inline Primitive::Type Field::GetTypeAsPrimitiveType() {
- return GetType()->GetPrimitiveType();
-}
-
} // namespace mirror
} // namespace art
diff --git a/runtime/mirror/field.cc b/runtime/mirror/field.cc
index 1af0778..e885d41 100644
--- a/runtime/mirror/field.cc
+++ b/runtime/mirror/field.cc
@@ -25,7 +25,7 @@
namespace mirror {
ArtField* Field::GetArtField() {
- mirror::Class* declaring_class = GetDeclaringClass();
+ ObjPtr<mirror::Class> declaring_class = GetDeclaringClass();
if (UNLIKELY(declaring_class->IsProxyClass())) {
DCHECK(IsStatic());
DCHECK_EQ(declaring_class->NumStaticFields(), 2U);
diff --git a/runtime/mirror/field.h b/runtime/mirror/field.h
index 3501e71..6ba8dc6 100644
--- a/runtime/mirror/field.h
+++ b/runtime/mirror/field.h
@@ -42,9 +42,7 @@
return GetField32(OFFSET_OF_OBJECT_MEMBER(Field, dex_field_index_));
}
- mirror::Class* GetDeclaringClass() REQUIRES_SHARED(Locks::mutator_lock_) {
- return GetFieldObject<Class>(OFFSET_OF_OBJECT_MEMBER(Field, declaring_class_));
- }
+ ObjPtr<mirror::Class> GetDeclaringClass() REQUIRES_SHARED(Locks::mutator_lock_);
uint32_t GetAccessFlags() REQUIRES_SHARED(Locks::mutator_lock_) {
return GetField32(OFFSET_OF_OBJECT_MEMBER(Field, access_flags_));
@@ -64,9 +62,7 @@
ALWAYS_INLINE Primitive::Type GetTypeAsPrimitiveType() REQUIRES_SHARED(Locks::mutator_lock_);
- mirror::Class* GetType() REQUIRES_SHARED(Locks::mutator_lock_) {
- return GetFieldObject<mirror::Class>(OFFSET_OF_OBJECT_MEMBER(Field, type_));
- }
+ ObjPtr<mirror::Class> GetType() REQUIRES_SHARED(Locks::mutator_lock_);
int32_t GetOffset() REQUIRES_SHARED(Locks::mutator_lock_) {
return GetField32(OFFSET_OF_OBJECT_MEMBER(Field, offset_));
@@ -76,8 +72,9 @@
ArtField* GetArtField() REQUIRES_SHARED(Locks::mutator_lock_);
template <PointerSize kPointerSize, bool kTransactionActive = false>
- static mirror::Field* CreateFromArtField(Thread* self, ArtField* field,
- bool force_resolve)
+ static ObjPtr<mirror::Field> CreateFromArtField(Thread* self,
+ ArtField* field,
+ bool force_resolve)
REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_);
private:
diff --git a/runtime/native/java_lang_Class.cc b/runtime/native/java_lang_Class.cc
index db62475..2b75c59 100644
--- a/runtime/native/java_lang_Class.cc
+++ b/runtime/native/java_lang_Class.cc
@@ -282,9 +282,8 @@
}
for (ArtField& field : ifields) {
if (IsDiscoverable(public_only, hiddenapi_context, &field)) {
- auto* reflect_field = mirror::Field::CreateFromArtField<kRuntimePointerSize>(self,
- &field,
- force_resolve);
+ ObjPtr<mirror::Field> reflect_field =
+ mirror::Field::CreateFromArtField<kRuntimePointerSize>(self, &field, force_resolve);
if (reflect_field == nullptr) {
if (kIsDebugBuild) {
self->AssertPendingException();
@@ -297,9 +296,8 @@
}
for (ArtField& field : sfields) {
if (IsDiscoverable(public_only, hiddenapi_context, &field)) {
- auto* reflect_field = mirror::Field::CreateFromArtField<kRuntimePointerSize>(self,
- &field,
- force_resolve);
+ ObjPtr<mirror::Field> reflect_field =
+ mirror::Field::CreateFromArtField<kRuntimePointerSize>(self, &field, force_resolve);
if (reflect_field == nullptr) {
if (kIsDebugBuild) {
self->AssertPendingException();
@@ -380,9 +378,9 @@
return nullptr;
}
-ALWAYS_INLINE static inline mirror::Field* GetDeclaredField(Thread* self,
- ObjPtr<mirror::Class> c,
- ObjPtr<mirror::String> name)
+ALWAYS_INLINE static inline ObjPtr<mirror::Field> GetDeclaredField(Thread* self,
+ ObjPtr<mirror::Class> c,
+ ObjPtr<mirror::String> name)
REQUIRES_SHARED(Locks::mutator_lock_) {
ArtField* art_field = FindFieldByName(name, c->GetIFieldsPtr());
if (art_field != nullptr) {
@@ -395,7 +393,7 @@
return nullptr;
}
-static mirror::Field* GetPublicFieldRecursive(
+static ObjPtr<mirror::Field> GetPublicFieldRecursive(
Thread* self, ObjPtr<mirror::Class> clazz, ObjPtr<mirror::String> name)
REQUIRES_SHARED(Locks::mutator_lock_) {
DCHECK(clazz != nullptr);
@@ -408,7 +406,7 @@
// We search the current class, its direct interfaces then its superclass.
while (h_clazz != nullptr) {
- mirror::Field* result = GetDeclaredField(self, h_clazz.Get(), h_name.Get());
+ ObjPtr<mirror::Field> result = GetDeclaredField(self, h_clazz.Get(), h_name.Get());
if ((result != nullptr) && (result->GetAccessFlags() & kAccPublic)) {
return result;
} else if (UNLIKELY(self->IsExceptionPending())) {
diff --git a/runtime/native/java_lang_reflect_Constructor.cc b/runtime/native/java_lang_reflect_Constructor.cc
index 337c084..f9cdc36 100644
--- a/runtime/native/java_lang_reflect_Constructor.cc
+++ b/runtime/native/java_lang_reflect_Constructor.cc
@@ -26,6 +26,7 @@
#include "jni/jni_internal.h"
#include "mirror/class-alloc-inl.h"
#include "mirror/class-inl.h"
+#include "mirror/executable-inl.h"
#include "mirror/method.h"
#include "mirror/object_array-alloc-inl.h"
#include "mirror/object-inl.h"