blob: 5fc5464d5f71249998bcff80f4ba3757e91d6bbf [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"
Mathieu Chartiere401d142015-04-22 13:56:20 -070018#include "art_method-inl.h"
Sebastien Hertz7cde48c2015-01-20 16:06:43 +010019#include "jni.h"
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010020#include "oat_quick_method_header.h"
Mathieu Chartier0795f232016-09-27 18:43:30 -070021#include "scoped_thread_state_change-inl.h"
Sebastien Hertz7cde48c2015-01-20 16:06:43 +010022#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, mirror::Object* this_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070032 REQUIRES_SHARED(Locks::mutator_lock_)
Nicolas Geoffray8e5bd182015-05-06 11:34:34 +010033 : StackVisitor(thread, context, StackVisitor::StackWalkKind::kIncludeInlinedFrames),
34 this_value_(this_value),
35 found_method_index_(0) {}
Sebastien Hertz7cde48c2015-01-20 16:06:43 +010036
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070037 bool VisitFrame() REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartiere401d142015-04-22 13:56:20 -070038 ArtMethod* m = GetMethod();
Sebastien Hertz7cde48c2015-01-20 16:06:43 +010039 std::string m_name(m->GetName());
40
41 if (m_name.compare("testSimpleVReg") == 0) {
42 found_method_index_ = 1;
43 uint32_t value = 0;
44
45 CHECK(GetVReg(m, 0, kIntVReg, &value));
46 CHECK_EQ(value, 42u);
47
48 bool success = GetVReg(m, 1, kIntVReg, &value);
Andreas Gampee4d4cd22016-11-29 16:52:33 -080049 if (!IsShadowFrame() && GetCurrentOatQuickMethodHeader()->IsOptimized()) {
Nicolas Geoffray6bc43742015-10-12 18:11:10 +010050 CHECK(!success);
51 }
Sebastien Hertz7cde48c2015-01-20 16:06:43 +010052
53 success = GetVReg(m, 2, kIntVReg, &value);
Andreas Gampee4d4cd22016-11-29 16:52:33 -080054 if (!IsShadowFrame() && GetCurrentOatQuickMethodHeader()->IsOptimized()) {
Nicolas Geoffray6bc43742015-10-12 18:11:10 +010055 CHECK(!success);
56 }
Sebastien Hertz7cde48c2015-01-20 16:06:43 +010057
58 CHECK(GetVReg(m, 3, kReferenceVReg, &value));
59 CHECK_EQ(reinterpret_cast<mirror::Object*>(value), this_value_);
60
61 CHECK(GetVReg(m, 4, kIntVReg, &value));
62 CHECK_EQ(value, 1u);
63
64 CHECK(GetVReg(m, 5, kFloatVReg, &value));
Roland Levillainda4d79b2015-03-24 14:36:11 +000065 uint32_t cast = bit_cast<uint32_t, float>(1.0f);
Sebastien Hertz7cde48c2015-01-20 16:06:43 +010066 CHECK_EQ(value, cast);
67
68 CHECK(GetVReg(m, 6, kIntVReg, &value));
69 CHECK_EQ(value, 2u);
70
71 CHECK(GetVReg(m, 7, kIntVReg, &value));
72 CHECK_EQ(value, true);
73
74 CHECK(GetVReg(m, 8, kIntVReg, &value));
75 CHECK_EQ(value, 3u);
76
77 CHECK(GetVReg(m, 9, kIntVReg, &value));
78 CHECK_EQ(value, static_cast<uint32_t>('c'));
79 } else if (m_name.compare("testPairVReg") == 0) {
80 found_method_index_ = 2;
81 uint64_t value = 0;
82 CHECK(GetVRegPair(m, 0, kLongLoVReg, kLongHiVReg, &value));
83 CHECK_EQ(value, 42u);
84
85 bool success = GetVRegPair(m, 2, kLongLoVReg, kLongHiVReg, &value);
Andreas Gampee4d4cd22016-11-29 16:52:33 -080086 if (!IsShadowFrame() && GetCurrentOatQuickMethodHeader()->IsOptimized()) {
Nicolas Geoffray6bc43742015-10-12 18:11:10 +010087 CHECK(!success);
88 }
Sebastien Hertz7cde48c2015-01-20 16:06:43 +010089
90 success = GetVRegPair(m, 4, kLongLoVReg, kLongHiVReg, &value);
Andreas Gampee4d4cd22016-11-29 16:52:33 -080091 if (!IsShadowFrame() && GetCurrentOatQuickMethodHeader()->IsOptimized()) {
Nicolas Geoffray6bc43742015-10-12 18:11:10 +010092 CHECK(!success);
93 }
Sebastien Hertz7cde48c2015-01-20 16:06:43 +010094
95 uint32_t value32 = 0;
96 CHECK(GetVReg(m, 6, kReferenceVReg, &value32));
97 CHECK_EQ(reinterpret_cast<mirror::Object*>(value32), this_value_);
98
99 CHECK(GetVRegPair(m, 7, kLongLoVReg, kLongHiVReg, &value));
100 CHECK_EQ(static_cast<int64_t>(value), std::numeric_limits<int64_t>::min());
101
102 CHECK(GetVRegPair(m, 9, kLongLoVReg, kLongHiVReg, &value));
103 CHECK_EQ(static_cast<int64_t>(value), std::numeric_limits<int64_t>::max());
104
105 CHECK(GetVRegPair(m, 11, kLongLoVReg, kLongHiVReg, &value));
106 CHECK_EQ(value, 0u);
107
108 CHECK(GetVRegPair(m, 13, kDoubleLoVReg, kDoubleHiVReg, &value));
Roland Levillainda4d79b2015-03-24 14:36:11 +0000109 uint64_t cast = bit_cast<uint64_t, double>(2.0);
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100110 CHECK_EQ(value, cast);
111 }
112
113 return true;
114 }
115
116 mirror::Object* this_value_;
117
118 // Value returned to Java to ensure the methods testSimpleVReg and testPairVReg
119 // have been found and tested.
120 jint found_method_index_;
121};
122
123extern "C" JNIEXPORT jint JNICALL Java_Main_doNativeCall(JNIEnv*, jobject value) {
124 ScopedObjectAccess soa(Thread::Current());
125 std::unique_ptr<Context> context(Context::Create());
Mathieu Chartier1cc62e42016-10-03 18:01:28 -0700126 TestVisitor visitor(soa.Self(), context.get(), soa.Decode<mirror::Object>(value).Ptr());
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100127 visitor.WalkStack();
128 return visitor.found_method_index_;
129}
130
131} // namespace
132
133} // namespace art