OLD | NEW |
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 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 1200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1211 Map::cast(obj)->set_is_undetectable(); | 1211 Map::cast(obj)->set_is_undetectable(); |
1212 | 1212 |
1213 obj = AllocateMap(BYTE_ARRAY_TYPE, ByteArray::kAlignedSize); | 1213 obj = AllocateMap(BYTE_ARRAY_TYPE, ByteArray::kAlignedSize); |
1214 if (obj->IsFailure()) return false; | 1214 if (obj->IsFailure()) return false; |
1215 set_byte_array_map(Map::cast(obj)); | 1215 set_byte_array_map(Map::cast(obj)); |
1216 | 1216 |
1217 obj = AllocateMap(PIXEL_ARRAY_TYPE, PixelArray::kAlignedSize); | 1217 obj = AllocateMap(PIXEL_ARRAY_TYPE, PixelArray::kAlignedSize); |
1218 if (obj->IsFailure()) return false; | 1218 if (obj->IsFailure()) return false; |
1219 set_pixel_array_map(Map::cast(obj)); | 1219 set_pixel_array_map(Map::cast(obj)); |
1220 | 1220 |
| 1221 obj = AllocateMap(EXTERNAL_BYTE_ARRAY_TYPE, |
| 1222 ExternalArray::kAlignedSize); |
| 1223 if (obj->IsFailure()) return false; |
| 1224 set_external_byte_array_map(Map::cast(obj)); |
| 1225 |
| 1226 obj = AllocateMap(EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE, |
| 1227 ExternalArray::kAlignedSize); |
| 1228 if (obj->IsFailure()) return false; |
| 1229 set_external_unsigned_byte_array_map(Map::cast(obj)); |
| 1230 |
| 1231 obj = AllocateMap(EXTERNAL_SHORT_ARRAY_TYPE, |
| 1232 ExternalArray::kAlignedSize); |
| 1233 if (obj->IsFailure()) return false; |
| 1234 set_external_short_array_map(Map::cast(obj)); |
| 1235 |
| 1236 obj = AllocateMap(EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE, |
| 1237 ExternalArray::kAlignedSize); |
| 1238 if (obj->IsFailure()) return false; |
| 1239 set_external_unsigned_short_array_map(Map::cast(obj)); |
| 1240 |
| 1241 obj = AllocateMap(EXTERNAL_INT_ARRAY_TYPE, |
| 1242 ExternalArray::kAlignedSize); |
| 1243 if (obj->IsFailure()) return false; |
| 1244 set_external_int_array_map(Map::cast(obj)); |
| 1245 |
| 1246 obj = AllocateMap(EXTERNAL_UNSIGNED_INT_ARRAY_TYPE, |
| 1247 ExternalArray::kAlignedSize); |
| 1248 if (obj->IsFailure()) return false; |
| 1249 set_external_unsigned_int_array_map(Map::cast(obj)); |
| 1250 |
| 1251 obj = AllocateMap(EXTERNAL_FLOAT_ARRAY_TYPE, |
| 1252 ExternalArray::kAlignedSize); |
| 1253 if (obj->IsFailure()) return false; |
| 1254 set_external_float_array_map(Map::cast(obj)); |
| 1255 |
1221 obj = AllocateMap(CODE_TYPE, Code::kHeaderSize); | 1256 obj = AllocateMap(CODE_TYPE, Code::kHeaderSize); |
1222 if (obj->IsFailure()) return false; | 1257 if (obj->IsFailure()) return false; |
1223 set_code_map(Map::cast(obj)); | 1258 set_code_map(Map::cast(obj)); |
1224 | 1259 |
1225 obj = AllocateMap(JS_GLOBAL_PROPERTY_CELL_TYPE, | 1260 obj = AllocateMap(JS_GLOBAL_PROPERTY_CELL_TYPE, |
1226 JSGlobalPropertyCell::kSize); | 1261 JSGlobalPropertyCell::kSize); |
1227 if (obj->IsFailure()) return false; | 1262 if (obj->IsFailure()) return false; |
1228 set_global_property_cell_map(Map::cast(obj)); | 1263 set_global_property_cell_map(Map::cast(obj)); |
1229 | 1264 |
1230 obj = AllocateMap(FILLER_TYPE, kPointerSize); | 1265 obj = AllocateMap(FILLER_TYPE, kPointerSize); |
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1631 } | 1666 } |
1632 Object* result = AllocateStringFromAscii(CStrVector(str)); | 1667 Object* result = AllocateStringFromAscii(CStrVector(str)); |
1633 | 1668 |
1634 if (!result->IsFailure()) { | 1669 if (!result->IsFailure()) { |
1635 SetNumberStringCache(number, String::cast(result)); | 1670 SetNumberStringCache(number, String::cast(result)); |
1636 } | 1671 } |
1637 return result; | 1672 return result; |
1638 } | 1673 } |
1639 | 1674 |
1640 | 1675 |
| 1676 Map* Heap::MapForExternalArrayType(ExternalArrayType array_type) { |
| 1677 return Map::cast(roots_[RootIndexForExternalArrayType(array_type)]); |
| 1678 } |
| 1679 |
| 1680 |
| 1681 Heap::RootListIndex Heap::RootIndexForExternalArrayType( |
| 1682 ExternalArrayType array_type) { |
| 1683 switch (array_type) { |
| 1684 case kExternalByteArray: |
| 1685 return kExternalByteArrayMapRootIndex; |
| 1686 case kExternalUnsignedByteArray: |
| 1687 return kExternalUnsignedByteArrayMapRootIndex; |
| 1688 case kExternalShortArray: |
| 1689 return kExternalShortArrayMapRootIndex; |
| 1690 case kExternalUnsignedShortArray: |
| 1691 return kExternalUnsignedShortArrayMapRootIndex; |
| 1692 case kExternalIntArray: |
| 1693 return kExternalIntArrayMapRootIndex; |
| 1694 case kExternalUnsignedIntArray: |
| 1695 return kExternalUnsignedIntArrayMapRootIndex; |
| 1696 case kExternalFloatArray: |
| 1697 return kExternalFloatArrayMapRootIndex; |
| 1698 default: |
| 1699 UNREACHABLE(); |
| 1700 return kUndefinedValueRootIndex; |
| 1701 } |
| 1702 } |
| 1703 |
| 1704 |
1641 Object* Heap::NewNumberFromDouble(double value, PretenureFlag pretenure) { | 1705 Object* Heap::NewNumberFromDouble(double value, PretenureFlag pretenure) { |
1642 return SmiOrNumberFromDouble(value, | 1706 return SmiOrNumberFromDouble(value, |
1643 true /* number object must be new */, | 1707 true /* number object must be new */, |
1644 pretenure); | 1708 pretenure); |
1645 } | 1709 } |
1646 | 1710 |
1647 | 1711 |
1648 Object* Heap::NumberFromDouble(double value, PretenureFlag pretenure) { | 1712 Object* Heap::NumberFromDouble(double value, PretenureFlag pretenure) { |
1649 return SmiOrNumberFromDouble(value, | 1713 return SmiOrNumberFromDouble(value, |
1650 false /* use preallocated NaN, -0.0 */, | 1714 false /* use preallocated NaN, -0.0 */, |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1956 if (result->IsFailure()) return result; | 2020 if (result->IsFailure()) return result; |
1957 | 2021 |
1958 reinterpret_cast<PixelArray*>(result)->set_map(pixel_array_map()); | 2022 reinterpret_cast<PixelArray*>(result)->set_map(pixel_array_map()); |
1959 reinterpret_cast<PixelArray*>(result)->set_length(length); | 2023 reinterpret_cast<PixelArray*>(result)->set_length(length); |
1960 reinterpret_cast<PixelArray*>(result)->set_external_pointer(external_pointer); | 2024 reinterpret_cast<PixelArray*>(result)->set_external_pointer(external_pointer); |
1961 | 2025 |
1962 return result; | 2026 return result; |
1963 } | 2027 } |
1964 | 2028 |
1965 | 2029 |
| 2030 Object* Heap::AllocateExternalArray(int length, |
| 2031 ExternalArrayType array_type, |
| 2032 void* external_pointer, |
| 2033 PretenureFlag pretenure) { |
| 2034 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; |
| 2035 |
| 2036 // New space can't cope with forced allocation. |
| 2037 if (always_allocate()) space = OLD_DATA_SPACE; |
| 2038 |
| 2039 Object* result = AllocateRaw(ExternalArray::kAlignedSize, |
| 2040 space, |
| 2041 OLD_DATA_SPACE); |
| 2042 |
| 2043 if (result->IsFailure()) return result; |
| 2044 |
| 2045 reinterpret_cast<ExternalArray*>(result)->set_map( |
| 2046 MapForExternalArrayType(array_type)); |
| 2047 reinterpret_cast<ExternalArray*>(result)->set_length(length); |
| 2048 reinterpret_cast<ExternalArray*>(result)->set_external_pointer( |
| 2049 external_pointer); |
| 2050 |
| 2051 return result; |
| 2052 } |
| 2053 |
| 2054 |
1966 Object* Heap::CreateCode(const CodeDesc& desc, | 2055 Object* Heap::CreateCode(const CodeDesc& desc, |
1967 ZoneScopeInfo* sinfo, | 2056 ZoneScopeInfo* sinfo, |
1968 Code::Flags flags, | 2057 Code::Flags flags, |
1969 Handle<Object> self_reference) { | 2058 Handle<Object> self_reference) { |
1970 // Compute size | 2059 // Compute size |
1971 int body_size = RoundUp(desc.instr_size + desc.reloc_size, kObjectAlignment); | 2060 int body_size = RoundUp(desc.instr_size + desc.reloc_size, kObjectAlignment); |
1972 int sinfo_size = 0; | 2061 int sinfo_size = 0; |
1973 if (sinfo != NULL) sinfo_size = sinfo->Serialize(NULL); | 2062 if (sinfo != NULL) sinfo_size = sinfo->Serialize(NULL); |
1974 int obj_size = Code::SizeFor(body_size, sinfo_size); | 2063 int obj_size = Code::SizeFor(body_size, sinfo_size); |
1975 ASSERT(IsAligned(obj_size, Code::kCodeAlignment)); | 2064 ASSERT(IsAligned(obj_size, Code::kCodeAlignment)); |
(...skipping 1939 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3915 for (int i = 0; i < kNumberOfCaches; i++) { | 4004 for (int i = 0; i < kNumberOfCaches; i++) { |
3916 if (caches_[i] != NULL) { | 4005 if (caches_[i] != NULL) { |
3917 delete caches_[i]; | 4006 delete caches_[i]; |
3918 caches_[i] = NULL; | 4007 caches_[i] = NULL; |
3919 } | 4008 } |
3920 } | 4009 } |
3921 } | 4010 } |
3922 | 4011 |
3923 | 4012 |
3924 } } // namespace v8::internal | 4013 } } // namespace v8::internal |
OLD | NEW |