Commit cd17215a authored by Jakob Kummerow's avatar Jakob Kummerow Committed by Commit Bot

[ubsan] Port HeapNumber to the new design

Bug: v8:3770
Change-Id: Iafde7e4514fcc803b627a4a9b3469c84b7413282
Reviewed-on: https://chromium-review.googlesource.com/c/1382453Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Commit-Queue: Jakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58319}
parent 32562e91
...@@ -162,12 +162,15 @@ class Handle final : public HandleBase { ...@@ -162,12 +162,15 @@ class Handle final : public HandleBase {
std::is_same<S, FixedArrayBase>::value || std::is_same<S, FixedArrayBase>::value ||
std::is_same<S, FixedDoubleArray>::value || std::is_same<S, FixedDoubleArray>::value ||
std::is_same<S, FunctionTemplateInfo>::value || std::is_same<S, FunctionTemplateInfo>::value ||
std::is_same<S, HeapNumber>::value ||
std::is_same<S, JSArray>::value || std::is_same<S, JSArray>::value ||
std::is_same<S, JSFunction>::value || std::is_same<S, JSFunction>::value ||
std::is_same<S, JSGlobalProxy>::value || std::is_same<S, JSGlobalProxy>::value ||
std::is_same<S, JSObject>::value || std::is_same<S, JSObject>::value ||
std::is_same<S, JSReceiver>::value || std::is_same<S, Map>::value || std::is_same<S, JSReceiver>::value || std::is_same<S, Map>::value ||
std::is_same<S, Module>::value || std::is_same<S, Name>::value || std::is_same<S, Module>::value ||
std::is_same<S, MutableHeapNumber>::value ||
std::is_same<S, Name>::value ||
std::is_same<S, NumberDictionary>::value || std::is_same<S, NumberDictionary>::value ||
std::is_same<S, ObjectBoilerplateDescription>::value || std::is_same<S, ObjectBoilerplateDescription>::value ||
std::is_same<S, OrderedHashMap>::value || std::is_same<S, OrderedHashMap>::value ||
......
...@@ -408,7 +408,7 @@ STRUCT_LIST(MAKE_STRUCT_PREDICATE) ...@@ -408,7 +408,7 @@ STRUCT_LIST(MAKE_STRUCT_PREDICATE)
double Object::Number() const { double Object::Number() const {
DCHECK(IsNumber()); DCHECK(IsNumber());
return IsSmi() ? static_cast<double>(Smi(this->ptr())->value()) return IsSmi() ? static_cast<double>(Smi(this->ptr())->value())
: reinterpret_cast<const HeapNumber*>(this)->value(); : HeapNumber::unchecked_cast(this)->value();
} }
bool Object::IsNaN() const { bool Object::IsNaN() const {
......
...@@ -18720,7 +18720,7 @@ Handle<Object> JSDate::SetValue(Handle<JSDate> date, double v) { ...@@ -18720,7 +18720,7 @@ Handle<Object> JSDate::SetValue(Handle<JSDate> date, double v) {
void JSDate::SetValue(Object* value, bool is_value_nan) { void JSDate::SetValue(Object* value, bool is_value_nan) {
set_value(value); set_value(value);
if (is_value_nan) { if (is_value_nan) {
HeapNumber* nan = GetReadOnlyRoots().nan_value(); HeapNumber nan = GetReadOnlyRoots().nan_value();
set_cache_stamp(nan, SKIP_WRITE_BARRIER); set_cache_stamp(nan, SKIP_WRITE_BARRIER);
set_year(nan, SKIP_WRITE_BARRIER); set_year(nan, SKIP_WRITE_BARRIER);
set_month(nan, SKIP_WRITE_BARRIER); set_month(nan, SKIP_WRITE_BARRIER);
......
...@@ -15,8 +15,12 @@ ...@@ -15,8 +15,12 @@
namespace v8 { namespace v8 {
namespace internal { namespace internal {
CAST_ACCESSOR(HeapNumber) OBJECT_CONSTRUCTORS_IMPL(HeapNumberBase, HeapObjectPtr)
CAST_ACCESSOR(MutableHeapNumber) OBJECT_CONSTRUCTORS_IMPL(HeapNumber, HeapNumberBase)
OBJECT_CONSTRUCTORS_IMPL(MutableHeapNumber, HeapNumberBase)
CAST_ACCESSOR2(HeapNumber)
CAST_ACCESSOR2(MutableHeapNumber)
double HeapNumberBase::value() const { double HeapNumberBase::value() const {
return READ_DOUBLE_FIELD(this, kValueOffset); return READ_DOUBLE_FIELD(this, kValueOffset);
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#ifndef V8_OBJECTS_HEAP_NUMBER_H_ #ifndef V8_OBJECTS_HEAP_NUMBER_H_
#define V8_OBJECTS_HEAP_NUMBER_H_ #define V8_OBJECTS_HEAP_NUMBER_H_
#include "src/objects.h" #include "src/objects/heap-object.h"
// Has to be the last include (doesn't have include guards): // Has to be the last include (doesn't have include guards):
#include "src/objects/object-macros.h" #include "src/objects/object-macros.h"
...@@ -17,7 +17,7 @@ namespace internal { ...@@ -17,7 +17,7 @@ namespace internal {
// represented in a Smi (small integer). MutableHeapNumber is the same, but its // represented in a Smi (small integer). MutableHeapNumber is the same, but its
// number value can change over time (it is used only as property storage). // number value can change over time (it is used only as property storage).
// HeapNumberBase merely exists to avoid code duplication. // HeapNumberBase merely exists to avoid code duplication.
class HeapNumberBase : public HeapObject { class HeapNumberBase : public HeapObjectPtr {
public: public:
// [value]: number value. // [value]: number value.
inline double value() const; inline double value() const;
...@@ -58,26 +58,27 @@ class HeapNumberBase : public HeapObject { ...@@ -58,26 +58,27 @@ class HeapNumberBase : public HeapObject {
static const int kMantissaBitsInTopWord = 20; static const int kMantissaBitsInTopWord = 20;
static const int kNonMantissaBitsInTopWord = 12; static const int kNonMantissaBitsInTopWord = 12;
private: // Just to make the macro-generated constructor happy. Subclasses should
DISALLOW_IMPLICIT_CONSTRUCTORS(HeapNumberBase); // perform their own proper type checking.
inline bool IsHeapNumberBase() const { return true; }
OBJECT_CONSTRUCTORS(HeapNumberBase, HeapObjectPtr);
}; };
class HeapNumber : public HeapNumberBase { class HeapNumber : public HeapNumberBase {
public: public:
DECL_CAST(HeapNumber) DECL_CAST2(HeapNumber)
V8_EXPORT_PRIVATE void HeapNumberPrint(std::ostream& os); V8_EXPORT_PRIVATE void HeapNumberPrint(std::ostream& os);
private: OBJECT_CONSTRUCTORS(HeapNumber, HeapNumberBase);
DISALLOW_IMPLICIT_CONSTRUCTORS(HeapNumber);
}; };
class MutableHeapNumber : public HeapNumberBase { class MutableHeapNumber : public HeapNumberBase {
public: public:
DECL_CAST(MutableHeapNumber) DECL_CAST2(MutableHeapNumber)
V8_EXPORT_PRIVATE void MutableHeapNumberPrint(std::ostream& os); V8_EXPORT_PRIVATE void MutableHeapNumberPrint(std::ostream& os);
private: OBJECT_CONSTRUCTORS(MutableHeapNumber, HeapNumberBase);
DISALLOW_IMPLICIT_CONSTRUCTORS(MutableHeapNumber);
}; };
} // namespace internal } // namespace internal
......
...@@ -210,11 +210,11 @@ class RootVisitor; ...@@ -210,11 +210,11 @@ class RootVisitor;
V(WeakFixedArray, empty_weak_fixed_array, EmptyWeakFixedArray) \ V(WeakFixedArray, empty_weak_fixed_array, EmptyWeakFixedArray) \
V(WeakArrayList, empty_weak_array_list, EmptyWeakArrayList) \ V(WeakArrayList, empty_weak_array_list, EmptyWeakArrayList) \
/* Special numbers */ \ /* Special numbers */ \
V(HeapNumber*, nan_value, NanValue) \ V(HeapNumber, nan_value, NanValue) \
V(HeapNumber*, hole_nan_value, HoleNanValue) \ V(HeapNumber, hole_nan_value, HoleNanValue) \
V(HeapNumber*, infinity_value, InfinityValue) \ V(HeapNumber, infinity_value, InfinityValue) \
V(HeapNumber*, minus_zero_value, MinusZeroValue) \ V(HeapNumber, minus_zero_value, MinusZeroValue) \
V(HeapNumber*, minus_infinity_value, MinusInfinityValue) \ V(HeapNumber, minus_infinity_value, MinusInfinityValue) \
/* Marker for self-references during code-generation */ \ /* Marker for self-references during code-generation */ \
V(HeapObject*, self_reference_marker, SelfReferenceMarker) \ V(HeapObject*, self_reference_marker, SelfReferenceMarker) \
/* Canonical trampoline RelocInfo */ \ /* Canonical trampoline RelocInfo */ \
......
...@@ -426,12 +426,12 @@ void ValueSerializer::WriteSmi(Smi smi) { ...@@ -426,12 +426,12 @@ void ValueSerializer::WriteSmi(Smi smi) {
WriteZigZag<int32_t>(smi->value()); WriteZigZag<int32_t>(smi->value());
} }
void ValueSerializer::WriteHeapNumber(HeapNumber* number) { void ValueSerializer::WriteHeapNumber(HeapNumber number) {
WriteTag(SerializationTag::kDouble); WriteTag(SerializationTag::kDouble);
WriteDouble(number->value()); WriteDouble(number->value());
} }
void ValueSerializer::WriteMutableHeapNumber(MutableHeapNumber* number) { void ValueSerializer::WriteMutableHeapNumber(MutableHeapNumber number) {
WriteTag(SerializationTag::kDouble); WriteTag(SerializationTag::kDouble);
WriteDouble(number->value()); WriteDouble(number->value());
} }
......
...@@ -110,8 +110,8 @@ class ValueSerializer { ...@@ -110,8 +110,8 @@ class ValueSerializer {
// Writing V8 objects of various kinds. // Writing V8 objects of various kinds.
void WriteOddball(Oddball* oddball); void WriteOddball(Oddball* oddball);
void WriteSmi(Smi smi); void WriteSmi(Smi smi);
void WriteHeapNumber(HeapNumber* number); void WriteHeapNumber(HeapNumber number);
void WriteMutableHeapNumber(MutableHeapNumber* number); void WriteMutableHeapNumber(MutableHeapNumber number);
void WriteBigInt(BigInt bigint); void WriteBigInt(BigInt bigint);
void WriteString(Handle<String> string); void WriteString(Handle<String> string);
Maybe<bool> WriteJSReceiver(Handle<JSReceiver> receiver) Maybe<bool> WriteJSReceiver(Handle<JSReceiver> receiver)
......
...@@ -291,7 +291,7 @@ ACCESSORS2(AsmWasmData, managed_native_module, Managed<wasm::NativeModule>, ...@@ -291,7 +291,7 @@ ACCESSORS2(AsmWasmData, managed_native_module, Managed<wasm::NativeModule>,
kManagedNativeModuleOffset) kManagedNativeModuleOffset)
ACCESSORS2(AsmWasmData, export_wrappers, FixedArray, kExportWrappersOffset) ACCESSORS2(AsmWasmData, export_wrappers, FixedArray, kExportWrappersOffset)
ACCESSORS2(AsmWasmData, asm_js_offset_table, ByteArray, kAsmJsOffsetTableOffset) ACCESSORS2(AsmWasmData, asm_js_offset_table, ByteArray, kAsmJsOffsetTableOffset)
ACCESSORS(AsmWasmData, uses_bitset, HeapNumber, kUsesBitsetOffset) ACCESSORS2(AsmWasmData, uses_bitset, HeapNumber, kUsesBitsetOffset)
#include "src/objects/object-macros-undef.h" #include "src/objects/object-macros-undef.h"
......
...@@ -715,7 +715,7 @@ class AsmWasmData : public Struct { ...@@ -715,7 +715,7 @@ class AsmWasmData : public Struct {
DECL_ACCESSORS2(managed_native_module, Managed<wasm::NativeModule>) DECL_ACCESSORS2(managed_native_module, Managed<wasm::NativeModule>)
DECL_ACCESSORS2(export_wrappers, FixedArray) DECL_ACCESSORS2(export_wrappers, FixedArray)
DECL_ACCESSORS2(asm_js_offset_table, ByteArray) DECL_ACCESSORS2(asm_js_offset_table, ByteArray)
DECL_ACCESSORS(uses_bitset, HeapNumber) DECL_ACCESSORS2(uses_bitset, HeapNumber)
DECL_CAST2(AsmWasmData) DECL_CAST2(AsmWasmData)
DECL_PRINTER(AsmWasmData) DECL_PRINTER(AsmWasmData)
......
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