Skip to content

Commit

Permalink
Remove the global Strength enum class completely.
Browse files Browse the repository at this point in the history
R=bmeurer@chromium.org
BUG=v8:3956
LOG=n

Review URL: https://codereview.chromium.org/1731063007

Cr-Commit-Position: refs/heads/master@{#34398}
  • Loading branch information
mstarzinger authored and Commit bot committed Mar 1, 2016
1 parent dbf5fff commit 00e9447
Show file tree
Hide file tree
Showing 27 changed files with 50 additions and 277 deletions.
2 changes: 1 addition & 1 deletion src/ast/ast.cc
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ void ArrayLiteral::BuildConstantElements(Isolate* isolate) {
// Allocate a fixed array to hold all the object literals.
Handle<JSArray> array = isolate->factory()->NewJSArray(
FAST_HOLEY_SMI_ELEMENTS, constants_length, constants_length,
Strength::WEAK, INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE);
INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE);

// Fill in the literals.
bool is_simple = true;
Expand Down
50 changes: 0 additions & 50 deletions src/bootstrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ class Genesis BASE_EMBEDDED {
Handle<JSFunction> GetThrowTypeErrorIntrinsic(Builtins::Name builtin_name);

void CreateStrictModeFunctionMaps(Handle<JSFunction> empty);
void CreateStrongModeFunctionMaps(Handle<JSFunction> empty);
void CreateIteratorMaps();

// Make the "arguments" and "caller" properties throw a TypeError on access.
Expand Down Expand Up @@ -284,8 +283,6 @@ class Genesis BASE_EMBEDDED {

Handle<Map> CreateStrictFunctionMap(FunctionMode function_mode,
Handle<JSFunction> empty_function);
Handle<Map> CreateStrongFunctionMap(Handle<JSFunction> empty_function,
bool is_constructor);


void SetStrictFunctionInstanceDescriptor(Handle<Map> map,
Expand Down Expand Up @@ -547,12 +544,6 @@ Handle<JSFunction> Genesis::CreateEmptyFunction(Isolate* isolate) {
native_context()->set_initial_array_prototype(*object_function_prototype);
Accessors::FunctionSetPrototype(object_fun, object_function_prototype)
.Assert();

// Allocate initial strong object map.
Handle<Map> strong_object_map =
Map::Copy(Handle<Map>(object_fun->initial_map()), "EmptyStrongObject");
strong_object_map->set_is_strong();
native_context()->set_js_object_strong_map(*strong_object_map);
}

// Allocate the empty function as the prototype for function - ES6 19.2.3
Expand Down Expand Up @@ -722,19 +713,6 @@ Handle<Map> Genesis::CreateStrictFunctionMap(
}


Handle<Map> Genesis::CreateStrongFunctionMap(
Handle<JSFunction> empty_function, bool is_constructor) {
Handle<Map> map = factory()->NewMap(JS_FUNCTION_TYPE, JSFunction::kSize);
SetStrongFunctionInstanceDescriptor(map);
map->set_is_constructor(is_constructor);
Map::SetPrototype(map, empty_function);
map->set_is_callable();
map->set_is_extensible(is_constructor);
map->set_is_strong();
return map;
}


void Genesis::CreateStrictModeFunctionMaps(Handle<JSFunction> empty) {
// Allocate map for the prototype-less strict mode instances.
Handle<Map> strict_function_without_prototype_map =
Expand All @@ -756,16 +734,6 @@ void Genesis::CreateStrictModeFunctionMaps(Handle<JSFunction> empty) {
}


void Genesis::CreateStrongModeFunctionMaps(Handle<JSFunction> empty) {
// Allocate map for strong mode instances, which never have prototypes.
Handle<Map> strong_function_map = CreateStrongFunctionMap(empty, false);
native_context()->set_strong_function_map(*strong_function_map);
// Constructors do, though.
Handle<Map> strong_constructor_map = CreateStrongFunctionMap(empty, true);
native_context()->set_strong_constructor_map(*strong_constructor_map);
}


void Genesis::CreateIteratorMaps() {
// Create iterator-related meta-objects.
Handle<JSObject> iterator_prototype =
Expand Down Expand Up @@ -803,15 +771,6 @@ void Genesis::CreateIteratorMaps() {
native_context()->set_strict_generator_function_map(
*strict_generator_function_map);

Handle<Map> strong_function_map(native_context()->strong_function_map());
Handle<Map> strong_generator_function_map =
Map::Copy(strong_function_map, "StrongGeneratorFunction");
strong_generator_function_map->set_is_constructor(false);
Map::SetPrototype(strong_generator_function_map,
generator_function_prototype);
native_context()->set_strong_generator_function_map(
*strong_generator_function_map);

Handle<JSFunction> object_function(native_context()->object_function());
Handle<Map> generator_object_prototype_map = Map::Create(isolate(), 0);
Map::SetPrototype(generator_object_prototype_map, generator_object_prototype);
Expand Down Expand Up @@ -1174,7 +1133,6 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,

sloppy_function_map_writable_prototype_->SetConstructor(*function_fun);
strict_function_map_writable_prototype_->SetConstructor(*function_fun);
native_context()->strong_function_map()->SetConstructor(*function_fun);
}

{ // --- A r r a y ---
Expand Down Expand Up @@ -1217,11 +1175,6 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
Handle<Code> code = array_constructor_stub.GetCode();
array_function->shared()->set_construct_stub(*code);

Handle<Map> initial_strong_map =
Map::Copy(initial_map, "SetInstancePrototype");
initial_strong_map->set_is_strong();
CacheInitialJSArrayMaps(native_context(), initial_strong_map);

Handle<JSFunction> is_arraylike = SimpleInstallFunction(
array_function, isolate->factory()->InternalizeUtf8String("isArray"),
Builtins::kArrayIsArray, 1, true);
Expand Down Expand Up @@ -2137,8 +2090,6 @@ void Bootstrapper::ExportFromRuntime(Isolate* isolate,
*generator_function_function);
native_context->strict_generator_function_map()->SetConstructor(
*generator_function_function);
native_context->strong_generator_function_map()->SetConstructor(
*generator_function_function);
}

{ // -- S e t I t e r a t o r
Expand Down Expand Up @@ -3603,7 +3554,6 @@ Genesis::Genesis(Isolate* isolate,
CreateRoots();
Handle<JSFunction> empty_function = CreateEmptyFunction(isolate);
CreateStrictModeFunctionMaps(empty_function);
CreateStrongModeFunctionMaps(empty_function);
CreateIteratorMaps();
Handle<JSGlobalObject> global_object =
CreateNewGlobals(global_proxy_template, global_proxy);
Expand Down
38 changes: 6 additions & 32 deletions src/contexts.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,21 +211,8 @@ enum BindingFlags {
js_array_fast_double_elements_map_index) \
V(JS_ARRAY_FAST_HOLEY_DOUBLE_ELEMENTS_MAP_INDEX, Map, \
js_array_fast_holey_double_elements_map_index) \
V(JS_ARRAY_FAST_SMI_ELEMENTS_STRONG_MAP_INDEX, Map, \
js_array_fast_smi_elements_strong_map_index) \
V(JS_ARRAY_FAST_HOLEY_SMI_ELEMENTS_STRONG_MAP_INDEX, Map, \
js_array_fast_holey_smi_elements_strong_map_index) \
V(JS_ARRAY_FAST_ELEMENTS_STRONG_MAP_INDEX, Map, \
js_array_fast_elements_strong_map_index) \
V(JS_ARRAY_FAST_HOLEY_ELEMENTS_STRONG_MAP_INDEX, Map, \
js_array_fast_holey_elements_strong_map_index) \
V(JS_ARRAY_FAST_DOUBLE_ELEMENTS_STRONG_MAP_INDEX, Map, \
js_array_fast_double_elements_strong_map_index) \
V(JS_ARRAY_FAST_HOLEY_DOUBLE_ELEMENTS_STRONG_MAP_INDEX, Map, \
js_array_fast_holey_double_elements_strong_map_index) \
V(JS_MAP_FUN_INDEX, JSFunction, js_map_fun) \
V(JS_MAP_MAP_INDEX, Map, js_map_map) \
V(JS_OBJECT_STRONG_MAP_INDEX, Map, js_object_strong_map) \
V(JS_SET_FUN_INDEX, JSFunction, js_set_fun) \
V(JS_SET_MAP_INDEX, Map, js_set_map) \
V(JS_WEAK_MAP_FUN_INDEX, JSFunction, js_weak_map_fun) \
Expand Down Expand Up @@ -269,10 +256,6 @@ enum BindingFlags {
V(STRICT_GENERATOR_FUNCTION_MAP_INDEX, Map, strict_generator_function_map) \
V(STRING_FUNCTION_INDEX, JSFunction, string_function) \
V(STRING_FUNCTION_PROTOTYPE_MAP_INDEX, Map, string_function_prototype_map) \
V(STRONG_CONSTRUCTOR_MAP_INDEX, Map, strong_constructor_map) \
V(STRONG_FUNCTION_MAP_INDEX, Map, strong_function_map) \
V(STRONG_GENERATOR_FUNCTION_MAP_INDEX, Map, strong_generator_function_map) \
V(STRONG_MAP_CACHE_INDEX, Object, strong_map_cache) \
V(SYMBOL_FUNCTION_INDEX, JSFunction, symbol_function) \
V(UINT16_ARRAY_FUN_INDEX, JSFunction, uint16_array_fun) \
V(UINT16X8_FUNCTION_INDEX, JSFunction, uint16x8_function) \
Expand Down Expand Up @@ -416,8 +399,6 @@ class Context: public FixedArray {
NATIVE_CONTEXT_SLOTS,
FIRST_WEAK_SLOT = OPTIMIZED_FUNCTIONS_LIST,
FIRST_JS_ARRAY_MAP_SLOT = JS_ARRAY_FAST_SMI_ELEMENTS_MAP_INDEX,
FIRST_JS_ARRAY_STRONG_MAP_SLOT =
JS_ARRAY_FAST_SMI_ELEMENTS_STRONG_MAP_INDEX,

MIN_CONTEXT_SLOTS = GLOBAL_PROXY_INDEX,
// This slot holds the thrown value in catch contexts.
Expand Down Expand Up @@ -539,34 +520,27 @@ class Context: public FixedArray {

static int FunctionMapIndex(LanguageMode language_mode, FunctionKind kind) {
if (IsGeneratorFunction(kind)) {
return is_strong(language_mode) ? STRONG_GENERATOR_FUNCTION_MAP_INDEX :
is_strict(language_mode) ? STRICT_GENERATOR_FUNCTION_MAP_INDEX
return is_strict(language_mode) ? STRICT_GENERATOR_FUNCTION_MAP_INDEX
: SLOPPY_GENERATOR_FUNCTION_MAP_INDEX;
}

if (IsClassConstructor(kind)) {
// Use strict function map (no own "caller" / "arguments")
return is_strong(language_mode) ? STRONG_CONSTRUCTOR_MAP_INDEX
: STRICT_FUNCTION_MAP_INDEX;
return STRICT_FUNCTION_MAP_INDEX;
}

if (IsArrowFunction(kind) || IsConciseMethod(kind) ||
IsAccessorFunction(kind)) {
return is_strong(language_mode)
? STRONG_FUNCTION_MAP_INDEX
: STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX;
return STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX;
}

return is_strong(language_mode) ? STRONG_FUNCTION_MAP_INDEX :
is_strict(language_mode) ? STRICT_FUNCTION_MAP_INDEX
return is_strict(language_mode) ? STRICT_FUNCTION_MAP_INDEX
: SLOPPY_FUNCTION_MAP_INDEX;
}

static int ArrayMapIndex(ElementsKind elements_kind,
Strength strength = Strength::WEAK) {
static int ArrayMapIndex(ElementsKind elements_kind) {
DCHECK(IsFastElementsKind(elements_kind));
return elements_kind + (is_strong(strength) ? FIRST_JS_ARRAY_STRONG_MAP_SLOT
: FIRST_JS_ARRAY_MAP_SLOT);
return elements_kind + FIRST_JS_ARRAY_MAP_SLOT;
}

static const int kSize = kHeaderSize + NATIVE_CONTEXT_SLOTS * kPointerSize;
Expand Down
2 changes: 1 addition & 1 deletion src/elements.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2663,7 +2663,7 @@ Handle<JSArray> ElementsAccessor::Concat(Isolate* isolate, Arguments* args,
? INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE
: DONT_INITIALIZE_ARRAY_ELEMENTS;
Handle<JSArray> result_array = isolate->factory()->NewJSArray(
elements_kind, result_len, result_len, Strength::WEAK, mode);
elements_kind, result_len, result_len, mode);
if (result_len == 0) return result_array;
int j = 0;
Handle<FixedArrayBase> storage(result_array->elements(), isolate);
Expand Down
32 changes: 9 additions & 23 deletions src/factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1596,35 +1596,31 @@ Handle<JSObject> Factory::NewJSObjectFromMap(


Handle<JSArray> Factory::NewJSArray(ElementsKind elements_kind,
Strength strength,
PretenureFlag pretenure) {
Map* map = isolate()->get_initial_js_array_map(elements_kind, strength);
Map* map = isolate()->get_initial_js_array_map(elements_kind);
if (map == nullptr) {
DCHECK(strength == Strength::WEAK);
Context* native_context = isolate()->context()->native_context();
JSFunction* array_function = native_context->array_function();
map = array_function->initial_map();
}
return Handle<JSArray>::cast(NewJSObjectFromMap(handle(map), pretenure));
}


Handle<JSArray> Factory::NewJSArray(ElementsKind elements_kind, int length,
int capacity, Strength strength,
int capacity,
ArrayStorageAllocationMode mode,
PretenureFlag pretenure) {
Handle<JSArray> array = NewJSArray(elements_kind, strength, pretenure);
Handle<JSArray> array = NewJSArray(elements_kind, pretenure);
NewJSArrayStorage(array, length, capacity, mode);
return array;
}


Handle<JSArray> Factory::NewJSArrayWithElements(Handle<FixedArrayBase> elements,
ElementsKind elements_kind,
int length, Strength strength,
int length,
PretenureFlag pretenure) {
DCHECK(length <= elements->length());
Handle<JSArray> array = NewJSArray(elements_kind, strength, pretenure);
Handle<JSArray> array = NewJSArray(elements_kind, pretenure);

array->set_elements(*elements);
array->set_length(Smi::FromInt(length));
Expand Down Expand Up @@ -2300,7 +2296,6 @@ Handle<JSWeakMap> Factory::NewJSWeakMap() {

Handle<Map> Factory::ObjectLiteralMapFromCache(Handle<Context> context,
int number_of_properties,
bool is_strong,
bool* is_result_from_cache) {
const int kMapCacheSize = 128;

Expand All @@ -2309,29 +2304,21 @@ Handle<Map> Factory::ObjectLiteralMapFromCache(Handle<Context> context,
isolate()->bootstrapper()->IsActive()) {
*is_result_from_cache = false;
Handle<Map> map = Map::Create(isolate(), number_of_properties);
if (is_strong) map->set_is_strong();
return map;
}
*is_result_from_cache = true;
if (number_of_properties == 0) {
// Reuse the initial map of the Object function if the literal has no
// predeclared properties, or the strong map if strong.
return handle(is_strong
? context->js_object_strong_map()
: context->object_function()->initial_map(), isolate());
// predeclared properties.
return handle(context->object_function()->initial_map(), isolate());
}

int cache_index = number_of_properties - 1;
Handle<Object> maybe_cache(is_strong ? context->strong_map_cache()
: context->map_cache(), isolate());
Handle<Object> maybe_cache(context->map_cache(), isolate());
if (maybe_cache->IsUndefined()) {
// Allocate the new map cache for the native context.
maybe_cache = NewFixedArray(kMapCacheSize, TENURED);
if (is_strong) {
context->set_strong_map_cache(*maybe_cache);
} else {
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<FixedArray> cache = Handle<FixedArray>::cast(maybe_cache);
Expand All @@ -2346,7 +2333,6 @@ Handle<Map> Factory::ObjectLiteralMapFromCache(Handle<Context> context,
// Create a new map and add it to the cache.
Handle<FixedArray> cache = Handle<FixedArray>::cast(maybe_cache);
Handle<Map> map = Map::Create(isolate(), number_of_properties);
if (is_strong) map->set_is_strong();
Handle<WeakCell> cell = NewWeakCell(map);
cache->set(cache_index, *cell);
return map;
Expand Down
10 changes: 2 additions & 8 deletions src/factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -410,34 +410,30 @@ class Factory final {
// according to the specified mode.
Handle<JSArray> NewJSArray(
ElementsKind elements_kind, int length, int capacity,
Strength strength = Strength::WEAK,
ArrayStorageAllocationMode mode = DONT_INITIALIZE_ARRAY_ELEMENTS,
PretenureFlag pretenure = NOT_TENURED);

Handle<JSArray> NewJSArray(
int capacity, ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND,
Strength strength = Strength::WEAK,
PretenureFlag pretenure = NOT_TENURED) {
if (capacity != 0) {
elements_kind = GetHoleyElementsKind(elements_kind);
}
return NewJSArray(elements_kind, 0, capacity, strength,
return NewJSArray(elements_kind, 0, capacity,
INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE, pretenure);
}

// Create a JSArray with the given elements.
Handle<JSArray> NewJSArrayWithElements(Handle<FixedArrayBase> elements,
ElementsKind elements_kind, int length,
Strength strength = Strength::WEAK,
PretenureFlag pretenure = NOT_TENURED);

Handle<JSArray> NewJSArrayWithElements(
Handle<FixedArrayBase> elements,
ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND,
Strength strength = Strength::WEAK,
PretenureFlag pretenure = NOT_TENURED) {
return NewJSArrayWithElements(elements, elements_kind, elements->length(),
strength, pretenure);
pretenure);
}

void NewJSArrayStorage(
Expand Down Expand Up @@ -651,7 +647,6 @@ class Factory final {
// native context.
Handle<Map> ObjectLiteralMapFromCache(Handle<Context> context,
int number_of_properties,
bool is_strong,
bool* is_result_from_cache);

// Creates a new FixedArray that holds the data associated with the
Expand Down Expand Up @@ -710,7 +705,6 @@ class Factory final {

// Create a JSArray with no elements and no length.
Handle<JSArray> NewJSArray(ElementsKind elements_kind,
Strength strength = Strength::WEAK,
PretenureFlag pretenure = NOT_TENURED);
};

Expand Down

0 comments on commit 00e9447

Please sign in to comment.