• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 "art_method-inl.h"
20 #include "base/callee_save_type.h"
21 #include "callee_save_frame.h"
22 #include "common_runtime_test.h"
23 #include "quick/quick_method_frame_info.h"
24 
25 namespace art {
26 
27 class QuickTrampolineEntrypointsTest : public CommonRuntimeTest {
28  protected:
SetUpRuntimeOptions(RuntimeOptions * options)29   void SetUpRuntimeOptions(RuntimeOptions *options) override {
30     // 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 
35   // 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.
FinalizeSetup()38   void FinalizeSetup() override {
39     ASSERT_EQ(InstructionSet::kX86_64, Runtime::Current()->GetInstructionSet());
40   }
41 
CreateCalleeSaveMethod(InstructionSet isa,CalleeSaveType type)42   static ArtMethod* CreateCalleeSaveMethod(InstructionSet isa, CalleeSaveType type)
43       NO_THREAD_SAFETY_ANALYSIS {
44     Runtime* r = Runtime::Current();
45 
46     Thread* t = Thread::Current();
47 
48     ScopedObjectAccess soa(t);
49 
50     r->SetInstructionSet(isa);
51     ArtMethod* save_method = r->CreateCalleeSaveMethod();
52     r->SetCalleeSaveMethod(save_method, type);
53 
54     return save_method;
55   }
56 
CheckPCOffset(InstructionSet isa,CalleeSaveType type,size_t pc_offset)57   static void CheckPCOffset(InstructionSet isa, CalleeSaveType type, size_t pc_offset)
58       NO_THREAD_SAFETY_ANALYSIS {
59     ArtMethod* save_method = CreateCalleeSaveMethod(isa, type);
60     QuickMethodFrameInfo frame_info = Runtime::Current()->GetRuntimeMethodFrameInfo(save_method);
61     EXPECT_EQ(frame_info.GetReturnPcOffset(), pc_offset)
62         << "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;
65   }
66 };
67 
68 // This test ensures that the constexpr specialization of the return PC offset computation in
69 // GetCalleeSavePCOffset is correct.
TEST_F(QuickTrampolineEntrypointsTest,ReturnPC)70 TEST_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
73   // sizeof(void*), which is wrong when the target bitwidth is not the same as the host's.
74   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));
98 }
99 
100 }  // namespace art
101