| OLD | NEW |
| 1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 message_buffer_ = NULL; | 118 message_buffer_ = NULL; |
| 119 | 119 |
| 120 delete mutex_; | 120 delete mutex_; |
| 121 mutex_ = NULL; | 121 mutex_ = NULL; |
| 122 | 122 |
| 123 is_stopped_ = false; | 123 is_stopped_ = false; |
| 124 return result; | 124 return result; |
| 125 } | 125 } |
| 126 | 126 |
| 127 | 127 |
| 128 LogMessageBuilder::LogMessageBuilder(Logger* logger) | 128 Log::MessageBuilder::MessageBuilder(Log* log) |
| 129 : log_(logger->log_), | 129 : log_(log), |
| 130 sl(log_->mutex_), | 130 sl(log_->mutex_), |
| 131 pos_(0) { | 131 pos_(0) { |
| 132 ASSERT(log_->message_buffer_ != NULL); | 132 ASSERT(log_->message_buffer_ != NULL); |
| 133 } | 133 } |
| 134 | 134 |
| 135 | 135 |
| 136 void LogMessageBuilder::Append(const char* format, ...) { | 136 void Log::MessageBuilder::Append(const char* format, ...) { |
| 137 Vector<char> buf(log_->message_buffer_ + pos_, | 137 Vector<char> buf(log_->message_buffer_ + pos_, |
| 138 Log::kMessageBufferSize - pos_); | 138 Log::kMessageBufferSize - pos_); |
| 139 va_list args; | 139 va_list args; |
| 140 va_start(args, format); | 140 va_start(args, format); |
| 141 AppendVA(format, args); | 141 AppendVA(format, args); |
| 142 va_end(args); | 142 va_end(args); |
| 143 ASSERT(pos_ <= Log::kMessageBufferSize); | 143 ASSERT(pos_ <= Log::kMessageBufferSize); |
| 144 } | 144 } |
| 145 | 145 |
| 146 | 146 |
| 147 void LogMessageBuilder::AppendVA(const char* format, va_list args) { | 147 void Log::MessageBuilder::AppendVA(const char* format, va_list args) { |
| 148 Vector<char> buf(log_->message_buffer_ + pos_, | 148 Vector<char> buf(log_->message_buffer_ + pos_, |
| 149 Log::kMessageBufferSize - pos_); | 149 Log::kMessageBufferSize - pos_); |
| 150 int result = v8::internal::OS::VSNPrintF(buf, format, args); | 150 int result = v8::internal::OS::VSNPrintF(buf, format, args); |
| 151 | 151 |
| 152 // Result is -1 if output was truncated. | 152 // Result is -1 if output was truncated. |
| 153 if (result >= 0) { | 153 if (result >= 0) { |
| 154 pos_ += result; | 154 pos_ += result; |
| 155 } else { | 155 } else { |
| 156 pos_ = Log::kMessageBufferSize; | 156 pos_ = Log::kMessageBufferSize; |
| 157 } | 157 } |
| 158 ASSERT(pos_ <= Log::kMessageBufferSize); | 158 ASSERT(pos_ <= Log::kMessageBufferSize); |
| 159 } | 159 } |
| 160 | 160 |
| 161 | 161 |
| 162 void LogMessageBuilder::Append(const char c) { | 162 void Log::MessageBuilder::Append(const char c) { |
| 163 if (pos_ < Log::kMessageBufferSize) { | 163 if (pos_ < Log::kMessageBufferSize) { |
| 164 log_->message_buffer_[pos_++] = c; | 164 log_->message_buffer_[pos_++] = c; |
| 165 } | 165 } |
| 166 ASSERT(pos_ <= Log::kMessageBufferSize); | 166 ASSERT(pos_ <= Log::kMessageBufferSize); |
| 167 } | 167 } |
| 168 | 168 |
| 169 | 169 |
| 170 void LogMessageBuilder::AppendDoubleQuotedString(const char* string) { | 170 void Log::MessageBuilder::AppendDoubleQuotedString(const char* string) { |
| 171 Append('"'); | 171 Append('"'); |
| 172 for (const char* p = string; *p != '\0'; p++) { | 172 for (const char* p = string; *p != '\0'; p++) { |
| 173 if (*p == '"') { | 173 if (*p == '"') { |
| 174 Append('\\'); | 174 Append('\\'); |
| 175 } | 175 } |
| 176 Append(*p); | 176 Append(*p); |
| 177 } | 177 } |
| 178 Append('"'); | 178 Append('"'); |
| 179 } | 179 } |
| 180 | 180 |
| 181 | 181 |
| 182 void LogMessageBuilder::Append(String* str) { | 182 void Log::MessageBuilder::Append(String* str) { |
| 183 DisallowHeapAllocation no_gc; // Ensure string stay valid. | 183 DisallowHeapAllocation no_gc; // Ensure string stay valid. |
| 184 int length = str->length(); | 184 int length = str->length(); |
| 185 for (int i = 0; i < length; i++) { | 185 for (int i = 0; i < length; i++) { |
| 186 Append(static_cast<char>(str->Get(i))); | 186 Append(static_cast<char>(str->Get(i))); |
| 187 } | 187 } |
| 188 } | 188 } |
| 189 | 189 |
| 190 | 190 |
| 191 void LogMessageBuilder::AppendAddress(Address addr) { | 191 void Log::MessageBuilder::AppendAddress(Address addr) { |
| 192 Append("0x%" V8PRIxPTR, addr); | 192 Append("0x%" V8PRIxPTR, addr); |
| 193 } | 193 } |
| 194 | 194 |
| 195 | 195 |
| 196 void LogMessageBuilder::AppendDetailed(String* str, bool show_impl_info) { | 196 void Log::MessageBuilder::AppendSymbolName(Symbol* symbol) { |
| 197 ASSERT(symbol); |
| 198 Append("symbol("); |
| 199 if (!symbol->name()->IsUndefined()) { |
| 200 Append("\""); |
| 201 AppendDetailed(String::cast(symbol->name()), false); |
| 202 Append("\" "); |
| 203 } |
| 204 Append("hash %x)", symbol->Hash()); |
| 205 } |
| 206 |
| 207 |
| 208 void Log::MessageBuilder::AppendDetailed(String* str, bool show_impl_info) { |
| 197 if (str == NULL) return; | 209 if (str == NULL) return; |
| 198 DisallowHeapAllocation no_gc; // Ensure string stay valid. | 210 DisallowHeapAllocation no_gc; // Ensure string stay valid. |
| 199 int len = str->length(); | 211 int len = str->length(); |
| 200 if (len > 0x1000) | 212 if (len > 0x1000) |
| 201 len = 0x1000; | 213 len = 0x1000; |
| 202 if (show_impl_info) { | 214 if (show_impl_info) { |
| 203 Append(str->IsOneByteRepresentation() ? 'a' : '2'); | 215 Append(str->IsOneByteRepresentation() ? 'a' : '2'); |
| 204 if (StringShape(str).IsExternal()) | 216 if (StringShape(str).IsExternal()) |
| 205 Append('e'); | 217 Append('e'); |
| 206 if (StringShape(str).IsInternalized()) | 218 if (StringShape(str).IsInternalized()) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 219 Append("\\\\"); | 231 Append("\\\\"); |
| 220 } else if (c == '\"') { | 232 } else if (c == '\"') { |
| 221 Append("\"\""); | 233 Append("\"\""); |
| 222 } else { | 234 } else { |
| 223 Append("%lc", c); | 235 Append("%lc", c); |
| 224 } | 236 } |
| 225 } | 237 } |
| 226 } | 238 } |
| 227 | 239 |
| 228 | 240 |
| 229 void LogMessageBuilder::AppendStringPart(const char* str, int len) { | 241 void Log::MessageBuilder::AppendStringPart(const char* str, int len) { |
| 230 if (pos_ + len > Log::kMessageBufferSize) { | 242 if (pos_ + len > Log::kMessageBufferSize) { |
| 231 len = Log::kMessageBufferSize - pos_; | 243 len = Log::kMessageBufferSize - pos_; |
| 232 ASSERT(len >= 0); | 244 ASSERT(len >= 0); |
| 233 if (len == 0) return; | 245 if (len == 0) return; |
| 234 } | 246 } |
| 235 Vector<char> buf(log_->message_buffer_ + pos_, | 247 Vector<char> buf(log_->message_buffer_ + pos_, |
| 236 Log::kMessageBufferSize - pos_); | 248 Log::kMessageBufferSize - pos_); |
| 237 OS::StrNCpy(buf, str, len); | 249 OS::StrNCpy(buf, str, len); |
| 238 pos_ += len; | 250 pos_ += len; |
| 239 ASSERT(pos_ <= Log::kMessageBufferSize); | 251 ASSERT(pos_ <= Log::kMessageBufferSize); |
| 240 } | 252 } |
| 241 | 253 |
| 242 | 254 |
| 243 void LogMessageBuilder::WriteToLogFile() { | 255 void Log::MessageBuilder::WriteToLogFile() { |
| 244 ASSERT(pos_ <= Log::kMessageBufferSize); | 256 ASSERT(pos_ <= Log::kMessageBufferSize); |
| 245 const int written = log_->WriteToFile(log_->message_buffer_, pos_); | 257 const int written = log_->WriteToFile(log_->message_buffer_, pos_); |
| 246 if (written != pos_) { | 258 if (written != pos_) { |
| 247 log_->stop(); | 259 log_->stop(); |
| 248 log_->logger_->LogFailure(); | 260 log_->logger_->LogFailure(); |
| 249 } | 261 } |
| 250 } | 262 } |
| 251 | 263 |
| 252 | 264 |
| 253 } } // namespace v8::internal | 265 } } // namespace v8::internal |
| OLD | NEW |