| Index: vm/stub_code_x64_test.cc
|
| ===================================================================
|
| --- vm/stub_code_x64_test.cc (revision 8520)
|
| +++ vm/stub_code_x64_test.cc (working copy)
|
| @@ -19,8 +19,17 @@
|
| namespace dart {
|
|
|
| DECLARE_RUNTIME_ENTRY(TestSmiSub);
|
| +DECLARE_LEAF_RUNTIME_ENTRY(TestLeafSmiAdd);
|
|
|
|
|
| +static Function* CreateFunction(const char* name) {
|
| + const String& function_name = String::ZoneHandle(String::NewSymbol(name));
|
| + Function& function = Function::ZoneHandle(
|
| + Function::New(function_name, RawFunction::kFunction, true, false, 0));
|
| + return &function;
|
| +}
|
| +
|
| +
|
| // Test calls to stub code which calls into the runtime.
|
| static void GenerateCallToCallRuntimeStub(Assembler* assembler,
|
| int value1, int value2) {
|
| @@ -44,14 +53,6 @@
|
| }
|
|
|
|
|
| -static Function* CreateFunction(const char* name) {
|
| - const String& function_name = String::ZoneHandle(String::NewSymbol(name));
|
| - Function& function = Function::ZoneHandle(
|
| - Function::New(function_name, RawFunction::kFunction, true, false, 0));
|
| - return &function;
|
| -}
|
| -
|
| -
|
| TEST_CASE(CallRuntimeStubCode) {
|
| extern const Function& RegisterFakeFunction(const char* name,
|
| const Code& code);
|
| @@ -71,6 +72,49 @@
|
| }
|
|
|
|
|
| +// Test calls to stub code which calls into the runtime.
|
| +static void GenerateCallToCallLeafRuntimeStub(Assembler* assembler,
|
| + int value1,
|
| + int value2) {
|
| + const int argc = 2;
|
| + const Smi& smi1 = Smi::ZoneHandle(Smi::New(value1));
|
| + const Smi& smi2 = Smi::ZoneHandle(Smi::New(value2));
|
| + const Object& result = Object::ZoneHandle();
|
| + const Context& context = Context::ZoneHandle(Context::New(0));
|
| + ASSERT(context.isolate() == Isolate::Current());
|
| + __ enter(Immediate(0));
|
| + __ LoadObject(CTX, context);
|
| + __ PushObject(result); // Push Null object for return value.
|
| + __ PushObject(smi1); // Push argument 1 smi1.
|
| + __ PushObject(smi2); // Push argument 2 smi2.
|
| + ASSERT(kTestLeafSmiAddRuntimeEntry.argument_count() == argc);
|
| + __ CallRuntime(kTestLeafSmiAddRuntimeEntry); // Call SmiAdd runtime func.
|
| + __ AddImmediate(RSP, Immediate(argc * kWordSize));
|
| + __ popq(RAX); // Pop return value from return slot.
|
| + __ leave();
|
| + __ ret();
|
| +}
|
| +
|
| +
|
| +TEST_CASE(CallLeafRuntimeStubCode) {
|
| + extern const Function& RegisterFakeFunction(const char* name,
|
| + const Code& code);
|
| + const int value1 = 10;
|
| + const int value2 = 20;
|
| + const char* kName = "Test_CallLeafRuntimeStubCode";
|
| + Assembler _assembler_;
|
| + GenerateCallToCallLeafRuntimeStub(&_assembler_, value1, value2);
|
| + const Code& code = Code::Handle(Code::FinalizeCode(
|
| + *CreateFunction("Test_CallLeafRuntimeStubCode"), &_assembler_));
|
| + const Function& function = RegisterFakeFunction(kName, code);
|
| + GrowableArray<const Object*> arguments;
|
| + const Array& kNoArgumentNames = Array::Handle();
|
| + Smi& result = Smi::Handle();
|
| + result ^= DartEntry::InvokeStatic(function, arguments, kNoArgumentNames);
|
| + EXPECT_EQ((value1 + value2), result.Value());
|
| +}
|
| +
|
| +
|
| // Test calls to stub code which calls a native C function.
|
| static void GenerateCallToCallNativeCFunctionStub(Assembler* assembler,
|
| int value1, int value2) {
|
|
|