blob: ce5602f6e1c22ef6614eb87ed74909882ddce326 [file] [log] [blame]
Nicolas Geoffrayeb0c7d82015-11-03 16:05:38 +00001/*
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 Chartier0795f232016-09-27 18:43:30 -070020#include "scoped_thread_state_change-inl.h"
Nicolas Geoffrayeb0c7d82015-11-03 16:05:38 +000021#include "stack.h"
22#include "thread.h"
23
24namespace art {
25
26namespace {
27
28class TestVisitor : public StackVisitor {
29 public:
30 TestVisitor(const ScopedObjectAccess& soa, Context* context, jobject expected_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070031 REQUIRES_SHARED(Locks::mutator_lock_)
Nicolas Geoffrayeb0c7d82015-11-03 16:05:38 +000032 : StackVisitor(soa.Self(), context, StackVisitor::StackWalkKind::kIncludeInlinedFrames),
33 expected_value_(expected_value),
34 found_(false),
35 soa_(soa) {}
36
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070037 bool VisitFrame() REQUIRES_SHARED(Locks::mutator_lock_) {
Nicolas Geoffrayeb0c7d82015-11-03 16:05:38 +000038 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 Chartier1cc62e42016-10-03 18:01:28 -070046 soa_.Decode<mirror::Object>(expected_value_).Ptr());
Nicolas Geoffrayeb0c7d82015-11-03 16:05:38 +000047 }
48 return true;
49 }
50
51 jobject expected_value_;
52 bool found_;
53 const ScopedObjectAccess& soa_;
54};
55
56} // namespace
57
58extern "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