diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2018-04-06 10:32:39 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2018-04-06 10:32:39 +0000 |
commit | c14f54b6d328eb23763391f98dfd776a720c4f54 (patch) | |
tree | 3cb887482d4ecc5d508cdc44bedee6499e368691 /test | |
parent | ddc694267aee845c9b61779be2a5487eb65b1757 (diff) | |
parent | 252a4e49ddeff7c6977ea88dfb4f5ddf593ba826 (diff) | |
download | art-c14f54b6d328eb23763391f98dfd776a720c4f54.tar.gz art-c14f54b6d328eb23763391f98dfd776a720c4f54.tar.bz2 art-c14f54b6d328eb23763391f98dfd776a720c4f54.zip |
Merge "Fix 616-cha-unloading."
Diffstat (limited to 'test')
-rw-r--r-- | test/616-cha-unloading/cha_unload.cc | 42 |
1 files changed, 38 insertions, 4 deletions
diff --git a/test/616-cha-unloading/cha_unload.cc b/test/616-cha-unloading/cha_unload.cc index 4be3456e3d..b17be6bd07 100644 --- a/test/616-cha-unloading/cha_unload.cc +++ b/test/616-cha-unloading/cha_unload.cc @@ -19,6 +19,7 @@ #include <iostream> #include "art_method.h" +#include "class_linker.h" #include "jit/jit.h" #include "linear_alloc.h" #include "nativehelper/ScopedUtfChars.h" @@ -29,6 +30,22 @@ namespace art { namespace { +class FindPointerAllocatorVisitor : public AllocatorVisitor { + public: + explicit FindPointerAllocatorVisitor(void* ptr) : is_found(false), ptr_(ptr) {} + + bool Visit(LinearAlloc* alloc) + REQUIRES_SHARED(Locks::classlinker_classes_lock_, Locks::mutator_lock_) OVERRIDE { + is_found = alloc->Contains(ptr_); + return !is_found; + } + + bool is_found; + + private: + void* ptr_; +}; + extern "C" JNIEXPORT jlong JNICALL Java_Main_getArtMethod(JNIEnv* env, jclass, jobject java_method) { @@ -40,13 +57,30 @@ extern "C" JNIEXPORT jlong JNICALL Java_Main_getArtMethod(JNIEnv* env, extern "C" JNIEXPORT void JNICALL Java_Main_reuseArenaOfMethod(JNIEnv*, jclass, jlong art_method) { - // Create a new allocation and use it to request a specified amount of arenas. - // Hopefully one of them is a reused one, the one that covers the art_method pointer. + void* ptr = reinterpret_cast<void*>(static_cast<uintptr_t>(art_method)); + + ReaderMutexLock mu(Thread::Current(), *Locks::mutator_lock_); + ReaderMutexLock mu2(Thread::Current(), *Locks::classlinker_classes_lock_); + // Check if the arena was already implicitly reused by boot classloader. + if (Runtime::Current()->GetLinearAlloc()->Contains(ptr)) { + return; + } + + // Check if the arena was already implicitly reused by some other classloader. + FindPointerAllocatorVisitor visitor(ptr); + Runtime::Current()->GetClassLinker()->VisitAllocators(&visitor); + if (visitor.is_found) { + return; + } + + // The arena was not reused yet. Do it explicitly. + // Create a new allocation and use it to request new arenas until one of them is + // a reused one that covers the art_method pointer. std::unique_ptr<LinearAlloc> alloc(Runtime::Current()->CreateLinearAlloc()); do { - // Ask for a byte - it's sufficient to get an arena and not have issues with size. + // Ask for a byte - it's sufficient to get an arena. alloc->Alloc(Thread::Current(), 1); - } while (!alloc->Contains(reinterpret_cast<void*>(static_cast<uintptr_t>(art_method)))); + } while (!alloc->Contains(ptr)); } } // namespace |