Commit 79b61ed6 authored by Jakob Kummerow's avatar Jakob Kummerow Committed by Commit Bot

[ubsan] Port Struct subclasses, part 3

AsmWasmData, WasmDebugInfo, WasmExceptionTag, WasmExportedFunctionData

Bug: v8:3770
Change-Id: I0343daaa10bdb9dfaba07f28051821077703a106
Reviewed-on: https://chromium-review.googlesource.com/c/1377456
Commit-Queue: Jakob Kummerow <jkummerow@chromium.org>
Reviewed-by: 's avatarDeepti Gandluri <gdeepti@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58256}
parent c31f33b2
......@@ -1911,7 +1911,7 @@ WasmInstanceObject WasmInterpreterEntryFrame::wasm_instance() const {
return WasmInstanceObject::cast(instance);
}
WasmDebugInfo* WasmInterpreterEntryFrame::debug_info() const {
WasmDebugInfo WasmInterpreterEntryFrame::debug_info() const {
return wasm_instance()->debug_info();
}
......
......@@ -987,7 +987,7 @@ class WasmInterpreterEntryFrame final : public StandardFrame {
Code unchecked_code() const override;
// Accessors.
WasmDebugInfo* debug_info() const;
WasmDebugInfo debug_info() const;
WasmInstanceObject wasm_instance() const;
Script* script() const override;
......
......@@ -36,6 +36,7 @@ class OrderedNameDictionary;
class SmallOrderedHashMap;
class SmallOrderedHashSet;
class SmallOrderedNameDictionary;
class WasmExportedFunctionData;
// ----------------------------------------------------------------------------
// Base class for Handle instantiations. Don't use directly.
......@@ -178,6 +179,7 @@ class Handle final : public HandleBase {
std::is_same<S, SmallOrderedHashSet>::value ||
std::is_same<S, SmallOrderedNameDictionary>::value ||
std::is_same<S, String>::value || std::is_same<S, Symbol>::value ||
std::is_same<S, WasmExportedFunctionData>::value ||
std::is_same<S, WasmInstanceObject>::value))>::type>
V8_INLINE Handle(Handle<S> handle) : HandleBase(handle) {}
......
......@@ -39,11 +39,13 @@ class MaybeHandle final {
// Constructor for handling automatic up casting.
// Ex. MaybeHandle<JSArray> can be passed when Handle<Object> is expected.
// TODO(3770): Remove std::is_same special cases after the migration.
template <typename S, typename = typename std::enable_if<
template <typename S,
typename = typename std::enable_if<
std::is_convertible<S*, T*>::value ||
std::is_same<T, Object>::value ||
(std::is_same<T, HeapObject>::value &&
std::is_same<S, Map>::value)>::type>
(std::is_same<S, Map>::value ||
std::is_same<S, WasmExportedFunctionData>::value))>::type>
V8_INLINE MaybeHandle(MaybeHandle<S> maybe_handle)
: location_(maybe_handle.location_) {}
......
......@@ -1746,7 +1746,7 @@ void ArrayBoilerplateDescription::ArrayBoilerplateDescriptionPrint(
}
void AsmWasmData::AsmWasmDataPrint(std::ostream& os) { // NOLINT
HeapObject::PrintHeader(os, "AsmWasmData");
PrintHeader(os, "AsmWasmData");
os << "\n - native module: " << Brief(managed_native_module());
os << "\n - export_wrappers: " << Brief(export_wrappers());
os << "\n - offset table: " << Brief(asm_js_offset_table());
......@@ -1755,13 +1755,13 @@ void AsmWasmData::AsmWasmDataPrint(std::ostream& os) { // NOLINT
}
void WasmDebugInfo::WasmDebugInfoPrint(std::ostream& os) { // NOLINT
HeapObject::PrintHeader(os, "WasmDebugInfo");
PrintHeader(os, "WasmDebugInfo");
os << "\n - wasm_instance: " << Brief(wasm_instance());
os << "\n";
}
void WasmExceptionTag::WasmExceptionTagPrint(std::ostream& os) { // NOLINT
HeapObject::PrintHeader(os, "WasmExceptionTag");
PrintHeader(os, "WasmExceptionTag");
os << "\n - index: " << index();
os << "\n";
}
......@@ -1814,7 +1814,7 @@ void WasmInstanceObject::WasmInstanceObjectPrint(std::ostream& os) { // NOLINT
void WasmExportedFunctionData::WasmExportedFunctionDataPrint(
std::ostream& os) { // NOLINT
HeapObject::PrintHeader(os, "WasmExportedFunctionData");
PrintHeader(os, "WasmExportedFunctionData");
os << "\n - wrapper_code: " << Brief(wrapper_code());
os << "\n - instance: " << Brief(instance());
os << "\n - function_index: " << function_index();
......
......@@ -13954,7 +13954,7 @@ Code SharedFunctionInfo::GetCode() const {
UNREACHABLE();
}
WasmExportedFunctionData* SharedFunctionInfo::wasm_exported_function_data()
WasmExportedFunctionData SharedFunctionInfo::wasm_exported_function_data()
const {
DCHECK(HasWasmExportedFunctionData());
return WasmExportedFunctionData::cast(function_data());
......
......@@ -509,12 +509,12 @@ bool SharedFunctionInfo::HasAsmWasmData() const {
return function_data()->IsAsmWasmData();
}
AsmWasmData* SharedFunctionInfo::asm_wasm_data() const {
AsmWasmData SharedFunctionInfo::asm_wasm_data() const {
DCHECK(HasAsmWasmData());
return AsmWasmData::cast(function_data());
}
void SharedFunctionInfo::set_asm_wasm_data(AsmWasmData* data) {
void SharedFunctionInfo::set_asm_wasm_data(AsmWasmData data) {
DCHECK(function_data() == Smi::FromEnum(Builtins::kCompileLazy) ||
HasUncompiledData() || HasAsmWasmData());
set_function_data(data);
......
......@@ -329,8 +329,8 @@ class SharedFunctionInfo : public HeapObjectPtr {
inline BytecodeArray GetDebugBytecodeArray() const;
inline void SetDebugBytecodeArray(BytecodeArray bytecode);
inline bool HasAsmWasmData() const;
inline AsmWasmData* asm_wasm_data() const;
inline void set_asm_wasm_data(AsmWasmData* data);
inline AsmWasmData asm_wasm_data() const;
inline void set_asm_wasm_data(AsmWasmData data);
// A brief note to clear up possible confusion:
// builtin_id corresponds to the auto-generated
......@@ -350,8 +350,7 @@ class SharedFunctionInfo : public HeapObjectPtr {
UncompiledDataWithPreParsedScope data);
inline bool HasUncompiledDataWithoutPreParsedScope() const;
inline bool HasWasmExportedFunctionData() const;
WasmExportedFunctionData* wasm_exported_function_data() const;
inline void set_wasm_exported_function_data(WasmExportedFunctionData* data);
WasmExportedFunctionData wasm_exported_function_data() const;
// Clear out pre-parsed scope data from UncompiledDataWithPreParsedScope,
// turning it into UncompiledDataWithoutPreParsedScope.
......
......@@ -129,7 +129,7 @@ class InterpreterHandle {
return {frame_base, frame_limit};
}
static ModuleWireBytes GetBytes(WasmDebugInfo* debug_info) {
static ModuleWireBytes GetBytes(WasmDebugInfo debug_info) {
// Return raw pointer into heap. The WasmInterpreter will make its own copy
// of this data anyway, and there is no heap allocation in-between.
NativeModule* native_module =
......@@ -539,13 +539,13 @@ wasm::InterpreterHandle* GetOrCreateInterpreterHandle(
return Handle<Managed<wasm::InterpreterHandle>>::cast(handle)->raw();
}
wasm::InterpreterHandle* GetInterpreterHandle(WasmDebugInfo* debug_info) {
wasm::InterpreterHandle* GetInterpreterHandle(WasmDebugInfo debug_info) {
Object* handle_obj = debug_info->interpreter_handle();
DCHECK(!handle_obj->IsUndefined());
return Managed<wasm::InterpreterHandle>::cast(handle_obj)->raw();
}
wasm::InterpreterHandle* GetInterpreterHandleOrNull(WasmDebugInfo* debug_info) {
wasm::InterpreterHandle* GetInterpreterHandleOrNull(WasmDebugInfo debug_info) {
Object* handle_obj = debug_info->interpreter_handle();
if (handle_obj->IsUndefined()) return nullptr;
return Managed<wasm::InterpreterHandle>::cast(handle_obj)->raw();
......@@ -636,7 +636,7 @@ void WasmDebugInfo::RedirectToInterpreter(Handle<WasmDebugInfo> debug_info,
}
void WasmDebugInfo::PrepareStep(StepAction step_action) {
GetInterpreterHandle(this)->PrepareStep(step_action);
GetInterpreterHandle(*this)->PrepareStep(step_action);
}
// static
......@@ -653,20 +653,20 @@ bool WasmDebugInfo::RunInterpreter(Isolate* isolate,
std::vector<std::pair<uint32_t, int>> WasmDebugInfo::GetInterpretedStack(
Address frame_pointer) {
return GetInterpreterHandle(this)->GetInterpretedStack(frame_pointer);
return GetInterpreterHandle(*this)->GetInterpretedStack(frame_pointer);
}
wasm::WasmInterpreter::FramePtr WasmDebugInfo::GetInterpretedFrame(
Address frame_pointer, int idx) {
return GetInterpreterHandle(this)->GetInterpretedFrame(frame_pointer, idx);
return GetInterpreterHandle(*this)->GetInterpretedFrame(frame_pointer, idx);
}
void WasmDebugInfo::Unwind(Address frame_pointer) {
return GetInterpreterHandle(this)->Unwind(frame_pointer);
return GetInterpreterHandle(*this)->Unwind(frame_pointer);
}
uint64_t WasmDebugInfo::NumInterpretedCalls() {
auto* handle = GetInterpreterHandleOrNull(this);
auto* handle = GetInterpreterHandleOrNull(*this);
return handle ? handle->NumInterpretedCalls() : 0;
}
......
......@@ -22,22 +22,28 @@ namespace v8 {
namespace internal {
OBJECT_CONSTRUCTORS_IMPL(WasmExceptionObject, JSObject)
OBJECT_CONSTRUCTORS_IMPL(WasmExceptionTag, StructPtr)
OBJECT_CONSTRUCTORS_IMPL(WasmExportedFunctionData, StructPtr)
OBJECT_CONSTRUCTORS_IMPL(WasmDebugInfo, StructPtr)
OBJECT_CONSTRUCTORS_IMPL(WasmGlobalObject, JSObject)
OBJECT_CONSTRUCTORS_IMPL(WasmInstanceObject, JSObject)
OBJECT_CONSTRUCTORS_IMPL(WasmMemoryObject, JSObject)
OBJECT_CONSTRUCTORS_IMPL(WasmModuleObject, JSObject)
OBJECT_CONSTRUCTORS_IMPL(WasmTableObject, JSObject)
OBJECT_CONSTRUCTORS_IMPL(AsmWasmData, StructPtr)
CAST_ACCESSOR(WasmDebugInfo)
NEVER_READ_ONLY_SPACE_IMPL(WasmDebugInfo)
CAST_ACCESSOR2(WasmDebugInfo)
CAST_ACCESSOR2(WasmExceptionObject)
CAST_ACCESSOR(WasmExceptionTag)
CAST_ACCESSOR(WasmExportedFunctionData)
CAST_ACCESSOR2(WasmExceptionTag)
CAST_ACCESSOR2(WasmExportedFunctionData)
CAST_ACCESSOR2(WasmGlobalObject)
CAST_ACCESSOR2(WasmInstanceObject)
CAST_ACCESSOR2(WasmMemoryObject)
CAST_ACCESSOR2(WasmModuleObject)
CAST_ACCESSOR2(WasmTableObject)
CAST_ACCESSOR(AsmWasmData)
CAST_ACCESSOR2(AsmWasmData)
#define OPTIONAL_ACCESSORS(holder, name, type, offset) \
bool holder::has_##name() { \
......@@ -200,7 +206,7 @@ OPTIONAL_ACCESSORS2(WasmInstanceObject, globals_buffer, JSArrayBuffer,
kGlobalsBufferOffset)
OPTIONAL_ACCESSORS2(WasmInstanceObject, imported_mutable_globals_buffers,
FixedArray, kImportedMutableGlobalsBuffersOffset)
OPTIONAL_ACCESSORS(WasmInstanceObject, debug_info, WasmDebugInfo,
OPTIONAL_ACCESSORS2(WasmInstanceObject, debug_info, WasmDebugInfo,
kDebugInfoOffset)
OPTIONAL_ACCESSORS2(WasmInstanceObject, table_object, WasmTableObject,
kTableObjectOffset)
......
......@@ -396,7 +396,7 @@ class WasmInstanceObject : public JSObject {
DECL_OPTIONAL_ACCESSORS2(memory_object, WasmMemoryObject)
DECL_OPTIONAL_ACCESSORS2(globals_buffer, JSArrayBuffer)
DECL_OPTIONAL_ACCESSORS2(imported_mutable_globals_buffers, FixedArray)
DECL_OPTIONAL_ACCESSORS(debug_info, WasmDebugInfo)
DECL_OPTIONAL_ACCESSORS2(debug_info, WasmDebugInfo)
DECL_OPTIONAL_ACCESSORS2(table_object, WasmTableObject)
DECL_ACCESSORS2(imported_function_refs, FixedArray)
DECL_OPTIONAL_ACCESSORS2(indirect_function_table_refs, FixedArray)
......@@ -548,14 +548,14 @@ class WasmExportedFunction : public JSFunction {
// Information for a WasmExportedFunction which is referenced as the function
// data of the SharedFunctionInfo underlying the function. For details please
// see the {SharedFunctionInfo::HasWasmExportedFunctionData} predicate.
class WasmExportedFunctionData : public Struct {
class WasmExportedFunctionData : public StructPtr {
public:
DECL_ACCESSORS2(wrapper_code, Code);
DECL_ACCESSORS2(instance, WasmInstanceObject)
DECL_INT_ACCESSORS(jump_table_offset);
DECL_INT_ACCESSORS(function_index);
DECL_CAST(WasmExportedFunctionData)
DECL_CAST2(WasmExportedFunctionData)
// Dispatched behavior.
DECL_PRINTER(WasmExportedFunctionData)
......@@ -572,10 +572,13 @@ class WasmExportedFunctionData : public Struct {
DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize,
WASM_EXPORTED_FUNCTION_DATA_FIELDS)
#undef WASM_EXPORTED_FUNCTION_DATA_FIELDS
OBJECT_CONSTRUCTORS(WasmExportedFunctionData, StructPtr)
};
class WasmDebugInfo : public Struct, public NeverReadOnlySpaceObject {
class WasmDebugInfo : public StructPtr {
public:
NEVER_READ_ONLY_SPACE
DECL_ACCESSORS2(wasm_instance, WasmInstanceObject)
DECL_ACCESSORS(interpreter_handle, Object); // Foreign or undefined
DECL_ACCESSORS2(interpreted_functions, FixedArray);
......@@ -583,7 +586,7 @@ class WasmDebugInfo : public Struct, public NeverReadOnlySpaceObject {
DECL_OPTIONAL_ACCESSORS2(c_wasm_entries, FixedArray)
DECL_OPTIONAL_ACCESSORS(c_wasm_entry_map, Managed<wasm::SignatureMap>)
DECL_CAST(WasmDebugInfo)
DECL_CAST2(WasmDebugInfo)
// Dispatched behavior.
DECL_PRINTER(WasmDebugInfo)
......@@ -667,13 +670,15 @@ class WasmDebugInfo : public Struct, public NeverReadOnlySpaceObject {
static Handle<JSFunction> GetCWasmEntry(Handle<WasmDebugInfo>,
wasm::FunctionSig*);
OBJECT_CONSTRUCTORS(WasmDebugInfo, StructPtr)
};
// Tags provide an object identity for each exception defined in a wasm module
// header. They are referenced by the following fields:
// - {WasmExceptionObject::exception_tag} : The tag of the exception object.
// - {WasmInstanceObject::exceptions_table}: List of tags used by an instance.
class WasmExceptionTag : public Struct {
class WasmExceptionTag : public StructPtr {
public:
static Handle<WasmExceptionTag> New(Isolate* isolate, int index);
......@@ -682,7 +687,7 @@ class WasmExceptionTag : public Struct {
// least one field, hence this also serves as a padding field for now.
DECL_INT_ACCESSORS(index);
DECL_CAST(WasmExceptionTag)
DECL_CAST2(WasmExceptionTag)
DECL_PRINTER(WasmExceptionTag)
DECL_VERIFIER(WasmExceptionTag)
......@@ -694,9 +699,11 @@ class WasmExceptionTag : public Struct {
DEFINE_FIELD_OFFSET_CONSTANTS(Struct::kHeaderSize, WASM_EXCEPTION_TAG_FIELDS)
#undef WASM_EXCEPTION_TAG_FIELDS
OBJECT_CONSTRUCTORS(WasmExceptionTag, StructPtr)
};
class AsmWasmData : public Struct {
class AsmWasmData : public StructPtr {
public:
static Handle<AsmWasmData> New(
Isolate* isolate, std::shared_ptr<wasm::NativeModule> native_module,
......@@ -708,7 +715,7 @@ class AsmWasmData : public Struct {
DECL_ACCESSORS2(asm_js_offset_table, ByteArray)
DECL_ACCESSORS(uses_bitset, HeapNumber)
DECL_CAST(AsmWasmData)
DECL_CAST2(AsmWasmData)
DECL_PRINTER(AsmWasmData)
DECL_VERIFIER(AsmWasmData)
......@@ -723,6 +730,8 @@ class AsmWasmData : public Struct {
DEFINE_FIELD_OFFSET_CONSTANTS(Struct::kHeaderSize, ASM_WASM_DATA_FIELDS)
#undef ASM_WASM_DATA_FIELDS
OBJECT_CONSTRUCTORS(AsmWasmData, StructPtr)
};
#undef DECL_OPTIONAL_ACCESSORS
......
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