Flutter Engine
The Flutter Engine
stub_code.h
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#ifndef RUNTIME_VM_STUB_CODE_H_
6#define RUNTIME_VM_STUB_CODE_H_
7
8#include "vm/allocation.h"
10#include "vm/object.h"
11#include "vm/stub_code_list.h"
12
13#if !defined(DART_PRECOMPILED_RUNTIME)
16#endif // !defined(DART_PRECOMPILED_RUNTIME)
17
18namespace dart {
19
20// Forward declarations.
21class Code;
22class Isolate;
23class ObjectPointerVisitor;
24
25// Is it permitted for the stubs above to refer to Object::null(), which is
26// allocated in the VM isolate and shared across all isolates.
27// However, in cases where a simple GC-safe placeholder is needed on the stack,
28// using Smi 0 instead of Object::null() is slightly more efficient, since a Smi
29// does not require relocation.
30
31// class StubCode is used to maintain the lifecycle of stubs.
32class StubCode : public AllStatic {
33 public:
34 // Generate all stubs which are shared across all isolates, this is done
35 // only once and the stub code resides in the vm_isolate heap.
36 static void Init();
37
38 static void Cleanup();
39
40 // Returns true if stub code has been initialized.
41 static bool HasBeenInitialized() {
42 return initialized_.load(std::memory_order_acquire);
43 }
44 static void InitializationDone() {
45 initialized_.store(true, std::memory_order_release);
46 }
47
48 // Check if specified pc is in the dart invocation stub used for
49 // transitioning into dart code.
50 static bool InInvocationStub(uword pc);
51
52 // Check if the specified pc is in the jump to frame stub.
53 static bool InJumpToFrameStub(uword pc);
54
55 // Returns nullptr if no stub found.
56 static const char* NameOfStub(uword entry_point);
57
58// Define the shared stub code accessors.
59#define STUB_CODE_ACCESSOR(name) \
60 static const Code& name() { return *entries_[k##name##Index].code; } \
61 static intptr_t name##Size() { return name().Size(); }
63#undef STUB_CODE_ACCESSOR
64
65#if !defined(DART_PRECOMPILED_RUNTIME)
66 static const Code& SubtypeTestCacheStubForUsedInputs(intptr_t i) {
67 switch (i) {
68 case 1:
69 return StubCode::Subtype1TestCache();
70 case 2:
71 return StubCode::Subtype2TestCache();
72 case 3:
73 return StubCode::Subtype3TestCache();
74 case 4:
75 return StubCode::Subtype4TestCache();
76 case 6:
77 return StubCode::Subtype6TestCache();
78 case 7:
79 return StubCode::Subtype7TestCache();
80 default:
82 return StubCode::Subtype7TestCache();
83 }
84 }
85 static CodePtr GetAllocationStubForClass(const Class& cls);
86 static CodePtr GetAllocationStubForTypedData(classid_t class_id);
87#endif // !defined(DART_PRECOMPILED_RUNTIME)
88
89#if !defined(DART_PRECOMPILED_RUNTIME)
90 // Generate the stub and finalize the generated code into the stub
91 // code executable area.
92 static CodePtr Generate(const char* name,
93 compiler::ObjectPoolBuilder* object_pool_builder,
94 void (compiler::StubCodeCompiler::* GenerateStub)());
95#endif // !defined(DART_PRECOMPILED_RUNTIME)
96
97 static const Code& UnoptimizedStaticCallEntry(intptr_t num_args_tested);
98
99 static const char* NameAt(intptr_t index) { return entries_[index].name; }
100
101 static const Code& EntryAt(intptr_t index) { return *(entries_[index].code); }
102 static void EntryAtPut(intptr_t index, Code* entry) {
103 DEBUG_ASSERT(entry->IsReadOnlyHandle());
104 ASSERT(entries_[index].code == nullptr);
105 entries_[index].code = entry;
106 }
107 static intptr_t NumEntries() { return kNumStubEntries; }
108
109#if !defined(DART_PRECOMPILED_RUNTIME)
110#define GENERATE_STUB(name) \
111 static CodePtr BuildIsolateSpecific##name##Stub( \
112 compiler::ObjectPoolBuilder* opw) { \
113 return StubCode::Generate( \
114 "_iso_stub_" #name, opw, \
115 &compiler::StubCodeCompiler::Generate##name##Stub); \
116 }
118#undef GENERATE_STUB
119#endif // !defined(DART_PRECOMPILED_RUNTIME)
120
121 private:
123
124 enum {
125#define STUB_CODE_ENTRY(name) k##name##Index,
127#undef STUB_CODE_ENTRY
128 kNumStubEntries
129 };
130
131 struct StubCodeEntry {
132 Code* code;
133 const char* name;
134#if !defined(DART_PRECOMPILED_RUNTIME)
135 void (compiler::StubCodeCompiler::* generator)();
136#endif
137 };
138 static StubCodeEntry entries_[kNumStubEntries];
139 static AcqRelAtomic<bool> initialized_;
140};
141
142} // namespace dart
143
144#endif // RUNTIME_VM_STUB_CODE_H_
#define UNREACHABLE()
Definition: assert.h:248
#define DEBUG_ASSERT(cond)
Definition: assert.h:321
T load(std::memory_order order=std::memory_order_acquire) const
Definition: atomic.h:101
void store(T arg, std::memory_order order=std::memory_order_release)
Definition: atomic.h:104
static CodePtr GetAllocationStubForClass(const Class &cls)
Definition: stub_code.cc:174
static void Init()
Definition: stub_code.cc:46
static const Code & UnoptimizedStaticCallEntry(intptr_t num_args_tested)
Definition: stub_code.cc:316
VM_STUB_CODE_LIST(GENERATE_STUB)
static CodePtr GetAllocationStubForTypedData(classid_t class_id)
Definition: stub_code.cc:279
static const char * NameOfStub(uword entry_point)
Definition: stub_code.cc:330
static const Code & EntryAt(intptr_t index)
Definition: stub_code.h:101
static bool HasBeenInitialized()
Definition: stub_code.h:41
static const Code & SubtypeTestCacheStubForUsedInputs(intptr_t i)
Definition: stub_code.h:66
static CodePtr Generate(const char *name, compiler::ObjectPoolBuilder *object_pool_builder, void(compiler::StubCodeCompiler::*GenerateStub)())
Definition: stub_code.cc:93
static const char * NameAt(intptr_t index)
Definition: stub_code.h:99
static void InitializationDone()
Definition: stub_code.h:44
static bool InInvocationStub(uword pc)
Definition: stub_code.cc:132
static intptr_t NumEntries()
Definition: stub_code.h:107
static void Cleanup()
Definition: stub_code.cc:124
static void EntryAtPut(intptr_t index, Code *entry)
Definition: stub_code.h:102
VM_STUB_CODE_LIST(STUB_CODE_ACCESSOR)
static bool InJumpToFrameStub(uword pc)
Definition: stub_code.cc:139
#define ASSERT(E)
Definition: dart_vm.cc:33
const char *const name
int32_t classid_t
Definition: globals.h:524
uintptr_t uword
Definition: globals.h:501
#define GENERATE_STUB(name)
Definition: stub_code.h:110
#define STUB_CODE_ENTRY(name)
Definition: stub_code.h:125
#define STUB_CODE_ACCESSOR(name)
Definition: stub_code.h:59