Commit a74a7960 authored by Georg Neis's avatar Georg Neis Committed by Commit Bot

[turbofan] Cleanup heap broker a little.

R=jarin@chromium.org

Bug: v8:7790
Change-Id: Ic1b1d47a655972d2b2f6264550db4fa5898fa46e
Reviewed-on: https://chromium-review.googlesource.com/1128871Reviewed-by: 's avatarJaroslav Sevcik <jarin@chromium.org>
Commit-Queue: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54339}
parent e51439d0
......@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "src/compiler/js-heap-broker.h"
#include "src/compiler/compilation-dependencies.h"
#include "src/objects-inl.h"
#include "src/objects/js-regexp-inl.h"
......@@ -11,33 +12,12 @@ namespace v8 {
namespace internal {
namespace compiler {
HeapObjectRef::HeapObjectRef(Handle<Object> object) : ObjectRef(object) {
AllowHandleDereference handle_dereference;
DCHECK(object->IsHeapObject());
}
MapRef HeapObjectRef::map(const JSHeapBroker* broker) const {
AllowHandleAllocation handle_allocation;
AllowHandleDereference allow_handle_dereference;
return MapRef(handle(object<HeapObject>()->map(), broker->isolate()));
}
JSFunctionRef::JSFunctionRef(Handle<Object> object) : JSObjectRef(object) {
AllowHandleDereference handle_dereference;
DCHECK(object->IsJSFunction());
}
HeapNumberRef::HeapNumberRef(Handle<Object> object) : HeapObjectRef(object) {
AllowHandleDereference handle_dereference;
DCHECK(object->IsHeapNumber());
}
MutableHeapNumberRef::MutableHeapNumberRef(Handle<Object> object)
: HeapObjectRef(object) {
AllowHandleDereference handle_dereference;
DCHECK(object->IsMutableHeapNumber());
}
double HeapNumberRef::value() const {
AllowHandleDereference allow_handle_dereference;
return object<HeapNumber>()->value();
......@@ -48,16 +28,6 @@ double MutableHeapNumberRef::value() const {
return object<MutableHeapNumber>()->value();
}
ContextRef::ContextRef(Handle<Object> object) : HeapObjectRef(object) {
AllowHandleDereference handle_dereference;
DCHECK(object->IsContext());
}
NativeContextRef::NativeContextRef(Handle<Object> object) : ContextRef(object) {
AllowHandleDereference handle_dereference;
DCHECK(object->IsNativeContext());
}
bool ObjectRef::IsSmi() const {
AllowHandleDereference allow_handle_dereference;
return object_->IsSmi();
......@@ -129,21 +99,17 @@ base::Optional<int> JSHeapBroker::TryGetSmi(Handle<Object> object) {
return Smi::cast(*object)->value();
}
#define HEAP_KIND_FUNCTIONS_DEF(Name) \
#define DEFINE_IS_AND_AS(Name) \
bool ObjectRef::Is##Name() const { \
AllowHandleDereference allow_handle_dereference; \
return object<Object>()->Is##Name(); \
}
HEAP_BROKER_KIND_LIST(HEAP_KIND_FUNCTIONS_DEF)
#undef HEAP_KIND_FUNCTIONS_DEF
#define HEAP_DATA_FUNCTIONS_DEF(Name) \
} \
Name##Ref ObjectRef::As##Name() const { \
DCHECK(Is##Name()); \
return Name##Ref(object<HeapObject>()); \
}
HEAP_BROKER_DATA_LIST(HEAP_DATA_FUNCTIONS_DEF)
#undef HEAP_DATA_FUNCTIONS_DEF
HEAP_BROKER_OBJECT_LIST(DEFINE_IS_AND_AS)
#undef DEFINE_IS_AND_AS
HeapObjectType HeapObjectRef::type(const JSHeapBroker* broker) const {
AllowHandleDereference allow_handle_dereference;
......@@ -207,17 +173,6 @@ MapRef JSFunctionRef::initial_map(const JSHeapBroker* broker) const {
return MapRef(handle(object<JSFunction>()->initial_map(), broker->isolate()));
}
NameRef::NameRef(Handle<Object> object) : HeapObjectRef(object) {
AllowHandleDereference handle_dereference;
DCHECK(object->IsName());
}
ScriptContextTableRef::ScriptContextTableRef(Handle<Object> object)
: HeapObjectRef(object) {
AllowHandleDereference handle_dereference;
DCHECK(object->IsScriptContextTable());
}
base::Optional<ScriptContextTableRef::LookupResult>
ScriptContextTableRef::lookup(const NameRef& name) const {
AllowHandleDereference handle_dereference;
......@@ -372,7 +327,7 @@ const int kMaxFastLiteralProperties = JSObject::kMaxInObjectProperties;
// Determines whether the given array or object literal boilerplate satisfies
// all limits to be considered for fast deep-copying and computes the total
// size of all objects that are part of the graph.
bool AllocationSiteRef::IsFastLiteral(const JSHeapBroker* broker) {
bool AllocationSiteRef::IsFastLiteral(const JSHeapBroker* broker) const {
AllowHandleDereference allow_handle_dereference;
int max_properties = kMaxFastLiteralProperties;
Handle<JSObject> boilerplate(object<AllocationSite>()->boilerplate(),
......
......@@ -14,8 +14,6 @@ namespace v8 {
namespace internal {
namespace compiler {
class CompilationDependencies;
enum class OddballType : uint8_t {
kNone, // Not an Oddball.
kBoolean, // True or False.
......@@ -54,7 +52,7 @@ class HeapObjectType {
Flags const flags_;
};
#define HEAP_BROKER_DATA_LIST(V) \
#define HEAP_BROKER_OBJECT_LIST(V) \
V(AllocationSite) \
V(Context) \
V(FeedbackVector) \
......@@ -63,30 +61,26 @@ class HeapObjectType {
V(FixedDoubleArray) \
V(HeapNumber) \
V(HeapObject) \
V(InternalizedString) \
V(JSArray) \
V(JSFunction) \
V(JSObject) \
V(JSRegExp) \
V(Map) \
V(MutableHeapNumber) \
V(Name) \
V(NativeContext) \
V(ScopeInfo) \
V(ScriptContextTable) \
V(SharedFunctionInfo) \
V(Map) \
V(String)
#define HEAP_BROKER_KIND_LIST(V) \
HEAP_BROKER_DATA_LIST(V) \
V(InternalizedString)
class CompilationDependencies;
class JSHeapBroker;
#define FORWARD_DECL(Name) class Name##Ref;
HEAP_BROKER_DATA_LIST(FORWARD_DECL)
HEAP_BROKER_OBJECT_LIST(FORWARD_DECL)
#undef FORWARD_DECL
class JSHeapBroker;
class HeapObjectRef;
class ObjectRef {
public:
explicit ObjectRef(Handle<Object> object) : object_(object) {}
......@@ -107,11 +101,11 @@ class ObjectRef {
bool equals(const ObjectRef& other) const;
#define HEAP_IS_METHOD_DECL(Name) bool Is##Name() const;
HEAP_BROKER_KIND_LIST(HEAP_IS_METHOD_DECL)
HEAP_BROKER_OBJECT_LIST(HEAP_IS_METHOD_DECL)
#undef HEAP_IS_METHOD_DECL
#define HEAP_AS_METHOD_DECL(Name) Name##Ref As##Name() const;
HEAP_BROKER_DATA_LIST(HEAP_AS_METHOD_DECL)
HEAP_BROKER_OBJECT_LIST(HEAP_AS_METHOD_DECL)
#undef HEAP_AS_METHOD_DECL
private:
......@@ -120,40 +114,17 @@ class ObjectRef {
class HeapObjectRef : public ObjectRef {
public:
explicit HeapObjectRef(Handle<Object> object);
HeapObjectType type(const JSHeapBroker* broker) const;
using ObjectRef::ObjectRef;
HeapObjectType type(const JSHeapBroker* broker) const;
MapRef map(const JSHeapBroker* broker) const;
base::Optional<MapRef> TryGetObjectCreateMap(
const JSHeapBroker* broker) const;
private:
friend class JSHeapBroker;
};
class V8_EXPORT_PRIVATE JSHeapBroker : public NON_EXPORTED_BASE(ZoneObject) {
public:
JSHeapBroker(Isolate* isolate);
HeapObjectType HeapObjectTypeFromMap(Handle<Map> map) const {
AllowHandleDereference handle_dereference;
return HeapObjectTypeFromMap(*map);
}
static base::Optional<int> TryGetSmi(Handle<Object> object);
Isolate* isolate() const { return isolate_; }
private:
friend class HeapObjectRef;
HeapObjectType HeapObjectTypeFromMap(Map* map) const;
Isolate* const isolate_;
};
class JSObjectRef : public HeapObjectRef {
public:
explicit JSObjectRef(Handle<Object> object) : HeapObjectRef(object) {}
using HeapObjectRef::HeapObjectRef;
bool IsUnboxedDoubleField(FieldIndex index) const;
double RawFastDoublePropertyAt(FieldIndex index) const;
......@@ -166,7 +137,7 @@ class JSObjectRef : public HeapObjectRef {
class JSFunctionRef : public JSObjectRef {
public:
explicit JSFunctionRef(Handle<Object> object);
using JSObjectRef::JSObjectRef;
bool HasBuiltinFunctionId() const;
BuiltinFunctionId GetBuiltinFunctionId() const;
......@@ -181,7 +152,7 @@ class JSFunctionRef : public JSObjectRef {
class JSRegExpRef : public JSObjectRef {
public:
explicit JSRegExpRef(Handle<Object> object) : JSObjectRef(object) {}
using JSObjectRef::JSObjectRef;
ObjectRef raw_properties_or_hash(const JSHeapBroker* broker) const;
ObjectRef data(const JSHeapBroker* broker) const;
......@@ -192,26 +163,29 @@ class JSRegExpRef : public JSObjectRef {
class HeapNumberRef : public HeapObjectRef {
public:
explicit HeapNumberRef(Handle<Object> object);
using HeapObjectRef::HeapObjectRef;
double value() const;
};
class MutableHeapNumberRef : public HeapObjectRef {
public:
explicit MutableHeapNumberRef(Handle<Object> object);
using HeapObjectRef::HeapObjectRef;
double value() const;
};
class ContextRef : public HeapObjectRef {
public:
explicit ContextRef(Handle<Object> object);
using HeapObjectRef::HeapObjectRef;
base::Optional<ContextRef> previous(const JSHeapBroker* broker) const;
ObjectRef get(const JSHeapBroker* broker, int index) const;
};
class NativeContextRef : public ContextRef {
public:
explicit NativeContextRef(Handle<Object> object);
using ContextRef::ContextRef;
ScriptContextTableRef script_context_table(const JSHeapBroker* broker) const;
......@@ -231,12 +205,12 @@ class NativeContextRef : public ContextRef {
class NameRef : public HeapObjectRef {
public:
explicit NameRef(Handle<Object> object);
using HeapObjectRef::HeapObjectRef;
};
class ScriptContextTableRef : public HeapObjectRef {
public:
explicit ScriptContextTableRef(Handle<Object> object);
using HeapObjectRef::HeapObjectRef;
struct LookupResult {
ContextRef context;
......@@ -249,80 +223,73 @@ class ScriptContextTableRef : public HeapObjectRef {
class FeedbackVectorRef : public HeapObjectRef {
public:
explicit FeedbackVectorRef(Handle<Object> object) : HeapObjectRef(object) {}
using HeapObjectRef::HeapObjectRef;
ObjectRef get(const JSHeapBroker* broker, FeedbackSlot slot) const;
};
class AllocationSiteRef : public HeapObjectRef {
public:
explicit AllocationSiteRef(Handle<HeapObject> object)
: HeapObjectRef(object) {}
using HeapObjectRef::HeapObjectRef;
JSObjectRef boilerplate(const JSHeapBroker* broker) const;
PretenureFlag GetPretenureMode() const;
bool IsFastLiteral(const JSHeapBroker* broker);
bool IsFastLiteral(const JSHeapBroker* broker) const;
};
class MapRef : public HeapObjectRef {
public:
explicit MapRef(Handle<HeapObject> object) : HeapObjectRef(object) {}
using HeapObjectRef::HeapObjectRef;
int instance_size() const;
InstanceType instance_type() const;
int GetInObjectProperties() const;
int NumberOfOwnDescriptors() const;
PropertyDetails GetPropertyDetails(int i) const;
NameRef GetPropertyKey(const JSHeapBroker* broker, int i) const;
FieldIndex GetFieldIndexFor(int i) const;
int GetInObjectPropertyOffset(int index) const;
bool is_dictionary_map() const;
ObjectRef constructor_or_backpointer(const JSHeapBroker* broker) const;
bool IsJSArrayMap() const;
bool IsFixedCowArrayMap(const JSHeapBroker* broker) const;
bool is_stable() const;
bool has_prototype_slot() const;
bool CanTransition() const;
bool IsInobjectSlackTrackingInProgress() const;
bool is_dictionary_map() const;
bool IsJSArrayMap() const;
bool IsFixedCowArrayMap(const JSHeapBroker* broker) const;
void DependOnStableMap(const JSHeapBroker* broker,
CompilationDependencies* dependencies) const;
};
class FixedArrayBaseRef : public HeapObjectRef {
public:
explicit FixedArrayBaseRef(Handle<HeapObject> object)
: HeapObjectRef(object) {}
using HeapObjectRef::HeapObjectRef;
int length() const;
};
class FixedArrayRef : public FixedArrayBaseRef {
public:
explicit FixedArrayRef(Handle<HeapObject> object)
: FixedArrayBaseRef(object) {}
using FixedArrayBaseRef::FixedArrayBaseRef;
bool is_the_hole(const JSHeapBroker* broker, int i) const;
ObjectRef get(const JSHeapBroker* broker, int i) const;
bool is_the_hole(const JSHeapBroker* broker, int i) const;
};
class FixedDoubleArrayRef : public FixedArrayBaseRef {
public:
explicit FixedDoubleArrayRef(Handle<HeapObject> object)
: FixedArrayBaseRef(object) {}
using FixedArrayBaseRef::FixedArrayBaseRef;
bool is_the_hole(int i) const;
double get_scalar(int i) const;
bool is_the_hole(int i) const;
};
class JSArrayRef : public JSObjectRef {
public:
explicit JSArrayRef(Handle<Object> object) : JSObjectRef(object) {}
using JSObjectRef::JSObjectRef;
ElementsKind GetElementsKind() const;
ObjectRef length(const JSHeapBroker* broker) const;
......@@ -330,15 +297,14 @@ class JSArrayRef : public JSObjectRef {
class ScopeInfoRef : public HeapObjectRef {
public:
explicit ScopeInfoRef(Handle<Object> object) : HeapObjectRef(object) {}
using HeapObjectRef::HeapObjectRef;
int ContextLength() const;
};
class SharedFunctionInfoRef : public HeapObjectRef {
public:
explicit SharedFunctionInfoRef(Handle<Object> object)
: HeapObjectRef(object) {}
using HeapObjectRef::HeapObjectRef;
int internal_formal_parameter_count() const;
bool has_duplicate_parameters() const;
......@@ -347,12 +313,37 @@ class SharedFunctionInfoRef : public HeapObjectRef {
class StringRef : public NameRef {
public:
explicit StringRef(Handle<Object> object) : NameRef(object) {}
using NameRef::NameRef;
int length() const;
uint16_t GetFirstChar();
};
class InternalizedStringRef : public StringRef {
public:
using StringRef::StringRef;
};
class V8_EXPORT_PRIVATE JSHeapBroker : public NON_EXPORTED_BASE(ZoneObject) {
public:
JSHeapBroker(Isolate* isolate);
HeapObjectType HeapObjectTypeFromMap(Handle<Map> map) const {
AllowHandleDereference handle_dereference;
return HeapObjectTypeFromMap(*map);
}
static base::Optional<int> TryGetSmi(Handle<Object> object);
Isolate* isolate() const { return isolate_; }
private:
friend class HeapObjectRef;
HeapObjectType HeapObjectTypeFromMap(Map* map) const;
Isolate* const isolate_;
};
} // namespace compiler
} // namespace internal
} // namespace v8
......
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