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_IA32) | 6 #if defined(TARGET_ARCH_IA32) |
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::kMinSource)); | 33 false, owner_class, TokenPosition::kMinSource)); |
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 __ enter(Immediate(0)); | 41 __ enter(Immediate(0)); |
43 __ PushObject(Object::null_object()); // Push Null object for return value. | 42 __ PushObject(Object::null_object()); // Push Null object 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(ESP, Immediate(argc * kWordSize)); | 47 __ AddImmediate(ESP, Immediate(argc * kWordSize)); |
49 __ popl(EAX); // Pop return value from return slot. | 48 __ popl(EAX); // Pop return value from return slot. |
50 __ leave(); | 49 __ leave(); |
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 __ enter(Immediate(0)); | 76 __ enter(Immediate(0)); |
80 __ ReserveAlignedFrameSpace(2 * kWordSize); | 77 __ ReserveAlignedFrameSpace(2 * kWordSize); |
81 __ LoadObject(EAX, bigint1); | 78 __ LoadObject(EAX, bigint1); |
82 __ movl(Address(ESP, 0), EAX); // Push argument 1 bigint1. | 79 __ movl(Address(ESP, 0), EAX); // Push argument 1 bigint1. |
83 __ LoadObject(EAX, bigint2); | 80 __ LoadObject(EAX, bigint2); |
84 __ movl(Address(ESP, kWordSize), EAX); // Push argument 2 bigint2. | 81 __ movl(Address(ESP, kWordSize), EAX); // Push argument 2 bigint2. |
85 __ CallRuntime(kBigintCompareRuntimeEntry, 2); | 82 __ CallRuntime(kBigintCompareRuntimeEntry, 2); |
86 __ SmiTag(EAX); | 83 __ SmiTag(EAX); |
87 __ leave(); | 84 __ leave(); |
88 __ ret(); // Return value is in EAX. | 85 __ ret(); // Return value is in EAX. |
89 } | 86 } |
90 | 87 |
91 | |
92 TEST_CASE(CallLeafRuntimeStubCode) { | 88 TEST_CASE(CallLeafRuntimeStubCode) { |
93 extern const Function& RegisterFakeFunction(const char* name, | 89 extern const Function& RegisterFakeFunction(const char* name, |
94 const Code& code); | 90 const Code& code); |
95 const char* value1 = "0xAAABBCCDDAABBCCDD"; | 91 const char* value1 = "0xAAABBCCDDAABBCCDD"; |
96 const char* value2 = "0xAABBCCDDAABBCCDD"; | 92 const char* value2 = "0xAABBCCDDAABBCCDD"; |
97 const char* kName = "Test_CallLeafRuntimeStubCode"; | 93 const char* kName = "Test_CallLeafRuntimeStubCode"; |
98 Assembler _assembler_; | 94 Assembler _assembler_; |
99 GenerateCallToCallLeafRuntimeStub(&_assembler_, value1, value2); | 95 GenerateCallToCallLeafRuntimeStub(&_assembler_, value1, value2); |
100 const Code& code = Code::Handle(Code::FinalizeCode( | 96 const Code& code = Code::Handle(Code::FinalizeCode( |
101 *CreateFunction("Test_CallLeafRuntimeStubCode"), &_assembler_)); | 97 *CreateFunction("Test_CallLeafRuntimeStubCode"), &_assembler_)); |
102 const Function& function = RegisterFakeFunction(kName, code); | 98 const Function& function = RegisterFakeFunction(kName, code); |
103 Smi& result = Smi::Handle(); | 99 Smi& result = Smi::Handle(); |
104 result ^= DartEntry::InvokeFunction(function, Object::empty_array()); | 100 result ^= DartEntry::InvokeFunction(function, Object::empty_array()); |
105 EXPECT_EQ(1, result.Value()); | 101 EXPECT_EQ(1, result.Value()); |
106 } | 102 } |
107 | 103 |
108 } // namespace dart | 104 } // namespace dart |
109 | 105 |
110 #endif // defined TARGET_ARCH_IA32 | 106 #endif // defined TARGET_ARCH_IA32 |
OLD | NEW |