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

Side by Side Diff: src/heap.cc

Issue 227623002: Handlify ten allocator functions from the Heap. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: 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 2992 matching lines...) Expand 10 before | Expand all | Expand 10 after
3003 global_property_cell_map()); 3003 global_property_cell_map());
3004 PropertyCell* cell = PropertyCell::cast(result); 3004 PropertyCell* cell = PropertyCell::cast(result);
3005 cell->set_dependent_code(DependentCode::cast(empty_fixed_array()), 3005 cell->set_dependent_code(DependentCode::cast(empty_fixed_array()),
3006 SKIP_WRITE_BARRIER); 3006 SKIP_WRITE_BARRIER);
3007 cell->set_value(the_hole_value()); 3007 cell->set_value(the_hole_value());
3008 cell->set_type(HeapType::None()); 3008 cell->set_type(HeapType::None());
3009 return result; 3009 return result;
3010 } 3010 }
3011 3011
3012 3012
3013 MaybeObject* Heap::AllocateBox(Object* value, PretenureFlag pretenure) {
3014 Box* result;
3015 MaybeObject* maybe_result = AllocateStruct(BOX_TYPE);
3016 if (!maybe_result->To(&result)) return maybe_result;
3017 result->set_value(value);
3018 return result;
3019 }
3020
3021
3022 MaybeObject* Heap::AllocateAllocationSite() { 3013 MaybeObject* Heap::AllocateAllocationSite() {
3023 AllocationSite* site; 3014 AllocationSite* site;
3024 MaybeObject* maybe_result = Allocate(allocation_site_map(), 3015 MaybeObject* maybe_result = Allocate(allocation_site_map(),
3025 OLD_POINTER_SPACE); 3016 OLD_POINTER_SPACE);
3026 if (!maybe_result->To(&site)) return maybe_result; 3017 if (!maybe_result->To(&site)) return maybe_result;
3027 site->Initialize(); 3018 site->Initialize();
3028 3019
3029 // Link the site 3020 // Link the site
3030 site->set_weak_next(allocation_sites_list()); 3021 site->set_weak_next(allocation_sites_list());
3031 set_allocation_sites_list(site); 3022 set_allocation_sites_list(site);
(...skipping 1506 matching lines...) Expand 10 before | Expand all | Expand 10 after
4538 allocation_site); 4529 allocation_site);
4539 #ifdef DEBUG 4530 #ifdef DEBUG
4540 // Make sure result is NOT a global object if valid. 4531 // Make sure result is NOT a global object if valid.
4541 Object* non_failure; 4532 Object* non_failure;
4542 ASSERT(!result->ToObject(&non_failure) || !non_failure->IsGlobalObject()); 4533 ASSERT(!result->ToObject(&non_failure) || !non_failure->IsGlobalObject());
4543 #endif 4534 #endif
4544 return result; 4535 return result;
4545 } 4536 }
4546 4537
4547 4538
4548 MaybeObject* Heap::AllocateJSModule(Context* context, ScopeInfo* scope_info) {
4549 // Allocate a fresh map. Modules do not have a prototype.
4550 Map* map;
4551 MaybeObject* maybe_map = AllocateMap(JS_MODULE_TYPE, JSModule::kSize);
4552 if (!maybe_map->To(&map)) return maybe_map;
4553 // Allocate the object based on the map.
4554 JSModule* module;
4555 MaybeObject* maybe_module = AllocateJSObjectFromMap(map, TENURED);
4556 if (!maybe_module->To(&module)) return maybe_module;
4557 module->set_context(context);
4558 module->set_scope_info(scope_info);
4559 return module;
4560 }
4561
4562
4563 MaybeObject* Heap::AllocateJSArrayAndStorage(
4564 ElementsKind elements_kind,
4565 int length,
4566 int capacity,
4567 ArrayStorageAllocationMode mode,
4568 PretenureFlag pretenure) {
4569 MaybeObject* maybe_array = AllocateJSArray(elements_kind, pretenure);
4570 JSArray* array;
4571 if (!maybe_array->To(&array)) return maybe_array;
4572
4573 // TODO(mvstanton): this body of code is duplicate with AllocateJSArrayStorage
4574 // for performance reasons.
4575 ASSERT(capacity >= length);
4576
4577 if (capacity == 0) {
4578 array->set_length(Smi::FromInt(0));
4579 array->set_elements(empty_fixed_array());
4580 return array;
4581 }
4582
4583 FixedArrayBase* elms;
4584 MaybeObject* maybe_elms = NULL;
4585 if (IsFastDoubleElementsKind(elements_kind)) {
4586 if (mode == DONT_INITIALIZE_ARRAY_ELEMENTS) {
4587 maybe_elms = AllocateUninitializedFixedDoubleArray(capacity);
4588 } else {
4589 ASSERT(mode == INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE);
4590 maybe_elms = AllocateFixedDoubleArrayWithHoles(capacity);
4591 }
4592 } else {
4593 ASSERT(IsFastSmiOrObjectElementsKind(elements_kind));
4594 if (mode == DONT_INITIALIZE_ARRAY_ELEMENTS) {
4595 maybe_elms = AllocateUninitializedFixedArray(capacity);
4596 } else {
4597 ASSERT(mode == INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE);
4598 maybe_elms = AllocateFixedArrayWithHoles(capacity);
4599 }
4600 }
4601 if (!maybe_elms->To(&elms)) return maybe_elms;
4602
4603 array->set_elements(elms);
4604 array->set_length(Smi::FromInt(length));
4605 return array;
4606 }
4607
4608
4609 MaybeObject* Heap::AllocateJSArrayStorage( 4539 MaybeObject* Heap::AllocateJSArrayStorage(
4610 JSArray* array, 4540 JSArray* array,
4611 int length, 4541 int length,
4612 int capacity, 4542 int capacity,
4613 ArrayStorageAllocationMode mode) { 4543 ArrayStorageAllocationMode mode) {
4614 ASSERT(capacity >= length); 4544 ASSERT(capacity >= length);
4615 4545
4616 if (capacity == 0) { 4546 if (capacity == 0) {
4617 array->set_length(Smi::FromInt(0)); 4547 array->set_length(Smi::FromInt(0));
4618 array->set_elements(empty_fixed_array()); 4548 array->set_elements(empty_fixed_array());
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
5105 5035
5106 // Partially initialize the object. 5036 // Partially initialize the object.
5107 HeapObject::cast(result)->set_map_no_write_barrier(string_map()); 5037 HeapObject::cast(result)->set_map_no_write_barrier(string_map());
5108 String::cast(result)->set_length(length); 5038 String::cast(result)->set_length(length);
5109 String::cast(result)->set_hash_field(String::kEmptyHashField); 5039 String::cast(result)->set_hash_field(String::kEmptyHashField);
5110 ASSERT_EQ(size, HeapObject::cast(result)->Size()); 5040 ASSERT_EQ(size, HeapObject::cast(result)->Size());
5111 return result; 5041 return result;
5112 } 5042 }
5113 5043
5114 5044
5115 MaybeObject* Heap::AllocateJSArray(
5116 ElementsKind elements_kind,
5117 PretenureFlag pretenure) {
5118 Context* native_context = isolate()->context()->native_context();
5119 JSFunction* array_function = native_context->array_function();
5120 Map* map = array_function->initial_map();
5121 Map* transition_map = isolate()->get_initial_js_array_map(elements_kind);
5122 if (transition_map != NULL) map = transition_map;
5123 return AllocateJSObjectFromMap(map, pretenure);
5124 }
5125
5126
5127 MaybeObject* Heap::AllocateEmptyFixedArray() { 5045 MaybeObject* Heap::AllocateEmptyFixedArray() {
5128 int size = FixedArray::SizeFor(0); 5046 int size = FixedArray::SizeFor(0);
5129 Object* result; 5047 Object* result;
5130 { MaybeObject* maybe_result = 5048 { MaybeObject* maybe_result =
5131 AllocateRaw(size, OLD_DATA_SPACE, OLD_DATA_SPACE); 5049 AllocateRaw(size, OLD_DATA_SPACE, OLD_DATA_SPACE);
5132 if (!maybe_result->ToObject(&result)) return maybe_result; 5050 if (!maybe_result->ToObject(&result)) return maybe_result;
5133 } 5051 }
5134 // Initialize the object. 5052 // Initialize the object.
5135 reinterpret_cast<FixedArray*>(result)->set_map_no_write_barrier( 5053 reinterpret_cast<FixedArray*>(result)->set_map_no_write_barrier(
5136 fixed_array_map()); 5054 fixed_array_map());
(...skipping 2659 matching lines...) Expand 10 before | Expand all | Expand 10 after
7796 static_cast<int>(object_sizes_last_time_[index])); 7714 static_cast<int>(object_sizes_last_time_[index]));
7797 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) 7715 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT)
7798 #undef ADJUST_LAST_TIME_OBJECT_COUNT 7716 #undef ADJUST_LAST_TIME_OBJECT_COUNT
7799 7717
7800 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); 7718 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_));
7801 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); 7719 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_));
7802 ClearObjectStats(); 7720 ClearObjectStats();
7803 } 7721 }
7804 7722
7805 } } // namespace v8::internal 7723 } } // 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