OLD | NEW |
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_UTILS_H_ | 5 #ifndef V8_UTILS_H_ |
6 #define V8_UTILS_H_ | 6 #define V8_UTILS_H_ |
7 | 7 |
8 #include <limits.h> | 8 #include <limits.h> |
9 #include <stdlib.h> | 9 #include <stdlib.h> |
10 #include <string.h> | 10 #include <string.h> |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 // Compare function to compare the object pointer value of two | 105 // Compare function to compare the object pointer value of two |
106 // handlified objects. The handles are passed as pointers to the | 106 // handlified objects. The handles are passed as pointers to the |
107 // handles. | 107 // handles. |
108 template<typename T> class Handle; // Forward declaration. | 108 template<typename T> class Handle; // Forward declaration. |
109 template <typename T> | 109 template <typename T> |
110 int HandleObjectPointerCompare(const Handle<T>* a, const Handle<T>* b) { | 110 int HandleObjectPointerCompare(const Handle<T>* a, const Handle<T>* b) { |
111 return Compare<T*>(*(*a), *(*b)); | 111 return Compare<T*>(*(*a), *(*b)); |
112 } | 112 } |
113 | 113 |
114 | 114 |
| 115 template <typename T, typename U> |
| 116 inline bool IsAligned(T value, U alignment) { |
| 117 return (value & (alignment - 1)) == 0; |
| 118 } |
| 119 |
| 120 |
115 // Returns true if (addr + offset) is aligned. | 121 // Returns true if (addr + offset) is aligned. |
116 inline bool IsAddressAligned(Address addr, | 122 inline bool IsAddressAligned(Address addr, |
117 intptr_t alignment, | 123 intptr_t alignment, |
118 int offset = 0) { | 124 int offset = 0) { |
119 intptr_t offs = OffsetFrom(addr + offset); | 125 intptr_t offs = OffsetFrom(addr + offset); |
120 return IsAligned(offs, alignment); | 126 return IsAligned(offs, alignment); |
121 } | 127 } |
122 | 128 |
123 | 129 |
124 // Returns the maximum of the two parameters. | 130 // Returns the maximum of the two parameters. |
(...skipping 1404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1529 // Check that the new result is below the 32 bit limit. | 1535 // Check that the new result is below the 32 bit limit. |
1530 if (result > 429496729U - ((d > 5) ? 1 : 0)) return false; | 1536 if (result > 429496729U - ((d > 5) ? 1 : 0)) return false; |
1531 result = (result * 10) + d; | 1537 result = (result * 10) + d; |
1532 } | 1538 } |
1533 | 1539 |
1534 *index = result; | 1540 *index = result; |
1535 return true; | 1541 return true; |
1536 } | 1542 } |
1537 | 1543 |
1538 | 1544 |
1539 } } // namespace v8::internal | 1545 // Returns current value of top of the stack. Works correctly with ASAN. |
| 1546 DISABLE_ASAN |
| 1547 inline uintptr_t GetCurrentStackPosition() { |
| 1548 // Takes the address of the limit variable in order to find out where |
| 1549 // the top of stack is right now. |
| 1550 uintptr_t limit = reinterpret_cast<uintptr_t>(&limit); |
| 1551 return limit; |
| 1552 } |
| 1553 |
| 1554 } // namespace internal |
| 1555 } // namespace v8 |
1540 | 1556 |
1541 #endif // V8_UTILS_H_ | 1557 #endif // V8_UTILS_H_ |
OLD | NEW |