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

[turbofan] Mechanically create the right *Data object.

Also define classes NativeContext and InternalizedString. Those object
kinds were already part of our Object hierarchy but didn't have their
own class, which was inconvenient.

R=jarin@chromium.org, mslekova@chromium.org

Bug: v8:7790
Cq-Include-Trybots: luci.v8.try:v8_linux_noi18n_rel_ng
Change-Id: Ic443a2b2e34afc89bc924e845d995e3f287a2535
Reviewed-on: https://chromium-review.googlesource.com/1185592Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Reviewed-by: 's avatarJaroslav Sevcik <jarin@chromium.org>
Commit-Queue: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55402}
parent 29879461
......@@ -168,7 +168,7 @@ class Genesis BASE_EMBEDDED {
Handle<JSGlobalProxy> global_proxy() { return global_proxy_; }
private:
Handle<Context> native_context() { return native_context_; }
Handle<NativeContext> native_context() { return native_context_; }
// Creates some basic objects. Used for creating a context from scratch.
void CreateRoots();
......@@ -297,7 +297,7 @@ class Genesis BASE_EMBEDDED {
Isolate* isolate_;
Handle<Context> result_;
Handle<Context> native_context_;
Handle<NativeContext> native_context_;
Handle<JSGlobalProxy> global_proxy_;
// Temporary function maps needed only during bootstrapping.
......@@ -3962,7 +3962,7 @@ void Bootstrapper::ExportFromRuntime(Isolate* isolate,
Handle<JSObject> container) {
Factory* factory = isolate->factory();
HandleScope scope(isolate);
Handle<Context> native_context = isolate->native_context();
Handle<NativeContext> native_context = isolate->native_context();
#define EXPORT_PRIVATE_SYMBOL(NAME) \
Handle<String> NAME##_name = factory->NewStringFromAsciiChecked(#NAME); \
JSObject::AddProperty(isolate, container, NAME##_name, factory->NAME(), NONE);
......@@ -5663,12 +5663,15 @@ Genesis::Genesis(
// We can only de-serialize a context if the isolate was initialized from
// a snapshot. Otherwise we have to build the context from scratch.
// Also create a context from scratch to expose natives, if required by flag.
if (!isolate->initialized_from_snapshot() ||
!Snapshot::NewContextFromSnapshot(isolate, global_proxy,
context_snapshot_index,
embedder_fields_deserializer)
.ToHandle(&native_context_)) {
native_context_ = Handle<Context>();
DCHECK(native_context_.is_null());
if (isolate->initialized_from_snapshot()) {
Handle<Context> context;
if (Snapshot::NewContextFromSnapshot(isolate, global_proxy,
context_snapshot_index,
embedder_fields_deserializer)
.ToHandle(&context)) {
native_context_ = Handle<NativeContext>::cast(context);
}
}
if (!native_context().is_null()) {
......
......@@ -532,8 +532,8 @@ BUILTIN(NumberFormatPrototypeFormatNumber) {
return *bound_format;
}
Handle<Context> native_context =
Handle<Context>(isolate->context()->native_context(), isolate);
Handle<NativeContext> native_context(isolate->context()->native_context(),
isolate);
Handle<Context> context = isolate->factory()->NewBuiltinContext(
native_context, NumberFormat::ContextSlot::kLength);
......@@ -621,8 +621,8 @@ BUILTIN(DateTimeFormatPrototypeFormat) {
return *bound_format;
}
Handle<Context> native_context =
Handle<Context>(isolate->context()->native_context(), isolate);
Handle<NativeContext> native_context(isolate->context()->native_context(),
isolate);
Handle<Context> context = isolate->factory()->NewBuiltinContext(
native_context, DateFormat::ContextSlot::kLength);
......@@ -1211,8 +1211,8 @@ BUILTIN(CollatorPrototypeCompare) {
return *bound_compare;
}
Handle<Context> native_context =
Handle<Context>(isolate->context()->native_context(), isolate);
Handle<NativeContext> native_context(isolate->context()->native_context(),
isolate);
Handle<Context> context = isolate->factory()->NewBuiltinContext(
native_context, JSCollator::ContextSlot::kLength);
......
This diff is collapsed.
......@@ -54,34 +54,42 @@ 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) \
V(AllocationSite) \
/* 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;
......
......@@ -47,6 +47,11 @@ Context* Context::cast(Object* context) {
return reinterpret_cast<Context*>(context);
}
NativeContext* NativeContext::cast(Object* context) {
DCHECK(context->IsNativeContext());
return reinterpret_cast<NativeContext*>(context);
}
void Context::set_scope_info(ScopeInfo* scope_info) {
set(SCOPE_INFO_INDEX, scope_info);
}
......@@ -68,21 +73,16 @@ void Context::set_extension(HeapObject* object) {
set(EXTENSION_INDEX, object);
}
Context* Context::native_context() const {
NativeContext* Context::native_context() const {
Object* result = get(NATIVE_CONTEXT_INDEX);
DCHECK(IsBootstrappingOrNativeContext(this->GetIsolate(), result));
return reinterpret_cast<Context*>(result);
return reinterpret_cast<NativeContext*>(result);
}
void Context::set_native_context(Context* context) {
void Context::set_native_context(NativeContext* context) {
set(NATIVE_CONTEXT_INDEX, context);
}
bool Context::IsNativeContext() const {
return map()->instance_type() == NATIVE_CONTEXT_TYPE;
}
bool Context::IsFunctionContext() const {
return map()->instance_type() == FUNCTION_CONTEXT_TYPE;
}
......
......@@ -10,6 +10,7 @@
namespace v8 {
namespace internal {
class NativeContext;
class RegExpMatchInfo;
enum ContextLookupFlags {
......@@ -537,13 +538,11 @@ class Context : public FixedArray, public NeverReadOnlySpaceObject {
Context* script_context();
// Compute the native context.
inline Context* native_context() const;
inline void set_native_context(Context* context);
inline NativeContext* native_context() const;
inline void set_native_context(NativeContext* context);
// Predicates for context types. IsNativeContext is also defined on Object
// because we frequently have to know if arbitrary objects are natives
// contexts.
inline bool IsNativeContext() const;
// Predicates for context types. IsNativeContext is already defined on
// Object.
inline bool IsFunctionContext() const;
inline bool IsCatchContext() const;
inline bool IsWithContext() const;
......@@ -642,6 +641,15 @@ class Context : public FixedArray, public NeverReadOnlySpaceObject {
STATIC_ASSERT(EMBEDDER_DATA_INDEX == Internals::kContextEmbedderDataIndex);
};
class NativeContext : public Context {
public:
static inline NativeContext* cast(Object* context);
// TODO(neis): Move some stuff from Context here.
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(NativeContext);
};
typedef Context::Field ContextField;
} // namespace internal
......
......@@ -1353,21 +1353,19 @@ Handle<Symbol> Factory::NewPrivateFieldSymbol() {
return symbol;
}
Handle<Context> Factory::NewNativeContext() {
Handle<Context> context = NewFixedArrayWithMap<Context>(
Handle<NativeContext> Factory::NewNativeContext() {
Handle<NativeContext> context = NewFixedArrayWithMap<NativeContext>(
Heap::kNativeContextMapRootIndex, Context::NATIVE_CONTEXT_SLOTS, TENURED);
context->set_native_context(*context);
context->set_errors_thrown(Smi::kZero);
context->set_math_random_index(Smi::kZero);
context->set_serialized_objects(*empty_fixed_array());
DCHECK(context->IsNativeContext());
return context;
}
Handle<Context> Factory::NewScriptContext(Handle<Context> outer,
Handle<Context> Factory::NewScriptContext(Handle<NativeContext> outer,
Handle<ScopeInfo> scope_info) {
DCHECK_EQ(scope_info->scope_type(), SCRIPT_SCOPE);
DCHECK(outer->IsNativeContext());
Handle<Context> context = NewFixedArrayWithMap<Context>(
Heap::kScriptContextMapRootIndex, scope_info->ContextLength(), TENURED);
context->set_scope_info(*scope_info);
......@@ -1388,7 +1386,7 @@ Handle<ScriptContextTable> Factory::NewScriptContextTable() {
}
Handle<Context> Factory::NewModuleContext(Handle<Module> module,
Handle<Context> outer,
Handle<NativeContext> outer,
Handle<ScopeInfo> scope_info) {
DCHECK_EQ(scope_info->scope_type(), MODULE_SCOPE);
Handle<Context> context = NewFixedArrayWithMap<Context>(
......@@ -1483,7 +1481,7 @@ Handle<Context> Factory::NewBlockContext(Handle<Context> previous,
return context;
}
Handle<Context> Factory::NewBuiltinContext(Handle<Context> native_context,
Handle<Context> Factory::NewBuiltinContext(Handle<NativeContext> native_context,
int length) {
DCHECK_GE(length, Context::MIN_CONTEXT_SLOTS);
Handle<Context> context =
......@@ -2304,7 +2302,7 @@ Handle<JSFunction> Factory::NewFunction(const NewFunctionArgs& args) {
DCHECK(!args.name_.is_null());
// Create the SharedFunctionInfo.
Handle<Context> context(isolate()->native_context());
Handle<NativeContext> context(isolate()->native_context());
Handle<Map> map = args.GetMap(isolate());
Handle<SharedFunctionInfo> info =
NewSharedFunctionInfo(args.name_, args.maybe_exported_function_data_,
......@@ -2385,8 +2383,8 @@ Handle<JSFunction> Factory::NewFunction(const NewFunctionArgs& args) {
Handle<JSObject> Factory::NewFunctionPrototype(Handle<JSFunction> function) {
// Make sure to use globals from the function's context, since the function
// can be from a different context.
Handle<Context> native_context(function->context()->native_context(),
isolate());
Handle<NativeContext> native_context(function->context()->native_context(),
isolate());
Handle<Map> new_map;
if (V8_UNLIKELY(IsAsyncGeneratorFunction(function->shared()->kind()))) {
new_map = handle(native_context->async_generator_object_prototype_map(),
......@@ -2915,7 +2913,7 @@ Handle<JSObject> Factory::NewSlowJSObjectFromMap(Handle<Map> map, int capacity,
Handle<JSArray> Factory::NewJSArray(ElementsKind elements_kind,
PretenureFlag pretenure) {
Context* native_context = isolate()->raw_native_context();
NativeContext* native_context = isolate()->raw_native_context();
Map* map = native_context->GetInitialJSArrayMap(elements_kind);
if (map == nullptr) {
JSFunction* array_function = native_context->array_function();
......@@ -2982,7 +2980,7 @@ void Factory::NewJSArrayStorage(Handle<JSArray> array, int length, int capacity,
}
Handle<JSWeakMap> Factory::NewJSWeakMap() {
Context* native_context = isolate()->raw_native_context();
NativeContext* native_context = isolate()->raw_native_context();
Handle<Map> map(native_context->js_weak_map_fun()->initial_map(), isolate());
Handle<JSWeakMap> weakmap(JSWeakMap::cast(*NewJSObjectFromMap(map)),
isolate());
......@@ -3153,7 +3151,7 @@ static void ForFixedTypedArray(ExternalArrayType array_type,
}
JSFunction* GetTypedArrayFun(ExternalArrayType type, Isolate* isolate) {
Context* native_context = isolate->context()->native_context();
NativeContext* native_context = isolate->context()->native_context();
switch (type) {
#define TYPED_ARRAY_FUN(Type, type, TYPE, ctype) \
case kExternal##Type##Array: \
......@@ -3166,7 +3164,7 @@ JSFunction* GetTypedArrayFun(ExternalArrayType type, Isolate* isolate) {
}
JSFunction* GetTypedArrayFun(ElementsKind elements_kind, Isolate* isolate) {
Context* native_context = isolate->context()->native_context();
NativeContext* native_context = isolate->context()->native_context();
switch (elements_kind) {
#define TYPED_ARRAY_FUN(Type, type, TYPE, ctype) \
case TYPE##_ELEMENTS: \
......@@ -3729,14 +3727,12 @@ Handle<JSObject> Factory::NewArgumentsObject(Handle<JSFunction> callee,
return result;
}
Handle<Map> Factory::ObjectLiteralMapFromCache(Handle<Context> native_context,
Handle<Map> Factory::ObjectLiteralMapFromCache(Handle<NativeContext> context,
int number_of_properties) {
DCHECK(native_context->IsNativeContext());
if (number_of_properties == 0) {
// Reuse the initial map of the Object function if the literal has no
// predeclared properties.
return handle(native_context->object_function()->initial_map(), isolate());
return handle(context->object_function()->initial_map(), isolate());
}
// We do not cache maps for too many properties or when running builtin code.
......@@ -3747,16 +3743,15 @@ Handle<Map> Factory::ObjectLiteralMapFromCache(Handle<Context> native_context,
// Use initial slow object proto map for too many properties.
const int kMapCacheSize = 128;
if (number_of_properties > kMapCacheSize) {
return handle(native_context->slow_object_with_object_prototype_map(),
isolate());
return handle(context->slow_object_with_object_prototype_map(), isolate());
}
int cache_index = number_of_properties - 1;
Handle<Object> maybe_cache(native_context->map_cache(), isolate());
Handle<Object> maybe_cache(context->map_cache(), isolate());
if (maybe_cache->IsUndefined(isolate())) {
// Allocate the new map cache for the native context.
maybe_cache = NewWeakFixedArray(kMapCacheSize, TENURED);
native_context->set_map_cache(*maybe_cache);
context->set_map_cache(*maybe_cache);
} else {
// Check to see whether there is a matching element in the cache.
Handle<WeakFixedArray> cache = Handle<WeakFixedArray>::cast(maybe_cache);
......
......@@ -50,6 +50,7 @@ class JSSetIterator;
class JSWeakMap;
class LoadHandler;
class ModuleInfo;
class NativeContext;
class NewFunctionArgs;
class PreParsedScopeData;
class PromiseResolveThenableJobTask;
......@@ -361,17 +362,18 @@ class V8_EXPORT_PRIVATE Factory {
Handle<Symbol> NewPrivateFieldSymbol();
// Create a global (but otherwise uninitialized) context.
Handle<Context> NewNativeContext();
Handle<NativeContext> NewNativeContext();
// Create a script context.
Handle<Context> NewScriptContext(Handle<Context> outer,
Handle<Context> NewScriptContext(Handle<NativeContext> outer,
Handle<ScopeInfo> scope_info);
// Create an empty script context table.
Handle<ScriptContextTable> NewScriptContextTable();
// Create a module context.
Handle<Context> NewModuleContext(Handle<Module> module, Handle<Context> outer,
Handle<Context> NewModuleContext(Handle<Module> module,
Handle<NativeContext> outer,
Handle<ScopeInfo> scope_info);
// Create a function or eval context.
......@@ -403,7 +405,8 @@ class V8_EXPORT_PRIVATE Factory {
// These are similar to function context but don't have a previous
// context or any scope info. These are used to store spec defined
// context values.
Handle<Context> NewBuiltinContext(Handle<Context> native_context, int length);
Handle<Context> NewBuiltinContext(Handle<NativeContext> native_context,
int length);
Handle<Struct> NewStruct(InstanceType type,
PretenureFlag pretenure = NOT_TENURED);
......@@ -914,7 +917,7 @@ class V8_EXPORT_PRIVATE Factory {
// Return a map for given number of properties using the map cache in the
// native context.
Handle<Map> ObjectLiteralMapFromCache(Handle<Context> native_context,
Handle<Map> ObjectLiteralMapFromCache(Handle<NativeContext> native_context,
int number_of_properties);
Handle<LoadHandler> NewLoadHandler(int data_count);
......
......@@ -26,11 +26,13 @@ void Isolate::set_context(Context* context) {
thread_local_top_.context_ = context;
}
Handle<Context> Isolate::native_context() {
Handle<NativeContext> Isolate::native_context() {
return handle(context()->native_context(), this);
}
Context* Isolate::raw_native_context() { return context()->native_context(); }
NativeContext* Isolate::raw_native_context() {
return context()->native_context();
}
Object* Isolate::pending_exception() {
DCHECK(has_pending_exception());
......
......@@ -3772,7 +3772,8 @@ MaybeHandle<JSPromise> NewRejectedPromise(Isolate* isolate,
MaybeHandle<JSPromise> Isolate::RunHostImportModuleDynamicallyCallback(
Handle<Script> referrer, Handle<Object> specifier) {
v8::Local<v8::Context> api_context = v8::Utils::ToLocal(native_context());
v8::Local<v8::Context> api_context =
v8::Utils::ToLocal(Handle<Context>(native_context()));
if (host_import_module_dynamically_callback_ == nullptr) {
Handle<Object> exception =
......@@ -3811,7 +3812,8 @@ Handle<JSObject> Isolate::RunHostInitializeImportMetaObjectCallback(
if (host_meta->IsTheHole(this)) {
host_meta = factory()->NewJSObjectWithNullProto();
if (host_initialize_import_meta_object_callback_ != nullptr) {
v8::Local<v8::Context> api_context = v8::Utils::ToLocal(native_context());
v8::Local<v8::Context> api_context =
v8::Utils::ToLocal(Handle<Context>(native_context()));
host_initialize_import_meta_object_callback_(
api_context, Utils::ToLocal(module),
v8::Local<v8::Object>::Cast(v8::Utils::ToLocal(host_meta)));
......
......@@ -955,8 +955,8 @@ class Isolate : private HiddenFactory {
void IterateThread(ThreadVisitor* v, char* t);
// Returns the current native context.
inline Handle<Context> native_context();
inline Context* raw_native_context();
inline Handle<NativeContext> native_context();
inline NativeContext* raw_native_context();
Handle<Context> GetIncumbentContext();
......
......@@ -26,6 +26,7 @@ CAST_ACCESSOR(ConsString)
CAST_ACCESSOR(ExternalOneByteString)
CAST_ACCESSOR(ExternalString)
CAST_ACCESSOR(ExternalTwoByteString)
CAST_ACCESSOR(InternalizedString)
CAST_ACCESSOR(SeqOneByteString)
CAST_ACCESSOR(SeqString)
CAST_ACCESSOR(SeqTwoByteString)
......
......@@ -487,6 +487,15 @@ class SeqString : public String {
DISALLOW_IMPLICIT_CONSTRUCTORS(SeqString);
};
class InternalizedString : public String {
public:
DECL_CAST(InternalizedString)
// TODO(neis): Possibly move some stuff from String here.
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(InternalizedString);
};
// The OneByteString class captures sequential one-byte string objects.
// Each character in the OneByteString is an one-byte character.
class SeqOneByteString : public SeqString {
......
......@@ -320,7 +320,7 @@ struct ObjectLiteralHelper {
static Handle<JSObject> Create(Isolate* isolate,
Handle<HeapObject> description, int flags,
PretenureFlag pretenure_flag) {
Handle<Context> native_context = isolate->native_context();
Handle<NativeContext> native_context = isolate->native_context();
Handle<ObjectBoilerplateDescription> object_boilerplate_description =
Handle<ObjectBoilerplateDescription>::cast(description);
bool use_fast_elements = (flags & ObjectLiteral::kFastElements) != 0;
......
......@@ -670,8 +670,8 @@ RUNTIME_FUNCTION(Runtime_NewScriptContext) {
DCHECK_EQ(1, args.length());
CONVERT_ARG_HANDLE_CHECKED(ScopeInfo, scope_info, 0);
Handle<Context> native_context(isolate->context(), isolate);
DCHECK(native_context->IsNativeContext());
Handle<NativeContext> native_context(NativeContext::cast(isolate->context()),
isolate);
Handle<JSGlobalObject> global_object(native_context->global_object(),
isolate);
Handle<ScriptContextTable> script_context_table(
......@@ -721,7 +721,7 @@ RUNTIME_FUNCTION(Runtime_PushModuleContext) {
CONVERT_ARG_HANDLE_CHECKED(Module, module, 0);
CONVERT_ARG_HANDLE_CHECKED(ScopeInfo, scope_info, 1);
Handle<Context> outer(isolate->context(), isolate);
Handle<NativeContext> outer(NativeContext::cast(isolate->context()), isolate);
Handle<Context> context =
isolate->factory()->NewModuleContext(module, outer, scope_info);
isolate->set_context(*context);
......
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