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