Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(257)

Side by Side Diff: vm/stub_code_x64_test.cc

Issue 10542123: Add support for leaf runtime calls (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« vm/stub_code_ia32.cc ('K') | « vm/stub_code_x64.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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);
23
24
25 static Function* CreateFunction(const char* name) {
26 const String& function_name = String::ZoneHandle(String::NewSymbol(name));
27 Function& function = Function::ZoneHandle(
28 Function::New(function_name, RawFunction::kFunction, true, false, 0));
29 return &function;
30 }
22 31
23 32
24 // Test calls to stub code which calls into the runtime. 33 // Test calls to stub code which calls into the runtime.
25 static void GenerateCallToCallRuntimeStub(Assembler* assembler, 34 static void GenerateCallToCallRuntimeStub(Assembler* assembler,
26 int value1, int value2) { 35 int value1, int value2) {
27 const int argc = 2; 36 const int argc = 2;
28 const Smi& smi1 = Smi::ZoneHandle(Smi::New(value1)); 37 const Smi& smi1 = Smi::ZoneHandle(Smi::New(value1));
29 const Smi& smi2 = Smi::ZoneHandle(Smi::New(value2)); 38 const Smi& smi2 = Smi::ZoneHandle(Smi::New(value2));
30 const Object& result = Object::ZoneHandle(); 39 const Object& result = Object::ZoneHandle();
31 const Context& context = Context::ZoneHandle(Context::New(0)); 40 const Context& context = Context::ZoneHandle(Context::New(0));
32 ASSERT(context.isolate() == Isolate::Current()); 41 ASSERT(context.isolate() == Isolate::Current());
33 __ enter(Immediate(0)); 42 __ enter(Immediate(0));
34 __ LoadObject(CTX, context); 43 __ LoadObject(CTX, context);
35 __ PushObject(result); // Push Null object for return value. 44 __ PushObject(result); // Push Null object for return value.
36 __ PushObject(smi1); // Push argument 1 smi1. 45 __ PushObject(smi1); // Push argument 1 smi1.
37 __ PushObject(smi2); // Push argument 2 smi2. 46 __ PushObject(smi2); // Push argument 2 smi2.
38 ASSERT(kTestSmiSubRuntimeEntry.argument_count() == argc); 47 ASSERT(kTestSmiSubRuntimeEntry.argument_count() == argc);
39 __ CallRuntime(kTestSmiSubRuntimeEntry); // Call SmiSub runtime func. 48 __ CallRuntime(kTestSmiSubRuntimeEntry); // Call SmiSub runtime func.
40 __ AddImmediate(RSP, Immediate(argc * kWordSize)); 49 __ AddImmediate(RSP, Immediate(argc * kWordSize));
41 __ popq(RAX); // Pop return value from return slot. 50 __ popq(RAX); // Pop return value from return slot.
42 __ leave(); 51 __ leave();
43 __ ret(); 52 __ ret();
44 } 53 }
45 54
46 55
47 static Function* CreateFunction(const char* name) {
48 const String& function_name = String::ZoneHandle(String::NewSymbol(name));
49 Function& function = Function::ZoneHandle(
50 Function::New(function_name, RawFunction::kFunction, true, false, 0));
51 return &function;
52 }
53
54
55 TEST_CASE(CallRuntimeStubCode) { 56 TEST_CASE(CallRuntimeStubCode) {
56 extern const Function& RegisterFakeFunction(const char* name, 57 extern const Function& RegisterFakeFunction(const char* name,
57 const Code& code); 58 const Code& code);
58 const int value1 = 10; 59 const int value1 = 10;
59 const int value2 = 20; 60 const int value2 = 20;
60 const char* kName = "Test_CallRuntimeStubCode"; 61 const char* kName = "Test_CallRuntimeStubCode";
61 Assembler _assembler_; 62 Assembler _assembler_;
62 GenerateCallToCallRuntimeStub(&_assembler_, value1, value2); 63 GenerateCallToCallRuntimeStub(&_assembler_, value1, value2);
63 const Code& code = Code::Handle(Code::FinalizeCode( 64 const Code& code = Code::Handle(Code::FinalizeCode(
64 *CreateFunction("Test_CallRuntimeStubCode"), &_assembler_)); 65 *CreateFunction("Test_CallRuntimeStubCode"), &_assembler_));
65 const Function& function = RegisterFakeFunction(kName, code); 66 const Function& function = RegisterFakeFunction(kName, code);
66 GrowableArray<const Object*> arguments; 67 GrowableArray<const Object*> arguments;
67 const Array& kNoArgumentNames = Array::Handle(); 68 const Array& kNoArgumentNames = Array::Handle();
68 Smi& result = Smi::Handle(); 69 Smi& result = Smi::Handle();
69 result ^= DartEntry::InvokeStatic(function, arguments, kNoArgumentNames); 70 result ^= DartEntry::InvokeStatic(function, arguments, kNoArgumentNames);
70 EXPECT_EQ((value1 - value2), result.Value()); 71 EXPECT_EQ((value1 - value2), result.Value());
71 } 72 }
72 73
73 74
75 // Test calls to stub code which calls into the runtime.
76 static void GenerateCallToCallLeafRuntimeStub(Assembler* assembler,
77 int value1,
78 int value2) {
79 const int argc = 2;
80 const Smi& smi1 = Smi::ZoneHandle(Smi::New(value1));
81 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));
86 __ LoadObject(CTX, context);
87 __ PushObject(result); // Push Null object for return value.
88 __ PushObject(smi1); // Push argument 1 smi1.
89 __ PushObject(smi2); // Push argument 2 smi2.
90 ASSERT(kTestLeafSmiAddRuntimeEntry.argument_count() == argc);
91 __ CallRuntime(kTestLeafSmiAddRuntimeEntry); // Call SmiAdd runtime func.
92 __ AddImmediate(RSP, Immediate(argc * kWordSize));
93 __ popq(RAX); // Pop return value from return slot.
94 __ leave();
95 __ ret();
96 }
97
98
99 TEST_CASE(CallLeafRuntimeStubCode) {
100 extern const Function& RegisterFakeFunction(const char* name,
101 const Code& code);
102 const int value1 = 10;
103 const int value2 = 20;
104 const char* kName = "Test_CallLeafRuntimeStubCode";
105 Assembler _assembler_;
106 GenerateCallToCallLeafRuntimeStub(&_assembler_, value1, value2);
107 const Code& code = Code::Handle(Code::FinalizeCode(
108 *CreateFunction("Test_CallLeafRuntimeStubCode"), &_assembler_));
109 const Function& function = RegisterFakeFunction(kName, code);
110 GrowableArray<const Object*> arguments;
111 const Array& kNoArgumentNames = Array::Handle();
112 Smi& result = Smi::Handle();
113 result ^= DartEntry::InvokeStatic(function, arguments, kNoArgumentNames);
114 EXPECT_EQ((value1 + value2), result.Value());
115 }
116
117
74 // Test calls to stub code which calls a native C function. 118 // Test calls to stub code which calls a native C function.
75 static void GenerateCallToCallNativeCFunctionStub(Assembler* assembler, 119 static void GenerateCallToCallNativeCFunctionStub(Assembler* assembler,
76 int value1, int value2) { 120 int value1, int value2) {
77 const int argc = 2; 121 const int argc = 2;
78 const Smi& smi1 = Smi::ZoneHandle(Smi::New(value1)); 122 const Smi& smi1 = Smi::ZoneHandle(Smi::New(value1));
79 const Smi& smi2 = Smi::ZoneHandle(Smi::New(value2)); 123 const Smi& smi2 = Smi::ZoneHandle(Smi::New(value2));
80 const Object& result = Object::ZoneHandle(); 124 const Object& result = Object::ZoneHandle();
81 const String& native_name = String::ZoneHandle(String::New("TestSmiSub")); 125 const String& native_name = String::ZoneHandle(String::New("TestSmiSub"));
82 Dart_NativeFunction native_function = 126 Dart_NativeFunction native_function =
83 NativeTestEntry_Lookup(native_name, argc); 127 NativeTestEntry_Lookup(native_name, argc);
(...skipping 30 matching lines...) Expand all
114 GrowableArray<const Object*> arguments; 158 GrowableArray<const Object*> arguments;
115 const Array& kNoArgumentNames = Array::Handle(); 159 const Array& kNoArgumentNames = Array::Handle();
116 Smi& result = Smi::Handle(); 160 Smi& result = Smi::Handle();
117 result ^= DartEntry::InvokeStatic(function, arguments, kNoArgumentNames); 161 result ^= DartEntry::InvokeStatic(function, arguments, kNoArgumentNames);
118 EXPECT_EQ((value1 - value2), result.Value()); 162 EXPECT_EQ((value1 - value2), result.Value());
119 } 163 }
120 164
121 } // namespace dart 165 } // namespace dart
122 166
123 #endif // defined TARGET_ARCH_X64 167 #endif // defined TARGET_ARCH_X64
OLDNEW
« vm/stub_code_ia32.cc ('K') | « vm/stub_code_x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698