Flutter Engine
The Flutter Engine
code_patcher_riscv_test.cc
Go to the documentation of this file.
1// Copyright (c) 2021, 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_RISCV32) || defined(TARGET_ARCH_RISCV64)
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 const Code& stub = StubCode::OneArgCheckInlineCache();
45
46 // Code is generated, but not executed. Just parsed with CodePatcher.
47 __ set_constant_pool_allowed(true); // Uninitialized pp is OK.
48 __ LoadUniqueObject(IC_DATA_REG, ic_data);
49 __ LoadUniqueObject(CODE_REG, stub);
50 __ Call(compiler::FieldAddress(
51 CODE_REG, Code::entry_point_offset(Code::EntryKind::kMonomorphic)));
52 __ ret();
53}
54
55ASSEMBLER_TEST_RUN(IcDataAccess, test) {
56 uword end = test->payload_start() + test->code().Size();
57 uword return_address = end - CInstr::kInstrSize;
58 ICData& ic_data = ICData::Handle();
59 CodePatcher::GetInstanceCallAt(return_address, test->code(), &ic_data);
60 EXPECT_STREQ("targetFunction",
61 String::Handle(ic_data.target_name()).ToCString());
62 EXPECT_EQ(1, ic_data.NumArgsTested());
63 EXPECT_EQ(0, ic_data.NumberOfChecks());
64}
65
66} // namespace dart
67
68#endif // defined TARGET_ARCH_RISCV
#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 constexpr uint32_t kInstrSize
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 intptr_t entry_point_offset(EntryKind kind=EntryKind::kNormal)
Definition: object.h:6793
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
const Register CODE_REG
ASSEMBLER_TEST_RUN(StoreIntoObject, test)
const Register IC_DATA_REG
const char *const function_name
#define ASSEMBLER_TEST_GENERATE(name, assembler)
Definition: unit_test.h:89