| 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_BASE_LOGGING_H_ | 5 #ifndef V8_BASE_LOGGING_H_ |
| 6 #define V8_BASE_LOGGING_H_ | 6 #define V8_BASE_LOGGING_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <string.h> | 9 #include <string.h> |
| 10 | 10 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #define FATAL(msg) \ | 26 #define FATAL(msg) \ |
| 27 V8_Fatal("", 0, "%s", (msg)) | 27 V8_Fatal("", 0, "%s", (msg)) |
| 28 #define UNIMPLEMENTED() \ | 28 #define UNIMPLEMENTED() \ |
| 29 V8_Fatal("", 0, "unimplemented code") | 29 V8_Fatal("", 0, "unimplemented code") |
| 30 #define UNREACHABLE() ((void) 0) | 30 #define UNREACHABLE() ((void) 0) |
| 31 #endif | 31 #endif |
| 32 | 32 |
| 33 | 33 |
| 34 // The CHECK macro checks that the given condition is true; if not, it | 34 // The CHECK macro checks that the given condition is true; if not, it |
| 35 // prints a message to stderr and aborts. | 35 // prints a message to stderr and aborts. |
| 36 #define CHECK(condition) do { \ | 36 #define CHECK(condition) \ |
| 37 if (!(condition)) { \ | 37 do { \ |
| 38 if (V8_UNLIKELY(!(condition))) { \ |
| 38 V8_Fatal(__FILE__, __LINE__, "CHECK(%s) failed", #condition); \ | 39 V8_Fatal(__FILE__, __LINE__, "CHECK(%s) failed", #condition); \ |
| 39 } \ | 40 } \ |
| 40 } while (0) | 41 } while (0) |
| 41 | 42 |
| 42 | 43 |
| 43 // Helper function used by the CHECK_EQ function when given int | 44 // Helper function used by the CHECK_EQ function when given int |
| 44 // arguments. Should not be called directly. | 45 // arguments. Should not be called directly. |
| 45 inline void CheckEqualsHelper(const char* file, int line, | 46 inline void CheckEqualsHelper(const char* file, int line, |
| 46 const char* expected_source, int expected, | 47 const char* expected_source, int expected, |
| 47 const char* value_source, int value) { | 48 const char* value_source, int value) { |
| 48 if (expected != value) { | 49 if (V8_UNLIKELY(expected != value)) { |
| 49 V8_Fatal(file, line, | 50 V8_Fatal(file, line, |
| 50 "CHECK_EQ(%s, %s) failed\n# Expected: %i\n# Found: %i", | 51 "CHECK_EQ(%s, %s) failed\n# Expected: %i\n# Found: %i", |
| 51 expected_source, value_source, expected, value); | 52 expected_source, value_source, expected, value); |
| 52 } | 53 } |
| 53 } | 54 } |
| 54 | 55 |
| 55 | 56 |
| 56 // Helper function used by the CHECK_EQ function when given int64_t | 57 // Helper function used by the CHECK_EQ function when given int64_t |
| 57 // arguments. Should not be called directly. | 58 // arguments. Should not be called directly. |
| 58 inline void CheckEqualsHelper(const char* file, int line, | 59 inline void CheckEqualsHelper(const char* file, int line, |
| 59 const char* expected_source, | 60 const char* expected_source, |
| 60 int64_t expected, | 61 int64_t expected, |
| 61 const char* value_source, | 62 const char* value_source, |
| 62 int64_t value) { | 63 int64_t value) { |
| 63 if (expected != value) { | 64 if (V8_UNLIKELY(expected != value)) { |
| 64 // Print int64_t values in hex, as two int32s, | 65 // Print int64_t values in hex, as two int32s, |
| 65 // to avoid platform-dependencies. | 66 // to avoid platform-dependencies. |
| 66 V8_Fatal(file, line, | 67 V8_Fatal(file, line, |
| 67 "CHECK_EQ(%s, %s) failed\n#" | 68 "CHECK_EQ(%s, %s) failed\n#" |
| 68 " Expected: 0x%08x%08x\n# Found: 0x%08x%08x", | 69 " Expected: 0x%08x%08x\n# Found: 0x%08x%08x", |
| 69 expected_source, value_source, | 70 expected_source, value_source, |
| 70 static_cast<uint32_t>(expected >> 32), | 71 static_cast<uint32_t>(expected >> 32), |
| 71 static_cast<uint32_t>(expected), | 72 static_cast<uint32_t>(expected), |
| 72 static_cast<uint32_t>(value >> 32), | 73 static_cast<uint32_t>(value >> 32), |
| 73 static_cast<uint32_t>(value)); | 74 static_cast<uint32_t>(value)); |
| 74 } | 75 } |
| 75 } | 76 } |
| 76 | 77 |
| 77 | 78 |
| 78 // Helper function used by the CHECK_NE function when given int | 79 // Helper function used by the CHECK_NE function when given int |
| 79 // arguments. Should not be called directly. | 80 // arguments. Should not be called directly. |
| 80 inline void CheckNonEqualsHelper(const char* file, | 81 inline void CheckNonEqualsHelper(const char* file, |
| 81 int line, | 82 int line, |
| 82 const char* unexpected_source, | 83 const char* unexpected_source, |
| 83 int unexpected, | 84 int unexpected, |
| 84 const char* value_source, | 85 const char* value_source, |
| 85 int value) { | 86 int value) { |
| 86 if (unexpected == value) { | 87 if (V8_UNLIKELY(unexpected == value)) { |
| 87 V8_Fatal(file, line, "CHECK_NE(%s, %s) failed\n# Value: %i", | 88 V8_Fatal(file, line, "CHECK_NE(%s, %s) failed\n# Value: %i", |
| 88 unexpected_source, value_source, value); | 89 unexpected_source, value_source, value); |
| 89 } | 90 } |
| 90 } | 91 } |
| 91 | 92 |
| 92 | 93 |
| 93 // Helper function used by the CHECK function when given string | 94 // Helper function used by the CHECK function when given string |
| 94 // arguments. Should not be called directly. | 95 // arguments. Should not be called directly. |
| 95 inline void CheckEqualsHelper(const char* file, | 96 inline void CheckEqualsHelper(const char* file, |
| 96 int line, | 97 int line, |
| 97 const char* expected_source, | 98 const char* expected_source, |
| 98 const char* expected, | 99 const char* expected, |
| 99 const char* value_source, | 100 const char* value_source, |
| 100 const char* value) { | 101 const char* value) { |
| 101 if ((expected == NULL && value != NULL) || | 102 if (V8_UNLIKELY((expected == NULL && value != NULL) || |
| 102 (expected != NULL && value == NULL) || | 103 (expected != NULL && value == NULL) || |
| 103 (expected != NULL && value != NULL && strcmp(expected, value) != 0)) { | 104 (expected != NULL && value != NULL && |
| 105 strcmp(expected, value) != 0))) { |
| 104 V8_Fatal(file, line, | 106 V8_Fatal(file, line, |
| 105 "CHECK_EQ(%s, %s) failed\n# Expected: %s\n# Found: %s", | 107 "CHECK_EQ(%s, %s) failed\n# Expected: %s\n# Found: %s", |
| 106 expected_source, value_source, expected, value); | 108 expected_source, value_source, expected, value); |
| 107 } | 109 } |
| 108 } | 110 } |
| 109 | 111 |
| 110 | 112 |
| 111 inline void CheckNonEqualsHelper(const char* file, | 113 inline void CheckNonEqualsHelper(const char* file, |
| 112 int line, | 114 int line, |
| 113 const char* expected_source, | 115 const char* expected_source, |
| 114 const char* expected, | 116 const char* expected, |
| 115 const char* value_source, | 117 const char* value_source, |
| 116 const char* value) { | 118 const char* value) { |
| 117 if (expected == value || | 119 if (V8_UNLIKELY(expected == value || (expected != NULL && value != NULL && |
| 118 (expected != NULL && value != NULL && strcmp(expected, value) == 0)) { | 120 strcmp(expected, value) == 0))) { |
| 119 V8_Fatal(file, line, "CHECK_NE(%s, %s) failed\n# Value: %s", | 121 V8_Fatal(file, line, "CHECK_NE(%s, %s) failed\n# Value: %s", |
| 120 expected_source, value_source, value); | 122 expected_source, value_source, value); |
| 121 } | 123 } |
| 122 } | 124 } |
| 123 | 125 |
| 124 | 126 |
| 125 // Helper function used by the CHECK function when given pointer | 127 // Helper function used by the CHECK function when given pointer |
| 126 // arguments. Should not be called directly. | 128 // arguments. Should not be called directly. |
| 127 inline void CheckEqualsHelper(const char* file, | 129 inline void CheckEqualsHelper(const char* file, |
| 128 int line, | 130 int line, |
| 129 const char* expected_source, | 131 const char* expected_source, |
| 130 const void* expected, | 132 const void* expected, |
| 131 const char* value_source, | 133 const char* value_source, |
| 132 const void* value) { | 134 const void* value) { |
| 133 if (expected != value) { | 135 if (V8_UNLIKELY(expected != value)) { |
| 134 V8_Fatal(file, line, | 136 V8_Fatal(file, line, |
| 135 "CHECK_EQ(%s, %s) failed\n# Expected: %p\n# Found: %p", | 137 "CHECK_EQ(%s, %s) failed\n# Expected: %p\n# Found: %p", |
| 136 expected_source, value_source, | 138 expected_source, value_source, |
| 137 expected, value); | 139 expected, value); |
| 138 } | 140 } |
| 139 } | 141 } |
| 140 | 142 |
| 141 | 143 |
| 142 inline void CheckNonEqualsHelper(const char* file, | 144 inline void CheckNonEqualsHelper(const char* file, |
| 143 int line, | 145 int line, |
| 144 const char* expected_source, | 146 const char* expected_source, |
| 145 const void* expected, | 147 const void* expected, |
| 146 const char* value_source, | 148 const char* value_source, |
| 147 const void* value) { | 149 const void* value) { |
| 148 if (expected == value) { | 150 if (V8_UNLIKELY(expected == value)) { |
| 149 V8_Fatal(file, line, "CHECK_NE(%s, %s) failed\n# Value: %p", | 151 V8_Fatal(file, line, "CHECK_NE(%s, %s) failed\n# Value: %p", |
| 150 expected_source, value_source, value); | 152 expected_source, value_source, value); |
| 151 } | 153 } |
| 152 } | 154 } |
| 153 | 155 |
| 154 | 156 |
| 155 inline void CheckNonEqualsHelper(const char* file, | 157 inline void CheckNonEqualsHelper(const char* file, |
| 156 int line, | 158 int line, |
| 157 const char* expected_source, | 159 const char* expected_source, |
| 158 int64_t expected, | 160 int64_t expected, |
| 159 const char* value_source, | 161 const char* value_source, |
| 160 int64_t value) { | 162 int64_t value) { |
| 161 if (expected == value) { | 163 if (V8_UNLIKELY(expected == value)) { |
| 162 V8_Fatal(file, line, | 164 V8_Fatal(file, line, |
| 163 "CHECK_EQ(%s, %s) failed\n# Expected: %f\n# Found: %f", | 165 "CHECK_EQ(%s, %s) failed\n# Expected: %f\n# Found: %f", |
| 164 expected_source, value_source, expected, value); | 166 expected_source, value_source, expected, value); |
| 165 } | 167 } |
| 166 } | 168 } |
| 167 | 169 |
| 168 | 170 |
| 169 #define CHECK_EQ(expected, value) CheckEqualsHelper(__FILE__, __LINE__, \ | 171 #define CHECK_EQ(expected, value) CheckEqualsHelper(__FILE__, __LINE__, \ |
| 170 #expected, expected, #value, value) | 172 #expected, expected, #value, value) |
| 171 | 173 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 | 216 |
| 215 // "Extra checks" are lightweight checks that are enabled in some release | 217 // "Extra checks" are lightweight checks that are enabled in some release |
| 216 // builds. | 218 // builds. |
| 217 #ifdef ENABLE_EXTRA_CHECKS | 219 #ifdef ENABLE_EXTRA_CHECKS |
| 218 #define EXTRA_CHECK(condition) CHECK(condition) | 220 #define EXTRA_CHECK(condition) CHECK(condition) |
| 219 #else | 221 #else |
| 220 #define EXTRA_CHECK(condition) ((void) 0) | 222 #define EXTRA_CHECK(condition) ((void) 0) |
| 221 #endif | 223 #endif |
| 222 | 224 |
| 223 #endif // V8_BASE_LOGGING_H_ | 225 #endif // V8_BASE_LOGGING_H_ |
| OLD | NEW |