blob: 80abb3b40629bb235c51a01cfdb5acaba24ac174 [file] [log] [blame]
Nicolas Geoffraye0fe7ae2015-03-09 10:02:49 +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"
Mathieu Chartiere401d142015-04-22 13:56:20 -070018#include "art_method-inl.h"
Nicolas Geoffraye0fe7ae2015-03-09 10:02:49 +000019#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"
Nicolas Geoffraye0fe7ae2015-03-09 10:02:49 +000022#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)
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) {}
Nicolas Geoffraye0fe7ae2015-03-09 10:02:49 +000034
Andreas Gampefa6a1b02018-09-07 08:11:55 -070035 bool VisitFrame() override REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartiere401d142015-04-22 13:56:20 -070036 ArtMethod* m = GetMethod();
Nicolas Geoffraye0fe7ae2015-03-09 10:02:49 +000037 std::string m_name(m->GetName());
38
39 if (m_name.compare("mergeOk") == 0) {
40 uint32_t value = 0;
41
42 CHECK(GetVReg(m, 0, kIntVReg, &value));
43 CHECK_EQ(value, 0u);
44
45 CHECK(GetVReg(m, 1, kIntVReg, &value));
46 CHECK_EQ(value, 1u);
47
48 CHECK(GetVReg(m, 2, kIntVReg, &value));
49 CHECK_EQ(value, 2u);
50
51 CHECK(GetVReg(m, 3, kIntVReg, &value));
52 CHECK_EQ(value, 1u);
53
54 CHECK(GetVReg(m, 4, kIntVReg, &value));
55 CHECK_EQ(value, 2u);
56 did_check_ = true;
57 } else if (m_name.compare("mergeNotOk") == 0) {
58 uint32_t value = 0;
59
60 CHECK(GetVReg(m, 0, kIntVReg, &value));
61 CHECK_EQ(value, 0u);
62
63 CHECK(GetVReg(m, 1, kIntVReg, &value));
64 CHECK_EQ(value, 1u);
65
66 bool success = GetVReg(m, 2, kIntVReg, &value);
Andreas Gampee4d4cd22016-11-29 16:52:33 -080067 if (!IsShadowFrame() && GetCurrentOatQuickMethodHeader()->IsOptimized()) {
Nicolas Geoffray6bc43742015-10-12 18:11:10 +010068 CHECK(!success);
69 }
Nicolas Geoffraye0fe7ae2015-03-09 10:02:49 +000070
Sebastien Hertz09687442015-11-17 10:35:39 +010071 CHECK(GetVReg(m, 3, kIntVReg, &value));
Nicolas Geoffraye0fe7ae2015-03-09 10:02:49 +000072 CHECK_EQ(value, 1u);
73
74 CHECK(GetVReg(m, 4, kFloatVReg, &value));
Roland Levillainda4d79b2015-03-24 14:36:11 +000075 uint32_t cast = bit_cast<uint32_t, float>(4.0f);
Nicolas Geoffraye0fe7ae2015-03-09 10:02:49 +000076 CHECK_EQ(value, cast);
77 did_check_ = true;
78 } else if (m_name.compare("phiEquivalent") == 0) {
79 uint32_t value = 0;
80
81 CHECK(GetVReg(m, 0, kIntVReg, &value));
82 // Quick doesn't like this one on x64.
83 CHECK_EQ(value, 0u);
84
85 CHECK(GetVReg(m, 1, kIntVReg, &value));
86 CHECK_EQ(value, 1u);
87
88 CHECK(GetVReg(m, 2, kFloatVReg, &value));
89 CHECK_EQ(value, 1u);
90
91 did_check_ = true;
92 } else if (m_name.compare("mergeReferences") == 0) {
93 uint32_t value = 0;
94
95 CHECK(GetVReg(m, 0, kIntVReg, &value));
96 CHECK_EQ(value, 0u);
97
98 CHECK(GetVReg(m, 1, kIntVReg, &value));
99 CHECK_EQ(value, 1u);
100
101 CHECK(GetVReg(m, 2, kReferenceVReg, &value));
102 CHECK_EQ(value, 0u);
103
104 CHECK(GetVReg(m, 3, kReferenceVReg, &value));
105 CHECK_NE(value, 0u);
106
107 did_check_ = true;
108 } else if (m_name.compare("phiAllEquivalents") == 0) {
109 uint32_t value = 0;
110
111 CHECK(GetVReg(m, 0, kIntVReg, &value));
112 CHECK_EQ(value, 0u);
113
114 CHECK(GetVReg(m, 1, kIntVReg, &value));
115 CHECK_EQ(value, 1u);
116
117 CHECK(GetVReg(m, 2, kReferenceVReg, &value));
118 CHECK_EQ(value, 0u);
119
120 did_check_ = true;
121 }
122
123 return true;
124 }
125
126 bool did_check_ = false;
127};
128
129extern "C" JNIEXPORT void JNICALL Java_PhiLiveness_regsNativeCall(
130 JNIEnv*, jclass value ATTRIBUTE_UNUSED) {
131 ScopedObjectAccess soa(Thread::Current());
132 std::unique_ptr<Context> context(Context::Create());
133 TestVisitor visitor(soa.Self(), context.get());
134 visitor.WalkStack();
135 CHECK(visitor.did_check_);
136}
137
138extern "C" JNIEXPORT void JNICALL Java_PhiLiveness_regsNativeCallWithParameters(
139 JNIEnv*, jclass value ATTRIBUTE_UNUSED, jobject main, jint int_value, jfloat float_value) {
140 ScopedObjectAccess soa(Thread::Current());
141 std::unique_ptr<Context> context(Context::Create());
Mathieu Chartier0795f232016-09-27 18:43:30 -0700142 CHECK(soa.Decode<mirror::Object>(main) == nullptr);
Nicolas Geoffraye0fe7ae2015-03-09 10:02:49 +0000143 CHECK_EQ(int_value, 0);
Roland Levillainda4d79b2015-03-24 14:36:11 +0000144 int32_t cast = bit_cast<int32_t, float>(float_value);
Nicolas Geoffraye0fe7ae2015-03-09 10:02:49 +0000145 CHECK_EQ(cast, 0);
146 TestVisitor visitor(soa.Self(), context.get());
147 visitor.WalkStack();
148 CHECK(visitor.did_check_);
149}
150
151} // namespace
152
153} // namespace art