OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 14 matching lines...) Expand all Loading... |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 #ifndef V8_UTILS_H_ | 28 #ifndef V8_UTILS_H_ |
29 #define V8_UTILS_H_ | 29 #define V8_UTILS_H_ |
30 | 30 |
31 #include <stdlib.h> | 31 #include <stdlib.h> |
32 #include <string.h> | 32 #include <string.h> |
33 #include <climits> | 33 #include <climits> |
34 | 34 |
| 35 #include "allocation.h" |
| 36 #include "checks.h" |
35 #include "globals.h" | 37 #include "globals.h" |
36 #include "checks.h" | |
37 #include "allocation.h" | |
38 | 38 |
39 namespace v8 { | 39 namespace v8 { |
40 namespace internal { | 40 namespace internal { |
41 | 41 |
42 // ---------------------------------------------------------------------------- | 42 // ---------------------------------------------------------------------------- |
43 // General helper functions | 43 // General helper functions |
44 | 44 |
45 #define IS_POWER_OF_TWO(x) (((x) & ((x) - 1)) == 0) | 45 #define IS_POWER_OF_TWO(x) (((x) & ((x) - 1)) == 0) |
46 | 46 |
47 // Returns true iff x is a power of 2 (or zero). Cannot be used with the | 47 // Returns true iff x is a power of 2 (or zero). Cannot be used with the |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 | 487 |
488 explicit EmbeddedVector(T initial_value) : Vector<T>(buffer_, kSize) { | 488 explicit EmbeddedVector(T initial_value) : Vector<T>(buffer_, kSize) { |
489 for (int i = 0; i < kSize; ++i) { | 489 for (int i = 0; i < kSize; ++i) { |
490 buffer_[i] = initial_value; | 490 buffer_[i] = initial_value; |
491 } | 491 } |
492 } | 492 } |
493 | 493 |
494 // When copying, make underlying Vector to reference our buffer. | 494 // When copying, make underlying Vector to reference our buffer. |
495 EmbeddedVector(const EmbeddedVector& rhs) | 495 EmbeddedVector(const EmbeddedVector& rhs) |
496 : Vector<T>(rhs) { | 496 : Vector<T>(rhs) { |
| 497 // TODO(jkummerow): Refactor #includes and use OS::MemCopy() instead. |
497 memcpy(buffer_, rhs.buffer_, sizeof(T) * kSize); | 498 memcpy(buffer_, rhs.buffer_, sizeof(T) * kSize); |
498 set_start(buffer_); | 499 set_start(buffer_); |
499 } | 500 } |
500 | 501 |
501 EmbeddedVector& operator=(const EmbeddedVector& rhs) { | 502 EmbeddedVector& operator=(const EmbeddedVector& rhs) { |
502 if (this == &rhs) return *this; | 503 if (this == &rhs) return *this; |
503 Vector<T>::operator=(rhs); | 504 Vector<T>::operator=(rhs); |
| 505 // TODO(jkummerow): Refactor #includes and use OS::MemCopy() instead. |
504 memcpy(buffer_, rhs.buffer_, sizeof(T) * kSize); | 506 memcpy(buffer_, rhs.buffer_, sizeof(T) * kSize); |
505 this->set_start(buffer_); | 507 this->set_start(buffer_); |
506 return *this; | 508 return *this; |
507 } | 509 } |
508 | 510 |
509 private: | 511 private: |
510 T buffer_[kSize]; | 512 T buffer_[kSize]; |
511 }; | 513 }; |
512 | 514 |
513 | 515 |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 | 871 |
870 // We need different implementations of BitCast for pointer and non-pointer | 872 // We need different implementations of BitCast for pointer and non-pointer |
871 // values. We use partial specialization of auxiliary struct to work around | 873 // values. We use partial specialization of auxiliary struct to work around |
872 // issues with template functions overloading. | 874 // issues with template functions overloading. |
873 template <class Dest, class Source> | 875 template <class Dest, class Source> |
874 struct BitCastHelper { | 876 struct BitCastHelper { |
875 STATIC_ASSERT(sizeof(Dest) == sizeof(Source)); | 877 STATIC_ASSERT(sizeof(Dest) == sizeof(Source)); |
876 | 878 |
877 INLINE(static Dest cast(const Source& source)) { | 879 INLINE(static Dest cast(const Source& source)) { |
878 Dest dest; | 880 Dest dest; |
| 881 // TODO(jkummerow): Refactor #includes and use OS::MemCopy() instead. |
879 memcpy(&dest, &source, sizeof(dest)); | 882 memcpy(&dest, &source, sizeof(dest)); |
880 return dest; | 883 return dest; |
881 } | 884 } |
882 }; | 885 }; |
883 | 886 |
884 template <class Dest, class Source> | 887 template <class Dest, class Source> |
885 struct BitCastHelper<Dest, Source*> { | 888 struct BitCastHelper<Dest, Source*> { |
886 INLINE(static Dest cast(Source* source)) { | 889 INLINE(static Dest cast(Source* source)) { |
887 return BitCastHelper<Dest, uintptr_t>:: | 890 return BitCastHelper<Dest, uintptr_t>:: |
888 cast(reinterpret_cast<uintptr_t>(source)); | 891 cast(reinterpret_cast<uintptr_t>(source)); |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1080 | 1083 |
1081 // Every compiled stub starts with this id. | 1084 // Every compiled stub starts with this id. |
1082 static const int kStubEntryId = 5; | 1085 static const int kStubEntryId = 5; |
1083 | 1086 |
1084 int id_; | 1087 int id_; |
1085 }; | 1088 }; |
1086 | 1089 |
1087 } } // namespace v8::internal | 1090 } } // namespace v8::internal |
1088 | 1091 |
1089 #endif // V8_UTILS_H_ | 1092 #endif // V8_UTILS_H_ |
OLD | NEW |