Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(408)

Side by Side Diff: src/objects.cc

Issue 1134333005: [strong] Object literals create strong objects (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <iomanip> 5 #include <iomanip>
6 #include <sstream> 6 #include <sstream>
7 7
8 #include "src/v8.h" 8 #include "src/v8.h"
9 9
10 #include "src/accessors.h" 10 #include "src/accessors.h"
(...skipping 3782 matching lines...) Expand 10 before | Expand all | Expand 10 after
3793 } 3793 }
3794 3794
3795 3795
3796 Handle<Map> Map::TransitionElementsTo(Handle<Map> map, 3796 Handle<Map> Map::TransitionElementsTo(Handle<Map> map,
3797 ElementsKind to_kind) { 3797 ElementsKind to_kind) {
3798 ElementsKind from_kind = map->elements_kind(); 3798 ElementsKind from_kind = map->elements_kind();
3799 if (from_kind == to_kind) return map; 3799 if (from_kind == to_kind) return map;
3800 3800
3801 Isolate* isolate = map->GetIsolate(); 3801 Isolate* isolate = map->GetIsolate();
3802 Context* native_context = isolate->context()->native_context(); 3802 Context* native_context = isolate->context()->native_context();
3803 Object* maybe_array_maps = native_context->js_array_maps(); 3803 Object* maybe_array_maps = map->is_strong()
3804 ? native_context->js_array_strong_maps()
3805 : native_context->js_array_maps();
3804 if (maybe_array_maps->IsFixedArray()) { 3806 if (maybe_array_maps->IsFixedArray()) {
3805 DisallowHeapAllocation no_gc; 3807 DisallowHeapAllocation no_gc;
3806 FixedArray* array_maps = FixedArray::cast(maybe_array_maps); 3808 FixedArray* array_maps = FixedArray::cast(maybe_array_maps);
3807 if (array_maps->get(from_kind) == *map) { 3809 if (array_maps->get(from_kind) == *map) {
3808 Object* maybe_transitioned_map = array_maps->get(to_kind); 3810 Object* maybe_transitioned_map = array_maps->get(to_kind);
3809 if (maybe_transitioned_map->IsMap()) { 3811 if (maybe_transitioned_map->IsMap()) {
3810 return handle(Map::cast(maybe_transitioned_map)); 3812 return handle(Map::cast(maybe_transitioned_map));
3811 } 3813 }
3812 } 3814 }
3813 } 3815 }
(...skipping 6467 matching lines...) Expand 10 before | Expand all | Expand 10 after
10281 Handle<JSObject> prototype_jsobj = Handle<JSObject>::cast(prototype); 10283 Handle<JSObject> prototype_jsobj = Handle<JSObject>::cast(prototype);
10282 JSObject::OptimizeAsPrototype(prototype_jsobj, proto_mode); 10284 JSObject::OptimizeAsPrototype(prototype_jsobj, proto_mode);
10283 } 10285 }
10284 WriteBarrierMode wb_mode = 10286 WriteBarrierMode wb_mode =
10285 prototype->IsNull() ? SKIP_WRITE_BARRIER : UPDATE_WRITE_BARRIER; 10287 prototype->IsNull() ? SKIP_WRITE_BARRIER : UPDATE_WRITE_BARRIER;
10286 map->set_prototype(*prototype, wb_mode); 10288 map->set_prototype(*prototype, wb_mode);
10287 } 10289 }
10288 10290
10289 10291
10290 Handle<Object> CacheInitialJSArrayMaps( 10292 Handle<Object> CacheInitialJSArrayMaps(
10291 Handle<Context> native_context, Handle<Map> initial_map) { 10293 Handle<Context> native_context, Handle<Map> initial_map, bool is_strong) {
10292 // Replace all of the cached initial array maps in the native context with 10294 // Replace all of the cached initial array maps in the native context with
10293 // the appropriate transitioned elements kind maps. 10295 // the appropriate transitioned elements kind maps.
10294 Factory* factory = native_context->GetIsolate()->factory(); 10296 Factory* factory = native_context->GetIsolate()->factory();
10295 Handle<FixedArray> maps = factory->NewFixedArrayWithHoles( 10297 Handle<FixedArray> maps = factory->NewFixedArrayWithHoles(
10296 kElementsKindCount, TENURED); 10298 kElementsKindCount, TENURED);
10297 10299
10298 Handle<Map> current_map = initial_map; 10300 Handle<Map> current_map = initial_map;
10299 ElementsKind kind = current_map->elements_kind(); 10301 ElementsKind kind = current_map->elements_kind();
10300 DCHECK(kind == GetInitialFastElementsKind()); 10302 DCHECK(kind == GetInitialFastElementsKind());
10301 maps->set(kind, *current_map); 10303 maps->set(kind, *current_map);
10302 for (int i = GetSequenceIndexFromFastElementsKind(kind) + 1; 10304 for (int i = GetSequenceIndexFromFastElementsKind(kind) + 1;
10303 i < kFastElementsKindCount; ++i) { 10305 i < kFastElementsKindCount; ++i) {
10304 Handle<Map> new_map; 10306 Handle<Map> new_map;
10305 ElementsKind next_kind = GetFastElementsKindFromSequenceIndex(i); 10307 ElementsKind next_kind = GetFastElementsKindFromSequenceIndex(i);
10306 Map* maybe_elements_transition = current_map->ElementsTransitionMap(); 10308 Map* maybe_elements_transition = current_map->ElementsTransitionMap();
10307 if (maybe_elements_transition != NULL) { 10309 if (maybe_elements_transition != NULL) {
10308 new_map = handle(maybe_elements_transition); 10310 new_map = handle(maybe_elements_transition);
10309 DCHECK(new_map->elements_kind() == next_kind); 10311 DCHECK(new_map->elements_kind() == next_kind);
10310 } else { 10312 } else {
10311 new_map = Map::CopyAsElementsKind( 10313 new_map = Map::CopyAsElementsKind(
10312 current_map, next_kind, INSERT_TRANSITION); 10314 current_map, next_kind, INSERT_TRANSITION);
10313 } 10315 }
10314 maps->set(next_kind, *new_map); 10316 maps->set(next_kind, *new_map);
10315 current_map = new_map; 10317 current_map = new_map;
10316 } 10318 }
10317 native_context->set_js_array_maps(*maps); 10319 if (is_strong)
10320 native_context->set_js_array_strong_maps(*maps);
10321 else
10322 native_context->set_js_array_maps(*maps);
10318 return initial_map; 10323 return initial_map;
10319 } 10324 }
10320 10325
10321 10326
10322 void JSFunction::SetInstancePrototype(Handle<JSFunction> function, 10327 void JSFunction::SetInstancePrototype(Handle<JSFunction> function,
10323 Handle<Object> value) { 10328 Handle<Object> value) {
10324 Isolate* isolate = function->GetIsolate(); 10329 Isolate* isolate = function->GetIsolate();
10325 10330
10326 DCHECK(value->IsJSReceiver()); 10331 DCHECK(value->IsJSReceiver());
10327 10332
(...skipping 20 matching lines...) Expand all
10348 Handle<Map> new_map = Map::Copy(initial_map, "SetInstancePrototype"); 10353 Handle<Map> new_map = Map::Copy(initial_map, "SetInstancePrototype");
10349 JSFunction::SetInitialMap(function, new_map, value); 10354 JSFunction::SetInitialMap(function, new_map, value);
10350 10355
10351 // If the function is used as the global Array function, cache the 10356 // If the function is used as the global Array function, cache the
10352 // initial map (and transitioned versions) in the native context. 10357 // initial map (and transitioned versions) in the native context.
10353 Context* native_context = function->context()->native_context(); 10358 Context* native_context = function->context()->native_context();
10354 Object* array_function = 10359 Object* array_function =
10355 native_context->get(Context::ARRAY_FUNCTION_INDEX); 10360 native_context->get(Context::ARRAY_FUNCTION_INDEX);
10356 if (array_function->IsJSFunction() && 10361 if (array_function->IsJSFunction() &&
10357 *function == JSFunction::cast(array_function)) { 10362 *function == JSFunction::cast(array_function)) {
10358 CacheInitialJSArrayMaps(handle(native_context, isolate), new_map); 10363 CacheInitialJSArrayMaps(handle(native_context, isolate), new_map,
10364 false);
10365 // Piggy-back this place to also create the strong array maps.
10366 Handle<Map> new_strong_map =
10367 Map::Copy(initial_map, "SetInstancePrototype");
10368 new_strong_map->set_is_strong(true);
10369 CacheInitialJSArrayMaps(handle(native_context, isolate),
10370 new_strong_map, true);
10359 } 10371 }
10360 } 10372 }
10361 10373
10362 // Deoptimize all code that embeds the previous initial map. 10374 // Deoptimize all code that embeds the previous initial map.
10363 initial_map->dependent_code()->DeoptimizeDependentCodeGroup( 10375 initial_map->dependent_code()->DeoptimizeDependentCodeGroup(
10364 isolate, DependentCode::kInitialMapChangedGroup); 10376 isolate, DependentCode::kInitialMapChangedGroup);
10365 } else { 10377 } else {
10366 // Put the value in the initial map field until an initial map is 10378 // Put the value in the initial map field until an initial map is
10367 // needed. At that point, a new initial map is created and the 10379 // needed. At that point, a new initial map is created and the
10368 // prototype is put into the initial map where it belongs. 10380 // prototype is put into the initial map where it belongs.
(...skipping 6877 matching lines...) Expand 10 before | Expand all | Expand 10 after
17246 void PropertyCell::SetValueWithInvalidation(Handle<PropertyCell> cell, 17258 void PropertyCell::SetValueWithInvalidation(Handle<PropertyCell> cell,
17247 Handle<Object> new_value) { 17259 Handle<Object> new_value) {
17248 if (cell->value() != *new_value) { 17260 if (cell->value() != *new_value) {
17249 cell->set_value(*new_value); 17261 cell->set_value(*new_value);
17250 Isolate* isolate = cell->GetIsolate(); 17262 Isolate* isolate = cell->GetIsolate();
17251 cell->dependent_code()->DeoptimizeDependentCodeGroup( 17263 cell->dependent_code()->DeoptimizeDependentCodeGroup(
17252 isolate, DependentCode::kPropertyCellChangedGroup); 17264 isolate, DependentCode::kPropertyCellChangedGroup);
17253 } 17265 }
17254 } 17266 }
17255 } } // namespace v8::internal 17267 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698