OLD | NEW |
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 3272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3283 MaybeObject* maybe_map_obj = AllocateMap(JS_PROXY_TYPE, JSProxy::kSize); | 3283 MaybeObject* maybe_map_obj = AllocateMap(JS_PROXY_TYPE, JSProxy::kSize); |
3284 if (!maybe_map_obj->To<Map>(&map)) return maybe_map_obj; | 3284 if (!maybe_map_obj->To<Map>(&map)) return maybe_map_obj; |
3285 map->set_prototype(prototype); | 3285 map->set_prototype(prototype); |
3286 | 3286 |
3287 // Allocate the proxy object. | 3287 // Allocate the proxy object. |
3288 JSProxy* result; | 3288 JSProxy* result; |
3289 MaybeObject* maybe_result = Allocate(map, NEW_SPACE); | 3289 MaybeObject* maybe_result = Allocate(map, NEW_SPACE); |
3290 if (!maybe_result->To<JSProxy>(&result)) return maybe_result; | 3290 if (!maybe_result->To<JSProxy>(&result)) return maybe_result; |
3291 result->InitializeBody(map->instance_size(), Smi::FromInt(0)); | 3291 result->InitializeBody(map->instance_size(), Smi::FromInt(0)); |
3292 result->set_handler(handler); | 3292 result->set_handler(handler); |
| 3293 result->set_hash(undefined_value()); |
3293 return result; | 3294 return result; |
3294 } | 3295 } |
3295 | 3296 |
3296 | 3297 |
3297 MaybeObject* Heap::AllocateJSFunctionProxy(Object* handler, | 3298 MaybeObject* Heap::AllocateJSFunctionProxy(Object* handler, |
3298 Object* call_trap, | 3299 Object* call_trap, |
3299 Object* construct_trap, | 3300 Object* construct_trap, |
3300 Object* prototype) { | 3301 Object* prototype) { |
3301 // Allocate map. | 3302 // Allocate map. |
3302 // TODO(rossberg): Once we optimize proxies, think about a scheme to share | 3303 // TODO(rossberg): Once we optimize proxies, think about a scheme to share |
3303 // maps. Will probably depend on the identity of the handler object, too. | 3304 // maps. Will probably depend on the identity of the handler object, too. |
3304 Map* map; | 3305 Map* map; |
3305 MaybeObject* maybe_map_obj = | 3306 MaybeObject* maybe_map_obj = |
3306 AllocateMap(JS_FUNCTION_PROXY_TYPE, JSFunctionProxy::kSize); | 3307 AllocateMap(JS_FUNCTION_PROXY_TYPE, JSFunctionProxy::kSize); |
3307 if (!maybe_map_obj->To<Map>(&map)) return maybe_map_obj; | 3308 if (!maybe_map_obj->To<Map>(&map)) return maybe_map_obj; |
3308 map->set_prototype(prototype); | 3309 map->set_prototype(prototype); |
3309 | 3310 |
3310 // Allocate the proxy object. | 3311 // Allocate the proxy object. |
3311 JSFunctionProxy* result; | 3312 JSFunctionProxy* result; |
3312 MaybeObject* maybe_result = Allocate(map, NEW_SPACE); | 3313 MaybeObject* maybe_result = Allocate(map, NEW_SPACE); |
3313 if (!maybe_result->To<JSFunctionProxy>(&result)) return maybe_result; | 3314 if (!maybe_result->To<JSFunctionProxy>(&result)) return maybe_result; |
3314 result->InitializeBody(map->instance_size(), Smi::FromInt(0)); | 3315 result->InitializeBody(map->instance_size(), Smi::FromInt(0)); |
3315 result->set_handler(handler); | 3316 result->set_handler(handler); |
| 3317 result->set_hash(undefined_value()); |
3316 result->set_call_trap(call_trap); | 3318 result->set_call_trap(call_trap); |
3317 result->set_construct_trap(construct_trap); | 3319 result->set_construct_trap(construct_trap); |
3318 return result; | 3320 return result; |
3319 } | 3321 } |
3320 | 3322 |
3321 | 3323 |
3322 MaybeObject* Heap::AllocateGlobalObject(JSFunction* constructor) { | 3324 MaybeObject* Heap::AllocateGlobalObject(JSFunction* constructor) { |
3323 ASSERT(constructor->has_initial_map()); | 3325 ASSERT(constructor->has_initial_map()); |
3324 Map* map = constructor->initial_map(); | 3326 Map* map = constructor->initial_map(); |
3325 | 3327 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3454 } | 3456 } |
3455 JSObject::cast(clone)->set_properties(FixedArray::cast(prop)); | 3457 JSObject::cast(clone)->set_properties(FixedArray::cast(prop)); |
3456 } | 3458 } |
3457 // Return the new clone. | 3459 // Return the new clone. |
3458 return clone; | 3460 return clone; |
3459 } | 3461 } |
3460 | 3462 |
3461 | 3463 |
3462 MaybeObject* Heap::ReinitializeJSReceiver( | 3464 MaybeObject* Heap::ReinitializeJSReceiver( |
3463 JSReceiver* object, InstanceType type, int size) { | 3465 JSReceiver* object, InstanceType type, int size) { |
3464 ASSERT(type >= FIRST_JS_RECEIVER_TYPE); | 3466 ASSERT(type >= FIRST_JS_OBJECT_TYPE); |
| 3467 |
| 3468 // Save identity hash. |
| 3469 MaybeObject* maybe_hash = object->GetIdentityHash(OMIT_CREATION); |
3465 | 3470 |
3466 // Allocate fresh map. | 3471 // Allocate fresh map. |
3467 // TODO(rossberg): Once we optimize proxies, cache these maps. | 3472 // TODO(rossberg): Once we optimize proxies, cache these maps. |
3468 Map* map; | 3473 Map* map; |
3469 MaybeObject* maybe_map_obj = AllocateMap(type, size); | 3474 MaybeObject* maybe = AllocateMap(type, size); |
3470 if (!maybe_map_obj->To<Map>(&map)) return maybe_map_obj; | 3475 if (!maybe->To<Map>(&map)) return maybe; |
3471 | 3476 |
3472 // Check that the receiver has at least the size of the fresh object. | 3477 // Check that the receiver has at least the size of the fresh object. |
3473 int size_difference = object->map()->instance_size() - map->instance_size(); | 3478 int size_difference = object->map()->instance_size() - map->instance_size(); |
3474 ASSERT(size_difference >= 0); | 3479 ASSERT(size_difference >= 0); |
3475 | 3480 |
3476 map->set_prototype(object->map()->prototype()); | 3481 map->set_prototype(object->map()->prototype()); |
3477 | 3482 |
3478 // Allocate the backing storage for the properties. | 3483 // Allocate the backing storage for the properties. |
3479 int prop_size = map->unused_property_fields() - map->inobject_properties(); | 3484 int prop_size = map->unused_property_fields() - map->inobject_properties(); |
3480 Object* properties; | 3485 Object* properties; |
3481 { MaybeObject* maybe_properties = AllocateFixedArray(prop_size, TENURED); | 3486 { MaybeObject* maybe_properties = AllocateFixedArray(prop_size, TENURED); |
3482 if (!maybe_properties->ToObject(&properties)) return maybe_properties; | 3487 if (!maybe_properties->ToObject(&properties)) return maybe_properties; |
3483 } | 3488 } |
3484 | 3489 |
3485 // Reset the map for the object. | 3490 // Reset the map for the object. |
3486 object->set_map(map); | 3491 object->set_map(map); |
| 3492 JSObject* jsobj = JSObject::cast(object); |
3487 | 3493 |
3488 // Reinitialize the object from the constructor map. | 3494 // Reinitialize the object from the constructor map. |
3489 InitializeJSObjectFromMap(JSObject::cast(object), | 3495 InitializeJSObjectFromMap(jsobj, FixedArray::cast(properties), map); |
3490 FixedArray::cast(properties), map); | |
3491 | 3496 |
3492 // Functions require some minimal initialization. | 3497 // Functions require some minimal initialization. |
3493 if (type == JS_FUNCTION_TYPE) { | 3498 if (type == JS_FUNCTION_TYPE) { |
3494 map->set_function_with_prototype(true); | 3499 map->set_function_with_prototype(true); |
3495 String* name; | 3500 String* name; |
3496 MaybeObject* maybe_name = LookupAsciiSymbol("<freezing call trap>"); | 3501 maybe = LookupAsciiSymbol("<freezing call trap>"); |
3497 if (!maybe_name->To<String>(&name)) return maybe_name; | 3502 if (!maybe->To<String>(&name)) return maybe; |
3498 SharedFunctionInfo* shared; | 3503 SharedFunctionInfo* shared; |
3499 MaybeObject* maybe_shared = AllocateSharedFunctionInfo(name); | 3504 maybe = AllocateSharedFunctionInfo(name); |
3500 if (!maybe_shared->To<SharedFunctionInfo>(&shared)) return maybe_shared; | 3505 if (!maybe->To<SharedFunctionInfo>(&shared)) return maybe; |
3501 JSFunction* func; | 3506 JSFunction* func; |
3502 MaybeObject* maybe_func = | 3507 maybe = InitializeFunction( |
3503 InitializeFunction(JSFunction::cast(object), shared, the_hole_value()); | 3508 JSFunction::cast(object), shared, the_hole_value()); |
3504 if (!maybe_func->To<JSFunction>(&func)) return maybe_func; | 3509 if (!maybe->To<JSFunction>(&func)) return maybe; |
3505 func->set_context(isolate()->context()->global_context()); | 3510 func->set_context(isolate()->context()->global_context()); |
3506 } | 3511 } |
3507 | 3512 |
3508 // Put in filler if the new object is smaller than the old. | 3513 // Put in filler if the new object is smaller than the old. |
3509 if (size_difference > 0) { | 3514 if (size_difference > 0) { |
3510 CreateFillerObjectAt( | 3515 CreateFillerObjectAt( |
3511 object->address() + map->instance_size(), size_difference); | 3516 object->address() + map->instance_size(), size_difference); |
3512 } | 3517 } |
3513 | 3518 |
| 3519 // Inherit identity, if it was present. |
| 3520 Object* hash; |
| 3521 if (maybe_hash->To<Object>(&hash) && hash->IsSmi()) { |
| 3522 maybe = jsobj->SetIdentityHash(hash, ALLOW_CREATION); |
| 3523 if (maybe->IsFailure()) return maybe; |
| 3524 } |
| 3525 |
3514 return object; | 3526 return object; |
3515 } | 3527 } |
3516 | 3528 |
3517 | 3529 |
3518 MaybeObject* Heap::ReinitializeJSGlobalProxy(JSFunction* constructor, | 3530 MaybeObject* Heap::ReinitializeJSGlobalProxy(JSFunction* constructor, |
3519 JSGlobalProxy* object) { | 3531 JSGlobalProxy* object) { |
3520 ASSERT(constructor->has_initial_map()); | 3532 ASSERT(constructor->has_initial_map()); |
3521 Map* map = constructor->initial_map(); | 3533 Map* map = constructor->initial_map(); |
3522 | 3534 |
3523 // Check that the already allocated object has the same size and type as | 3535 // Check that the already allocated object has the same size and type as |
(...skipping 2589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6113 } | 6125 } |
6114 | 6126 |
6115 | 6127 |
6116 void ExternalStringTable::TearDown() { | 6128 void ExternalStringTable::TearDown() { |
6117 new_space_strings_.Free(); | 6129 new_space_strings_.Free(); |
6118 old_space_strings_.Free(); | 6130 old_space_strings_.Free(); |
6119 } | 6131 } |
6120 | 6132 |
6121 | 6133 |
6122 } } // namespace v8::internal | 6134 } } // namespace v8::internal |
OLD | NEW |