blob: 85a0b99ab154887eb5e6a554fc3bfee6fe14c857 [file] [log] [blame]
Alexei Zavjalov41c507a2014-05-15 16:02:46 +07001/*
2 * Copyright (C) 2014 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 <stdint.h>
18
19#include "callee_save_frame.h"
20#include "common_runtime_test.h"
21#include "mirror/art_method-inl.h"
22#include "quick/quick_method_frame_info.h"
23
24namespace art {
25
26class QuickTrampolineEntrypointsTest : public CommonRuntimeTest {
27 protected:
28 static mirror::ArtMethod* CreateCalleeSaveMethod(InstructionSet isa,
29 Runtime::CalleeSaveType type)
30 NO_THREAD_SAFETY_ANALYSIS {
31 Runtime* r = Runtime::Current();
32
33 Thread* t = Thread::Current();
34 t->TransitionFromSuspendedToRunnable(); // So we can create callee-save methods.
35
36 r->SetInstructionSet(isa);
Ian Rogers6a3c1fc2014-10-31 00:33:20 -070037 mirror::ArtMethod* save_method = r->CreateCalleeSaveMethod();
Alexei Zavjalov41c507a2014-05-15 16:02:46 +070038 r->SetCalleeSaveMethod(save_method, type);
39
40 t->TransitionFromRunnableToSuspended(ThreadState::kNative); // So we can shut down.
41
42 return save_method;
43 }
44
45 static void CheckFrameSize(InstructionSet isa, Runtime::CalleeSaveType type, uint32_t save_size)
46 NO_THREAD_SAFETY_ANALYSIS {
47 mirror::ArtMethod* save_method = CreateCalleeSaveMethod(isa, type);
48 QuickMethodFrameInfo frame_info = save_method->GetQuickFrameInfo();
49 EXPECT_EQ(frame_info.FrameSizeInBytes(), save_size) << "Expected and real size differs for "
50 << type << " core spills=" << std::hex << frame_info.CoreSpillMask() << " fp spills="
51 << frame_info.FpSpillMask() << std::dec << " ISA " << isa;
52 }
53
54 static void CheckPCOffset(InstructionSet isa, Runtime::CalleeSaveType type, size_t pc_offset)
55 NO_THREAD_SAFETY_ANALYSIS {
56 mirror::ArtMethod* save_method = CreateCalleeSaveMethod(isa, type);
57 QuickMethodFrameInfo frame_info = save_method->GetQuickFrameInfo();
Ian Rogers6f3dbba2014-10-14 17:41:57 -070058 EXPECT_EQ(save_method->GetReturnPcOffset().SizeValue(), pc_offset)
59 << "Expected and real pc offset differs for " << type
60 << " core spills=" << std::hex << frame_info.CoreSpillMask()
61 << " fp spills=" << frame_info.FpSpillMask() << std::dec << " ISA " << isa;
Alexei Zavjalov41c507a2014-05-15 16:02:46 +070062 }
63};
64
65// Note: these tests are all runtime tests. They let the Runtime create the corresponding ArtMethod
66// and check against it. Technically we know and expect certain values, but the Runtime code is
67// not constexpr, so we cannot make this compile-time checks (and I want the Runtime code tested).
68
69// This test ensures that kQuickCalleeSaveFrame_RefAndArgs_FrameSize is correct.
70TEST_F(QuickTrampolineEntrypointsTest, FrameSize) {
71 // We have to use a define here as the callee_save_frame.h functions are constexpr.
72#define CHECK_FRAME_SIZE(isa) \
73 CheckFrameSize(isa, Runtime::kRefsAndArgs, GetCalleeSaveFrameSize(isa, Runtime::kRefsAndArgs)); \
74 CheckFrameSize(isa, Runtime::kRefsOnly, GetCalleeSaveFrameSize(isa, Runtime::kRefsOnly)); \
75 CheckFrameSize(isa, Runtime::kSaveAll, GetCalleeSaveFrameSize(isa, Runtime::kSaveAll))
76
77 CHECK_FRAME_SIZE(kArm);
78 CHECK_FRAME_SIZE(kArm64);
79 CHECK_FRAME_SIZE(kMips);
80 CHECK_FRAME_SIZE(kX86);
81 CHECK_FRAME_SIZE(kX86_64);
82}
83
84// This test ensures that GetConstExprPointerSize is correct with respect to
85// GetInstructionSetPointerSize.
86TEST_F(QuickTrampolineEntrypointsTest, PointerSize) {
87 EXPECT_EQ(GetInstructionSetPointerSize(kArm), GetConstExprPointerSize(kArm));
88 EXPECT_EQ(GetInstructionSetPointerSize(kArm64), GetConstExprPointerSize(kArm64));
89 EXPECT_EQ(GetInstructionSetPointerSize(kMips), GetConstExprPointerSize(kMips));
90 EXPECT_EQ(GetInstructionSetPointerSize(kX86), GetConstExprPointerSize(kX86));
91 EXPECT_EQ(GetInstructionSetPointerSize(kX86_64), GetConstExprPointerSize(kX86_64));
92}
93
94// This test ensures that the constexpr specialization of the return PC offset computation in
95// GetCalleeSavePCOffset is correct.
96TEST_F(QuickTrampolineEntrypointsTest, ReturnPC) {
97 // Ensure that the computation in callee_save_frame.h correct.
98 // Note: we can only check against the kRuntimeISA, because the ArtMethod computation uses
Ian Rogers13735952014-10-08 12:43:28 -070099 // sizeof(void*), which is wrong when the target bitwidth is not the same as the host's.
Alexei Zavjalov41c507a2014-05-15 16:02:46 +0700100 CheckPCOffset(kRuntimeISA, Runtime::kRefsAndArgs,
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700101 GetCalleeSaveReturnPcOffset(kRuntimeISA, Runtime::kRefsAndArgs));
Alexei Zavjalov41c507a2014-05-15 16:02:46 +0700102 CheckPCOffset(kRuntimeISA, Runtime::kRefsOnly,
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700103 GetCalleeSaveReturnPcOffset(kRuntimeISA, Runtime::kRefsOnly));
Alexei Zavjalov41c507a2014-05-15 16:02:46 +0700104 CheckPCOffset(kRuntimeISA, Runtime::kSaveAll,
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700105 GetCalleeSaveReturnPcOffset(kRuntimeISA, Runtime::kSaveAll));
Alexei Zavjalov41c507a2014-05-15 16:02:46 +0700106}
107
108} // namespace art