Commit 8d3c8093 authored by Georg Neis's avatar Georg Neis Committed by V8 LUCI CQ

[factory] Make NewByteArray return canonical empty byte array

... for length = 0, analogously to what e.g. NewFixedArray does.

Simplify some call sites that had special handling for this case
(there are others that didn't).

Change-Id: Ib3de5506300e967aca072fad53df7ab04ef68839
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3009225Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Commit-Queue: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75629}
parent 9a914dd9
...@@ -60,7 +60,6 @@ namespace baseline { ...@@ -60,7 +60,6 @@ namespace baseline {
template <typename IsolateT> template <typename IsolateT>
Handle<ByteArray> BytecodeOffsetTableBuilder::ToBytecodeOffsetTable( Handle<ByteArray> BytecodeOffsetTableBuilder::ToBytecodeOffsetTable(
IsolateT* isolate) { IsolateT* isolate) {
if (bytes_.empty()) return isolate->factory()->empty_byte_array();
Handle<ByteArray> table = isolate->factory()->NewByteArray( Handle<ByteArray> table = isolate->factory()->NewByteArray(
static_cast<int>(bytes_.size()), AllocationType::kOld); static_cast<int>(bytes_.size()), AllocationType::kOld);
MemCopy(table->GetDataStartAddress(), bytes_.data(), bytes_.size()); MemCopy(table->GetDataStartAddress(), bytes_.data(), bytes_.size());
......
...@@ -173,9 +173,7 @@ void SourcePositionTableBuilder::AddEntry(const PositionTableEntry& entry) { ...@@ -173,9 +173,7 @@ void SourcePositionTableBuilder::AddEntry(const PositionTableEntry& entry) {
template <typename IsolateT> template <typename IsolateT>
Handle<ByteArray> SourcePositionTableBuilder::ToSourcePositionTable( Handle<ByteArray> SourcePositionTableBuilder::ToSourcePositionTable(
IsolateT* isolate) { IsolateT* isolate) {
if (bytes_.empty()) return isolate->factory()->empty_byte_array();
DCHECK(!Omit()); DCHECK(!Omit());
Handle<ByteArray> table = isolate->factory()->NewByteArray( Handle<ByteArray> table = isolate->factory()->NewByteArray(
static_cast<int>(bytes_.size()), AllocationType::kOld); static_cast<int>(bytes_.size()), AllocationType::kOld);
MemCopy(table->GetDataStartAddress(), bytes_.data(), bytes_.size()); MemCopy(table->GetDataStartAddress(), bytes_.data(), bytes_.size());
......
...@@ -983,10 +983,6 @@ Handle<PodArray<InliningPosition>> CreateInliningPositions( ...@@ -983,10 +983,6 @@ Handle<PodArray<InliningPosition>> CreateInliningPositions(
OptimizedCompilationInfo* info, Isolate* isolate) { OptimizedCompilationInfo* info, Isolate* isolate) {
const OptimizedCompilationInfo::InlinedFunctionList& inlined_functions = const OptimizedCompilationInfo::InlinedFunctionList& inlined_functions =
info->inlined_functions(); info->inlined_functions();
if (inlined_functions.size() == 0) {
return Handle<PodArray<InliningPosition>>::cast(
isolate->factory()->empty_byte_array());
}
Handle<PodArray<InliningPosition>> inl_positions = Handle<PodArray<InliningPosition>> inl_positions =
PodArray<InliningPosition>::New( PodArray<InliningPosition>::New(
isolate, static_cast<int>(inlined_functions.size()), isolate, static_cast<int>(inlined_functions.size()),
......
...@@ -170,6 +170,7 @@ Handle<ByteArray> FactoryBase<Impl>::NewByteArray(int length, ...@@ -170,6 +170,7 @@ Handle<ByteArray> FactoryBase<Impl>::NewByteArray(int length,
FATAL("Fatal JavaScript invalid size error %d", length); FATAL("Fatal JavaScript invalid size error %d", length);
UNREACHABLE(); UNREACHABLE();
} }
if (length == 0) return impl()->empty_byte_array();
int size = ByteArray::SizeFor(length); int size = ByteArray::SizeFor(length);
HeapObject result = AllocateRawWithImmortalMap( HeapObject result = AllocateRawWithImmortalMap(
size, allocation, read_only_roots().byte_array_map()); size, allocation, read_only_roots().byte_array_map());
......
...@@ -115,15 +115,17 @@ class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) FactoryBase ...@@ -115,15 +115,17 @@ class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) FactoryBase
int length, AllocationType allocation = AllocationType::kYoung); int length, AllocationType allocation = AllocationType::kYoung);
// Allocates a weak fixed array-like object with given map and initialized // Allocates a weak fixed array-like object with given map and initialized
// with undefined values. // with undefined values. Length must be > 0.
Handle<WeakFixedArray> NewWeakFixedArrayWithMap( Handle<WeakFixedArray> NewWeakFixedArrayWithMap(
Map map, int length, AllocationType allocation = AllocationType::kYoung); Map map, int length, AllocationType allocation = AllocationType::kYoung);
// Allocates a fixed array which may contain in-place weak references. The // Allocates a fixed array which may contain in-place weak references. The
// array is initialized with undefined values // array is initialized with undefined values
// The function returns a pre-allocated empty weak fixed array for length = 0.
Handle<WeakFixedArray> NewWeakFixedArray( Handle<WeakFixedArray> NewWeakFixedArray(
int length, AllocationType allocation = AllocationType::kYoung); int length, AllocationType allocation = AllocationType::kYoung);
// The function returns a pre-allocated empty byte array for length = 0.
Handle<ByteArray> NewByteArray( Handle<ByteArray> NewByteArray(
int length, AllocationType allocation = AllocationType::kYoung); int length, AllocationType allocation = AllocationType::kYoung);
......
...@@ -89,6 +89,7 @@ inline void MemCopy(void* dest, const void* src, size_t size) { ...@@ -89,6 +89,7 @@ inline void MemCopy(void* dest, const void* src, size_t size) {
case N: \ case N: \
memcpy(dest, src, N); \ memcpy(dest, src, N); \
return; return;
CASE(0)
CASE(1) CASE(1)
CASE(2) CASE(2)
CASE(3) CASE(3)
......
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