[base] Move v8memory.h to base/memory.h

v8memory.h does not have V8 specific definitions, and having it in base
makes it clear that every component may include the file. It also
ensures that including it does not create spurious dependencies on
v8_base.

Change-Id: I565f63b25f33a9ada19d7b2ac5990863ab17f4a7
Bug: v8:9183, v8:8855
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1657923
Commit-Queue: Sigurd Schneider <sigurds@chromium.org>
Reviewed-by: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62309}
This commit is contained in:
Sigurd Schneider 2019-06-17 11:26:18 +02:00 committed by Commit Bot
parent a1ba0a85e5
commit dd65ef6a9a
43 changed files with 196 additions and 172 deletions

View File

@ -2110,7 +2110,6 @@ v8_source_set("v8_base_without_compiler") {
"src/common/checks.h", "src/common/checks.h",
"src/common/ptr-compr-inl.h", "src/common/ptr-compr-inl.h",
"src/common/ptr-compr.h", "src/common/ptr-compr.h",
"src/common/v8memory.h",
"src/compiler-dispatcher/compiler-dispatcher.cc", "src/compiler-dispatcher/compiler-dispatcher.cc",
"src/compiler-dispatcher/compiler-dispatcher.h", "src/compiler-dispatcher/compiler-dispatcher.h",
"src/compiler-dispatcher/optimizing-compile-dispatcher.cc", "src/compiler-dispatcher/optimizing-compile-dispatcher.cc",
@ -3449,6 +3448,7 @@ v8_component("v8_libbase") {
"src/base/logging.h", "src/base/logging.h",
"src/base/lsan.h", "src/base/lsan.h",
"src/base/macros.h", "src/base/macros.h",
"src/base/memory.h",
"src/base/once.cc", "src/base/once.cc",
"src/base/once.h", "src/base/once.h",
"src/base/optional.h", "src/base/optional.h",

View File

@ -2,14 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef V8_COMMON_V8MEMORY_H_ #ifndef V8_BASE_MEMORY_H_
#define V8_COMMON_V8MEMORY_H_ #define V8_BASE_MEMORY_H_
#include "src/base/macros.h" #include "src/base/macros.h"
#include "src/common/globals.h"
namespace v8 { namespace v8 {
namespace internal { namespace base {
using Address = uintptr_t;
using byte = uint8_t;
// Memory provides an interface to 'raw' memory. It encapsulates the casts // Memory provides an interface to 'raw' memory. It encapsulates the casts
// that typically are needed when incompatible pointer types are used. // that typically are needed when incompatible pointer types are used.
@ -39,22 +41,6 @@ static inline void WriteUnalignedValue(Address p, V value) {
memcpy(reinterpret_cast<void*>(p), &value, sizeof(V)); memcpy(reinterpret_cast<void*>(p), &value, sizeof(V));
} }
static inline uint16_t ReadUnalignedUInt16(Address p) {
return ReadUnalignedValue<uint16_t>(p);
}
static inline void WriteUnalignedUInt16(Address p, uint16_t value) {
WriteUnalignedValue(p, value);
}
static inline uint32_t ReadUnalignedUInt32(Address p) {
return ReadUnalignedValue<uint32_t>(p);
}
static inline void WriteUnalignedUInt32(Address p, uint32_t value) {
WriteUnalignedValue(p, value);
}
template <typename V> template <typename V>
static inline V ReadLittleEndianValue(Address p) { static inline V ReadLittleEndianValue(Address p) {
#if defined(V8_TARGET_LITTLE_ENDIAN) #if defined(V8_TARGET_LITTLE_ENDIAN)
@ -93,7 +79,7 @@ static inline void WriteLittleEndianValue(V* p, V value) {
WriteLittleEndianValue<V>(reinterpret_cast<Address>(p), value); WriteLittleEndianValue<V>(reinterpret_cast<Address>(p), value);
} }
} // namespace internal } // namespace base
} // namespace v8 } // namespace v8
#endif // V8_COMMON_V8MEMORY_H_ #endif // V8_BASE_MEMORY_H_

View File

@ -7,9 +7,9 @@
#include <type_traits> #include <type_traits>
#include "src/base/memory.h"
#include "src/codegen/arm64/assembler-arm64.h" #include "src/codegen/arm64/assembler-arm64.h"
#include "src/codegen/assembler.h" #include "src/codegen/assembler.h"
#include "src/common/v8memory.h"
#include "src/debug/debug.h" #include "src/debug/debug.h"
#include "src/objects/objects-inl.h" #include "src/objects/objects-inl.h"
#include "src/objects/smi.h" #include "src/objects/smi.h"

View File

@ -37,6 +37,7 @@
#include <forward_list> #include <forward_list>
#include "src/base/memory.h"
#include "src/codegen/code-comments.h" #include "src/codegen/code-comments.h"
#include "src/codegen/cpu-features.h" #include "src/codegen/cpu-features.h"
#include "src/codegen/external-reference.h" #include "src/codegen/external-reference.h"
@ -55,6 +56,10 @@ class ApiFunction;
namespace internal { namespace internal {
using base::Memory;
using base::ReadUnalignedValue;
using base::WriteUnalignedValue;
// Forward declarations. // Forward declarations.
class EmbeddedData; class EmbeddedData;
class InstructionStream; class InstructionStream;

View File

@ -5,8 +5,8 @@
#ifndef V8_CODEGEN_SAFEPOINT_TABLE_H_ #ifndef V8_CODEGEN_SAFEPOINT_TABLE_H_
#define V8_CODEGEN_SAFEPOINT_TABLE_H_ #define V8_CODEGEN_SAFEPOINT_TABLE_H_
#include "src/base/memory.h"
#include "src/common/assert-scope.h" #include "src/common/assert-scope.h"
#include "src/common/v8memory.h"
#include "src/utils/allocation.h" #include "src/utils/allocation.h"
#include "src/utils/utils.h" #include "src/utils/utils.h"
#include "src/zone/zone-chunk-list.h" #include "src/zone/zone-chunk-list.h"
@ -76,22 +76,23 @@ class SafepointTable {
unsigned GetPcOffset(unsigned index) const { unsigned GetPcOffset(unsigned index) const {
DCHECK(index < length_); DCHECK(index < length_);
return Memory<uint32_t>(GetPcOffsetLocation(index)); return base::Memory<uint32_t>(GetPcOffsetLocation(index));
} }
int GetTrampolinePcOffset(unsigned index) const { int GetTrampolinePcOffset(unsigned index) const {
DCHECK(index < length_); DCHECK(index < length_);
return Memory<int>(GetTrampolineLocation(index)); return base::Memory<int>(GetTrampolineLocation(index));
} }
unsigned find_return_pc(unsigned pc_offset); unsigned find_return_pc(unsigned pc_offset);
SafepointEntry GetEntry(unsigned index) const { SafepointEntry GetEntry(unsigned index) const {
DCHECK(index < length_); DCHECK(index < length_);
unsigned deopt_index = Memory<uint32_t>(GetEncodedInfoLocation(index)); unsigned deopt_index =
uint8_t* bits = &Memory<uint8_t>(entries_ + (index * entry_size_)); base::Memory<uint32_t>(GetEncodedInfoLocation(index));
uint8_t* bits = &base::Memory<uint8_t>(entries_ + (index * entry_size_));
int trampoline_pc = int trampoline_pc =
has_deopt_ ? Memory<int>(GetTrampolineLocation(index)) : -1; has_deopt_ ? base::Memory<int>(GetTrampolineLocation(index)) : -1;
return SafepointEntry(deopt_index, bits, trampoline_pc); return SafepointEntry(deopt_index, bits, trampoline_pc);
} }

View File

@ -8,7 +8,7 @@
#include "src/codegen/x64/assembler-x64.h" #include "src/codegen/x64/assembler-x64.h"
#include "src/base/cpu.h" #include "src/base/cpu.h"
#include "src/common/v8memory.h" #include "src/base/memory.h"
#include "src/debug/debug.h" #include "src/debug/debug.h"
#include "src/objects/objects-inl.h" #include "src/objects/objects-inl.h"

View File

@ -582,7 +582,8 @@ void EhFrameDisassembler::DumpDwarfDirectives(std::ostream& stream, // NOLINT
void EhFrameDisassembler::DisassembleToStream(std::ostream& stream) { // NOLINT void EhFrameDisassembler::DisassembleToStream(std::ostream& stream) { // NOLINT
// The encoded CIE size does not include the size field itself. // The encoded CIE size does not include the size field itself.
const int cie_size = const int cie_size =
ReadUnalignedUInt32(reinterpret_cast<Address>(start_)) + kInt32Size; base::ReadUnalignedValue<uint32_t>(reinterpret_cast<Address>(start_)) +
kInt32Size;
const int fde_offset = cie_size; const int fde_offset = cie_size;
const byte* cie_directives_start = const byte* cie_directives_start =
@ -597,12 +598,13 @@ void EhFrameDisassembler::DisassembleToStream(std::ostream& stream) { // NOLINT
reinterpret_cast<Address>(start_) + fde_offset + reinterpret_cast<Address>(start_) + fde_offset +
EhFrameConstants::kProcedureAddressOffsetInFde; EhFrameConstants::kProcedureAddressOffsetInFde;
int32_t procedure_offset = int32_t procedure_offset =
ReadUnalignedValue<int32_t>(procedure_offset_address); base::ReadUnalignedValue<int32_t>(procedure_offset_address);
Address procedure_size_address = reinterpret_cast<Address>(start_) + Address procedure_size_address = reinterpret_cast<Address>(start_) +
fde_offset + fde_offset +
EhFrameConstants::kProcedureSizeOffsetInFde; EhFrameConstants::kProcedureSizeOffsetInFde;
uint32_t procedure_size = ReadUnalignedUInt32(procedure_size_address); uint32_t procedure_size =
base::ReadUnalignedValue<uint32_t>(procedure_size_address);
const byte* fde_start = start_ + fde_offset; const byte* fde_start = start_ + fde_offset;
stream << reinterpret_cast<const void*>(fde_start) << " .eh_frame: FDE\n" stream << reinterpret_cast<const void*>(fde_start) << " .eh_frame: FDE\n"

View File

@ -6,9 +6,9 @@
#define V8_DIAGNOSTICS_EH_FRAME_H_ #define V8_DIAGNOSTICS_EH_FRAME_H_
#include "src/base/compiler-specific.h" #include "src/base/compiler-specific.h"
#include "src/base/memory.h"
#include "src/codegen/register-arch.h" #include "src/codegen/register-arch.h"
#include "src/common/globals.h" #include "src/common/globals.h"
#include "src/common/v8memory.h"
#include "src/zone/zone-containers.h" #include "src/zone/zone-containers.h"
namespace v8 { namespace v8 {
@ -144,11 +144,11 @@ class V8_EXPORT_PRIVATE EhFrameWriter {
} }
void PatchInt32(int base_offset, uint32_t value) { void PatchInt32(int base_offset, uint32_t value) {
DCHECK_EQ( DCHECK_EQ(
ReadUnalignedUInt32(reinterpret_cast<Address>(eh_frame_buffer_.data()) + base::ReadUnalignedValue<uint32_t>(
base_offset), reinterpret_cast<Address>(eh_frame_buffer_.data()) + base_offset),
kInt32Placeholder); kInt32Placeholder);
DCHECK_LT(base_offset + kInt32Size, eh_frame_offset()); DCHECK_LT(base_offset + kInt32Size, eh_frame_offset());
WriteUnalignedUInt32( base::WriteUnalignedValue<uint32_t>(
reinterpret_cast<Address>(eh_frame_buffer_.data()) + base_offset, reinterpret_cast<Address>(eh_frame_buffer_.data()) + base_offset,
value); value);
} }
@ -216,7 +216,9 @@ class V8_EXPORT_PRIVATE EhFrameIterator {
void SkipCie() { void SkipCie() {
DCHECK_EQ(next_, start_); DCHECK_EQ(next_, start_);
next_ += ReadUnalignedUInt32(reinterpret_cast<Address>(next_)) + kInt32Size; next_ +=
base::ReadUnalignedValue<uint32_t>(reinterpret_cast<Address>(next_)) +
kInt32Size;
} }
void SkipToFdeDirectives() { void SkipToFdeDirectives() {
@ -267,7 +269,7 @@ class V8_EXPORT_PRIVATE EhFrameIterator {
T GetNextValue() { T GetNextValue() {
T result; T result;
DCHECK_LE(next_ + sizeof(result), end_); DCHECK_LE(next_ + sizeof(result), end_);
result = ReadUnalignedValue<T>(reinterpret_cast<Address>(next_)); result = base::ReadUnalignedValue<T>(reinterpret_cast<Address>(next_));
next_ += sizeof(result); next_ += sizeof(result);
return result; return result;
} }

View File

@ -5,7 +5,7 @@
#ifndef V8_EXECUTION_FRAMES_INL_H_ #ifndef V8_EXECUTION_FRAMES_INL_H_
#define V8_EXECUTION_FRAMES_INL_H_ #define V8_EXECUTION_FRAMES_INL_H_
#include "src/common/v8memory.h" #include "src/base/memory.h"
#include "src/execution/frame-constants.h" #include "src/execution/frame-constants.h"
#include "src/execution/frames.h" #include "src/execution/frames.h"
#include "src/execution/isolate.h" #include "src/execution/isolate.h"
@ -48,11 +48,11 @@ inline Address StackHandler::address() const {
inline StackHandler* StackHandler::next() const { inline StackHandler* StackHandler::next() const {
const int offset = StackHandlerConstants::kNextOffset; const int offset = StackHandlerConstants::kNextOffset;
return FromAddress(Memory<Address>(address() + offset)); return FromAddress(base::Memory<Address>(address() + offset));
} }
inline Address StackHandler::next_address() const { inline Address StackHandler::next_address() const {
return Memory<Address>(address() + StackHandlerConstants::kNextOffset); return base::Memory<Address>(address() + StackHandlerConstants::kNextOffset);
} }
inline StackHandler* StackHandler::FromAddress(Address address) { inline StackHandler* StackHandler::FromAddress(Address address) {
@ -112,21 +112,22 @@ inline Object BuiltinExitFrame::receiver_slot_object() const {
const int receiverOffset = BuiltinExitFrameConstants::kNewTargetOffset + const int receiverOffset = BuiltinExitFrameConstants::kNewTargetOffset +
(argc - 1) * kSystemPointerSize; (argc - 1) * kSystemPointerSize;
return Object(Memory<Address>(fp() + receiverOffset)); return Object(base::Memory<Address>(fp() + receiverOffset));
} }
inline Object BuiltinExitFrame::argc_slot_object() const { inline Object BuiltinExitFrame::argc_slot_object() const {
return Object(Memory<Address>(fp() + BuiltinExitFrameConstants::kArgcOffset)); return Object(
base::Memory<Address>(fp() + BuiltinExitFrameConstants::kArgcOffset));
} }
inline Object BuiltinExitFrame::target_slot_object() const { inline Object BuiltinExitFrame::target_slot_object() const {
return Object( return Object(
Memory<Address>(fp() + BuiltinExitFrameConstants::kTargetOffset)); base::Memory<Address>(fp() + BuiltinExitFrameConstants::kTargetOffset));
} }
inline Object BuiltinExitFrame::new_target_slot_object() const { inline Object BuiltinExitFrame::new_target_slot_object() const {
return Object( return Object(base::Memory<Address>(
Memory<Address>(fp() + BuiltinExitFrameConstants::kNewTargetOffset)); fp() + BuiltinExitFrameConstants::kNewTargetOffset));
} }
inline StandardFrame::StandardFrame(StackFrameIteratorBase* iterator) inline StandardFrame::StandardFrame(StackFrameIteratorBase* iterator)
@ -134,20 +135,20 @@ inline StandardFrame::StandardFrame(StackFrameIteratorBase* iterator)
} }
inline Object StandardFrame::GetExpression(int index) const { inline Object StandardFrame::GetExpression(int index) const {
return Object(Memory<Address>(GetExpressionAddress(index))); return Object(base::Memory<Address>(GetExpressionAddress(index)));
} }
inline void StandardFrame::SetExpression(int index, Object value) { inline void StandardFrame::SetExpression(int index, Object value) {
Memory<Address>(GetExpressionAddress(index)) = value.ptr(); base::Memory<Address>(GetExpressionAddress(index)) = value.ptr();
} }
inline Address StandardFrame::caller_fp() const { inline Address StandardFrame::caller_fp() const {
return Memory<Address>(fp() + StandardFrameConstants::kCallerFPOffset); return base::Memory<Address>(fp() + StandardFrameConstants::kCallerFPOffset);
} }
inline Address StandardFrame::caller_pc() const { inline Address StandardFrame::caller_pc() const {
return Memory<Address>(ComputePCAddress(fp())); return base::Memory<Address>(ComputePCAddress(fp()));
} }
@ -163,14 +164,14 @@ inline Address StandardFrame::ComputeConstantPoolAddress(Address fp) {
inline bool StandardFrame::IsArgumentsAdaptorFrame(Address fp) { inline bool StandardFrame::IsArgumentsAdaptorFrame(Address fp) {
intptr_t frame_type = intptr_t frame_type =
Memory<intptr_t>(fp + TypedFrameConstants::kFrameTypeOffset); base::Memory<intptr_t>(fp + TypedFrameConstants::kFrameTypeOffset);
return frame_type == StackFrame::TypeToMarker(StackFrame::ARGUMENTS_ADAPTOR); return frame_type == StackFrame::TypeToMarker(StackFrame::ARGUMENTS_ADAPTOR);
} }
inline bool StandardFrame::IsConstructFrame(Address fp) { inline bool StandardFrame::IsConstructFrame(Address fp) {
intptr_t frame_type = intptr_t frame_type =
Memory<intptr_t>(fp + TypedFrameConstants::kFrameTypeOffset); base::Memory<intptr_t>(fp + TypedFrameConstants::kFrameTypeOffset);
return frame_type == StackFrame::TypeToMarker(StackFrame::CONSTRUCT); return frame_type == StackFrame::TypeToMarker(StackFrame::CONSTRUCT);
} }
@ -187,7 +188,7 @@ Address JavaScriptFrame::GetParameterSlot(int index) const {
} }
inline void JavaScriptFrame::set_receiver(Object value) { inline void JavaScriptFrame::set_receiver(Object value) {
Memory<Address>(GetParameterSlot(-1)) = value.ptr(); base::Memory<Address>(GetParameterSlot(-1)) = value.ptr();
} }
inline bool JavaScriptFrame::has_adapted_arguments() const { inline bool JavaScriptFrame::has_adapted_arguments() const {
@ -196,7 +197,7 @@ inline bool JavaScriptFrame::has_adapted_arguments() const {
inline Object JavaScriptFrame::function_slot_object() const { inline Object JavaScriptFrame::function_slot_object() const {
const int offset = JavaScriptFrameConstants::kFunctionOffset; const int offset = JavaScriptFrameConstants::kFunctionOffset;
return Object(Memory<Address>(fp() + offset)); return Object(base::Memory<Address>(fp() + offset));
} }
inline StubFrame::StubFrame(StackFrameIteratorBase* iterator) inline StubFrame::StubFrame(StackFrameIteratorBase* iterator)

View File

@ -5,8 +5,8 @@
#ifndef V8_HEAP_REMEMBERED_SET_H_ #ifndef V8_HEAP_REMEMBERED_SET_H_
#define V8_HEAP_REMEMBERED_SET_H_ #define V8_HEAP_REMEMBERED_SET_H_
#include "src/base/memory.h"
#include "src/codegen/reloc-info.h" #include "src/codegen/reloc-info.h"
#include "src/common/v8memory.h"
#include "src/heap/heap.h" #include "src/heap/heap.h"
#include "src/heap/slot-set.h" #include "src/heap/slot-set.h"
#include "src/heap/spaces.h" #include "src/heap/spaces.h"
@ -309,7 +309,7 @@ class UpdateTypedSlotHelper {
SlotCallbackResult result = callback(FullMaybeObjectSlot(&code)); SlotCallbackResult result = callback(FullMaybeObjectSlot(&code));
DCHECK(!HasWeakHeapObjectTag(code)); DCHECK(!HasWeakHeapObjectTag(code));
if (code != old_code) { if (code != old_code) {
Memory<Address>(entry_address) = code.entry(); base::Memory<Address>(entry_address) = code.entry();
} }
return result; return result;
} }

View File

@ -156,7 +156,7 @@ void IsolateAllocator::CommitPagesForIsolate(Address heap_address) {
if (Heap::ShouldZapGarbage()) { if (Heap::ShouldZapGarbage()) {
for (Address address = committed_region_address; for (Address address = committed_region_address;
address < committed_region_size; address += kSystemPointerSize) { address < committed_region_size; address += kSystemPointerSize) {
Memory<Address>(address) = static_cast<Address>(kZapValue); base::Memory<Address>(address) = static_cast<Address>(kZapValue);
} }
} }
} }

View File

@ -5,12 +5,12 @@ include_rules = [
"+src/base/compiler-specific.h", "+src/base/compiler-specific.h",
"+src/base/logging.h", "+src/base/logging.h",
"+src/base/macros.h", "+src/base/macros.h",
"+src/base/memory.h",
"+src/base/platform/platform.h", "+src/base/platform/platform.h",
"+src/base/platform/mutex.h", "+src/base/platform/mutex.h",
"+src/base/safe_conversions.h", "+src/base/safe_conversions.h",
"+src/base/template-utils.h", "+src/base/template-utils.h",
"+src/base/v8-fallthrough.h", "+src/base/v8-fallthrough.h",
"+src/common/v8memory.h",
"+src/numbers/conversions.h", "+src/numbers/conversions.h",
"+src/inspector", "+src/inspector",
"+src/tracing", "+src/tracing",

View File

@ -4,7 +4,7 @@
#include "src/inspector/v8-debugger-script.h" #include "src/inspector/v8-debugger-script.h"
#include "src/common/v8memory.h" #include "src/base/memory.h"
#include "src/inspector/inspected-context.h" #include "src/inspector/inspected-context.h"
#include "src/inspector/string-util.h" #include "src/inspector/string-util.h"
#include "src/inspector/v8-debugger-agent-impl.h" #include "src/inspector/v8-debugger-agent-impl.h"
@ -44,7 +44,7 @@ String16 calculateHash(v8::Isolate* isolate, v8::Local<v8::String> source) {
size_t sizeInBytes = sizeof(UChar) * written; size_t sizeInBytes = sizeof(UChar) * written;
data = reinterpret_cast<const uint32_t*>(buffer.get()); data = reinterpret_cast<const uint32_t*>(buffer.get());
for (size_t i = 0; i < sizeInBytes / 4; ++i) { for (size_t i = 0; i < sizeInBytes / 4; ++i) {
uint32_t d = v8::internal::ReadUnalignedUInt32( uint32_t d = v8::base::ReadUnalignedValue<uint32_t>(
reinterpret_cast<v8::internal::Address>(data + i)); reinterpret_cast<v8::internal::Address>(data + i));
#if V8_TARGET_LITTLE_ENDIAN #if V8_TARGET_LITTLE_ENDIAN
uint32_t v = d; uint32_t v = d;

View File

@ -334,8 +334,8 @@ void BytecodeArrayWriter::PatchJumpWith16BitOperand(size_t jump_location,
// The jump fits within the range of an Imm16 operand, so cancel // The jump fits within the range of an Imm16 operand, so cancel
// the reservation and jump directly. // the reservation and jump directly.
constant_array_builder()->DiscardReservedEntry(OperandSize::kShort); constant_array_builder()->DiscardReservedEntry(OperandSize::kShort);
WriteUnalignedUInt16(reinterpret_cast<Address>(operand_bytes), base::WriteUnalignedValue<uint16_t>(
static_cast<uint16_t>(delta)); reinterpret_cast<Address>(operand_bytes), static_cast<uint16_t>(delta));
} else { } else {
// The jump does not fit within the range of an Imm16 operand, so // The jump does not fit within the range of an Imm16 operand, so
// commit reservation putting the offset into the constant pool, // commit reservation putting the offset into the constant pool,
@ -344,8 +344,8 @@ void BytecodeArrayWriter::PatchJumpWith16BitOperand(size_t jump_location,
OperandSize::kShort, Smi::FromInt(delta)); OperandSize::kShort, Smi::FromInt(delta));
jump_bytecode = GetJumpWithConstantOperand(jump_bytecode); jump_bytecode = GetJumpWithConstantOperand(jump_bytecode);
bytecodes()->at(jump_location) = Bytecodes::ToByte(jump_bytecode); bytecodes()->at(jump_location) = Bytecodes::ToByte(jump_bytecode);
WriteUnalignedUInt16(reinterpret_cast<Address>(operand_bytes), base::WriteUnalignedValue<uint16_t>(
static_cast<uint16_t>(entry)); reinterpret_cast<Address>(operand_bytes), static_cast<uint16_t>(entry));
} }
DCHECK(bytecodes()->at(operand_location) == k8BitJumpPlaceholder && DCHECK(bytecodes()->at(operand_location) == k8BitJumpPlaceholder &&
bytecodes()->at(operand_location + 1) == k8BitJumpPlaceholder); bytecodes()->at(operand_location + 1) == k8BitJumpPlaceholder);
@ -359,8 +359,8 @@ void BytecodeArrayWriter::PatchJumpWith32BitOperand(size_t jump_location,
Bytecodes::FromByte(bytecodes()->at(jump_location)))); Bytecodes::FromByte(bytecodes()->at(jump_location))));
constant_array_builder()->DiscardReservedEntry(OperandSize::kQuad); constant_array_builder()->DiscardReservedEntry(OperandSize::kQuad);
uint8_t operand_bytes[4]; uint8_t operand_bytes[4];
WriteUnalignedUInt32(reinterpret_cast<Address>(operand_bytes), base::WriteUnalignedValue<uint32_t>(reinterpret_cast<Address>(operand_bytes),
static_cast<uint32_t>(delta)); static_cast<uint32_t>(delta));
size_t operand_location = jump_location + 1; size_t operand_location = jump_location + 1;
DCHECK(bytecodes()->at(operand_location) == k8BitJumpPlaceholder && DCHECK(bytecodes()->at(operand_location) == k8BitJumpPlaceholder &&
bytecodes()->at(operand_location + 1) == k8BitJumpPlaceholder && bytecodes()->at(operand_location + 1) == k8BitJumpPlaceholder &&

View File

@ -42,9 +42,11 @@ int32_t BytecodeDecoder::DecodeSignedOperand(Address operand_start,
case OperandSize::kByte: case OperandSize::kByte:
return *reinterpret_cast<const int8_t*>(operand_start); return *reinterpret_cast<const int8_t*>(operand_start);
case OperandSize::kShort: case OperandSize::kShort:
return static_cast<int16_t>(ReadUnalignedUInt16(operand_start)); return static_cast<int16_t>(
base::ReadUnalignedValue<uint16_t>(operand_start));
case OperandSize::kQuad: case OperandSize::kQuad:
return static_cast<int32_t>(ReadUnalignedUInt32(operand_start)); return static_cast<int32_t>(
base::ReadUnalignedValue<uint32_t>(operand_start));
case OperandSize::kNone: case OperandSize::kNone:
UNREACHABLE(); UNREACHABLE();
} }
@ -60,9 +62,9 @@ uint32_t BytecodeDecoder::DecodeUnsignedOperand(Address operand_start,
case OperandSize::kByte: case OperandSize::kByte:
return *reinterpret_cast<const uint8_t*>(operand_start); return *reinterpret_cast<const uint8_t*>(operand_start);
case OperandSize::kShort: case OperandSize::kShort:
return ReadUnalignedUInt16(operand_start); return base::ReadUnalignedValue<uint16_t>(operand_start);
case OperandSize::kQuad: case OperandSize::kQuad:
return ReadUnalignedUInt32(operand_start); return base::ReadUnalignedValue<uint32_t>(operand_start);
case OperandSize::kNone: case OperandSize::kNone:
UNREACHABLE(); UNREACHABLE();
} }

View File

@ -7,8 +7,8 @@
#include "src/objects/code.h" #include "src/objects/code.h"
#include "src/base/memory.h"
#include "src/codegen/code-desc.h" #include "src/codegen/code-desc.h"
#include "src/common/v8memory.h"
#include "src/execution/isolate.h" #include "src/execution/isolate.h"
#include "src/interpreter/bytecode-register.h" #include "src/interpreter/bytecode-register.h"
#include "src/objects/dictionary.h" #include "src/objects/dictionary.h"
@ -575,7 +575,7 @@ Code Code::GetCodeFromTargetAddress(Address address) {
} }
Code Code::GetObjectFromEntryAddress(Address location_of_address) { Code Code::GetObjectFromEntryAddress(Address location_of_address) {
Address code_entry = Memory<Address>(location_of_address); Address code_entry = base::Memory<Address>(location_of_address);
HeapObject code = HeapObject::FromAddress(code_entry - Code::kHeaderSize); HeapObject code = HeapObject::FromAddress(code_entry - Code::kHeaderSize);
// Unchecked cast because we can't rely on the map currently // Unchecked cast because we can't rely on the map currently
// not being a forwarding pointer. // not being a forwarding pointer.

View File

@ -2901,7 +2901,7 @@ class TypedElementsAccessor
// fields (external pointers, doubles and BigInt data) are only // fields (external pointers, doubles and BigInt data) are only
// kTaggedSize aligned so we have to use unaligned pointer friendly way of // kTaggedSize aligned so we have to use unaligned pointer friendly way of
// accessing them in order to avoid undefined behavior in C++ code. // accessing them in order to avoid undefined behavior in C++ code.
WriteUnalignedValue<ElementType>( base::WriteUnalignedValue<ElementType>(
reinterpret_cast<Address>(data_ptr + entry), value); reinterpret_cast<Address>(data_ptr + entry), value);
} else { } else {
data_ptr[entry] = value; data_ptr[entry] = value;
@ -2941,7 +2941,7 @@ class TypedElementsAccessor
// fields (external pointers, doubles and BigInt data) are only // fields (external pointers, doubles and BigInt data) are only
// kTaggedSize aligned so we have to use unaligned pointer friendly way of // kTaggedSize aligned so we have to use unaligned pointer friendly way of
// accessing them in order to avoid undefined behavior in C++ code. // accessing them in order to avoid undefined behavior in C++ code.
result = ReadUnalignedValue<ElementType>( result = base::ReadUnalignedValue<ElementType>(
reinterpret_cast<Address>(data_ptr + entry)); reinterpret_cast<Address>(data_ptr + entry));
} else { } else {
result = data_ptr[entry]; result = data_ptr[entry];

View File

@ -7,7 +7,7 @@
#include "src/objects/embedder-data-slot.h" #include "src/objects/embedder-data-slot.h"
#include "src/common/v8memory.h" #include "src/base/memory.h"
#include "src/heap/heap-write-barrier-inl.h" #include "src/heap/heap-write-barrier-inl.h"
#include "src/objects/embedder-data-array.h" #include "src/objects/embedder-data-array.h"
#include "src/objects/js-objects-inl.h" #include "src/objects/js-objects-inl.h"

View File

@ -323,7 +323,7 @@ uint64_t FixedDoubleArray::get_representation(int index) {
DCHECK(index >= 0 && index < this->length()); DCHECK(index >= 0 && index < this->length());
int offset = kHeaderSize + index * kDoubleSize; int offset = kHeaderSize + index * kDoubleSize;
// Bug(v8:8875): Doubles may be unaligned. // Bug(v8:8875): Doubles may be unaligned.
return ReadUnalignedValue<uint64_t>(field_address(offset)); return base::ReadUnalignedValue<uint64_t>(field_address(offset));
} }
Handle<Object> FixedDoubleArray::get(FixedDoubleArray array, int index, Handle<Object> FixedDoubleArray::get(FixedDoubleArray array, int index,
@ -355,7 +355,7 @@ void FixedDoubleArray::set_the_hole(int index) {
DCHECK(map() != GetReadOnlyRoots().fixed_cow_array_map() && DCHECK(map() != GetReadOnlyRoots().fixed_cow_array_map() &&
map() != GetReadOnlyRoots().fixed_array_map()); map() != GetReadOnlyRoots().fixed_array_map());
int offset = kHeaderSize + index * kDoubleSize; int offset = kHeaderSize + index * kDoubleSize;
WriteUnalignedValue<uint64_t>(field_address(offset), kHoleNanInt64); base::WriteUnalignedValue<uint64_t>(field_address(offset), kHoleNanInt64);
} }
bool FixedDoubleArray::is_the_hole(Isolate* isolate, int index) { bool FixedDoubleArray::is_the_hole(Isolate* isolate, int index) {

View File

@ -31,11 +31,11 @@ void HeapNumberBase::set_value(double value) {
uint64_t HeapNumberBase::value_as_bits() const { uint64_t HeapNumberBase::value_as_bits() const {
// Bug(v8:8875): HeapNumber's double may be unaligned. // Bug(v8:8875): HeapNumber's double may be unaligned.
return ReadUnalignedValue<uint64_t>(field_address(kValueOffset)); return base::ReadUnalignedValue<uint64_t>(field_address(kValueOffset));
} }
void HeapNumberBase::set_value_as_bits(uint64_t bits) { void HeapNumberBase::set_value_as_bits(uint64_t bits) {
WriteUnalignedValue<uint64_t>(field_address(kValueOffset), bits); base::WriteUnalignedValue<uint64_t>(field_address(kValueOffset), bits);
} }
int HeapNumberBase::get_exponent() { int HeapNumberBase::get_exponent() {

View File

@ -14,7 +14,7 @@
// for fields that can be written to and read from multiple threads at the same // for fields that can be written to and read from multiple threads at the same
// time. See comments in src/base/atomicops.h for the memory ordering sematics. // time. See comments in src/base/atomicops.h for the memory ordering sematics.
#include "src/common/v8memory.h" #include "src/base/memory.h"
// Since this changes visibility, it should always be last in a class // Since this changes visibility, it should always be last in a class
// definition. // definition.

View File

@ -15,8 +15,8 @@
#include "src/objects/objects.h" #include "src/objects/objects.h"
#include "src/base/bits.h" #include "src/base/bits.h"
#include "src/base/memory.h"
#include "src/builtins/builtins.h" #include "src/builtins/builtins.h"
#include "src/common/v8memory.h"
#include "src/handles/handles-inl.h" #include "src/handles/handles-inl.h"
#include "src/heap/factory.h" #include "src/heap/factory.h"
#include "src/heap/heap-write-barrier-inl.h" #include "src/heap/heap-write-barrier-inl.h"

View File

@ -15,6 +15,7 @@
#include "src/base/build_config.h" #include "src/base/build_config.h"
#include "src/base/flags.h" #include "src/base/flags.h"
#include "src/base/logging.h" #include "src/base/logging.h"
#include "src/base/memory.h"
#include "src/codegen/constants-arch.h" #include "src/codegen/constants-arch.h"
#include "src/common/assert-scope.h" #include "src/common/assert-scope.h"
#include "src/common/checks.h" #include "src/common/checks.h"
@ -625,9 +626,9 @@ class Object : public TaggedImpl<HeapObjectReferenceType::STRONG, Address> {
#endif #endif
if (std::is_same<T, double>::value || v8_pointer_compression_unaligned) { if (std::is_same<T, double>::value || v8_pointer_compression_unaligned) {
// Bug(v8:8875) Double fields may be unaligned. // Bug(v8:8875) Double fields may be unaligned.
return ReadUnalignedValue<T>(field_address(offset)); return base::ReadUnalignedValue<T>(field_address(offset));
} else { } else {
return Memory<T>(field_address(offset)); return base::Memory<T>(field_address(offset));
} }
} }
@ -642,9 +643,9 @@ class Object : public TaggedImpl<HeapObjectReferenceType::STRONG, Address> {
#endif #endif
if (std::is_same<T, double>::value || v8_pointer_compression_unaligned) { if (std::is_same<T, double>::value || v8_pointer_compression_unaligned) {
// Bug(v8:8875) Double fields may be unaligned. // Bug(v8:8875) Double fields may be unaligned.
WriteUnalignedValue<T>(field_address(offset), value); base::WriteUnalignedValue<T>(field_address(offset), value);
} else { } else {
Memory<T>(field_address(offset)) = value; base::Memory<T>(field_address(offset)) = value;
} }
} }

View File

@ -22,7 +22,7 @@ TQ_OBJECT_CONSTRUCTORS_IMPL(Oddball)
void Oddball::set_to_number_raw_as_bits(uint64_t bits) { void Oddball::set_to_number_raw_as_bits(uint64_t bits) {
// Bug(v8:8875): HeapNumber's double may be unaligned. // Bug(v8:8875): HeapNumber's double may be unaligned.
WriteUnalignedValue<uint64_t>(field_address(kToNumberRawOffset), bits); base::WriteUnalignedValue<uint64_t>(field_address(kToNumberRawOffset), bits);
} }
byte Oddball::kind() const { byte Oddball::kind() const {

View File

@ -5,8 +5,8 @@
#ifndef V8_OBJECTS_SLOTS_H_ #ifndef V8_OBJECTS_SLOTS_H_
#define V8_OBJECTS_SLOTS_H_ #define V8_OBJECTS_SLOTS_H_
#include "src/base/memory.h"
#include "src/common/globals.h" #include "src/common/globals.h"
#include "src/common/v8memory.h"
namespace v8 { namespace v8 {
namespace internal { namespace internal {
@ -192,11 +192,11 @@ class UnalignedSlot : public SlotBase<UnalignedSlot<T>, T, 1> {
Reference(const Reference&) V8_NOEXCEPT = default; Reference(const Reference&) V8_NOEXCEPT = default;
Reference& operator=(const Reference& other) V8_NOEXCEPT { Reference& operator=(const Reference& other) V8_NOEXCEPT {
WriteUnalignedValue<T>(address_, other.value()); base::WriteUnalignedValue<T>(address_, other.value());
return *this; return *this;
} }
Reference& operator=(T value) { Reference& operator=(T value) {
WriteUnalignedValue<T>(address_, value); base::WriteUnalignedValue<T>(address_, value);
return *this; return *this;
} }
@ -206,8 +206,8 @@ class UnalignedSlot : public SlotBase<UnalignedSlot<T>, T, 1> {
void swap(Reference& other) { void swap(Reference& other) {
T tmp = value(); T tmp = value();
WriteUnalignedValue<T>(address_, other.value()); base::WriteUnalignedValue<T>(address_, other.value());
WriteUnalignedValue<T>(other.address_, tmp); base::WriteUnalignedValue<T>(other.address_, tmp);
} }
bool operator<(const Reference& other) const { bool operator<(const Reference& other) const {
@ -219,7 +219,7 @@ class UnalignedSlot : public SlotBase<UnalignedSlot<T>, T, 1> {
} }
private: private:
T value() const { return ReadUnalignedValue<T>(address_); } T value() const { return base::ReadUnalignedValue<T>(address_); }
Address address_; Address address_;
}; };

View File

@ -270,9 +270,9 @@ bool TickSample::GetStackSample(Isolate* v8_isolate, RegisterState* regs,
// bytecode_array might be garbage, so don't actually dereference it. We // bytecode_array might be garbage, so don't actually dereference it. We
// avoid the frame->GetXXX functions since they call BytecodeArray::cast, // avoid the frame->GetXXX functions since they call BytecodeArray::cast,
// which has a heap access in its DCHECK. // which has a heap access in its DCHECK.
i::Address bytecode_array = i::Memory<i::Address>( i::Address bytecode_array = base::Memory<i::Address>(
frame->fp() + i::InterpreterFrameConstants::kBytecodeArrayFromFp); frame->fp() + i::InterpreterFrameConstants::kBytecodeArrayFromFp);
i::Address bytecode_offset = i::Memory<i::Address>( i::Address bytecode_offset = base::Memory<i::Address>(
frame->fp() + i::InterpreterFrameConstants::kBytecodeOffsetFromFp); frame->fp() + i::InterpreterFrameConstants::kBytecodeOffsetFromFp);
// If the bytecode array is a heap object and the bytecode offset is a // If the bytecode array is a heap object and the bytecode offset is a

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "src/common/v8memory.h" #include "src/base/memory.h"
#include "src/compiler/wasm-compiler.h" #include "src/compiler/wasm-compiler.h"
#include "src/debug/debug.h" #include "src/debug/debug.h"
#include "src/execution/arguments-inl.h" #include "src/execution/arguments-inl.h"
@ -209,12 +209,13 @@ RUNTIME_FUNCTION(Runtime_WasmRunInterpreter) {
// methods that could trigger a GC are being called. // methods that could trigger a GC are being called.
Address arg_buf_ptr = arg_buffer; Address arg_buf_ptr = arg_buffer;
for (int i = 0; i < num_params; ++i) { for (int i = 0; i < num_params; ++i) {
#define CASE_ARG_TYPE(type, ctype) \ #define CASE_ARG_TYPE(type, ctype) \
case wasm::type: \ case wasm::type: \
DCHECK_EQ(wasm::ValueTypes::ElementSizeInBytes(sig->GetParam(i)), \ DCHECK_EQ(wasm::ValueTypes::ElementSizeInBytes(sig->GetParam(i)), \
sizeof(ctype)); \ sizeof(ctype)); \
wasm_args[i] = wasm::WasmValue(ReadUnalignedValue<ctype>(arg_buf_ptr)); \ wasm_args[i] = \
arg_buf_ptr += sizeof(ctype); \ wasm::WasmValue(base::ReadUnalignedValue<ctype>(arg_buf_ptr)); \
arg_buf_ptr += sizeof(ctype); \
break; break;
switch (sig->GetParam(i)) { switch (sig->GetParam(i)) {
CASE_ARG_TYPE(kWasmI32, uint32_t) CASE_ARG_TYPE(kWasmI32, uint32_t)
@ -227,7 +228,8 @@ RUNTIME_FUNCTION(Runtime_WasmRunInterpreter) {
case wasm::kWasmExceptRef: { case wasm::kWasmExceptRef: {
DCHECK_EQ(wasm::ValueTypes::ElementSizeInBytes(sig->GetParam(i)), DCHECK_EQ(wasm::ValueTypes::ElementSizeInBytes(sig->GetParam(i)),
kSystemPointerSize); kSystemPointerSize);
Handle<Object> ref(ReadUnalignedValue<Object>(arg_buf_ptr), isolate); Handle<Object> ref(base::ReadUnalignedValue<Object>(arg_buf_ptr),
isolate);
wasm_args[i] = wasm::WasmValue(ref); wasm_args[i] = wasm::WasmValue(ref);
arg_buf_ptr += kSystemPointerSize; arg_buf_ptr += kSystemPointerSize;
break; break;
@ -259,12 +261,12 @@ RUNTIME_FUNCTION(Runtime_WasmRunInterpreter) {
// also un-boxes reference types from handles into raw pointers. // also un-boxes reference types from handles into raw pointers.
arg_buf_ptr = arg_buffer; arg_buf_ptr = arg_buffer;
for (int i = 0; i < num_returns; ++i) { for (int i = 0; i < num_returns; ++i) {
#define CASE_RET_TYPE(type, ctype) \ #define CASE_RET_TYPE(type, ctype) \
case wasm::type: \ case wasm::type: \
DCHECK_EQ(wasm::ValueTypes::ElementSizeInBytes(sig->GetReturn(i)), \ DCHECK_EQ(wasm::ValueTypes::ElementSizeInBytes(sig->GetReturn(i)), \
sizeof(ctype)); \ sizeof(ctype)); \
WriteUnalignedValue<ctype>(arg_buf_ptr, wasm_rets[i].to<ctype>()); \ base::WriteUnalignedValue<ctype>(arg_buf_ptr, wasm_rets[i].to<ctype>()); \
arg_buf_ptr += sizeof(ctype); \ arg_buf_ptr += sizeof(ctype); \
break; break;
switch (sig->GetReturn(i)) { switch (sig->GetReturn(i)) {
CASE_RET_TYPE(kWasmI32, uint32_t) CASE_RET_TYPE(kWasmI32, uint32_t)
@ -277,7 +279,8 @@ RUNTIME_FUNCTION(Runtime_WasmRunInterpreter) {
case wasm::kWasmExceptRef: { case wasm::kWasmExceptRef: {
DCHECK_EQ(wasm::ValueTypes::ElementSizeInBytes(sig->GetReturn(i)), DCHECK_EQ(wasm::ValueTypes::ElementSizeInBytes(sig->GetReturn(i)),
kSystemPointerSize); kSystemPointerSize);
WriteUnalignedValue<Object>(arg_buf_ptr, *wasm_rets[i].to_anyref()); base::WriteUnalignedValue<Object>(arg_buf_ptr,
*wasm_rets[i].to_anyref());
arg_buf_ptr += kSystemPointerSize; arg_buf_ptr += kSystemPointerSize;
break; break;
} }

View File

@ -6,9 +6,9 @@
#define V8_SNAPSHOT_SERIALIZER_COMMON_H_ #define V8_SNAPSHOT_SERIALIZER_COMMON_H_
#include "src/base/bits.h" #include "src/base/bits.h"
#include "src/base/memory.h"
#include "src/codegen/external-reference-table.h" #include "src/codegen/external-reference-table.h"
#include "src/common/globals.h" #include "src/common/globals.h"
#include "src/common/v8memory.h"
#include "src/objects/visitors.h" #include "src/objects/visitors.h"
#include "src/sanitizer/msan.h" #include "src/sanitizer/msan.h"
#include "src/snapshot/references.h" #include "src/snapshot/references.h"
@ -344,12 +344,13 @@ class SerializedData {
protected: protected:
void SetHeaderValue(uint32_t offset, uint32_t value) { void SetHeaderValue(uint32_t offset, uint32_t value) {
WriteLittleEndianValue(reinterpret_cast<Address>(data_) + offset, value); base::WriteLittleEndianValue(reinterpret_cast<Address>(data_) + offset,
value);
} }
uint32_t GetHeaderValue(uint32_t offset) const { uint32_t GetHeaderValue(uint32_t offset) const {
return ReadLittleEndianValue<uint32_t>(reinterpret_cast<Address>(data_) + return base::ReadLittleEndianValue<uint32_t>(
offset); reinterpret_cast<Address>(data_) + offset);
} }
void AllocateData(uint32_t size); void AllocateData(uint32_t size);

View File

@ -98,11 +98,12 @@ class Snapshot : public AllStatic {
uint32_t index); uint32_t index);
static uint32_t GetHeaderValue(const v8::StartupData* data, uint32_t offset) { static uint32_t GetHeaderValue(const v8::StartupData* data, uint32_t offset) {
return ReadLittleEndianValue<uint32_t>( return base::ReadLittleEndianValue<uint32_t>(
reinterpret_cast<Address>(data->data) + offset); reinterpret_cast<Address>(data->data) + offset);
} }
static void SetHeaderValue(char* data, uint32_t offset, uint32_t value) { static void SetHeaderValue(char* data, uint32_t offset, uint32_t value) {
WriteLittleEndianValue(reinterpret_cast<Address>(data) + offset, value); base::WriteLittleEndianValue(reinterpret_cast<Address>(data) + offset,
value);
} }
static void CheckVersion(const v8::StartupData* data); static void CheckVersion(const v8::StartupData* data);

View File

@ -1814,24 +1814,24 @@ i::Address FuncData::v8_callback(void* data, i::Address argv) {
for (int i = 0; i < num_param_types; ++i) { for (int i = 0; i < num_param_types; ++i) {
switch (param_types[i]->kind()) { switch (param_types[i]->kind()) {
case I32: case I32:
params[i] = Val(i::ReadUnalignedValue<int32_t>(p)); params[i] = Val(v8::base::ReadUnalignedValue<int32_t>(p));
p += 4; p += 4;
break; break;
case I64: case I64:
params[i] = Val(i::ReadUnalignedValue<int64_t>(p)); params[i] = Val(v8::base::ReadUnalignedValue<int64_t>(p));
p += 8; p += 8;
break; break;
case F32: case F32:
params[i] = Val(i::ReadUnalignedValue<float32_t>(p)); params[i] = Val(v8::base::ReadUnalignedValue<float32_t>(p));
p += 4; p += 4;
break; break;
case F64: case F64:
params[i] = Val(i::ReadUnalignedValue<float64_t>(p)); params[i] = Val(v8::base::ReadUnalignedValue<float64_t>(p));
p += 8; p += 8;
break; break;
case ANYREF: case ANYREF:
case FUNCREF: { case FUNCREF: {
i::Address raw = i::ReadUnalignedValue<i::Address>(p); i::Address raw = v8::base::ReadUnalignedValue<i::Address>(p);
p += sizeof(raw); p += sizeof(raw);
if (raw == i::kNullAddress) { if (raw == i::kNullAddress) {
params[i] = Val(nullptr); params[i] = Val(nullptr);
@ -1864,27 +1864,28 @@ i::Address FuncData::v8_callback(void* data, i::Address argv) {
for (int i = 0; i < num_result_types; ++i) { for (int i = 0; i < num_result_types; ++i) {
switch (result_types[i]->kind()) { switch (result_types[i]->kind()) {
case I32: case I32:
i::WriteUnalignedValue(p, results[i].i32()); v8::base::WriteUnalignedValue(p, results[i].i32());
p += 4; p += 4;
break; break;
case I64: case I64:
i::WriteUnalignedValue(p, results[i].i64()); v8::base::WriteUnalignedValue(p, results[i].i64());
p += 8; p += 8;
break; break;
case F32: case F32:
i::WriteUnalignedValue(p, results[i].f32()); v8::base::WriteUnalignedValue(p, results[i].f32());
p += 4; p += 4;
break; break;
case F64: case F64:
i::WriteUnalignedValue(p, results[i].f64()); v8::base::WriteUnalignedValue(p, results[i].f64());
p += 8; p += 8;
break; break;
case ANYREF: case ANYREF:
case FUNCREF: { case FUNCREF: {
if (results[i].ref() == nullptr) { if (results[i].ref() == nullptr) {
i::WriteUnalignedValue(p, i::kNullAddress); v8::base::WriteUnalignedValue(p, i::kNullAddress);
} else { } else {
i::WriteUnalignedValue(p, impl(results[i].ref())->v8_object()->ptr()); v8::base::WriteUnalignedValue(
p, impl(results[i].ref())->v8_object()->ptr());
} }
p += sizeof(i::Address); p += sizeof(i::Address);
break; break;

View File

@ -10,8 +10,8 @@
#include <memory> #include <memory>
#include "src/base/compiler-specific.h" #include "src/base/compiler-specific.h"
#include "src/base/memory.h"
#include "src/codegen/signature.h" #include "src/codegen/signature.h"
#include "src/common/v8memory.h"
#include "src/flags/flags.h" #include "src/flags/flags.h"
#include "src/utils/utils.h" #include "src/utils/utils.h"
#include "src/utils/vector.h" #include "src/utils/vector.h"
@ -299,7 +299,7 @@ class Decoder {
} else if (!validate_size(pc, sizeof(IntType), msg)) { } else if (!validate_size(pc, sizeof(IntType), msg)) {
return IntType{0}; return IntType{0};
} }
return ReadLittleEndianValue<IntType>(reinterpret_cast<Address>(pc)); return base::ReadLittleEndianValue<IntType>(reinterpret_cast<Address>(pc));
} }
template <typename IntType> template <typename IntType>

View File

@ -6,7 +6,7 @@
#include <cinttypes> #include <cinttypes>
#include "src/common/v8memory.h" #include "src/base/memory.h"
#include "src/utils/utils.h" #include "src/utils/utils.h"
#include "src/utils/vector.h" #include "src/utils/vector.h"
@ -22,9 +22,9 @@ void TraceMemoryOperation(ExecutionTier tier, const MemoryTracingInfo* info,
#define TRACE_TYPE(rep, str, format, ctype1, ctype2) \ #define TRACE_TYPE(rep, str, format, ctype1, ctype2) \
case MachineRepresentation::rep: \ case MachineRepresentation::rep: \
SNPrintF(value, str ":" format, \ SNPrintF(value, str ":" format, \
ReadLittleEndianValue<ctype1>( \ base::ReadLittleEndianValue<ctype1>( \
reinterpret_cast<Address>(mem_start) + info->address), \ reinterpret_cast<Address>(mem_start) + info->address), \
ReadLittleEndianValue<ctype2>( \ base::ReadLittleEndianValue<ctype2>( \
reinterpret_cast<Address>(mem_start) + info->address)); \ reinterpret_cast<Address>(mem_start) + info->address)); \
break; break;
TRACE_TYPE(kWord8, " i8", "%d / %02x", uint8_t, uint8_t) TRACE_TYPE(kWord8, " i8", "%d / %02x", uint8_t, uint8_t)

View File

@ -25,6 +25,9 @@ namespace v8 {
namespace internal { namespace internal {
namespace wasm { namespace wasm {
using base::ReadLittleEndianValue;
using base::WriteLittleEndianValue;
namespace { namespace {
byte* raw_buffer_ptr(MaybeHandle<JSArrayBuffer> buffer, int offset) { byte* raw_buffer_ptr(MaybeHandle<JSArrayBuffer> buffer, int offset) {
return static_cast<byte*>(buffer.ToHandleChecked()->backing_store()) + offset; return static_cast<byte*>(buffer.ToHandleChecked()->backing_store()) + offset;

View File

@ -29,7 +29,7 @@
#include "src/trap-handler/trap-handler.h" #include "src/trap-handler/trap-handler.h"
#endif #endif
#include "src/common/v8memory.h" #include "src/base/memory.h"
#include "src/utils/utils.h" #include "src/utils/utils.h"
#include "src/wasm/wasm-external-refs.h" #include "src/wasm/wasm-external-refs.h"
@ -37,6 +37,9 @@ namespace v8 {
namespace internal { namespace internal {
namespace wasm { namespace wasm {
using base::ReadUnalignedValue;
using base::WriteUnalignedValue;
void f32_trunc_wrapper(Address data) { void f32_trunc_wrapper(Address data) {
WriteUnalignedValue<float>(data, truncf(ReadUnalignedValue<float>(data))); WriteUnalignedValue<float>(data, truncf(ReadUnalignedValue<float>(data)));
} }

View File

@ -34,6 +34,11 @@ namespace v8 {
namespace internal { namespace internal {
namespace wasm { namespace wasm {
using base::ReadLittleEndianValue;
using base::ReadUnalignedValue;
using base::WriteLittleEndianValue;
using base::WriteUnalignedValue;
#define TRACE(...) \ #define TRACE(...) \
do { \ do { \
if (FLAG_trace_wasm_interpreter) PrintF(__VA_ARGS__); \ if (FLAG_trace_wasm_interpreter) PrintF(__VA_ARGS__); \

View File

@ -16,7 +16,7 @@
#include "src/wasm/wasm-module.h" #include "src/wasm/wasm-module.h"
#include "src/wasm/wasm-opcodes.h" #include "src/wasm/wasm-opcodes.h"
#include "src/common/v8memory.h" #include "src/base/memory.h"
namespace v8 { namespace v8 {
namespace internal { namespace internal {

View File

@ -8,7 +8,7 @@
#include "src/codegen/signature.h" #include "src/codegen/signature.h"
#include "src/zone/zone-containers.h" #include "src/zone/zone-containers.h"
#include "src/common/v8memory.h" #include "src/base/memory.h"
#include "src/utils/vector.h" #include "src/utils/vector.h"
#include "src/wasm/leb-helper.h" #include "src/wasm/leb-helper.h"
#include "src/wasm/local-decl-encoder.h" #include "src/wasm/local-decl-encoder.h"
@ -36,19 +36,19 @@ class ZoneBuffer : public ZoneObject {
void write_u16(uint16_t x) { void write_u16(uint16_t x) {
EnsureSpace(2); EnsureSpace(2);
WriteLittleEndianValue<uint16_t>(reinterpret_cast<Address>(pos_), x); base::WriteLittleEndianValue<uint16_t>(reinterpret_cast<Address>(pos_), x);
pos_ += 2; pos_ += 2;
} }
void write_u32(uint32_t x) { void write_u32(uint32_t x) {
EnsureSpace(4); EnsureSpace(4);
WriteLittleEndianValue<uint32_t>(reinterpret_cast<Address>(pos_), x); base::WriteLittleEndianValue<uint32_t>(reinterpret_cast<Address>(pos_), x);
pos_ += 4; pos_ += 4;
} }
void write_u64(uint64_t x) { void write_u64(uint64_t x) {
EnsureSpace(8); EnsureSpace(8);
WriteLittleEndianValue<uint64_t>(reinterpret_cast<Address>(pos_), x); base::WriteLittleEndianValue<uint64_t>(reinterpret_cast<Address>(pos_), x);
pos_ += 8; pos_ += 8;
} }

View File

@ -7,7 +7,7 @@
#include "src/wasm/wasm-objects.h" #include "src/wasm/wasm-objects.h"
#include "src/common/v8memory.h" #include "src/base/memory.h"
#include "src/heap/heap-write-barrier-inl.h" #include "src/heap/heap-write-barrier-inl.h"
#include "src/objects/contexts-inl.h" #include "src/objects/contexts-inl.h"
#include "src/objects/foreign-inl.h" #include "src/objects/foreign-inl.h"
@ -65,7 +65,7 @@ CAST_ACCESSOR(AsmWasmData)
/* kTaggedSize aligned so we have to use unaligned pointer friendly */ \ /* kTaggedSize aligned so we have to use unaligned pointer friendly */ \
/* way of accessing them in order to avoid undefined behavior in C++ */ \ /* way of accessing them in order to avoid undefined behavior in C++ */ \
/* code. */ \ /* code. */ \
return ReadUnalignedValue<type>(FIELD_ADDR(*this, offset)); \ return base::ReadUnalignedValue<type>(FIELD_ADDR(*this, offset)); \
} else { \ } else { \
return *reinterpret_cast<type const*>(FIELD_ADDR(*this, offset)); \ return *reinterpret_cast<type const*>(FIELD_ADDR(*this, offset)); \
} \ } \
@ -77,7 +77,7 @@ CAST_ACCESSOR(AsmWasmData)
/* kTaggedSize aligned so we have to use unaligned pointer friendly */ \ /* kTaggedSize aligned so we have to use unaligned pointer friendly */ \
/* way of accessing them in order to avoid undefined behavior in C++ */ \ /* way of accessing them in order to avoid undefined behavior in C++ */ \
/* code. */ \ /* code. */ \
WriteUnalignedValue<type>(FIELD_ADDR(*this, offset), value); \ base::WriteUnalignedValue<type>(FIELD_ADDR(*this, offset), value); \
} else { \ } else { \
*reinterpret_cast<type*>(FIELD_ADDR(*this, offset)) = value; \ *reinterpret_cast<type*>(FIELD_ADDR(*this, offset)) = value; \
} \ } \
@ -148,19 +148,19 @@ Address WasmGlobalObject::address() const {
} }
int32_t WasmGlobalObject::GetI32() { int32_t WasmGlobalObject::GetI32() {
return ReadLittleEndianValue<int32_t>(address()); return base::ReadLittleEndianValue<int32_t>(address());
} }
int64_t WasmGlobalObject::GetI64() { int64_t WasmGlobalObject::GetI64() {
return ReadLittleEndianValue<int64_t>(address()); return base::ReadLittleEndianValue<int64_t>(address());
} }
float WasmGlobalObject::GetF32() { float WasmGlobalObject::GetF32() {
return ReadLittleEndianValue<float>(address()); return base::ReadLittleEndianValue<float>(address());
} }
double WasmGlobalObject::GetF64() { double WasmGlobalObject::GetF64() {
return ReadLittleEndianValue<double>(address()); return base::ReadLittleEndianValue<double>(address());
} }
Handle<Object> WasmGlobalObject::GetRef() { Handle<Object> WasmGlobalObject::GetRef() {
@ -170,19 +170,19 @@ Handle<Object> WasmGlobalObject::GetRef() {
} }
void WasmGlobalObject::SetI32(int32_t value) { void WasmGlobalObject::SetI32(int32_t value) {
WriteLittleEndianValue<int32_t>(address(), value); base::WriteLittleEndianValue<int32_t>(address(), value);
} }
void WasmGlobalObject::SetI64(int64_t value) { void WasmGlobalObject::SetI64(int64_t value) {
WriteLittleEndianValue<int64_t>(address(), value); base::WriteLittleEndianValue<int64_t>(address(), value);
} }
void WasmGlobalObject::SetF32(float value) { void WasmGlobalObject::SetF32(float value) {
WriteLittleEndianValue<float>(address(), value); base::WriteLittleEndianValue<float>(address(), value);
} }
void WasmGlobalObject::SetF64(double value) { void WasmGlobalObject::SetF64(double value) {
WriteLittleEndianValue<double>(address(), value); base::WriteLittleEndianValue<double>(address(), value);
} }
void WasmGlobalObject::SetAnyRef(Handle<Object> value) { void WasmGlobalObject::SetAnyRef(Handle<Object> value) {

View File

@ -5,7 +5,7 @@
#ifndef V8_WASM_WASM_VALUE_H_ #ifndef V8_WASM_WASM_VALUE_H_
#define V8_WASM_WASM_VALUE_H_ #define V8_WASM_WASM_VALUE_H_
#include "src/common/v8memory.h" #include "src/base/memory.h"
#include "src/handles/handles.h" #include "src/handles/handles.h"
#include "src/utils/boxed-float.h" #include "src/utils/boxed-float.h"
#include "src/wasm/wasm-opcodes.h" #include "src/wasm/wasm-opcodes.h"
@ -35,12 +35,12 @@ class Simd128 {
val_[i] = 0; val_[i] = 0;
} }
} }
#define DEFINE_SIMD_TYPE_SPECIFIC_METHODS(cType, sType, name, size) \ #define DEFINE_SIMD_TYPE_SPECIFIC_METHODS(cType, sType, name, size) \
explicit Simd128(sType val) { \ explicit Simd128(sType val) { \
WriteUnalignedValue<sType>(reinterpret_cast<Address>(val_), val); \ base::WriteUnalignedValue<sType>(reinterpret_cast<Address>(val_), val); \
} \ } \
sType to_##name() { \ sType to_##name() { \
return ReadUnalignedValue<sType>(reinterpret_cast<Address>(val_)); \ return base::ReadUnalignedValue<sType>(reinterpret_cast<Address>(val_)); \
} }
FOREACH_SIMD_TYPE(DEFINE_SIMD_TYPE_SPECIFIC_METHODS) FOREACH_SIMD_TYPE(DEFINE_SIMD_TYPE_SPECIFIC_METHODS)
#undef DEFINE_SIMD_TYPE_SPECIFIC_METHODS #undef DEFINE_SIMD_TYPE_SPECIFIC_METHODS
@ -73,18 +73,20 @@ class WasmValue {
public: public:
WasmValue() : type_(kWasmStmt), bit_pattern_{} {} WasmValue() : type_(kWasmStmt), bit_pattern_{} {}
#define DEFINE_TYPE_SPECIFIC_METHODS(name, localtype, ctype) \ #define DEFINE_TYPE_SPECIFIC_METHODS(name, localtype, ctype) \
explicit WasmValue(ctype v) : type_(localtype), bit_pattern_{} { \ explicit WasmValue(ctype v) : type_(localtype), bit_pattern_{} { \
static_assert(sizeof(ctype) <= sizeof(bit_pattern_), \ static_assert(sizeof(ctype) <= sizeof(bit_pattern_), \
"size too big for WasmValue"); \ "size too big for WasmValue"); \
WriteUnalignedValue<ctype>(reinterpret_cast<Address>(bit_pattern_), v); \ base::WriteUnalignedValue<ctype>(reinterpret_cast<Address>(bit_pattern_), \
} \ v); \
ctype to_##name() const { \ } \
DCHECK_EQ(localtype, type_); \ ctype to_##name() const { \
return to_##name##_unchecked(); \ DCHECK_EQ(localtype, type_); \
} \ return to_##name##_unchecked(); \
ctype to_##name##_unchecked() const { \ } \
return ReadUnalignedValue<ctype>(reinterpret_cast<Address>(bit_pattern_)); \ ctype to_##name##_unchecked() const { \
return base::ReadUnalignedValue<ctype>( \
reinterpret_cast<Address>(bit_pattern_)); \
} }
FOREACH_WASMVAL_TYPE(DEFINE_TYPE_SPECIFIC_METHODS) FOREACH_WASMVAL_TYPE(DEFINE_TYPE_SPECIFIC_METHODS)
#undef DEFINE_TYPE_SPECIFIC_METHODS #undef DEFINE_TYPE_SPECIFIC_METHODS

View File

@ -28,6 +28,8 @@ namespace internal {
namespace wasm { namespace wasm {
namespace test_run_wasm_module { namespace test_run_wasm_module {
using base::ReadLittleEndianValue;
using base::WriteLittleEndianValue;
using testing::CompileAndInstantiateForTesting; using testing::CompileAndInstantiateForTesting;
namespace { namespace {

View File

@ -47,6 +47,9 @@ namespace v8 {
namespace internal { namespace internal {
namespace wasm { namespace wasm {
using base::ReadLittleEndianValue;
using base::WriteLittleEndianValue;
constexpr uint32_t kMaxFunctions = 10; constexpr uint32_t kMaxFunctions = 10;
constexpr uint32_t kMaxGlobalsSize = 128; constexpr uint32_t kMaxGlobalsSize = 128;

View File

@ -69,7 +69,7 @@ class InputProvider {
int NextInt32(int limit) { int NextInt32(int limit) {
if (current_ + sizeof(uint32_t) > end_) return 0; if (current_ + sizeof(uint32_t) > end_) return 0;
int result = int result =
ReadLittleEndianValue<int>(reinterpret_cast<Address>(current_)); base::ReadLittleEndianValue<int>(reinterpret_cast<Address>(current_));
current_ += sizeof(uint32_t); current_ += sizeof(uint32_t);
return result % limit; return result % limit;
} }

View File

@ -353,7 +353,7 @@ TEST_F(FunctionBodyDecoderTest, Float32Const) {
byte code[] = {kExprF32Const, 0, 0, 0, 0}; byte code[] = {kExprF32Const, 0, 0, 0, 0};
Address ptr = reinterpret_cast<Address>(code + 1); Address ptr = reinterpret_cast<Address>(code + 1);
for (int i = 0; i < 30; i++) { for (int i = 0; i < 30; i++) {
WriteLittleEndianValue<float>(ptr, i * -7.75f); base::WriteLittleEndianValue<float>(ptr, i * -7.75f);
ExpectValidates(sigs.f_ff(), code); ExpectValidates(sigs.f_ff(), code);
} }
} }
@ -362,7 +362,7 @@ TEST_F(FunctionBodyDecoderTest, Float64Const) {
byte code[] = {kExprF64Const, 0, 0, 0, 0, 0, 0, 0, 0}; byte code[] = {kExprF64Const, 0, 0, 0, 0, 0, 0, 0, 0};
Address ptr = reinterpret_cast<Address>(code + 1); Address ptr = reinterpret_cast<Address>(code + 1);
for (int i = 0; i < 30; i++) { for (int i = 0; i < 30; i++) {
WriteLittleEndianValue<double>(ptr, i * 33.45); base::WriteLittleEndianValue<double>(ptr, i * 33.45);
ExpectValidates(sigs.d_dd(), code); ExpectValidates(sigs.d_dd(), code);
} }
} }