OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/factory.h" | 5 #include "src/factory.h" |
6 | 6 |
7 #include "src/allocation-site-scopes.h" | 7 #include "src/allocation-site-scopes.h" |
8 #include "src/base/bits.h" | 8 #include "src/base/bits.h" |
9 #include "src/bootstrapper.h" | 9 #include "src/bootstrapper.h" |
10 #include "src/conversions.h" | 10 #include "src/conversions.h" |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 } | 204 } |
205 | 205 |
206 | 206 |
207 // Internalized strings are created in the old generation (data space). | 207 // Internalized strings are created in the old generation (data space). |
208 Handle<String> Factory::InternalizeUtf8String(Vector<const char> string) { | 208 Handle<String> Factory::InternalizeUtf8String(Vector<const char> string) { |
209 Utf8StringKey key(string, isolate()->heap()->HashSeed()); | 209 Utf8StringKey key(string, isolate()->heap()->HashSeed()); |
210 return InternalizeStringWithKey(&key); | 210 return InternalizeStringWithKey(&key); |
211 } | 211 } |
212 | 212 |
213 | 213 |
214 // Internalized strings are created in the old generation (data space). | |
215 Handle<String> Factory::InternalizeString(Handle<String> string) { | |
216 if (string->IsInternalizedString()) return string; | |
217 return StringTable::LookupString(isolate(), string); | |
218 } | |
219 | |
220 | |
221 Handle<String> Factory::InternalizeOneByteString(Vector<const uint8_t> string) { | 214 Handle<String> Factory::InternalizeOneByteString(Vector<const uint8_t> string) { |
222 OneByteStringKey key(string, isolate()->heap()->HashSeed()); | 215 OneByteStringKey key(string, isolate()->heap()->HashSeed()); |
223 return InternalizeStringWithKey(&key); | 216 return InternalizeStringWithKey(&key); |
224 } | 217 } |
225 | 218 |
226 | 219 |
227 Handle<String> Factory::InternalizeOneByteString( | 220 Handle<String> Factory::InternalizeOneByteString( |
228 Handle<SeqOneByteString> string, int from, int length) { | 221 Handle<SeqOneByteString> string, int from, int length) { |
229 SeqOneByteSubStringKey key(string, from, length); | 222 SeqOneByteSubStringKey key(string, from, length); |
230 return InternalizeStringWithKey(&key); | 223 return InternalizeStringWithKey(&key); |
231 } | 224 } |
232 | 225 |
233 | 226 |
234 Handle<String> Factory::InternalizeTwoByteString(Vector<const uc16> string) { | 227 Handle<String> Factory::InternalizeTwoByteString(Vector<const uc16> string) { |
235 TwoByteStringKey key(string, isolate()->heap()->HashSeed()); | 228 TwoByteStringKey key(string, isolate()->heap()->HashSeed()); |
236 return InternalizeStringWithKey(&key); | 229 return InternalizeStringWithKey(&key); |
237 } | 230 } |
238 | 231 |
239 | 232 |
240 template<class StringTableKey> | 233 template<class StringTableKey> |
241 Handle<String> Factory::InternalizeStringWithKey(StringTableKey* key) { | 234 Handle<String> Factory::InternalizeStringWithKey(StringTableKey* key) { |
242 return StringTable::LookupKey(isolate(), key); | 235 return StringTable::LookupKey(isolate(), key); |
243 } | 236 } |
244 | 237 |
245 | 238 |
246 Handle<Name> Factory::InternalizeName(Handle<Name> name) { | |
247 if (name->IsUniqueName()) return name; | |
248 return InternalizeString(Handle<String>::cast(name)); | |
249 } | |
250 | |
251 | |
252 MaybeHandle<String> Factory::NewStringFromOneByte(Vector<const uint8_t> string, | 239 MaybeHandle<String> Factory::NewStringFromOneByte(Vector<const uint8_t> string, |
253 PretenureFlag pretenure) { | 240 PretenureFlag pretenure) { |
254 int length = string.length(); | 241 int length = string.length(); |
255 if (length == 1) return LookupSingleCharacterStringFromCode(string[0]); | 242 if (length == 1) return LookupSingleCharacterStringFromCode(string[0]); |
256 Handle<SeqOneByteString> result; | 243 Handle<SeqOneByteString> result; |
257 ASSIGN_RETURN_ON_EXCEPTION( | 244 ASSIGN_RETURN_ON_EXCEPTION( |
258 isolate(), | 245 isolate(), |
259 result, | 246 result, |
260 NewRawOneByteString(string.length(), pretenure), | 247 NewRawOneByteString(string.length(), pretenure), |
261 String); | 248 String); |
(...skipping 1973 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2235 int num = Handle<Smi>::cast(number)->value(); | 2222 int num = Handle<Smi>::cast(number)->value(); |
2236 str = IntToCString(num, buffer); | 2223 str = IntToCString(num, buffer); |
2237 } else { | 2224 } else { |
2238 double num = Handle<HeapNumber>::cast(number)->value(); | 2225 double num = Handle<HeapNumber>::cast(number)->value(); |
2239 str = DoubleToCString(num, buffer); | 2226 str = DoubleToCString(num, buffer); |
2240 } | 2227 } |
2241 | 2228 |
2242 // We tenure the allocated string since it is referenced from the | 2229 // We tenure the allocated string since it is referenced from the |
2243 // number-string cache which lives in the old space. | 2230 // number-string cache which lives in the old space. |
2244 Handle<String> js_string = NewStringFromAsciiChecked(str, TENURED); | 2231 Handle<String> js_string = NewStringFromAsciiChecked(str, TENURED); |
| 2232 // Make sure the string cached in the number cache is also the internalized |
| 2233 // version of the same string. |
| 2234 js_string = InternalizeString(js_string); |
2245 SetNumberStringCache(number, js_string); | 2235 SetNumberStringCache(number, js_string); |
2246 return js_string; | 2236 return js_string; |
2247 } | 2237 } |
2248 | 2238 |
2249 | 2239 |
2250 Handle<DebugInfo> Factory::NewDebugInfo(Handle<SharedFunctionInfo> shared) { | 2240 Handle<DebugInfo> Factory::NewDebugInfo(Handle<SharedFunctionInfo> shared) { |
2251 // Allocate initial fixed array for active break points before allocating the | 2241 // Allocate initial fixed array for active break points before allocating the |
2252 // debug info object to avoid allocation while setting up the debug info | 2242 // debug info object to avoid allocation while setting up the debug info |
2253 // object. | 2243 // object. |
2254 Handle<FixedArray> break_points( | 2244 Handle<FixedArray> break_points( |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2401 } | 2391 } |
2402 | 2392 |
2403 | 2393 |
2404 Handle<Object> Factory::ToBoolean(bool value) { | 2394 Handle<Object> Factory::ToBoolean(bool value) { |
2405 return value ? true_value() : false_value(); | 2395 return value ? true_value() : false_value(); |
2406 } | 2396 } |
2407 | 2397 |
2408 | 2398 |
2409 } // namespace internal | 2399 } // namespace internal |
2410 } // namespace v8 | 2400 } // namespace v8 |
OLD | NEW |