blob: 193ab9dc4ef4ad13e92e0bfcb9e7ca68c48c5d62 [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"
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)
31 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
Nicolas Geoffray8e5bd182015-05-06 11:34:34 +010032 : StackVisitor(thread, context, StackVisitor::StackWalkKind::kIncludeInlinedFrames) {}
Nicolas Geoffraye0fe7ae2015-03-09 10:02:49 +000033
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("mergeOk") == 0) {
39 uint32_t value = 0;
40
41 CHECK(GetVReg(m, 0, kIntVReg, &value));
42 CHECK_EQ(value, 0u);
43
44 CHECK(GetVReg(m, 1, kIntVReg, &value));
45 CHECK_EQ(value, 1u);
46
47 CHECK(GetVReg(m, 2, kIntVReg, &value));
48 CHECK_EQ(value, 2u);
49
50 CHECK(GetVReg(m, 3, kIntVReg, &value));
51 CHECK_EQ(value, 1u);
52
53 CHECK(GetVReg(m, 4, kIntVReg, &value));
54 CHECK_EQ(value, 2u);
55 did_check_ = true;
56 } else if (m_name.compare("mergeNotOk") == 0) {
57 uint32_t value = 0;
58
59 CHECK(GetVReg(m, 0, kIntVReg, &value));
60 CHECK_EQ(value, 0u);
61
62 CHECK(GetVReg(m, 1, kIntVReg, &value));
63 CHECK_EQ(value, 1u);
64
65 bool success = GetVReg(m, 2, kIntVReg, &value);
66 if (m->IsOptimized(sizeof(void*))) CHECK(!success);
67
68 CHECK(GetVReg(m, 3, kReferenceVReg, &value));
69 CHECK_EQ(value, 1u);
70
71 CHECK(GetVReg(m, 4, kFloatVReg, &value));
Roland Levillainda4d79b2015-03-24 14:36:11 +000072 uint32_t cast = bit_cast<uint32_t, float>(4.0f);
Nicolas Geoffraye0fe7ae2015-03-09 10:02:49 +000073 CHECK_EQ(value, cast);
74 did_check_ = true;
75 } else if (m_name.compare("phiEquivalent") == 0) {
76 uint32_t value = 0;
77
78 CHECK(GetVReg(m, 0, kIntVReg, &value));
79 // Quick doesn't like this one on x64.
80 CHECK_EQ(value, 0u);
81
82 CHECK(GetVReg(m, 1, kIntVReg, &value));
83 CHECK_EQ(value, 1u);
84
85 CHECK(GetVReg(m, 2, kFloatVReg, &value));
86 CHECK_EQ(value, 1u);
87
88 did_check_ = true;
89 } else if (m_name.compare("mergeReferences") == 0) {
90 uint32_t value = 0;
91
92 CHECK(GetVReg(m, 0, kIntVReg, &value));
93 CHECK_EQ(value, 0u);
94
95 CHECK(GetVReg(m, 1, kIntVReg, &value));
96 CHECK_EQ(value, 1u);
97
98 CHECK(GetVReg(m, 2, kReferenceVReg, &value));
99 CHECK_EQ(value, 0u);
100
101 CHECK(GetVReg(m, 3, kReferenceVReg, &value));
102 CHECK_NE(value, 0u);
103
104 did_check_ = true;
105 } else if (m_name.compare("phiAllEquivalents") == 0) {
106 uint32_t value = 0;
107
108 CHECK(GetVReg(m, 0, kIntVReg, &value));
109 CHECK_EQ(value, 0u);
110
111 CHECK(GetVReg(m, 1, kIntVReg, &value));
112 CHECK_EQ(value, 1u);
113
114 CHECK(GetVReg(m, 2, kReferenceVReg, &value));
115 CHECK_EQ(value, 0u);
116
117 did_check_ = true;
118 }
119
120 return true;
121 }
122
123 bool did_check_ = false;
124};
125
126extern "C" JNIEXPORT void JNICALL Java_PhiLiveness_regsNativeCall(
127 JNIEnv*, jclass value ATTRIBUTE_UNUSED) {
128 ScopedObjectAccess soa(Thread::Current());
129 std::unique_ptr<Context> context(Context::Create());
130 TestVisitor visitor(soa.Self(), context.get());
131 visitor.WalkStack();
132 CHECK(visitor.did_check_);
133}
134
135extern "C" JNIEXPORT void JNICALL Java_PhiLiveness_regsNativeCallWithParameters(
136 JNIEnv*, jclass value ATTRIBUTE_UNUSED, jobject main, jint int_value, jfloat float_value) {
137 ScopedObjectAccess soa(Thread::Current());
138 std::unique_ptr<Context> context(Context::Create());
139 CHECK(soa.Decode<mirror::Object*>(main) == nullptr);
140 CHECK_EQ(int_value, 0);
Roland Levillainda4d79b2015-03-24 14:36:11 +0000141 int32_t cast = bit_cast<int32_t, float>(float_value);
Nicolas Geoffraye0fe7ae2015-03-09 10:02:49 +0000142 CHECK_EQ(cast, 0);
143 TestVisitor visitor(soa.Self(), context.get());
144 visitor.WalkStack();
145 CHECK(visitor.did_check_);
146}
147
148} // namespace
149
150} // namespace art