Skip to content

Commit 17fff9b

Browse files
victoragnezcommit-bot@chromium.org
authored andcommitted
[vm] Generate different offsets for dart_precompiled_runtime
Some raw objects have fields that do not exist in dart_precompiled_runtime, making the instance size of such objects smaller. The offsets extractor should therefore generate different offsets for the precompiled runtime in order to reflect those differences. Change-Id: I367e20744fe5b2f8ffaba03bd19b2c74a422c750 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/133064 Reviewed-by: Martin Kustermann <[email protected]> Commit-Queue: Victor Agnez Lima <[email protected]>
1 parent cdeb9a7 commit 17fff9b

File tree

6 files changed

+1321
-9
lines changed

6 files changed

+1321
-9
lines changed

runtime/vm/BUILD.gn

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,3 +196,16 @@ executable("offsets_extractor") {
196196
]
197197
include_dirs = [ ".." ]
198198
}
199+
200+
executable("offsets_extractor_precompiled_runtime") {
201+
configs += [
202+
"..:dart_arch_config",
203+
"..:dart_config",
204+
"..:dart_precompiled_runtime_config",
205+
":libdart_vm_config",
206+
]
207+
sources = [
208+
"compiler/offsets_extractor.cc",
209+
]
210+
include_dirs = [ ".." ]
211+
}

runtime/vm/compiler/offsets_extractor.cc

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,55 @@ void Assert::Fail(const char* format, ...) {
3737
class OffsetsExtractor : public AllStatic {
3838
public:
3939
static void DumpOffsets() {
40+
#if defined(DART_PRECOMPILED_RUNTIME)
41+
42+
#define PRINT_FIELD_OFFSET(Class, Name) \
43+
std::cout << "static constexpr dart::compiler::target::word AOT_" #Class \
44+
"_" #Name " = " \
45+
<< Class::Name() << ";\n";
46+
47+
#define PRINT_ARRAY_LAYOUT(Class, Name) \
48+
std::cout << "static constexpr dart::compiler::target::word AOT_" #Class \
49+
"_elements_start_offset = " \
50+
<< Class::ArrayLayout::elements_start_offset() << ";\n"; \
51+
std::cout << "static constexpr dart::compiler::target::word AOT_" #Class \
52+
"_element_size = " \
53+
<< Class::ArrayLayout::kElementSize << ";\n";
54+
55+
#define PRINT_ARRAY_STRUCTFIELD_OFFSET(Class, Name, ElementOffsetName, \
56+
FieldOffset)
57+
58+
#define PRINT_SIZEOF(Class, Name, What) \
59+
std::cout << "static constexpr dart::compiler::target::word AOT_" #Class \
60+
"_" #Name " = " \
61+
<< sizeof(What) << ";\n";
62+
63+
#define PRINT_RANGE(Class, Name, Type, First, Last, Filter) \
64+
{ \
65+
auto filter = Filter; \
66+
bool comma = false; \
67+
std::cout << "static constexpr dart::compiler::target::word AOT_" #Class \
68+
"_" #Name "[] = {"; \
69+
for (intptr_t i = static_cast<intptr_t>(First); \
70+
i <= static_cast<intptr_t>(Last); i++) { \
71+
auto v = static_cast<Type>(i); \
72+
std::cout << (comma ? ", " : "") << (filter(v) ? Class::Name(v) : -1); \
73+
comma = true; \
74+
} \
75+
std::cout << "};\n"; \
76+
}
77+
78+
#define PRINT_CONSTANT(Class, Name) \
79+
std::cout << "static constexpr dart::compiler::target::word AOT_" #Class \
80+
"_" #Name " = " \
81+
<< Class::Name << ";\n";
82+
83+
#define PRECOMP_NO_CHECK(Code)
84+
85+
#define PRECOMP_CALCULATE(Code) Code
86+
87+
#else // defined(DART_PRECOMPILED_RUNTIME)
88+
4089
#define PRINT_FIELD_OFFSET(Class, Name) \
4190
std::cout << "static constexpr dart::compiler::target::word " #Class \
4291
"_" #Name " = " \
@@ -80,9 +129,14 @@ class OffsetsExtractor : public AllStatic {
80129

81130
#define PRECOMP_NO_CHECK(Code) Code
82131

83-
OFFSETS_LIST(PRINT_FIELD_OFFSET, PRINT_ARRAY_LAYOUT,
84-
PRINT_ARRAY_STRUCTFIELD_OFFSET, PRINT_SIZEOF, PRINT_RANGE,
85-
PRINT_CONSTANT, PRECOMP_NO_CHECK)
132+
#define PRECOMP_CALCULATE(Code) Code
133+
134+
#endif // defined(DART_PRECOMPILED_RUNTIME)
135+
136+
OFFSETS_LIST_EXTENDED(PRINT_FIELD_OFFSET, PRINT_ARRAY_LAYOUT,
137+
PRINT_ARRAY_STRUCTFIELD_OFFSET, PRINT_SIZEOF,
138+
PRINT_RANGE, PRINT_CONSTANT, PRECOMP_NO_CHECK,
139+
PRECOMP_CALCULATE)
86140

87141
#undef PRINT_FIELD_OFFSET
88142
#undef PRINT_ARRAY_LAYOUT
@@ -98,7 +152,9 @@ class OffsetsExtractor : public AllStatic {
98152

99153
int main(int argc, char* argv[]) {
100154
std::cout << "#if " << ARCH_DEF << std::endl;
155+
#if !defined(TARGET_ARCH_IA32) || !defined(DART_PRECOMPILED_RUNTIME)
101156
dart::OffsetsExtractor::DumpOffsets();
157+
#endif
102158
std::cout << "#endif // " << ARCH_DEF << std::endl;
103159
return 0;
104160
}

runtime/vm/compiler/runtime_api.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,9 +469,20 @@ word Context::variable_offset(word n) {
469469
return element_offset(index) + field_offset; \
470470
}
471471

472+
#if defined(TARGET_ARCH_IA32)
473+
472474
#define DEFINE_SIZEOF(clazz, name, what) \
473475
word clazz::name() { return clazz##_##name; }
474476

477+
#else
478+
479+
#define DEFINE_SIZEOF(clazz, name, what) \
480+
word clazz::name() { \
481+
return FLAG_precompiled_mode ? AOT_##clazz##_##name : clazz##_##name; \
482+
}
483+
484+
#endif // defined(TARGET_ARCH_IA32)
485+
475486
#define DEFINE_RANGE(Class, Getter, Type, First, Last, Filter) \
476487
word Class::Getter(Type index) { \
477488
return Class##_##Getter[static_cast<intptr_t>(index) - \

0 commit comments

Comments
 (0)