Skip to content

Commit 31d4511

Browse files
sstricklcommit-bot@chromium.org
authored andcommitted
[vm/compiler] Fix handling of runtime offsets.
Before this, we had to use PRECOMP_NO_CHECK() for any entries that involved field offsets that came after NOT_IN_PRECOMPILED() fields, because the offsets would differ between JIT and AOT. That removed the check in dart.cc that the offsets match, but that just meant that precompiled code that used these offsets were wrong. One possible workaround is to just lift any field definitions whose offset might be used in precompiled code before any NOT_IN_PRECOMPILED() defined fields, but this means otherwise unnecessary changes in the Layout classes. Instead, just fix the runtime offset generation/retrieval by splitting the list of offsets into two parts: offsets common to all modes and offsets only valid in JIT mode. While this complicates the code that generates and imports these offsets, it ensures that our code generation actually uses the right offsets for the target mode. In addition, by doing this split we can add checks for uses of JIT-only offsets when in precompiled mode. Adding these checks found some uses of JIT-only field offsets in code compiled in precompiled mode. (These uses may have been benign if the stubs that included the uses were never called in the precompiled runtime, but now there's explicitly a check for precompiled mode around these uses.) Also remove the unused ARRAY_STRUCTFIELD type from offset lists. Change-Id: I083ab5997d3a5245b5f1487b614b62faee47d405 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/155780 Commit-Queue: Tess Strickland <[email protected]> Reviewed-by: Daco Harkes <[email protected]> Reviewed-by: Martin Kustermann <[email protected]>
1 parent ddfc484 commit 31d4511

8 files changed

+278
-96
lines changed

runtime/vm/compiler/offsets_extractor.cc

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ class OffsetsExtractor : public AllStatic {
5353
"_element_size = " \
5454
<< Class::ArrayTraits::kElementSize << ";\n";
5555

56-
#define PRINT_ARRAY_STRUCTFIELD_OFFSET(Class, Name, ElementOffsetName, \
57-
FieldOffset)
58-
5956
#define PRINT_SIZEOF(Class, Name, What) \
6057
std::cout << "static constexpr dart::compiler::target::word AOT_" #Class \
6158
"_" #Name " = " \
@@ -81,8 +78,6 @@ class OffsetsExtractor : public AllStatic {
8178
"_" #Name " = " \
8279
<< Class::Name << ";\n";
8380

84-
#define PRECOMP_NO_CHECK(Code)
85-
8681
#else // defined(DART_PRECOMPILED_RUNTIME)
8782

8883
#define PRINT_FIELD_OFFSET(Class, Name) \
@@ -98,9 +93,6 @@ class OffsetsExtractor : public AllStatic {
9893
"_element_size = " \
9994
<< Class::ArrayTraits::kElementSize << ";\n";
10095

101-
#define PRINT_ARRAY_STRUCTFIELD_OFFSET(Class, Name, ElementOffsetName, \
102-
FieldOffset)
103-
10496
#define PRINT_SIZEOF(Class, Name, What) \
10597
std::cout << "static constexpr dart::compiler::target::word " #Class \
10698
"_" #Name " = " \
@@ -126,21 +118,19 @@ class OffsetsExtractor : public AllStatic {
126118
"_" #Name " = " \
127119
<< Class::Name << ";\n";
128120

129-
#define PRECOMP_NO_CHECK(Code) Code
121+
JIT_OFFSETS_LIST(PRINT_FIELD_OFFSET, PRINT_ARRAY_LAYOUT, PRINT_SIZEOF,
122+
PRINT_RANGE, PRINT_CONSTANT)
130123

131124
#endif // defined(DART_PRECOMPILED_RUNTIME)
132125

133-
OFFSETS_LIST(PRINT_FIELD_OFFSET, PRINT_ARRAY_LAYOUT,
134-
PRINT_ARRAY_STRUCTFIELD_OFFSET, PRINT_SIZEOF, PRINT_RANGE,
135-
PRINT_CONSTANT, PRECOMP_NO_CHECK)
126+
COMMON_OFFSETS_LIST(PRINT_FIELD_OFFSET, PRINT_ARRAY_LAYOUT, PRINT_SIZEOF,
127+
PRINT_RANGE, PRINT_CONSTANT)
136128

137129
#undef PRINT_FIELD_OFFSET
138130
#undef PRINT_ARRAY_LAYOUT
139-
#undef PRINT_ARRAY_STRUCTFIELD_OFFSET
140131
#undef PRINT_SIZEOF
141132
#undef PRINT_RANGE
142133
#undef PRINT_CONSTANT
143-
#undef PRECOMP_NO_CHECK
144134
}
145135
};
146136

runtime/vm/compiler/runtime_api.cc

Lines changed: 95 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,10 @@ word Context::variable_offset(word n) {
508508
return TranslateOffsetInWords(dart::Context::variable_offset(n));
509509
}
510510

511+
#define DEFINE_CONSTANT(Class, Name) const word Class::Name = Class##_##Name;
512+
513+
#if defined(TARGET_ARCH_IA32)
514+
511515
#define DEFINE_FIELD(clazz, name) \
512516
word clazz::name() { return clazz##_##name; }
513517

@@ -516,50 +520,120 @@ word Context::variable_offset(word n) {
516520
return clazz##_elements_start_offset + index * clazz##_element_size; \
517521
}
518522

519-
#define DEFINE_ARRAY_STRUCTFIELD(clazz, name, element_offset, field_offset) \
520-
word clazz::name(intptr_t index) { \
521-
return element_offset(index) + field_offset; \
523+
#define DEFINE_SIZEOF(clazz, name, what) \
524+
word clazz::name() { return clazz##_##name; }
525+
526+
#define DEFINE_RANGE(Class, Getter, Type, First, Last, Filter) \
527+
word Class::Getter(Type index) { \
528+
return Class##_##Getter[static_cast<intptr_t>(index) - \
529+
static_cast<intptr_t>(First)]; \
522530
}
523531

524-
#if defined(TARGET_ARCH_IA32)
532+
JIT_OFFSETS_LIST(DEFINE_FIELD,
533+
DEFINE_ARRAY,
534+
DEFINE_SIZEOF,
535+
DEFINE_RANGE,
536+
DEFINE_CONSTANT)
525537

526-
#define DEFINE_SIZEOF(clazz, name, what) \
527-
word clazz::name() { return clazz##_##name; }
538+
COMMON_OFFSETS_LIST(DEFINE_FIELD,
539+
DEFINE_ARRAY,
540+
DEFINE_SIZEOF,
541+
DEFINE_RANGE,
542+
DEFINE_CONSTANT)
528543

529544
#else
530545

531-
#define DEFINE_SIZEOF(clazz, name, what) \
546+
#define DEFINE_JIT_FIELD(clazz, name) \
532547
word clazz::name() { \
533-
return FLAG_precompiled_mode ? AOT_##clazz##_##name : clazz##_##name; \
548+
if (FLAG_precompiled_mode) { \
549+
FATAL1("Use JIT-only field %s in precompiled mode", #clazz "::" #name); \
550+
} \
551+
return clazz##_##name; \
534552
}
535553

536-
#endif // defined(TARGET_ARCH_IA32)
554+
#define DEFINE_JIT_ARRAY(clazz, name) \
555+
word clazz::name(intptr_t index) { \
556+
if (FLAG_precompiled_mode) { \
557+
FATAL1("Use of JIT-only array %s in precompiled mode", \
558+
#clazz "::" #name); \
559+
} \
560+
return clazz##_elements_start_offset + index * clazz##_element_size; \
561+
}
537562

538-
#define DEFINE_RANGE(Class, Getter, Type, First, Last, Filter) \
563+
#define DEFINE_JIT_SIZEOF(clazz, name, what) \
564+
word clazz::name() { \
565+
if (FLAG_precompiled_mode) { \
566+
FATAL1("Use of JIT-only sizeof %s in precompiled mode", \
567+
#clazz "::" #name); \
568+
} \
569+
return clazz##_##name; \
570+
}
571+
572+
#define DEFINE_JIT_RANGE(Class, Getter, Type, First, Last, Filter) \
539573
word Class::Getter(Type index) { \
574+
if (FLAG_precompiled_mode) { \
575+
FATAL1("Use of JIT-only range %s in precompiled mode", \
576+
#Class "::" #Getter); \
577+
} \
540578
return Class##_##Getter[static_cast<intptr_t>(index) - \
541579
static_cast<intptr_t>(First)]; \
542580
}
543581

544-
#define DEFINE_CONSTANT(Class, Name) const word Class::Name = Class##_##Name;
582+
JIT_OFFSETS_LIST(DEFINE_JIT_FIELD,
583+
DEFINE_JIT_ARRAY,
584+
DEFINE_JIT_SIZEOF,
585+
DEFINE_JIT_RANGE,
586+
DEFINE_CONSTANT)
587+
588+
#undef DEFINE_JIT_FIELD
589+
#undef DEFINE_JIT_ARRAY
590+
#undef DEFINE_JIT_SIZEOF
591+
#undef DEFINE_JIT_RANGE
592+
593+
#define DEFINE_FIELD(clazz, name) \
594+
word clazz::name() { \
595+
return FLAG_precompiled_mode ? AOT_##clazz##_##name : clazz##_##name; \
596+
}
597+
598+
#define DEFINE_ARRAY(clazz, name) \
599+
word clazz::name(intptr_t index) { \
600+
if (FLAG_precompiled_mode) { \
601+
return AOT_##clazz##_elements_start_offset + \
602+
index * AOT_##clazz##_element_size; \
603+
} else { \
604+
return clazz##_elements_start_offset + index * clazz##_element_size; \
605+
} \
606+
}
545607

546-
#define PRECOMP_NO_CHECK(Code) Code
608+
#define DEFINE_SIZEOF(clazz, name, what) \
609+
word clazz::name() { \
610+
return FLAG_precompiled_mode ? AOT_##clazz##_##name : clazz##_##name; \
611+
}
547612

548-
OFFSETS_LIST(DEFINE_FIELD,
549-
DEFINE_ARRAY,
550-
DEFINE_ARRAY_STRUCTFIELD,
551-
DEFINE_SIZEOF,
552-
DEFINE_RANGE,
553-
DEFINE_CONSTANT,
554-
PRECOMP_NO_CHECK)
613+
#define DEFINE_RANGE(Class, Getter, Type, First, Last, Filter) \
614+
word Class::Getter(Type index) { \
615+
if (FLAG_precompiled_mode) { \
616+
return AOT_##Class##_##Getter[static_cast<intptr_t>(index) - \
617+
static_cast<intptr_t>(First)]; \
618+
} else { \
619+
return Class##_##Getter[static_cast<intptr_t>(index) - \
620+
static_cast<intptr_t>(First)]; \
621+
} \
622+
}
623+
624+
COMMON_OFFSETS_LIST(DEFINE_FIELD,
625+
DEFINE_ARRAY,
626+
DEFINE_SIZEOF,
627+
DEFINE_RANGE,
628+
DEFINE_CONSTANT)
629+
630+
#endif
555631

556632
#undef DEFINE_FIELD
557633
#undef DEFINE_ARRAY
558-
#undef DEFINE_ARRAY_STRUCTFIELD
559634
#undef DEFINE_SIZEOF
560635
#undef DEFINE_RANGE
561636
#undef DEFINE_CONSTANT
562-
#undef PRECOMP_NO_CHECK
563637

564638
const word StoreBufferBlock::kSize = dart::StoreBufferBlock::kSize;
565639

0 commit comments

Comments
 (0)