| 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" |
| 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/unit_test.h" | 15 #include "vm/unit_test.h" |
| 16 | 16 |
| 17 #define __ assembler-> | 17 #define __ assembler-> |
| 18 | 18 |
| 19 namespace dart { | 19 namespace dart { |
| 20 | 20 |
| 21 DECLARE_RUNTIME_ENTRY(TestSmiSub); | 21 DECLARE_RUNTIME_ENTRY(TestSmiSub); |
| 22 DECLARE_LEAF_RUNTIME_ENTRY(TestLeafSmiAdd); | 22 DECLARE_LEAF_RUNTIME_ENTRY(RawObject*, TestLeafSmiAdd, RawObject*, RawObject*); |
| 23 | 23 |
| 24 | 24 |
| 25 static Function* CreateFunction(const char* name) { | 25 static Function* CreateFunction(const char* name) { |
| 26 const String& function_name = String::ZoneHandle(String::NewSymbol(name)); | 26 const String& function_name = String::ZoneHandle(String::NewSymbol(name)); |
| 27 Function& function = Function::ZoneHandle( | 27 Function& function = Function::ZoneHandle( |
| 28 Function::New(function_name, RawFunction::kFunction, true, false, 0)); | 28 Function::New(function_name, RawFunction::kFunction, true, false, 0)); |
| 29 return &function; | 29 return &function; |
| 30 } | 30 } |
| 31 | 31 |
| 32 | 32 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 Smi& result = Smi::Handle(); | 69 Smi& result = Smi::Handle(); |
| 70 result ^= DartEntry::InvokeStatic(function, arguments, kNoArgumentNames); | 70 result ^= DartEntry::InvokeStatic(function, arguments, kNoArgumentNames); |
| 71 EXPECT_EQ((value1 - value2), result.Value()); | 71 EXPECT_EQ((value1 - value2), result.Value()); |
| 72 } | 72 } |
| 73 | 73 |
| 74 | 74 |
| 75 // Test calls to stub code which calls into the runtime. | 75 // Test calls to stub code which calls into the runtime. |
| 76 static void GenerateCallToCallLeafRuntimeStub(Assembler* assembler, | 76 static void GenerateCallToCallLeafRuntimeStub(Assembler* assembler, |
| 77 int value1, | 77 int value1, |
| 78 int value2) { | 78 int value2) { |
| 79 const int argc = 2; | |
| 80 const Smi& smi1 = Smi::ZoneHandle(Smi::New(value1)); | 79 const Smi& smi1 = Smi::ZoneHandle(Smi::New(value1)); |
| 81 const Smi& smi2 = Smi::ZoneHandle(Smi::New(value2)); | 80 const Smi& smi2 = Smi::ZoneHandle(Smi::New(value2)); |
| 82 const Object& result = Object::ZoneHandle(); | |
| 83 const Context& context = Context::ZoneHandle(Context::New(0)); | |
| 84 ASSERT(context.isolate() == Isolate::Current()); | |
| 85 __ enter(Immediate(0)); | 81 __ enter(Immediate(0)); |
| 86 __ LoadObject(CTX, context); | 82 __ ReserveAlignedFrameSpace(2 * kWordSize); |
| 87 __ PushObject(result); // Push Null object for return value. | 83 __ LoadObject(RAX, smi1); |
| 88 __ PushObject(smi1); // Push argument 1 smi1. | 84 __ movq(Address(RSP, 0), EAX); // Push argument 1 smi1. |
| 89 __ PushObject(smi2); // Push argument 2 smi2. | 85 __ LoadObject(RAX, smi2); |
| 90 ASSERT(kTestLeafSmiAddRuntimeEntry.argument_count() == argc); | 86 __ movq(Address(RSP, kWordSize), EAX); // Push argument 2 smi2. |
| 91 __ CallRuntime(kTestLeafSmiAddRuntimeEntry); // Call SmiAdd runtime func. | 87 __ CallRuntime(kTestLeafSmiAddRuntimeEntry); // Call SmiAdd runtime func. |
| 92 __ AddImmediate(RSP, Immediate(argc * kWordSize)); | |
| 93 __ popq(RAX); // Pop return value from return slot. | |
| 94 __ leave(); | 88 __ leave(); |
| 95 __ ret(); | 89 __ ret(); // Return value is in RAX. |
| 96 } | 90 } |
| 97 | 91 |
| 98 | 92 |
| 99 TEST_CASE(CallLeafRuntimeStubCode) { | 93 TEST_CASE(CallLeafRuntimeStubCode) { |
| 100 extern const Function& RegisterFakeFunction(const char* name, | 94 extern const Function& RegisterFakeFunction(const char* name, |
| 101 const Code& code); | 95 const Code& code); |
| 102 const int value1 = 10; | 96 const int value1 = 10; |
| 103 const int value2 = 20; | 97 const int value2 = 20; |
| 104 const char* kName = "Test_CallLeafRuntimeStubCode"; | 98 const char* kName = "Test_CallLeafRuntimeStubCode"; |
| 105 Assembler _assembler_; | 99 Assembler _assembler_; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 GrowableArray<const Object*> arguments; | 152 GrowableArray<const Object*> arguments; |
| 159 const Array& kNoArgumentNames = Array::Handle(); | 153 const Array& kNoArgumentNames = Array::Handle(); |
| 160 Smi& result = Smi::Handle(); | 154 Smi& result = Smi::Handle(); |
| 161 result ^= DartEntry::InvokeStatic(function, arguments, kNoArgumentNames); | 155 result ^= DartEntry::InvokeStatic(function, arguments, kNoArgumentNames); |
| 162 EXPECT_EQ((value1 - value2), result.Value()); | 156 EXPECT_EQ((value1 - value2), result.Value()); |
| 163 } | 157 } |
| 164 | 158 |
| 165 } // namespace dart | 159 } // namespace dart |
| 166 | 160 |
| 167 #endif // defined TARGET_ARCH_X64 | 161 #endif // defined TARGET_ARCH_X64 |
| OLD | NEW |