blob: d3a033b12aab81518db1aacba967b4d1cca91ac0 [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"
Nicolas Geoffrayd8126be2015-03-27 10:22:41 +000019#include "jni.h"
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010020#include "oat_quick_method_header.h"
Mathieu Chartier0795f232016-09-27 18:43:30 -070021#include "scoped_thread_state_change-inl.h"
Nicolas Geoffrayd8126be2015-03-27 10:22:41 +000022#include "stack.h"
23#include "thread.h"
24
25namespace art {
26
27namespace {
28
29class TestVisitor : public StackVisitor {
30 public:
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070031 TestVisitor(Thread* thread, Context* context) REQUIRES_SHARED(Locks::mutator_lock_)
Nicolas Geoffray8e5bd182015-05-06 11:34:34 +010032 : StackVisitor(thread, context, StackVisitor::StackWalkKind::kIncludeInlinedFrames) {}
Nicolas Geoffrayd8126be2015-03-27 10:22:41 +000033
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070034 bool VisitFrame() REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartiere401d142015-04-22 13:56:20 -070035 ArtMethod* m = GetMethod();
Nicolas Geoffrayd8126be2015-03-27 10:22:41 +000036 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 Geoffray5949fa02015-12-18 10:57:10 +000043 } 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 Geoffrayd8126be2015-03-27 10:22:41 +000046 found_method_ = true;
47 uint32_t value = 0;
Nicolas Geoffray1920c102015-09-29 18:00:03 +000048 if (GetCurrentQuickFrame() != nullptr &&
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010049 GetCurrentOatQuickMethodHeader()->IsOptimized() &&
Nicolas Geoffray1920c102015-09-29 18:00:03 +000050 !Runtime::Current()->IsDebuggable()) {
Nicolas Geoffray5949fa02015-12-18 10:57:10 +000051 CHECK_EQ(GetVReg(m, dex_register_of_first_parameter, kIntVReg, &value), false);
Nicolas Geoffrayd8126be2015-03-27 10:22:41 +000052 } else {
Nicolas Geoffray5949fa02015-12-18 10:57:10 +000053 CHECK(GetVReg(m, dex_register_of_first_parameter, kIntVReg, &value));
Nicolas Geoffrayd8126be2015-03-27 10:22:41 +000054 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
66extern "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