Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(207)

Side by Side Diff: src/string-stream.cc

Issue 1149623010: Print and save JS stacktrace on OOM crash. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Address comments Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/string-stream.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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 #include "src/string-stream.h" 5 #include "src/string-stream.h"
6 6
7 #include "src/handles-inl.h" 7 #include "src/handles-inl.h"
8 #include "src/prototype.h" 8 #include "src/prototype.h"
9 9
10 namespace v8 { 10 namespace v8 {
11 namespace internal { 11 namespace internal {
12 12
13 static const int kMentionedObjectCacheMaxSize = 256; 13 static const int kMentionedObjectCacheMaxSize = 256;
14 14
15 char* HeapStringAllocator::allocate(unsigned bytes) { 15 char* HeapStringAllocator::allocate(unsigned bytes) {
16 space_ = NewArray<char>(bytes); 16 space_ = NewArray<char>(bytes);
17 return space_; 17 return space_;
18 } 18 }
19 19
20 20
21 char* FixedStringAllocator::allocate(unsigned bytes) {
22 CHECK_LE(bytes, length_);
23 return buffer_;
24 }
25
26
27 char* FixedStringAllocator::grow(unsigned* old) {
28 *old = length_;
29 return buffer_;
30 }
31
32
21 bool StringStream::Put(char c) { 33 bool StringStream::Put(char c) {
22 if (full()) return false; 34 if (full()) return false;
23 DCHECK(length_ < capacity_); 35 DCHECK(length_ < capacity_);
24 // Since the trailing '\0' is not accounted for in length_ fullness is 36 // Since the trailing '\0' is not accounted for in length_ fullness is
25 // indicated by a difference of 1 between length_ and capacity_. Thus when 37 // indicated by a difference of 1 between length_ and capacity_. Thus when
26 // reaching a difference of 2 we need to grow the buffer. 38 // reaching a difference of 2 we need to grow the buffer.
27 if (length_ == capacity_ - 2) { 39 if (length_ == capacity_ - 2) {
28 unsigned new_capacity = capacity_; 40 unsigned new_capacity = capacity_;
29 char* new_buffer = allocator_->grow(&new_capacity); 41 char* new_buffer = allocator_->grow(&new_capacity);
30 if (new_capacity > capacity_) { 42 if (new_capacity > capacity_) {
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 175
164 void StringStream::PrintObject(Object* o) { 176 void StringStream::PrintObject(Object* o) {
165 o->ShortPrint(this); 177 o->ShortPrint(this);
166 if (o->IsString()) { 178 if (o->IsString()) {
167 if (String::cast(o)->length() <= String::kMaxShortPrintLength) { 179 if (String::cast(o)->length() <= String::kMaxShortPrintLength) {
168 return; 180 return;
169 } 181 }
170 } else if (o->IsNumber() || o->IsOddball()) { 182 } else if (o->IsNumber() || o->IsOddball()) {
171 return; 183 return;
172 } 184 }
173 if (o->IsHeapObject()) { 185 if (o->IsHeapObject() && object_print_mode_ == kPrintObjectVerbose) {
174 HeapObject* ho = HeapObject::cast(o); 186 HeapObject* ho = HeapObject::cast(o);
175 DebugObjectCache* debug_object_cache = ho->GetIsolate()-> 187 DebugObjectCache* debug_object_cache = ho->GetIsolate()->
176 string_stream_debug_object_cache(); 188 string_stream_debug_object_cache();
177 for (int i = 0; i < debug_object_cache->length(); i++) { 189 for (int i = 0; i < debug_object_cache->length(); i++) {
178 if ((*debug_object_cache)[i] == o) { 190 if ((*debug_object_cache)[i] == o) {
179 Add("#%d#", i); 191 Add("#%d#", i);
180 return; 192 return;
181 } 193 }
182 } 194 }
183 if (debug_object_cache->length() < kMentionedObjectCacheMaxSize) { 195 if (debug_object_cache->length() < kMentionedObjectCacheMaxSize) {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 isolate->set_string_stream_current_security_token(NULL); 289 isolate->set_string_stream_current_security_token(NULL);
278 if (isolate->string_stream_debug_object_cache() == NULL) { 290 if (isolate->string_stream_debug_object_cache() == NULL) {
279 isolate->set_string_stream_debug_object_cache(new DebugObjectCache(0)); 291 isolate->set_string_stream_debug_object_cache(new DebugObjectCache(0));
280 } 292 }
281 isolate->string_stream_debug_object_cache()->Clear(); 293 isolate->string_stream_debug_object_cache()->Clear();
282 } 294 }
283 295
284 296
285 #ifdef DEBUG 297 #ifdef DEBUG
286 bool StringStream::IsMentionedObjectCacheClear(Isolate* isolate) { 298 bool StringStream::IsMentionedObjectCacheClear(Isolate* isolate) {
287 return isolate->string_stream_debug_object_cache()->length() == 0; 299 return object_print_mode_ == kPrintObjectConcise ||
300 isolate->string_stream_debug_object_cache()->length() == 0;
288 } 301 }
289 #endif 302 #endif
290 303
291 304
292 bool StringStream::Put(String* str) { 305 bool StringStream::Put(String* str) {
293 return Put(str, 0, str->length()); 306 return Put(str, 0, str->length());
294 } 307 }
295 308
296 309
297 bool StringStream::Put(String* str, int start, int end) { 310 bool StringStream::Put(String* str, int start, int end) {
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 } 409 }
397 Add("\n"); 410 Add("\n");
398 } 411 }
399 if (limit >= 10) { 412 if (limit >= 10) {
400 Add(" ...\n"); 413 Add(" ...\n");
401 } 414 }
402 } 415 }
403 416
404 417
405 void StringStream::PrintMentionedObjectCache(Isolate* isolate) { 418 void StringStream::PrintMentionedObjectCache(Isolate* isolate) {
419 if (object_print_mode_ == kPrintObjectConcise) return;
406 DebugObjectCache* debug_object_cache = 420 DebugObjectCache* debug_object_cache =
407 isolate->string_stream_debug_object_cache(); 421 isolate->string_stream_debug_object_cache();
408 Add("==== Key ============================================\n\n"); 422 Add("==== Key ============================================\n\n");
409 for (int i = 0; i < debug_object_cache->length(); i++) { 423 for (int i = 0; i < debug_object_cache->length(); i++) {
410 HeapObject* printee = (*debug_object_cache)[i]; 424 HeapObject* printee = (*debug_object_cache)[i];
411 Add(" #%d# %p: ", i, printee); 425 Add(" #%d# %p: ", i, printee);
412 printee->ShortPrint(this); 426 printee->ShortPrint(this);
413 Add("\n"); 427 Add("\n");
414 if (printee->IsJSObject()) { 428 if (printee->IsJSObject()) {
415 if (printee->IsJSValue()) { 429 if (printee->IsJSValue()) {
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 MemCopy(new_space, space_, *bytes); 571 MemCopy(new_space, space_, *bytes);
558 *bytes = new_bytes; 572 *bytes = new_bytes;
559 DeleteArray(space_); 573 DeleteArray(space_);
560 space_ = new_space; 574 space_ = new_space;
561 return new_space; 575 return new_space;
562 } 576 }
563 577
564 578
565 } // namespace internal 579 } // namespace internal
566 } // namespace v8 580 } // namespace v8
OLDNEW
« no previous file with comments | « src/string-stream.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698