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

Side by Side Diff: src/objects.cc

Issue 260803002: Map::TransitionElementsTo() extracted from JSObject::GetElementsTransitionMap(). (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 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 | Annotate | Revision Log
« no previous file with comments | « src/objects.h ('k') | src/runtime.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "v8.h" 5 #include "v8.h"
6 6
7 #include "accessors.h" 7 #include "accessors.h"
8 #include "allocation-site-scopes.h" 8 #include "allocation-site-scopes.h"
9 #include "api.h" 9 #include "api.h"
10 #include "arguments.h" 10 #include "arguments.h"
(...skipping 3397 matching lines...) Expand 10 before | Expand all | Expand 10 after
3408 if (kind != to_kind) { 3408 if (kind != to_kind) {
3409 current_map = Map::CopyAsElementsKind( 3409 current_map = Map::CopyAsElementsKind(
3410 current_map, to_kind, INSERT_TRANSITION); 3410 current_map, to_kind, INSERT_TRANSITION);
3411 } 3411 }
3412 3412
3413 ASSERT(current_map->elements_kind() == to_kind); 3413 ASSERT(current_map->elements_kind() == to_kind);
3414 return current_map; 3414 return current_map;
3415 } 3415 }
3416 3416
3417 3417
3418 Handle<Map> JSObject::GetElementsTransitionMap(Handle<JSObject> object, 3418 Handle<Map> Map::TransitionElementsTo(Handle<Map> map,
3419 ElementsKind to_kind) { 3419 ElementsKind to_kind) {
3420 Isolate* isolate = object->GetIsolate(); 3420 ElementsKind from_kind = map->elements_kind();
3421 Handle<Map> current_map(object->map()); 3421 if (from_kind == to_kind) return map;
3422 ElementsKind from_kind = current_map->elements_kind();
3423 if (from_kind == to_kind) return current_map;
3424 3422
3423 Isolate* isolate = map->GetIsolate();
3425 Context* native_context = isolate->context()->native_context(); 3424 Context* native_context = isolate->context()->native_context();
3426 Object* maybe_array_maps = native_context->js_array_maps(); 3425 Object* maybe_array_maps = native_context->js_array_maps();
3427 if (maybe_array_maps->IsFixedArray()) { 3426 if (maybe_array_maps->IsFixedArray()) {
3428 DisallowHeapAllocation no_gc; 3427 DisallowHeapAllocation no_gc;
3429 FixedArray* array_maps = FixedArray::cast(maybe_array_maps); 3428 FixedArray* array_maps = FixedArray::cast(maybe_array_maps);
3430 if (array_maps->get(from_kind) == *current_map) { 3429 if (array_maps->get(from_kind) == *map) {
3431 Object* maybe_transitioned_map = array_maps->get(to_kind); 3430 Object* maybe_transitioned_map = array_maps->get(to_kind);
3432 if (maybe_transitioned_map->IsMap()) { 3431 if (maybe_transitioned_map->IsMap()) {
3433 return handle(Map::cast(maybe_transitioned_map)); 3432 return handle(Map::cast(maybe_transitioned_map));
3434 } 3433 }
3435 } 3434 }
3436 } 3435 }
3437 3436
3438 return GetElementsTransitionMapSlow(object, to_kind); 3437 return TransitionElementsToSlow(map, to_kind);
3439 } 3438 }
3440 3439
3441 3440
3442 Handle<Map> JSObject::GetElementsTransitionMapSlow(Handle<JSObject> object, 3441 Handle<Map> Map::TransitionElementsToSlow(Handle<Map> map,
3443 ElementsKind to_kind) { 3442 ElementsKind to_kind) {
3444 Handle<Map> start_map(object->map()); 3443 ElementsKind from_kind = map->elements_kind();
3445 ElementsKind from_kind = start_map->elements_kind();
3446 3444
3447 if (from_kind == to_kind) { 3445 if (from_kind == to_kind) {
3448 return start_map; 3446 return map;
3449 } 3447 }
3450 3448
3451 bool allow_store_transition = 3449 bool allow_store_transition =
3452 // Only remember the map transition if there is not an already existing 3450 // Only remember the map transition if there is not an already existing
3453 // non-matching element transition. 3451 // non-matching element transition.
3454 !start_map->IsUndefined() && !start_map->is_shared() && 3452 !map->IsUndefined() && !map->is_shared() &&
3455 IsTransitionElementsKind(from_kind); 3453 IsTransitionElementsKind(from_kind);
3456 3454
3457 // Only store fast element maps in ascending generality. 3455 // Only store fast element maps in ascending generality.
3458 if (IsFastElementsKind(to_kind)) { 3456 if (IsFastElementsKind(to_kind)) {
3459 allow_store_transition &= 3457 allow_store_transition &=
3460 IsTransitionableFastElementsKind(from_kind) && 3458 IsTransitionableFastElementsKind(from_kind) &&
3461 IsMoreGeneralElementsKindTransition(from_kind, to_kind); 3459 IsMoreGeneralElementsKindTransition(from_kind, to_kind);
3462 } 3460 }
3463 3461
3464 if (!allow_store_transition) { 3462 if (!allow_store_transition) {
3465 return Map::CopyAsElementsKind(start_map, to_kind, OMIT_TRANSITION); 3463 return Map::CopyAsElementsKind(map, to_kind, OMIT_TRANSITION);
3466 } 3464 }
3467 3465
3468 return Map::AsElementsKind(start_map, to_kind); 3466 return Map::AsElementsKind(map, to_kind);
3469 } 3467 }
3470 3468
3471 3469
3472 // static 3470 // static
3473 Handle<Map> Map::AsElementsKind(Handle<Map> map, ElementsKind kind) { 3471 Handle<Map> Map::AsElementsKind(Handle<Map> map, ElementsKind kind) {
3474 Handle<Map> closest_map(FindClosestElementsTransition(*map, kind)); 3472 Handle<Map> closest_map(FindClosestElementsTransition(*map, kind));
3475 3473
3476 if (closest_map->elements_kind() == kind) { 3474 if (closest_map->elements_kind() == kind) {
3477 return closest_map; 3475 return closest_map;
3478 } 3476 }
3479 3477
3480 return AddMissingElementsTransitions(closest_map, kind); 3478 return AddMissingElementsTransitions(closest_map, kind);
3481 } 3479 }
3482 3480
3483 3481
3482 Handle<Map> JSObject::GetElementsTransitionMap(Handle<JSObject> object,
3483 ElementsKind to_kind) {
3484 Handle<Map> map(object->map());
3485 return Map::TransitionElementsTo(map, to_kind);
3486 }
3487
3488
3484 void JSObject::LocalLookupRealNamedProperty(Handle<Name> name, 3489 void JSObject::LocalLookupRealNamedProperty(Handle<Name> name,
3485 LookupResult* result) { 3490 LookupResult* result) {
3486 DisallowHeapAllocation no_gc; 3491 DisallowHeapAllocation no_gc;
3487 if (IsJSGlobalProxy()) { 3492 if (IsJSGlobalProxy()) {
3488 Object* proto = GetPrototype(); 3493 Object* proto = GetPrototype();
3489 if (proto->IsNull()) return result->NotFound(); 3494 if (proto->IsNull()) return result->NotFound();
3490 ASSERT(proto->IsJSGlobalObject()); 3495 ASSERT(proto->IsJSGlobalObject());
3491 return JSObject::cast(proto)->LocalLookupRealNamedProperty(name, result); 3496 return JSObject::cast(proto)->LocalLookupRealNamedProperty(name, result);
3492 } 3497 }
3493 3498
(...skipping 13626 matching lines...) Expand 10 before | Expand all | Expand 10 after
17120 17125
17121 17126
17122 Handle<JSArrayBuffer> JSTypedArray::MaterializeArrayBuffer( 17127 Handle<JSArrayBuffer> JSTypedArray::MaterializeArrayBuffer(
17123 Handle<JSTypedArray> typed_array) { 17128 Handle<JSTypedArray> typed_array) {
17124 17129
17125 Handle<Map> map(typed_array->map()); 17130 Handle<Map> map(typed_array->map());
17126 Isolate* isolate = typed_array->GetIsolate(); 17131 Isolate* isolate = typed_array->GetIsolate();
17127 17132
17128 ASSERT(IsFixedTypedArrayElementsKind(map->elements_kind())); 17133 ASSERT(IsFixedTypedArrayElementsKind(map->elements_kind()));
17129 17134
17135 Handle<Map> new_map = Map::TransitionElementsTo(
17136 map,
17137 FixedToExternalElementsKind(map->elements_kind()));
17138
17130 Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer(); 17139 Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer();
17131 Handle<FixedTypedArrayBase> fixed_typed_array( 17140 Handle<FixedTypedArrayBase> fixed_typed_array(
17132 FixedTypedArrayBase::cast(typed_array->elements())); 17141 FixedTypedArrayBase::cast(typed_array->elements()));
17133 Runtime::SetupArrayBufferAllocatingData(isolate, buffer, 17142 Runtime::SetupArrayBufferAllocatingData(isolate, buffer,
17134 fixed_typed_array->DataSize(), false); 17143 fixed_typed_array->DataSize(), false);
17135 memcpy(buffer->backing_store(), 17144 memcpy(buffer->backing_store(),
17136 fixed_typed_array->DataPtr(), 17145 fixed_typed_array->DataPtr(),
17137 fixed_typed_array->DataSize()); 17146 fixed_typed_array->DataSize());
17138 Handle<ExternalArray> new_elements = 17147 Handle<ExternalArray> new_elements =
17139 isolate->factory()->NewExternalArray( 17148 isolate->factory()->NewExternalArray(
17140 fixed_typed_array->length(), typed_array->type(), 17149 fixed_typed_array->length(), typed_array->type(),
17141 static_cast<uint8_t*>(buffer->backing_store())); 17150 static_cast<uint8_t*>(buffer->backing_store()));
17142 Handle<Map> new_map = JSObject::GetElementsTransitionMap(
17143 typed_array,
17144 FixedToExternalElementsKind(map->elements_kind()));
17145 17151
17146 buffer->set_weak_first_view(*typed_array); 17152 buffer->set_weak_first_view(*typed_array);
17147 ASSERT(typed_array->weak_next() == isolate->heap()->undefined_value()); 17153 ASSERT(typed_array->weak_next() == isolate->heap()->undefined_value());
17148 typed_array->set_buffer(*buffer); 17154 typed_array->set_buffer(*buffer);
17149 JSObject::SetMapAndElements(typed_array, new_map, new_elements); 17155 JSObject::SetMapAndElements(typed_array, new_map, new_elements);
17150 17156
17151 return buffer; 17157 return buffer;
17152 } 17158 }
17153 17159
17154 17160
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
17226 #define ERROR_MESSAGES_TEXTS(C, T) T, 17232 #define ERROR_MESSAGES_TEXTS(C, T) T,
17227 static const char* error_messages_[] = { 17233 static const char* error_messages_[] = {
17228 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) 17234 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS)
17229 }; 17235 };
17230 #undef ERROR_MESSAGES_TEXTS 17236 #undef ERROR_MESSAGES_TEXTS
17231 return error_messages_[reason]; 17237 return error_messages_[reason];
17232 } 17238 }
17233 17239
17234 17240
17235 } } // namespace v8::internal 17241 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/runtime.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698