Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [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" |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [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" |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [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, mirror::Object* this_value) |
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), |
| 34 | this_value_(this_value), |
| 35 | found_method_index_(0) {} |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 36 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 37 | bool VisitFrame() REQUIRES_SHARED(Locks::mutator_lock_) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 38 | ArtMethod* m = GetMethod(); |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 39 | 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 Gampe | e4d4cd2 | 2016-11-29 16:52:33 -0800 | [diff] [blame] | 49 | if (!IsShadowFrame() && GetCurrentOatQuickMethodHeader()->IsOptimized()) { |
Nicolas Geoffray | 6bc4374 | 2015-10-12 18:11:10 +0100 | [diff] [blame] | 50 | CHECK(!success); |
| 51 | } |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 52 | |
| 53 | success = GetVReg(m, 2, kIntVReg, &value); |
Andreas Gampe | e4d4cd2 | 2016-11-29 16:52:33 -0800 | [diff] [blame] | 54 | if (!IsShadowFrame() && GetCurrentOatQuickMethodHeader()->IsOptimized()) { |
Nicolas Geoffray | 6bc4374 | 2015-10-12 18:11:10 +0100 | [diff] [blame] | 55 | CHECK(!success); |
| 56 | } |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 57 | |
| 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 Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 65 | uint32_t cast = bit_cast<uint32_t, float>(1.0f); |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 66 | 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 Gampe | e4d4cd2 | 2016-11-29 16:52:33 -0800 | [diff] [blame] | 86 | if (!IsShadowFrame() && GetCurrentOatQuickMethodHeader()->IsOptimized()) { |
Nicolas Geoffray | 6bc4374 | 2015-10-12 18:11:10 +0100 | [diff] [blame] | 87 | CHECK(!success); |
| 88 | } |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 89 | |
| 90 | success = GetVRegPair(m, 4, kLongLoVReg, kLongHiVReg, &value); |
Andreas Gampe | e4d4cd2 | 2016-11-29 16:52:33 -0800 | [diff] [blame] | 91 | if (!IsShadowFrame() && GetCurrentOatQuickMethodHeader()->IsOptimized()) { |
Nicolas Geoffray | 6bc4374 | 2015-10-12 18:11:10 +0100 | [diff] [blame] | 92 | CHECK(!success); |
| 93 | } |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 94 | |
| 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 Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 109 | uint64_t cast = bit_cast<uint64_t, double>(2.0); |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 110 | 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 | |
| 123 | extern "C" JNIEXPORT jint JNICALL Java_Main_doNativeCall(JNIEnv*, jobject value) { |
| 124 | ScopedObjectAccess soa(Thread::Current()); |
| 125 | std::unique_ptr<Context> context(Context::Create()); |
Mathieu Chartier | 1cc62e4 | 2016-10-03 18:01:28 -0700 | [diff] [blame] | 126 | TestVisitor visitor(soa.Self(), context.get(), soa.Decode<mirror::Object>(value).Ptr()); |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 127 | visitor.WalkStack(); |
| 128 | return visitor.found_method_index_; |
| 129 | } |
| 130 | |
| 131 | } // namespace |
| 132 | |
| 133 | } // namespace art |