| 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 3258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3269 MaybeObject* Heap::AllocateJSProxy(Object* handler, Object* prototype) { | 3269 MaybeObject* Heap::AllocateJSProxy(Object* handler, Object* prototype) { |
| 3270 // Allocate map. | 3270 // Allocate map. |
| 3271 // TODO(rossberg): Once we optimize proxies, think about a scheme to share | 3271 // TODO(rossberg): Once we optimize proxies, think about a scheme to share |
| 3272 // maps. Will probably depend on the identity of the handler object, too. | 3272 // maps. Will probably depend on the identity of the handler object, too. |
| 3273 Map* map; | 3273 Map* map; |
| 3274 MaybeObject* maybe_map_obj = AllocateMap(JS_PROXY_TYPE, JSProxy::kSize); | 3274 MaybeObject* maybe_map_obj = AllocateMap(JS_PROXY_TYPE, JSProxy::kSize); |
| 3275 if (!maybe_map_obj->To<Map>(&map)) return maybe_map_obj; | 3275 if (!maybe_map_obj->To<Map>(&map)) return maybe_map_obj; |
| 3276 map->set_prototype(prototype); | 3276 map->set_prototype(prototype); |
| 3277 | 3277 |
| 3278 // Allocate the proxy object. | 3278 // Allocate the proxy object. |
| 3279 Object* result; | 3279 JSProxy* result; |
| 3280 MaybeObject* maybe_result = Allocate(map, NEW_SPACE); | 3280 MaybeObject* maybe_result = Allocate(map, NEW_SPACE); |
| 3281 if (!maybe_result->ToObject(&result)) return maybe_result; | 3281 if (!maybe_result->To<JSProxy>(&result)) return maybe_result; |
| 3282 JSProxy::cast(result)->set_handler(handler); | 3282 result->InitializeBody(map->instance_size(), Smi::FromInt(0)); |
| 3283 JSProxy::cast(result)->set_padding(Smi::FromInt(0)); | 3283 result->set_handler(handler); |
| 3284 return result; | 3284 return result; |
| 3285 } | 3285 } |
| 3286 | 3286 |
| 3287 |
| 3288 MaybeObject* Heap::AllocateJSFunctionProxy(Object* handler, |
| 3289 Object* call_trap, |
| 3290 Object* construct_trap, |
| 3291 Object* prototype) { |
| 3292 // Allocate map. |
| 3293 // TODO(rossberg): Once we optimize proxies, think about a scheme to share |
| 3294 // maps. Will probably depend on the identity of the handler object, too. |
| 3295 Map* map; |
| 3296 MaybeObject* maybe_map_obj = |
| 3297 AllocateMap(JS_FUNCTION_PROXY_TYPE, JSFunctionProxy::kSize); |
| 3298 if (!maybe_map_obj->To<Map>(&map)) return maybe_map_obj; |
| 3299 map->set_prototype(prototype); |
| 3300 |
| 3301 // Allocate the proxy object. |
| 3302 JSFunctionProxy* result; |
| 3303 MaybeObject* maybe_result = Allocate(map, NEW_SPACE); |
| 3304 if (!maybe_result->To<JSFunctionProxy>(&result)) return maybe_result; |
| 3305 result->InitializeBody(map->instance_size(), Smi::FromInt(0)); |
| 3306 result->set_handler(handler); |
| 3307 result->set_call_trap(call_trap); |
| 3308 result->set_construct_trap(construct_trap); |
| 3309 return result; |
| 3310 } |
| 3311 |
| 3287 | 3312 |
| 3288 MaybeObject* Heap::AllocateGlobalObject(JSFunction* constructor) { | 3313 MaybeObject* Heap::AllocateGlobalObject(JSFunction* constructor) { |
| 3289 ASSERT(constructor->has_initial_map()); | 3314 ASSERT(constructor->has_initial_map()); |
| 3290 Map* map = constructor->initial_map(); | 3315 Map* map = constructor->initial_map(); |
| 3291 | 3316 |
| 3292 // Make sure no field properties are described in the initial map. | 3317 // Make sure no field properties are described in the initial map. |
| 3293 // This guarantees us that normalizing the properties does not | 3318 // This guarantees us that normalizing the properties does not |
| 3294 // require us to change property values to JSGlobalPropertyCells. | 3319 // require us to change property values to JSGlobalPropertyCells. |
| 3295 ASSERT(map->NextFreePropertyIndex() == 0); | 3320 ASSERT(map->NextFreePropertyIndex() == 0); |
| 3296 | 3321 |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3418 { MaybeObject* maybe_prop = CopyFixedArray(properties); | 3443 { MaybeObject* maybe_prop = CopyFixedArray(properties); |
| 3419 if (!maybe_prop->ToObject(&prop)) return maybe_prop; | 3444 if (!maybe_prop->ToObject(&prop)) return maybe_prop; |
| 3420 } | 3445 } |
| 3421 JSObject::cast(clone)->set_properties(FixedArray::cast(prop)); | 3446 JSObject::cast(clone)->set_properties(FixedArray::cast(prop)); |
| 3422 } | 3447 } |
| 3423 // Return the new clone. | 3448 // Return the new clone. |
| 3424 return clone; | 3449 return clone; |
| 3425 } | 3450 } |
| 3426 | 3451 |
| 3427 | 3452 |
| 3428 MaybeObject* Heap::ReinitializeJSProxyAsJSObject(JSProxy* object) { | 3453 MaybeObject* Heap::ReinitializeJSReceiver( |
| 3454 JSReceiver* object, InstanceType type, int size) { |
| 3455 ASSERT(type >= FIRST_JS_RECEIVER_TYPE); |
| 3456 |
| 3429 // Allocate fresh map. | 3457 // Allocate fresh map. |
| 3430 // TODO(rossberg): Once we optimize proxies, cache these maps. | 3458 // TODO(rossberg): Once we optimize proxies, cache these maps. |
| 3431 Map* map; | 3459 Map* map; |
| 3432 MaybeObject* maybe_map_obj = | 3460 MaybeObject* maybe_map_obj = AllocateMap(type, size); |
| 3433 AllocateMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); | |
| 3434 if (!maybe_map_obj->To<Map>(&map)) return maybe_map_obj; | 3461 if (!maybe_map_obj->To<Map>(&map)) return maybe_map_obj; |
| 3435 | 3462 |
| 3436 // Check that the receiver has the same size as a fresh object. | 3463 // Check that the receiver has at least the size of the fresh object. |
| 3437 ASSERT(map->instance_size() == object->map()->instance_size()); | 3464 int size_difference = object->map()->instance_size() - map->instance_size(); |
| 3465 ASSERT(size_difference >= 0); |
| 3438 | 3466 |
| 3439 map->set_prototype(object->map()->prototype()); | 3467 map->set_prototype(object->map()->prototype()); |
| 3440 | 3468 |
| 3441 // Allocate the backing storage for the properties. | 3469 // Allocate the backing storage for the properties. |
| 3442 int prop_size = map->unused_property_fields() - map->inobject_properties(); | 3470 int prop_size = map->unused_property_fields() - map->inobject_properties(); |
| 3443 Object* properties; | 3471 Object* properties; |
| 3444 { MaybeObject* maybe_properties = AllocateFixedArray(prop_size, TENURED); | 3472 { MaybeObject* maybe_properties = AllocateFixedArray(prop_size, TENURED); |
| 3445 if (!maybe_properties->ToObject(&properties)) return maybe_properties; | 3473 if (!maybe_properties->ToObject(&properties)) return maybe_properties; |
| 3446 } | 3474 } |
| 3447 | 3475 |
| 3448 // Reset the map for the object. | 3476 // Reset the map for the object. |
| 3449 object->set_map(map); | 3477 object->set_map(map); |
| 3450 | 3478 |
| 3451 // Reinitialize the object from the constructor map. | 3479 // Reinitialize the object from the constructor map. |
| 3452 InitializeJSObjectFromMap(JSObject::cast(object), | 3480 InitializeJSObjectFromMap(JSObject::cast(object), |
| 3453 FixedArray::cast(properties), map); | 3481 FixedArray::cast(properties), map); |
| 3482 |
| 3483 // Functions require some minimal initialization. |
| 3484 if (type == JS_FUNCTION_TYPE) { |
| 3485 String* name; |
| 3486 MaybeObject* maybe_name = LookupAsciiSymbol("<freezing call trap>"); |
| 3487 if (!maybe_name->To<String>(&name)) return maybe_name; |
| 3488 SharedFunctionInfo* shared; |
| 3489 MaybeObject* maybe_shared = AllocateSharedFunctionInfo(name); |
| 3490 if (!maybe_shared->To<SharedFunctionInfo>(&shared)) return maybe_shared; |
| 3491 JSFunction* func; |
| 3492 MaybeObject* maybe_func = |
| 3493 InitializeFunction(JSFunction::cast(object), shared, the_hole_value()); |
| 3494 if (!maybe_func->To<JSFunction>(&func)) return maybe_func; |
| 3495 func->set_context(isolate()->context()->global_context()); |
| 3496 } |
| 3497 |
| 3498 // Put in filler if the new object is smaller than the old. |
| 3499 if (size_difference > 0) { |
| 3500 CreateFillerObjectAt( |
| 3501 object->address() + map->instance_size(), size_difference); |
| 3502 } |
| 3503 |
| 3454 return object; | 3504 return object; |
| 3455 } | 3505 } |
| 3456 | 3506 |
| 3457 | 3507 |
| 3458 MaybeObject* Heap::ReinitializeJSGlobalProxy(JSFunction* constructor, | 3508 MaybeObject* Heap::ReinitializeJSGlobalProxy(JSFunction* constructor, |
| 3459 JSGlobalProxy* object) { | 3509 JSGlobalProxy* object) { |
| 3460 ASSERT(constructor->has_initial_map()); | 3510 ASSERT(constructor->has_initial_map()); |
| 3461 Map* map = constructor->initial_map(); | 3511 Map* map = constructor->initial_map(); |
| 3462 | 3512 |
| 3463 // Check that the already allocated object has the same size and type as | 3513 // 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... |
| 6053 } | 6103 } |
| 6054 | 6104 |
| 6055 | 6105 |
| 6056 void ExternalStringTable::TearDown() { | 6106 void ExternalStringTable::TearDown() { |
| 6057 new_space_strings_.Free(); | 6107 new_space_strings_.Free(); |
| 6058 old_space_strings_.Free(); | 6108 old_space_strings_.Free(); |
| 6059 } | 6109 } |
| 6060 | 6110 |
| 6061 | 6111 |
| 6062 } } // namespace v8::internal | 6112 } } // namespace v8::internal |
| OLD | NEW |