Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 1 | /* |
| 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 Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 18 | #include "art_method-inl.h" |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 19 | #include "jni.h" |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 20 | #include "oat_quick_method_header.h" |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 21 | #include "scoped_thread_state_change-inl.h" |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 22 | #include "stack.h" |
| 23 | #include "thread.h" |
| 24 | |
| 25 | namespace art { |
| 26 | |
| 27 | namespace { |
| 28 | |
| 29 | class TestVisitor : public StackVisitor { |
| 30 | public: |
| 31 | TestVisitor(Thread* thread, Context* context) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 32 | REQUIRES_SHARED(Locks::mutator_lock_) |
Nicolas Geoffray | 8e5bd18 | 2015-05-06 11:34:34 +0100 | [diff] [blame] | 33 | : StackVisitor(thread, context, StackVisitor::StackWalkKind::kIncludeInlinedFrames) {} |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 34 | |
Andreas Gampe | fa6a1b0 | 2018-09-07 08:11:55 -0700 | [diff] [blame] | 35 | bool VisitFrame() override REQUIRES_SHARED(Locks::mutator_lock_) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 36 | ArtMethod* m = GetMethod(); |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 37 | 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 Gampe | e4d4cd2 | 2016-11-29 16:52:33 -0800 | [diff] [blame] | 67 | if (!IsShadowFrame() && GetCurrentOatQuickMethodHeader()->IsOptimized()) { |
Nicolas Geoffray | 6bc4374 | 2015-10-12 18:11:10 +0100 | [diff] [blame] | 68 | CHECK(!success); |
| 69 | } |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 70 | |
Sebastien Hertz | 0968744 | 2015-11-17 10:35:39 +0100 | [diff] [blame] | 71 | CHECK(GetVReg(m, 3, kIntVReg, &value)); |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 72 | CHECK_EQ(value, 1u); |
| 73 | |
| 74 | CHECK(GetVReg(m, 4, kFloatVReg, &value)); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 75 | uint32_t cast = bit_cast<uint32_t, float>(4.0f); |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 76 | 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 | |
| 129 | extern "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 | |
| 138 | extern "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 Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 142 | CHECK(soa.Decode<mirror::Object>(main) == nullptr); |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 143 | CHECK_EQ(int_value, 0); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 144 | int32_t cast = bit_cast<int32_t, float>(float_value); |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 145 | 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 |