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

Side by Side Diff: src/heap.cc

Issue 236983002: Handlify Heap::AllocateJSArrayStorage and friends. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Some more follow-up work. Created 6 years, 8 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/heap.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 4253 matching lines...) Expand 10 before | Expand all | Expand 10 after
4264 allocation_site); 4264 allocation_site);
4265 #ifdef DEBUG 4265 #ifdef DEBUG
4266 // Make sure result is NOT a global object if valid. 4266 // Make sure result is NOT a global object if valid.
4267 Object* non_failure; 4267 Object* non_failure;
4268 ASSERT(!result->ToObject(&non_failure) || !non_failure->IsGlobalObject()); 4268 ASSERT(!result->ToObject(&non_failure) || !non_failure->IsGlobalObject());
4269 #endif 4269 #endif
4270 return result; 4270 return result;
4271 } 4271 }
4272 4272
4273 4273
4274 MaybeObject* Heap::AllocateJSArrayStorage(
4275 JSArray* array,
4276 int length,
4277 int capacity,
4278 ArrayStorageAllocationMode mode) {
4279 ASSERT(capacity >= length);
4280
4281 if (capacity == 0) {
4282 array->set_length(Smi::FromInt(0));
4283 array->set_elements(empty_fixed_array());
4284 return array;
4285 }
4286
4287 FixedArrayBase* elms;
4288 MaybeObject* maybe_elms = NULL;
4289 ElementsKind elements_kind = array->GetElementsKind();
4290 if (IsFastDoubleElementsKind(elements_kind)) {
4291 if (mode == DONT_INITIALIZE_ARRAY_ELEMENTS) {
4292 maybe_elms = AllocateUninitializedFixedDoubleArray(capacity);
4293 } else {
4294 ASSERT(mode == INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE);
4295 maybe_elms = AllocateFixedDoubleArrayWithHoles(capacity);
4296 }
4297 } else {
4298 ASSERT(IsFastSmiOrObjectElementsKind(elements_kind));
4299 if (mode == DONT_INITIALIZE_ARRAY_ELEMENTS) {
4300 maybe_elms = AllocateUninitializedFixedArray(capacity);
4301 } else {
4302 ASSERT(mode == INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE);
4303 maybe_elms = AllocateFixedArrayWithHoles(capacity);
4304 }
4305 }
4306 if (!maybe_elms->To(&elms)) return maybe_elms;
4307
4308 array->set_elements(elms);
4309 array->set_length(Smi::FromInt(length));
4310 return array;
4311 }
4312
4313
4314 MaybeObject* Heap::AllocateJSProxy(Object* handler, Object* prototype) { 4274 MaybeObject* Heap::AllocateJSProxy(Object* handler, Object* prototype) {
4315 // Allocate map. 4275 // Allocate map.
4316 // TODO(rossberg): Once we optimize proxies, think about a scheme to share 4276 // TODO(rossberg): Once we optimize proxies, think about a scheme to share
4317 // maps. Will probably depend on the identity of the handler object, too. 4277 // maps. Will probably depend on the identity of the handler object, too.
4318 Map* map; 4278 Map* map;
4319 MaybeObject* maybe_map_obj = AllocateMap(JS_PROXY_TYPE, JSProxy::kSize); 4279 MaybeObject* maybe_map_obj = AllocateMap(JS_PROXY_TYPE, JSProxy::kSize);
4320 if (!maybe_map_obj->To<Map>(&map)) return maybe_map_obj; 4280 if (!maybe_map_obj->To<Map>(&map)) return maybe_map_obj;
4321 map->set_prototype(prototype); 4281 map->set_prototype(prototype);
4322 4282
4323 // Allocate the proxy object. 4283 // Allocate the proxy object.
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after
4926 MemsetPointer(array->data_start(), filler, length); 4886 MemsetPointer(array->data_start(), filler, length);
4927 return array; 4887 return array;
4928 } 4888 }
4929 4889
4930 4890
4931 MaybeObject* Heap::AllocateFixedArray(int length, PretenureFlag pretenure) { 4891 MaybeObject* Heap::AllocateFixedArray(int length, PretenureFlag pretenure) {
4932 return AllocateFixedArrayWithFiller(length, pretenure, undefined_value()); 4892 return AllocateFixedArrayWithFiller(length, pretenure, undefined_value());
4933 } 4893 }
4934 4894
4935 4895
4936 MaybeObject* Heap::AllocateFixedArrayWithHoles(int length,
4937 PretenureFlag pretenure) {
4938 return AllocateFixedArrayWithFiller(length, pretenure, the_hole_value());
4939 }
4940
4941
4942 MaybeObject* Heap::AllocateUninitializedFixedArray(int length) { 4896 MaybeObject* Heap::AllocateUninitializedFixedArray(int length) {
4943 if (length == 0) return empty_fixed_array(); 4897 if (length == 0) return empty_fixed_array();
4944 4898
4945 Object* obj; 4899 Object* obj;
4946 { MaybeObject* maybe_obj = AllocateRawFixedArray(length, NOT_TENURED); 4900 { MaybeObject* maybe_obj = AllocateRawFixedArray(length, NOT_TENURED);
4947 if (!maybe_obj->ToObject(&obj)) return maybe_obj; 4901 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
4948 } 4902 }
4949 4903
4950 reinterpret_cast<FixedArray*>(obj)->set_map_no_write_barrier( 4904 reinterpret_cast<FixedArray*>(obj)->set_map_no_write_barrier(
4951 fixed_array_map()); 4905 fixed_array_map());
(...skipping 27 matching lines...) Expand all
4979 if (!maybe_obj->ToObject(&elements_object)) return maybe_obj; 4933 if (!maybe_obj->ToObject(&elements_object)) return maybe_obj;
4980 FixedDoubleArray* elements = 4934 FixedDoubleArray* elements =
4981 reinterpret_cast<FixedDoubleArray*>(elements_object); 4935 reinterpret_cast<FixedDoubleArray*>(elements_object);
4982 4936
4983 elements->set_map_no_write_barrier(fixed_double_array_map()); 4937 elements->set_map_no_write_barrier(fixed_double_array_map());
4984 elements->set_length(length); 4938 elements->set_length(length);
4985 return elements; 4939 return elements;
4986 } 4940 }
4987 4941
4988 4942
4989 MaybeObject* Heap::AllocateFixedDoubleArrayWithHoles(
4990 int length,
4991 PretenureFlag pretenure) {
4992 if (length == 0) return empty_fixed_array();
4993
4994 Object* elements_object;
4995 MaybeObject* maybe_obj = AllocateRawFixedDoubleArray(length, pretenure);
4996 if (!maybe_obj->ToObject(&elements_object)) return maybe_obj;
4997 FixedDoubleArray* elements =
4998 reinterpret_cast<FixedDoubleArray*>(elements_object);
4999
5000 for (int i = 0; i < length; ++i) {
5001 elements->set_the_hole(i);
5002 }
5003
5004 elements->set_map_no_write_barrier(fixed_double_array_map());
5005 elements->set_length(length);
5006 return elements;
5007 }
5008
5009
5010 MaybeObject* Heap::AllocateRawFixedDoubleArray(int length, 4943 MaybeObject* Heap::AllocateRawFixedDoubleArray(int length,
5011 PretenureFlag pretenure) { 4944 PretenureFlag pretenure) {
5012 if (length < 0 || length > FixedDoubleArray::kMaxLength) { 4945 if (length < 0 || length > FixedDoubleArray::kMaxLength) {
5013 v8::internal::Heap::FatalProcessOutOfMemory("invalid array length", true); 4946 v8::internal::Heap::FatalProcessOutOfMemory("invalid array length", true);
5014 } 4947 }
5015 int size = FixedDoubleArray::SizeFor(length); 4948 int size = FixedDoubleArray::SizeFor(length);
5016 #ifndef V8_HOST_ARCH_64_BIT 4949 #ifndef V8_HOST_ARCH_64_BIT
5017 size += kPointerSize; 4950 size += kPointerSize;
5018 #endif 4951 #endif
5019 AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, pretenure); 4952 AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, pretenure);
(...skipping 2337 matching lines...) Expand 10 before | Expand all | Expand 10 after
7357 static_cast<int>(object_sizes_last_time_[index])); 7290 static_cast<int>(object_sizes_last_time_[index]));
7358 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) 7291 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT)
7359 #undef ADJUST_LAST_TIME_OBJECT_COUNT 7292 #undef ADJUST_LAST_TIME_OBJECT_COUNT
7360 7293
7361 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); 7294 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_));
7362 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); 7295 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_));
7363 ClearObjectStats(); 7296 ClearObjectStats();
7364 } 7297 }
7365 7298
7366 } } // namespace v8::internal 7299 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/heap.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698