| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/globals.h" | 5 #include "vm/globals.h" |
| 6 #if defined(TARGET_ARCH_X64) | 6 #if defined(TARGET_ARCH_X64) |
| 7 | 7 |
| 8 #include "vm/isolate.h" | 8 #include "vm/isolate.h" |
| 9 #include "vm/dart_entry.h" | 9 #include "vm/dart_entry.h" |
| 10 #include "vm/native_entry.h" | 10 #include "vm/native_entry.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 } | 38 } |
| 39 | 39 |
| 40 | 40 |
| 41 // Test calls to stub code which calls into the runtime. | 41 // Test calls to stub code which calls into the runtime. |
| 42 static void GenerateCallToCallRuntimeStub(Assembler* assembler, | 42 static void GenerateCallToCallRuntimeStub(Assembler* assembler, |
| 43 int value1, int value2) { | 43 int value1, int value2) { |
| 44 const int argc = 2; | 44 const int argc = 2; |
| 45 const Smi& smi1 = Smi::ZoneHandle(Smi::New(value1)); | 45 const Smi& smi1 = Smi::ZoneHandle(Smi::New(value1)); |
| 46 const Smi& smi2 = Smi::ZoneHandle(Smi::New(value2)); | 46 const Smi& smi2 = Smi::ZoneHandle(Smi::New(value2)); |
| 47 __ EnterStubFrame(); | 47 __ EnterStubFrame(); |
| 48 __ PushObject(Object::null_object(), PP); // Push Null obj for return value. | 48 __ PushObject(Object::null_object()); // Push Null obj for return value. |
| 49 __ PushObject(smi1, PP); // Push argument 1 smi1. | 49 __ PushObject(smi1); // Push argument 1 smi1. |
| 50 __ PushObject(smi2, PP); // Push argument 2 smi2. | 50 __ PushObject(smi2); // Push argument 2 smi2. |
| 51 ASSERT(kTestSmiSubRuntimeEntry.argument_count() == argc); | 51 ASSERT(kTestSmiSubRuntimeEntry.argument_count() == argc); |
| 52 __ CallRuntime(kTestSmiSubRuntimeEntry, argc); // Call SmiSub runtime func. | 52 __ CallRuntime(kTestSmiSubRuntimeEntry, argc); // Call SmiSub runtime func. |
| 53 __ AddImmediate(RSP, Immediate(argc * kWordSize), PP); | 53 __ AddImmediate(RSP, Immediate(argc * kWordSize)); |
| 54 __ popq(RAX); // Pop return value from return slot. | 54 __ popq(RAX); // Pop return value from return slot. |
| 55 __ LeaveStubFrame(); | 55 __ LeaveStubFrame(); |
| 56 __ ret(); | 56 __ ret(); |
| 57 } | 57 } |
| 58 | 58 |
| 59 | 59 |
| 60 TEST_CASE(CallRuntimeStubCode) { | 60 TEST_CASE(CallRuntimeStubCode) { |
| 61 extern const Function& RegisterFakeFunction(const char* name, | 61 extern const Function& RegisterFakeFunction(const char* name, |
| 62 const Code& code); | 62 const Code& code); |
| 63 const int value1 = 10; | 63 const int value1 = 10; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 75 | 75 |
| 76 | 76 |
| 77 // Test calls to stub code which calls into a leaf runtime entry. | 77 // Test calls to stub code which calls into a leaf runtime entry. |
| 78 static void GenerateCallToCallLeafRuntimeStub(Assembler* assembler, | 78 static void GenerateCallToCallLeafRuntimeStub(Assembler* assembler, |
| 79 int value1, | 79 int value1, |
| 80 int value2) { | 80 int value2) { |
| 81 const Smi& smi1 = Smi::ZoneHandle(Smi::New(value1)); | 81 const Smi& smi1 = Smi::ZoneHandle(Smi::New(value1)); |
| 82 const Smi& smi2 = Smi::ZoneHandle(Smi::New(value2)); | 82 const Smi& smi2 = Smi::ZoneHandle(Smi::New(value2)); |
| 83 __ enter(Immediate(0)); | 83 __ enter(Immediate(0)); |
| 84 __ ReserveAlignedFrameSpace(0); | 84 __ ReserveAlignedFrameSpace(0); |
| 85 __ LoadObject(CallingConventions::kArg1Reg, smi1, PP); | 85 __ LoadObject(CallingConventions::kArg1Reg, smi1); |
| 86 __ LoadObject(CallingConventions::kArg2Reg, smi2, PP); | 86 __ LoadObject(CallingConventions::kArg2Reg, smi2); |
| 87 __ CallRuntime(kTestLeafSmiAddRuntimeEntry, 2); // Call SmiAdd runtime func. | 87 __ CallRuntime(kTestLeafSmiAddRuntimeEntry, 2); // Call SmiAdd runtime func. |
| 88 __ leave(); | 88 __ leave(); |
| 89 __ ret(); // Return value is in RAX. | 89 __ ret(); // Return value is in RAX. |
| 90 } | 90 } |
| 91 | 91 |
| 92 | 92 |
| 93 TEST_CASE(CallLeafRuntimeStubCode) { | 93 TEST_CASE(CallLeafRuntimeStubCode) { |
| 94 extern const Function& RegisterFakeFunction(const char* name, | 94 extern const Function& RegisterFakeFunction(const char* name, |
| 95 const Code& code); | 95 const Code& code); |
| 96 const int value1 = 10; | 96 const int value1 = 10; |
| 97 const int value2 = 20; | 97 const int value2 = 20; |
| 98 const char* kName = "Test_CallLeafRuntimeStubCode"; | 98 const char* kName = "Test_CallLeafRuntimeStubCode"; |
| 99 Assembler _assembler_; | 99 Assembler _assembler_; |
| 100 GenerateCallToCallLeafRuntimeStub(&_assembler_, value1, value2); | 100 GenerateCallToCallLeafRuntimeStub(&_assembler_, value1, value2); |
| 101 const Code& code = Code::Handle(Code::FinalizeCode( | 101 const Code& code = Code::Handle(Code::FinalizeCode( |
| 102 *CreateFunction("Test_CallLeafRuntimeStubCode"), &_assembler_)); | 102 *CreateFunction("Test_CallLeafRuntimeStubCode"), &_assembler_)); |
| 103 const Function& function = RegisterFakeFunction(kName, code); | 103 const Function& function = RegisterFakeFunction(kName, code); |
| 104 Smi& result = Smi::Handle(); | 104 Smi& result = Smi::Handle(); |
| 105 result ^= DartEntry::InvokeFunction(function, Object::empty_array()); | 105 result ^= DartEntry::InvokeFunction(function, Object::empty_array()); |
| 106 EXPECT_EQ((value1 + value2), result.Value()); | 106 EXPECT_EQ((value1 + value2), result.Value()); |
| 107 } | 107 } |
| 108 | 108 |
| 109 } // namespace dart | 109 } // namespace dart |
| 110 | 110 |
| 111 #endif // defined TARGET_ARCH_X64 | 111 #endif // defined TARGET_ARCH_X64 |
| OLD | NEW |