ObjPtr<>-ify ClassLinker::FindClass(), fix 1 stale reference use.
Thread::CreateAnnotatedStackTrace() was using a stale
reference `aste_array_class`.
Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing
Bug: 31113334
Change-Id: I191907c0053456bb57de425aa6ccd9668df818a2
diff --git a/runtime/class_linker-inl.h b/runtime/class_linker-inl.h
index 7a99d3d..25eb85d 100644
--- a/runtime/class_linker-inl.h
+++ b/runtime/class_linker-inl.h
@@ -33,8 +33,8 @@
namespace art {
-inline mirror::Class* ClassLinker::FindArrayClass(Thread* self,
- ObjPtr<mirror::Class>* element_class) {
+inline ObjPtr<mirror::Class> ClassLinker::FindArrayClass(Thread* self,
+ ObjPtr<mirror::Class>* element_class) {
for (size_t i = 0; i < kFindArrayCacheSize; ++i) {
// Read the cached array class once to avoid races with other threads setting it.
ObjPtr<mirror::Class> array_class = find_array_class_cache_[i].Read();
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index 0952723..cd03401 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -2059,8 +2059,7 @@
// Add 100 in case new classes get loaded when we are filling in the object array.
class_table_size = NumZygoteClasses() + NumNonZygoteClasses() + 100;
}
- ObjPtr<mirror::Class> class_type = mirror::Class::GetJavaLangClass();
- ObjPtr<mirror::Class> array_of_class = FindArrayClass(self, &class_type);
+ ObjPtr<mirror::Class> array_of_class = GetClassRoot<mirror::ObjectArray<mirror::Class>>(this);
classes.Assign(
mirror::ObjectArray<mirror::Class>::Alloc(self, array_of_class, class_table_size));
CHECK(classes != nullptr); // OOME.
@@ -2163,9 +2162,9 @@
return dex_cache.Ptr();
}
-mirror::Class* ClassLinker::AllocClass(Thread* self,
- ObjPtr<mirror::Class> java_lang_Class,
- uint32_t class_size) {
+ObjPtr<mirror::Class> ClassLinker::AllocClass(Thread* self,
+ ObjPtr<mirror::Class> java_lang_Class,
+ uint32_t class_size) {
DCHECK_GE(class_size, sizeof(mirror::Class));
gc::Heap* heap = Runtime::Current()->GetHeap();
mirror::Class::InitializeClassVisitor visitor(class_size);
@@ -2179,7 +2178,7 @@
return k->AsClass();
}
-mirror::Class* ClassLinker::AllocClass(Thread* self, uint32_t class_size) {
+ObjPtr<mirror::Class> ClassLinker::AllocClass(Thread* self, uint32_t class_size) {
return AllocClass(self, GetClassRoot<mirror::Class>(this), class_size);
}
@@ -2190,9 +2189,9 @@
self, GetClassRoot<mirror::ObjectArray<mirror::StackTraceElement>>(this), length);
}
-mirror::Class* ClassLinker::EnsureResolved(Thread* self,
- const char* descriptor,
- ObjPtr<mirror::Class> klass) {
+ObjPtr<mirror::Class> ClassLinker::EnsureResolved(Thread* self,
+ const char* descriptor,
+ ObjPtr<mirror::Class> klass) {
DCHECK(klass != nullptr);
if (kIsDebugBuild) {
StackHandleScope<1> hs(self);
@@ -2400,9 +2399,9 @@
return ret;
}
-mirror::Class* ClassLinker::FindClass(Thread* self,
- const char* descriptor,
- Handle<mirror::ClassLoader> class_loader) {
+ObjPtr<mirror::Class> ClassLinker::FindClass(Thread* self,
+ const char* descriptor,
+ Handle<mirror::ClassLoader> class_loader) {
DCHECK_NE(*descriptor, '\0') << "descriptor is empty string";
DCHECK(self != nullptr);
self->AssertNoPendingException();
@@ -2571,12 +2570,12 @@
return result_ptr.Ptr();
}
-mirror::Class* ClassLinker::DefineClass(Thread* self,
- const char* descriptor,
- size_t hash,
- Handle<mirror::ClassLoader> class_loader,
- const DexFile& dex_file,
- const DexFile::ClassDef& dex_class_def) {
+ObjPtr<mirror::Class> ClassLinker::DefineClass(Thread* self,
+ const char* descriptor,
+ size_t hash,
+ Handle<mirror::ClassLoader> class_loader,
+ const DexFile& dex_file,
+ const DexFile::ClassDef& dex_class_def) {
StackHandleScope<3> hs(self);
auto klass = hs.NewHandle<mirror::Class>(nullptr);
@@ -3534,7 +3533,7 @@
return DexCacheData();
}
-mirror::Class* ClassLinker::CreatePrimitiveClass(Thread* self, Primitive::Type type) {
+ObjPtr<mirror::Class> ClassLinker::CreatePrimitiveClass(Thread* self, Primitive::Type type) {
ObjPtr<mirror::Class> primitive_class =
AllocClass(self, mirror::Class::PrimitiveClassSize(image_pointer_size_));
if (UNLIKELY(primitive_class == nullptr)) {
@@ -3570,8 +3569,10 @@
// array class; that always comes from the base element class.
//
// Returns null with an exception raised on failure.
-mirror::Class* ClassLinker::CreateArrayClass(Thread* self, const char* descriptor, size_t hash,
- Handle<mirror::ClassLoader> class_loader) {
+ObjPtr<mirror::Class> ClassLinker::CreateArrayClass(Thread* self,
+ const char* descriptor,
+ size_t hash,
+ Handle<mirror::ClassLoader> class_loader) {
// Identify the underlying component type
CHECK_EQ('[', descriptor[0]);
StackHandleScope<2> hs(self);
@@ -3718,27 +3719,27 @@
return existing.Ptr();
}
-mirror::Class* ClassLinker::FindPrimitiveClass(char type) {
+ObjPtr<mirror::Class> ClassLinker::FindPrimitiveClass(char type) {
ObjPtr<mirror::ObjectArray<mirror::Class>> class_roots = GetClassRoots();
switch (type) {
case 'B':
- return GetClassRoot(ClassRoot::kPrimitiveByte, class_roots).Ptr();
+ return GetClassRoot(ClassRoot::kPrimitiveByte, class_roots);
case 'C':
- return GetClassRoot(ClassRoot::kPrimitiveChar, class_roots).Ptr();
+ return GetClassRoot(ClassRoot::kPrimitiveChar, class_roots);
case 'D':
- return GetClassRoot(ClassRoot::kPrimitiveDouble, class_roots).Ptr();
+ return GetClassRoot(ClassRoot::kPrimitiveDouble, class_roots);
case 'F':
- return GetClassRoot(ClassRoot::kPrimitiveFloat, class_roots).Ptr();
+ return GetClassRoot(ClassRoot::kPrimitiveFloat, class_roots);
case 'I':
- return GetClassRoot(ClassRoot::kPrimitiveInt, class_roots).Ptr();
+ return GetClassRoot(ClassRoot::kPrimitiveInt, class_roots);
case 'J':
- return GetClassRoot(ClassRoot::kPrimitiveLong, class_roots).Ptr();
+ return GetClassRoot(ClassRoot::kPrimitiveLong, class_roots);
case 'S':
- return GetClassRoot(ClassRoot::kPrimitiveShort, class_roots).Ptr();
+ return GetClassRoot(ClassRoot::kPrimitiveShort, class_roots);
case 'Z':
- return GetClassRoot(ClassRoot::kPrimitiveBoolean, class_roots).Ptr();
+ return GetClassRoot(ClassRoot::kPrimitiveBoolean, class_roots);
case 'V':
- return GetClassRoot(ClassRoot::kPrimitiveVoid, class_roots).Ptr();
+ return GetClassRoot(ClassRoot::kPrimitiveVoid, class_roots);
default:
break;
}
@@ -3747,7 +3748,9 @@
return nullptr;
}
-mirror::Class* ClassLinker::InsertClass(const char* descriptor, ObjPtr<mirror::Class> klass, size_t hash) {
+ObjPtr<mirror::Class> ClassLinker::InsertClass(const char* descriptor,
+ ObjPtr<mirror::Class> klass,
+ size_t hash) {
if (VLOG_IS_ON(class_linker)) {
ObjPtr<mirror::DexCache> dex_cache = klass->GetDexCache();
std::string source;
@@ -3802,16 +3805,16 @@
Runtime::Current()->GetHeap()->WriteBarrierEveryFieldOf(klass);
}
-mirror::Class* ClassLinker::LookupClass(Thread* self,
- const char* descriptor,
- ObjPtr<mirror::ClassLoader> class_loader) {
+ObjPtr<mirror::Class> ClassLinker::LookupClass(Thread* self,
+ const char* descriptor,
+ ObjPtr<mirror::ClassLoader> class_loader) {
return LookupClass(self, descriptor, ComputeModifiedUtf8Hash(descriptor), class_loader);
}
-mirror::Class* ClassLinker::LookupClass(Thread* self,
- const char* descriptor,
- size_t hash,
- ObjPtr<mirror::ClassLoader> class_loader) {
+ObjPtr<mirror::Class> ClassLinker::LookupClass(Thread* self,
+ const char* descriptor,
+ size_t hash,
+ ObjPtr<mirror::ClassLoader> class_loader) {
ReaderMutexLock mu(self, *Locks::classlinker_classes_lock_);
ClassTable* const class_table = ClassTableForClassLoader(class_loader);
if (class_table != nullptr) {
@@ -4264,12 +4267,12 @@
}
}
-mirror::Class* ClassLinker::CreateProxyClass(ScopedObjectAccessAlreadyRunnable& soa,
- jstring name,
- jobjectArray interfaces,
- jobject loader,
- jobjectArray methods,
- jobjectArray throws) {
+ObjPtr<mirror::Class> ClassLinker::CreateProxyClass(ScopedObjectAccessAlreadyRunnable& soa,
+ jstring name,
+ jobjectArray interfaces,
+ jobject loader,
+ jobjectArray methods,
+ jobjectArray throws) {
Thread* self = soa.Self();
StackHandleScope<10> hs(self);
MutableHandle<mirror::Class> temp_klass(hs.NewHandle(
@@ -8112,8 +8115,7 @@
// other than by looking at the shorty ?
const size_t num_method_args = strlen(dex_file.StringDataByIdx(proto_id.shorty_idx_)) - 1;
- ObjPtr<mirror::Class> class_type = mirror::Class::GetJavaLangClass();
- ObjPtr<mirror::Class> array_of_class = FindArrayClass(self, &class_type);
+ ObjPtr<mirror::Class> array_of_class = GetClassRoot<mirror::ObjectArray<mirror::Class>>(this);
Handle<mirror::ObjectArray<mirror::Class>> method_params(hs.NewHandle(
mirror::ObjectArray<mirror::Class>::Alloc(self, array_of_class, num_method_args)));
if (method_params == nullptr) {
@@ -8219,11 +8221,10 @@
}
StackHandleScope<4> hs(self);
- ObjPtr<mirror::Class> class_type = mirror::Class::GetJavaLangClass();
- ObjPtr<mirror::Class> array_of_class = FindArrayClass(self, &class_type);
+ ObjPtr<mirror::Class> array_of_class = GetClassRoot<mirror::ObjectArray<mirror::Class>>(this);
Handle<mirror::ObjectArray<mirror::Class>> method_params(hs.NewHandle(
mirror::ObjectArray<mirror::Class>::Alloc(self, array_of_class, num_params)));
- if (UNLIKELY(method_params.Get() == nullptr)) {
+ if (UNLIKELY(method_params == nullptr)) {
DCHECK(self->IsExceptionPending());
return nullptr;
}
@@ -8398,8 +8399,7 @@
int32_t num_params = static_cast<int32_t>(shorty_length + receiver_count - 1);
StackHandleScope<7> hs(self);
- ObjPtr<mirror::Class> class_type = mirror::Class::GetJavaLangClass();
- ObjPtr<mirror::Class> array_of_class = FindArrayClass(self, &class_type);
+ ObjPtr<mirror::Class> array_of_class = GetClassRoot<mirror::ObjectArray<mirror::Class>>(this);
Handle<mirror::ObjectArray<mirror::Class>> method_params(hs.NewHandle(
mirror::ObjectArray<mirror::Class>::Alloc(self, array_of_class, num_params)));
if (method_params.Get() == nullptr) {
@@ -8897,19 +8897,19 @@
const PointerSize pointer_size_;
};
-mirror::Class* ClassLinker::GetHoldingClassOfCopiedMethod(ArtMethod* method) {
+ObjPtr<mirror::Class> ClassLinker::GetHoldingClassOfCopiedMethod(ArtMethod* method) {
ScopedTrace trace(__FUNCTION__); // Since this function is slow, have a trace to notify people.
CHECK(method->IsCopied());
FindVirtualMethodHolderVisitor visitor(method, image_pointer_size_);
VisitClasses(&visitor);
- return visitor.holder_.Ptr();
+ return visitor.holder_;
}
-mirror::IfTable* ClassLinker::AllocIfTable(Thread* self, size_t ifcount) {
- return down_cast<mirror::IfTable*>(
+ObjPtr<mirror::IfTable> ClassLinker::AllocIfTable(Thread* self, size_t ifcount) {
+ return ObjPtr<mirror::IfTable>::DownCast(ObjPtr<mirror::ObjectArray<mirror::Object>>(
mirror::IfTable::Alloc(self,
GetClassRoot<mirror::ObjectArray<mirror::Object>>(this),
- ifcount * mirror::IfTable::kMax));
+ ifcount * mirror::IfTable::kMax)));
}
// Instantiate ResolveMethod.
diff --git a/runtime/class_linker.h b/runtime/class_linker.h
index 1f94c43..b38f01d 100644
--- a/runtime/class_linker.h
+++ b/runtime/class_linker.h
@@ -146,22 +146,22 @@
// Finds a class by its descriptor, loading it if necessary.
// If class_loader is null, searches boot_class_path_.
- mirror::Class* FindClass(Thread* self,
- const char* descriptor,
- Handle<mirror::ClassLoader> class_loader)
+ ObjPtr<mirror::Class> FindClass(Thread* self,
+ const char* descriptor,
+ Handle<mirror::ClassLoader> class_loader)
REQUIRES_SHARED(Locks::mutator_lock_)
REQUIRES(!Locks::dex_lock_);
// Finds a class by its descriptor using the "system" class loader, ie by searching the
// boot_class_path_.
- mirror::Class* FindSystemClass(Thread* self, const char* descriptor)
+ ObjPtr<mirror::Class> FindSystemClass(Thread* self, const char* descriptor)
REQUIRES_SHARED(Locks::mutator_lock_)
REQUIRES(!Locks::dex_lock_) {
return FindClass(self, descriptor, ScopedNullHandle<mirror::ClassLoader>());
}
// Finds the array class given for the element class.
- mirror::Class* FindArrayClass(Thread* self, ObjPtr<mirror::Class>* element_class)
+ ObjPtr<mirror::Class> FindArrayClass(Thread* self, ObjPtr<mirror::Class>* element_class)
REQUIRES_SHARED(Locks::mutator_lock_)
REQUIRES(!Locks::dex_lock_);
@@ -171,20 +171,20 @@
}
// Define a new a class based on a ClassDef from a DexFile
- mirror::Class* DefineClass(Thread* self,
- const char* descriptor,
- size_t hash,
- Handle<mirror::ClassLoader> class_loader,
- const DexFile& dex_file,
- const DexFile::ClassDef& dex_class_def)
+ ObjPtr<mirror::Class> DefineClass(Thread* self,
+ const char* descriptor,
+ size_t hash,
+ Handle<mirror::ClassLoader> class_loader,
+ const DexFile& dex_file,
+ const DexFile::ClassDef& dex_class_def)
REQUIRES_SHARED(Locks::mutator_lock_)
REQUIRES(!Locks::dex_lock_);
// Finds a class by its descriptor, returning null if it isn't wasn't loaded
// by the given 'class_loader'.
- mirror::Class* LookupClass(Thread* self,
- const char* descriptor,
- ObjPtr<mirror::ClassLoader> class_loader)
+ ObjPtr<mirror::Class> LookupClass(Thread* self,
+ const char* descriptor,
+ ObjPtr<mirror::ClassLoader> class_loader)
REQUIRES(!Locks::classlinker_classes_lock_)
REQUIRES_SHARED(Locks::mutator_lock_);
@@ -193,7 +193,7 @@
REQUIRES(!Locks::classlinker_classes_lock_)
REQUIRES_SHARED(Locks::mutator_lock_);
- mirror::Class* FindPrimitiveClass(char type) REQUIRES_SHARED(Locks::mutator_lock_);
+ ObjPtr<mirror::Class> FindPrimitiveClass(char type) REQUIRES_SHARED(Locks::mutator_lock_);
void DumpForSigQuit(std::ostream& os) REQUIRES(!Locks::classlinker_classes_lock_);
@@ -456,7 +456,7 @@
REQUIRES_SHARED(Locks::mutator_lock_)
REQUIRES(!Roles::uninterruptible_);
- mirror::IfTable* AllocIfTable(Thread* self, size_t ifcount)
+ ObjPtr<mirror::IfTable> AllocIfTable(Thread* self, size_t ifcount)
REQUIRES_SHARED(Locks::mutator_lock_)
REQUIRES(!Roles::uninterruptible_);
@@ -483,12 +483,12 @@
REQUIRES_SHARED(Locks::mutator_lock_)
REQUIRES(!Locks::dex_lock_);
- mirror::Class* CreateProxyClass(ScopedObjectAccessAlreadyRunnable& soa,
- jstring name,
- jobjectArray interfaces,
- jobject loader,
- jobjectArray methods,
- jobjectArray throws)
+ ObjPtr<mirror::Class> CreateProxyClass(ScopedObjectAccessAlreadyRunnable& soa,
+ jstring name,
+ jobjectArray interfaces,
+ jobject loader,
+ jobjectArray methods,
+ jobjectArray throws)
REQUIRES_SHARED(Locks::mutator_lock_);
std::string GetDescriptorForProxy(ObjPtr<mirror::Class> proxy_class)
REQUIRES_SHARED(Locks::mutator_lock_);
@@ -531,7 +531,9 @@
// Attempts to insert a class into a class table. Returns null if
// the class was inserted, otherwise returns an existing class with
// the same descriptor and ClassLoader.
- mirror::Class* InsertClass(const char* descriptor, ObjPtr<mirror::Class> klass, size_t hash)
+ ObjPtr<mirror::Class> InsertClass(const char* descriptor,
+ ObjPtr<mirror::Class> klass,
+ size_t hash)
REQUIRES(!Locks::classlinker_classes_lock_)
REQUIRES_SHARED(Locks::mutator_lock_);
@@ -659,7 +661,7 @@
REQUIRES(!Locks::dex_lock_);
// Get the actual holding class for a copied method. Pretty slow, don't call often.
- mirror::Class* GetHoldingClassOfCopiedMethod(ArtMethod* method)
+ ObjPtr<mirror::Class> GetHoldingClassOfCopiedMethod(ArtMethod* method)
REQUIRES_SHARED(Locks::mutator_lock_);
// Returns null if not found.
@@ -763,16 +765,16 @@
REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_);
// For early bootstrapping by Init
- mirror::Class* AllocClass(Thread* self,
- ObjPtr<mirror::Class> java_lang_Class,
- uint32_t class_size)
+ ObjPtr<mirror::Class> AllocClass(Thread* self,
+ ObjPtr<mirror::Class> java_lang_Class,
+ uint32_t class_size)
REQUIRES_SHARED(Locks::mutator_lock_)
REQUIRES(!Roles::uninterruptible_);
- // Alloc* convenience functions to avoid needing to pass in mirror::Class*
- // values that are known to the ClassLinker such as
- // kObjectArrayClass and kJavaLangString etc.
- mirror::Class* AllocClass(Thread* self, uint32_t class_size)
+ // Alloc* convenience functions to avoid needing to pass in ObjPtr<mirror::Class>
+ // values that are known to the ClassLinker such as classes corresponding to
+ // ClassRoot::kObjectArrayClass and ClassRoot::kJavaLangString etc.
+ ObjPtr<mirror::Class> AllocClass(Thread* self, uint32_t class_size)
REQUIRES_SHARED(Locks::mutator_lock_)
REQUIRES(!Roles::uninterruptible_);
@@ -790,14 +792,14 @@
REQUIRES(!Locks::dex_lock_)
REQUIRES(!Roles::uninterruptible_);
- mirror::Class* CreatePrimitiveClass(Thread* self, Primitive::Type type)
+ ObjPtr<mirror::Class> CreatePrimitiveClass(Thread* self, Primitive::Type type)
REQUIRES_SHARED(Locks::mutator_lock_)
REQUIRES(!Roles::uninterruptible_);
- mirror::Class* CreateArrayClass(Thread* self,
- const char* descriptor,
- size_t hash,
- Handle<mirror::ClassLoader> class_loader)
+ ObjPtr<mirror::Class> CreateArrayClass(Thread* self,
+ const char* descriptor,
+ size_t hash,
+ Handle<mirror::ClassLoader> class_loader)
REQUIRES_SHARED(Locks::mutator_lock_)
REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_);
@@ -889,10 +891,10 @@
// Finds a class by its descriptor, returning NULL if it isn't wasn't loaded
// by the given 'class_loader'. Uses the provided hash for the descriptor.
- mirror::Class* LookupClass(Thread* self,
- const char* descriptor,
- size_t hash,
- ObjPtr<mirror::ClassLoader> class_loader)
+ ObjPtr<mirror::Class> LookupClass(Thread* self,
+ const char* descriptor,
+ size_t hash,
+ ObjPtr<mirror::ClassLoader> class_loader)
REQUIRES(!Locks::classlinker_classes_lock_)
REQUIRES_SHARED(Locks::mutator_lock_);
@@ -1163,7 +1165,9 @@
// when resolution has occurred. This happens in mirror::Class::SetStatus. As resolution may
// retire a class, the version of the class in the table is returned and this may differ from
// the class passed in.
- mirror::Class* EnsureResolved(Thread* self, const char* descriptor, ObjPtr<mirror::Class> klass)
+ ObjPtr<mirror::Class> EnsureResolved(Thread* self,
+ const char* descriptor,
+ ObjPtr<mirror::Class> klass)
WARN_UNUSED
REQUIRES_SHARED(Locks::mutator_lock_)
REQUIRES(!Locks::dex_lock_);
diff --git a/runtime/class_linker_test.cc b/runtime/class_linker_test.cc
index 48ec6b6..5d420aa 100644
--- a/runtime/class_linker_test.cc
+++ b/runtime/class_linker_test.cc
@@ -198,7 +198,8 @@
ASSERT_STREQ(array_descriptor.c_str(), array->GetDescriptor(&temp));
EXPECT_TRUE(array->GetSuperClass() != nullptr);
Thread* self = Thread::Current();
- EXPECT_EQ(class_linker_->FindSystemClass(self, "Ljava/lang/Object;"), array->GetSuperClass());
+ EXPECT_OBJ_PTR_EQ(class_linker_->FindSystemClass(self, "Ljava/lang/Object;"),
+ array->GetSuperClass());
EXPECT_TRUE(array->HasSuperClass());
ASSERT_TRUE(array->GetComponentType() != nullptr);
ASSERT_GT(strlen(array->GetComponentType()->GetDescriptor(&temp)), 0U);
@@ -1079,27 +1080,27 @@
ScopedObjectAccess soa(Thread::Current());
StackHandleScope<5> hs(soa.Self());
Handle<mirror::LongArray> long_array(hs.NewHandle(mirror::LongArray::Alloc(soa.Self(), 0)));
- EXPECT_EQ(class_linker_->FindSystemClass(soa.Self(), "[J"), long_array->GetClass());
+ EXPECT_OBJ_PTR_EQ(class_linker_->FindSystemClass(soa.Self(), "[J"), long_array->GetClass());
uintptr_t data_offset = reinterpret_cast<uintptr_t>(long_array->GetData());
EXPECT_TRUE(IsAligned<8>(data_offset)); // Longs require 8 byte alignment
Handle<mirror::DoubleArray> double_array(hs.NewHandle(mirror::DoubleArray::Alloc(soa.Self(), 0)));
- EXPECT_EQ(class_linker_->FindSystemClass(soa.Self(), "[D"), double_array->GetClass());
+ EXPECT_OBJ_PTR_EQ(class_linker_->FindSystemClass(soa.Self(), "[D"), double_array->GetClass());
data_offset = reinterpret_cast<uintptr_t>(double_array->GetData());
EXPECT_TRUE(IsAligned<8>(data_offset)); // Doubles require 8 byte alignment
Handle<mirror::IntArray> int_array(hs.NewHandle(mirror::IntArray::Alloc(soa.Self(), 0)));
- EXPECT_EQ(class_linker_->FindSystemClass(soa.Self(), "[I"), int_array->GetClass());
+ EXPECT_OBJ_PTR_EQ(class_linker_->FindSystemClass(soa.Self(), "[I"), int_array->GetClass());
data_offset = reinterpret_cast<uintptr_t>(int_array->GetData());
EXPECT_TRUE(IsAligned<4>(data_offset)); // Ints require 4 byte alignment
Handle<mirror::CharArray> char_array(hs.NewHandle(mirror::CharArray::Alloc(soa.Self(), 0)));
- EXPECT_EQ(class_linker_->FindSystemClass(soa.Self(), "[C"), char_array->GetClass());
+ EXPECT_OBJ_PTR_EQ(class_linker_->FindSystemClass(soa.Self(), "[C"), char_array->GetClass());
data_offset = reinterpret_cast<uintptr_t>(char_array->GetData());
EXPECT_TRUE(IsAligned<2>(data_offset)); // Chars require 2 byte alignment
Handle<mirror::ShortArray> short_array(hs.NewHandle(mirror::ShortArray::Alloc(soa.Self(), 0)));
- EXPECT_EQ(class_linker_->FindSystemClass(soa.Self(), "[S"), short_array->GetClass());
+ EXPECT_OBJ_PTR_EQ(class_linker_->FindSystemClass(soa.Self(), "[S"), short_array->GetClass());
data_offset = reinterpret_cast<uintptr_t>(short_array->GetData());
EXPECT_TRUE(IsAligned<2>(data_offset)); // Shorts require 2 byte alignment
diff --git a/runtime/gc/space/space_test.h b/runtime/gc/space/space_test.h
index d5861ed..c94b666 100644
--- a/runtime/gc/space/space_test.h
+++ b/runtime/gc/space/space_test.h
@@ -53,13 +53,11 @@
}
mirror::Class* GetByteArrayClass(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_) {
- StackHandleScope<1> hs(self);
- auto null_loader(hs.NewHandle<mirror::ClassLoader>(nullptr));
if (byte_array_class_ == nullptr) {
- mirror::Class* byte_array_class =
- Runtime::Current()->GetClassLinker()->FindClass(self, "[B", null_loader);
+ ObjPtr<mirror::Class> byte_array_class =
+ Runtime::Current()->GetClassLinker()->FindSystemClass(self, "[B");
EXPECT_TRUE(byte_array_class != nullptr);
- byte_array_class_ = self->GetJniEnv()->NewLocalRef(byte_array_class);
+ byte_array_class_ = self->GetJniEnv()->NewLocalRef(byte_array_class.Ptr());
EXPECT_TRUE(byte_array_class_ != nullptr);
}
return self->DecodeJObject(byte_array_class_)->AsClass();
diff --git a/runtime/hidden_api_test.cc b/runtime/hidden_api_test.cc
index ab0c290..a41d284 100644
--- a/runtime/hidden_api_test.cc
+++ b/runtime/hidden_api_test.cc
@@ -325,8 +325,8 @@
ASSERT_TRUE(h_iface != nullptr);
// Create the proxy class.
- std::vector<mirror::Class*> interfaces;
- interfaces.push_back(h_iface.Get());
+ std::vector<Handle<mirror::Class>> interfaces;
+ interfaces.push_back(h_iface);
Handle<mirror::Class> proxyClass = hs.NewHandle(proxy_test::GenerateProxyClass(
soa, jclass_loader_, runtime_->GetClassLinker(), "$Proxy1234", interfaces));
ASSERT_TRUE(proxyClass != nullptr);
diff --git a/runtime/interpreter/interpreter_common.cc b/runtime/interpreter/interpreter_common.cc
index fab3509..56658c3 100644
--- a/runtime/interpreter/interpreter_common.cc
+++ b/runtime/interpreter/interpreter_common.cc
@@ -1128,9 +1128,9 @@
StackHandleScope<2> hs(self);
// Create array for parameter types.
- ObjPtr<mirror::Class> class_type = mirror::Class::GetJavaLangClass();
ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
- ObjPtr<mirror::Class> class_array_type = class_linker->FindArrayClass(self, &class_type);
+ ObjPtr<mirror::Class> class_array_type =
+ GetClassRoot<mirror::ObjectArray<mirror::Class>>(class_linker);
Handle<mirror::ObjectArray<mirror::Class>> ptypes = hs.NewHandle(
mirror::ObjectArray<mirror::Class>::Alloc(self,
class_array_type,
diff --git a/runtime/interpreter/unstarted_runtime_test.cc b/runtime/interpreter/unstarted_runtime_test.cc
index 88cfafb..fee8375 100644
--- a/runtime/interpreter/unstarted_runtime_test.cc
+++ b/runtime/interpreter/unstarted_runtime_test.cc
@@ -196,7 +196,7 @@
// Prepare for aborts. Aborts assume that the exception class is already resolved, as the
// loading code doesn't work under transactions.
void PrepareForAborts() REQUIRES_SHARED(Locks::mutator_lock_) {
- mirror::Object* result = Runtime::Current()->GetClassLinker()->FindClass(
+ ObjPtr<mirror::Object> result = Runtime::Current()->GetClassLinker()->FindClass(
Thread::Current(),
Transaction::kAbortExceptionSignature,
ScopedNullHandle<mirror::ClassLoader>());
diff --git a/runtime/method_handles_test.cc b/runtime/method_handles_test.cc
index a947342..0db9551 100644
--- a/runtime/method_handles_test.cc
+++ b/runtime/method_handles_test.cc
@@ -17,6 +17,7 @@
#include "method_handles.h"
#include "class_linker-inl.h"
+#include "class_root.h"
#include "common_runtime_test.h"
#include "handle_scope-inl.h"
#include "jvalue-inl.h"
@@ -49,12 +50,11 @@
REQUIRES_SHARED(Locks::mutator_lock_) {
ClassLinker* cl = Runtime::Current()->GetClassLinker();
StackHandleScope<2> hs(self);
- ObjPtr<mirror::Class> class_type = mirror::Class::GetJavaLangClass();
- ObjPtr<mirror::Class> class_array_type = cl->FindArrayClass(self, &class_type);
+ ObjPtr<mirror::Class> class_array_type = GetClassRoot<mirror::ObjectArray<mirror::Class>>(cl);
auto parameter_types = hs.NewHandle(
mirror::ObjectArray<mirror::Class>::Alloc(self, class_array_type, 1));
parameter_types->Set(0, parameter_type.Get());
- Handle<mirror::Class> void_class = hs.NewHandle(cl->FindPrimitiveClass('V'));
+ Handle<mirror::Class> void_class = hs.NewHandle(GetClassRoot(ClassRoot::kPrimitiveVoid, cl));
return mirror::MethodType::Create(self, void_class, parameter_types);
}
diff --git a/runtime/mirror/method_type.cc b/runtime/mirror/method_type.cc
index a8be8b7..483fff5 100644
--- a/runtime/mirror/method_type.cc
+++ b/runtime/mirror/method_type.cc
@@ -28,9 +28,7 @@
ObjPtr<ObjectArray<Class>> AllocatePTypesArray(Thread* self, int count)
REQUIRES_SHARED(Locks::mutator_lock_) {
- ObjPtr<Class> class_type = Class::GetJavaLangClass();
- ObjPtr<Class> class_array_type =
- Runtime::Current()->GetClassLinker()->FindArrayClass(self, &class_type);
+ ObjPtr<Class> class_array_type = GetClassRoot<mirror::ObjectArray<mirror::Class>>();
return ObjectArray<Class>::Alloc(self, class_array_type, count);
}
diff --git a/runtime/mirror/method_type_test.cc b/runtime/mirror/method_type_test.cc
index 16bfc73..2bdea72 100644
--- a/runtime/mirror/method_type_test.cc
+++ b/runtime/mirror/method_type_test.cc
@@ -22,6 +22,7 @@
#include "class-inl.h"
#include "class_linker-inl.h"
#include "class_loader.h"
+#include "class_root.h"
#include "common_runtime_test.h"
#include "handle_scope-inl.h"
#include "object_array-inl.h"
@@ -53,8 +54,8 @@
soa.Self(), FullyQualifiedType(return_type).c_str(), boot_class_loader));
CHECK(return_clazz != nullptr);
- ObjPtr<mirror::Class> class_type = mirror::Class::GetJavaLangClass();
- ObjPtr<mirror::Class> class_array_type = class_linker->FindArrayClass(self, &class_type);
+ ObjPtr<mirror::Class> class_array_type =
+ GetClassRoot<mirror::ObjectArray<mirror::Class>>(class_linker);
Handle<mirror::ObjectArray<mirror::Class>> param_classes = hs.NewHandle(
mirror::ObjectArray<mirror::Class>::Alloc(self, class_array_type, param_types.size()));
diff --git a/runtime/mirror/var_handle.cc b/runtime/mirror/var_handle.cc
index 8311d91..71f41b9 100644
--- a/runtime/mirror/var_handle.cc
+++ b/runtime/mirror/var_handle.cc
@@ -27,6 +27,7 @@
#include "jvalue-inl.h"
#include "method_handles-inl.h"
#include "method_type.h"
+#include "obj_ptr-inl.h"
#include "well_known_classes.h"
namespace art {
@@ -266,31 +267,22 @@
// Returns the return type associated with an AccessModeTemplate based
// on the template and the variable type specified.
-Class* GetReturnType(AccessModeTemplate access_mode_template, ObjPtr<Class> varType)
+static ObjPtr<Class> GetReturnType(AccessModeTemplate access_mode_template, ObjPtr<Class> varType)
REQUIRES_SHARED(Locks::mutator_lock_) {
DCHECK(varType != nullptr);
switch (access_mode_template) {
case AccessModeTemplate::kCompareAndSet:
- return Runtime::Current()->GetClassLinker()->FindPrimitiveClass('Z');
+ return GetClassRoot(ClassRoot::kPrimitiveBoolean);
case AccessModeTemplate::kCompareAndExchange:
case AccessModeTemplate::kGet:
case AccessModeTemplate::kGetAndUpdate:
- return varType.Ptr();
+ return varType;
case AccessModeTemplate::kSet:
- return Runtime::Current()->GetClassLinker()->FindPrimitiveClass('V');
+ return GetClassRoot(ClassRoot::kPrimitiveVoid);
}
return nullptr;
}
-ObjectArray<Class>* NewArrayOfClasses(Thread* self, int count)
- REQUIRES_SHARED(Locks::mutator_lock_) {
- Runtime* const runtime = Runtime::Current();
- ClassLinker* const class_linker = runtime->GetClassLinker();
- ObjPtr<mirror::Class> class_type = mirror::Class::GetJavaLangClass();
- ObjPtr<mirror::Class> array_of_class = class_linker->FindArrayClass(self, &class_type);
- return ObjectArray<Class>::Alloc(Thread::Current(), array_of_class, count);
-}
-
// Method to insert a read barrier for accessors to reference fields.
inline void ReadBarrierForVarHandleAccess(ObjPtr<Object> obj, MemberOffset field_offset)
REQUIRES_SHARED(Locks::mutator_lock_) {
@@ -1410,15 +1402,15 @@
} // namespace
-Class* VarHandle::GetVarType() {
+ObjPtr<Class> VarHandle::GetVarType() {
return GetFieldObject<Class>(VarTypeOffset());
}
-Class* VarHandle::GetCoordinateType0() {
+ObjPtr<Class> VarHandle::GetCoordinateType0() {
return GetFieldObject<Class>(CoordinateType0Offset());
}
-Class* VarHandle::GetCoordinateType1() {
+ObjPtr<Class> VarHandle::GetCoordinateType1() {
return GetFieldObject<Class>(CoordinateType1Offset());
}
@@ -1438,7 +1430,7 @@
// Check return type first. If the return type of the method
// of the VarHandle is immaterial.
if (mt_rtype->GetPrimitiveType() != Primitive::Type::kPrimVoid) {
- ObjPtr<Class> vh_rtype = GetReturnType(access_mode_template, var_type.Ptr());
+ ObjPtr<Class> vh_rtype = GetReturnType(access_mode_template, var_type);
if (vh_rtype != mt_rtype) {
if (!IsReturnTypeConvertible(vh_rtype, mt_rtype)) {
return MatchKind::kNone;
@@ -1513,9 +1505,9 @@
return true;
}
-MethodType* VarHandle::GetMethodTypeForAccessMode(Thread* self,
- ObjPtr<VarHandle> var_handle,
- AccessMode access_mode) {
+ObjPtr<MethodType> VarHandle::GetMethodTypeForAccessMode(Thread* self,
+ ObjPtr<VarHandle> var_handle,
+ AccessMode access_mode) {
// This is a static method as the var_handle might be moved by the GC during it's execution.
AccessModeTemplate access_mode_template = GetAccessModeTemplate(access_mode);
@@ -1525,7 +1517,9 @@
const int32_t ptypes_count = GetNumberOfParameters(access_mode_template,
vh->GetCoordinateType0(),
vh->GetCoordinateType1());
- Handle<ObjectArray<Class>> ptypes = hs.NewHandle(NewArrayOfClasses(self, ptypes_count));
+ ObjPtr<Class> array_of_class = GetClassRoot<ObjectArray<Class>>();
+ Handle<ObjectArray<Class>> ptypes =
+ hs.NewHandle(ObjectArray<Class>::Alloc(Thread::Current(), array_of_class, ptypes_count));
if (ptypes == nullptr) {
return nullptr;
}
@@ -1537,12 +1531,12 @@
vh->GetCoordinateType0(),
vh->GetCoordinateType1());
for (int32_t i = 0; i < ptypes_count; ++i) {
- ptypes->Set(i, ptypes_array[i].Ptr());
+ ptypes->Set(i, ptypes_array[i]);
}
return MethodType::Create(self, rtype, ptypes);
}
-MethodType* VarHandle::GetMethodTypeForAccessMode(Thread* self, AccessMode access_mode) {
+ObjPtr<MethodType> VarHandle::GetMethodTypeForAccessMode(Thread* self, AccessMode access_mode) {
return GetMethodTypeForAccessMode(self, this, access_mode);
}
diff --git a/runtime/mirror/var_handle.h b/runtime/mirror/var_handle.h
index 9829456..48c9d74 100644
--- a/runtime/mirror/var_handle.h
+++ b/runtime/mirror/var_handle.h
@@ -26,6 +26,7 @@
template<class T> class Handle;
class InstructionOperands;
+template<class T> class ObjPtr;
enum class Intrinsics;
@@ -120,7 +121,7 @@
// AccessMode. No check is made for whether the AccessMode is a
// supported operation so the MethodType can be used when raising a
// WrongMethodTypeException exception.
- MethodType* GetMethodTypeForAccessMode(Thread* self, AccessMode accessMode)
+ ObjPtr<MethodType> GetMethodTypeForAccessMode(Thread* self, AccessMode accessMode)
REQUIRES_SHARED(Locks::mutator_lock_);
// Returns a string representing the descriptor of the MethodType associated with
@@ -135,7 +136,7 @@
REQUIRES_SHARED(Locks::mutator_lock_);
// Gets the variable type that is operated on by this VarHandle instance.
- Class* GetVarType() REQUIRES_SHARED(Locks::mutator_lock_);
+ ObjPtr<Class> GetVarType() REQUIRES_SHARED(Locks::mutator_lock_);
// Gets the return type descriptor for a named accessor method,
// nullptr if accessor_method is not supported.
@@ -149,13 +150,13 @@
static bool GetAccessModeByMethodName(const char* method_name, AccessMode* access_mode);
private:
- Class* GetCoordinateType0() REQUIRES_SHARED(Locks::mutator_lock_);
- Class* GetCoordinateType1() REQUIRES_SHARED(Locks::mutator_lock_);
+ ObjPtr<Class> GetCoordinateType0() REQUIRES_SHARED(Locks::mutator_lock_);
+ ObjPtr<Class> GetCoordinateType1() REQUIRES_SHARED(Locks::mutator_lock_);
int32_t GetAccessModesBitMask() REQUIRES_SHARED(Locks::mutator_lock_);
- static MethodType* GetMethodTypeForAccessMode(Thread* self,
- ObjPtr<VarHandle> var_handle,
- AccessMode access_mode)
+ static ObjPtr<MethodType> GetMethodTypeForAccessMode(Thread* self,
+ ObjPtr<VarHandle> var_handle,
+ AccessMode access_mode)
REQUIRES_SHARED(Locks::mutator_lock_);
static MemberOffset VarTypeOffset() {
diff --git a/runtime/mirror/var_handle_test.cc b/runtime/mirror/var_handle_test.cc
index cb2d628..9df96dd 100644
--- a/runtime/mirror/var_handle_test.cc
+++ b/runtime/mirror/var_handle_test.cc
@@ -130,17 +130,17 @@
}
// Helper to get the VarType of a VarHandle.
- static Class* GetVarType(VarHandle* vh) REQUIRES_SHARED(Locks::mutator_lock_) {
+ static ObjPtr<Class> GetVarType(VarHandle* vh) REQUIRES_SHARED(Locks::mutator_lock_) {
return vh->GetVarType();
}
// Helper to get the CoordinateType0 of a VarHandle.
- static Class* GetCoordinateType0(VarHandle* vh) REQUIRES_SHARED(Locks::mutator_lock_) {
+ static ObjPtr<Class> GetCoordinateType0(VarHandle* vh) REQUIRES_SHARED(Locks::mutator_lock_) {
return vh->GetCoordinateType0();
}
// Helper to get the CoordinateType1 of a VarHandle.
- static Class* GetCoordinateType1(VarHandle* vh) REQUIRES_SHARED(Locks::mutator_lock_) {
+ static ObjPtr<Class> GetCoordinateType1(VarHandle* vh) REQUIRES_SHARED(Locks::mutator_lock_) {
return vh->GetCoordinateType1();
}
@@ -150,7 +150,7 @@
}
private:
- static void InitializeVarHandle(VarHandle* vh,
+ static void InitializeVarHandle(ObjPtr<VarHandle> vh,
Handle<Class> var_type,
int32_t access_modes_bit_mask)
REQUIRES_SHARED(Locks::mutator_lock_) {
@@ -158,7 +158,7 @@
vh->SetField32<false>(VarHandle::AccessModesBitMaskOffset(), access_modes_bit_mask);
}
- static void InitializeVarHandle(VarHandle* vh,
+ static void InitializeVarHandle(ObjPtr<VarHandle> vh,
Handle<Class> var_type,
Handle<Class> coordinate_type0,
int32_t access_modes_bit_mask)
@@ -167,7 +167,7 @@
vh->SetFieldObject<false>(VarHandle::CoordinateType0Offset(), coordinate_type0.Get());
}
- static void InitializeVarHandle(VarHandle* vh,
+ static void InitializeVarHandle(ObjPtr<VarHandle> vh,
Handle<Class> var_type,
Handle<Class> coordinate_type0,
Handle<Class> coordinate_type1,
diff --git a/runtime/native/java_lang_Class.cc b/runtime/native/java_lang_Class.cc
index 261178b..c6bdfa1 100644
--- a/runtime/native/java_lang_Class.cc
+++ b/runtime/native/java_lang_Class.cc
@@ -215,17 +215,9 @@
return soa.AddLocalReference<jstring>(mirror::Class::ComputeName(hs.NewHandle(c)));
}
-// TODO: Move this to mirror::Class ? Other mirror types that commonly appear
-// as arrays have a GetArrayClass() method.
-static ObjPtr<mirror::Class> GetClassArrayClass(Thread* self)
- REQUIRES_SHARED(Locks::mutator_lock_) {
- ObjPtr<mirror::Class> class_class = mirror::Class::GetJavaLangClass();
- return Runtime::Current()->GetClassLinker()->FindArrayClass(self, &class_class);
-}
-
static jobjectArray Class_getInterfacesInternal(JNIEnv* env, jobject javaThis) {
ScopedFastNativeObjectAccess soa(env);
- StackHandleScope<4> hs(soa.Self());
+ StackHandleScope<1> hs(soa.Self());
Handle<mirror::Class> klass = hs.NewHandle(DecodeClass(soa, javaThis));
if (klass->IsProxyClass()) {
@@ -237,10 +229,12 @@
return nullptr;
}
+ ClassLinker* linker = Runtime::Current()->GetClassLinker();
const uint32_t num_ifaces = iface_list->Size();
- Handle<mirror::Class> class_array_class = hs.NewHandle(GetClassArrayClass(soa.Self()));
- Handle<mirror::ObjectArray<mirror::Class>> ifaces = hs.NewHandle(
- mirror::ObjectArray<mirror::Class>::Alloc(soa.Self(), class_array_class.Get(), num_ifaces));
+ ObjPtr<mirror::Class> class_array_class =
+ GetClassRoot<mirror::ObjectArray<mirror::Class>>(linker);
+ ObjPtr<mirror::ObjectArray<mirror::Class>> ifaces =
+ mirror::ObjectArray<mirror::Class>::Alloc(soa.Self(), class_array_class, num_ifaces);
if (ifaces.IsNull()) {
DCHECK(soa.Self()->IsExceptionPending());
return nullptr;
@@ -250,20 +244,21 @@
// with kActiveTransaction == false.
DCHECK(!Runtime::Current()->IsActiveTransaction());
- ClassLinker* linker = Runtime::Current()->GetClassLinker();
- MutableHandle<mirror::Class> interface(hs.NewHandle<mirror::Class>(nullptr));
for (uint32_t i = 0; i < num_ifaces; ++i) {
const dex::TypeIndex type_idx = iface_list->GetTypeItem(i).type_idx_;
- interface.Assign(linker->LookupResolvedType(type_idx, klass.Get()));
- ifaces->SetWithoutChecks<false>(i, interface.Get());
+ ObjPtr<mirror::Class> interface = linker->LookupResolvedType(type_idx, klass.Get());
+ DCHECK(interface != nullptr);
+ ifaces->SetWithoutChecks<false>(i, interface);
}
- return soa.AddLocalReference<jobjectArray>(ifaces.Get());
+ return soa.AddLocalReference<jobjectArray>(ifaces);
}
-static mirror::ObjectArray<mirror::Field>* GetDeclaredFields(
- Thread* self, ObjPtr<mirror::Class> klass, bool public_only, bool force_resolve)
- REQUIRES_SHARED(Locks::mutator_lock_) {
+static ObjPtr<mirror::ObjectArray<mirror::Field>> GetDeclaredFields(
+ Thread* self,
+ ObjPtr<mirror::Class> klass,
+ bool public_only,
+ bool force_resolve) REQUIRES_SHARED(Locks::mutator_lock_) {
StackHandleScope<1> hs(self);
IterationRange<StrideIterator<ArtField>> ifields = klass->GetIFields();
IterationRange<StrideIterator<ArtField>> sfields = klass->GetSFields();
@@ -672,10 +667,8 @@
// Pending exception from GetDeclaredClasses.
return nullptr;
}
- ObjPtr<mirror::Class> class_array_class = GetClassArrayClass(soa.Self());
- if (class_array_class == nullptr) {
- return nullptr;
- }
+ ObjPtr<mirror::Class> class_array_class = GetClassRoot<mirror::ObjectArray<mirror::Class>>();
+ DCHECK(class_array_class != nullptr);
ObjPtr<mirror::ObjectArray<mirror::Class>> empty_array =
mirror::ObjectArray<mirror::Class>::Alloc(soa.Self(), class_array_class, 0);
return soa.AddLocalReference<jobjectArray>(empty_array);
diff --git a/runtime/native/java_lang_VMClassLoader.cc b/runtime/native/java_lang_VMClassLoader.cc
index b1511c0..42c7ad5 100644
--- a/runtime/native/java_lang_VMClassLoader.cc
+++ b/runtime/native/java_lang_VMClassLoader.cc
@@ -37,11 +37,11 @@
// A class so we can be friends with ClassLinker and access internal methods.
class VMClassLoader {
public:
- static mirror::Class* LookupClass(ClassLinker* cl,
- Thread* self,
- const char* descriptor,
- size_t hash,
- ObjPtr<mirror::ClassLoader> class_loader)
+ static ObjPtr<mirror::Class> LookupClass(ClassLinker* cl,
+ Thread* self,
+ const char* descriptor,
+ size_t hash,
+ ObjPtr<mirror::ClassLoader> class_loader)
REQUIRES(!Locks::classlinker_classes_lock_)
REQUIRES_SHARED(Locks::mutator_lock_) {
return cl->LookupClass(self, descriptor, hash, class_loader);
diff --git a/runtime/native/java_lang_reflect_Constructor.cc b/runtime/native/java_lang_reflect_Constructor.cc
index 13a8d28..a961cb2 100644
--- a/runtime/native/java_lang_reflect_Constructor.cc
+++ b/runtime/native/java_lang_reflect_Constructor.cc
@@ -20,8 +20,8 @@
#include "art_method-inl.h"
#include "base/enums.h"
-#include "class_linker-inl.h"
#include "class_linker.h"
+#include "class_root.h"
#include "dex/dex_file_annotations.h"
#include "jni/jni_internal.h"
#include "mirror/class-inl.h"
@@ -42,12 +42,8 @@
annotations::GetExceptionTypesForMethod(method);
if (result_array == nullptr) {
// Return an empty array instead of a null pointer.
- ObjPtr<mirror::Class> class_class = mirror::Class::GetJavaLangClass();
- ObjPtr<mirror::Class> class_array_class =
- Runtime::Current()->GetClassLinker()->FindArrayClass(soa.Self(), &class_class);
- if (class_array_class == nullptr) {
- return nullptr;
- }
+ ObjPtr<mirror::Class> class_array_class = GetClassRoot<mirror::ObjectArray<mirror::Class>>();
+ DCHECK(class_array_class != nullptr);
ObjPtr<mirror::ObjectArray<mirror::Class>> empty_array =
mirror::ObjectArray<mirror::Class>::Alloc(soa.Self(), class_array_class, 0);
return soa.AddLocalReference<jobjectArray>(empty_array);
diff --git a/runtime/native/java_lang_reflect_Executable.cc b/runtime/native/java_lang_reflect_Executable.cc
index 9a2d302..a40cb9b 100644
--- a/runtime/native/java_lang_reflect_Executable.cc
+++ b/runtime/native/java_lang_reflect_Executable.cc
@@ -20,6 +20,7 @@
#include "nativehelper/jni_macros.h"
#include "art_method-inl.h"
+#include "class_root.h"
#include "dex/dex_file_annotations.h"
#include "handle.h"
#include "jni/jni_internal.h"
@@ -335,15 +336,6 @@
return soa.AddLocalReference<jclass>(return_type);
}
-// TODO: Move this to mirror::Class ? Other mirror types that commonly appear
-// as arrays have a GetArrayClass() method. This is duplicated in
-// java_lang_Class.cc as well.
-static ObjPtr<mirror::Class> GetClassArrayClass(Thread* self)
- REQUIRES_SHARED(Locks::mutator_lock_) {
- ObjPtr<mirror::Class> class_class = mirror::Class::GetJavaLangClass();
- return Runtime::Current()->GetClassLinker()->FindArrayClass(self, &class_class);
-}
-
static jobjectArray Executable_getParameterTypesInternal(JNIEnv* env, jobject javaMethod) {
ScopedFastNativeObjectAccess soa(env);
ArtMethod* method = ArtMethod::FromReflectedMethod(soa, javaMethod);
@@ -356,10 +348,10 @@
const uint32_t num_params = params->Size();
- StackHandleScope<3> hs(soa.Self());
- Handle<mirror::Class> class_array_class = hs.NewHandle(GetClassArrayClass(soa.Self()));
+ StackHandleScope<2> hs(soa.Self());
+ ObjPtr<mirror::Class> class_array_class = GetClassRoot<mirror::ObjectArray<mirror::Class>>();
Handle<mirror::ObjectArray<mirror::Class>> ptypes = hs.NewHandle(
- mirror::ObjectArray<mirror::Class>::Alloc(soa.Self(), class_array_class.Get(), num_params));
+ mirror::ObjectArray<mirror::Class>::Alloc(soa.Self(), class_array_class, num_params));
if (ptypes.IsNull()) {
DCHECK(soa.Self()->IsExceptionPending());
return nullptr;
diff --git a/runtime/native/java_lang_reflect_Method.cc b/runtime/native/java_lang_reflect_Method.cc
index 52e0494..34455fe 100644
--- a/runtime/native/java_lang_reflect_Method.cc
+++ b/runtime/native/java_lang_reflect_Method.cc
@@ -22,6 +22,7 @@
#include "base/enums.h"
#include "class_linker-inl.h"
#include "class_linker.h"
+#include "class_root.h"
#include "dex/dex_file_annotations.h"
#include "jni/jni_internal.h"
#include "mirror/class-inl.h"
@@ -66,12 +67,8 @@
annotations::GetExceptionTypesForMethod(method);
if (result_array == nullptr) {
// Return an empty array instead of a null pointer
- ObjPtr<mirror::Class> class_class = mirror::Class::GetJavaLangClass();
- ObjPtr<mirror::Class> class_array_class =
- Runtime::Current()->GetClassLinker()->FindArrayClass(soa.Self(), &class_class);
- if (class_array_class == nullptr) {
- return nullptr;
- }
+ ObjPtr<mirror::Class> class_array_class = GetClassRoot<mirror::ObjectArray<mirror::Class>>();
+ DCHECK(class_array_class != nullptr);
mirror::ObjectArray<mirror::Class>* empty_array =
mirror::ObjectArray<mirror::Class>::Alloc(soa.Self(), class_array_class, 0);
return soa.AddLocalReference<jobjectArray>(empty_array);
diff --git a/runtime/proxy_test.cc b/runtime/proxy_test.cc
index 4e0bf89..946ea01 100644
--- a/runtime/proxy_test.cc
+++ b/runtime/proxy_test.cc
@@ -44,9 +44,9 @@
ASSERT_TRUE(I != nullptr);
ASSERT_TRUE(J != nullptr);
- std::vector<mirror::Class*> interfaces;
- interfaces.push_back(I.Get());
- interfaces.push_back(J.Get());
+ std::vector<Handle<mirror::Class>> interfaces;
+ interfaces.push_back(I);
+ interfaces.push_back(J);
Handle<mirror::Class> proxy_class(hs.NewHandle(
GenerateProxyClass(soa, jclass_loader, class_linker_, "$Proxy1234", interfaces)));
interfaces.clear(); // Don't least possibly stale objects in the array as good practice.
@@ -80,9 +80,9 @@
Handle<mirror::Class> proxyClass;
{
- std::vector<mirror::Class*> interfaces;
- interfaces.push_back(I.Get());
- interfaces.push_back(J.Get());
+ std::vector<Handle<mirror::Class>> interfaces;
+ interfaces.push_back(I);
+ interfaces.push_back(J);
proxyClass = hs.NewHandle(
GenerateProxyClass(soa, jclass_loader, class_linker_, "$Proxy1234", interfaces));
}
@@ -131,7 +131,7 @@
Handle<mirror::Class> proxyClass0;
Handle<mirror::Class> proxyClass1;
{
- std::vector<mirror::Class*> interfaces;
+ std::vector<Handle<mirror::Class>> interfaces;
proxyClass0 = hs.NewHandle(
GenerateProxyClass(soa, jclass_loader, class_linker_, "$Proxy0", interfaces));
proxyClass1 = hs.NewHandle(
diff --git a/runtime/proxy_test.h b/runtime/proxy_test.h
index fa5a449..860d96c 100644
--- a/runtime/proxy_test.h
+++ b/runtime/proxy_test.h
@@ -25,6 +25,7 @@
#include "class_root.h"
#include "mirror/class-inl.h"
#include "mirror/method.h"
+#include "obj_ptr-inl.h"
namespace art {
namespace proxy_test {
@@ -32,11 +33,11 @@
// Generate a proxy class with the given name and interfaces. This is a simplification from what
// libcore does to fit to our test needs. We do not check for duplicated interfaces or methods and
// we do not declare exceptions.
-mirror::Class* GenerateProxyClass(ScopedObjectAccess& soa,
- jobject jclass_loader,
- ClassLinker* class_linker,
- const char* className,
- const std::vector<mirror::Class*>& interfaces)
+ObjPtr<mirror::Class> GenerateProxyClass(ScopedObjectAccess& soa,
+ jobject jclass_loader,
+ ClassLinker* class_linker,
+ const char* className,
+ const std::vector<Handle<mirror::Class>>& interfaces)
REQUIRES_SHARED(Locks::mutator_lock_) {
StackHandleScope<1> hs(soa.Self());
Handle<mirror::Class> javaLangObject = hs.NewHandle(
@@ -46,21 +47,23 @@
jclass javaLangClass = soa.AddLocalReference<jclass>(mirror::Class::GetJavaLangClass());
// Builds the interfaces array.
- jobjectArray proxyClassInterfaces = soa.Env()->NewObjectArray(interfaces.size(), javaLangClass,
- nullptr);
+ jobjectArray proxyClassInterfaces =
+ soa.Env()->NewObjectArray(interfaces.size(), javaLangClass, /* initialElement */ nullptr);
soa.Self()->AssertNoPendingException();
for (size_t i = 0; i < interfaces.size(); ++i) {
soa.Env()->SetObjectArrayElement(proxyClassInterfaces, i,
- soa.AddLocalReference<jclass>(interfaces[i]));
+ soa.AddLocalReference<jclass>(interfaces[i].Get()));
}
// Builds the method array.
jsize methods_count = 3; // Object.equals, Object.hashCode and Object.toString.
- for (mirror::Class* interface : interfaces) {
+ for (Handle<mirror::Class> interface : interfaces) {
methods_count += interface->NumVirtualMethods();
}
jobjectArray proxyClassMethods = soa.Env()->NewObjectArray(
- methods_count, soa.AddLocalReference<jclass>(GetClassRoot<mirror::Method>()), nullptr);
+ methods_count,
+ soa.AddLocalReference<jclass>(GetClassRoot<mirror::Method>()),
+ /* initialElement */ nullptr);
soa.Self()->AssertNoPendingException();
jsize array_index = 0;
@@ -91,7 +94,7 @@
proxyClassMethods, array_index++, soa.AddLocalReference<jobject>(
mirror::Method::CreateFromArtMethod<kRuntimePointerSize, false>(soa.Self(), method)));
// Now adds all interfaces virtual methods.
- for (mirror::Class* interface : interfaces) {
+ for (Handle<mirror::Class> interface : interfaces) {
for (auto& m : interface->GetDeclaredVirtualMethods(kRuntimePointerSize)) {
soa.Env()->SetObjectArrayElement(
proxyClassMethods, array_index++, soa.AddLocalReference<jobject>(
@@ -104,9 +107,13 @@
jobjectArray proxyClassThrows = soa.Env()->NewObjectArray(0, javaLangClass, nullptr);
soa.Self()->AssertNoPendingException();
- mirror::Class* proxyClass = class_linker->CreateProxyClass(
- soa, soa.Env()->NewStringUTF(className), proxyClassInterfaces, jclass_loader,
- proxyClassMethods, proxyClassThrows);
+ ObjPtr<mirror::Class> proxyClass = class_linker->CreateProxyClass(
+ soa,
+ soa.Env()->NewStringUTF(className),
+ proxyClassInterfaces,
+ jclass_loader,
+ proxyClassMethods,
+ proxyClassThrows);
soa.Self()->AssertNoPendingException();
return proxyClass;
}
diff --git a/runtime/reflection_test.cc b/runtime/reflection_test.cc
index d2d720f..424ee06 100644
--- a/runtime/reflection_test.cc
+++ b/runtime/reflection_test.cc
@@ -80,7 +80,7 @@
jclass GetPrimitiveClass(char descriptor) {
ScopedObjectAccess soa(env_);
- mirror::Class* c = class_linker_->FindPrimitiveClass(descriptor);
+ ObjPtr<mirror::Class> c = class_linker_->FindPrimitiveClass(descriptor);
CHECK(c != nullptr);
return soa.AddLocalReference<jclass>(c);
}
@@ -518,7 +518,7 @@
hs.NewHandle(soa.Decode<mirror::ClassLoader>(jclass_loader)));
CompileDirectMethod(class_loader, "Main", "main", "([Ljava/lang/String;)V");
- mirror::Class* klass = class_linker_->FindClass(soa.Self(), "LMain;", class_loader);
+ ObjPtr<mirror::Class> klass = class_linker_->FindClass(soa.Self(), "LMain;", class_loader);
ASSERT_TRUE(klass != nullptr);
ArtMethod* method = klass->FindClassMethod("main",
diff --git a/runtime/thread.cc b/runtime/thread.cc
index ab1a4bb..b59606a 100644
--- a/runtime/thread.cc
+++ b/runtime/thread.cc
@@ -2862,27 +2862,18 @@
ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
StackHandleScope<6> hs(soa.Self());
- mirror::Class* aste_array_class = class_linker->FindClass(
+ Handle<mirror::Class> h_aste_array_class = hs.NewHandle(class_linker->FindSystemClass(
soa.Self(),
- "[Ldalvik/system/AnnotatedStackTraceElement;",
- ScopedNullHandle<mirror::ClassLoader>());
- if (aste_array_class == nullptr) {
+ "[Ldalvik/system/AnnotatedStackTraceElement;"));
+ if (h_aste_array_class == nullptr) {
return nullptr;
}
- Handle<mirror::Class> h_aste_array_class(hs.NewHandle<mirror::Class>(aste_array_class));
+ Handle<mirror::Class> h_aste_class = hs.NewHandle(h_aste_array_class->GetComponentType());
- mirror::Class* o_array_class = class_linker->FindClass(soa.Self(),
- "[Ljava/lang/Object;",
- ScopedNullHandle<mirror::ClassLoader>());
- if (o_array_class == nullptr) {
- // This should not fail in a healthy runtime.
- soa.Self()->AssertPendingException();
- return nullptr;
- }
- Handle<mirror::Class> h_o_array_class(hs.NewHandle<mirror::Class>(o_array_class));
+ Handle<mirror::Class> h_o_array_class =
+ hs.NewHandle(GetClassRoot<mirror::ObjectArray<mirror::Object>>(class_linker));
+ DCHECK(h_o_array_class != nullptr); // Class roots must be already initialized.
- Handle<mirror::Class> h_aste_class(hs.NewHandle<mirror::Class>(
- h_aste_array_class->GetComponentType()));
// Make sure the AnnotatedStackTraceElement.class is initialized, b/76208924 .
class_linker->EnsureInitialized(soa.Self(),
@@ -2906,7 +2897,7 @@
size_t length = dumper.stack_trace_elements_.size();
ObjPtr<mirror::ObjectArray<mirror::Object>> array =
- mirror::ObjectArray<mirror::Object>::Alloc(soa.Self(), aste_array_class, length);
+ mirror::ObjectArray<mirror::Object>::Alloc(soa.Self(), h_aste_array_class.Get(), length);
if (array == nullptr) {
soa.Self()->AssertPendingOOMException();
return nullptr;
diff --git a/runtime/verifier/method_verifier.cc b/runtime/verifier/method_verifier.cc
index cc71dc5..2e3a659 100644
--- a/runtime/verifier/method_verifier.cc
+++ b/runtime/verifier/method_verifier.cc
@@ -144,7 +144,7 @@
}
FailureKind MethodVerifier::VerifyClass(Thread* self,
- mirror::Class* klass,
+ ObjPtr<mirror::Class> klass,
CompilerCallbacks* callbacks,
bool allow_soft_failures,
HardFailLogMode log_level,
diff --git a/runtime/verifier/method_verifier.h b/runtime/verifier/method_verifier.h
index b2adc62..ae7481c 100644
--- a/runtime/verifier/method_verifier.h
+++ b/runtime/verifier/method_verifier.h
@@ -96,7 +96,7 @@
public:
// Verify a class. Returns "kNoFailure" on success.
static FailureKind VerifyClass(Thread* self,
- mirror::Class* klass,
+ ObjPtr<mirror::Class> klass,
CompilerCallbacks* callbacks,
bool allow_soft_failures,
HardFailLogMode log_level,
diff --git a/runtime/verifier/method_verifier_test.cc b/runtime/verifier/method_verifier_test.cc
index db3f093..d1be9fa 100644
--- a/runtime/verifier/method_verifier_test.cc
+++ b/runtime/verifier/method_verifier_test.cc
@@ -37,7 +37,7 @@
REQUIRES_SHARED(Locks::mutator_lock_) {
ASSERT_TRUE(descriptor != nullptr);
Thread* self = Thread::Current();
- mirror::Class* klass = class_linker_->FindSystemClass(self, descriptor.c_str());
+ ObjPtr<mirror::Class> klass = class_linker_->FindSystemClass(self, descriptor.c_str());
// Verify the class
std::string error_msg;