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

Side by Side Diff: src/objects.cc

Issue 8820014: Support Smi->Double->HeapObject transitions in constructed Arrays. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Disable smi only array optimizations Created 9 years 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
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 8349 matching lines...) Expand 10 before | Expand all | Expand 10 after
8360 { MaybeObject* maybe_obj = heap->AllocateFixedArrayWithHoles(capacity); 8360 { MaybeObject* maybe_obj = heap->AllocateFixedArrayWithHoles(capacity);
8361 if (!maybe_obj->ToObject(&obj)) return maybe_obj; 8361 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
8362 } 8362 }
8363 new_elements = FixedArray::cast(obj); 8363 new_elements = FixedArray::cast(obj);
8364 } 8364 }
8365 set_elements(new_elements); 8365 set_elements(new_elements);
8366 return this; 8366 return this;
8367 } 8367 }
8368 8368
8369 8369
8370 void JSArray::Expand(int required_size) { 8370 void JSArray::Expand(int required_size) {
Jakob Kummerow 2011/12/07 17:02:47 Instead of all this code here, we should be able t
danno 2011/12/08 15:09:09 Done.
8371 Handle<JSArray> self(this); 8371 Handle<JSArray> self(this);
8372 Handle<FixedArray> old_backing(FixedArray::cast(elements())); 8372 Handle<FixedArrayBase> old_backing_raw(FixedArrayBase::cast(elements()));
8373 int old_size = old_backing->length(); 8373 int old_size = old_backing_raw->length();
8374 int new_size = required_size > old_size ? required_size : old_size; 8374 int new_size = required_size > old_size ? required_size : old_size;
8375 Handle<FixedArray> new_backing = FACTORY->NewFixedArray(new_size); 8375 if (old_backing_raw->map() == GetHeap()->fixed_double_array_map()) {
8376 // Can't use this any more now because we may have had a GC! 8376 Handle<FixedDoubleArray> new_backing =
8377 for (int i = 0; i < old_size; i++) new_backing->set(i, old_backing->get(i)); 8377 FACTORY->NewFixedDoubleArray(new_size);
8378 GetIsolate()->factory()->SetContent(self, new_backing); 8378 // Can't use this any more now because we may have had a GC!
8379 FixedDoubleArray* old_backing(FixedDoubleArray::cast(*old_backing_raw));
8380 for (int i = 0; i < old_size; i++) {
8381 new_backing->set(i, old_backing->get_scalar(i));
8382 }
8383 GetIsolate()->factory()->SetContent(self, new_backing);
8384 } else {
8385 Handle<FixedArray> new_backing = FACTORY->NewFixedArray(new_size);
8386 // Can't use this any more now because we may have had a GC!
8387 FixedArray* old_backing(FixedArray::cast(*old_backing_raw));
8388 for (int i = 0; i < old_size; i++) new_backing->set(i, old_backing->get(i));
8389 GetIsolate()->factory()->SetContent(self, new_backing);
8390 }
8379 } 8391 }
8380 8392
8381 8393
8382 MaybeObject* JSObject::SetElementsLength(Object* len) { 8394 MaybeObject* JSObject::SetElementsLength(Object* len) {
8383 // We should never end in here with a pixel or external array. 8395 // We should never end in here with a pixel or external array.
8384 ASSERT(AllowsSetElementsLength()); 8396 ASSERT(AllowsSetElementsLength());
8385 return GetElementsAccessor()->SetLength(this, len); 8397 return GetElementsAccessor()->SetLength(this, len);
8386 } 8398 }
8387 8399
8388 8400
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
8522 real_receiver->set_map(Map::cast(new_map)); 8534 real_receiver->set_map(Map::cast(new_map));
8523 8535
8524 heap->ClearInstanceofCache(); 8536 heap->ClearInstanceofCache();
8525 ASSERT(size == Size()); 8537 ASSERT(size == Size());
8526 return value; 8538 return value;
8527 } 8539 }
8528 8540
8529 8541
8530 MaybeObject* JSObject::EnsureCanContainElements(Arguments* args, 8542 MaybeObject* JSObject::EnsureCanContainElements(Arguments* args,
8531 uint32_t first_arg, 8543 uint32_t first_arg,
8532 uint32_t arg_count) { 8544 uint32_t arg_count,
8545 EnsureElementsMode mode) {
8533 // Elements in |Arguments| are ordered backwards (because they're on the 8546 // Elements in |Arguments| are ordered backwards (because they're on the
8534 // stack), but the method that's called here iterates over them in forward 8547 // stack), but the method that's called here iterates over them in forward
8535 // direction. 8548 // direction.
8536 return EnsureCanContainElements( 8549 return EnsureCanContainElements(
8537 args->arguments() - first_arg - (arg_count - 1), 8550 args->arguments() - first_arg - (arg_count - 1),
8538 arg_count); 8551 arg_count, mode);
8539 } 8552 }
8540 8553
8541 8554
8542 bool JSObject::HasElementPostInterceptor(JSReceiver* receiver, uint32_t index) { 8555 bool JSObject::HasElementPostInterceptor(JSReceiver* receiver, uint32_t index) {
8543 switch (GetElementsKind()) { 8556 switch (GetElementsKind()) {
8544 case FAST_SMI_ONLY_ELEMENTS: 8557 case FAST_SMI_ONLY_ELEMENTS:
8545 case FAST_ELEMENTS: { 8558 case FAST_ELEMENTS: {
8546 uint32_t length = IsJSArray() ? 8559 uint32_t length = IsJSArray() ?
8547 static_cast<uint32_t> 8560 static_cast<uint32_t>
8548 (Smi::cast(JSArray::cast(this)->length())->value()) : 8561 (Smi::cast(JSArray::cast(this)->length())->value()) :
(...skipping 931 matching lines...) Expand 10 before | Expand all | Expand 10 after
9480 return isolate->heap()->null_value(); 9493 return isolate->heap()->null_value();
9481 } 9494 }
9482 9495
9483 9496
9484 MUST_USE_RESULT MaybeObject* JSObject::TransitionElementsKind( 9497 MUST_USE_RESULT MaybeObject* JSObject::TransitionElementsKind(
9485 ElementsKind to_kind) { 9498 ElementsKind to_kind) {
9486 ElementsKind from_kind = map()->elements_kind(); 9499 ElementsKind from_kind = map()->elements_kind();
9487 FixedArrayBase* elms = FixedArrayBase::cast(elements()); 9500 FixedArrayBase* elms = FixedArrayBase::cast(elements());
9488 uint32_t capacity = static_cast<uint32_t>(elms->length()); 9501 uint32_t capacity = static_cast<uint32_t>(elms->length());
9489 uint32_t length = capacity; 9502 uint32_t length = capacity;
9503
9490 if (IsJSArray()) { 9504 if (IsJSArray()) {
9491 CHECK(JSArray::cast(this)->length()->ToArrayIndex(&length)); 9505 Object* raw_length = JSArray::cast(this)->length();
9506 if (raw_length->IsUndefined()) {
9507 // If length is undefined, then JSArray is being initialized and has no
9508 // elements, assume a length of zero.
9509 length = 0;
9510 } else {
9511 CHECK(JSArray::cast(this)->length()->ToArrayIndex(&length));
9512 }
9492 } 9513 }
9493 if (from_kind == FAST_SMI_ONLY_ELEMENTS) { 9514
9494 if (to_kind == FAST_DOUBLE_ELEMENTS) { 9515 if ((from_kind == FAST_SMI_ONLY_ELEMENTS && to_kind == FAST_ELEMENTS) ||
9495 MaybeObject* maybe_result = 9516 (length == 0)) {
9496 SetFastDoubleElementsCapacityAndLength(capacity, length); 9517 MaybeObject* maybe_new_map = GetElementsTransitionMap(to_kind);
9497 if (maybe_result->IsFailure()) return maybe_result; 9518 Map* new_map;
9498 return this; 9519 if (!maybe_new_map->To(&new_map)) return maybe_new_map;
9499 } else if (to_kind == FAST_ELEMENTS) { 9520 if (FLAG_trace_elements_transitions) {
9500 MaybeObject* maybe_new_map = GetElementsTransitionMap(FAST_ELEMENTS); 9521 PrintElementsTransition(stdout, from_kind, elms, to_kind, elms);
9501 Map* new_map;
9502 if (!maybe_new_map->To(&new_map)) return maybe_new_map;
9503 if (FLAG_trace_elements_transitions) {
9504 PrintElementsTransition(stdout, from_kind, elms, FAST_ELEMENTS, elms);
9505 }
9506 set_map(new_map);
9507 return this;
9508 } 9522 }
9509 } else if (from_kind == FAST_DOUBLE_ELEMENTS && to_kind == FAST_ELEMENTS) { 9523 set_map(new_map);
9524 return this;
9525 }
9526
9527 if (from_kind == FAST_SMI_ONLY_ELEMENTS &&
9528 to_kind == FAST_DOUBLE_ELEMENTS) {
9529 MaybeObject* maybe_result =
9530 SetFastDoubleElementsCapacityAndLength(capacity, length);
9531 if (maybe_result->IsFailure()) return maybe_result;
9532 return this;
9533 }
9534
9535 if (from_kind == FAST_DOUBLE_ELEMENTS && to_kind == FAST_ELEMENTS) {
9510 MaybeObject* maybe_result = SetFastElementsCapacityAndLength( 9536 MaybeObject* maybe_result = SetFastElementsCapacityAndLength(
9511 capacity, length, kDontAllowSmiOnlyElements); 9537 capacity, length, kDontAllowSmiOnlyElements);
9512 if (maybe_result->IsFailure()) return maybe_result; 9538 if (maybe_result->IsFailure()) return maybe_result;
9513 return this; 9539 return this;
9514 } 9540 }
9541
9515 // This method should never be called for any other case than the ones 9542 // This method should never be called for any other case than the ones
9516 // handled above. 9543 // handled above.
9517 UNREACHABLE(); 9544 UNREACHABLE();
9518 return GetIsolate()->heap()->null_value(); 9545 return GetIsolate()->heap()->null_value();
9519 } 9546 }
9520 9547
9521 9548
9522 // static 9549 // static
9523 bool Map::IsValidElementsTransition(ElementsKind from_kind, 9550 bool Map::IsValidElementsTransition(ElementsKind from_kind,
9524 ElementsKind to_kind) { 9551 ElementsKind to_kind) {
(...skipping 3015 matching lines...) Expand 10 before | Expand all | Expand 10 after
12540 if (break_point_objects()->IsUndefined()) return 0; 12567 if (break_point_objects()->IsUndefined()) return 0;
12541 // Single break point. 12568 // Single break point.
12542 if (!break_point_objects()->IsFixedArray()) return 1; 12569 if (!break_point_objects()->IsFixedArray()) return 1;
12543 // Multiple break points. 12570 // Multiple break points.
12544 return FixedArray::cast(break_point_objects())->length(); 12571 return FixedArray::cast(break_point_objects())->length();
12545 } 12572 }
12546 #endif // ENABLE_DEBUGGER_SUPPORT 12573 #endif // ENABLE_DEBUGGER_SUPPORT
12547 12574
12548 12575
12549 } } // namespace v8::internal 12576 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698