• 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 "dex/code_item_accessors-inl.h"
20 #include "jni.h"
21 #include "oat_quick_method_header.h"
22 #include "scoped_thread_state_change-inl.h"
23 #include "stack.h"
24 #include "thread.h"
25 
26 namespace art {
27 
28 namespace {
29 
30 class TestVisitor : public StackVisitor {
31  public:
TestVisitor(Thread * thread,Context * context)32   TestVisitor(Thread* thread, Context* context) REQUIRES_SHARED(Locks::mutator_lock_)
33       : StackVisitor(thread, context, StackVisitor::StackWalkKind::kIncludeInlinedFrames) {}
34 
VisitFrame()35   bool VisitFrame() REQUIRES_SHARED(Locks::mutator_lock_) {
36     ArtMethod* m = GetMethod();
37     std::string m_name(m->GetName());
38 
39     if (m_name.compare("testLiveArgument") == 0) {
40       found_method_ = true;
41       uint32_t value = 0;
42       CHECK(GetVReg(m, 0, kIntVReg, &value));
43       CHECK_EQ(value, 42u);
44     } else if (m_name.compare("$opt$noinline$testIntervalHole") == 0) {
45       uint32_t number_of_dex_registers =
46           CodeItemDataAccessor(m->DexInstructionData()).RegistersSize();
47       uint32_t dex_register_of_first_parameter = number_of_dex_registers - 2;
48       found_method_ = true;
49       uint32_t value = 0;
50       if (GetCurrentQuickFrame() != nullptr &&
51           GetCurrentOatQuickMethodHeader()->IsOptimized() &&
52           !Runtime::Current()->IsJavaDebuggable()) {
53         CHECK_EQ(GetVReg(m, dex_register_of_first_parameter, kIntVReg, &value), false);
54       } else {
55         CHECK(GetVReg(m, dex_register_of_first_parameter, kIntVReg, &value));
56         CHECK_EQ(value, 1u);
57       }
58     }
59 
60     return true;
61   }
62 
63   // Value returned to Java to ensure the methods testSimpleVReg and testPairVReg
64   // have been found and tested.
65   bool found_method_ = false;
66 };
67 
Java_Main_doStaticNativeCallLiveVreg(JNIEnv *,jclass)68 extern "C" JNIEXPORT void JNICALL Java_Main_doStaticNativeCallLiveVreg(JNIEnv*, jclass) {
69   ScopedObjectAccess soa(Thread::Current());
70   std::unique_ptr<Context> context(Context::Create());
71   TestVisitor visitor(soa.Self(), context.get());
72   visitor.WalkStack();
73   CHECK(visitor.found_method_);
74 }
75 
76 }  // namespace
77 
78 }  // namespace art
79