OLD | NEW |
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 2499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2510 if (!maybe_obj->ToObject(&obj)) return false; | 2510 if (!maybe_obj->ToObject(&obj)) return false; |
2511 } | 2511 } |
2512 set_non_strict_arguments_elements_map(Map::cast(obj)); | 2512 set_non_strict_arguments_elements_map(Map::cast(obj)); |
2513 | 2513 |
2514 { MaybeObject* maybe_obj = AllocateMap(EXTERNAL_DOUBLE_ARRAY_TYPE, | 2514 { MaybeObject* maybe_obj = AllocateMap(EXTERNAL_DOUBLE_ARRAY_TYPE, |
2515 ExternalArray::kAlignedSize); | 2515 ExternalArray::kAlignedSize); |
2516 if (!maybe_obj->ToObject(&obj)) return false; | 2516 if (!maybe_obj->ToObject(&obj)) return false; |
2517 } | 2517 } |
2518 set_external_double_array_map(Map::cast(obj)); | 2518 set_external_double_array_map(Map::cast(obj)); |
2519 | 2519 |
| 2520 { MaybeObject* maybe_obj = AllocateEmptyExternalArray(kExternalByteArray); |
| 2521 if (!maybe_obj->ToObject(&obj)) return false; |
| 2522 } |
| 2523 set_empty_external_byte_array(ExternalArray::cast(obj)); |
| 2524 |
| 2525 { MaybeObject* maybe_obj = |
| 2526 AllocateEmptyExternalArray(kExternalUnsignedByteArray); |
| 2527 if (!maybe_obj->ToObject(&obj)) return false; |
| 2528 } |
| 2529 set_empty_external_unsigned_byte_array(ExternalArray::cast(obj)); |
| 2530 |
| 2531 { MaybeObject* maybe_obj = AllocateEmptyExternalArray(kExternalShortArray); |
| 2532 if (!maybe_obj->ToObject(&obj)) return false; |
| 2533 } |
| 2534 set_empty_external_short_array(ExternalArray::cast(obj)); |
| 2535 |
| 2536 { MaybeObject* maybe_obj = AllocateEmptyExternalArray( |
| 2537 kExternalUnsignedShortArray); |
| 2538 if (!maybe_obj->ToObject(&obj)) return false; |
| 2539 } |
| 2540 set_empty_external_unsigned_short_array(ExternalArray::cast(obj)); |
| 2541 |
| 2542 { MaybeObject* maybe_obj = AllocateEmptyExternalArray(kExternalIntArray); |
| 2543 if (!maybe_obj->ToObject(&obj)) return false; |
| 2544 } |
| 2545 set_empty_external_int_array(ExternalArray::cast(obj)); |
| 2546 |
| 2547 { MaybeObject* maybe_obj = |
| 2548 AllocateEmptyExternalArray(kExternalUnsignedIntArray); |
| 2549 if (!maybe_obj->ToObject(&obj)) return false; |
| 2550 } |
| 2551 set_empty_external_unsigned_int_array(ExternalArray::cast(obj)); |
| 2552 |
| 2553 { MaybeObject* maybe_obj = AllocateEmptyExternalArray(kExternalFloatArray); |
| 2554 if (!maybe_obj->ToObject(&obj)) return false; |
| 2555 } |
| 2556 set_empty_external_float_array(ExternalArray::cast(obj)); |
| 2557 |
| 2558 { MaybeObject* maybe_obj = AllocateEmptyExternalArray(kExternalDoubleArray); |
| 2559 if (!maybe_obj->ToObject(&obj)) return false; |
| 2560 } |
| 2561 set_empty_external_double_array(ExternalArray::cast(obj)); |
| 2562 |
| 2563 { MaybeObject* maybe_obj = AllocateEmptyExternalArray(kExternalPixelArray); |
| 2564 if (!maybe_obj->ToObject(&obj)) return false; |
| 2565 } |
| 2566 set_empty_external_pixel_array(ExternalArray::cast(obj)); |
| 2567 |
2520 { MaybeObject* maybe_obj = AllocateMap(CODE_TYPE, kVariableSizeSentinel); | 2568 { MaybeObject* maybe_obj = AllocateMap(CODE_TYPE, kVariableSizeSentinel); |
2521 if (!maybe_obj->ToObject(&obj)) return false; | 2569 if (!maybe_obj->ToObject(&obj)) return false; |
2522 } | 2570 } |
2523 set_code_map(Map::cast(obj)); | 2571 set_code_map(Map::cast(obj)); |
2524 | 2572 |
2525 { MaybeObject* maybe_obj = AllocateMap(JS_GLOBAL_PROPERTY_CELL_TYPE, | 2573 { MaybeObject* maybe_obj = AllocateMap(JS_GLOBAL_PROPERTY_CELL_TYPE, |
2526 JSGlobalPropertyCell::kSize); | 2574 JSGlobalPropertyCell::kSize); |
2527 if (!maybe_obj->ToObject(&obj)) return false; | 2575 if (!maybe_obj->ToObject(&obj)) return false; |
2528 } | 2576 } |
2529 set_global_property_cell_map(Map::cast(obj)); | 2577 set_global_property_cell_map(Map::cast(obj)); |
(...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3241 case kExternalDoubleArray: | 3289 case kExternalDoubleArray: |
3242 return kExternalDoubleArrayMapRootIndex; | 3290 return kExternalDoubleArrayMapRootIndex; |
3243 case kExternalPixelArray: | 3291 case kExternalPixelArray: |
3244 return kExternalPixelArrayMapRootIndex; | 3292 return kExternalPixelArrayMapRootIndex; |
3245 default: | 3293 default: |
3246 UNREACHABLE(); | 3294 UNREACHABLE(); |
3247 return kUndefinedValueRootIndex; | 3295 return kUndefinedValueRootIndex; |
3248 } | 3296 } |
3249 } | 3297 } |
3250 | 3298 |
| 3299 Heap::RootListIndex Heap::RootIndexForEmptyExternalArray( |
| 3300 ElementsKind elementsKind) { |
| 3301 switch (elementsKind) { |
| 3302 case EXTERNAL_BYTE_ELEMENTS: |
| 3303 return kEmptyExternalByteArrayRootIndex; |
| 3304 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: |
| 3305 return kEmptyExternalUnsignedByteArrayRootIndex; |
| 3306 case EXTERNAL_SHORT_ELEMENTS: |
| 3307 return kEmptyExternalShortArrayRootIndex; |
| 3308 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: |
| 3309 return kEmptyExternalUnsignedShortArrayRootIndex; |
| 3310 case EXTERNAL_INT_ELEMENTS: |
| 3311 return kEmptyExternalIntArrayRootIndex; |
| 3312 case EXTERNAL_UNSIGNED_INT_ELEMENTS: |
| 3313 return kEmptyExternalUnsignedIntArrayRootIndex; |
| 3314 case EXTERNAL_FLOAT_ELEMENTS: |
| 3315 return kEmptyExternalFloatArrayRootIndex; |
| 3316 case EXTERNAL_DOUBLE_ELEMENTS: |
| 3317 return kEmptyExternalDoubleArrayRootIndex; |
| 3318 case EXTERNAL_PIXEL_ELEMENTS: |
| 3319 return kEmptyExternalPixelArrayRootIndex; |
| 3320 default: |
| 3321 UNREACHABLE(); |
| 3322 return kUndefinedValueRootIndex; |
| 3323 } |
| 3324 } |
| 3325 |
| 3326 ExternalArray* Heap::EmptyExternalArrayForMap(Map* map) { |
| 3327 return ExternalArray::cast( |
| 3328 roots_[RootIndexForEmptyExternalArray(map->elements_kind())]); |
| 3329 } |
| 3330 |
| 3331 |
| 3332 |
3251 | 3333 |
3252 MaybeObject* Heap::NumberFromDouble(double value, PretenureFlag pretenure) { | 3334 MaybeObject* Heap::NumberFromDouble(double value, PretenureFlag pretenure) { |
3253 // We need to distinguish the minus zero value and this cannot be | 3335 // We need to distinguish the minus zero value and this cannot be |
3254 // done after conversion to int. Doing this by comparing bit | 3336 // done after conversion to int. Doing this by comparing bit |
3255 // patterns is faster than using fpclassify() et al. | 3337 // patterns is faster than using fpclassify() et al. |
3256 static const DoubleRepresentation minus_zero(-0.0); | 3338 static const DoubleRepresentation minus_zero(-0.0); |
3257 | 3339 |
3258 DoubleRepresentation rep(value); | 3340 DoubleRepresentation rep(value); |
3259 if (rep.bits == minus_zero.bits) { | 3341 if (rep.bits == minus_zero.bits) { |
3260 return AllocateHeapNumber(-0.0, pretenure); | 3342 return AllocateHeapNumber(-0.0, pretenure); |
(...skipping 984 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4245 (pretenure == TENURED) ? OLD_POINTER_SPACE : NEW_SPACE; | 4327 (pretenure == TENURED) ? OLD_POINTER_SPACE : NEW_SPACE; |
4246 if (map->instance_size() > Page::kMaxNonCodeHeapObjectSize) space = LO_SPACE; | 4328 if (map->instance_size() > Page::kMaxNonCodeHeapObjectSize) space = LO_SPACE; |
4247 Object* obj; | 4329 Object* obj; |
4248 MaybeObject* maybe_obj = Allocate(map, space); | 4330 MaybeObject* maybe_obj = Allocate(map, space); |
4249 if (!maybe_obj->To(&obj)) return maybe_obj; | 4331 if (!maybe_obj->To(&obj)) return maybe_obj; |
4250 | 4332 |
4251 // Initialize the JSObject. | 4333 // Initialize the JSObject. |
4252 InitializeJSObjectFromMap(JSObject::cast(obj), | 4334 InitializeJSObjectFromMap(JSObject::cast(obj), |
4253 FixedArray::cast(properties), | 4335 FixedArray::cast(properties), |
4254 map); | 4336 map); |
4255 ASSERT(JSObject::cast(obj)->HasFastElements()); | 4337 ASSERT(JSObject::cast(obj)->HasFastElements() || |
| 4338 JSObject::cast(obj)->HasExternalArrayElements()); |
4256 return obj; | 4339 return obj; |
4257 } | 4340 } |
4258 | 4341 |
4259 | 4342 |
4260 MaybeObject* Heap::AllocateJSObjectFromMapWithAllocationSite(Map* map, | 4343 MaybeObject* Heap::AllocateJSObjectFromMapWithAllocationSite(Map* map, |
4261 Handle<Object> allocation_site_info_payload) { | 4344 Handle<Object> allocation_site_info_payload) { |
4262 // JSFunctions should be allocated using AllocateFunction to be | 4345 // JSFunctions should be allocated using AllocateFunction to be |
4263 // properly initialized. | 4346 // properly initialized. |
4264 ASSERT(map->instance_type() != JS_FUNCTION_TYPE); | 4347 ASSERT(map->instance_type() != JS_FUNCTION_TYPE); |
4265 | 4348 |
(...skipping 943 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5209 AllocateRaw(size, OLD_DATA_SPACE, OLD_DATA_SPACE); | 5292 AllocateRaw(size, OLD_DATA_SPACE, OLD_DATA_SPACE); |
5210 if (!maybe_result->ToObject(&result)) return maybe_result; | 5293 if (!maybe_result->ToObject(&result)) return maybe_result; |
5211 } | 5294 } |
5212 // Initialize the object. | 5295 // Initialize the object. |
5213 reinterpret_cast<FixedArray*>(result)->set_map_no_write_barrier( | 5296 reinterpret_cast<FixedArray*>(result)->set_map_no_write_barrier( |
5214 fixed_array_map()); | 5297 fixed_array_map()); |
5215 reinterpret_cast<FixedArray*>(result)->set_length(0); | 5298 reinterpret_cast<FixedArray*>(result)->set_length(0); |
5216 return result; | 5299 return result; |
5217 } | 5300 } |
5218 | 5301 |
| 5302 MaybeObject* Heap::AllocateEmptyExternalArray(ExternalArrayType array_type) { |
| 5303 return AllocateExternalArray(0, array_type, NULL, TENURED); |
| 5304 } |
| 5305 |
5219 | 5306 |
5220 MaybeObject* Heap::AllocateRawFixedArray(int length) { | 5307 MaybeObject* Heap::AllocateRawFixedArray(int length) { |
5221 if (length < 0 || length > FixedArray::kMaxLength) { | 5308 if (length < 0 || length > FixedArray::kMaxLength) { |
5222 return Failure::OutOfMemoryException(0xd); | 5309 return Failure::OutOfMemoryException(0xd); |
5223 } | 5310 } |
5224 ASSERT(length > 0); | 5311 ASSERT(length > 0); |
5225 // Use the general function if we're forced to always allocate. | 5312 // Use the general function if we're forced to always allocate. |
5226 if (always_allocate()) return AllocateFixedArray(length, TENURED); | 5313 if (always_allocate()) return AllocateFixedArray(length, TENURED); |
5227 // Allocate the raw data for a fixed array. | 5314 // Allocate the raw data for a fixed array. |
5228 int size = FixedArray::SizeFor(length); | 5315 int size = FixedArray::SizeFor(length); |
(...skipping 2647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7876 if (FLAG_parallel_recompilation) { | 7963 if (FLAG_parallel_recompilation) { |
7877 heap_->relocation_mutex_->Lock(); | 7964 heap_->relocation_mutex_->Lock(); |
7878 #ifdef DEBUG | 7965 #ifdef DEBUG |
7879 heap_->relocation_mutex_locked_by_optimizer_thread_ = | 7966 heap_->relocation_mutex_locked_by_optimizer_thread_ = |
7880 heap_->isolate()->optimizing_compiler_thread()->IsOptimizerThread(); | 7967 heap_->isolate()->optimizing_compiler_thread()->IsOptimizerThread(); |
7881 #endif // DEBUG | 7968 #endif // DEBUG |
7882 } | 7969 } |
7883 } | 7970 } |
7884 | 7971 |
7885 } } // namespace v8::internal | 7972 } } // namespace v8::internal |
OLD | NEW |