Determine HLoadClass/String load kind early.
This helps save memory by avoiding the allocation of
HEnvironment and related objects for AOT references to
boot image strings and classes (kBootImage* load kinds)
and also for JIT references (kJitTableAddress).
Compiling aosp_taimen-userdebug boot image, the most memory
hungry method BatteryStats.dumpLocked() needs
- before:
Used 55105384 bytes of arena memory...
...
UseListNode 10009704
Environment 423248
EnvVRegs 20676560
...
- after:
Used 50559176 bytes of arena memory...
...
UseListNode 8568936
Environment 365680
EnvVRegs 17628704
...
Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing --jit
Bug: 34053922
Change-Id: I68e73a438e6ac8e8908e6fccf53bbeea8a64a077
diff --git a/runtime/art_method.cc b/runtime/art_method.cc
index 43a5139..ebfa4fe 100644
--- a/runtime/art_method.cc
+++ b/runtime/art_method.cc
@@ -134,7 +134,7 @@
return dex_file->GetIndexForClassDef(*class_def);
}
-mirror::String* ArtMethod::GetNameAsString(Thread* self) {
+ObjPtr<mirror::String> ArtMethod::GetNameAsString(Thread* self) {
CHECK(!IsProxyMethod());
StackHandleScope<1> hs(self);
Handle<mirror::DexCache> dex_cache(hs.NewHandle(GetDexCache()));
@@ -550,8 +550,8 @@
}
auto* cl = Runtime::Current()->GetClassLinker();
for (size_t i = 0; i < count; ++i) {
- auto type_idx = proto_params->GetTypeItem(i).type_idx_;
- auto* type = cl->ResolveType(type_idx, this);
+ dex::TypeIndex type_idx = proto_params->GetTypeItem(i).type_idx_;
+ ObjPtr<mirror::Class> type = cl->ResolveType(type_idx, this);
if (type == nullptr) {
Thread::Current()->AssertPendingException();
return false;
diff --git a/runtime/art_method.h b/runtime/art_method.h
index 0a592e0..60e436c 100644
--- a/runtime/art_method.h
+++ b/runtime/art_method.h
@@ -575,7 +575,7 @@
ALWAYS_INLINE const char* GetName() REQUIRES_SHARED(Locks::mutator_lock_);
- mirror::String* GetNameAsString(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_);
+ ObjPtr<mirror::String> GetNameAsString(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_);
const DexFile::CodeItem* GetCodeItem() REQUIRES_SHARED(Locks::mutator_lock_);
diff --git a/runtime/class_linker-inl.h b/runtime/class_linker-inl.h
index d6f0030..648b455 100644
--- a/runtime/class_linker-inl.h
+++ b/runtime/class_linker-inl.h
@@ -73,7 +73,8 @@
return type;
}
-inline mirror::Class* ClassLinker::ResolveType(dex::TypeIndex type_idx, ArtMethod* referrer) {
+inline ObjPtr<mirror::Class> ClassLinker::ResolveType(dex::TypeIndex type_idx,
+ ArtMethod* referrer) {
Thread::PoisonObjectPointersIfDebug();
if (kIsDebugBuild) {
Thread::Current()->AssertNoPendingException();
@@ -87,7 +88,7 @@
const DexFile& dex_file = *dex_cache->GetDexFile();
resolved_type = ResolveType(dex_file, type_idx, dex_cache, class_loader);
}
- return resolved_type.Ptr();
+ return resolved_type;
}
template <bool kThrowOnError, typename ClassGetter>
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index e5bb786..80d4bb1 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -7727,14 +7727,14 @@
klass->SetReferenceInstanceOffsets(reference_offsets);
}
-mirror::String* ClassLinker::ResolveString(const DexFile& dex_file,
- dex::StringIndex string_idx,
- Handle<mirror::DexCache> dex_cache) {
+ObjPtr<mirror::String> ClassLinker::ResolveString(const DexFile& dex_file,
+ dex::StringIndex string_idx,
+ Handle<mirror::DexCache> dex_cache) {
DCHECK(dex_cache != nullptr);
Thread::PoisonObjectPointersIfDebug();
ObjPtr<mirror::String> resolved = dex_cache->GetResolvedString(string_idx);
if (resolved != nullptr) {
- return resolved.Ptr();
+ return resolved;
}
uint32_t utf16_length;
const char* utf8_data = dex_file.StringDataAndUtf16LengthByIdx(string_idx, &utf16_length);
@@ -7742,16 +7742,16 @@
if (string != nullptr) {
dex_cache->SetResolvedString(string_idx, string);
}
- return string.Ptr();
+ return string;
}
-mirror::String* ClassLinker::LookupString(const DexFile& dex_file,
- dex::StringIndex string_idx,
- ObjPtr<mirror::DexCache> dex_cache) {
+ObjPtr<mirror::String> ClassLinker::LookupString(const DexFile& dex_file,
+ dex::StringIndex string_idx,
+ ObjPtr<mirror::DexCache> dex_cache) {
DCHECK(dex_cache != nullptr);
ObjPtr<mirror::String> resolved = dex_cache->GetResolvedString(string_idx);
if (resolved != nullptr) {
- return resolved.Ptr();
+ return resolved;
}
uint32_t utf16_length;
const char* utf8_data = dex_file.StringDataAndUtf16LengthByIdx(string_idx, &utf16_length);
@@ -7760,7 +7760,7 @@
if (string != nullptr) {
dex_cache->SetResolvedString(string_idx, string);
}
- return string.Ptr();
+ return string;
}
ObjPtr<mirror::Class> ClassLinker::LookupResolvedType(const DexFile& dex_file,
@@ -7794,19 +7794,19 @@
return type;
}
-mirror::Class* ClassLinker::ResolveType(const DexFile& dex_file,
- dex::TypeIndex type_idx,
- ObjPtr<mirror::Class> referrer) {
+ObjPtr<mirror::Class> ClassLinker::ResolveType(const DexFile& dex_file,
+ dex::TypeIndex type_idx,
+ ObjPtr<mirror::Class> referrer) {
StackHandleScope<2> hs(Thread::Current());
Handle<mirror::DexCache> dex_cache(hs.NewHandle(referrer->GetDexCache()));
Handle<mirror::ClassLoader> class_loader(hs.NewHandle(referrer->GetClassLoader()));
return ResolveType(dex_file, type_idx, dex_cache, class_loader);
}
-mirror::Class* ClassLinker::ResolveType(const DexFile& dex_file,
- dex::TypeIndex type_idx,
- Handle<mirror::DexCache> dex_cache,
- Handle<mirror::ClassLoader> class_loader) {
+ObjPtr<mirror::Class> ClassLinker::ResolveType(const DexFile& dex_file,
+ dex::TypeIndex type_idx,
+ Handle<mirror::DexCache> dex_cache,
+ Handle<mirror::ClassLoader> class_loader) {
DCHECK(dex_cache != nullptr);
Thread::PoisonObjectPointersIfDebug();
ObjPtr<mirror::Class> resolved = dex_cache->GetResolvedType(type_idx);
@@ -7835,7 +7835,7 @@
}
DCHECK((resolved == nullptr) || resolved->IsResolved())
<< resolved->PrettyDescriptor() << " " << resolved->GetStatus();
- return resolved.Ptr();
+ return resolved;
}
template <ClassLinker::ResolveMode kResolveMode>
@@ -8410,7 +8410,7 @@
DexFileParameterIterator it(*dex_file, target_method->GetPrototype());
while (it.HasNext()) {
const dex::TypeIndex type_idx = it.GetTypeIdx();
- mirror::Class* klass = ResolveType(*dex_file, type_idx, dex_cache, class_loader);
+ ObjPtr<mirror::Class> klass = ResolveType(*dex_file, type_idx, dex_cache, class_loader);
if (nullptr == klass) {
DCHECK(self->IsExceptionPending());
return nullptr;
diff --git a/runtime/class_linker.h b/runtime/class_linker.h
index a4c4f3d..16255f4 100644
--- a/runtime/class_linker.h
+++ b/runtime/class_linker.h
@@ -245,31 +245,31 @@
// Resolve a String with the given index from the DexFile, storing the
// result in the DexCache.
- mirror::String* ResolveString(const DexFile& dex_file,
- dex::StringIndex string_idx,
- Handle<mirror::DexCache> dex_cache)
+ ObjPtr<mirror::String> ResolveString(const DexFile& dex_file,
+ dex::StringIndex string_idx,
+ Handle<mirror::DexCache> dex_cache)
REQUIRES_SHARED(Locks::mutator_lock_);
// Find a String with the given index from the DexFile, storing the
// result in the DexCache if found. Return null if not found.
- mirror::String* LookupString(const DexFile& dex_file,
- dex::StringIndex string_idx,
- ObjPtr<mirror::DexCache> dex_cache)
+ ObjPtr<mirror::String> LookupString(const DexFile& dex_file,
+ dex::StringIndex string_idx,
+ ObjPtr<mirror::DexCache> dex_cache)
REQUIRES_SHARED(Locks::mutator_lock_);
// Resolve a Type with the given index from the DexFile, storing the
// result in the DexCache. The referrer is used to identify the
// target DexCache and ClassLoader to use for resolution.
- mirror::Class* ResolveType(const DexFile& dex_file,
- dex::TypeIndex type_idx,
- ObjPtr<mirror::Class> referrer)
+ ObjPtr<mirror::Class> ResolveType(const DexFile& dex_file,
+ dex::TypeIndex type_idx,
+ ObjPtr<mirror::Class> referrer)
REQUIRES_SHARED(Locks::mutator_lock_)
REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_);
// Resolve a Type with the given index from the DexFile, storing the
// result in the DexCache. The referrer is used to identify the
// target DexCache and ClassLoader to use for resolution.
- mirror::Class* ResolveType(dex::TypeIndex type_idx, ArtMethod* referrer)
+ ObjPtr<mirror::Class> ResolveType(dex::TypeIndex type_idx, ArtMethod* referrer)
REQUIRES_SHARED(Locks::mutator_lock_)
REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_);
@@ -289,10 +289,10 @@
// result in DexCache. The ClassLoader is used to search for the
// type, since it may be referenced from but not contained within
// the given DexFile.
- mirror::Class* ResolveType(const DexFile& dex_file,
- dex::TypeIndex type_idx,
- Handle<mirror::DexCache> dex_cache,
- Handle<mirror::ClassLoader> class_loader)
+ ObjPtr<mirror::Class> ResolveType(const DexFile& dex_file,
+ dex::TypeIndex type_idx,
+ Handle<mirror::DexCache> dex_cache,
+ Handle<mirror::ClassLoader> class_loader)
REQUIRES_SHARED(Locks::mutator_lock_)
REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_);
diff --git a/runtime/class_linker_test.cc b/runtime/class_linker_test.cc
index 892a850..9412550 100644
--- a/runtime/class_linker_test.cc
+++ b/runtime/class_linker_test.cc
@@ -1304,10 +1304,18 @@
const DexFile::TypeId* type_id = dex_file->FindTypeId("LStaticsFromCode;");
ASSERT_TRUE(type_id != nullptr);
dex::TypeIndex type_idx = dex_file->GetIndexForTypeId(*type_id);
- mirror::Class* uninit = ResolveVerifyAndClinit(type_idx, clinit, soa.Self(), true, false);
+ ObjPtr<mirror::Class> uninit = ResolveVerifyAndClinit(type_idx,
+ clinit,
+ soa.Self(),
+ /* can_run_clinit */ true,
+ /* verify_access */ false);
EXPECT_TRUE(uninit != nullptr);
EXPECT_FALSE(uninit->IsInitialized());
- mirror::Class* init = ResolveVerifyAndClinit(type_idx, getS0, soa.Self(), true, false);
+ ObjPtr<mirror::Class> init = ResolveVerifyAndClinit(type_idx,
+ getS0,
+ soa.Self(),
+ /* can_run_clinit */ true,
+ /* verify_access */ false);
EXPECT_TRUE(init != nullptr);
EXPECT_TRUE(init->IsInitialized());
}
diff --git a/runtime/dex_file_annotations.cc b/runtime/dex_file_annotations.cc
index b44bd51..27b9202 100644
--- a/runtime/dex_file_annotations.cc
+++ b/runtime/dex_file_annotations.cc
@@ -783,9 +783,8 @@
uint32_t type_index = DecodeUnsignedLeb128(&annotation);
ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
Thread* self = Thread::Current();
- mirror::Class* resolved_class;
StackHandleScope<2> hs(self);
- resolved_class = class_linker->ResolveType(
+ ObjPtr<mirror::Class> resolved_class = class_linker->ResolveType(
klass.GetDexFile(),
dex::TypeIndex(type_index),
hs.NewHandle(klass.GetDexCache()),
@@ -1594,17 +1593,17 @@
case kDouble: field->SetDouble<kTransactionActive>(field->GetDeclaringClass(), jval_.d); break;
case kNull: field->SetObject<kTransactionActive>(field->GetDeclaringClass(), nullptr); break;
case kString: {
- mirror::String* resolved = linker_->ResolveString(dex_file_,
- dex::StringIndex(jval_.i),
- *dex_cache_);
+ ObjPtr<mirror::String> resolved = linker_->ResolveString(dex_file_,
+ dex::StringIndex(jval_.i),
+ *dex_cache_);
field->SetObject<kTransactionActive>(field->GetDeclaringClass(), resolved);
break;
}
case kType: {
- mirror::Class* resolved = linker_->ResolveType(dex_file_,
- dex::TypeIndex(jval_.i),
- *dex_cache_,
- *class_loader_);
+ ObjPtr<mirror::Class> resolved = linker_->ResolveType(dex_file_,
+ dex::TypeIndex(jval_.i),
+ *dex_cache_,
+ *class_loader_);
field->SetObject<kTransactionActive>(field->GetDeclaringClass(), resolved);
break;
}
diff --git a/runtime/entrypoints/entrypoint_utils-inl.h b/runtime/entrypoints/entrypoint_utils-inl.h
index 8253739..475c1e7 100644
--- a/runtime/entrypoints/entrypoint_utils-inl.h
+++ b/runtime/entrypoints/entrypoint_utils-inl.h
@@ -245,7 +245,7 @@
*slow_path = true;
return nullptr; // Failure
}
- mirror::Class* klass = method->GetDexCache()->GetResolvedType(type_idx);
+ ObjPtr<mirror::Class> klass = method->GetDexCache()->GetResolvedType(type_idx);
if (UNLIKELY(klass == nullptr)) { // Not in dex cache so try to resolve
ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
klass = class_linker->ResolveType(type_idx, method);
@@ -264,7 +264,7 @@
return nullptr; // Failure
}
}
- return klass;
+ return klass.Ptr();
}
// Given the context of a calling Method, use its DexCache to resolve a type to an array Class. If
@@ -500,7 +500,8 @@
Handle<mirror::Class> h_referring_class(hs2.NewHandle(referrer->GetDeclaringClass()));
const dex::TypeIndex method_type_idx =
referrer->GetDexFile()->GetMethodId(method_idx).class_idx_;
- mirror::Class* method_reference_class = class_linker->ResolveType(method_type_idx, referrer);
+ ObjPtr<mirror::Class> method_reference_class =
+ class_linker->ResolveType(method_type_idx, referrer);
if (UNLIKELY(method_reference_class == nullptr)) {
// Bad type idx.
CHECK(self->IsExceptionPending());
@@ -711,13 +712,13 @@
}
}
-inline mirror::Class* ResolveVerifyAndClinit(dex::TypeIndex type_idx,
- ArtMethod* referrer,
- Thread* self,
- bool can_run_clinit,
- bool verify_access) {
+inline ObjPtr<mirror::Class> ResolveVerifyAndClinit(dex::TypeIndex type_idx,
+ ArtMethod* referrer,
+ Thread* self,
+ bool can_run_clinit,
+ bool verify_access) {
ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
- mirror::Class* klass = class_linker->ResolveType(type_idx, referrer);
+ ObjPtr<mirror::Class> klass = class_linker->ResolveType(type_idx, referrer);
if (UNLIKELY(klass == nullptr)) {
CHECK(self->IsExceptionPending());
return nullptr; // Failure - Indicate to caller to deliver exception
@@ -748,9 +749,9 @@
return h_class.Get();
}
-static inline mirror::String* ResolveString(ClassLinker* class_linker,
- dex::StringIndex string_idx,
- ArtMethod* referrer)
+static inline ObjPtr<mirror::String> ResolveString(ClassLinker* class_linker,
+ dex::StringIndex string_idx,
+ ArtMethod* referrer)
REQUIRES_SHARED(Locks::mutator_lock_) {
Thread::PoisonObjectPointersIfDebug();
ObjPtr<mirror::String> string = referrer->GetDexCache()->GetResolvedString(string_idx);
@@ -760,10 +761,11 @@
const DexFile& dex_file = *dex_cache->GetDexFile();
string = class_linker->ResolveString(dex_file, string_idx, dex_cache);
}
- return string.Ptr();
+ return string;
}
-inline mirror::String* ResolveStringFromCode(ArtMethod* referrer, dex::StringIndex string_idx) {
+inline ObjPtr<mirror::String> ResolveStringFromCode(ArtMethod* referrer,
+ dex::StringIndex string_idx) {
Thread::PoisonObjectPointersIfDebug();
ObjPtr<mirror::String> string = referrer->GetDexCache()->GetResolvedString(string_idx);
if (UNLIKELY(string == nullptr)) {
@@ -773,7 +775,7 @@
ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
string = class_linker->ResolveString(dex_file, string_idx, dex_cache);
}
- return string.Ptr();
+ return string;
}
inline void UnlockJniSynchronizedMethod(jobject locked, Thread* self) {
diff --git a/runtime/entrypoints/entrypoint_utils.h b/runtime/entrypoints/entrypoint_utils.h
index cda70ea..830ef84 100644
--- a/runtime/entrypoints/entrypoint_utils.h
+++ b/runtime/entrypoints/entrypoint_utils.h
@@ -143,15 +143,16 @@
ArtMethod* referrer)
REQUIRES_SHARED(Locks::mutator_lock_);
-inline mirror::Class* ResolveVerifyAndClinit(dex::TypeIndex type_idx,
- ArtMethod* referrer,
- Thread* self,
- bool can_run_clinit,
- bool verify_access)
+inline ObjPtr<mirror::Class> ResolveVerifyAndClinit(dex::TypeIndex type_idx,
+ ArtMethod* referrer,
+ Thread* self,
+ bool can_run_clinit,
+ bool verify_access)
REQUIRES_SHARED(Locks::mutator_lock_)
REQUIRES(!Roles::uninterruptible_);
-inline mirror::String* ResolveStringFromCode(ArtMethod* referrer, dex::StringIndex string_idx)
+inline ObjPtr<mirror::String> ResolveStringFromCode(ArtMethod* referrer,
+ dex::StringIndex string_idx)
REQUIRES_SHARED(Locks::mutator_lock_)
REQUIRES(!Roles::uninterruptible_);
diff --git a/runtime/entrypoints/quick/quick_dexcache_entrypoints.cc b/runtime/entrypoints/quick/quick_dexcache_entrypoints.cc
index 238ada9..9837838 100644
--- a/runtime/entrypoints/quick/quick_dexcache_entrypoints.cc
+++ b/runtime/entrypoints/quick/quick_dexcache_entrypoints.cc
@@ -138,15 +138,15 @@
auto caller_and_outer = GetCalleeSaveMethodCallerAndOuterMethod(
self, CalleeSaveType::kSaveEverythingForClinit);
ArtMethod* caller = caller_and_outer.caller;
- mirror::Class* result = ResolveVerifyAndClinit(dex::TypeIndex(type_idx),
- caller,
- self,
- /* can_run_clinit */ true,
- /* verify_access */ false);
+ ObjPtr<mirror::Class> result = ResolveVerifyAndClinit(dex::TypeIndex(type_idx),
+ caller,
+ self,
+ /* can_run_clinit */ true,
+ /* verify_access */ false);
if (LIKELY(result != nullptr) && CanReferenceBss(caller_and_outer.outer_method, caller)) {
StoreTypeInBss(caller_and_outer.outer_method, dex::TypeIndex(type_idx), result);
}
- return result;
+ return result.Ptr();
}
extern "C" mirror::Class* artInitializeTypeFromCode(uint32_t type_idx, Thread* self)
@@ -156,15 +156,15 @@
auto caller_and_outer = GetCalleeSaveMethodCallerAndOuterMethod(
self, CalleeSaveType::kSaveEverythingForClinit);
ArtMethod* caller = caller_and_outer.caller;
- mirror::Class* result = ResolveVerifyAndClinit(dex::TypeIndex(type_idx),
- caller,
- self,
- /* can_run_clinit */ false,
- /* verify_access */ false);
+ ObjPtr<mirror::Class> result = ResolveVerifyAndClinit(dex::TypeIndex(type_idx),
+ caller,
+ self,
+ /* can_run_clinit */ false,
+ /* verify_access */ false);
if (LIKELY(result != nullptr) && CanReferenceBss(caller_and_outer.outer_method, caller)) {
StoreTypeInBss(caller_and_outer.outer_method, dex::TypeIndex(type_idx), result);
}
- return result;
+ return result.Ptr();
}
extern "C" mirror::Class* artInitializeTypeAndVerifyAccessFromCode(uint32_t type_idx, Thread* self)
@@ -174,13 +174,13 @@
auto caller_and_outer = GetCalleeSaveMethodCallerAndOuterMethod(self,
CalleeSaveType::kSaveEverything);
ArtMethod* caller = caller_and_outer.caller;
- mirror::Class* result = ResolveVerifyAndClinit(dex::TypeIndex(type_idx),
- caller,
- self,
- /* can_run_clinit */ false,
- /* verify_access */ true);
+ ObjPtr<mirror::Class> result = ResolveVerifyAndClinit(dex::TypeIndex(type_idx),
+ caller,
+ self,
+ /* can_run_clinit */ false,
+ /* verify_access */ true);
// Do not StoreTypeInBss(); access check entrypoint is never used together with .bss.
- return result;
+ return result.Ptr();
}
extern "C" mirror::String* artResolveStringFromCode(int32_t string_idx, Thread* self)
@@ -189,11 +189,11 @@
auto caller_and_outer = GetCalleeSaveMethodCallerAndOuterMethod(self,
CalleeSaveType::kSaveEverything);
ArtMethod* caller = caller_and_outer.caller;
- mirror::String* result = ResolveStringFromCode(caller, dex::StringIndex(string_idx));
+ ObjPtr<mirror::String> result = ResolveStringFromCode(caller, dex::StringIndex(string_idx));
if (LIKELY(result != nullptr) && CanReferenceBss(caller_and_outer.outer_method, caller)) {
StoreStringInBss(caller_and_outer.outer_method, dex::StringIndex(string_idx), result);
}
- return result;
+ return result.Ptr();
}
} // namespace art
diff --git a/runtime/interpreter/mterp/mterp.cc b/runtime/interpreter/mterp/mterp.cc
index 987298b..9c7645a 100644
--- a/runtime/interpreter/mterp/mterp.cc
+++ b/runtime/interpreter/mterp/mterp.cc
@@ -376,15 +376,15 @@
ShadowFrame* shadow_frame,
Thread* self)
REQUIRES_SHARED(Locks::mutator_lock_) {
- mirror::Class* c = ResolveVerifyAndClinit(dex::TypeIndex(index),
- shadow_frame->GetMethod(),
- self,
- false,
- false);
+ ObjPtr<mirror::Class> c = ResolveVerifyAndClinit(dex::TypeIndex(index),
+ shadow_frame->GetMethod(),
+ self,
+ /* can_run_clinit */ false,
+ /* verify_access */ false);
if (UNLIKELY(c == nullptr)) {
return true;
}
- shadow_frame->SetVRegReference(tgt_vreg, c);
+ shadow_frame->SetVRegReference(tgt_vreg, c.Ptr());
return false;
}
@@ -463,17 +463,17 @@
REQUIRES_SHARED(Locks::mutator_lock_) {
const Instruction* inst = Instruction::At(shadow_frame->GetDexPCPtr());
mirror::Object* obj = nullptr;
- mirror::Class* c = ResolveVerifyAndClinit(dex::TypeIndex(inst->VRegB_21c()),
- shadow_frame->GetMethod(),
- self,
- false,
- false);
+ ObjPtr<mirror::Class> c = ResolveVerifyAndClinit(dex::TypeIndex(inst->VRegB_21c()),
+ shadow_frame->GetMethod(),
+ self,
+ /* can_run_clinit */ false,
+ /* verify_access */ false);
if (LIKELY(c != nullptr)) {
if (UNLIKELY(c->IsStringClass())) {
gc::AllocatorType allocator_type = Runtime::Current()->GetHeap()->GetCurrentAllocator();
obj = mirror::String::AllocEmptyString<true>(self, allocator_type);
} else {
- obj = AllocObjectFromCode<true>(c,
+ obj = AllocObjectFromCode<true>(c.Ptr(),
self,
Runtime::Current()->GetHeap()->GetCurrentAllocator());
}
diff --git a/runtime/transaction_test.cc b/runtime/transaction_test.cc
index e52dd08..f922dd3 100644
--- a/runtime/transaction_test.cc
+++ b/runtime/transaction_test.cc
@@ -502,10 +502,11 @@
ASSERT_TRUE(h_klass->IsInitialized());
// Make sure the string got resolved by the transaction.
{
- mirror::String* s = class_linker_->LookupString(*dex_file, string_idx, h_dex_cache.Get());
+ ObjPtr<mirror::String> s =
+ class_linker_->LookupString(*dex_file, string_idx, h_dex_cache.Get());
ASSERT_TRUE(s != nullptr);
EXPECT_STREQ(s->ToModifiedUtf8().c_str(), kResolvedString);
- EXPECT_EQ(s, h_dex_cache->GetResolvedString(string_idx));
+ EXPECT_EQ(s.Ptr(), h_dex_cache->GetResolvedString(string_idx));
}
Runtime::Current()->RollbackAndExitTransactionMode();
// Check that the string did not stay resolved.
diff --git a/runtime/verifier/method_verifier.cc b/runtime/verifier/method_verifier.cc
index fefb4f6..b6b152f 100644
--- a/runtime/verifier/method_verifier.cc
+++ b/runtime/verifier/method_verifier.cc
@@ -1074,9 +1074,9 @@
// Ensure exception types are resolved so that they don't need resolution to be delivered,
// unresolved exception types will be ignored by exception delivery
if (iterator.GetHandlerTypeIndex().IsValid()) {
- mirror::Class* exception_type = linker->ResolveType(*dex_file_,
- iterator.GetHandlerTypeIndex(),
- dex_cache_, class_loader_);
+ ObjPtr<mirror::Class> exception_type = linker->ResolveType(*dex_file_,
+ iterator.GetHandlerTypeIndex(),
+ dex_cache_, class_loader_);
if (exception_type == nullptr) {
DCHECK(self_->IsExceptionPending());
self_->ClearException();
@@ -3639,8 +3639,8 @@
has_catch_all_handler = true;
} else {
// It is also a catch-all if it is java.lang.Throwable.
- mirror::Class* klass = linker->ResolveType(*dex_file_, handler_type_idx, dex_cache_,
- class_loader_);
+ ObjPtr<mirror::Class> klass =
+ linker->ResolveType(*dex_file_, handler_type_idx, dex_cache_, class_loader_);
if (klass != nullptr) {
if (klass == mirror::Throwable::GetJavaLangThrowable()) {
has_catch_all_handler = true;
@@ -3758,16 +3758,16 @@
<< "non-instantiable klass " << descriptor;
}
-inline bool MethodVerifier::IsInstantiableOrPrimitive(mirror::Class* klass) {
+inline bool MethodVerifier::IsInstantiableOrPrimitive(ObjPtr<mirror::Class> klass) {
return klass->IsInstantiable() || klass->IsPrimitive();
}
template <MethodVerifier::CheckAccess C>
const RegType& MethodVerifier::ResolveClass(dex::TypeIndex class_idx) {
- mirror::Class* klass = can_load_classes_
+ ObjPtr<mirror::Class> klass = can_load_classes_
? Runtime::Current()->GetClassLinker()->ResolveType(
*dex_file_, class_idx, dex_cache_, class_loader_)
- : ClassLinker::LookupResolvedType(class_idx, dex_cache_.Get(), class_loader_.Get()).Ptr();
+ : ClassLinker::LookupResolvedType(class_idx, dex_cache_.Get(), class_loader_.Get());
if (can_load_classes_ && klass == nullptr) {
DCHECK(self_->IsExceptionPending());
self_->ClearException();
@@ -3780,10 +3780,10 @@
UninstantiableError(descriptor);
precise = false;
}
- result = reg_types_.FindClass(klass, precise);
+ result = reg_types_.FindClass(klass.Ptr(), precise);
if (result == nullptr) {
const char* descriptor = dex_file_->StringByTypeIdx(class_idx);
- result = reg_types_.InsertClass(descriptor, klass, precise);
+ result = reg_types_.InsertClass(descriptor, klass.Ptr(), precise);
}
} else {
const char* descriptor = dex_file_->StringByTypeIdx(class_idx);
@@ -3798,7 +3798,7 @@
}
// Record result of class resolution attempt.
- VerifierDeps::MaybeRecordClassResolution(*dex_file_, class_idx, klass);
+ VerifierDeps::MaybeRecordClassResolution(*dex_file_, class_idx, klass.Ptr());
// If requested, check if access is allowed. Unresolved types are included in this check, as the
// interpreter only tests whether access is allowed when a class is not pre-verified and runs in
diff --git a/runtime/verifier/method_verifier.h b/runtime/verifier/method_verifier.h
index c885914..f26f3e2 100644
--- a/runtime/verifier/method_verifier.h
+++ b/runtime/verifier/method_verifier.h
@@ -257,7 +257,8 @@
REQUIRES_SHARED(Locks::mutator_lock_);
void UninstantiableError(const char* descriptor);
- static bool IsInstantiableOrPrimitive(mirror::Class* klass) REQUIRES_SHARED(Locks::mutator_lock_);
+ static bool IsInstantiableOrPrimitive(ObjPtr<mirror::Class> klass)
+ REQUIRES_SHARED(Locks::mutator_lock_);
// Is the method being verified a constructor? See the comment on the field.
bool IsConstructor() const {