blob: f0b78e1f5e865a47649955c8fc124bf25d0cfdda [file] [log] [blame]
Nicolas Geoffray915b9d02015-03-11 15:11:19 +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 "jni.h"
19#include "mirror/art_method-inl.h"
20#include "scoped_thread_state_change.h"
21#include "stack.h"
22#include "thread.h"
23
24namespace art {
25
26namespace {
27
28class TestVisitor : public StackVisitor {
29 public:
30 TestVisitor(Thread* thread, Context* context, mirror::Object* this_value)
31 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
32 : StackVisitor(thread, context), this_value_(this_value), found_method_index_(0) {}
33
34 bool VisitFrame() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
35 mirror::ArtMethod* m = GetMethod();
36 std::string m_name(m->GetName());
37
38 if (m_name.compare("testThisWithInstanceCall") == 0) {
39 found_method_index_ = 1;
40 uint32_t value = 0;
41 CHECK(GetVReg(m, 1, kReferenceVReg, &value));
42 CHECK_EQ(reinterpret_cast<mirror::Object*>(value), this_value_);
43 CHECK_EQ(GetThisObject(), this_value_);
44 } else if (m_name.compare("testThisWithStaticCall") == 0) {
45 found_method_index_ = 2;
46 uint32_t value = 0;
47 CHECK(GetVReg(m, 1, kReferenceVReg, &value));
48 } else if (m_name.compare("testParameter") == 0) {
49 found_method_index_ = 3;
50 uint32_t value = 0;
51 CHECK(GetVReg(m, 1, kReferenceVReg, &value));
52 } else if (m_name.compare("testObjectInScope") == 0) {
53 found_method_index_ = 4;
54 uint32_t value = 0;
55 CHECK(GetVReg(m, 0, kReferenceVReg, &value));
56 }
57
58 return true;
59 }
60
61 mirror::Object* this_value_;
62
63 // Value returned to Java to ensure the methods testSimpleVReg and testPairVReg
64 // have been found and tested.
65 jint found_method_index_;
66};
67
68extern "C" JNIEXPORT jint JNICALL Java_Main_doNativeCallRef(JNIEnv*, jobject value) {
69 ScopedObjectAccess soa(Thread::Current());
70 std::unique_ptr<Context> context(Context::Create());
71 TestVisitor visitor(soa.Self(), context.get(), soa.Decode<mirror::Object*>(value));
72 visitor.WalkStack();
73 return visitor.found_method_index_;
74}
75
76extern "C" JNIEXPORT jint JNICALL Java_Main_doStaticNativeCallRef(JNIEnv*, jclass) {
77 ScopedObjectAccess soa(Thread::Current());
78 std::unique_ptr<Context> context(Context::Create());
79 TestVisitor visitor(soa.Self(), context.get(), nullptr);
80 visitor.WalkStack();
81 return visitor.found_method_index_;
82}
83
84} // namespace
85
86} // namespace art