blob: 0f0fb69f4b7a648e9971456781ae37578fd95f07 [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
Mathieu Chartiere401d142015-04-22 13:56:20 -070019#include "art_method-inl.h"
Andreas Gampe8228cdf2017-05-30 15:03:54 -070020#include "base/callee_save_type.h"
Alexei Zavjalov41c507a2014-05-15 16:02:46 +070021#include "callee_save_frame.h"
22#include "common_runtime_test.h"
Alexei Zavjalov41c507a2014-05-15 16:02:46 +070023#include "quick/quick_method_frame_info.h"
24
25namespace art {
26
27class QuickTrampolineEntrypointsTest : public CommonRuntimeTest {
28 protected:
Roland Levillainbbc6e7e2018-08-24 16:58:47 +010029 void SetUpRuntimeOptions(RuntimeOptions *options) override {
Jeff Hao6d254192015-02-17 18:01:00 -080030 // Use 64-bit ISA for runtime setup to make method size potentially larger
31 // than necessary (rather than smaller) during CreateCalleeSaveMethod
32 options->push_back(std::make_pair("imageinstructionset", "x86_64"));
33 }
34
Andreas Gampea00f0122015-12-16 16:54:35 -080035 // Do not do any of the finalization. We don't want to run any code, we don't need the heap
36 // prepared, it actually will be a problem with setting the instruction set to x86_64 in
37 // SetUpRuntimeOptions.
Roland Levillainbbc6e7e2018-08-24 16:58:47 +010038 void FinalizeSetup() override {
Andreas Gampea00f0122015-12-16 16:54:35 -080039 ASSERT_EQ(InstructionSet::kX86_64, Runtime::Current()->GetInstructionSet());
40 }
41
Andreas Gampe8228cdf2017-05-30 15:03:54 -070042 static ArtMethod* CreateCalleeSaveMethod(InstructionSet isa, CalleeSaveType type)
Alexei Zavjalov41c507a2014-05-15 16:02:46 +070043 NO_THREAD_SAFETY_ANALYSIS {
44 Runtime* r = Runtime::Current();
45
46 Thread* t = Thread::Current();
Mathieu Chartierf1d666e2015-09-03 16:13:34 -070047
48 ScopedObjectAccess soa(t);
Alexei Zavjalov41c507a2014-05-15 16:02:46 +070049
50 r->SetInstructionSet(isa);
Mathieu Chartiere401d142015-04-22 13:56:20 -070051 ArtMethod* save_method = r->CreateCalleeSaveMethod();
Alexei Zavjalov41c507a2014-05-15 16:02:46 +070052 r->SetCalleeSaveMethod(save_method, type);
53
Alexei Zavjalov41c507a2014-05-15 16:02:46 +070054 return save_method;
55 }
56
Andreas Gampe8228cdf2017-05-30 15:03:54 -070057 static void CheckPCOffset(InstructionSet isa, CalleeSaveType type, size_t pc_offset)
Alexei Zavjalov41c507a2014-05-15 16:02:46 +070058 NO_THREAD_SAFETY_ANALYSIS {
Mathieu Chartiere401d142015-04-22 13:56:20 -070059 ArtMethod* save_method = CreateCalleeSaveMethod(isa, type);
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010060 QuickMethodFrameInfo frame_info = Runtime::Current()->GetRuntimeMethodFrameInfo(save_method);
61 EXPECT_EQ(frame_info.GetReturnPcOffset(), pc_offset)
Ian Rogers6f3dbba2014-10-14 17:41:57 -070062 << "Expected and real pc offset differs for " << type
63 << " core spills=" << std::hex << frame_info.CoreSpillMask()
64 << " fp spills=" << frame_info.FpSpillMask() << std::dec << " ISA " << isa;
Alexei Zavjalov41c507a2014-05-15 16:02:46 +070065 }
66};
67
Alexei Zavjalov41c507a2014-05-15 16:02:46 +070068// This test ensures that the constexpr specialization of the return PC offset computation in
69// GetCalleeSavePCOffset is correct.
70TEST_F(QuickTrampolineEntrypointsTest, ReturnPC) {
71 // Ensure that the computation in callee_save_frame.h correct.
72 // Note: we can only check against the kRuntimeISA, because the ArtMethod computation uses
Ian Rogers13735952014-10-08 12:43:28 -070073 // sizeof(void*), which is wrong when the target bitwidth is not the same as the host's.
Vladimir Markod3083dd2018-05-17 08:43:47 +010074 CheckPCOffset(
75 kRuntimeISA,
76 CalleeSaveType::kSaveRefsAndArgs,
77 RuntimeCalleeSaveFrame::GetReturnPcOffset(CalleeSaveType::kSaveRefsAndArgs));
78 CheckPCOffset(
79 kRuntimeISA,
80 CalleeSaveType::kSaveRefsOnly,
81 RuntimeCalleeSaveFrame::GetReturnPcOffset(CalleeSaveType::kSaveRefsOnly));
82 CheckPCOffset(
83 kRuntimeISA,
84 CalleeSaveType::kSaveAllCalleeSaves,
85 RuntimeCalleeSaveFrame::GetReturnPcOffset(CalleeSaveType::kSaveAllCalleeSaves));
86 CheckPCOffset(
87 kRuntimeISA,
88 CalleeSaveType::kSaveEverything,
89 RuntimeCalleeSaveFrame::GetReturnPcOffset(CalleeSaveType::kSaveEverything));
90 CheckPCOffset(
91 kRuntimeISA,
92 CalleeSaveType::kSaveEverythingForClinit,
93 RuntimeCalleeSaveFrame::GetReturnPcOffset(CalleeSaveType::kSaveEverythingForClinit));
94 CheckPCOffset(
95 kRuntimeISA,
96 CalleeSaveType::kSaveEverythingForSuspendCheck,
97 RuntimeCalleeSaveFrame::GetReturnPcOffset(CalleeSaveType::kSaveEverythingForSuspendCheck));
Alexei Zavjalov41c507a2014-05-15 16:02:46 +070098}
99
100} // namespace art