Nicolas Geoffray | 915b9d0 | 2015-03-11 15:11:19 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "arch/context.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 18 | #include "art_method-inl.h" |
Nicolas Geoffray | 915b9d0 | 2015-03-11 15:11:19 +0000 | [diff] [blame] | 19 | #include "jni.h" |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 20 | #include "scoped_thread_state_change-inl.h" |
Nicolas Geoffray | 915b9d0 | 2015-03-11 15:11:19 +0000 | [diff] [blame] | 21 | #include "stack.h" |
| 22 | #include "thread.h" |
| 23 | |
| 24 | namespace art { |
| 25 | |
| 26 | namespace { |
| 27 | |
| 28 | class TestVisitor : public StackVisitor { |
| 29 | public: |
| 30 | TestVisitor(Thread* thread, Context* context, mirror::Object* this_value) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 31 | REQUIRES_SHARED(Locks::mutator_lock_) |
Nicolas Geoffray | 8e5bd18 | 2015-05-06 11:34:34 +0100 | [diff] [blame] | 32 | : StackVisitor(thread, context, StackVisitor::StackWalkKind::kIncludeInlinedFrames), |
| 33 | this_value_(this_value), |
| 34 | found_method_index_(0) {} |
Nicolas Geoffray | 915b9d0 | 2015-03-11 15:11:19 +0000 | [diff] [blame] | 35 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 36 | bool VisitFrame() REQUIRES_SHARED(Locks::mutator_lock_) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 37 | ArtMethod* m = GetMethod(); |
Nicolas Geoffray | 915b9d0 | 2015-03-11 15:11:19 +0000 | [diff] [blame] | 38 | std::string m_name(m->GetName()); |
| 39 | |
| 40 | if (m_name.compare("testThisWithInstanceCall") == 0) { |
| 41 | found_method_index_ = 1; |
| 42 | uint32_t value = 0; |
| 43 | CHECK(GetVReg(m, 1, kReferenceVReg, &value)); |
| 44 | CHECK_EQ(reinterpret_cast<mirror::Object*>(value), this_value_); |
| 45 | CHECK_EQ(GetThisObject(), this_value_); |
| 46 | } else if (m_name.compare("testThisWithStaticCall") == 0) { |
| 47 | found_method_index_ = 2; |
| 48 | uint32_t value = 0; |
| 49 | CHECK(GetVReg(m, 1, kReferenceVReg, &value)); |
| 50 | } else if (m_name.compare("testParameter") == 0) { |
| 51 | found_method_index_ = 3; |
| 52 | uint32_t value = 0; |
| 53 | CHECK(GetVReg(m, 1, kReferenceVReg, &value)); |
| 54 | } else if (m_name.compare("testObjectInScope") == 0) { |
| 55 | found_method_index_ = 4; |
| 56 | uint32_t value = 0; |
| 57 | CHECK(GetVReg(m, 0, kReferenceVReg, &value)); |
| 58 | } |
| 59 | |
| 60 | return true; |
| 61 | } |
| 62 | |
| 63 | mirror::Object* this_value_; |
| 64 | |
| 65 | // Value returned to Java to ensure the methods testSimpleVReg and testPairVReg |
| 66 | // have been found and tested. |
| 67 | jint found_method_index_; |
| 68 | }; |
| 69 | |
| 70 | extern "C" JNIEXPORT jint JNICALL Java_Main_doNativeCallRef(JNIEnv*, jobject value) { |
| 71 | ScopedObjectAccess soa(Thread::Current()); |
| 72 | std::unique_ptr<Context> context(Context::Create()); |
Mathieu Chartier | 1cc62e4 | 2016-10-03 18:01:28 -0700 | [diff] [blame] | 73 | TestVisitor visitor(soa.Self(), context.get(), soa.Decode<mirror::Object>(value).Ptr()); |
Nicolas Geoffray | 915b9d0 | 2015-03-11 15:11:19 +0000 | [diff] [blame] | 74 | visitor.WalkStack(); |
| 75 | return visitor.found_method_index_; |
| 76 | } |
| 77 | |
| 78 | extern "C" JNIEXPORT jint JNICALL Java_Main_doStaticNativeCallRef(JNIEnv*, jclass) { |
| 79 | ScopedObjectAccess soa(Thread::Current()); |
| 80 | std::unique_ptr<Context> context(Context::Create()); |
| 81 | TestVisitor visitor(soa.Self(), context.get(), nullptr); |
| 82 | visitor.WalkStack(); |
| 83 | return visitor.found_method_index_; |
| 84 | } |
| 85 | |
| 86 | } // namespace |
| 87 | |
| 88 | } // namespace art |