blob: b1fd6b550b4cfaf6233c4b1e17e55ddbbc5cd7a7 [file] [log] [blame]
Nicolas Geoffrayd8126be2015-03-27 10:22:41 +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"
Mathieu Chartiere401d142015-04-22 13:56:20 -070018#include "art_method-inl.h"
David Sehr9e734c72018-01-04 17:56:19 -080019#include "dex/code_item_accessors-inl.h"
Nicolas Geoffrayd8126be2015-03-27 10:22:41 +000020#include "jni.h"
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010021#include "oat_quick_method_header.h"
Mathieu Chartier0795f232016-09-27 18:43:30 -070022#include "scoped_thread_state_change-inl.h"
Nicolas Geoffrayd8126be2015-03-27 10:22:41 +000023#include "stack.h"
24#include "thread.h"
25
26namespace art {
27
28namespace {
29
30class TestVisitor : public StackVisitor {
31 public:
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070032 TestVisitor(Thread* thread, Context* context) REQUIRES_SHARED(Locks::mutator_lock_)
Nicolas Geoffray8e5bd182015-05-06 11:34:34 +010033 : StackVisitor(thread, context, StackVisitor::StackWalkKind::kIncludeInlinedFrames) {}
Nicolas Geoffrayd8126be2015-03-27 10:22:41 +000034
Andreas Gampefa6a1b02018-09-07 08:11:55 -070035 bool VisitFrame() override REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartiere401d142015-04-22 13:56:20 -070036 ArtMethod* m = GetMethod();
Nicolas Geoffrayd8126be2015-03-27 10:22:41 +000037 std::string m_name(m->GetName());
38
Artem Serovd6750532018-05-30 20:07:43 +010039 if (m_name.compare("$noinline$testLiveArgument") == 0) {
Nicolas Geoffrayd8126be2015-03-27 10:22:41 +000040 found_method_ = true;
Artem Serovd6750532018-05-30 20:07:43 +010041 CHECK_EQ(CodeItemDataAccessor(m->DexInstructionData()).RegistersSize(), 3u);
42 CheckOptimizedOutRegLiveness(m, 1, kIntVReg, true, 42);
Artem Serov2808be82018-12-20 19:15:11 +000043 CheckOptimizedOutRegLiveness(m, 2, kReferenceVReg);
Artem Serovd6750532018-05-30 20:07:43 +010044 } else if (m_name.compare("$noinline$testIntervalHole") == 0) {
45 found_method_ = true;
David Sehr0225f8e2018-01-31 08:52:24 +000046 uint32_t number_of_dex_registers =
47 CodeItemDataAccessor(m->DexInstructionData()).RegistersSize();
Nicolas Geoffray5949fa02015-12-18 10:57:10 +000048 uint32_t dex_register_of_first_parameter = number_of_dex_registers - 2;
Artem Serovd6750532018-05-30 20:07:43 +010049 CheckOptimizedOutRegLiveness(m, dex_register_of_first_parameter, kIntVReg, true, 1);
50 } else if (m_name.compare("$noinline$testCodeSinking") == 0) {
Nicolas Geoffrayd8126be2015-03-27 10:22:41 +000051 found_method_ = true;
Artem Serovd6750532018-05-30 20:07:43 +010052 CheckOptimizedOutRegLiveness(m, 0, kReferenceVReg);
Nicolas Geoffrayd8126be2015-03-27 10:22:41 +000053 }
54
55 return true;
56 }
57
Artem Serovd6750532018-05-30 20:07:43 +010058 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 Geoffrayd8126be2015-03-27 10:22:41 +000077 bool found_method_ = false;
78};
79
80extern "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