blob: dffbfa47d861121aa1156ee2b7a626c5e86f2772 [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) {}
Sebastien Hertz7cde48c2015-01-20 16:06:43 +010034
35 bool VisitFrame() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
36 mirror::ArtMethod* m = GetMethod();
37 std::string m_name(m->GetName());
38
39 if (m_name.compare("testIntVReg") == 0) {
40 uint32_t value = 0;
41 CHECK(GetVReg(m, 1, kReferenceVReg, &value));
42 CHECK_EQ(reinterpret_cast<mirror::Object*>(value), this_value_);
43
44 CHECK(SetVReg(m, 2, 5, kIntVReg));
45 CHECK(SetVReg(m, 3, 4, kIntVReg));
46 CHECK(SetVReg(m, 4, 3, kIntVReg));
47 CHECK(SetVReg(m, 5, 2, kIntVReg));
48 CHECK(SetVReg(m, 6, 1, kIntVReg));
49 } else if (m_name.compare("testLongVReg") == 0) {
50 uint32_t value = 0;
51 CHECK(GetVReg(m, 3, kReferenceVReg, &value));
52 CHECK_EQ(reinterpret_cast<mirror::Object*>(value), this_value_);
53
54 CHECK(SetVRegPair(m, 4, std::numeric_limits<int64_t>::max(), kLongLoVReg, kLongHiVReg));
55 CHECK(SetVRegPair(m, 6, 4, kLongLoVReg, kLongHiVReg));
56 CHECK(SetVRegPair(m, 8, 3, kLongLoVReg, kLongHiVReg));
57 CHECK(SetVRegPair(m, 10, 2, kLongLoVReg, kLongHiVReg));
58 CHECK(SetVRegPair(m, 12, 1, kLongLoVReg, kLongHiVReg));
59 } else if (m_name.compare("testFloatVReg") == 0) {
60 uint32_t value = 0;
61 CHECK(GetVReg(m, 1, kReferenceVReg, &value));
62 CHECK_EQ(reinterpret_cast<mirror::Object*>(value), this_value_);
63
Roland Levillainda4d79b2015-03-24 14:36:11 +000064 CHECK(SetVReg(m, 2, bit_cast<uint32_t, float>(5.0f), kFloatVReg));
65 CHECK(SetVReg(m, 3, bit_cast<uint32_t, float>(4.0f), kFloatVReg));
66 CHECK(SetVReg(m, 4, bit_cast<uint32_t, float>(3.0f), kFloatVReg));
67 CHECK(SetVReg(m, 5, bit_cast<uint32_t, float>(2.0f), kFloatVReg));
68 CHECK(SetVReg(m, 6, bit_cast<uint32_t, float>(1.0f), kFloatVReg));
Sebastien Hertz7cde48c2015-01-20 16:06:43 +010069 } else if (m_name.compare("testDoubleVReg") == 0) {
70 uint32_t value = 0;
71 CHECK(GetVReg(m, 3, kReferenceVReg, &value));
72 CHECK_EQ(reinterpret_cast<mirror::Object*>(value), this_value_);
73
Roland Levillainda4d79b2015-03-24 14:36:11 +000074 CHECK(SetVRegPair(m, 4, bit_cast<uint64_t, double>(5.0), kDoubleLoVReg, kDoubleHiVReg));
75 CHECK(SetVRegPair(m, 6, bit_cast<uint64_t, double>(4.0), kDoubleLoVReg, kDoubleHiVReg));
76 CHECK(SetVRegPair(m, 8, bit_cast<uint64_t, double>(3.0), kDoubleLoVReg, kDoubleHiVReg));
77 CHECK(SetVRegPair(m, 10, bit_cast<uint64_t, double>(2.0), kDoubleLoVReg, kDoubleHiVReg));
78 CHECK(SetVRegPair(m, 12, bit_cast<uint64_t, double>(1.0), kDoubleLoVReg, kDoubleHiVReg));
Sebastien Hertz7cde48c2015-01-20 16:06:43 +010079 }
80
81 return true;
82 }
83
84 mirror::Object* this_value_;
85};
86
87extern "C" JNIEXPORT void JNICALL Java_Main_doNativeCallSetVReg(JNIEnv*, jobject value) {
88 ScopedObjectAccess soa(Thread::Current());
89 std::unique_ptr<Context> context(Context::Create());
90 TestVisitor visitor(soa.Self(), context.get(), soa.Decode<mirror::Object*>(value));
91 visitor.WalkStack();
92}
93
94} // namespace
95
96} // namespace art