| 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" |
| Alexei Zavjalov | 41c507a | 2014-05-15 16:02:46 +0700 | [diff] [blame] | 20 | #include "callee_save_frame.h" |
| 21 | #include "common_runtime_test.h" |
| Alexei Zavjalov | 41c507a | 2014-05-15 16:02:46 +0700 | [diff] [blame] | 22 | #include "quick/quick_method_frame_info.h" |
| 23 | |
| 24 | namespace art { |
| 25 | |
| 26 | class QuickTrampolineEntrypointsTest : public CommonRuntimeTest { |
| 27 | protected: |
| Jeff Hao | 6d25419 | 2015-02-17 18:01:00 -0800 | [diff] [blame] | 28 | void SetUpRuntimeOptions(RuntimeOptions *options) OVERRIDE { |
| 29 | // Use 64-bit ISA for runtime setup to make method size potentially larger |
| 30 | // than necessary (rather than smaller) during CreateCalleeSaveMethod |
| 31 | options->push_back(std::make_pair("imageinstructionset", "x86_64")); |
| 32 | } |
| 33 | |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 34 | static ArtMethod* CreateCalleeSaveMethod(InstructionSet isa, Runtime::CalleeSaveType type) |
| Alexei Zavjalov | 41c507a | 2014-05-15 16:02:46 +0700 | [diff] [blame] | 35 | NO_THREAD_SAFETY_ANALYSIS { |
| 36 | Runtime* r = Runtime::Current(); |
| 37 | |
| 38 | Thread* t = Thread::Current(); |
| 39 | t->TransitionFromSuspendedToRunnable(); // So we can create callee-save methods. |
| 40 | |
| 41 | r->SetInstructionSet(isa); |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 42 | ArtMethod* save_method = r->CreateCalleeSaveMethod(); |
| Alexei Zavjalov | 41c507a | 2014-05-15 16:02:46 +0700 | [diff] [blame] | 43 | r->SetCalleeSaveMethod(save_method, type); |
| 44 | |
| 45 | t->TransitionFromRunnableToSuspended(ThreadState::kNative); // So we can shut down. |
| 46 | |
| 47 | return save_method; |
| 48 | } |
| 49 | |
| 50 | static void CheckFrameSize(InstructionSet isa, Runtime::CalleeSaveType type, uint32_t save_size) |
| 51 | NO_THREAD_SAFETY_ANALYSIS { |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 52 | ArtMethod* save_method = CreateCalleeSaveMethod(isa, type); |
| Alexei Zavjalov | 41c507a | 2014-05-15 16:02:46 +0700 | [diff] [blame] | 53 | QuickMethodFrameInfo frame_info = save_method->GetQuickFrameInfo(); |
| 54 | EXPECT_EQ(frame_info.FrameSizeInBytes(), save_size) << "Expected and real size differs for " |
| 55 | << type << " core spills=" << std::hex << frame_info.CoreSpillMask() << " fp spills=" |
| 56 | << frame_info.FpSpillMask() << std::dec << " ISA " << isa; |
| 57 | } |
| 58 | |
| 59 | static void CheckPCOffset(InstructionSet isa, Runtime::CalleeSaveType type, size_t pc_offset) |
| 60 | NO_THREAD_SAFETY_ANALYSIS { |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 61 | ArtMethod* save_method = CreateCalleeSaveMethod(isa, type); |
| Alexei Zavjalov | 41c507a | 2014-05-15 16:02:46 +0700 | [diff] [blame] | 62 | QuickMethodFrameInfo frame_info = save_method->GetQuickFrameInfo(); |
| Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 63 | EXPECT_EQ(save_method->GetReturnPcOffset().SizeValue(), pc_offset) |
| 64 | << "Expected and real pc offset differs for " << type |
| 65 | << " core spills=" << std::hex << frame_info.CoreSpillMask() |
| 66 | << " fp spills=" << frame_info.FpSpillMask() << std::dec << " ISA " << isa; |
| Alexei Zavjalov | 41c507a | 2014-05-15 16:02:46 +0700 | [diff] [blame] | 67 | } |
| 68 | }; |
| 69 | |
| 70 | // Note: these tests are all runtime tests. They let the Runtime create the corresponding ArtMethod |
| 71 | // and check against it. Technically we know and expect certain values, but the Runtime code is |
| 72 | // not constexpr, so we cannot make this compile-time checks (and I want the Runtime code tested). |
| 73 | |
| 74 | // This test ensures that kQuickCalleeSaveFrame_RefAndArgs_FrameSize is correct. |
| 75 | TEST_F(QuickTrampolineEntrypointsTest, FrameSize) { |
| 76 | // We have to use a define here as the callee_save_frame.h functions are constexpr. |
| 77 | #define CHECK_FRAME_SIZE(isa) \ |
| 78 | CheckFrameSize(isa, Runtime::kRefsAndArgs, GetCalleeSaveFrameSize(isa, Runtime::kRefsAndArgs)); \ |
| 79 | CheckFrameSize(isa, Runtime::kRefsOnly, GetCalleeSaveFrameSize(isa, Runtime::kRefsOnly)); \ |
| 80 | CheckFrameSize(isa, Runtime::kSaveAll, GetCalleeSaveFrameSize(isa, Runtime::kSaveAll)) |
| 81 | |
| 82 | CHECK_FRAME_SIZE(kArm); |
| 83 | CHECK_FRAME_SIZE(kArm64); |
| 84 | CHECK_FRAME_SIZE(kMips); |
| 85 | CHECK_FRAME_SIZE(kX86); |
| 86 | CHECK_FRAME_SIZE(kX86_64); |
| 87 | } |
| 88 | |
| 89 | // This test ensures that GetConstExprPointerSize is correct with respect to |
| 90 | // GetInstructionSetPointerSize. |
| 91 | TEST_F(QuickTrampolineEntrypointsTest, PointerSize) { |
| 92 | EXPECT_EQ(GetInstructionSetPointerSize(kArm), GetConstExprPointerSize(kArm)); |
| 93 | EXPECT_EQ(GetInstructionSetPointerSize(kArm64), GetConstExprPointerSize(kArm64)); |
| 94 | EXPECT_EQ(GetInstructionSetPointerSize(kMips), GetConstExprPointerSize(kMips)); |
| 95 | EXPECT_EQ(GetInstructionSetPointerSize(kX86), GetConstExprPointerSize(kX86)); |
| 96 | EXPECT_EQ(GetInstructionSetPointerSize(kX86_64), GetConstExprPointerSize(kX86_64)); |
| 97 | } |
| 98 | |
| 99 | // This test ensures that the constexpr specialization of the return PC offset computation in |
| 100 | // GetCalleeSavePCOffset is correct. |
| 101 | TEST_F(QuickTrampolineEntrypointsTest, ReturnPC) { |
| 102 | // Ensure that the computation in callee_save_frame.h correct. |
| 103 | // 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] | 104 | // sizeof(void*), which is wrong when the target bitwidth is not the same as the host's. |
| Alexei Zavjalov | 41c507a | 2014-05-15 16:02:46 +0700 | [diff] [blame] | 105 | CheckPCOffset(kRuntimeISA, Runtime::kRefsAndArgs, |
| Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 106 | GetCalleeSaveReturnPcOffset(kRuntimeISA, Runtime::kRefsAndArgs)); |
| Alexei Zavjalov | 41c507a | 2014-05-15 16:02:46 +0700 | [diff] [blame] | 107 | CheckPCOffset(kRuntimeISA, Runtime::kRefsOnly, |
| Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 108 | GetCalleeSaveReturnPcOffset(kRuntimeISA, Runtime::kRefsOnly)); |
| Alexei Zavjalov | 41c507a | 2014-05-15 16:02:46 +0700 | [diff] [blame] | 109 | CheckPCOffset(kRuntimeISA, Runtime::kSaveAll, |
| Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 110 | GetCalleeSaveReturnPcOffset(kRuntimeISA, Runtime::kSaveAll)); |
| Alexei Zavjalov | 41c507a | 2014-05-15 16:02:46 +0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | } // namespace art |