blob: 1885f8d9f5a3361b4265aacc4a634b25f88851eb [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
Nicolas Geoffrayeb0c7d82015-11-03 16:05:38 +000026extern "C" JNIEXPORT void JNICALL Java_Main_lookForMyRegisters(JNIEnv*, jclass, jobject value) {
27 ScopedObjectAccess soa(Thread::Current());
28 std::unique_ptr<Context> context(Context::Create());
Andreas Gampec7d878d2018-11-19 18:42:06 +000029 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);
Nicolas Geoffrayeb0c7d82015-11-03 16:05:38 +000048}
49
50} // namespace art