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

Side by Side Diff: src/heap.cc

Issue 240263002: Handlify six more allocators in from the Heap class. (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 3525 matching lines...) Expand 10 before | Expand all | Expand 10 after
3536 STATIC_ASSERT(Foreign::kSize <= Page::kMaxRegularHeapObjectSize); 3536 STATIC_ASSERT(Foreign::kSize <= Page::kMaxRegularHeapObjectSize);
3537 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; 3537 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE;
3538 Foreign* result; 3538 Foreign* result;
3539 MaybeObject* maybe_result = Allocate(foreign_map(), space); 3539 MaybeObject* maybe_result = Allocate(foreign_map(), space);
3540 if (!maybe_result->To(&result)) return maybe_result; 3540 if (!maybe_result->To(&result)) return maybe_result;
3541 result->set_foreign_address(address); 3541 result->set_foreign_address(address);
3542 return result; 3542 return result;
3543 } 3543 }
3544 3544
3545 3545
3546 MaybeObject* Heap::AllocateSharedFunctionInfo(Object* name) {
3547 SharedFunctionInfo* share;
3548 MaybeObject* maybe = Allocate(shared_function_info_map(), OLD_POINTER_SPACE);
3549 if (!maybe->To<SharedFunctionInfo>(&share)) return maybe;
3550
3551 // Set pointer fields.
3552 share->set_name(name);
3553 Code* illegal = isolate_->builtins()->builtin(Builtins::kIllegal);
3554 share->set_code(illegal);
3555 share->set_optimized_code_map(Smi::FromInt(0));
3556 share->set_scope_info(ScopeInfo::Empty(isolate_));
3557 Code* construct_stub =
3558 isolate_->builtins()->builtin(Builtins::kJSConstructStubGeneric);
3559 share->set_construct_stub(construct_stub);
3560 share->set_instance_class_name(Object_string());
3561 share->set_function_data(undefined_value(), SKIP_WRITE_BARRIER);
3562 share->set_script(undefined_value(), SKIP_WRITE_BARRIER);
3563 share->set_debug_info(undefined_value(), SKIP_WRITE_BARRIER);
3564 share->set_inferred_name(empty_string(), SKIP_WRITE_BARRIER);
3565 share->set_initial_map(undefined_value(), SKIP_WRITE_BARRIER);
3566 share->set_ast_node_count(0);
3567 share->set_counters(0);
3568
3569 // Set integer fields (smi or int, depending on the architecture).
3570 share->set_length(0);
3571 share->set_formal_parameter_count(0);
3572 share->set_expected_nof_properties(0);
3573 share->set_num_literals(0);
3574 share->set_start_position_and_type(0);
3575 share->set_end_position(0);
3576 share->set_function_token_position(0);
3577 // All compiler hints default to false or 0.
3578 share->set_compiler_hints(0);
3579 share->set_opt_count_and_bailout_reason(0);
3580
3581 return share;
3582 }
3583
3584
3585 MaybeObject* Heap::AllocateJSMessageObject(String* type,
3586 JSArray* arguments,
3587 int start_position,
3588 int end_position,
3589 Object* script,
3590 Object* stack_frames) {
3591 Object* result;
3592 { MaybeObject* maybe_result = Allocate(message_object_map(), NEW_SPACE);
3593 if (!maybe_result->ToObject(&result)) return maybe_result;
3594 }
3595 JSMessageObject* message = JSMessageObject::cast(result);
3596 message->set_properties(Heap::empty_fixed_array(), SKIP_WRITE_BARRIER);
3597 message->initialize_elements();
3598 message->set_elements(Heap::empty_fixed_array(), SKIP_WRITE_BARRIER);
3599 message->set_type(type);
3600 message->set_arguments(arguments);
3601 message->set_start_position(start_position);
3602 message->set_end_position(end_position);
3603 message->set_script(script);
3604 message->set_stack_frames(stack_frames);
3605 return result;
3606 }
3607
3608
3609 MaybeObject* Heap::AllocateExternalStringFromAscii(
3610 const ExternalAsciiString::Resource* resource) {
3611 size_t length = resource->length();
3612 if (length > static_cast<size_t>(String::kMaxLength)) {
3613 return isolate()->ThrowInvalidStringLength();
3614 }
3615
3616 Map* map = external_ascii_string_map();
3617 Object* result;
3618 { MaybeObject* maybe_result = Allocate(map, NEW_SPACE);
3619 if (!maybe_result->ToObject(&result)) return maybe_result;
3620 }
3621
3622 ExternalAsciiString* external_string = ExternalAsciiString::cast(result);
3623 external_string->set_length(static_cast<int>(length));
3624 external_string->set_hash_field(String::kEmptyHashField);
3625 external_string->set_resource(resource);
3626
3627 return result;
3628 }
3629
3630
3631 MaybeObject* Heap::AllocateExternalStringFromTwoByte(
3632 const ExternalTwoByteString::Resource* resource) {
3633 size_t length = resource->length();
3634 if (length > static_cast<size_t>(String::kMaxLength)) {
3635 return isolate()->ThrowInvalidStringLength();
3636 }
3637
3638 // For small strings we check whether the resource contains only
3639 // one byte characters. If yes, we use a different string map.
3640 static const size_t kOneByteCheckLengthLimit = 32;
3641 bool is_one_byte = length <= kOneByteCheckLengthLimit &&
3642 String::IsOneByte(resource->data(), static_cast<int>(length));
3643 Map* map = is_one_byte ?
3644 external_string_with_one_byte_data_map() : external_string_map();
3645 Object* result;
3646 { MaybeObject* maybe_result = Allocate(map, NEW_SPACE);
3647 if (!maybe_result->ToObject(&result)) return maybe_result;
3648 }
3649
3650 ExternalTwoByteString* external_string = ExternalTwoByteString::cast(result);
3651 external_string->set_length(static_cast<int>(length));
3652 external_string->set_hash_field(String::kEmptyHashField);
3653 external_string->set_resource(resource);
3654
3655 return result;
3656 }
3657
3658
3659 MaybeObject* Heap::LookupSingleCharacterStringFromCode(uint16_t code) { 3546 MaybeObject* Heap::LookupSingleCharacterStringFromCode(uint16_t code) {
3660 if (code <= String::kMaxOneByteCharCode) { 3547 if (code <= String::kMaxOneByteCharCode) {
3661 Object* value = single_character_string_cache()->get(code); 3548 Object* value = single_character_string_cache()->get(code);
3662 if (value != undefined_value()) return value; 3549 if (value != undefined_value()) return value;
3663 3550
3664 uint8_t buffer[1]; 3551 uint8_t buffer[1];
3665 buffer[0] = static_cast<uint8_t>(code); 3552 buffer[0] = static_cast<uint8_t>(code);
3666 Object* result; 3553 Object* result;
3667 OneByteStringKey key(Vector<const uint8_t>(buffer, 1), HashSeed()); 3554 OneByteStringKey key(Vector<const uint8_t>(buffer, 1), HashSeed());
3668 MaybeObject* maybe_result = InternalizeStringWithKey(&key); 3555 MaybeObject* maybe_result = InternalizeStringWithKey(&key);
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
4140 allocation_site); 4027 allocation_site);
4141 #ifdef DEBUG 4028 #ifdef DEBUG
4142 // Make sure result is NOT a global object if valid. 4029 // Make sure result is NOT a global object if valid.
4143 Object* non_failure; 4030 Object* non_failure;
4144 ASSERT(!result->ToObject(&non_failure) || !non_failure->IsGlobalObject()); 4031 ASSERT(!result->ToObject(&non_failure) || !non_failure->IsGlobalObject());
4145 #endif 4032 #endif
4146 return result; 4033 return result;
4147 } 4034 }
4148 4035
4149 4036
4150 MaybeObject* Heap::AllocateJSProxy(Object* handler, Object* prototype) {
4151 // Allocate map.
4152 // TODO(rossberg): Once we optimize proxies, think about a scheme to share
4153 // maps. Will probably depend on the identity of the handler object, too.
4154 Map* map;
4155 MaybeObject* maybe_map_obj = AllocateMap(JS_PROXY_TYPE, JSProxy::kSize);
4156 if (!maybe_map_obj->To<Map>(&map)) return maybe_map_obj;
4157 map->set_prototype(prototype);
4158
4159 // Allocate the proxy object.
4160 JSProxy* result;
4161 MaybeObject* maybe_result = Allocate(map, NEW_SPACE);
4162 if (!maybe_result->To<JSProxy>(&result)) return maybe_result;
4163 result->InitializeBody(map->instance_size(), Smi::FromInt(0));
4164 result->set_handler(handler);
4165 result->set_hash(undefined_value(), SKIP_WRITE_BARRIER);
4166 return result;
4167 }
4168
4169
4170 MaybeObject* Heap::AllocateJSFunctionProxy(Object* handler,
4171 Object* call_trap,
4172 Object* construct_trap,
4173 Object* prototype) {
4174 // Allocate map.
4175 // TODO(rossberg): Once we optimize proxies, think about a scheme to share
4176 // maps. Will probably depend on the identity of the handler object, too.
4177 Map* map;
4178 MaybeObject* maybe_map_obj =
4179 AllocateMap(JS_FUNCTION_PROXY_TYPE, JSFunctionProxy::kSize);
4180 if (!maybe_map_obj->To<Map>(&map)) return maybe_map_obj;
4181 map->set_prototype(prototype);
4182
4183 // Allocate the proxy object.
4184 JSFunctionProxy* result;
4185 MaybeObject* maybe_result = Allocate(map, NEW_SPACE);
4186 if (!maybe_result->To<JSFunctionProxy>(&result)) return maybe_result;
4187 result->InitializeBody(map->instance_size(), Smi::FromInt(0));
4188 result->set_handler(handler);
4189 result->set_hash(undefined_value(), SKIP_WRITE_BARRIER);
4190 result->set_call_trap(call_trap);
4191 result->set_construct_trap(construct_trap);
4192 return result;
4193 }
4194
4195
4196 MaybeObject* Heap::CopyJSObject(JSObject* source, AllocationSite* site) { 4037 MaybeObject* Heap::CopyJSObject(JSObject* source, AllocationSite* site) {
4197 // Never used to copy functions. If functions need to be copied we 4038 // Never used to copy functions. If functions need to be copied we
4198 // have to be careful to clear the literals array. 4039 // have to be careful to clear the literals array.
4199 SLOW_ASSERT(!source->IsJSFunction()); 4040 SLOW_ASSERT(!source->IsJSFunction());
4200 4041
4201 // Make the clone. 4042 // Make the clone.
4202 Map* map = source->map(); 4043 Map* map = source->map();
4203 int object_size = map->instance_size(); 4044 int object_size = map->instance_size();
4204 Object* clone; 4045 Object* clone;
4205 4046
(...skipping 2858 matching lines...) Expand 10 before | Expand all | Expand 10 after
7064 static_cast<int>(object_sizes_last_time_[index])); 6905 static_cast<int>(object_sizes_last_time_[index]));
7065 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) 6906 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT)
7066 #undef ADJUST_LAST_TIME_OBJECT_COUNT 6907 #undef ADJUST_LAST_TIME_OBJECT_COUNT
7067 6908
7068 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); 6909 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_));
7069 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); 6910 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_));
7070 ClearObjectStats(); 6911 ClearObjectStats();
7071 } 6912 }
7072 6913
7073 } } // namespace v8::internal 6914 } } // 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