Nicolas Geoffray | d8126be | 2015-03-27 10:22:41 +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" |
David Sehr | 9e734c7 | 2018-01-04 17:56:19 -0800 | [diff] [blame] | 19 | #include "dex/code_item_accessors-inl.h" |
Nicolas Geoffray | d8126be | 2015-03-27 10:22:41 +0000 | [diff] [blame] | 20 | #include "jni.h" |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 21 | #include "oat_quick_method_header.h" |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 22 | #include "scoped_thread_state_change-inl.h" |
Nicolas Geoffray | d8126be | 2015-03-27 10:22:41 +0000 | [diff] [blame] | 23 | #include "stack.h" |
| 24 | #include "thread.h" |
| 25 | |
| 26 | namespace art { |
| 27 | |
| 28 | namespace { |
| 29 | |
| 30 | class TestVisitor : public StackVisitor { |
| 31 | public: |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 32 | TestVisitor(Thread* thread, Context* context) 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 | d8126be | 2015-03-27 10:22:41 +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 | d8126be | 2015-03-27 10:22:41 +0000 | [diff] [blame] | 37 | std::string m_name(m->GetName()); |
| 38 | |
Artem Serov | d675053 | 2018-05-30 20:07:43 +0100 | [diff] [blame] | 39 | if (m_name.compare("$noinline$testLiveArgument") == 0) { |
Nicolas Geoffray | d8126be | 2015-03-27 10:22:41 +0000 | [diff] [blame] | 40 | found_method_ = true; |
Artem Serov | d675053 | 2018-05-30 20:07:43 +0100 | [diff] [blame] | 41 | CHECK_EQ(CodeItemDataAccessor(m->DexInstructionData()).RegistersSize(), 3u); |
| 42 | CheckOptimizedOutRegLiveness(m, 1, kIntVReg, true, 42); |
Artem Serov | 2808be8 | 2018-12-20 19:15:11 +0000 | [diff] [blame] | 43 | CheckOptimizedOutRegLiveness(m, 2, kReferenceVReg); |
Artem Serov | d675053 | 2018-05-30 20:07:43 +0100 | [diff] [blame] | 44 | } else if (m_name.compare("$noinline$testIntervalHole") == 0) { |
| 45 | found_method_ = true; |
David Sehr | 0225f8e | 2018-01-31 08:52:24 +0000 | [diff] [blame] | 46 | uint32_t number_of_dex_registers = |
| 47 | CodeItemDataAccessor(m->DexInstructionData()).RegistersSize(); |
Nicolas Geoffray | 5949fa0 | 2015-12-18 10:57:10 +0000 | [diff] [blame] | 48 | uint32_t dex_register_of_first_parameter = number_of_dex_registers - 2; |
Artem Serov | d675053 | 2018-05-30 20:07:43 +0100 | [diff] [blame] | 49 | CheckOptimizedOutRegLiveness(m, dex_register_of_first_parameter, kIntVReg, true, 1); |
| 50 | } else if (m_name.compare("$noinline$testCodeSinking") == 0) { |
Nicolas Geoffray | d8126be | 2015-03-27 10:22:41 +0000 | [diff] [blame] | 51 | found_method_ = true; |
Artem Serov | d675053 | 2018-05-30 20:07:43 +0100 | [diff] [blame] | 52 | CheckOptimizedOutRegLiveness(m, 0, kReferenceVReg); |
Nicolas Geoffray | d8126be | 2015-03-27 10:22:41 +0000 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | return true; |
| 56 | } |
| 57 | |
Artem Serov | d675053 | 2018-05-30 20:07:43 +0100 | [diff] [blame] | 58 | void CheckOptimizedOutRegLiveness(ArtMethod* m, |
| 59 | uint32_t dex_reg, |
| 60 | VRegKind vreg_kind, |
| 61 | bool check_val = false, |
| 62 | uint32_t expected = 0) REQUIRES_SHARED(Locks::mutator_lock_) { |
| 63 | uint32_t value = 0; |
| 64 | if (GetCurrentQuickFrame() != nullptr && |
| 65 | GetCurrentOatQuickMethodHeader()->IsOptimized() && |
| 66 | !Runtime::Current()->IsJavaDebuggable()) { |
| 67 | CHECK_EQ(GetVReg(m, dex_reg, vreg_kind, &value), false); |
| 68 | } else { |
| 69 | CHECK(GetVReg(m, dex_reg, vreg_kind, &value)); |
| 70 | if (check_val) { |
| 71 | CHECK_EQ(value, expected); |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | // Value returned to Java to ensure the required methods have been found and tested. |
Nicolas Geoffray | d8126be | 2015-03-27 10:22:41 +0000 | [diff] [blame] | 77 | bool found_method_ = false; |
| 78 | }; |
| 79 | |
| 80 | extern "C" JNIEXPORT void JNICALL Java_Main_doStaticNativeCallLiveVreg(JNIEnv*, jclass) { |
| 81 | ScopedObjectAccess soa(Thread::Current()); |
| 82 | std::unique_ptr<Context> context(Context::Create()); |
| 83 | TestVisitor visitor(soa.Self(), context.get()); |
| 84 | visitor.WalkStack(); |
| 85 | CHECK(visitor.found_method_); |
| 86 | } |
| 87 | |
| 88 | } // namespace |
| 89 | |
| 90 | } // namespace art |