Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(518)

Side by Side Diff: src/heap.h

Issue 3970005: Make Failure inherit from MaybeObject instead of Object. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/globals.h ('k') | src/heap.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 // Protect/unprotect the heap by marking all spaces read-only/writable. 309 // Protect/unprotect the heap by marking all spaces read-only/writable.
310 static void Protect(); 310 static void Protect();
311 static void Unprotect(); 311 static void Unprotect();
312 #endif 312 #endif
313 313
314 // Allocates and initializes a new JavaScript object based on a 314 // Allocates and initializes a new JavaScript object based on a
315 // constructor. 315 // constructor.
316 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation 316 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
317 // failed. 317 // failed.
318 // Please note this does not perform a garbage collection. 318 // Please note this does not perform a garbage collection.
319 MUST_USE_RESULT static Object* AllocateJSObject( 319 MUST_USE_RESULT static MaybeObject* AllocateJSObject(
320 JSFunction* constructor, PretenureFlag pretenure = NOT_TENURED); 320 JSFunction* constructor, PretenureFlag pretenure = NOT_TENURED);
321 321
322 // Allocates and initializes a new global object based on a constructor. 322 // Allocates and initializes a new global object based on a constructor.
323 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation 323 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
324 // failed. 324 // failed.
325 // Please note this does not perform a garbage collection. 325 // Please note this does not perform a garbage collection.
326 MUST_USE_RESULT static Object* AllocateGlobalObject(JSFunction* constructor); 326 MUST_USE_RESULT static MaybeObject* AllocateGlobalObject(
327 JSFunction* constructor);
327 328
328 // Returns a deep copy of the JavaScript object. 329 // Returns a deep copy of the JavaScript object.
329 // Properties and elements are copied too. 330 // Properties and elements are copied too.
330 // Returns failure if allocation failed. 331 // Returns failure if allocation failed.
331 MUST_USE_RESULT static Object* CopyJSObject(JSObject* source); 332 MUST_USE_RESULT static MaybeObject* CopyJSObject(JSObject* source);
332 333
333 // Allocates the function prototype. 334 // Allocates the function prototype.
334 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation 335 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
335 // failed. 336 // failed.
336 // Please note this does not perform a garbage collection. 337 // Please note this does not perform a garbage collection.
337 MUST_USE_RESULT static Object* AllocateFunctionPrototype( 338 MUST_USE_RESULT static MaybeObject* AllocateFunctionPrototype(
338 JSFunction* function); 339 JSFunction* function);
339 340
340 // Reinitialize an JSGlobalProxy based on a constructor. The object 341 // Reinitialize an JSGlobalProxy based on a constructor. The object
341 // must have the same size as objects allocated using the 342 // must have the same size as objects allocated using the
342 // constructor. The object is reinitialized and behaves as an 343 // constructor. The object is reinitialized and behaves as an
343 // object that has been freshly allocated using the constructor. 344 // object that has been freshly allocated using the constructor.
344 MUST_USE_RESULT static Object* ReinitializeJSGlobalProxy( 345 MUST_USE_RESULT static MaybeObject* ReinitializeJSGlobalProxy(
345 JSFunction* constructor, 346 JSFunction* constructor,
346 JSGlobalProxy* global); 347 JSGlobalProxy* global);
347 348
348 // Allocates and initializes a new JavaScript object based on a map. 349 // Allocates and initializes a new JavaScript object based on a map.
349 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation 350 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
350 // failed. 351 // failed.
351 // Please note this does not perform a garbage collection. 352 // Please note this does not perform a garbage collection.
352 MUST_USE_RESULT static Object* AllocateJSObjectFromMap( 353 MUST_USE_RESULT static MaybeObject* AllocateJSObjectFromMap(
353 Map* map, PretenureFlag pretenure = NOT_TENURED); 354 Map* map, PretenureFlag pretenure = NOT_TENURED);
354 355
355 // Allocates a heap object based on the map. 356 // Allocates a heap object based on the map.
356 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation 357 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
357 // failed. 358 // failed.
358 // Please note this function does not perform a garbage collection. 359 // Please note this function does not perform a garbage collection.
359 MUST_USE_RESULT static Object* Allocate(Map* map, AllocationSpace space); 360 MUST_USE_RESULT static MaybeObject* Allocate(Map* map, AllocationSpace space);
360 361
361 // Allocates a JS Map in the heap. 362 // Allocates a JS Map in the heap.
362 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation 363 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
363 // failed. 364 // failed.
364 // Please note this function does not perform a garbage collection. 365 // Please note this function does not perform a garbage collection.
365 MUST_USE_RESULT static Object* AllocateMap(InstanceType instance_type, 366 MUST_USE_RESULT static MaybeObject* AllocateMap(InstanceType instance_type,
366 int instance_size); 367 int instance_size);
367 368
368 // Allocates a partial map for bootstrapping. 369 // Allocates a partial map for bootstrapping.
369 MUST_USE_RESULT static Object* AllocatePartialMap(InstanceType instance_type, 370 MUST_USE_RESULT static MaybeObject* AllocatePartialMap(
370 int instance_size); 371 InstanceType instance_type,
372 int instance_size);
371 373
372 // Allocate a map for the specified function 374 // Allocate a map for the specified function
373 MUST_USE_RESULT static Object* AllocateInitialMap(JSFunction* fun); 375 MUST_USE_RESULT static MaybeObject* AllocateInitialMap(JSFunction* fun);
374 376
375 // Allocates an empty code cache. 377 // Allocates an empty code cache.
376 MUST_USE_RESULT static Object* AllocateCodeCache(); 378 MUST_USE_RESULT static MaybeObject* AllocateCodeCache();
377 379
378 // Clear the Instanceof cache (used when a prototype changes). 380 // Clear the Instanceof cache (used when a prototype changes).
379 static void ClearInstanceofCache() { 381 static void ClearInstanceofCache() {
380 set_instanceof_cache_function(the_hole_value()); 382 set_instanceof_cache_function(the_hole_value());
381 } 383 }
382 384
383 // Allocates and fully initializes a String. There are two String 385 // Allocates and fully initializes a String. There are two String
384 // encodings: ASCII and two byte. One should choose between the three string 386 // encodings: ASCII and two byte. One should choose between the three string
385 // allocation functions based on the encoding of the string buffer used to 387 // allocation functions based on the encoding of the string buffer used to
386 // initialized the string. 388 // initialized the string.
387 // - ...FromAscii initializes the string from a buffer that is ASCII 389 // - ...FromAscii initializes the string from a buffer that is ASCII
388 // encoded (it does not check that the buffer is ASCII encoded) and the 390 // encoded (it does not check that the buffer is ASCII encoded) and the
389 // result will be ASCII encoded. 391 // result will be ASCII encoded.
390 // - ...FromUTF8 initializes the string from a buffer that is UTF-8 392 // - ...FromUTF8 initializes the string from a buffer that is UTF-8
391 // encoded. If the characters are all single-byte characters, the 393 // encoded. If the characters are all single-byte characters, the
392 // result will be ASCII encoded, otherwise it will converted to two 394 // result will be ASCII encoded, otherwise it will converted to two
393 // byte. 395 // byte.
394 // - ...FromTwoByte initializes the string from a buffer that is two-byte 396 // - ...FromTwoByte initializes the string from a buffer that is two-byte
395 // encoded. If the characters are all single-byte characters, the 397 // encoded. If the characters are all single-byte characters, the
396 // result will be converted to ASCII, otherwise it will be left as 398 // result will be converted to ASCII, otherwise it will be left as
397 // two-byte. 399 // two-byte.
398 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation 400 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
399 // failed. 401 // failed.
400 // Please note this does not perform a garbage collection. 402 // Please note this does not perform a garbage collection.
401 MUST_USE_RESULT static Object* AllocateStringFromAscii( 403 MUST_USE_RESULT static MaybeObject* AllocateStringFromAscii(
402 Vector<const char> str, 404 Vector<const char> str,
403 PretenureFlag pretenure = NOT_TENURED); 405 PretenureFlag pretenure = NOT_TENURED);
404 MUST_USE_RESULT static Object* AllocateStringFromUtf8( 406 MUST_USE_RESULT static MaybeObject* AllocateStringFromUtf8(
405 Vector<const char> str, 407 Vector<const char> str,
406 PretenureFlag pretenure = NOT_TENURED); 408 PretenureFlag pretenure = NOT_TENURED);
407 MUST_USE_RESULT static Object* AllocateStringFromTwoByte( 409 MUST_USE_RESULT static MaybeObject* AllocateStringFromTwoByte(
408 Vector<const uc16> str, 410 Vector<const uc16> str,
409 PretenureFlag pretenure = NOT_TENURED); 411 PretenureFlag pretenure = NOT_TENURED);
410 412
411 // Allocates a symbol in old space based on the character stream. 413 // Allocates a symbol in old space based on the character stream.
412 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation 414 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
413 // failed. 415 // failed.
414 // Please note this function does not perform a garbage collection. 416 // Please note this function does not perform a garbage collection.
415 MUST_USE_RESULT static inline Object* AllocateSymbol(Vector<const char> str, 417 MUST_USE_RESULT static inline MaybeObject* AllocateSymbol(
416 int chars, 418 Vector<const char> str,
417 uint32_t hash_field); 419 int chars,
420 uint32_t hash_field);
418 421
419 MUST_USE_RESULT static Object* AllocateInternalSymbol( 422 MUST_USE_RESULT static MaybeObject* AllocateInternalSymbol(
420 unibrow::CharacterStream* buffer, int chars, uint32_t hash_field); 423 unibrow::CharacterStream* buffer, int chars, uint32_t hash_field);
421 424
422 MUST_USE_RESULT static Object* AllocateExternalSymbol(Vector<const char> str, 425 MUST_USE_RESULT static MaybeObject* AllocateExternalSymbol(
423 int chars); 426 Vector<const char> str,
427 int chars);
424 428
425 429
426 // Allocates and partially initializes a String. There are two String 430 // Allocates and partially initializes a String. There are two String
427 // encodings: ASCII and two byte. These functions allocate a string of the 431 // encodings: ASCII and two byte. These functions allocate a string of the
428 // given length and set its map and length fields. The characters of the 432 // given length and set its map and length fields. The characters of the
429 // string are uninitialized. 433 // string are uninitialized.
430 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation 434 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
431 // failed. 435 // failed.
432 // Please note this does not perform a garbage collection. 436 // Please note this does not perform a garbage collection.
433 MUST_USE_RESULT static Object* AllocateRawAsciiString( 437 MUST_USE_RESULT static MaybeObject* AllocateRawAsciiString(
434 int length, 438 int length,
435 PretenureFlag pretenure = NOT_TENURED); 439 PretenureFlag pretenure = NOT_TENURED);
436 MUST_USE_RESULT static Object* AllocateRawTwoByteString( 440 MUST_USE_RESULT static MaybeObject* AllocateRawTwoByteString(
437 int length, 441 int length,
438 PretenureFlag pretenure = NOT_TENURED); 442 PretenureFlag pretenure = NOT_TENURED);
439 443
440 // Computes a single character string where the character has code. 444 // Computes a single character string where the character has code.
441 // A cache is used for ascii codes. 445 // A cache is used for ascii codes.
442 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation 446 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
443 // failed. Please note this does not perform a garbage collection. 447 // failed. Please note this does not perform a garbage collection.
444 MUST_USE_RESULT static Object* LookupSingleCharacterStringFromCode( 448 MUST_USE_RESULT static MaybeObject* LookupSingleCharacterStringFromCode(
445 uint16_t code); 449 uint16_t code);
446 450
447 // Allocate a byte array of the specified length 451 // Allocate a byte array of the specified length
448 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation 452 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
449 // failed. 453 // failed.
450 // Please note this does not perform a garbage collection. 454 // Please note this does not perform a garbage collection.
451 MUST_USE_RESULT static Object* AllocateByteArray(int length, 455 MUST_USE_RESULT static MaybeObject* AllocateByteArray(int length,
452 PretenureFlag pretenure); 456 PretenureFlag pretenure);
453 457
454 // Allocate a non-tenured byte array of the specified length 458 // Allocate a non-tenured byte array of the specified length
455 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation 459 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
456 // failed. 460 // failed.
457 // Please note this does not perform a garbage collection. 461 // Please note this does not perform a garbage collection.
458 MUST_USE_RESULT static Object* AllocateByteArray(int length); 462 MUST_USE_RESULT static MaybeObject* AllocateByteArray(int length);
459 463
460 // Allocate a pixel array of the specified length 464 // Allocate a pixel array of the specified length
461 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation 465 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
462 // failed. 466 // failed.
463 // Please note this does not perform a garbage collection. 467 // Please note this does not perform a garbage collection.
464 MUST_USE_RESULT static Object* AllocatePixelArray(int length, 468 MUST_USE_RESULT static MaybeObject* AllocatePixelArray(int length,
465 uint8_t* external_pointer, 469 uint8_t* external_pointer,
466 PretenureFlag pretenure); 470 PretenureFlag pretenure);
467 471
468 // Allocates an external array of the specified length and type. 472 // Allocates an external array of the specified length and type.
469 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation 473 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
470 // failed. 474 // failed.
471 // Please note this does not perform a garbage collection. 475 // Please note this does not perform a garbage collection.
472 MUST_USE_RESULT static Object* AllocateExternalArray( 476 MUST_USE_RESULT static MaybeObject* AllocateExternalArray(
473 int length, 477 int length,
474 ExternalArrayType array_type, 478 ExternalArrayType array_type,
475 void* external_pointer, 479 void* external_pointer,
476 PretenureFlag pretenure); 480 PretenureFlag pretenure);
477 481
478 // Allocate a tenured JS global property cell. 482 // Allocate a tenured JS global property cell.
479 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation 483 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
480 // failed. 484 // failed.
481 // Please note this does not perform a garbage collection. 485 // Please note this does not perform a garbage collection.
482 MUST_USE_RESULT static Object* AllocateJSGlobalPropertyCell(Object* value); 486 MUST_USE_RESULT static MaybeObject* AllocateJSGlobalPropertyCell(
487 Object* value);
483 488
484 // Allocates a fixed array initialized with undefined values 489 // Allocates a fixed array initialized with undefined values
485 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation 490 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
486 // failed. 491 // failed.
487 // Please note this does not perform a garbage collection. 492 // Please note this does not perform a garbage collection.
488 MUST_USE_RESULT static Object* AllocateFixedArray(int length, 493 MUST_USE_RESULT static MaybeObject* AllocateFixedArray(
489 PretenureFlag pretenure); 494 int length,
495 PretenureFlag pretenure);
490 // Allocates a fixed array initialized with undefined values 496 // Allocates a fixed array initialized with undefined values
491 MUST_USE_RESULT static Object* AllocateFixedArray(int length); 497 MUST_USE_RESULT static MaybeObject* AllocateFixedArray(int length);
492 498
493 // Allocates an uninitialized fixed array. It must be filled by the caller. 499 // Allocates an uninitialized fixed array. It must be filled by the caller.
494 // 500 //
495 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation 501 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
496 // failed. 502 // failed.
497 // Please note this does not perform a garbage collection. 503 // Please note this does not perform a garbage collection.
498 MUST_USE_RESULT static Object* AllocateUninitializedFixedArray(int length); 504 MUST_USE_RESULT static MaybeObject* AllocateUninitializedFixedArray(
505 int length);
499 506
500 // Make a copy of src and return it. Returns 507 // Make a copy of src and return it. Returns
501 // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed. 508 // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed.
502 MUST_USE_RESULT static inline Object* CopyFixedArray(FixedArray* src); 509 MUST_USE_RESULT static inline MaybeObject* CopyFixedArray(FixedArray* src);
503 510
504 // Make a copy of src, set the map, and return the copy. Returns 511 // Make a copy of src, set the map, and return the copy. Returns
505 // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed. 512 // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed.
506 MUST_USE_RESULT static Object* CopyFixedArrayWithMap(FixedArray* src, 513 MUST_USE_RESULT static MaybeObject* CopyFixedArrayWithMap(FixedArray* src,
507 Map* map); 514 Map* map);
508 515
509 // Allocates a fixed array initialized with the hole values. 516 // Allocates a fixed array initialized with the hole values.
510 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation 517 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
511 // failed. 518 // failed.
512 // Please note this does not perform a garbage collection. 519 // Please note this does not perform a garbage collection.
513 MUST_USE_RESULT static Object* AllocateFixedArrayWithHoles( 520 MUST_USE_RESULT static MaybeObject* AllocateFixedArrayWithHoles(
514 int length, 521 int length,
515 PretenureFlag pretenure = NOT_TENURED); 522 PretenureFlag pretenure = NOT_TENURED);
516 523
517 // AllocateHashTable is identical to AllocateFixedArray except 524 // AllocateHashTable is identical to AllocateFixedArray except
518 // that the resulting object has hash_table_map as map. 525 // that the resulting object has hash_table_map as map.
519 MUST_USE_RESULT static Object* AllocateHashTable( 526 MUST_USE_RESULT static MaybeObject* AllocateHashTable(
520 int length, PretenureFlag pretenure = NOT_TENURED); 527 int length, PretenureFlag pretenure = NOT_TENURED);
521 528
522 // Allocate a global (but otherwise uninitialized) context. 529 // Allocate a global (but otherwise uninitialized) context.
523 MUST_USE_RESULT static Object* AllocateGlobalContext(); 530 MUST_USE_RESULT static MaybeObject* AllocateGlobalContext();
524 531
525 // Allocate a function context. 532 // Allocate a function context.
526 MUST_USE_RESULT static Object* AllocateFunctionContext(int length, 533 MUST_USE_RESULT static MaybeObject* AllocateFunctionContext(
527 JSFunction* closure); 534 int length,
535 JSFunction* closure);
528 536
529 // Allocate a 'with' context. 537 // Allocate a 'with' context.
530 MUST_USE_RESULT static Object* AllocateWithContext(Context* previous, 538 MUST_USE_RESULT static MaybeObject* AllocateWithContext(
531 JSObject* extension, 539 Context* previous,
532 bool is_catch_context); 540 JSObject* extension,
541 bool is_catch_context);
533 542
534 // Allocates a new utility object in the old generation. 543 // Allocates a new utility object in the old generation.
535 MUST_USE_RESULT static Object* AllocateStruct(InstanceType type); 544 MUST_USE_RESULT static MaybeObject* AllocateStruct(InstanceType type);
536 545
537 // Allocates a function initialized with a shared part. 546 // Allocates a function initialized with a shared part.
538 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation 547 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
539 // failed. 548 // failed.
540 // Please note this does not perform a garbage collection. 549 // Please note this does not perform a garbage collection.
541 MUST_USE_RESULT static Object* AllocateFunction( 550 MUST_USE_RESULT static MaybeObject* AllocateFunction(
542 Map* function_map, 551 Map* function_map,
543 SharedFunctionInfo* shared, 552 SharedFunctionInfo* shared,
544 Object* prototype, 553 Object* prototype,
545 PretenureFlag pretenure = TENURED); 554 PretenureFlag pretenure = TENURED);
546 555
547 // Indicies for direct access into argument objects. 556 // Indicies for direct access into argument objects.
548 static const int kArgumentsObjectSize = 557 static const int kArgumentsObjectSize =
549 JSObject::kHeaderSize + 2 * kPointerSize; 558 JSObject::kHeaderSize + 2 * kPointerSize;
550 static const int arguments_callee_index = 0; 559 static const int arguments_callee_index = 0;
551 static const int arguments_length_index = 1; 560 static const int arguments_length_index = 1;
552 561
553 // Allocates an arguments object - optionally with an elements array. 562 // Allocates an arguments object - optionally with an elements array.
554 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation 563 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
555 // failed. 564 // failed.
556 // Please note this does not perform a garbage collection. 565 // Please note this does not perform a garbage collection.
557 MUST_USE_RESULT static Object* AllocateArgumentsObject(Object* callee, 566 MUST_USE_RESULT static MaybeObject* AllocateArgumentsObject(Object* callee,
558 int length); 567 int length);
559 568
560 // Same as NewNumberFromDouble, but may return a preallocated/immutable 569 // Same as NewNumberFromDouble, but may return a preallocated/immutable
561 // number object (e.g., minus_zero_value_, nan_value_) 570 // number object (e.g., minus_zero_value_, nan_value_)
562 MUST_USE_RESULT static Object* NumberFromDouble( 571 MUST_USE_RESULT static MaybeObject* NumberFromDouble(
563 double value, PretenureFlag pretenure = NOT_TENURED); 572 double value, PretenureFlag pretenure = NOT_TENURED);
564 573
565 // Allocated a HeapNumber from value. 574 // Allocated a HeapNumber from value.
566 MUST_USE_RESULT static Object* AllocateHeapNumber(double value, 575 MUST_USE_RESULT static MaybeObject* AllocateHeapNumber(
567 PretenureFlag pretenure); 576 double value,
577 PretenureFlag pretenure);
568 // pretenure = NOT_TENURED. 578 // pretenure = NOT_TENURED.
569 MUST_USE_RESULT static Object* AllocateHeapNumber(double value); 579 MUST_USE_RESULT static MaybeObject* AllocateHeapNumber(double value);
570 580
571 // Converts an int into either a Smi or a HeapNumber object. 581 // Converts an int into either a Smi or a HeapNumber object.
572 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation 582 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
573 // failed. 583 // failed.
574 // Please note this does not perform a garbage collection. 584 // Please note this does not perform a garbage collection.
575 MUST_USE_RESULT static inline Object* NumberFromInt32(int32_t value); 585 MUST_USE_RESULT static inline MaybeObject* NumberFromInt32(int32_t value);
576 586
577 // Converts an int into either a Smi or a HeapNumber object. 587 // Converts an int into either a Smi or a HeapNumber object.
578 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation 588 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
579 // failed. 589 // failed.
580 // Please note this does not perform a garbage collection. 590 // Please note this does not perform a garbage collection.
581 MUST_USE_RESULT static inline Object* NumberFromUint32(uint32_t value); 591 MUST_USE_RESULT static inline MaybeObject* NumberFromUint32(uint32_t value);
582 592
583 // Allocates a new proxy object. 593 // Allocates a new proxy object.
584 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation 594 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
585 // failed. 595 // failed.
586 // Please note this does not perform a garbage collection. 596 // Please note this does not perform a garbage collection.
587 MUST_USE_RESULT static Object* AllocateProxy( 597 MUST_USE_RESULT static MaybeObject* AllocateProxy(
588 Address proxy, 598 Address proxy,
589 PretenureFlag pretenure = NOT_TENURED); 599 PretenureFlag pretenure = NOT_TENURED);
590 600
591 // Allocates a new SharedFunctionInfo object. 601 // Allocates a new SharedFunctionInfo object.
592 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation 602 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
593 // failed. 603 // failed.
594 // Please note this does not perform a garbage collection. 604 // Please note this does not perform a garbage collection.
595 MUST_USE_RESULT static Object* AllocateSharedFunctionInfo(Object* name); 605 MUST_USE_RESULT static MaybeObject* AllocateSharedFunctionInfo(Object* name);
596 606
597 // Allocates a new cons string object. 607 // Allocates a new cons string object.
598 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation 608 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
599 // failed. 609 // failed.
600 // Please note this does not perform a garbage collection. 610 // Please note this does not perform a garbage collection.
601 MUST_USE_RESULT static Object* AllocateConsString(String* first, 611 MUST_USE_RESULT static MaybeObject* AllocateConsString(String* first,
602 String* second); 612 String* second);
603 613
604 // Allocates a new sub string object which is a substring of an underlying 614 // Allocates a new sub string object which is a substring of an underlying
605 // string buffer stretching from the index start (inclusive) to the index 615 // string buffer stretching from the index start (inclusive) to the index
606 // end (exclusive). 616 // end (exclusive).
607 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation 617 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
608 // failed. 618 // failed.
609 // Please note this does not perform a garbage collection. 619 // Please note this does not perform a garbage collection.
610 MUST_USE_RESULT static Object* AllocateSubString( 620 MUST_USE_RESULT static MaybeObject* AllocateSubString(
611 String* buffer, 621 String* buffer,
612 int start, 622 int start,
613 int end, 623 int end,
614 PretenureFlag pretenure = NOT_TENURED); 624 PretenureFlag pretenure = NOT_TENURED);
615 625
616 // Allocate a new external string object, which is backed by a string 626 // Allocate a new external string object, which is backed by a string
617 // resource that resides outside the V8 heap. 627 // resource that resides outside the V8 heap.
618 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation 628 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
619 // failed. 629 // failed.
620 // Please note this does not perform a garbage collection. 630 // Please note this does not perform a garbage collection.
621 MUST_USE_RESULT static Object* AllocateExternalStringFromAscii( 631 MUST_USE_RESULT static MaybeObject* AllocateExternalStringFromAscii(
622 ExternalAsciiString::Resource* resource); 632 ExternalAsciiString::Resource* resource);
623 MUST_USE_RESULT static Object* AllocateExternalStringFromTwoByte( 633 MUST_USE_RESULT static MaybeObject* AllocateExternalStringFromTwoByte(
624 ExternalTwoByteString::Resource* resource); 634 ExternalTwoByteString::Resource* resource);
625 635
626 // Finalizes an external string by deleting the associated external 636 // Finalizes an external string by deleting the associated external
627 // data and clearing the resource pointer. 637 // data and clearing the resource pointer.
628 static inline void FinalizeExternalString(String* string); 638 static inline void FinalizeExternalString(String* string);
629 639
630 // Allocates an uninitialized object. The memory is non-executable if the 640 // Allocates an uninitialized object. The memory is non-executable if the
631 // hardware and OS allow. 641 // hardware and OS allow.
632 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation 642 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
633 // failed. 643 // failed.
634 // Please note this function does not perform a garbage collection. 644 // Please note this function does not perform a garbage collection.
635 MUST_USE_RESULT static inline Object* AllocateRaw( 645 MUST_USE_RESULT static inline MaybeObject* AllocateRaw(
636 int size_in_bytes, 646 int size_in_bytes,
637 AllocationSpace space, 647 AllocationSpace space,
638 AllocationSpace retry_space); 648 AllocationSpace retry_space);
639 649
640 // Initialize a filler object to keep the ability to iterate over the heap 650 // Initialize a filler object to keep the ability to iterate over the heap
641 // when shortening objects. 651 // when shortening objects.
642 static void CreateFillerObjectAt(Address addr, int size); 652 static void CreateFillerObjectAt(Address addr, int size);
643 653
644 // Makes a new native code object 654 // Makes a new native code object
645 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation 655 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
646 // failed. On success, the pointer to the Code object is stored in the 656 // failed. On success, the pointer to the Code object is stored in the
647 // self_reference. This allows generated code to reference its own Code 657 // self_reference. This allows generated code to reference its own Code
648 // object by containing this pointer. 658 // object by containing this pointer.
649 // Please note this function does not perform a garbage collection. 659 // Please note this function does not perform a garbage collection.
650 MUST_USE_RESULT static Object* CreateCode(const CodeDesc& desc, 660 MUST_USE_RESULT static MaybeObject* CreateCode(const CodeDesc& desc,
651 Code::Flags flags, 661 Code::Flags flags,
652 Handle<Object> self_reference); 662 Handle<Object> self_reference);
653 663
654 MUST_USE_RESULT static Object* CopyCode(Code* code); 664 MUST_USE_RESULT static MaybeObject* CopyCode(Code* code);
655 665
656 // Copy the code and scope info part of the code object, but insert 666 // Copy the code and scope info part of the code object, but insert
657 // the provided data as the relocation information. 667 // the provided data as the relocation information.
658 MUST_USE_RESULT static Object* CopyCode(Code* code, Vector<byte> reloc_info); 668 MUST_USE_RESULT static MaybeObject* CopyCode(Code* code,
669 Vector<byte> reloc_info);
659 670
660 // Finds the symbol for string in the symbol table. 671 // Finds the symbol for string in the symbol table.
661 // If not found, a new symbol is added to the table and returned. 672 // If not found, a new symbol is added to the table and returned.
662 // Returns Failure::RetryAfterGC(requested_bytes, space) if allocation 673 // Returns Failure::RetryAfterGC(requested_bytes, space) if allocation
663 // failed. 674 // failed.
664 // Please note this function does not perform a garbage collection. 675 // Please note this function does not perform a garbage collection.
665 MUST_USE_RESULT static Object* LookupSymbol(Vector<const char> str); 676 MUST_USE_RESULT static MaybeObject* LookupSymbol(Vector<const char> str);
666 MUST_USE_RESULT static Object* LookupAsciiSymbol(const char* str) { 677 MUST_USE_RESULT static MaybeObject* LookupAsciiSymbol(const char* str) {
667 return LookupSymbol(CStrVector(str)); 678 return LookupSymbol(CStrVector(str));
668 } 679 }
669 MUST_USE_RESULT static Object* LookupSymbol(String* str); 680 MUST_USE_RESULT static MaybeObject* LookupSymbol(String* str);
670 static bool LookupSymbolIfExists(String* str, String** symbol); 681 static bool LookupSymbolIfExists(String* str, String** symbol);
671 static bool LookupTwoCharsSymbolIfExists(String* str, String** symbol); 682 static bool LookupTwoCharsSymbolIfExists(String* str, String** symbol);
672 683
673 // Compute the matching symbol map for a string if possible. 684 // Compute the matching symbol map for a string if possible.
674 // NULL is returned if string is in new space or not flattened. 685 // NULL is returned if string is in new space or not flattened.
675 static Map* SymbolMapForString(String* str); 686 static Map* SymbolMapForString(String* str);
676 687
677 // Tries to flatten a string before compare operation. 688 // Tries to flatten a string before compare operation.
678 // 689 //
679 // Returns a failure in case it was decided that flattening was 690 // Returns a failure in case it was decided that flattening was
680 // necessary and failed. Note, if flattening is not necessary the 691 // necessary and failed. Note, if flattening is not necessary the
681 // string might stay non-flat even when not a failure is returned. 692 // string might stay non-flat even when not a failure is returned.
682 // 693 //
683 // Please note this function does not perform a garbage collection. 694 // Please note this function does not perform a garbage collection.
684 MUST_USE_RESULT static inline Object* PrepareForCompare(String* str); 695 MUST_USE_RESULT static inline MaybeObject* PrepareForCompare(String* str);
685 696
686 // Converts the given boolean condition to JavaScript boolean value. 697 // Converts the given boolean condition to JavaScript boolean value.
687 static Object* ToBoolean(bool condition) { 698 static Object* ToBoolean(bool condition) {
688 return condition ? true_value() : false_value(); 699 return condition ? true_value() : false_value();
689 } 700 }
690 701
691 // Code that should be run before and after each GC. Includes some 702 // Code that should be run before and after each GC. Includes some
692 // reporting/verification activities when compiled with DEBUG set. 703 // reporting/verification activities when compiled with DEBUG set.
693 static void GarbageCollectionPrologue(); 704 static void GarbageCollectionPrologue();
694 static void GarbageCollectionEpilogue(); 705 static void GarbageCollectionEpilogue();
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 901
891 #if defined(ENABLE_LOGGING_AND_PROFILING) 902 #if defined(ENABLE_LOGGING_AND_PROFILING)
892 // Print short heap statistics. 903 // Print short heap statistics.
893 static void PrintShortHeapStatistics(); 904 static void PrintShortHeapStatistics();
894 #endif 905 #endif
895 906
896 // Makes a new symbol object 907 // Makes a new symbol object
897 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation 908 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
898 // failed. 909 // failed.
899 // Please note this function does not perform a garbage collection. 910 // Please note this function does not perform a garbage collection.
900 MUST_USE_RESULT static Object* CreateSymbol(const char* str, 911 MUST_USE_RESULT static MaybeObject* CreateSymbol(const char* str,
901 int length, 912 int length,
902 int hash); 913 int hash);
903 MUST_USE_RESULT static Object* CreateSymbol(String* str); 914 MUST_USE_RESULT static MaybeObject* CreateSymbol(String* str);
904 915
905 // Write barrier support for address[offset] = o. 916 // Write barrier support for address[offset] = o.
906 static inline void RecordWrite(Address address, int offset); 917 static inline void RecordWrite(Address address, int offset);
907 918
908 // Write barrier support for address[start : start + len[ = o. 919 // Write barrier support for address[start : start + len[ = o.
909 static inline void RecordWrites(Address address, int start, int len); 920 static inline void RecordWrites(Address address, int start, int len);
910 921
911 // Given an address occupied by a live code object, return that object. 922 // Given an address occupied by a live code object, return that object.
912 static Object* FindCodeObject(Address a); 923 static Object* FindCodeObject(Address a);
913 924
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
965 static Object* GetNumberStringCache(Object* number); 976 static Object* GetNumberStringCache(Object* number);
966 977
967 // Update the cache with a new number-string pair. 978 // Update the cache with a new number-string pair.
968 static void SetNumberStringCache(Object* number, String* str); 979 static void SetNumberStringCache(Object* number, String* str);
969 980
970 // Adjusts the amount of registered external memory. 981 // Adjusts the amount of registered external memory.
971 // Returns the adjusted value. 982 // Returns the adjusted value.
972 static inline int AdjustAmountOfExternalAllocatedMemory(int change_in_bytes); 983 static inline int AdjustAmountOfExternalAllocatedMemory(int change_in_bytes);
973 984
974 // Allocate uninitialized fixed array. 985 // Allocate uninitialized fixed array.
975 MUST_USE_RESULT static Object* AllocateRawFixedArray(int length); 986 MUST_USE_RESULT static MaybeObject* AllocateRawFixedArray(int length);
976 MUST_USE_RESULT static Object* AllocateRawFixedArray(int length, 987 MUST_USE_RESULT static MaybeObject* AllocateRawFixedArray(
977 PretenureFlag pretenure); 988 int length,
989 PretenureFlag pretenure);
978 990
979 // True if we have reached the allocation limit in the old generation that 991 // True if we have reached the allocation limit in the old generation that
980 // should force the next GC (caused normally) to be a full one. 992 // should force the next GC (caused normally) to be a full one.
981 static bool OldGenerationPromotionLimitReached() { 993 static bool OldGenerationPromotionLimitReached() {
982 return (PromotedSpaceSize() + PromotedExternalMemorySize()) 994 return (PromotedSpaceSize() + PromotedExternalMemorySize())
983 > old_gen_promotion_limit_; 995 > old_gen_promotion_limit_;
984 } 996 }
985 997
986 static intptr_t OldGenerationSpaceAvailable() { 998 static intptr_t OldGenerationSpaceAvailable() {
987 return old_gen_allocation_limit_ - 999 return old_gen_allocation_limit_ -
(...skipping 22 matching lines...) Expand all
1010 1022
1011 #define SYMBOL_INDEX_DECLARATION(name, str) k##name##RootIndex, 1023 #define SYMBOL_INDEX_DECLARATION(name, str) k##name##RootIndex,
1012 SYMBOL_LIST(SYMBOL_INDEX_DECLARATION) 1024 SYMBOL_LIST(SYMBOL_INDEX_DECLARATION)
1013 #undef SYMBOL_DECLARATION 1025 #undef SYMBOL_DECLARATION
1014 1026
1015 kSymbolTableRootIndex, 1027 kSymbolTableRootIndex,
1016 kStrongRootListLength = kSymbolTableRootIndex, 1028 kStrongRootListLength = kSymbolTableRootIndex,
1017 kRootListLength 1029 kRootListLength
1018 }; 1030 };
1019 1031
1020 MUST_USE_RESULT static Object* NumberToString( 1032 MUST_USE_RESULT static MaybeObject* NumberToString(
1021 Object* number, 1033 Object* number,
1022 bool check_number_string_cache = true); 1034 bool check_number_string_cache = true);
1023 1035
1024 static Map* MapForExternalArrayType(ExternalArrayType array_type); 1036 static Map* MapForExternalArrayType(ExternalArrayType array_type);
1025 static RootListIndex RootIndexForExternalArrayType( 1037 static RootListIndex RootIndexForExternalArrayType(
1026 ExternalArrayType array_type); 1038 ExternalArrayType array_type);
1027 1039
1028 static void RecordStats(HeapStats* stats, bool take_snapshot = false); 1040 static void RecordStats(HeapStats* stats, bool take_snapshot = false);
1029 1041
1030 // Copy block of memory from src to dst. Size of block should be aligned 1042 // Copy block of memory from src to dst. Size of block should be aligned
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
1234 static GarbageCollector SelectGarbageCollector(AllocationSpace space); 1246 static GarbageCollector SelectGarbageCollector(AllocationSpace space);
1235 1247
1236 // Performs garbage collection 1248 // Performs garbage collection
1237 static void PerformGarbageCollection(GarbageCollector collector, 1249 static void PerformGarbageCollection(GarbageCollector collector,
1238 GCTracer* tracer); 1250 GCTracer* tracer);
1239 1251
1240 // Allocate an uninitialized object in map space. The behavior is identical 1252 // Allocate an uninitialized object in map space. The behavior is identical
1241 // to Heap::AllocateRaw(size_in_bytes, MAP_SPACE), except that (a) it doesn't 1253 // to Heap::AllocateRaw(size_in_bytes, MAP_SPACE), except that (a) it doesn't
1242 // have to test the allocation space argument and (b) can reduce code size 1254 // have to test the allocation space argument and (b) can reduce code size
1243 // (since both AllocateRaw and AllocateRawMap are inlined). 1255 // (since both AllocateRaw and AllocateRawMap are inlined).
1244 MUST_USE_RESULT static inline Object* AllocateRawMap(); 1256 MUST_USE_RESULT static inline MaybeObject* AllocateRawMap();
1245 1257
1246 // Allocate an uninitialized object in the global property cell space. 1258 // Allocate an uninitialized object in the global property cell space.
1247 MUST_USE_RESULT static inline Object* AllocateRawCell(); 1259 MUST_USE_RESULT static inline MaybeObject* AllocateRawCell();
1248 1260
1249 // Initializes a JSObject based on its map. 1261 // Initializes a JSObject based on its map.
1250 static void InitializeJSObjectFromMap(JSObject* obj, 1262 static void InitializeJSObjectFromMap(JSObject* obj,
1251 FixedArray* properties, 1263 FixedArray* properties,
1252 Map* map); 1264 Map* map);
1253 1265
1254 static bool CreateInitialMaps(); 1266 static bool CreateInitialMaps();
1255 static bool CreateInitialObjects(); 1267 static bool CreateInitialObjects();
1256 1268
1257 // These four Create*EntryStub functions are here and forced to not be inlined 1269 // These four Create*EntryStub functions are here and forced to not be inlined
1258 // because of a gcc-4.4 bug that assigns wrong vtable entries. 1270 // because of a gcc-4.4 bug that assigns wrong vtable entries.
1259 NO_INLINE(static void CreateCEntryStub()); 1271 NO_INLINE(static void CreateCEntryStub());
1260 NO_INLINE(static void CreateJSEntryStub()); 1272 NO_INLINE(static void CreateJSEntryStub());
1261 NO_INLINE(static void CreateJSConstructEntryStub()); 1273 NO_INLINE(static void CreateJSConstructEntryStub());
1262 NO_INLINE(static void CreateRegExpCEntryStub()); 1274 NO_INLINE(static void CreateRegExpCEntryStub());
1263 1275
1264 static void CreateFixedStubs(); 1276 static void CreateFixedStubs();
1265 1277
1266 static Object* CreateOddball(const char* to_string, Object* to_number); 1278 MUST_USE_RESULT static MaybeObject* CreateOddball(const char* to_string,
1279 Object* to_number);
1267 1280
1268 // Allocate empty fixed array. 1281 // Allocate empty fixed array.
1269 static Object* AllocateEmptyFixedArray(); 1282 MUST_USE_RESULT static MaybeObject* AllocateEmptyFixedArray();
1270 1283
1271 // Performs a minor collection in new generation. 1284 // Performs a minor collection in new generation.
1272 static void Scavenge(); 1285 static void Scavenge();
1273 1286
1274 static String* UpdateNewSpaceReferenceInExternalStringTableEntry( 1287 static String* UpdateNewSpaceReferenceInExternalStringTableEntry(
1275 Object** pointer); 1288 Object** pointer);
1276 1289
1277 static Address DoScavenge(ObjectVisitor* scavenge_visitor, 1290 static Address DoScavenge(ObjectVisitor* scavenge_visitor,
1278 Address new_space_front); 1291 Address new_space_front);
1279 1292
(...skipping 18 matching lines...) Expand all
1298 1311
1299 // Slow part of scavenge object. 1312 // Slow part of scavenge object.
1300 static void ScavengeObjectSlow(HeapObject** p, HeapObject* object); 1313 static void ScavengeObjectSlow(HeapObject** p, HeapObject* object);
1301 1314
1302 // Initializes a function with a shared part and prototype. 1315 // Initializes a function with a shared part and prototype.
1303 // Returns the function. 1316 // Returns the function.
1304 // Note: this code was factored out of AllocateFunction such that 1317 // Note: this code was factored out of AllocateFunction such that
1305 // other parts of the VM could use it. Specifically, a function that creates 1318 // other parts of the VM could use it. Specifically, a function that creates
1306 // instances of type JS_FUNCTION_TYPE benefit from the use of this function. 1319 // instances of type JS_FUNCTION_TYPE benefit from the use of this function.
1307 // Please note this does not perform a garbage collection. 1320 // Please note this does not perform a garbage collection.
1308 MUST_USE_RESULT static inline Object* InitializeFunction( 1321 MUST_USE_RESULT static inline MaybeObject* InitializeFunction(
1309 JSFunction* function, 1322 JSFunction* function,
1310 SharedFunctionInfo* shared, 1323 SharedFunctionInfo* shared,
1311 Object* prototype); 1324 Object* prototype);
1312 1325
1313 static GCTracer* tracer_; 1326 static GCTracer* tracer_;
1314 1327
1315 1328
1316 // Initializes the number to string cache based on the max semispace size. 1329 // Initializes the number to string cache based on the max semispace size.
1317 static Object* InitializeNumberStringCache(); 1330 MUST_USE_RESULT static MaybeObject* InitializeNumberStringCache();
1318 // Flush the number to string cache. 1331 // Flush the number to string cache.
1319 static void FlushNumberStringCache(); 1332 static void FlushNumberStringCache();
1320 1333
1321 static void UpdateSurvivalRateTrend(int start_new_space_size); 1334 static void UpdateSurvivalRateTrend(int start_new_space_size);
1322 1335
1323 enum SurvivalRateTrend { INCREASING, STABLE, DECREASING, FLUCTUATING }; 1336 enum SurvivalRateTrend { INCREASING, STABLE, DECREASING, FLUCTUATING };
1324 1337
1325 static const int kYoungSurvivalRateThreshold = 90; 1338 static const int kYoungSurvivalRateThreshold = 90;
1326 static const int kYoungSurvivalRateAllowedDeviation = 15; 1339 static const int kYoungSurvivalRateAllowedDeviation = 15;
1327 1340
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after
1915 1928
1916 1929
1917 class TranscendentalCache { 1930 class TranscendentalCache {
1918 public: 1931 public:
1919 enum Type {ACOS, ASIN, ATAN, COS, EXP, LOG, SIN, TAN, kNumberOfCaches}; 1932 enum Type {ACOS, ASIN, ATAN, COS, EXP, LOG, SIN, TAN, kNumberOfCaches};
1920 1933
1921 explicit TranscendentalCache(Type t); 1934 explicit TranscendentalCache(Type t);
1922 1935
1923 // Returns a heap number with f(input), where f is a math function specified 1936 // Returns a heap number with f(input), where f is a math function specified
1924 // by the 'type' argument. 1937 // by the 'type' argument.
1925 MUST_USE_RESULT static inline Object* Get(Type type, double input) { 1938 MUST_USE_RESULT static inline MaybeObject* Get(Type type, double input) {
1926 TranscendentalCache* cache = caches_[type]; 1939 TranscendentalCache* cache = caches_[type];
1927 if (cache == NULL) { 1940 if (cache == NULL) {
1928 caches_[type] = cache = new TranscendentalCache(type); 1941 caches_[type] = cache = new TranscendentalCache(type);
1929 } 1942 }
1930 return cache->Get(input); 1943 return cache->Get(input);
1931 } 1944 }
1932 1945
1933 // The cache contains raw Object pointers. This method disposes of 1946 // The cache contains raw Object pointers. This method disposes of
1934 // them before a garbage collection. 1947 // them before a garbage collection.
1935 static void Clear(); 1948 static void Clear();
1936 1949
1937 private: 1950 private:
1938 MUST_USE_RESULT inline Object* Get(double input) { 1951 MUST_USE_RESULT inline MaybeObject* Get(double input) {
1939 Converter c; 1952 Converter c;
1940 c.dbl = input; 1953 c.dbl = input;
1941 int hash = Hash(c); 1954 int hash = Hash(c);
1942 Element e = elements_[hash]; 1955 Element e = elements_[hash];
1943 if (e.in[0] == c.integers[0] && 1956 if (e.in[0] == c.integers[0] &&
1944 e.in[1] == c.integers[1]) { 1957 e.in[1] == c.integers[1]) {
1945 ASSERT(e.output != NULL); 1958 ASSERT(e.output != NULL);
1946 Counters::transcendental_cache_hit.Increment(); 1959 Counters::transcendental_cache_hit.Increment();
1947 return e.output; 1960 return e.output;
1948 } 1961 }
1949 double answer = Calculate(input); 1962 double answer = Calculate(input);
1950 Object* heap_number = Heap::AllocateHeapNumber(answer); 1963 Counters::transcendental_cache_miss.Increment();
1951 if (!heap_number->IsFailure()) { 1964 Object* heap_number;
1952 elements_[hash].in[0] = c.integers[0]; 1965 { MaybeObject* maybe_heap_number = Heap::AllocateHeapNumber(answer);
1953 elements_[hash].in[1] = c.integers[1]; 1966 if (!maybe_heap_number->ToObject(&heap_number)) return maybe_heap_number;
1954 elements_[hash].output = heap_number;
1955 } 1967 }
1956 Counters::transcendental_cache_miss.Increment(); 1968 elements_[hash].in[0] = c.integers[0];
1969 elements_[hash].in[1] = c.integers[1];
1970 elements_[hash].output = heap_number;
1957 return heap_number; 1971 return heap_number;
1958 } 1972 }
1959 1973
1960 inline double Calculate(double input) { 1974 inline double Calculate(double input) {
1961 switch (type_) { 1975 switch (type_) {
1962 case ACOS: 1976 case ACOS:
1963 return acos(input); 1977 return acos(input);
1964 case ASIN: 1978 case ASIN:
1965 return asin(input); 1979 return asin(input);
1966 case ATAN: 1980 case ATAN:
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
2053 // Return whether this object should be retained. If NULL is returned the 2067 // Return whether this object should be retained. If NULL is returned the
2054 // object has no references. Otherwise the address of the retained object 2068 // object has no references. Otherwise the address of the retained object
2055 // should be returned as in some GC situations the object has been moved. 2069 // should be returned as in some GC situations the object has been moved.
2056 virtual Object* RetainAs(Object* object) = 0; 2070 virtual Object* RetainAs(Object* object) = 0;
2057 }; 2071 };
2058 2072
2059 2073
2060 } } // namespace v8::internal 2074 } } // namespace v8::internal
2061 2075
2062 #endif // V8_HEAP_H_ 2076 #endif // V8_HEAP_H_
OLDNEW
« no previous file with comments | « src/globals.h ('k') | src/heap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698