[turbofan] Rearrange heap broker classes.

Bug: v8:7790
Change-Id: I0508596370470068ee07bfd7e441a4e393266c11
Reviewed-on: https://chromium-review.googlesource.com/1099238
Reviewed-by: Jaroslav Sevcik <jarin@chromium.org>
Commit-Queue: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53735}
This commit is contained in:
Georg Neis 2018-06-14 15:50:28 +02:00 committed by Commit Bot
parent 87fe40134a
commit 17db4a30cc
5 changed files with 54 additions and 52 deletions

View File

@ -42,9 +42,7 @@ HeapReferenceType JSHeapBroker::HeapReferenceTypeFromMap(Map* map) const {
HeapReference JSHeapBroker::HeapReferenceForObject(
Handle<Object> object) const {
AllowHandleDereference allow_handle_dereference;
Handle<HeapObject> heap_object = Handle<HeapObject>::cast(object);
HeapReferenceType type = HeapReferenceTypeFromMap(heap_object->map());
return HeapReference(heap_object, type);
return HeapReference(Handle<HeapObject>::cast(object));
}
// static
@ -62,24 +60,33 @@ base::Optional<int> JSHeapBroker::TryGetSmi(Handle<Object> object) {
HEAP_BROKER_KIND_LIST(HEAP_KIND_FUNCTIONS_DEF)
#undef HEAP_KIND_FUNCTIONS_DEF
NumberHeapData HeapReference::AsNumber() const {
#define HEAP_DATA_FUNCTIONS_DEF(Name) \
Name##HeapReference HeapReference::As##Name() const { \
AllowHandleDereference allow_handle_dereference; \
SLOW_DCHECK(object_->Is##Name()); \
return Name##HeapReference(object_); \
}
HEAP_BROKER_DATA_LIST(HEAP_DATA_FUNCTIONS_DEF)
#undef HEAP_DATA_FUNCTIONS_DEF
HeapReferenceType HeapReference::type(const JSHeapBroker* broker) const {
AllowHandleDereference allow_handle_dereference;
return NumberHeapData(object_->Number());
return broker->HeapReferenceTypeFromMap(object_->map());
}
JSFunctionHeapData HeapReference::AsJSFunction() const {
double NumberHeapReference::value() const {
AllowHandleDereference allow_handle_dereference;
return JSFunctionHeapData(Handle<JSFunction>::cast(object_));
return object()->Number();
}
bool JSFunctionHeapData::HasBuiltinFunctionId() const {
bool JSFunctionHeapReference::HasBuiltinFunctionId() const {
AllowHandleDereference allow_handle_dereference;
return function_->shared()->HasBuiltinFunctionId();
return JSFunction::cast(*object())->shared()->HasBuiltinFunctionId();
}
BuiltinFunctionId JSFunctionHeapData::GetBuiltinFunctionId() const {
BuiltinFunctionId JSFunctionHeapReference::GetBuiltinFunctionId() const {
AllowHandleDereference allow_handle_dereference;
return function_->shared()->builtin_function_id();
return JSFunction::cast(*object())->shared()->builtin_function_id();
}
} // namespace compiler

View File

@ -14,32 +14,6 @@ namespace v8 {
namespace internal {
namespace compiler {
class JSFunctionHeapData {
public:
bool HasBuiltinFunctionId() const;
BuiltinFunctionId GetBuiltinFunctionId() const;
private:
friend class HeapReference;
explicit JSFunctionHeapData(Handle<JSFunction> function)
: function_(function) {}
Handle<JSFunction> const function_;
};
class NumberHeapData {
public:
double value() const { return value_; }
private:
friend class HeapReference;
explicit NumberHeapData(double value) : value_(value) {}
double const value_;
};
class HeapReferenceType {
public:
enum OddballType : uint8_t { kUnknown, kBoolean, kUndefined, kNull, kHole };
@ -72,30 +46,33 @@ class HeapReferenceType {
#define HEAP_BROKER_KIND_LIST(V) \
HEAP_BROKER_DATA_LIST(V) \
V(String) \
V(InternalizedString)
V(InternalizedString) \
V(String)
#define FORWARD_DECL(Name) class Name##HeapReference;
HEAP_BROKER_DATA_LIST(FORWARD_DECL)
#undef FORWARD_DECL
class JSHeapBroker;
class HeapReference {
public:
explicit HeapReference(Handle<HeapObject> object) : object_(object) {}
#define HEAP_IS_METHOD_DECL(Name) bool Is##Name() const;
HEAP_BROKER_KIND_LIST(HEAP_IS_METHOD_DECL)
#undef HEAP_IS_METHOD_DECL
#define HEAP_AS_METHOD_DECL(Name) Name##HeapData As##Name() const;
#define HEAP_AS_METHOD_DECL(Name) Name##HeapReference As##Name() const;
HEAP_BROKER_DATA_LIST(HEAP_AS_METHOD_DECL)
#undef HEAP_AS_METHOD_DECL
const HeapReferenceType& type() const { return type_; }
Handle<HeapObject> value() const { return object_; }
HeapReferenceType type(const JSHeapBroker* broker) const;
Handle<HeapObject> object() const { return object_; }
private:
friend class JSHeapBroker;
HeapReference(Handle<HeapObject> object, const HeapReferenceType& type)
: object_(object), type_(type) {}
Handle<HeapObject> const object_;
HeapReferenceType const type_;
};
class V8_EXPORT_PRIVATE JSHeapBroker : public NON_EXPORTED_BASE(ZoneObject) {
@ -111,9 +88,26 @@ class V8_EXPORT_PRIVATE JSHeapBroker : public NON_EXPORTED_BASE(ZoneObject) {
static base::Optional<int> TryGetSmi(Handle<Object> object);
private:
friend class HeapReference;
HeapReferenceType HeapReferenceTypeFromMap(Map* map) const;
Isolate* const isolate_;
Isolate* isolate() const { return isolate_; }
};
class JSFunctionHeapReference : public HeapReference {
public:
explicit JSFunctionHeapReference(Handle<HeapObject> object)
: HeapReference(object) {}
bool HasBuiltinFunctionId() const;
BuiltinFunctionId GetBuiltinFunctionId() const;
};
class NumberHeapReference : public HeapReference {
public:
explicit NumberHeapReference(Handle<HeapObject> object)
: HeapReference(object) {}
double value() const;
};
} // namespace compiler

View File

@ -1405,7 +1405,7 @@ Type Typer::Visitor::JSCallTyper(Type fun, Typer* t) {
if (!fun.IsHeapConstant() || !fun.AsHeapConstant()->Ref().IsJSFunction()) {
return Type::NonInternal();
}
JSFunctionHeapData function = fun.AsHeapConstant()->Ref().AsJSFunction();
JSFunctionHeapReference function = fun.AsHeapConstant()->Ref().AsJSFunction();
if (!function.HasBuiltinFunctionId()) {
return Type::NonInternal();
}

View File

@ -1045,7 +1045,7 @@ Type Type::OtherNumberConstant(double value, Zone* zone) {
Type Type::HeapConstant(const JSHeapBroker* js_heap_broker,
Handle<i::Object> value, Zone* zone) {
return FromTypeBase(HeapConstantType::New(
js_heap_broker->HeapReferenceForObject(value), zone));
js_heap_broker, js_heap_broker->HeapReferenceForObject(value), zone));
}
// static

View File

@ -534,17 +534,18 @@ class OtherNumberConstantType : public TypeBase {
class V8_EXPORT_PRIVATE HeapConstantType : public NON_EXPORTED_BASE(TypeBase) {
public:
Handle<HeapObject> Value() const { return heap_ref_.value(); }
Handle<HeapObject> Value() const { return heap_ref_.object(); }
const HeapReference& Ref() const { return heap_ref_; }
private:
friend class Type;
friend class BitsetType;
static HeapConstantType* New(const HeapReference& heap_ref, Zone* zone) {
static HeapConstantType* New(const JSHeapBroker* broker,
const HeapReference& heap_ref, Zone* zone) {
DCHECK(!heap_ref.IsNumber());
DCHECK_IMPLIES(heap_ref.IsString(), heap_ref.IsInternalizedString());
BitsetType::bitset bitset = BitsetType::Lub(heap_ref.type());
BitsetType::bitset bitset = BitsetType::Lub(heap_ref.type(broker));
return new (zone->New(sizeof(HeapConstantType)))
HeapConstantType(bitset, heap_ref);
}