summaryrefslogtreecommitdiff
path: root/deps/v8/src/compiler/js-heap-broker.h
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/src/compiler/js-heap-broker.h')
-rw-r--r--deps/v8/src/compiler/js-heap-broker.h250
1 files changed, 160 insertions, 90 deletions
diff --git a/deps/v8/src/compiler/js-heap-broker.h b/deps/v8/src/compiler/js-heap-broker.h
index 8503e82d12..7ea12ee733 100644
--- a/deps/v8/src/compiler/js-heap-broker.h
+++ b/deps/v8/src/compiler/js-heap-broker.h
@@ -9,18 +9,12 @@
#include "src/base/optional.h"
#include "src/globals.h"
#include "src/objects.h"
+#include "src/zone/zone-containers.h"
namespace v8 {
namespace internal {
namespace compiler {
-class DisallowHeapAccess {
- DisallowHeapAllocation no_heap_allocation_;
- DisallowHandleAllocation no_handle_allocation_;
- DisallowHandleDereference no_handle_dereference_;
- DisallowCodeDependencyChange no_dependency_change_;
-};
-
enum class OddballType : uint8_t {
kNone, // Not an Oddball.
kBoolean, // True or False.
@@ -31,6 +25,7 @@ enum class OddballType : uint8_t {
kOther // Oddball, but none of the above.
};
+// TODO(neis): Get rid of the HeapObjectType class.
class HeapObjectType {
public:
enum Flag : uint8_t { kUndetectable = 1 << 0, kCallable = 1 << 1 };
@@ -59,49 +54,63 @@ class HeapObjectType {
Flags const flags_;
};
+// This list is sorted such that subtypes appear before their supertypes.
+// DO NOT VIOLATE THIS PROPERTY!
#define HEAP_BROKER_OBJECT_LIST(V) \
+ /* Subtypes of JSObject */ \
+ V(JSArray) \
+ V(JSFunction) \
+ V(JSGlobalProxy) \
+ V(JSRegExp) \
+ /* Subtypes of Context */ \
+ V(NativeContext) \
+ /* Subtypes of FixedArrayBase */ \
+ V(BytecodeArray) \
+ V(FixedArray) \
+ V(FixedDoubleArray) \
+ /* Subtypes of Name */ \
+ V(InternalizedString) \
+ V(String) \
+ /* Subtypes of HeapObject */ \
V(AllocationSite) \
V(Cell) \
V(Code) \
- V(Context) \
V(FeedbackVector) \
- V(FixedArray) \
+ V(Map) \
+ V(Module) \
+ V(ScopeInfo) \
+ V(ScriptContextTable) \
+ V(SharedFunctionInfo) \
+ V(Context) \
V(FixedArrayBase) \
- V(FixedDoubleArray) \
V(HeapNumber) \
- V(HeapObject) \
- V(InternalizedString) \
- V(JSArray) \
- V(JSFunction) \
- V(JSGlobalProxy) \
V(JSObject) \
- V(JSRegExp) \
- V(Map) \
- V(Module) \
V(MutableHeapNumber) \
V(Name) \
- V(NativeContext) \
V(PropertyCell) \
- V(ScopeInfo) \
- V(ScriptContextTable) \
- V(SharedFunctionInfo) \
- V(String)
+ /* Subtypes of Object */ \
+ V(HeapObject)
class CompilationDependencies;
class JSHeapBroker;
+class ObjectData;
#define FORWARD_DECL(Name) class Name##Ref;
HEAP_BROKER_OBJECT_LIST(FORWARD_DECL)
#undef FORWARD_DECL
class ObjectRef {
public:
- explicit ObjectRef(const JSHeapBroker* broker, Handle<Object> object)
- : broker_(broker), object_(object) {}
+ ObjectRef(JSHeapBroker* broker, Handle<Object> object);
+ explicit ObjectRef(ObjectData* data) : data_(data) { CHECK_NOT_NULL(data_); }
+
+ bool equals(const ObjectRef& other) const;
+ Handle<Object> object() const;
+ // TODO(neis): Remove eventually.
template <typename T>
Handle<T> object() const {
AllowHandleDereference handle_dereference;
- return Handle<T>::cast(object_);
+ return Handle<T>::cast(object());
}
OddballType oddball_type() const;
@@ -109,8 +118,6 @@ class ObjectRef {
bool IsSmi() const;
int AsSmi() const;
- bool equals(const ObjectRef& other) const;
-
#define HEAP_IS_METHOD_DECL(Name) bool Is##Name() const;
HEAP_BROKER_OBJECT_LIST(HEAP_IS_METHOD_DECL)
#undef HEAP_IS_METHOD_DECL
@@ -123,17 +130,14 @@ class ObjectRef {
bool BooleanValue();
double OddballToNumber() const;
+ Isolate* isolate() const;
+
protected:
- const JSHeapBroker* broker() const { return broker_; }
+ JSHeapBroker* broker() const;
+ ObjectData* data() const;
private:
- const JSHeapBroker* broker_;
- Handle<Object> object_;
-};
-
-class FieldTypeRef : public ObjectRef {
- public:
- using ObjectRef::ObjectRef;
+ ObjectData* data_;
};
class HeapObjectRef : public ObjectRef {
@@ -165,30 +169,22 @@ class JSObjectRef : public HeapObjectRef {
FixedArrayBaseRef elements() const;
void EnsureElementsTenured();
- ElementsKind GetElementsKind();
-};
-
-struct SlackTrackingResult {
- SlackTrackingResult(int instance_sizex, int inobject_property_countx)
- : instance_size(instance_sizex),
- inobject_property_count(inobject_property_countx) {}
- int instance_size;
- int inobject_property_count;
+ ElementsKind GetElementsKind() const;
};
class JSFunctionRef : public JSObjectRef {
public:
using JSObjectRef::JSObjectRef;
- bool HasBuiltinFunctionId() const;
- BuiltinFunctionId GetBuiltinFunctionId() const;
bool IsConstructor() const;
bool has_initial_map() const;
MapRef initial_map() const;
+ bool has_prototype() const;
+ ObjectRef prototype() const;
+ bool PrototypeRequiresRuntimeLookup() const;
JSGlobalProxyRef global_proxy() const;
- SlackTrackingResult FinishSlackTracking() const;
+ int InitialMapInstanceSizeWithMinSlack() const;
SharedFunctionInfoRef shared() const;
- void EnsureHasInitialMap() const;
};
class JSRegExpRef : public JSObjectRef {
@@ -224,27 +220,39 @@ class ContextRef : public HeapObjectRef {
ObjectRef get(int index) const;
};
+#define BROKER_NATIVE_CONTEXT_FIELDS(V) \
+ V(JSFunction, array_function) \
+ V(JSFunction, object_function) \
+ V(JSFunction, promise_function) \
+ V(Map, fast_aliased_arguments_map) \
+ V(Map, initial_array_iterator_map) \
+ V(Map, iterator_result_map) \
+ V(Map, js_array_holey_double_elements_map) \
+ V(Map, js_array_holey_elements_map) \
+ V(Map, js_array_holey_smi_elements_map) \
+ V(Map, js_array_packed_double_elements_map) \
+ V(Map, js_array_packed_elements_map) \
+ V(Map, js_array_packed_smi_elements_map) \
+ V(Map, map_key_iterator_map) \
+ V(Map, map_key_value_iterator_map) \
+ V(Map, map_value_iterator_map) \
+ V(Map, set_key_value_iterator_map) \
+ V(Map, set_value_iterator_map) \
+ V(Map, sloppy_arguments_map) \
+ V(Map, strict_arguments_map) \
+ V(Map, string_iterator_map) \
+ V(ScriptContextTable, script_context_table)
+
class NativeContextRef : public ContextRef {
public:
using ContextRef::ContextRef;
- ScriptContextTableRef script_context_table() const;
-
- MapRef fast_aliased_arguments_map() const;
- MapRef sloppy_arguments_map() const;
- MapRef strict_arguments_map() const;
- MapRef js_array_fast_elements_map_index() const;
- MapRef initial_array_iterator_map() const;
- MapRef set_value_iterator_map() const;
- MapRef set_key_value_iterator_map() const;
- MapRef map_key_iterator_map() const;
- MapRef map_value_iterator_map() const;
- MapRef map_key_value_iterator_map() const;
- MapRef iterator_result_map() const;
- MapRef string_iterator_map() const;
- MapRef promise_function_initial_map() const;
+#define DECL_ACCESSOR(type, name) type##Ref name() const;
+ BROKER_NATIVE_CONTEXT_FIELDS(DECL_ACCESSOR)
+#undef DECL_ACCESSOR
MapRef GetFunctionMapFromIndex(int index) const;
+ MapRef GetInitialJSArrayMap(ElementsKind kind) const;
};
class NameRef : public HeapObjectRef {
@@ -276,12 +284,21 @@ class AllocationSiteRef : public HeapObjectRef {
public:
using HeapObjectRef::HeapObjectRef;
- JSObjectRef boilerplate() const;
+ bool PointsToLiteral() const;
PretenureFlag GetPretenureMode() const;
- bool IsFastLiteral() const;
ObjectRef nested_site() const;
- bool PointsToLiteral() const;
+
+ // {IsFastLiteral} 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.
+ //
+ // If PointsToLiteral() is false, then IsFastLiteral() is also false.
+ bool IsFastLiteral() const;
+ // We only serialize boilerplate if IsFastLiteral is true.
+ base::Optional<JSObjectRef> boilerplate() const;
+
ElementsKind GetElementsKind() const;
+ bool CanInlineCall() const;
};
class MapRef : public HeapObjectRef {
@@ -291,26 +308,30 @@ class MapRef : public HeapObjectRef {
int instance_size() const;
InstanceType instance_type() const;
int GetInObjectProperties() const;
+ int GetInObjectPropertiesStartInWords() const;
int NumberOfOwnDescriptors() const;
- PropertyDetails GetPropertyDetails(int i) const;
- NameRef GetPropertyKey(int i) const;
- FieldIndex GetFieldIndexFor(int i) const;
int GetInObjectPropertyOffset(int index) const;
ElementsKind elements_kind() const;
- ObjectRef constructor_or_backpointer() const;
bool is_stable() const;
bool has_prototype_slot() const;
bool is_deprecated() const;
bool CanBeDeprecated() const;
bool CanTransition() const;
bool IsInobjectSlackTrackingInProgress() const;
- MapRef FindFieldOwner(int descriptor) const;
bool is_dictionary_map() const;
bool IsJSArrayMap() const;
bool IsFixedCowArrayMap() const;
+ ObjectRef constructor_or_backpointer() const;
+
+ base::Optional<MapRef> AsElementsKind(ElementsKind kind) const;
+
// Concerning the underlying instance_descriptors:
- FieldTypeRef GetFieldType(int descriptor) const;
+ MapRef FindFieldOwner(int descriptor) const;
+ PropertyDetails GetPropertyDetails(int i) const;
+ NameRef GetPropertyKey(int i) const;
+ FieldIndex GetFieldIndexFor(int i) const;
+ ObjectRef GetFieldType(int descriptor) const;
};
class FixedArrayBaseRef : public HeapObjectRef {
@@ -336,11 +357,17 @@ class FixedDoubleArrayRef : public FixedArrayBaseRef {
bool is_the_hole(int i) const;
};
+class BytecodeArrayRef : public FixedArrayBaseRef {
+ public:
+ using FixedArrayBaseRef::FixedArrayBaseRef;
+
+ int register_count() const;
+};
+
class JSArrayRef : public JSObjectRef {
public:
using JSObjectRef::JSObjectRef;
- ElementsKind GetElementsKind() const;
ObjectRef length() const;
};
@@ -351,22 +378,29 @@ class ScopeInfoRef : public HeapObjectRef {
int ContextLength() const;
};
+#define BROKER_SFI_FIELDS(V) \
+ V(int, internal_formal_parameter_count) \
+ V(bool, has_duplicate_parameters) \
+ V(int, function_map_index) \
+ V(FunctionKind, kind) \
+ V(LanguageMode, language_mode) \
+ V(bool, native) \
+ V(bool, HasBreakInfo) \
+ V(bool, HasBuiltinFunctionId) \
+ V(bool, HasBuiltinId) \
+ V(BuiltinFunctionId, builtin_function_id) \
+ V(bool, construct_as_builtin) \
+ V(bool, HasBytecodeArray)
+
class SharedFunctionInfoRef : public HeapObjectRef {
public:
using HeapObjectRef::HeapObjectRef;
- int internal_formal_parameter_count() const;
- bool has_duplicate_parameters() const;
- int function_map_index() const;
- FunctionKind kind() const;
- LanguageMode language_mode();
- bool native() const;
- bool HasBreakInfo() const;
- bool HasBuiltinId() const;
int builtin_id() const;
- bool construct_as_builtin() const;
- bool HasBytecodeArray() const;
- int GetBytecodeArrayRegisterCount() const;
+ BytecodeArrayRef GetBytecodeArray() const;
+#define DECL_ACCESSOR(type, name) type name() const;
+ BROKER_SFI_FIELDS(DECL_ACCESSOR)
+#undef DECL_ACCSESOR
};
class StringRef : public NameRef {
@@ -375,7 +409,7 @@ class StringRef : public NameRef {
int length() const;
uint16_t GetFirstChar();
- double ToNumber();
+ base::Optional<double> ToNumber();
};
class ModuleRef : public HeapObjectRef {
@@ -407,23 +441,59 @@ class InternalizedStringRef : public StringRef {
class V8_EXPORT_PRIVATE JSHeapBroker : public NON_EXPORTED_BASE(ZoneObject) {
public:
- JSHeapBroker(Isolate* isolate);
+ JSHeapBroker(Isolate* isolate, Zone* zone);
+ void SerializeStandardObjects();
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_; }
+ Zone* zone() const { return zone_; }
+
+ enum BrokerMode { kDisabled, kSerializing, kSerialized };
+ BrokerMode mode() const { return mode_; }
+ void StopSerializing() {
+ CHECK_EQ(mode_, kSerializing);
+ mode_ = kSerialized;
+ }
+ bool SerializingAllowed() const;
+
+ // Returns nullptr iff handle unknown.
+ ObjectData* GetData(Handle<Object>) const;
+ // Never returns nullptr.
+ ObjectData* GetOrCreateData(Handle<Object>);
+
+ void Trace(const char* format, ...) const;
private:
friend class HeapObjectRef;
+ friend class ObjectRef;
+ friend class ObjectData;
+
+ // TODO(neis): Remove eventually.
HeapObjectType HeapObjectTypeFromMap(Map* map) const;
+ void AddData(Handle<Object> object, ObjectData* data);
+
Isolate* const isolate_;
-};
+ Zone* const zone_;
+ ZoneUnorderedMap<Address, ObjectData*> refs_;
+ BrokerMode mode_;
+};
+
+#define ASSIGN_RETURN_NO_CHANGE_IF_DATA_MISSING(something_var, \
+ optionally_something) \
+ auto optionally_something_ = optionally_something; \
+ if (!optionally_something_) \
+ return NoChangeBecauseOfMissingData(js_heap_broker(), __FUNCTION__, \
+ __LINE__); \
+ something_var = *optionally_something_;
+
+class Reduction;
+Reduction NoChangeBecauseOfMissingData(JSHeapBroker* broker,
+ const char* function, int line);
} // namespace compiler
} // namespace internal