| Alexei Zavjalov | 41c507a | 2014-05-15 16:02:46 +0700 | [diff] [blame] | 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 | |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 19 | #include "art_method-inl.h" |
| Andreas Gampe | 8228cdf | 2017-05-30 15:03:54 -0700 | [diff] [blame] | 20 | #include "base/callee_save_type.h" |
| Alexei Zavjalov | 41c507a | 2014-05-15 16:02:46 +0700 | [diff] [blame] | 21 | #include "callee_save_frame.h" |
| 22 | #include "common_runtime_test.h" |
| Alexei Zavjalov | 41c507a | 2014-05-15 16:02:46 +0700 | [diff] [blame] | 23 | #include "quick/quick_method_frame_info.h" |
| 24 | |
| 25 | namespace art { |
| 26 | |
| 27 | class QuickTrampolineEntrypointsTest : public CommonRuntimeTest { |
| 28 | protected: |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 29 | void SetUpRuntimeOptions(RuntimeOptions *options) override { |
| Jeff Hao | 6d25419 | 2015-02-17 18:01:00 -0800 | [diff] [blame] | 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 | |
| Andreas Gampe | a00f012 | 2015-12-16 16:54:35 -0800 | [diff] [blame] | 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. |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 38 | void FinalizeSetup() override { |
| Andreas Gampe | a00f012 | 2015-12-16 16:54:35 -0800 | [diff] [blame] | 39 | ASSERT_EQ(InstructionSet::kX86_64, Runtime::Current()->GetInstructionSet()); |
| 40 | } |
| 41 | |
| Andreas Gampe | 8228cdf | 2017-05-30 15:03:54 -0700 | [diff] [blame] | 42 | static ArtMethod* CreateCalleeSaveMethod(InstructionSet isa, CalleeSaveType type) |
| Alexei Zavjalov | 41c507a | 2014-05-15 16:02:46 +0700 | [diff] [blame] | 43 | NO_THREAD_SAFETY_ANALYSIS { |
| 44 | Runtime* r = Runtime::Current(); |
| 45 | |
| 46 | Thread* t = Thread::Current(); |
| Mathieu Chartier | f1d666e | 2015-09-03 16:13:34 -0700 | [diff] [blame] | 47 | |
| 48 | ScopedObjectAccess soa(t); |
| Alexei Zavjalov | 41c507a | 2014-05-15 16:02:46 +0700 | [diff] [blame] | 49 | |
| 50 | r->SetInstructionSet(isa); |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 51 | ArtMethod* save_method = r->CreateCalleeSaveMethod(); |
| Alexei Zavjalov | 41c507a | 2014-05-15 16:02:46 +0700 | [diff] [blame] | 52 | r->SetCalleeSaveMethod(save_method, type); |
| 53 | |
| Alexei Zavjalov | 41c507a | 2014-05-15 16:02:46 +0700 | [diff] [blame] | 54 | return save_method; |
| 55 | } |
| 56 | |
| Andreas Gampe | 8228cdf | 2017-05-30 15:03:54 -0700 | [diff] [blame] | 57 | static void CheckPCOffset(InstructionSet isa, CalleeSaveType type, size_t pc_offset) |
| Alexei Zavjalov | 41c507a | 2014-05-15 16:02:46 +0700 | [diff] [blame] | 58 | NO_THREAD_SAFETY_ANALYSIS { |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 59 | ArtMethod* save_method = CreateCalleeSaveMethod(isa, type); |
| Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 60 | QuickMethodFrameInfo frame_info = Runtime::Current()->GetRuntimeMethodFrameInfo(save_method); |
| 61 | EXPECT_EQ(frame_info.GetReturnPcOffset(), pc_offset) |
| Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 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; |
| Alexei Zavjalov | 41c507a | 2014-05-15 16:02:46 +0700 | [diff] [blame] | 65 | } |
| 66 | }; |
| 67 | |
| Alexei Zavjalov | 41c507a | 2014-05-15 16:02:46 +0700 | [diff] [blame] | 68 | // This test ensures that the constexpr specialization of the return PC offset computation in |
| 69 | // GetCalleeSavePCOffset is correct. |
| 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 |
| Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 73 | // sizeof(void*), which is wrong when the target bitwidth is not the same as the host's. |
| Vladimir Marko | d3083dd | 2018-05-17 08:43:47 +0100 | [diff] [blame] | 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)); |
| Alexei Zavjalov | 41c507a | 2014-05-15 16:02:46 +0700 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | } // namespace art |