• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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           // For optimized non-debuggable code do not expect dex register info to be present.
38           if (stack_visitor->GetCurrentShadowFrame() == nullptr &&
39               !Runtime::Current()->IsAsyncDeoptimizeable(stack_visitor->GetOuterMethod(),
40                                                          stack_visitor->GetCurrentQuickFramePc())) {
41             return true;
42           }
43           uint32_t stack_value = 0;
44           CHECK(stack_visitor->GetVReg(m, 1, kReferenceVReg, &stack_value));
45           CHECK_EQ(reinterpret_cast<mirror::Object*>(stack_value),
46                    soa.Decode<mirror::Object>(value).Ptr());
47         }
48         return true;
49       },
50       soa.Self(),
51       context.get(),
52       art::StackVisitor::StackWalkKind::kIncludeInlinedFrames);
53   CHECK(found);
54 }
55 
56 }  // namespace art
57