| 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/code_index_table.h" | |
| 9 #include "vm/isolate.h" | 8 #include "vm/isolate.h" |
| 10 #include "vm/dart_entry.h" | 9 #include "vm/dart_entry.h" |
| 11 #include "vm/native_entry.h" | 10 #include "vm/native_entry.h" |
| 12 #include "vm/native_entry_test.h" | 11 #include "vm/native_entry_test.h" |
| 13 #include "vm/object.h" | 12 #include "vm/object.h" |
| 14 #include "vm/runtime_entry.h" | 13 #include "vm/runtime_entry.h" |
| 15 #include "vm/stub_code.h" | 14 #include "vm/stub_code.h" |
| 16 #include "vm/unit_test.h" | 15 #include "vm/unit_test.h" |
| 17 | 16 |
| 18 #define __ assembler-> | 17 #define __ assembler-> |
| 19 | 18 |
| 20 namespace dart { | 19 namespace dart { |
| 21 | 20 |
| 22 DECLARE_RUNTIME_ENTRY(TestSmiSub); | 21 DECLARE_RUNTIME_ENTRY(TestSmiSub); |
| 23 | 22 |
| 24 | 23 |
| 25 // Add function to a class and that class to the class dictionary so that | |
| 26 // frame walking can be used. | |
| 27 static const Function& RegisterFakeFunction(const char* name, | |
| 28 const Code& code) { | |
| 29 const String& function_name = String::ZoneHandle(String::NewSymbol(name)); | |
| 30 const Function& function = Function::ZoneHandle( | |
| 31 Function::New(function_name, RawFunction::kFunction, true, false, 0)); | |
| 32 Class& cls = Class::ZoneHandle(); | |
| 33 const Script& script = Script::Handle(); | |
| 34 cls = Class::New(function_name, script); | |
| 35 const Array& functions = Array::Handle(Array::New(1)); | |
| 36 functions.SetAt(0, function); | |
| 37 cls.SetFunctions(functions); | |
| 38 Library& lib = Library::Handle(Library::CoreLibrary()); | |
| 39 lib.AddClass(cls); | |
| 40 function.SetCode(code); | |
| 41 CodeIndexTable* code_index_table = Isolate::Current()->code_index_table(); | |
| 42 ASSERT(code_index_table != NULL); | |
| 43 code_index_table->AddFunction(function); | |
| 44 return function; | |
| 45 } | |
| 46 | |
| 47 | |
| 48 // Test calls to stub code which calls into the runtime. | 24 // Test calls to stub code which calls into the runtime. |
| 49 static void GenerateCallToCallRuntimeStub(Assembler* assembler, | 25 static void GenerateCallToCallRuntimeStub(Assembler* assembler, |
| 50 int value1, int value2) { | 26 int value1, int value2) { |
| 51 const int argc = 2; | 27 const int argc = 2; |
| 52 const Smi& smi1 = Smi::ZoneHandle(Smi::New(value1)); | 28 const Smi& smi1 = Smi::ZoneHandle(Smi::New(value1)); |
| 53 const Smi& smi2 = Smi::ZoneHandle(Smi::New(value2)); | 29 const Smi& smi2 = Smi::ZoneHandle(Smi::New(value2)); |
| 54 const Object& result = Object::ZoneHandle(); | 30 const Object& result = Object::ZoneHandle(); |
| 55 const Context& context = Context::ZoneHandle(Context::New(0)); | 31 const Context& context = Context::ZoneHandle(Context::New(0)); |
| 56 ASSERT(context.isolate() == Isolate::Current()); | 32 ASSERT(context.isolate() == Isolate::Current()); |
| 57 __ enter(Immediate(0)); | 33 __ enter(Immediate(0)); |
| 58 __ LoadObject(CTX, context); | 34 __ LoadObject(CTX, context); |
| 59 __ PushObject(result); // Push Null object for return value. | 35 __ PushObject(result); // Push Null object for return value. |
| 60 __ PushObject(smi1); // Push argument 1 smi1. | 36 __ PushObject(smi1); // Push argument 1 smi1. |
| 61 __ PushObject(smi2); // Push argument 2 smi2. | 37 __ PushObject(smi2); // Push argument 2 smi2. |
| 62 ASSERT(kTestSmiSubRuntimeEntry.argument_count() == argc); | 38 ASSERT(kTestSmiSubRuntimeEntry.argument_count() == argc); |
| 63 __ CallRuntimeFromStub(kTestSmiSubRuntimeEntry); // Call SmiSub runtime func. | 39 __ CallRuntimeFromStub(kTestSmiSubRuntimeEntry); // Call SmiSub runtime func. |
| 64 __ AddImmediate(ESP, Immediate(argc * kWordSize)); | 40 __ AddImmediate(ESP, Immediate(argc * kWordSize)); |
| 65 __ popl(EAX); // Pop return value from return slot. | 41 __ popl(EAX); // Pop return value from return slot. |
| 66 __ leave(); | 42 __ leave(); |
| 67 __ ret(); | 43 __ ret(); |
| 68 } | 44 } |
| 69 | 45 |
| 70 | 46 |
| 71 TEST_CASE(CallRuntimeStubCode) { | 47 TEST_CASE(CallRuntimeStubCode) { |
| 48 extern const Function& RegisterFakeFunction(const char* name, |
| 49 const Code& code); |
| 72 const int value1 = 10; | 50 const int value1 = 10; |
| 73 const int value2 = 20; | 51 const int value2 = 20; |
| 74 const char* kName = "Test_CallRuntimeStubCode"; | 52 const char* kName = "Test_CallRuntimeStubCode"; |
| 75 Assembler _assembler_; | 53 Assembler _assembler_; |
| 76 GenerateCallToCallRuntimeStub(&_assembler_, value1, value2); | 54 GenerateCallToCallRuntimeStub(&_assembler_, value1, value2); |
| 77 const Code& code = Code::Handle( | 55 const Code& code = Code::Handle( |
| 78 Code::FinalizeCode("Test_CallRuntimeStubCode", &_assembler_)); | 56 Code::FinalizeCode("Test_CallRuntimeStubCode", &_assembler_)); |
| 79 const Function& function = RegisterFakeFunction(kName, code); | 57 const Function& function = RegisterFakeFunction(kName, code); |
| 80 GrowableArray<const Object*> arguments; | 58 GrowableArray<const Object*> arguments; |
| 81 const Array& kNoArgumentNames = Array::Handle(); | 59 const Array& kNoArgumentNames = Array::Handle(); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 108 __ movl(EDX, Immediate(argc)); | 86 __ movl(EDX, Immediate(argc)); |
| 109 __ call(&StubCode::CallNativeCFunctionLabel()); | 87 __ call(&StubCode::CallNativeCFunctionLabel()); |
| 110 __ popl(EAX); // Pop return value from return slot. | 88 __ popl(EAX); // Pop return value from return slot. |
| 111 __ AddImmediate(ESP, Immediate(argc * kWordSize)); | 89 __ AddImmediate(ESP, Immediate(argc * kWordSize)); |
| 112 __ leave(); | 90 __ leave(); |
| 113 __ ret(); | 91 __ ret(); |
| 114 } | 92 } |
| 115 | 93 |
| 116 | 94 |
| 117 TEST_CASE(CallNativeCFunctionStubCode) { | 95 TEST_CASE(CallNativeCFunctionStubCode) { |
| 96 extern const Function& RegisterFakeFunction(const char* name, |
| 97 const Code& code); |
| 118 const int value1 = 15; | 98 const int value1 = 15; |
| 119 const int value2 = 20; | 99 const int value2 = 20; |
| 120 const char* kName = "Test_CallNativeCFunctionStubCode"; | 100 const char* kName = "Test_CallNativeCFunctionStubCode"; |
| 121 Assembler _assembler_; | 101 Assembler _assembler_; |
| 122 GenerateCallToCallNativeCFunctionStub(&_assembler_, value1, value2); | 102 GenerateCallToCallNativeCFunctionStub(&_assembler_, value1, value2); |
| 123 const Code& code = Code::Handle( | 103 const Code& code = Code::Handle( |
| 124 Code::FinalizeCode(kName, &_assembler_)); | 104 Code::FinalizeCode(kName, &_assembler_)); |
| 125 const Function& function = RegisterFakeFunction(kName, code); | 105 const Function& function = RegisterFakeFunction(kName, code); |
| 126 GrowableArray<const Object*> arguments; | 106 GrowableArray<const Object*> arguments; |
| 127 const Array& kNoArgumentNames = Array::Handle(); | 107 const Array& kNoArgumentNames = Array::Handle(); |
| 128 Smi& result = Smi::Handle(); | 108 Smi& result = Smi::Handle(); |
| 129 result ^= DartEntry::InvokeStatic(function, arguments, kNoArgumentNames); | 109 result ^= DartEntry::InvokeStatic(function, arguments, kNoArgumentNames); |
| 130 EXPECT_EQ((value1 - value2), result.Value()); | 110 EXPECT_EQ((value1 - value2), result.Value()); |
| 131 } | 111 } |
| 132 | 112 |
| 133 } // namespace dart | 113 } // namespace dart |
| 134 | 114 |
| 135 #endif // defined TARGET_ARCH_IA32 | 115 #endif // defined TARGET_ARCH_IA32 |
| OLD | NEW |