Commit 7e5b7ad1 authored by Jakob Kummerow's avatar Jakob Kummerow Committed by V8 LUCI CQ

[wasm][cleanup] Simplify array.init_from_data

We can simply trap in the runtime, instead of returning sentinels.

Bug: v8:7748, v8:12425
Change-Id: I179c8675fabd3cb730f002ba99ba8cf942a9d4ec
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3669108Reviewed-by: 's avatarManos Koukoutos <manoskouk@chromium.org>
Auto-Submit: Jakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80758}
parent cc8b4427
...@@ -5260,21 +5260,9 @@ Node* WasmGraphBuilder::ArrayInitFromData(const wasm::ArrayType* type, ...@@ -5260,21 +5260,9 @@ Node* WasmGraphBuilder::ArrayInitFromData(const wasm::ArrayType* type,
uint32_t data_segment, Node* offset, uint32_t data_segment, Node* offset,
Node* length, Node* rtt, Node* length, Node* rtt,
wasm::WasmCodePosition position) { wasm::WasmCodePosition position) {
Node* array = gasm_->CallBuiltin( return gasm_->CallBuiltin(
Builtin::kWasmArrayInitFromData, Operator::kNoDeopt | Operator::kNoThrow, Builtin::kWasmArrayInitFromData, Operator::kNoDeopt | Operator::kNoThrow,
gasm_->Uint32Constant(data_segment), offset, length, rtt); gasm_->Uint32Constant(data_segment), offset, length, rtt);
TrapIfTrue(wasm::kTrapArrayTooLarge,
gasm_->TaggedEqual(
array, gasm_->NumberConstant(
wasm::kArrayInitFromDataArrayTooLargeErrorCode)),
position);
TrapIfTrue(
wasm::kTrapDataSegmentOutOfBounds,
gasm_->TaggedEqual(
array, gasm_->NumberConstant(
wasm::kArrayInitFromDataSegmentOutOfBoundsErrorCode)),
position);
return array;
} }
Node* WasmGraphBuilder::RttCanon(uint32_t type_index) { Node* WasmGraphBuilder::RttCanon(uint32_t type_index) {
......
...@@ -713,10 +713,6 @@ RUNTIME_FUNCTION(Runtime_WasmArrayCopy) { ...@@ -713,10 +713,6 @@ RUNTIME_FUNCTION(Runtime_WasmArrayCopy) {
return ReadOnlyRoots(isolate).undefined_value(); return ReadOnlyRoots(isolate).undefined_value();
} }
// Returns
// - the new array if the operation succeeds,
// - Smi(0) if the requested array length is too large,
// - Smi(1) if the data segment ran out-of-bounds.
RUNTIME_FUNCTION(Runtime_WasmArrayInitFromData) { RUNTIME_FUNCTION(Runtime_WasmArrayInitFromData) {
ClearThreadInWasmScope flag_scope(isolate); ClearThreadInWasmScope flag_scope(isolate);
HandleScope scope(isolate); HandleScope scope(isolate);
...@@ -730,14 +726,15 @@ RUNTIME_FUNCTION(Runtime_WasmArrayInitFromData) { ...@@ -730,14 +726,15 @@ RUNTIME_FUNCTION(Runtime_WasmArrayInitFromData) {
uint32_t length_in_bytes = length * element_size; uint32_t length_in_bytes = length * element_size;
if (length > static_cast<uint32_t>(WasmArray::MaxLength(element_size))) { if (length > static_cast<uint32_t>(WasmArray::MaxLength(element_size))) {
return Smi::FromInt(wasm::kArrayInitFromDataArrayTooLargeErrorCode); return ThrowWasmError(isolate, MessageTemplate::kWasmTrapArrayTooLarge);
} }
// The check above implies no overflow. // The check above implies no overflow.
DCHECK_EQ(length_in_bytes / element_size, length); DCHECK_EQ(length_in_bytes / element_size, length);
if (!base::IsInBounds<uint32_t>( if (!base::IsInBounds<uint32_t>(
offset, length_in_bytes, offset, length_in_bytes,
instance->data_segment_sizes()[data_segment])) { instance->data_segment_sizes()[data_segment])) {
return Smi::FromInt(wasm::kArrayInitFromDataSegmentOutOfBoundsErrorCode); return ThrowWasmError(isolate,
MessageTemplate::kWasmTrapDataSegmentOutOfBounds);
} }
Address source = instance->data_segment_starts()[data_segment] + offset; Address source = instance->data_segment_starts()[data_segment] + offset;
......
...@@ -3329,6 +3329,8 @@ class LiftoffCompiler { ...@@ -3329,6 +3329,8 @@ class LiftoffCompiler {
return values; return values;
} }
// Call this after emitting a runtime call that can show up in a stack trace
// (e.g. because it can trap).
void RegisterDebugSideTableEntry( void RegisterDebugSideTableEntry(
FullDecoder* decoder, FullDecoder* decoder,
DebugSideTableBuilder::AssumeSpilling assume_spilling) { DebugSideTableBuilder::AssumeSpilling assume_spilling) {
...@@ -5563,20 +5565,11 @@ class LiftoffCompiler { ...@@ -5563,20 +5565,11 @@ class LiftoffCompiler {
}, },
decoder->position()); decoder->position());
LiftoffRegister result(kReturnRegister0); // Pop parameters from the value stack.
// Reuse the data segment register for error handling. __ cache_state()->stack_state.pop_back(3);
LiftoffRegister error_smi = data_segment_reg; RegisterDebugSideTableEntry(decoder, DebugSideTableBuilder::kDidSpill);
LoadSmi(error_smi, kArrayInitFromDataArrayTooLargeErrorCode);
Label* trap_label_array_too_large =
AddOutOfLineTrap(decoder, WasmCode::kThrowWasmTrapArrayTooLarge);
__ emit_cond_jump(kEqual, trap_label_array_too_large, kRef, result.gp(),
error_smi.gp());
LoadSmi(error_smi, kArrayInitFromDataSegmentOutOfBoundsErrorCode);
Label* trap_label_segment_out_of_bounds = AddOutOfLineTrap(
decoder, WasmCode::kThrowWasmTrapDataSegmentOutOfBounds);
__ emit_cond_jump(kEqual, trap_label_segment_out_of_bounds, kRef,
result.gp(), error_smi.gp());
LiftoffRegister result(kReturnRegister0);
__ PushRegister(kRef, result); __ PushRegister(kRef, result);
} }
......
...@@ -193,9 +193,6 @@ constexpr int kMaxPolymorphism = 4; ...@@ -193,9 +193,6 @@ constexpr int kMaxPolymorphism = 4;
constexpr int32_t kOSRTargetOffset = 5 * kSystemPointerSize; constexpr int32_t kOSRTargetOffset = 5 * kSystemPointerSize;
#endif #endif
constexpr Tagged_t kArrayInitFromDataArrayTooLargeErrorCode = 0;
constexpr Tagged_t kArrayInitFromDataSegmentOutOfBoundsErrorCode = 1;
} // namespace wasm } // namespace wasm
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
......
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