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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 output_handle_ = OS::FOpen(name, OS::LogFileOpenMode); | 148 output_handle_ = OS::FOpen(name, OS::LogFileOpenMode); |
149 Write = WriteToFile; | 149 Write = WriteToFile; |
150 Init(); | 150 Init(); |
151 } | 151 } |
152 | 152 |
153 | 153 |
154 void Log::OpenMemoryBuffer() { | 154 void Log::OpenMemoryBuffer() { |
155 ASSERT(!IsEnabled()); | 155 ASSERT(!IsEnabled()); |
156 output_buffer_ = new LogDynamicBuffer( | 156 output_buffer_ = new LogDynamicBuffer( |
157 kDynamicBufferBlockSize, kMaxDynamicBufferSize, | 157 kDynamicBufferBlockSize, kMaxDynamicBufferSize, |
158 kDynamicBufferSeal, strlen(kDynamicBufferSeal)); | 158 kDynamicBufferSeal, StrLength(kDynamicBufferSeal)); |
159 Write = WriteToMemory; | 159 Write = WriteToMemory; |
160 Init(); | 160 Init(); |
161 } | 161 } |
162 | 162 |
163 | 163 |
164 void Log::Close() { | 164 void Log::Close() { |
165 if (Write == WriteToFile) { | 165 if (Write == WriteToFile) { |
166 if (output_handle_ != NULL) fclose(output_handle_); | 166 if (output_handle_ != NULL) fclose(output_handle_); |
167 output_handle_ = NULL; | 167 output_handle_ = NULL; |
168 } else if (Write == WriteToMemory) { | 168 } else if (Write == WriteToMemory) { |
(...skipping 19 matching lines...) Expand all Loading... |
188 ASSERT(output_buffer_ != NULL); | 188 ASSERT(output_buffer_ != NULL); |
189 ASSERT(from_pos >= 0); | 189 ASSERT(from_pos >= 0); |
190 ASSERT(max_size >= 0); | 190 ASSERT(max_size >= 0); |
191 int actual_size = output_buffer_->Read(from_pos, dest_buf, max_size); | 191 int actual_size = output_buffer_->Read(from_pos, dest_buf, max_size); |
192 ASSERT(actual_size <= max_size); | 192 ASSERT(actual_size <= max_size); |
193 if (actual_size == 0) return 0; | 193 if (actual_size == 0) return 0; |
194 | 194 |
195 // Find previous log line boundary. | 195 // Find previous log line boundary. |
196 char* end_pos = dest_buf + actual_size - 1; | 196 char* end_pos = dest_buf + actual_size - 1; |
197 while (end_pos >= dest_buf && *end_pos != '\n') --end_pos; | 197 while (end_pos >= dest_buf && *end_pos != '\n') --end_pos; |
198 actual_size = end_pos - dest_buf + 1; | 198 actual_size = static_cast<int>(end_pos - dest_buf + 1); |
199 ASSERT(actual_size <= max_size); | 199 ASSERT(actual_size <= max_size); |
200 return actual_size; | 200 return actual_size; |
201 } | 201 } |
202 | 202 |
203 | 203 |
204 LogMessageBuilder::WriteFailureHandler | 204 LogMessageBuilder::WriteFailureHandler |
205 LogMessageBuilder::write_failure_handler = NULL; | 205 LogMessageBuilder::write_failure_handler = NULL; |
206 | 206 |
207 | 207 |
208 LogMessageBuilder::LogMessageBuilder(): sl(Log::mutex_), pos_(0) { | 208 LogMessageBuilder::LogMessageBuilder(): sl(Log::mutex_), pos_(0) { |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 void LogMessageBuilder::WriteToLogFile() { | 345 void LogMessageBuilder::WriteToLogFile() { |
346 ASSERT(pos_ <= Log::kMessageBufferSize); | 346 ASSERT(pos_ <= Log::kMessageBufferSize); |
347 const int written = Log::Write(Log::message_buffer_, pos_); | 347 const int written = Log::Write(Log::message_buffer_, pos_); |
348 if (written != pos_ && write_failure_handler != NULL) { | 348 if (written != pos_ && write_failure_handler != NULL) { |
349 write_failure_handler(); | 349 write_failure_handler(); |
350 } | 350 } |
351 } | 351 } |
352 | 352 |
353 | 353 |
354 void LogMessageBuilder::WriteCStringToLogFile(const char* str) { | 354 void LogMessageBuilder::WriteCStringToLogFile(const char* str) { |
355 const int len = strlen(str); | 355 const int len = StrLength(str); |
356 const int written = Log::Write(str, len); | 356 const int written = Log::Write(str, len); |
357 if (written != len && write_failure_handler != NULL) { | 357 if (written != len && write_failure_handler != NULL) { |
358 write_failure_handler(); | 358 write_failure_handler(); |
359 } | 359 } |
360 } | 360 } |
361 | 361 |
362 | 362 |
363 // Formatting string for back references to the whole line. E.g. "#2" means | 363 // Formatting string for back references to the whole line. E.g. "#2" means |
364 // "the second line above". | 364 // "the second line above". |
365 const char* LogRecordCompressor::kLineBackwardReferenceFormat = "#%d"; | 365 const char* LogRecordCompressor::kLineBackwardReferenceFormat = "#%d"; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 const char* const data_end = data.start() + data.length(); | 454 const char* const data_end = data.start() + data.length(); |
455 const char* prev_ptr = prev_end; | 455 const char* prev_ptr = prev_end; |
456 const char* data_ptr = data_end; | 456 const char* data_ptr = data_end; |
457 // Compare strings backwards, stop on the last matching character. | 457 // Compare strings backwards, stop on the last matching character. |
458 while (prev_ptr != prev_start && data_ptr != data.start() | 458 while (prev_ptr != prev_start && data_ptr != data.start() |
459 && *(prev_ptr - 1) == *(data_ptr - 1)) { | 459 && *(prev_ptr - 1) == *(data_ptr - 1)) { |
460 --prev_ptr; | 460 --prev_ptr; |
461 --data_ptr; | 461 --data_ptr; |
462 } | 462 } |
463 const intptr_t truncated_len = prev_end - prev_ptr; | 463 const intptr_t truncated_len = prev_end - prev_ptr; |
464 const int copy_from_pos = data_ptr - data.start(); | 464 const int copy_from_pos = static_cast<int>(data_ptr - data.start()); |
465 // Check if the length of compressed tail is enough. | 465 // Check if the length of compressed tail is enough. |
466 if (truncated_len <= kMaxBackwardReferenceSize | 466 if (truncated_len <= kMaxBackwardReferenceSize |
467 && truncated_len <= GetBackwardReferenceSize(distance, copy_from_pos)) { | 467 && truncated_len <= GetBackwardReferenceSize(distance, copy_from_pos)) { |
468 continue; | 468 continue; |
469 } | 469 } |
470 | 470 |
471 // Record compression results. | 471 // Record compression results. |
472 if (truncated_len > best.truncated_len) { | 472 if (truncated_len > best.truncated_len) { |
473 best.truncated_len = truncated_len; | 473 best.truncated_len = truncated_len; |
474 best.distance = distance; | 474 best.distance = distance; |
(...skipping 11 matching lines...) Expand all Loading... |
486 // Copy the uncompressible part unchanged. | 486 // Copy the uncompressible part unchanged. |
487 const intptr_t unchanged_len = prev.length() - best.truncated_len; | 487 const intptr_t unchanged_len = prev.length() - best.truncated_len; |
488 // + 1 for '\0'. | 488 // + 1 for '\0'. |
489 ASSERT(prev_record->length() >= unchanged_len + best.backref_size + 1); | 489 ASSERT(prev_record->length() >= unchanged_len + best.backref_size + 1); |
490 memcpy(prev_record->start(), prev.start(), unchanged_len); | 490 memcpy(prev_record->start(), prev.start(), unchanged_len); |
491 // Append the backward reference. | 491 // Append the backward reference. |
492 Vector<char> backref( | 492 Vector<char> backref( |
493 prev_record->start() + unchanged_len, best.backref_size + 1); | 493 prev_record->start() + unchanged_len, best.backref_size + 1); |
494 PrintBackwardReference(backref, best.distance, best.copy_from_pos); | 494 PrintBackwardReference(backref, best.distance, best.copy_from_pos); |
495 ASSERT(strlen(backref.start()) - best.backref_size == 0); | 495 ASSERT(strlen(backref.start()) - best.backref_size == 0); |
496 prev_record->Truncate(unchanged_len + best.backref_size); | 496 prev_record->Truncate(static_cast<int>(unchanged_len + best.backref_size)); |
497 } | 497 } |
498 return true; | 498 return true; |
499 } | 499 } |
500 | 500 |
501 #endif // ENABLE_LOGGING_AND_PROFILING | 501 #endif // ENABLE_LOGGING_AND_PROFILING |
502 | 502 |
503 } } // namespace v8::internal | 503 } } // namespace v8::internal |
OLD | NEW |