Nicolas Geoffray | eb0c7d8 | 2015-11-03 16:05:38 +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" |
| 18 | #include "art_method-inl.h" |
| 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 | eb0c7d8 | 2015-11-03 16:05:38 +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(const ScopedObjectAccess& soa, Context* context, jobject expected_value) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 31 | REQUIRES_SHARED(Locks::mutator_lock_) |
Nicolas Geoffray | eb0c7d8 | 2015-11-03 16:05:38 +0000 | [diff] [blame] | 32 | : StackVisitor(soa.Self(), context, StackVisitor::StackWalkKind::kIncludeInlinedFrames), |
| 33 | expected_value_(expected_value), |
| 34 | found_(false), |
| 35 | soa_(soa) {} |
| 36 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 37 | bool VisitFrame() REQUIRES_SHARED(Locks::mutator_lock_) { |
Nicolas Geoffray | eb0c7d8 | 2015-11-03 16:05:38 +0000 | [diff] [blame] | 38 | ArtMethod* m = GetMethod(); |
| 39 | std::string m_name(m->GetName()); |
| 40 | |
| 41 | if (m_name == "testCase") { |
| 42 | found_ = true; |
| 43 | uint32_t value = 0; |
| 44 | CHECK(GetVReg(m, 1, kReferenceVReg, &value)); |
| 45 | CHECK_EQ(reinterpret_cast<mirror::Object*>(value), |
Mathieu Chartier | 1cc62e4 | 2016-10-03 18:01:28 -0700 | [diff] [blame] | 46 | soa_.Decode<mirror::Object>(expected_value_).Ptr()); |
Nicolas Geoffray | eb0c7d8 | 2015-11-03 16:05:38 +0000 | [diff] [blame] | 47 | } |
| 48 | return true; |
| 49 | } |
| 50 | |
| 51 | jobject expected_value_; |
| 52 | bool found_; |
| 53 | const ScopedObjectAccess& soa_; |
| 54 | }; |
| 55 | |
| 56 | } // namespace |
| 57 | |
| 58 | extern "C" JNIEXPORT void JNICALL Java_Main_lookForMyRegisters(JNIEnv*, jclass, jobject value) { |
| 59 | ScopedObjectAccess soa(Thread::Current()); |
| 60 | std::unique_ptr<Context> context(Context::Create()); |
| 61 | TestVisitor visitor(soa, context.get(), value); |
| 62 | visitor.WalkStack(); |
| 63 | CHECK(visitor.found_); |
| 64 | } |
| 65 | |
| 66 | } // namespace art |