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" |
Nicolas Geoffray | d8126be | 2015-03-27 10:22:41 +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 | d8126be | 2015-03-27 10:22:41 +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: |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 31 | TestVisitor(Thread* thread, Context* context) REQUIRES_SHARED(Locks::mutator_lock_) |
Nicolas Geoffray | 8e5bd18 | 2015-05-06 11:34:34 +0100 | [diff] [blame] | 32 | : StackVisitor(thread, context, StackVisitor::StackWalkKind::kIncludeInlinedFrames) {} |
Nicolas Geoffray | d8126be | 2015-03-27 10:22:41 +0000 | [diff] [blame] | 33 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 34 | bool VisitFrame() REQUIRES_SHARED(Locks::mutator_lock_) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 35 | ArtMethod* m = GetMethod(); |
Nicolas Geoffray | d8126be | 2015-03-27 10:22:41 +0000 | [diff] [blame] | 36 | std::string m_name(m->GetName()); |
| 37 | |
| 38 | if (m_name.compare("testLiveArgument") == 0) { |
| 39 | found_method_ = true; |
| 40 | uint32_t value = 0; |
| 41 | CHECK(GetVReg(m, 0, kIntVReg, &value)); |
| 42 | CHECK_EQ(value, 42u); |
Nicolas Geoffray | 5949fa0 | 2015-12-18 10:57:10 +0000 | [diff] [blame] | 43 | } else if (m_name.compare("$opt$noinline$testIntervalHole") == 0) { |
| 44 | uint32_t number_of_dex_registers = m->GetCodeItem()->registers_size_; |
| 45 | uint32_t dex_register_of_first_parameter = number_of_dex_registers - 2; |
Nicolas Geoffray | d8126be | 2015-03-27 10:22:41 +0000 | [diff] [blame] | 46 | found_method_ = true; |
| 47 | uint32_t value = 0; |
Nicolas Geoffray | 1920c10 | 2015-09-29 18:00:03 +0000 | [diff] [blame] | 48 | if (GetCurrentQuickFrame() != nullptr && |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 49 | GetCurrentOatQuickMethodHeader()->IsOptimized() && |
Nicolas Geoffray | a0619e2 | 2016-12-20 13:57:43 +0000 | [diff] [blame] | 50 | !Runtime::Current()->IsJavaDebuggable()) { |
Nicolas Geoffray | 5949fa0 | 2015-12-18 10:57:10 +0000 | [diff] [blame] | 51 | CHECK_EQ(GetVReg(m, dex_register_of_first_parameter, kIntVReg, &value), false); |
Nicolas Geoffray | d8126be | 2015-03-27 10:22:41 +0000 | [diff] [blame] | 52 | } else { |
Nicolas Geoffray | 5949fa0 | 2015-12-18 10:57:10 +0000 | [diff] [blame] | 53 | CHECK(GetVReg(m, dex_register_of_first_parameter, kIntVReg, &value)); |
Nicolas Geoffray | d8126be | 2015-03-27 10:22:41 +0000 | [diff] [blame] | 54 | CHECK_EQ(value, 1u); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | return true; |
| 59 | } |
| 60 | |
| 61 | // Value returned to Java to ensure the methods testSimpleVReg and testPairVReg |
| 62 | // have been found and tested. |
| 63 | bool found_method_ = false; |
| 64 | }; |
| 65 | |
| 66 | extern "C" JNIEXPORT void JNICALL Java_Main_doStaticNativeCallLiveVreg(JNIEnv*, jclass) { |
| 67 | ScopedObjectAccess soa(Thread::Current()); |
| 68 | std::unique_ptr<Context> context(Context::Create()); |
| 69 | TestVisitor visitor(soa.Self(), context.get()); |
| 70 | visitor.WalkStack(); |
| 71 | CHECK(visitor.found_method_); |
| 72 | } |
| 73 | |
| 74 | } // namespace |
| 75 | |
| 76 | } // namespace art |