OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 760 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
771 bool Failure::IsOutOfMemoryException() const { | 771 bool Failure::IsOutOfMemoryException() const { |
772 return type() == OUT_OF_MEMORY_EXCEPTION; | 772 return type() == OUT_OF_MEMORY_EXCEPTION; |
773 } | 773 } |
774 | 774 |
775 | 775 |
776 int Failure::requested() const { | 776 int Failure::requested() const { |
777 const int kShiftBits = | 777 const int kShiftBits = |
778 kFailureTypeTagSize + kSpaceTagSize - kObjectAlignmentBits; | 778 kFailureTypeTagSize + kSpaceTagSize - kObjectAlignmentBits; |
779 STATIC_ASSERT(kShiftBits >= 0); | 779 STATIC_ASSERT(kShiftBits >= 0); |
780 ASSERT(type() == RETRY_AFTER_GC); | 780 ASSERT(type() == RETRY_AFTER_GC); |
781 return value() >> kShiftBits; | 781 return static_cast<int>(value() >> kShiftBits); |
782 } | 782 } |
783 | 783 |
784 | 784 |
785 AllocationSpace Failure::allocation_space() const { | 785 AllocationSpace Failure::allocation_space() const { |
786 ASSERT_EQ(RETRY_AFTER_GC, type()); | 786 ASSERT_EQ(RETRY_AFTER_GC, type()); |
787 return static_cast<AllocationSpace>((value() >> kFailureTypeTagSize) | 787 return static_cast<AllocationSpace>((value() >> kFailureTypeTagSize) |
788 & kSpaceTagMask); | 788 & kSpaceTagMask); |
789 } | 789 } |
790 | 790 |
791 | 791 |
792 Failure* Failure::InternalError() { | 792 Failure* Failure::InternalError() { |
793 return Construct(INTERNAL_ERROR); | 793 return Construct(INTERNAL_ERROR); |
794 } | 794 } |
795 | 795 |
796 | 796 |
797 Failure* Failure::Exception() { | 797 Failure* Failure::Exception() { |
798 return Construct(EXCEPTION); | 798 return Construct(EXCEPTION); |
799 } | 799 } |
800 | 800 |
801 | 801 |
802 Failure* Failure::OutOfMemoryException() { | 802 Failure* Failure::OutOfMemoryException() { |
803 return Construct(OUT_OF_MEMORY_EXCEPTION); | 803 return Construct(OUT_OF_MEMORY_EXCEPTION); |
804 } | 804 } |
805 | 805 |
806 | 806 |
807 int Failure::value() const { | 807 intptr_t Failure::value() const { |
808 return static_cast<int>(reinterpret_cast<intptr_t>(this) >> kFailureTagSize); | 808 return reinterpret_cast<intptr_t>(this) >> kFailureTagSize; |
809 } | 809 } |
810 | 810 |
811 | 811 |
812 Failure* Failure::RetryAfterGC(int requested_bytes) { | 812 Failure* Failure::RetryAfterGC(int requested_bytes) { |
813 // Assert that the space encoding fits in the three bytes allotted for it. | 813 // Assert that the space encoding fits in the three bytes allotted for it. |
814 ASSERT((LAST_SPACE & ~kSpaceTagMask) == 0); | 814 ASSERT((LAST_SPACE & ~kSpaceTagMask) == 0); |
815 int requested = requested_bytes >> kObjectAlignmentBits; | 815 intptr_t requested = requested_bytes >> kObjectAlignmentBits; |
| 816 int tag_bits = kSpaceTagSize + kFailureTypeTagSize; |
| 817 if (((requested << tag_bits) >> tag_bits) != requested) { |
| 818 // No room for entire requested size in the bits. Round down to |
| 819 // maximally representable size. |
| 820 requested = static_cast<intptr_t>( |
| 821 (~static_cast<uintptr_t>(0)) >> (tag_bits + 1)); |
| 822 } |
816 int value = (requested << kSpaceTagSize) | NEW_SPACE; | 823 int value = (requested << kSpaceTagSize) | NEW_SPACE; |
817 ASSERT(value >> kSpaceTagSize == requested); | |
818 ASSERT(Smi::IsValid(value)); | |
819 ASSERT(value == ((value << kFailureTypeTagSize) >> kFailureTypeTagSize)); | |
820 ASSERT(Smi::IsValid(value << kFailureTypeTagSize)); | |
821 return Construct(RETRY_AFTER_GC, value); | 824 return Construct(RETRY_AFTER_GC, value); |
822 } | 825 } |
823 | 826 |
824 | 827 |
825 Failure* Failure::Construct(Type type, int value) { | 828 Failure* Failure::Construct(Type type, intptr_t value) { |
826 int info = (value << kFailureTypeTagSize) | type; | 829 intptr_t info = (static_cast<intptr_t>(value) << kFailureTypeTagSize) | type; |
827 ASSERT(((info << kFailureTagSize) >> kFailureTagSize) == info); | 830 ASSERT(((info << kFailureTagSize) >> kFailureTagSize) == info); |
828 return reinterpret_cast<Failure*>( | 831 return reinterpret_cast<Failure*>((info << kFailureTagSize) | kFailureTag); |
829 (static_cast<intptr_t>(info) << kFailureTagSize) | kFailureTag); | |
830 } | 832 } |
831 | 833 |
832 | 834 |
833 bool Smi::IsValid(intptr_t value) { | 835 bool Smi::IsValid(intptr_t value) { |
834 #ifdef DEBUG | 836 #ifdef DEBUG |
835 bool in_range = (value >= kMinValue) && (value <= kMaxValue); | 837 bool in_range = (value >= kMinValue) && (value <= kMaxValue); |
836 #endif | 838 #endif |
837 | 839 |
838 #ifdef V8_TARGET_ARCH_X64 | 840 #ifdef V8_TARGET_ARCH_X64 |
839 // To be representable as a long smi, the value must be a 32-bit integer. | 841 // To be representable as a long smi, the value must be a 32-bit integer. |
(...skipping 2047 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2887 #undef WRITE_INT_FIELD | 2889 #undef WRITE_INT_FIELD |
2888 #undef READ_SHORT_FIELD | 2890 #undef READ_SHORT_FIELD |
2889 #undef WRITE_SHORT_FIELD | 2891 #undef WRITE_SHORT_FIELD |
2890 #undef READ_BYTE_FIELD | 2892 #undef READ_BYTE_FIELD |
2891 #undef WRITE_BYTE_FIELD | 2893 #undef WRITE_BYTE_FIELD |
2892 | 2894 |
2893 | 2895 |
2894 } } // namespace v8::internal | 2896 } } // namespace v8::internal |
2895 | 2897 |
2896 #endif // V8_OBJECTS_INL_H_ | 2898 #endif // V8_OBJECTS_INL_H_ |
OLD | NEW |