| 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/dart_entry.h" |
| 8 #include "vm/isolate.h" | 9 #include "vm/isolate.h" |
| 9 #include "vm/dart_entry.h" | |
| 10 #include "vm/native_entry.h" | 10 #include "vm/native_entry.h" |
| 11 #include "vm/native_entry_test.h" | 11 #include "vm/native_entry_test.h" |
| 12 #include "vm/object.h" | 12 #include "vm/object.h" |
| 13 #include "vm/runtime_entry.h" | 13 #include "vm/runtime_entry.h" |
| 14 #include "vm/stub_code.h" | 14 #include "vm/stub_code.h" |
| 15 #include "vm/symbols.h" | 15 #include "vm/symbols.h" |
| 16 #include "vm/unit_test.h" | 16 #include "vm/unit_test.h" |
| 17 | 17 |
| 18 #define __ assembler-> | 18 #define __ assembler-> |
| 19 | 19 |
| 20 namespace dart { | 20 namespace dart { |
| 21 | 21 |
| 22 static Function* CreateFunction(const char* name) { | 22 static Function* CreateFunction(const char* name) { |
| 23 const String& class_name = | 23 const String& class_name = |
| 24 String::Handle(Symbols::New(Thread::Current(), "ownerClass")); | 24 String::Handle(Symbols::New(Thread::Current(), "ownerClass")); |
| 25 const Script& script = Script::Handle(); | 25 const Script& script = Script::Handle(); |
| 26 const Library& lib = Library::Handle(Library::New(class_name)); | 26 const Library& lib = Library::Handle(Library::New(class_name)); |
| 27 const Class& owner_class = Class::Handle( | 27 const Class& owner_class = Class::Handle( |
| 28 Class::New(lib, class_name, script, TokenPosition::kNoSource)); | 28 Class::New(lib, class_name, script, TokenPosition::kNoSource)); |
| 29 const String& function_name = | 29 const String& function_name = |
| 30 String::ZoneHandle(Symbols::New(Thread::Current(), name)); | 30 String::ZoneHandle(Symbols::New(Thread::Current(), name)); |
| 31 Function& function = Function::ZoneHandle(Function::New( | 31 Function& function = Function::ZoneHandle(Function::New( |
| 32 function_name, RawFunction::kRegularFunction, true, false, false, false, | 32 function_name, RawFunction::kRegularFunction, true, false, false, false, |
| 33 false, owner_class, TokenPosition::kNoSource)); | 33 false, owner_class, TokenPosition::kNoSource)); |
| 34 return &function; | 34 return &function; |
| 35 } | 35 } |
| 36 | 36 |
| 37 | |
| 38 // Test calls to stub code which calls into the runtime. | 37 // Test calls to stub code which calls into the runtime. |
| 39 static void GenerateCallToCallRuntimeStub(Assembler* assembler, int length) { | 38 static void GenerateCallToCallRuntimeStub(Assembler* assembler, int length) { |
| 40 const int argc = 2; | 39 const int argc = 2; |
| 41 const Smi& smi_length = Smi::ZoneHandle(Smi::New(length)); | 40 const Smi& smi_length = Smi::ZoneHandle(Smi::New(length)); |
| 42 __ EnterStubFrame(); | 41 __ EnterStubFrame(); |
| 43 __ PushObject(Object::null_object()); // Push Null obj for return value. | 42 __ PushObject(Object::null_object()); // Push Null obj for return value. |
| 44 __ PushObject(smi_length); // Push argument 1: length. | 43 __ PushObject(smi_length); // Push argument 1: length. |
| 45 __ PushObject(Object::null_object()); // Push argument 2: type arguments. | 44 __ PushObject(Object::null_object()); // Push argument 2: type arguments. |
| 46 ASSERT(kAllocateArrayRuntimeEntry.argument_count() == argc); | 45 ASSERT(kAllocateArrayRuntimeEntry.argument_count() == argc); |
| 47 __ CallRuntime(kAllocateArrayRuntimeEntry, argc); | 46 __ CallRuntime(kAllocateArrayRuntimeEntry, argc); |
| 48 __ AddImmediate(RSP, Immediate(argc * kWordSize)); | 47 __ AddImmediate(RSP, Immediate(argc * kWordSize)); |
| 49 __ popq(RAX); // Pop return value from return slot. | 48 __ popq(RAX); // Pop return value from return slot. |
| 50 __ LeaveStubFrame(); | 49 __ LeaveStubFrame(); |
| 51 __ ret(); | 50 __ ret(); |
| 52 } | 51 } |
| 53 | 52 |
| 54 | |
| 55 TEST_CASE(CallRuntimeStubCode) { | 53 TEST_CASE(CallRuntimeStubCode) { |
| 56 extern const Function& RegisterFakeFunction(const char* name, | 54 extern const Function& RegisterFakeFunction(const char* name, |
| 57 const Code& code); | 55 const Code& code); |
| 58 const int length = 10; | 56 const int length = 10; |
| 59 const char* kName = "Test_CallRuntimeStubCode"; | 57 const char* kName = "Test_CallRuntimeStubCode"; |
| 60 Assembler _assembler_; | 58 Assembler _assembler_; |
| 61 GenerateCallToCallRuntimeStub(&_assembler_, length); | 59 GenerateCallToCallRuntimeStub(&_assembler_, length); |
| 62 const Code& code = Code::Handle(Code::FinalizeCode( | 60 const Code& code = Code::Handle(Code::FinalizeCode( |
| 63 *CreateFunction("Test_CallRuntimeStubCode"), &_assembler_)); | 61 *CreateFunction("Test_CallRuntimeStubCode"), &_assembler_)); |
| 64 const Function& function = RegisterFakeFunction(kName, code); | 62 const Function& function = RegisterFakeFunction(kName, code); |
| 65 Array& result = Array::Handle(); | 63 Array& result = Array::Handle(); |
| 66 result ^= DartEntry::InvokeFunction(function, Object::empty_array()); | 64 result ^= DartEntry::InvokeFunction(function, Object::empty_array()); |
| 67 EXPECT_EQ(length, result.Length()); | 65 EXPECT_EQ(length, result.Length()); |
| 68 } | 66 } |
| 69 | 67 |
| 70 | |
| 71 // Test calls to stub code which calls into a leaf runtime entry. | 68 // Test calls to stub code which calls into a leaf runtime entry. |
| 72 static void GenerateCallToCallLeafRuntimeStub(Assembler* assembler, | 69 static void GenerateCallToCallLeafRuntimeStub(Assembler* assembler, |
| 73 const char* value1, | 70 const char* value1, |
| 74 const char* value2) { | 71 const char* value2) { |
| 75 const Bigint& bigint1 = | 72 const Bigint& bigint1 = |
| 76 Bigint::ZoneHandle(Bigint::NewFromCString(value1, Heap::kOld)); | 73 Bigint::ZoneHandle(Bigint::NewFromCString(value1, Heap::kOld)); |
| 77 const Bigint& bigint2 = | 74 const Bigint& bigint2 = |
| 78 Bigint::ZoneHandle(Bigint::NewFromCString(value2, Heap::kOld)); | 75 Bigint::ZoneHandle(Bigint::NewFromCString(value2, Heap::kOld)); |
| 79 __ EnterStubFrame(); | 76 __ EnterStubFrame(); |
| 80 __ ReserveAlignedFrameSpace(0); | 77 __ ReserveAlignedFrameSpace(0); |
| 81 __ LoadObject(CallingConventions::kArg1Reg, bigint1); | 78 __ LoadObject(CallingConventions::kArg1Reg, bigint1); |
| 82 __ LoadObject(CallingConventions::kArg2Reg, bigint2); | 79 __ LoadObject(CallingConventions::kArg2Reg, bigint2); |
| 83 __ CallRuntime(kBigintCompareRuntimeEntry, 2); | 80 __ CallRuntime(kBigintCompareRuntimeEntry, 2); |
| 84 __ SmiTag(RAX); | 81 __ SmiTag(RAX); |
| 85 __ LeaveStubFrame(); | 82 __ LeaveStubFrame(); |
| 86 __ ret(); // Return value is in RAX. | 83 __ ret(); // Return value is in RAX. |
| 87 } | 84 } |
| 88 | 85 |
| 89 | |
| 90 TEST_CASE(CallLeafRuntimeStubCode) { | 86 TEST_CASE(CallLeafRuntimeStubCode) { |
| 91 extern const Function& RegisterFakeFunction(const char* name, | 87 extern const Function& RegisterFakeFunction(const char* name, |
| 92 const Code& code); | 88 const Code& code); |
| 93 const char* value1 = "0xAAABBCCDDAABBCCDD"; | 89 const char* value1 = "0xAAABBCCDDAABBCCDD"; |
| 94 const char* value2 = "0xAABBCCDDAABBCCDD"; | 90 const char* value2 = "0xAABBCCDDAABBCCDD"; |
| 95 const char* kName = "Test_CallLeafRuntimeStubCode"; | 91 const char* kName = "Test_CallLeafRuntimeStubCode"; |
| 96 Assembler _assembler_; | 92 Assembler _assembler_; |
| 97 GenerateCallToCallLeafRuntimeStub(&_assembler_, value1, value2); | 93 GenerateCallToCallLeafRuntimeStub(&_assembler_, value1, value2); |
| 98 const Code& code = Code::Handle(Code::FinalizeCode( | 94 const Code& code = Code::Handle(Code::FinalizeCode( |
| 99 *CreateFunction("Test_CallLeafRuntimeStubCode"), &_assembler_)); | 95 *CreateFunction("Test_CallLeafRuntimeStubCode"), &_assembler_)); |
| 100 const Function& function = RegisterFakeFunction(kName, code); | 96 const Function& function = RegisterFakeFunction(kName, code); |
| 101 Smi& result = Smi::Handle(); | 97 Smi& result = Smi::Handle(); |
| 102 result ^= DartEntry::InvokeFunction(function, Object::empty_array()); | 98 result ^= DartEntry::InvokeFunction(function, Object::empty_array()); |
| 103 EXPECT_EQ(1, result.Value()); | 99 EXPECT_EQ(1, result.Value()); |
| 104 } | 100 } |
| 105 | 101 |
| 106 } // namespace dart | 102 } // namespace dart |
| 107 | 103 |
| 108 #endif // defined TARGET_ARCH_X64 | 104 #endif // defined TARGET_ARCH_X64 |
| OLD | NEW |