📄 objects.h.svn-base
字号:
PropertyAttributes* attributes); Object* GetProperty(Object* receiver, LookupResult* result, String* key, PropertyAttributes* attributes); Object* GetPropertyWithCallback(Object* receiver, Object* structure, String* name, Object* holder); inline Object* GetElement(uint32_t index); Object* GetElementWithReceiver(Object* receiver, uint32_t index); // Return the object's prototype (might be Heap::null_value()). Object* GetPrototype(); // Returns true if this is a JSValue containing a string and the index is // < the length of the string. Used to implement [] on strings. inline bool IsStringObjectWithCharacterAt(uint32_t index);#ifdef DEBUG // Prints this object with details. void Print(); void PrintLn(); // Verifies the object. void Verify(); // Verify a pointer is a valid object pointer. static void VerifyPointer(Object* p);#endif // Prints this object without details. void ShortPrint(); // Prints this object without details to a message accumulator. void ShortPrint(StringStream* accumulator); // Casting: This cast is only needed to satisfy macros in objects-inl.h. static Object* cast(Object* value) { return value; } // Layout description. static const int kHeaderSize = 0; // Object does not take up any space. private: DISALLOW_IMPLICIT_CONSTRUCTORS(Object);};// Smi represents integer Numbers that can be stored in 31 bits.// Smis are immediate which means they are NOT allocated in the heap.// The this pointer has the following format: [31 bit signed int] 0// Smi stands for small integer.class Smi: public Object { public: // Returns the integer value. inline int value(); // Convert a value to a Smi object. static inline Smi* FromInt(int value); // Returns whether value can be represented in a Smi. static inline bool IsValid(int value); // Casting. static inline Smi* cast(Object* object); // Dispatched behavior. void SmiPrint(); void SmiPrint(StringStream* accumulator);#ifdef DEBUG void SmiVerify();#endif // Min and max limits for Smi values. static const int kMinValue = -(1 << (kBitsPerPointer - (kSmiTagSize + 1))); static const int kMaxValue = (1 << (kBitsPerPointer - (kSmiTagSize + 1))) - 1; private: DISALLOW_IMPLICIT_CONSTRUCTORS(Smi);};// Failure is used for reporing out of memory situations and// propagating exceptions through the runtime system. Failure objects// are transient and cannot occur as part of the objects graph.//// Failures are a single word, encoded as follows:// +-------------------------+---+--+--+// |rrrrrrrrrrrrrrrrrrrrrrrrr|sss|tt|11|// +-------------------------+---+--+--+//// The low two bits, 0-1, are the failure tag, 11. The next two bits,// 2-3, are a failure type tag 'tt' with possible values:// 00 RETRY_AFTER_GC// 01 EXCEPTION// 10 INTERNAL_ERROR// 11 OUT_OF_MEMORY_EXCEPTION//// The next three bits, 4-6, are an allocation space tag 'sss'. The// allocation space tag is 000 for all failure types except// RETRY_AFTER_GC. For RETRY_AFTER_GC, the possible values are// (the encoding is found in globals.h):// 000 NEW_SPACE// 001 OLD_SPACE// 010 CODE_SPACE// 011 MAP_SPACE// 100 LO_SPACE//// The remaining bits is the number of words requested by the// allocation request that failed, and is zeroed except for// RETRY_AFTER_GC failures. The 25 bits (on a 32 bit platform) gives// a representable range of 2^27 bytes (128MB).// Failure type tag info.const int kFailureTypeTagSize = 2;const int kFailureTypeTagMask = (1 << kFailureTypeTagSize) - 1;class Failure: public Object { public: // RuntimeStubs assumes EXCEPTION = 1 in the compiler-generated code. enum Type { RETRY_AFTER_GC = 0, EXCEPTION = 1, // Returning this marker tells the real exception // is in Top::pending_exception. INTERNAL_ERROR = 2, OUT_OF_MEMORY_EXCEPTION = 3 }; inline Type type() const; // Returns the space that needs to be collected for RetryAfterGC failures. inline AllocationSpace allocation_space() const; // Returns the number of bytes requested (up to the representable maximum) // for RetryAfterGC failures. inline int requested() const; inline bool IsInternalError() const; inline bool IsOutOfMemoryException() const; static Failure* RetryAfterGC(int requested_bytes, AllocationSpace space); static inline Failure* Exception(); static inline Failure* InternalError(); static inline Failure* OutOfMemoryException(); // Casting. static inline Failure* cast(Object* object); // Dispatched behavior. void FailurePrint(); void FailurePrint(StringStream* accumulator);#ifdef DEBUG void FailureVerify();#endif private: inline int value() const; static inline Failure* Construct(Type type, int value = 0); DISALLOW_IMPLICIT_CONSTRUCTORS(Failure);};// Heap objects typically have a map pointer in their first word. However,// during GC other data (eg, mark bits, forwarding addresses) is sometimes// encoded in the first word. The class MapWord is an abstraction of the// value in a heap object's first word.class MapWord BASE_EMBEDDED { public: // Normal state: the map word contains a map pointer. // Create a map word from a map pointer. static inline MapWord FromMap(Map* map); // View this map word as a map pointer. inline Map* ToMap(); // Scavenge collection: the map word of live objects in the from space // contains a forwarding address (a heap object pointer in the to space). // True if this map word is a forwarding address for a scavenge // collection. Only valid during a scavenge collection (specifically, // when all map words are heap object pointers, ie. not during a full GC). inline bool IsForwardingAddress(); // Create a map word from a forwarding address. static inline MapWord FromForwardingAddress(HeapObject* object); // View this map word as a forwarding address. inline HeapObject* ToForwardingAddress(); // Marking phase of full collection: the map word of live objects is // marked, and may be marked as overflowed (eg, the object is live, its // children have not been visited, and it does not fit in the marking // stack). // True if this map word's mark bit is set. inline bool IsMarked(); // Return this map word but with its mark bit set. inline void SetMark(); // Return this map word but with its mark bit cleared. inline void ClearMark(); // True if this map word's overflow bit is set. inline bool IsOverflowed(); // Return this map word but with its overflow bit set. inline void SetOverflow(); // Return this map word but with its overflow bit cleared. inline void ClearOverflow(); // Compacting phase of a full compacting collection: the map word of live // objects contains an encoding of the original map address along with the // forwarding address (represented as an offset from the first live object // in the same page as the (old) object address). // Create a map word from a map address and a forwarding address offset. static inline MapWord EncodeAddress(Address map_address, int offset); // Return the map address encoded in this map word. inline Address DecodeMapAddress(MapSpace* map_space); // Return the forwarding offset encoded in this map word. inline int DecodeOffset(); // During serialization: the map word is used to hold an encoded // address, and possibly a mark bit (set and cleared with SetMark // and ClearMark). // Create a map word from an encoded address. static inline MapWord FromEncodedAddress(Address address); inline Address ToEncodedAddress(); private: // HeapObject calls the private constructor and directly reads the value. friend class HeapObject; explicit MapWord(uintptr_t value) : value_(value) {} uintptr_t value_; // Bits used by the marking phase of the garbage collector. // // The first word of a heap object is normall a map pointer. The last two // bits are tagged as '01' (kHeapObjectTag). We reuse the last two bits to // mark an object as live and/or overflowed: // last bit = 0, marked as alive // second bit = 1, overflowed // An object is only marked as overflowed when it is marked as live while // the marking stack is overflowed. static const int kMarkingBit = 0; // marking bit static const int kMarkingMask = (1 << kMarkingBit); // marking mask static const int kOverflowBit = 1; // overflow bit static const int kOverflowMask = (1 << kOverflowBit); // overflow mask // Forwarding pointers and map pointer encoding // 31 21 20 10 9 0 // +-----------------+------------------+-----------------+ // |forwarding offset|page offset of map|page index of map| // +-----------------+------------------+-----------------+ // 11 bits 11 bits 10 bits static const int kMapPageIndexBits = 10; static const int kMapPageOffsetBits = 11; static const int kForwardingOffsetBits = 11; static const int kMapPageIndexShift = 0; static const int kMapPageOffsetShift = kMapPageIndexShift + kMapPageIndexBits; static const int kForwardingOffsetShift = kMapPageOffsetShift + kMapPageOffsetBits; // 0x000003FF static const uint32_t kMapPageIndexMask = (1 << kMapPageOffsetShift) - 1; // 0x001FFC00 static const uint32_t kMapPageOffsetMask = ((1 << kForwardingOffsetShift) - 1) & ~kMapPageIndexMask; // 0xFFE00000 static const uint32_t kForwardingOffsetMask = ~(kMapPageIndexMask | kMapPageOffsetMask);};// HeapObject is the superclass for all classes describing heap allocated// objects.class HeapObject: public Object { public: // [map]: Contains a map which contains the object's reflective // information. inline Map* map(); inline void set_map(Map* value); // During garbage collection, the map word of a heap object does not // necessarily contain a map pointer. inline MapWord map_word(); inline void set_map_word(MapWord map_word); // Converts an address to a HeapObject pointer. static inline HeapObject* FromAddress(Address address); // Returns the address of this HeapObject. inline Address address(); // Iterates over pointers contained in the object (including the Map) void Iterate(ObjectVisitor* v); // Iterates over all pointers contained in the object except the // first map pointer. The object type is given in the first // parameter. This function does not access the map pointer in the // object, and so is safe to call while the map pointer is modified. void IterateBody(InstanceType type, int object_size, ObjectVisitor* v); // This method only applies to struct objects. Iterates over all the fields // of this struct. void IterateStructBody(int object_size, ObjectVisitor* v); // Copy the body from the 'from' object to this. // Please note the two object must have the same map prior to the call. inline void CopyBody(JSObject* from); // Returns the heap object's size in bytes inline int Size(); // Given a heap object's map pointer, returns the heap size in bytes
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -