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