| 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 | 
|---|
| 3 | // BSD-style license that can be found in the LICENSE file. | 
|---|
| 4 |  | 
|---|
| 5 | #include "vm/globals.h" | 
|---|
| 6 | #if defined(TARGET_ARCH_X64) | 
|---|
| 7 |  | 
|---|
| 8 | #include "vm/code_patcher.h" | 
|---|
| 9 | #include "vm/compiler/assembler/assembler.h" | 
|---|
| 10 | #include "vm/dart_entry.h" | 
|---|
| 11 | #include "vm/instructions.h" | 
|---|
| 12 | #include "vm/native_entry.h" | 
|---|
| 13 | #include "vm/native_entry_test.h" | 
|---|
| 14 | #include "vm/runtime_entry.h" | 
|---|
| 15 | #include "vm/stub_code.h" | 
|---|
| 16 | #include "vm/symbols.h" | 
|---|
| 17 | #include "vm/unit_test.h" | 
|---|
| 18 |  | 
|---|
| 19 | namespace dart { | 
|---|
| 20 |  | 
|---|
| 21 | #define __ assembler-> | 
|---|
| 22 |  | 
|---|
| 23 | ASSEMBLER_TEST_GENERATE(IcDataAccess, assembler) { | 
|---|
| 24 | Thread* thread = Thread::Current(); | 
|---|
| 25 | const String& class_name = String::Handle(Symbols::New(thread, "ownerClass")); | 
|---|
| 26 | const Script& script = Script::Handle(); | 
|---|
| 27 | const Class& owner_class = Class::Handle(Class::New( | 
|---|
| 28 | Library::Handle(), class_name, script, TokenPosition::kNoSource)); | 
|---|
| 29 | const String& function_name = | 
|---|
| 30 | String::Handle(Symbols::New(thread, "callerFunction")); | 
|---|
| 31 | const Function& function = Function::Handle(Function::New( | 
|---|
| 32 | function_name, FunctionLayout::kRegularFunction, true, false, false, | 
|---|
| 33 | false, false, owner_class, TokenPosition::kNoSource)); | 
|---|
| 34 |  | 
|---|
| 35 | const String& target_name = String::Handle(String::New( "targetFunction")); | 
|---|
| 36 | const intptr_t kTypeArgsLen = 0; | 
|---|
| 37 | const intptr_t kNumArgs = 1; | 
|---|
| 38 | const Array& args_descriptor = Array::Handle(ArgumentsDescriptor::NewBoxed( | 
|---|
| 39 | kTypeArgsLen, kNumArgs, Object::null_array())); | 
|---|
| 40 | const ICData& ic_data = ICData::ZoneHandle(ICData::New( | 
|---|
| 41 | function, target_name, args_descriptor, 15, 1, ICData::kInstance)); | 
|---|
| 42 |  | 
|---|
| 43 | // Code accessing pp is generated, but not executed. Uninitialized pp is OK. | 
|---|
| 44 | __ set_constant_pool_allowed(true); | 
|---|
| 45 |  | 
|---|
| 46 | __ LoadObject(RBX, ic_data); | 
|---|
| 47 | __ CallPatchable(StubCode::OneArgCheckInlineCache()); | 
|---|
| 48 | __ ret(); | 
|---|
| 49 | } | 
|---|
| 50 |  | 
|---|
| 51 | ASSEMBLER_TEST_RUN(IcDataAccess, test) { | 
|---|
| 52 | uword end = test->payload_start() + test->code().Size(); | 
|---|
| 53 | uword return_address = end - 1;  // sizeof(ret) | 
|---|
| 54 | ICData& ic_data = ICData::Handle(); | 
|---|
| 55 | CodePatcher::GetInstanceCallAt(return_address, test->code(), &ic_data); | 
|---|
| 56 | EXPECT_STREQ( "targetFunction", | 
|---|
| 57 | String::Handle(ic_data.target_name()).ToCString()); | 
|---|
| 58 | EXPECT_EQ(1, ic_data.NumArgsTested()); | 
|---|
| 59 | EXPECT_EQ(0, ic_data.NumberOfChecks()); | 
|---|
| 60 | } | 
|---|
| 61 |  | 
|---|
| 62 | }  // namespace dart | 
|---|
| 63 |  | 
|---|
| 64 | #endif  // TARGET_ARCH_X64 | 
|---|
| 65 |  | 
|---|