blob: 7e9a583faf0e00d2644520aa7c53c8f9fd901fdd [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 Geoffrayd8126be2015-03-27 10:22:41 +000020#include "scoped_thread_state_change.h"
21#include "stack.h"
22#include "thread.h"
23
24namespace art {
25
26namespace {
27
28class TestVisitor : public StackVisitor {
29 public:
Mathieu Chartier90443472015-07-16 20:32:27 -070030 TestVisitor(Thread* thread, Context* context) SHARED_REQUIRES(Locks::mutator_lock_)
Nicolas Geoffray8e5bd182015-05-06 11:34:34 +010031 : StackVisitor(thread, context, StackVisitor::StackWalkKind::kIncludeInlinedFrames) {}
Nicolas Geoffrayd8126be2015-03-27 10:22:41 +000032
Mathieu Chartier90443472015-07-16 20:32:27 -070033 bool VisitFrame() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartiere401d142015-04-22 13:56:20 -070034 ArtMethod* m = GetMethod();
Nicolas Geoffrayd8126be2015-03-27 10:22:41 +000035 std::string m_name(m->GetName());
36
37 if (m_name.compare("testLiveArgument") == 0) {
38 found_method_ = true;
39 uint32_t value = 0;
40 CHECK(GetVReg(m, 0, kIntVReg, &value));
41 CHECK_EQ(value, 42u);
42 } else if (m_name.compare("testIntervalHole") == 0) {
43 found_method_ = true;
44 uint32_t value = 0;
Nicolas Geoffray1920c102015-09-29 18:00:03 +000045 if (GetCurrentQuickFrame() != nullptr &&
46 m->IsOptimized(sizeof(void*)) &&
47 !Runtime::Current()->IsDebuggable()) {
Nicolas Geoffrayd8126be2015-03-27 10:22:41 +000048 CHECK_EQ(GetVReg(m, 0, kIntVReg, &value), false);
49 } else {
50 CHECK(GetVReg(m, 0, kIntVReg, &value));
51 CHECK_EQ(value, 1u);
52 }
53 }
54
55 return true;
56 }
57
58 // Value returned to Java to ensure the methods testSimpleVReg and testPairVReg
59 // have been found and tested.
60 bool found_method_ = false;
61};
62
63extern "C" JNIEXPORT void JNICALL Java_Main_doStaticNativeCallLiveVreg(JNIEnv*, jclass) {
64 ScopedObjectAccess soa(Thread::Current());
65 std::unique_ptr<Context> context(Context::Create());
66 TestVisitor visitor(soa.Self(), context.get());
67 visitor.WalkStack();
68 CHECK(visitor.found_method_);
69}
70
71} // namespace
72
73} // namespace art