blob: 0ef2964e3590c67754d1109527e0d845073380a9 [file] [log] [blame]
Sebastien Hertz7cde48c2015-01-20 16:06:43 +01001/*
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_)
Nicolas Geoffray8e5bd182015-05-06 11:34:34 +010032 : StackVisitor(thread, context, StackVisitor::StackWalkKind::kIncludeInlinedFrames),
33 this_value_(this_value),
34 found_method_index_(0) {}
Sebastien Hertz7cde48c2015-01-20 16:06:43 +010035
36 bool VisitFrame() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
37 mirror::ArtMethod* m = GetMethod();
38 std::string m_name(m->GetName());
39
40 if (m_name.compare("testSimpleVReg") == 0) {
41 found_method_index_ = 1;
42 uint32_t value = 0;
43
44 CHECK(GetVReg(m, 0, kIntVReg, &value));
45 CHECK_EQ(value, 42u);
46
47 bool success = GetVReg(m, 1, kIntVReg, &value);
48 if (m->IsOptimized(sizeof(void*))) CHECK(!success);
49
50 success = GetVReg(m, 2, kIntVReg, &value);
51 if (m->IsOptimized(sizeof(void*))) CHECK(!success);
52
53 CHECK(GetVReg(m, 3, kReferenceVReg, &value));
54 CHECK_EQ(reinterpret_cast<mirror::Object*>(value), this_value_);
55
56 CHECK(GetVReg(m, 4, kIntVReg, &value));
57 CHECK_EQ(value, 1u);
58
59 CHECK(GetVReg(m, 5, kFloatVReg, &value));
Roland Levillainda4d79b2015-03-24 14:36:11 +000060 uint32_t cast = bit_cast<uint32_t, float>(1.0f);
Sebastien Hertz7cde48c2015-01-20 16:06:43 +010061 CHECK_EQ(value, cast);
62
63 CHECK(GetVReg(m, 6, kIntVReg, &value));
64 CHECK_EQ(value, 2u);
65
66 CHECK(GetVReg(m, 7, kIntVReg, &value));
67 CHECK_EQ(value, true);
68
69 CHECK(GetVReg(m, 8, kIntVReg, &value));
70 CHECK_EQ(value, 3u);
71
72 CHECK(GetVReg(m, 9, kIntVReg, &value));
73 CHECK_EQ(value, static_cast<uint32_t>('c'));
74 } else if (m_name.compare("testPairVReg") == 0) {
75 found_method_index_ = 2;
76 uint64_t value = 0;
77 CHECK(GetVRegPair(m, 0, kLongLoVReg, kLongHiVReg, &value));
78 CHECK_EQ(value, 42u);
79
80 bool success = GetVRegPair(m, 2, kLongLoVReg, kLongHiVReg, &value);
81 if (m->IsOptimized(sizeof(void*))) CHECK(!success);
82
83 success = GetVRegPair(m, 4, kLongLoVReg, kLongHiVReg, &value);
84 if (m->IsOptimized(sizeof(void*))) CHECK(!success);
85
86 uint32_t value32 = 0;
87 CHECK(GetVReg(m, 6, kReferenceVReg, &value32));
88 CHECK_EQ(reinterpret_cast<mirror::Object*>(value32), this_value_);
89
90 CHECK(GetVRegPair(m, 7, kLongLoVReg, kLongHiVReg, &value));
91 CHECK_EQ(static_cast<int64_t>(value), std::numeric_limits<int64_t>::min());
92
93 CHECK(GetVRegPair(m, 9, kLongLoVReg, kLongHiVReg, &value));
94 CHECK_EQ(static_cast<int64_t>(value), std::numeric_limits<int64_t>::max());
95
96 CHECK(GetVRegPair(m, 11, kLongLoVReg, kLongHiVReg, &value));
97 CHECK_EQ(value, 0u);
98
99 CHECK(GetVRegPair(m, 13, kDoubleLoVReg, kDoubleHiVReg, &value));
Roland Levillainda4d79b2015-03-24 14:36:11 +0000100 uint64_t cast = bit_cast<uint64_t, double>(2.0);
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100101 CHECK_EQ(value, cast);
102 }
103
104 return true;
105 }
106
107 mirror::Object* this_value_;
108
109 // Value returned to Java to ensure the methods testSimpleVReg and testPairVReg
110 // have been found and tested.
111 jint found_method_index_;
112};
113
114extern "C" JNIEXPORT jint JNICALL Java_Main_doNativeCall(JNIEnv*, jobject value) {
115 ScopedObjectAccess soa(Thread::Current());
116 std::unique_ptr<Context> context(Context::Create());
117 TestVisitor visitor(soa.Self(), context.get(), soa.Decode<mirror::Object*>(value));
118 visitor.WalkStack();
119 return visitor.found_method_index_;
120}
121
122} // namespace
123
124} // namespace art