Commit 3d2f61fb authored by Camillo Bruni's avatar Camillo Bruni Committed by Commit Bot

[factory] Consistently skip write barriers where possible in factory.cc

Bug: v8:11263
Change-Id: Ia98fc29c52e68ba3a7dcdcdc1a06ce1192b10f93
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2787487Reviewed-by: 's avatarOmer Katz <omerkatz@chromium.org>
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#73754}
parent de5f8614
......@@ -72,6 +72,7 @@ Handle<AccessorPair> FactoryBase<Impl>::NewAccessorPair() {
Handle<AccessorPair> accessors = Handle<AccessorPair>::cast(
NewStruct(ACCESSOR_PAIR_TYPE, AllocationType::kOld));
AccessorPair raw = *accessors;
DisallowGarbageCollection no_gc;
raw.set_getter(read_only_roots().null_value(), SKIP_WRITE_BARRIER);
raw.set_setter(read_only_roots().null_value(), SKIP_WRITE_BARRIER);
return accessors;
......@@ -396,8 +397,10 @@ FactoryBase<Impl>::NewArrayBoilerplateDescription(
Handle<ArrayBoilerplateDescription> result =
Handle<ArrayBoilerplateDescription>::cast(
NewStruct(ARRAY_BOILERPLATE_DESCRIPTION_TYPE, AllocationType::kOld));
result->set_elements_kind(elements_kind);
result->set_constant_elements(*constant_values);
DisallowGarbageCollection no_gc;
ArrayBoilerplateDescription raw = *result;
raw.set_elements_kind(elements_kind);
raw.set_constant_elements(*constant_values);
return result;
}
......@@ -409,9 +412,11 @@ FactoryBase<Impl>::NewRegExpBoilerplateDescription(Handle<FixedArray> data,
Handle<RegExpBoilerplateDescription> result =
Handle<RegExpBoilerplateDescription>::cast(NewStruct(
REG_EXP_BOILERPLATE_DESCRIPTION_TYPE, AllocationType::kOld));
result->set_data(*data);
result->set_source(*source);
result->set_flags(flags.value());
DisallowGarbageCollection no_gc;
RegExpBoilerplateDescription raw = *result;
raw.set_data(*data);
raw.set_source(*source);
raw.set_flags(flags.value());
return result;
}
......@@ -424,8 +429,10 @@ FactoryBase<Impl>::NewTemplateObjectDescription(
Handle<TemplateObjectDescription> result =
Handle<TemplateObjectDescription>::cast(
NewStruct(TEMPLATE_OBJECT_DESCRIPTION_TYPE, AllocationType::kOld));
result->set_raw_strings(*raw_strings);
result->set_cooked_strings(*cooked_strings);
DisallowGarbageCollection no_gc;
TemplateObjectDescription raw = *result;
raw.set_raw_strings(*raw_strings);
raw.set_cooked_strings(*cooked_strings);
return result;
}
......@@ -434,19 +441,18 @@ Handle<FeedbackMetadata> FactoryBase<Impl>::NewFeedbackMetadata(
int slot_count, int create_closure_slot_count, AllocationType allocation) {
DCHECK_LE(0, slot_count);
int size = FeedbackMetadata::SizeFor(slot_count);
HeapObject result = AllocateRawWithImmortalMap(
size, allocation, read_only_roots().feedback_metadata_map());
Handle<FeedbackMetadata> data(FeedbackMetadata::cast(result), isolate());
data->set_slot_count(slot_count);
data->set_create_closure_slot_count(create_closure_slot_count);
FeedbackMetadata result = FeedbackMetadata::cast(AllocateRawWithImmortalMap(
size, allocation, read_only_roots().feedback_metadata_map()));
result.set_slot_count(slot_count);
result.set_create_closure_slot_count(create_closure_slot_count);
// Initialize the data section to 0.
int data_size = size - FeedbackMetadata::kHeaderSize;
Address data_start = data->address() + FeedbackMetadata::kHeaderSize;
Address data_start = result.address() + FeedbackMetadata::kHeaderSize;
memset(reinterpret_cast<byte*>(data_start), 0, data_size);
// Fields have been zeroed out but not initialized, so this object will not
// pass object verification at this point.
return data;
return handle(result, isolate());
}
template <typename Impl>
......@@ -456,17 +462,14 @@ Handle<CoverageInfo> FactoryBase<Impl>::NewCoverageInfo(
int size = CoverageInfo::SizeFor(slot_count);
Map map = read_only_roots().coverage_info_map();
HeapObject result =
AllocateRawWithImmortalMap(size, AllocationType::kOld, map);
Handle<CoverageInfo> info(CoverageInfo::cast(result), isolate());
info->set_slot_count(slot_count);
CoverageInfo info = CoverageInfo::cast(
AllocateRawWithImmortalMap(size, AllocationType::kOld, map));
info.set_slot_count(slot_count);
for (int i = 0; i < slot_count; i++) {
SourceRange range = slots[i];
info->InitializeSlot(i, range.start, range.end);
info.InitializeSlot(i, range.start, range.end);
}
return info;
return handle(info, isolate());
}
template <typename Impl>
......@@ -677,7 +680,6 @@ Handle<String> FactoryBase<Impl>::NewConsString(Handle<String> left,
DisallowGarbageCollection no_gc;
WriteBarrierMode mode = result.GetWriteBarrierMode(no_gc);
result.set_raw_hash_field(String::kEmptyHashField);
result.set_length(length);
result.set_first(*left, mode);
......@@ -852,6 +854,7 @@ HeapObject FactoryBase<Impl>::AllocateRawWithImmortalMap(
// noone does so this check is sufficient.
DCHECK(ReadOnlyHeap::Contains(map));
HeapObject result = AllocateRaw(size, allocation, alignment);
DisallowGarbageCollection no_gc;
result.set_map_after_allocation(map, SKIP_WRITE_BARRIER);
return result;
}
......@@ -885,11 +888,11 @@ FactoryBase<Impl>::NewSwissNameDictionaryWithCapacity(
Map map = read_only_roots().swiss_name_dictionary_map();
int size = SwissNameDictionary::SizeFor(capacity);
HeapObject result = AllocateRawWithImmortalMap(size, allocation, map);
Handle<SwissNameDictionary> table(SwissNameDictionary::cast(result),
isolate());
table->Initialize(isolate(), *meta_table, capacity);
return table;
SwissNameDictionary table = SwissNameDictionary::cast(
AllocateRawWithImmortalMap(size, allocation, map));
DisallowGarbageCollection no_gc;
table.Initialize(isolate(), *meta_table, capacity);
return handle(table, isolate());
}
template <typename Impl>
......
This diff is collapsed.
......@@ -66,8 +66,8 @@ V8_INLINE void Context::set(int index, Object value, WriteBarrierMode mode) {
set_elements(index, value, mode);
}
void Context::set_scope_info(ScopeInfo scope_info) {
set(SCOPE_INFO_INDEX, scope_info);
void Context::set_scope_info(ScopeInfo scope_info, WriteBarrierMode mode) {
set(SCOPE_INFO_INDEX, scope_info, mode);
}
Object Context::synchronized_get(int index) const {
......@@ -96,7 +96,9 @@ Context Context::previous() {
DCHECK(IsBootstrappingOrValidParentContext(result, *this));
return Context::unchecked_cast(result);
}
void Context::set_previous(Context context) { set(PREVIOUS_INDEX, context); }
void Context::set_previous(Context context, WriteBarrierMode mode) {
set(PREVIOUS_INDEX, context, mode);
}
Object Context::next_context_link() { return get(Context::NEXT_CONTEXT_LINK); }
......@@ -109,9 +111,9 @@ HeapObject Context::extension() {
return HeapObject::cast(get(EXTENSION_INDEX));
}
void Context::set_extension(HeapObject object) {
void Context::set_extension(HeapObject object, WriteBarrierMode mode) {
DCHECK(scope_info().HasContextExtensionSlot());
set(EXTENSION_INDEX, object);
set(EXTENSION_INDEX, object, mode);
}
NativeContext Context::native_context() const {
......
......@@ -517,17 +517,20 @@ class Context : public TorqueGeneratedContext<Context, HeapObject> {
static const int kInvalidContext = 1;
// Direct slot access.
inline void set_scope_info(ScopeInfo scope_info);
inline void set_scope_info(ScopeInfo scope_info,
WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
inline Object unchecked_previous();
inline Context previous();
inline void set_previous(Context context);
inline void set_previous(Context context,
WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
inline Object next_context_link();
inline bool has_extension();
inline HeapObject extension();
inline void set_extension(HeapObject object);
inline void set_extension(HeapObject object,
WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
JSObject extension_object();
JSReceiver extension_receiver();
V8_EXPORT_PRIVATE ScopeInfo scope_info();
......
......@@ -200,10 +200,10 @@ NativeContext JSFunction::native_context() {
return context().native_context();
}
void JSFunction::set_context(HeapObject value) {
void JSFunction::set_context(HeapObject value, WriteBarrierMode mode) {
DCHECK(value.IsUndefined() || value.IsContext());
WRITE_FIELD(*this, kContextOffset, value);
WRITE_BARRIER(*this, kContextOffset, value);
CONDITIONAL_WRITE_BARRIER(*this, kContextOffset, value, mode);
}
ACCESSORS_CHECKED(JSFunction, prototype_or_initial_map, HeapObject,
......
......@@ -70,7 +70,8 @@ class JSFunction : public JSFunctionOrBoundFunction {
// [context]: The context for this function.
inline Context context();
inline bool has_context() const;
inline void set_context(HeapObject context);
inline void set_context(HeapObject context,
WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
inline JSGlobalProxy global_proxy();
inline NativeContext native_context();
inline int length();
......
......@@ -855,9 +855,9 @@ String RegExpMatchInfo::LastSubject() {
return String::cast(get(kLastSubjectIndex));
}
void RegExpMatchInfo::SetLastSubject(String value) {
void RegExpMatchInfo::SetLastSubject(String value, WriteBarrierMode mode) {
DCHECK_GE(length(), kLastMatchOverhead);
set(kLastSubjectIndex, value);
set(kLastSubjectIndex, value, mode);
}
Object RegExpMatchInfo::LastInput() {
......@@ -865,9 +865,9 @@ Object RegExpMatchInfo::LastInput() {
return get(kLastInputIndex);
}
void RegExpMatchInfo::SetLastInput(Object value) {
void RegExpMatchInfo::SetLastInput(Object value, WriteBarrierMode mode) {
DCHECK_GE(length(), kLastMatchOverhead);
set(kLastInputIndex, value);
set(kLastInputIndex, value, mode);
}
int RegExpMatchInfo::Capture(int i) {
......
......@@ -37,11 +37,13 @@ class V8_EXPORT_PRIVATE RegExpMatchInfo : NON_EXPORTED_BASE(public FixedArray) {
// Returns the subject string of the last match.
inline String LastSubject();
inline void SetLastSubject(String value);
inline void SetLastSubject(String value,
WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
// Like LastSubject, but modifiable by the user.
inline Object LastInput();
inline void SetLastInput(Object value);
inline void SetLastInput(Object value,
WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
// Returns the i'th capture index, 0 <= i < NumberOfCaptures(). Capture(0) and
// Capture(1) determine the start- and endpoint of the match itself.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment