diff options
author | Mathieu Chartier <mathieuc@google.com> | 2014-05-07 15:43:14 -0700 |
---|---|---|
committer | Mathieu Chartier <mathieuc@google.com> | 2014-05-13 14:45:54 -0700 |
commit | eb8167a4f4d27fce0530f6724ab8032610cd146b (patch) | |
tree | bcfeaf13ad78f2dd68466bbd0e20c71944f7e854 /runtime/native | |
parent | 6fb66a2bc4e1c0b7931101153e58714991237af7 (diff) | |
download | art-eb8167a4f4d27fce0530f6724ab8032610cd146b.zip art-eb8167a4f4d27fce0530f6724ab8032610cd146b.tar.gz art-eb8167a4f4d27fce0530f6724ab8032610cd146b.tar.bz2 |
Add Handle/HandleScope and delete SirtRef.
Delete SirtRef and replaced it with Handle. Handles are value types
which wrap around StackReference*.
Renamed StackIndirectReferenceTable to HandleScope.
Added a scoped handle wrapper which wraps around an Object** and
restores it in its destructor.
Renamed Handle::get -> Get.
Bug: 8473721
Change-Id: Idbfebd4f35af629f0f43931b7c5184b334822c7a
Diffstat (limited to 'runtime/native')
-rw-r--r-- | runtime/native/dalvik_system_DexFile.cc | 4 | ||||
-rw-r--r-- | runtime/native/dalvik_system_VMRuntime.cc | 21 | ||||
-rw-r--r-- | runtime/native/java_lang_Class.cc | 12 | ||||
-rw-r--r-- | runtime/native/java_lang_Runtime.cc | 8 | ||||
-rw-r--r-- | runtime/native/java_lang_reflect_Array.cc | 9 | ||||
-rw-r--r-- | runtime/native/java_lang_reflect_Constructor.cc | 5 | ||||
-rw-r--r-- | runtime/native/java_lang_reflect_Field.cc | 10 |
7 files changed, 39 insertions, 30 deletions
diff --git a/runtime/native/dalvik_system_DexFile.cc b/runtime/native/dalvik_system_DexFile.cc index ed1ee7a..52abaab 100644 --- a/runtime/native/dalvik_system_DexFile.cc +++ b/runtime/native/dalvik_system_DexFile.cc @@ -186,7 +186,9 @@ static jclass DexFile_defineClassNative(JNIEnv* env, jclass, jstring javaName, j ScopedObjectAccess soa(env); ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); class_linker->RegisterDexFile(*dex_file); - SirtRef<mirror::ClassLoader> class_loader(soa.Self(), soa.Decode<mirror::ClassLoader*>(javaLoader)); + StackHandleScope<1> hs(soa.Self()); + Handle<mirror::ClassLoader> class_loader( + hs.NewHandle(soa.Decode<mirror::ClassLoader*>(javaLoader))); mirror::Class* result = class_linker->DefineClass(descriptor.c_str(), class_loader, *dex_file, *dex_class_def); VLOG(class_linker) << "DexFile_defineClassNative returning " << result; diff --git a/runtime/native/dalvik_system_VMRuntime.cc b/runtime/native/dalvik_system_VMRuntime.cc index 76c5866..50a8e47 100644 --- a/runtime/native/dalvik_system_VMRuntime.cc +++ b/runtime/native/dalvik_system_VMRuntime.cc @@ -214,7 +214,7 @@ static void PreloadDexCachesStringsCallback(mirror::Object** root, void* arg, } // Based on ClassLinker::ResolveString. -static void PreloadDexCachesResolveString(SirtRef<mirror::DexCache>& dex_cache, uint32_t string_idx, +static void PreloadDexCachesResolveString(Handle<mirror::DexCache>& dex_cache, uint32_t string_idx, StringTable& strings) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { mirror::String* string = dex_cache->GetResolvedString(string_idx); @@ -260,7 +260,7 @@ static void PreloadDexCachesResolveType(mirror::DexCache* dex_cache, uint32_t ty } // Based on ClassLinker::ResolveField. -static void PreloadDexCachesResolveField(SirtRef<mirror::DexCache>& dex_cache, +static void PreloadDexCachesResolveField(Handle<mirror::DexCache>& dex_cache, uint32_t field_idx, bool is_static) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { @@ -275,9 +275,9 @@ static void PreloadDexCachesResolveField(SirtRef<mirror::DexCache>& dex_cache, return; } if (is_static) { - field = klass->FindStaticField(dex_cache.get(), field_idx); + field = klass->FindStaticField(dex_cache.Get(), field_idx); } else { - field = klass->FindInstanceField(dex_cache.get(), field_idx); + field = klass->FindInstanceField(dex_cache.Get(), field_idx); } if (field == NULL) { return; @@ -287,7 +287,7 @@ static void PreloadDexCachesResolveField(SirtRef<mirror::DexCache>& dex_cache, } // Based on ClassLinker::ResolveMethod. -static void PreloadDexCachesResolveMethod(SirtRef<mirror::DexCache>& dex_cache, +static void PreloadDexCachesResolveMethod(Handle<mirror::DexCache>& dex_cache, uint32_t method_idx, InvokeType invoke_type) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { @@ -304,14 +304,14 @@ static void PreloadDexCachesResolveMethod(SirtRef<mirror::DexCache>& dex_cache, switch (invoke_type) { case kDirect: case kStatic: - method = klass->FindDirectMethod(dex_cache.get(), method_idx); + method = klass->FindDirectMethod(dex_cache.Get(), method_idx); break; case kInterface: - method = klass->FindInterfaceMethod(dex_cache.get(), method_idx); + method = klass->FindInterfaceMethod(dex_cache.Get(), method_idx); break; case kSuper: case kVirtual: - method = klass->FindVirtualMethod(dex_cache.get(), method_idx); + method = klass->FindVirtualMethod(dex_cache.Get(), method_idx); break; default: LOG(FATAL) << "Unreachable - invocation type: " << invoke_type; @@ -434,7 +434,8 @@ static void VMRuntime_preloadDexCaches(JNIEnv* env, jobject) { for (size_t i = 0; i< boot_class_path.size(); i++) { const DexFile* dex_file = boot_class_path[i]; CHECK(dex_file != NULL); - SirtRef<mirror::DexCache> dex_cache(self, linker->FindDexCache(*dex_file)); + StackHandleScope<1> hs(self); + Handle<mirror::DexCache> dex_cache(hs.NewHandle(linker->FindDexCache(*dex_file))); if (kPreloadDexCachesStrings) { for (size_t i = 0; i < dex_cache->NumStrings(); i++) { @@ -444,7 +445,7 @@ static void VMRuntime_preloadDexCaches(JNIEnv* env, jobject) { if (kPreloadDexCachesTypes) { for (size_t i = 0; i < dex_cache->NumResolvedTypes(); i++) { - PreloadDexCachesResolveType(dex_cache.get(), i); + PreloadDexCachesResolveType(dex_cache.Get(), i); } } diff --git a/runtime/native/java_lang_Class.cc b/runtime/native/java_lang_Class.cc index 6daf9a9..b6cf7d8 100644 --- a/runtime/native/java_lang_Class.cc +++ b/runtime/native/java_lang_Class.cc @@ -62,12 +62,12 @@ static jclass Class_classForName(JNIEnv* env, jclass, jstring javaName, jboolean } std::string descriptor(DotToDescriptor(name.c_str())); - SirtRef<mirror::ClassLoader> class_loader(soa.Self(), - soa.Decode<mirror::ClassLoader*>(javaLoader)); + StackHandleScope<2> hs(soa.Self()); + Handle<mirror::ClassLoader> class_loader(hs.NewHandle(soa.Decode<mirror::ClassLoader*>(javaLoader))); ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); - SirtRef<mirror::Class> c(soa.Self(), class_linker->FindClass(soa.Self(), descriptor.c_str(), - class_loader)); - if (c.get() == nullptr) { + Handle<mirror::Class> c( + hs.NewHandle(class_linker->FindClass(soa.Self(), descriptor.c_str(), class_loader))); + if (c.Get() == nullptr) { ScopedLocalRef<jthrowable> cause(env, env->ExceptionOccurred()); env->ExceptionClear(); jthrowable cnfe = reinterpret_cast<jthrowable>(env->NewObject(WellKnownClasses::java_lang_ClassNotFoundException, @@ -79,7 +79,7 @@ static jclass Class_classForName(JNIEnv* env, jclass, jstring javaName, jboolean if (initialize) { class_linker->EnsureInitialized(c, true, true); } - return soa.AddLocalReference<jclass>(c.get()); + return soa.AddLocalReference<jclass>(c.Get()); } static jstring Class_getNameNative(JNIEnv* env, jobject javaThis) { diff --git a/runtime/native/java_lang_Runtime.cc b/runtime/native/java_lang_Runtime.cc index 636be5d..496a1b2 100644 --- a/runtime/native/java_lang_Runtime.cc +++ b/runtime/native/java_lang_Runtime.cc @@ -19,12 +19,13 @@ #include <unistd.h> #include "gc/heap.h" +#include "handle_scope-inl.h" #include "jni_internal.h" #include "mirror/class_loader.h" #include "runtime.h" #include "scoped_thread_state_change.h" #include "ScopedUtfChars.h" -#include "sirt_ref-inl.h" +#include "verify_object-inl.h" namespace art { @@ -65,8 +66,9 @@ static jstring Runtime_nativeLoad(JNIEnv* env, jclass, jstring javaFilename, job std::string detail; { ScopedObjectAccess soa(env); - SirtRef<mirror::ClassLoader> classLoader(soa.Self(), - soa.Decode<mirror::ClassLoader*>(javaLoader)); + StackHandleScope<1> hs(soa.Self()); + Handle<mirror::ClassLoader> classLoader( + hs.NewHandle(soa.Decode<mirror::ClassLoader*>(javaLoader))); JavaVMExt* vm = Runtime::Current()->GetJavaVM(); bool success = vm->LoadNativeLibrary(filename.c_str(), classLoader, &detail); if (success) { diff --git a/runtime/native/java_lang_reflect_Array.cc b/runtime/native/java_lang_reflect_Array.cc index a991818..7c6f2f3 100644 --- a/runtime/native/java_lang_reflect_Array.cc +++ b/runtime/native/java_lang_reflect_Array.cc @@ -22,21 +22,22 @@ #include "mirror/object-inl.h" #include "object_utils.h" #include "scoped_fast_native_object_access.h" -#include "sirt_ref.h" +#include "handle_scope-inl.h" namespace art { static jobject Array_createMultiArray(JNIEnv* env, jclass, jclass javaElementClass, jobject javaDimArray) { ScopedFastNativeObjectAccess soa(env); DCHECK(javaElementClass != NULL); - SirtRef<mirror::Class> element_class(soa.Self(), soa.Decode<mirror::Class*>(javaElementClass)); + StackHandleScope<2> hs(soa.Self()); + Handle<mirror::Class> element_class(hs.NewHandle(soa.Decode<mirror::Class*>(javaElementClass))); DCHECK(element_class->IsClass()); DCHECK(javaDimArray != NULL); mirror::Object* dimensions_obj = soa.Decode<mirror::Object*>(javaDimArray); DCHECK(dimensions_obj->IsArrayInstance()); DCHECK_STREQ(ClassHelper(dimensions_obj->GetClass()).GetDescriptor(), "[I"); - SirtRef<mirror::IntArray> dimensions_array(soa.Self(), - down_cast<mirror::IntArray*>(dimensions_obj)); + Handle<mirror::IntArray> dimensions_array( + hs.NewHandle(down_cast<mirror::IntArray*>(dimensions_obj))); mirror::Array* new_array = mirror::Array::CreateMultiArray(soa.Self(), element_class, dimensions_array); return soa.AddLocalReference<jobject>(new_array); diff --git a/runtime/native/java_lang_reflect_Constructor.cc b/runtime/native/java_lang_reflect_Constructor.cc index 2445b53..1981bfd 100644 --- a/runtime/native/java_lang_reflect_Constructor.cc +++ b/runtime/native/java_lang_reflect_Constructor.cc @@ -38,13 +38,14 @@ static jobject Constructor_newInstance(JNIEnv* env, jobject javaMethod, jobjectA jboolean accessible) { ScopedFastNativeObjectAccess soa(env); mirror::ArtMethod* m = mirror::ArtMethod::FromReflectedMethod(soa, javaMethod); - SirtRef<mirror::Class> c(soa.Self(), m->GetDeclaringClass()); + StackHandleScope<1> hs(soa.Self()); + Handle<mirror::Class> c(hs.NewHandle(m->GetDeclaringClass())); if (UNLIKELY(c->IsAbstract())) { ThrowLocation throw_location = soa.Self()->GetCurrentLocationForThrow(); soa.Self()->ThrowNewExceptionF(throw_location, "Ljava/lang/InstantiationException;", "Can't instantiate %s %s", c->IsInterface() ? "interface" : "abstract class", - PrettyDescriptor(c.get()).c_str()); + PrettyDescriptor(c.Get()).c_str()); return nullptr; } diff --git a/runtime/native/java_lang_reflect_Field.cc b/runtime/native/java_lang_reflect_Field.cc index ce622d9..0d54772 100644 --- a/runtime/native/java_lang_reflect_Field.cc +++ b/runtime/native/java_lang_reflect_Field.cc @@ -94,13 +94,14 @@ static bool CheckReceiver(const ScopedFastNativeObjectAccess& soa, jobject j_rcv SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { soa.Self()->AssertThreadSuspensionIsAllowable(); if (f->IsStatic()) { - SirtRef<mirror::Class> sirt_klass(soa.Self(), f->GetDeclaringClass()); - if (UNLIKELY(!Runtime::Current()->GetClassLinker()->EnsureInitialized(sirt_klass, true, true))) { + StackHandleScope<1> hs(soa.Self()); + Handle<mirror::Class> h_klass(hs.NewHandle(f->GetDeclaringClass())); + if (UNLIKELY(!Runtime::Current()->GetClassLinker()->EnsureInitialized(h_klass, true, true))) { DCHECK(soa.Self()->IsExceptionPending()); *class_or_rcvr = nullptr; return false; } - *class_or_rcvr = sirt_klass.get(); + *class_or_rcvr = h_klass.Get(); return true; } @@ -271,7 +272,8 @@ static void Field_set(JNIEnv* env, jobject javaField, jobject javaObj, jobject j const char* field_type_desciptor = fh.GetTypeDescriptor(); field_prim_type = Primitive::GetType(field_type_desciptor[0]); if (field_prim_type == Primitive::kPrimNot) { - SirtRef<mirror::Object> sirt_obj(soa.Self(), o); + StackHandleScope<1> hs(soa.Self()); + HandleWrapper<mirror::Object> h(hs.NewHandleWrapper(&o)); // May cause resolution. CHECK(!kMovingFields) << "Resolution may trigger thread suspension"; field_type = fh.GetType(true); |