Commit 2276e95a authored by Clemens Backes's avatar Clemens Backes Committed by V8 LUCI CQ

Revert "[factory] Make NewByteArray return canonical empty byte array"

This reverts commit 8d3c8093.

Reason for revert: Fails on UBSan (nullptr on memcpy): https://ci.chromium.org/ui/p/v8/builders/ci/V8%20Linux64%20UBSan/17246/overview

Original change's description:
> [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/+/3009225
> Reviewed-by: Leszek Swirski <leszeks@chromium.org>
> Commit-Queue: Georg Neis <neis@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#75629}

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