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"
20 #include "scoped_thread_state_change-inl.h"
21 #include "stack.h"
22 #include "thread.h"
23
24 namespace art {
25
Java_Main_lookForMyRegisters(JNIEnv *,jclass,jobject value)26 extern "C" JNIEXPORT void JNICALL Java_Main_lookForMyRegisters(JNIEnv*, jclass, jobject value) {
27 ScopedObjectAccess soa(Thread::Current());
28 std::unique_ptr<Context> context(Context::Create());
29 bool found = false;
30 StackVisitor::WalkStack(
31 [&](const art::StackVisitor* stack_visitor) REQUIRES_SHARED(Locks::mutator_lock_) {
32 ArtMethod* m = stack_visitor->GetMethod();
33 std::string m_name(m->GetName());
34
35 if (m_name == "testCase") {
36 found = true;
37 uint32_t stack_value = 0;
38 CHECK(stack_visitor->GetVReg(m, 1, kReferenceVReg, &stack_value));
39 CHECK_EQ(reinterpret_cast<mirror::Object*>(stack_value),
40 soa.Decode<mirror::Object>(value).Ptr());
41 }
42 return true;
43 },
44 soa.Self(),
45 context.get(),
46 art::StackVisitor::StackWalkKind::kIncludeInlinedFrames);
47 CHECK(found);
48 }
49
50 } // namespace art
51