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 {
std::is_same<S, FixedArrayBase>::value ||
std::is_same<S, FixedDoubleArray>::value ||
std::is_same<S, FunctionTemplateInfo>::value ||
std::is_same<S, HeapNumber>::value ||
std::is_same<S, JSArray>::value ||
std::is_same<S, JSFunction>::value ||
std::is_same<S, JSGlobalProxy>::value ||
std::is_same<S, JSObject>::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, ObjectBoilerplateDescription>::value ||
std::is_same<S, OrderedHashMap>::value ||
......
......@@ -408,7 +408,7 @@ STRUCT_LIST(MAKE_STRUCT_PREDICATE)
double Object::Number() const {
DCHECK(IsNumber());
return IsSmi() ? static_cast<double>(Smi(this->ptr())->value())
: reinterpret_cast<const HeapNumber*>(this)->value();
: HeapNumber::unchecked_cast(this)->value();
}
bool Object::IsNaN() const {
......
......@@ -18720,7 +18720,7 @@ Handle<Object> JSDate::SetValue(Handle<JSDate> date, double v) {
void JSDate::SetValue(Object* value, bool is_value_nan) {
set_value(value);
if (is_value_nan) {
HeapNumber* nan = GetReadOnlyRoots().nan_value();
HeapNumber nan = GetReadOnlyRoots().nan_value();
set_cache_stamp(nan, SKIP_WRITE_BARRIER);
set_year(nan, SKIP_WRITE_BARRIER);
set_month(nan, SKIP_WRITE_BARRIER);
......
......@@ -15,8 +15,12 @@
namespace v8 {
namespace internal {
CAST_ACCESSOR(HeapNumber)
CAST_ACCESSOR(MutableHeapNumber)
OBJECT_CONSTRUCTORS_IMPL(HeapNumberBase, HeapObjectPtr)
OBJECT_CONSTRUCTORS_IMPL(HeapNumber, HeapNumberBase)
OBJECT_CONSTRUCTORS_IMPL(MutableHeapNumber, HeapNumberBase)
CAST_ACCESSOR2(HeapNumber)
CAST_ACCESSOR2(MutableHeapNumber)
double HeapNumberBase::value() const {
return READ_DOUBLE_FIELD(this, kValueOffset);
......
......@@ -5,7 +5,7 @@
#ifndef 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):
#include "src/objects/object-macros.h"
......@@ -17,7 +17,7 @@ namespace internal {
// 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).
// HeapNumberBase merely exists to avoid code duplication.
class HeapNumberBase : public HeapObject {
class HeapNumberBase : public HeapObjectPtr {
public:
// [value]: number value.
inline double value() const;
......@@ -58,26 +58,27 @@ class HeapNumberBase : public HeapObject {
static const int kMantissaBitsInTopWord = 20;
static const int kNonMantissaBitsInTopWord = 12;
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(HeapNumberBase);
// Just to make the macro-generated constructor happy. Subclasses should
// perform their own proper type checking.
inline bool IsHeapNumberBase() const { return true; }
OBJECT_CONSTRUCTORS(HeapNumberBase, HeapObjectPtr);
};
class HeapNumber : public HeapNumberBase {
public:
DECL_CAST(HeapNumber)
DECL_CAST2(HeapNumber)
V8_EXPORT_PRIVATE void HeapNumberPrint(std::ostream& os);
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(HeapNumber);
OBJECT_CONSTRUCTORS(HeapNumber, HeapNumberBase);
};
class MutableHeapNumber : public HeapNumberBase {
public:
DECL_CAST(MutableHeapNumber)
DECL_CAST2(MutableHeapNumber)
V8_EXPORT_PRIVATE void MutableHeapNumberPrint(std::ostream& os);
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(MutableHeapNumber);
OBJECT_CONSTRUCTORS(MutableHeapNumber, HeapNumberBase);
};
} // namespace internal
......
......@@ -210,11 +210,11 @@ class RootVisitor;
V(WeakFixedArray, empty_weak_fixed_array, EmptyWeakFixedArray) \
V(WeakArrayList, empty_weak_array_list, EmptyWeakArrayList) \
/* Special numbers */ \
V(HeapNumber*, nan_value, NanValue) \
V(HeapNumber*, hole_nan_value, HoleNanValue) \
V(HeapNumber*, infinity_value, InfinityValue) \
V(HeapNumber*, minus_zero_value, MinusZeroValue) \
V(HeapNumber*, minus_infinity_value, MinusInfinityValue) \
V(HeapNumber, nan_value, NanValue) \
V(HeapNumber, hole_nan_value, HoleNanValue) \
V(HeapNumber, infinity_value, InfinityValue) \
V(HeapNumber, minus_zero_value, MinusZeroValue) \
V(HeapNumber, minus_infinity_value, MinusInfinityValue) \
/* Marker for self-references during code-generation */ \
V(HeapObject*, self_reference_marker, SelfReferenceMarker) \
/* Canonical trampoline RelocInfo */ \
......
......@@ -426,12 +426,12 @@ void ValueSerializer::WriteSmi(Smi smi) {
WriteZigZag<int32_t>(smi->value());
}
void ValueSerializer::WriteHeapNumber(HeapNumber* number) {
void ValueSerializer::WriteHeapNumber(HeapNumber number) {
WriteTag(SerializationTag::kDouble);
WriteDouble(number->value());
}
void ValueSerializer::WriteMutableHeapNumber(MutableHeapNumber* number) {
void ValueSerializer::WriteMutableHeapNumber(MutableHeapNumber number) {
WriteTag(SerializationTag::kDouble);
WriteDouble(number->value());
}
......
......@@ -110,8 +110,8 @@ class ValueSerializer {
// Writing V8 objects of various kinds.
void WriteOddball(Oddball* oddball);
void WriteSmi(Smi smi);
void WriteHeapNumber(HeapNumber* number);
void WriteMutableHeapNumber(MutableHeapNumber* number);
void WriteHeapNumber(HeapNumber number);
void WriteMutableHeapNumber(MutableHeapNumber number);
void WriteBigInt(BigInt bigint);
void WriteString(Handle<String> string);
Maybe<bool> WriteJSReceiver(Handle<JSReceiver> receiver)
......
......@@ -291,7 +291,7 @@ ACCESSORS2(AsmWasmData, managed_native_module, Managed<wasm::NativeModule>,
kManagedNativeModuleOffset)
ACCESSORS2(AsmWasmData, export_wrappers, FixedArray, kExportWrappersOffset)
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"
......
......@@ -715,7 +715,7 @@ class AsmWasmData : public Struct {
DECL_ACCESSORS2(managed_native_module, Managed<wasm::NativeModule>)
DECL_ACCESSORS2(export_wrappers, FixedArray)
DECL_ACCESSORS2(asm_js_offset_table, ByteArray)
DECL_ACCESSORS(uses_bitset, HeapNumber)
DECL_ACCESSORS2(uses_bitset, HeapNumber)
DECL_CAST2(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