Flutter Engine
The Flutter Engine
code_patcher_x64_test.cc
Go to the documentation of this 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
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"
10#include "vm/dart_entry.h"
11#include "vm/instructions.h"
12#include "vm/native_entry.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
19namespace dart {
20
21#define __ assembler->
22
23ASSEMBLER_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 FunctionType& signature = FunctionType::ZoneHandle(FunctionType::New());
32 const Function& function = Function::Handle(Function::New(
33 signature, function_name, UntaggedFunction::kRegularFunction, true, false,
34 false, false, false, owner_class, TokenPosition::kNoSource));
35
36 const String& target_name =
37 String::Handle(Symbols::New(thread, "targetFunction"));
38 const intptr_t kTypeArgsLen = 0;
39 const intptr_t kNumArgs = 1;
40 const Array& args_descriptor = Array::Handle(ArgumentsDescriptor::NewBoxed(
41 kTypeArgsLen, kNumArgs, Object::null_array()));
42 const ICData& ic_data = ICData::ZoneHandle(ICData::New(
43 function, target_name, args_descriptor, 15, 1, ICData::kInstance));
44
45 // Code accessing pp is generated, but not executed. Uninitialized pp is OK.
46 __ set_constant_pool_allowed(true);
47
48 __ LoadObject(RBX, ic_data);
49 __ CallPatchable(StubCode::OneArgCheckInlineCache());
50 __ ret();
51}
52
53ASSEMBLER_TEST_RUN(IcDataAccess, test) {
54 uword end = test->payload_start() + test->code().Size();
55 uword return_address = end - 1; // sizeof(ret)
56 ICData& ic_data = ICData::Handle();
57 CodePatcher::GetInstanceCallAt(return_address, test->code(), &ic_data);
58 EXPECT_STREQ("targetFunction",
59 String::Handle(ic_data.target_name()).ToCString());
60 EXPECT_EQ(1, ic_data.NumArgsTested());
61 EXPECT_EQ(0, ic_data.NumberOfChecks());
62}
63
64} // namespace dart
65
66#endif // TARGET_ARCH_X64
#define __
static ArrayPtr NewBoxed(intptr_t type_args_len, intptr_t num_arguments, const Array &optional_arguments_names, Heap::Space space=Heap::kOld)
Definition: dart_entry.h:83
static ClassPtr New(IsolateGroup *isolate_group, bool register_class=true)
Definition: object.cc:3053
static CodePtr GetInstanceCallAt(uword return_address, const Code &caller_code, Object *data)
static FunctionTypePtr New(intptr_t num_parent_type_arguments=0, Nullability nullability=Nullability::kNonNullable, Heap::Space space=Heap::kOld)
Definition: object.cc:11631
static FunctionPtr New(const FunctionType &signature, const String &name, UntaggedFunction::Kind kind, bool is_static, bool is_const, bool is_abstract, bool is_external, bool is_native, const Object &owner, TokenPosition token_pos, Heap::Space space=Heap::kOld)
Definition: object.cc:10243
virtual const char * ToCString() const
Definition: object.h:366
static Object & Handle()
Definition: object.h:407
static Object & ZoneHandle()
Definition: object.h:419
static StringPtr New(Thread *thread, const char *cstr)
Definition: symbols.h:723
static Thread * Current()
Definition: thread.h:362
glong glong end
Dart_NativeFunction function
Definition: fuchsia.cc:51
Definition: dart_vm.cc:33
const char *const class_name
uintptr_t uword
Definition: globals.h:501
ASSEMBLER_TEST_RUN(StoreIntoObject, test)
const char *const function_name
#define ASSEMBLER_TEST_GENERATE(name, assembler)
Definition: unit_test.h:89