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

Side by Side Diff: src/objects.h

Issue 1422773007: Make JSFunction::BodyDescriptor the only single place that knows how to iterate JSFunction's body. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Addressing comments Created 5 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
« no previous file with comments | « src/heap/objects-visiting-inl.h ('k') | src/objects.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 #ifndef V8_OBJECTS_H_ 5 #ifndef V8_OBJECTS_H_
6 #define V8_OBJECTS_H_ 6 #define V8_OBJECTS_H_
7 7
8 #include <iosfwd> 8 #include <iosfwd>
9 9
10 #include "src/allocation.h" 10 #include "src/allocation.h"
(...skipping 1626 matching lines...) Expand 10 before | Expand all | Expand 10 after
1637 }; 1637 };
1638 1638
1639 1639
1640 // This is the base class for object's body descriptors. 1640 // This is the base class for object's body descriptors.
1641 class BodyDescriptorBase { 1641 class BodyDescriptorBase {
1642 protected: 1642 protected:
1643 static inline void IterateBodyImpl(HeapObject* obj, int start_offset, 1643 static inline void IterateBodyImpl(HeapObject* obj, int start_offset,
1644 int end_offset, ObjectVisitor* v); 1644 int end_offset, ObjectVisitor* v);
1645 1645
1646 template <typename StaticVisitor> 1646 template <typename StaticVisitor>
1647 static inline void IterateBodyImpl(HeapObject* obj, int start_offset, 1647 static inline void IterateBodyImpl(Heap* heap, HeapObject* obj,
1648 int end_offset); 1648 int start_offset, int end_offset);
1649
1650 static inline void IteratePointers(HeapObject* obj, int start_offset,
1651 int end_offset, ObjectVisitor* v);
1652
1653 template <typename StaticVisitor>
1654 static inline void IteratePointers(Heap* heap, HeapObject* obj,
1655 int start_offset, int end_offset);
1649 }; 1656 };
1650 1657
1651 1658
1652 // This class describes a body of an object of a fixed size 1659 // This class describes a body of an object of a fixed size
1653 // in which all pointer fields are located in the [start_offset, end_offset) 1660 // in which all pointer fields are located in the [start_offset, end_offset)
1654 // interval. 1661 // interval.
1655 template <int start_offset, int end_offset, int size> 1662 template <int start_offset, int end_offset, int size>
1656 class FixedBodyDescriptor : public BodyDescriptorBase { 1663 class FixedBodyDescriptor : public BodyDescriptorBase {
1657 public: 1664 public:
1658 static const int kStartOffset = start_offset; 1665 static const int kStartOffset = start_offset;
1659 static const int kEndOffset = end_offset; 1666 static const int kEndOffset = end_offset;
1660 static const int kSize = size; 1667 static const int kSize = size;
1661 1668
1662 static inline void IterateBody(HeapObject* obj, ObjectVisitor* v) { 1669 static inline void IterateBody(HeapObject* obj, ObjectVisitor* v) {
1663 IterateBodyImpl(obj, start_offset, end_offset, v); 1670 IterateBodyImpl(obj, start_offset, end_offset, v);
1664 } 1671 }
1665 1672
1666 template <typename StaticVisitor> 1673 template <typename StaticVisitor>
1667 static inline void IterateBody(HeapObject* obj) { 1674 static inline void IterateBody(HeapObject* obj) {
1668 IterateBodyImpl<StaticVisitor>(obj, start_offset, end_offset); 1675 Heap* heap = obj->GetHeap();
1676 IterateBodyImpl<StaticVisitor>(heap, obj, start_offset, end_offset);
1669 } 1677 }
1670 }; 1678 };
1671 1679
1672 1680
1673 // This base class describes a body of an object of a variable size 1681 // This base class describes a body of an object of a variable size
1674 // in which all pointer fields are located in the [start_offset, object_size) 1682 // in which all pointer fields are located in the [start_offset, object_size)
1675 // interval. 1683 // interval.
1676 template <int start_offset> 1684 template <int start_offset>
1677 class FlexibleBodyDescriptorBase : public BodyDescriptorBase { 1685 class FlexibleBodyDescriptorBase : public BodyDescriptorBase {
1678 public: 1686 public:
1679 static const int kStartOffset = start_offset; 1687 static const int kStartOffset = start_offset;
1680 1688
1681 static inline void IterateBody(HeapObject* obj, int object_size, 1689 static inline void IterateBody(HeapObject* obj, int object_size,
1682 ObjectVisitor* v) { 1690 ObjectVisitor* v) {
1683 IterateBodyImpl(obj, start_offset, object_size, v); 1691 IterateBodyImpl(obj, start_offset, object_size, v);
1684 } 1692 }
1685 1693
1686 template <typename StaticVisitor> 1694 template <typename StaticVisitor>
1687 static inline void IterateBody(HeapObject* obj, int object_size) { 1695 static inline void IterateBody(HeapObject* obj, int object_size) {
1688 IterateBodyImpl<StaticVisitor>(obj, start_offset, object_size); 1696 Heap* heap = obj->GetHeap();
1697 IterateBodyImpl<StaticVisitor>(heap, obj, start_offset, object_size);
1689 } 1698 }
1690 }; 1699 };
1691 1700
1692 1701
1693 // This class describes a body of an object of a variable size 1702 // This class describes a body of an object of a variable size
1694 // in which all pointer fields are located in the [start_offset, object_size) 1703 // in which all pointer fields are located in the [start_offset, object_size)
1695 // interval. The size of the object is taken from the map. 1704 // interval. The size of the object is taken from the map.
1696 template <int start_offset> 1705 template <int start_offset>
1697 class FlexibleBodyDescriptor : public FlexibleBodyDescriptorBase<start_offset> { 1706 class FlexibleBodyDescriptor : public FlexibleBodyDescriptorBase<start_offset> {
1698 public: 1707 public:
(...skipping 5693 matching lines...) Expand 10 before | Expand all | Expand 10 after
7392 7401
7393 // Calculate the instance size and in-object properties count. 7402 // Calculate the instance size and in-object properties count.
7394 void CalculateInstanceSize(InstanceType instance_type, 7403 void CalculateInstanceSize(InstanceType instance_type,
7395 int requested_internal_fields, int* instance_size, 7404 int requested_internal_fields, int* instance_size,
7396 int* in_object_properties); 7405 int* in_object_properties);
7397 void CalculateInstanceSizeForDerivedClass(InstanceType instance_type, 7406 void CalculateInstanceSizeForDerivedClass(InstanceType instance_type,
7398 int requested_internal_fields, 7407 int requested_internal_fields,
7399 int* instance_size, 7408 int* instance_size,
7400 int* in_object_properties); 7409 int* in_object_properties);
7401 7410
7402 // Iterates the objects, including code objects indirectly referenced 7411 // Visiting policy flags define whether the code entry or next function
7403 // through pointers to the first instruction in the code object. 7412 // should be visited or not.
7404 void JSFunctionIterateBody(int object_size, ObjectVisitor* v); 7413 enum BodyVisitingPolicy {
7414 kVisitCodeEntry = 1 << 0,
7415 kVisitNextFunction = 1 << 1,
7416
7417 kSkipCodeEntryAndNextFunction = 0,
7418 kVisitCodeEntryAndNextFunction = kVisitCodeEntry | kVisitNextFunction
7419 };
7420 // Iterates the function object according to the visiting policy.
7421 template <BodyVisitingPolicy>
7422 class BodyDescriptorImpl;
7423
7424 // Visit the whole object.
7425 typedef BodyDescriptorImpl<kVisitCodeEntryAndNextFunction> BodyDescriptor;
7426
7427 // Don't visit next function.
7428 typedef BodyDescriptorImpl<kVisitCodeEntry> BodyDescriptorStrongCode;
7429 typedef BodyDescriptorImpl<kSkipCodeEntryAndNextFunction>
7430 BodyDescriptorWeakCode;
7405 7431
7406 // Dispatched behavior. 7432 // Dispatched behavior.
7407 DECLARE_PRINTER(JSFunction) 7433 DECLARE_PRINTER(JSFunction)
7408 DECLARE_VERIFIER(JSFunction) 7434 DECLARE_VERIFIER(JSFunction)
7409 7435
7410 // Returns the number of allocated literals. 7436 // Returns the number of allocated literals.
7411 inline int NumberOfLiterals(); 7437 inline int NumberOfLiterals();
7412 7438
7413 // Used for flags such as --hydrogen-filter. 7439 // Used for flags such as --hydrogen-filter.
7414 bool PassesFilter(const char* raw_filter); 7440 bool PassesFilter(const char* raw_filter);
7415 7441
7416 // The function's name if it is configured, otherwise shared function info 7442 // The function's name if it is configured, otherwise shared function info
7417 // debug name. 7443 // debug name.
7418 static Handle<String> GetDebugName(Handle<JSFunction> function); 7444 static Handle<String> GetDebugName(Handle<JSFunction> function);
7419 7445
7420 // Layout descriptors. The last property (from kNonWeakFieldsEndOffset to 7446 // Layout descriptors. The last property (from kNonWeakFieldsEndOffset to
7421 // kSize) is weak and has special handling during garbage collection. 7447 // kSize) is weak and has special handling during garbage collection.
7422 static const int kCodeEntryOffset = JSObject::kHeaderSize; 7448 static const int kPrototypeOrInitialMapOffset = JSObject::kHeaderSize;
7423 static const int kPrototypeOrInitialMapOffset =
7424 kCodeEntryOffset + kPointerSize;
7425 static const int kSharedFunctionInfoOffset = 7449 static const int kSharedFunctionInfoOffset =
7426 kPrototypeOrInitialMapOffset + kPointerSize; 7450 kPrototypeOrInitialMapOffset + kPointerSize;
7427 static const int kContextOffset = kSharedFunctionInfoOffset + kPointerSize; 7451 static const int kContextOffset = kSharedFunctionInfoOffset + kPointerSize;
7428 static const int kLiteralsOffset = kContextOffset + kPointerSize; 7452 static const int kLiteralsOffset = kContextOffset + kPointerSize;
7429 static const int kNonWeakFieldsEndOffset = kLiteralsOffset + kPointerSize; 7453 static const int kNonWeakFieldsEndOffset = kLiteralsOffset + kPointerSize;
7430 static const int kNextFunctionLinkOffset = kNonWeakFieldsEndOffset; 7454 static const int kCodeEntryOffset = kNonWeakFieldsEndOffset;
7455 static const int kNextFunctionLinkOffset = kCodeEntryOffset + kPointerSize;
7431 static const int kSize = kNextFunctionLinkOffset + kPointerSize; 7456 static const int kSize = kNextFunctionLinkOffset + kPointerSize;
7432 7457
7433 private: 7458 private:
7434 DISALLOW_IMPLICIT_CONSTRUCTORS(JSFunction); 7459 DISALLOW_IMPLICIT_CONSTRUCTORS(JSFunction);
7435 }; 7460 };
7436 7461
7437 7462
7438 // JSGlobalProxy's prototype must be a JSGlobalObject or null, 7463 // JSGlobalProxy's prototype must be a JSGlobalObject or null,
7439 // and the prototype is hidden. JSGlobalProxy always delegates 7464 // and the prototype is hidden. JSGlobalProxy always delegates
7440 // property accesses to its prototype if the prototype is not null. 7465 // property accesses to its prototype if the prototype is not null.
(...skipping 3310 matching lines...) Expand 10 before | Expand all | Expand 10 after
10751 } 10776 }
10752 return value; 10777 return value;
10753 } 10778 }
10754 }; 10779 };
10755 10780
10756 10781
10757 } // NOLINT, false-positive due to second-order macros. 10782 } // NOLINT, false-positive due to second-order macros.
10758 } // NOLINT, false-positive due to second-order macros. 10783 } // NOLINT, false-positive due to second-order macros.
10759 10784
10760 #endif // V8_OBJECTS_H_ 10785 #endif // V8_OBJECTS_H_
OLDNEW
« no previous file with comments | « src/heap/objects-visiting-inl.h ('k') | src/objects.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698