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

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

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/isolate.cc ('k') | src/string-stream.cc » ('j') | 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 #ifndef V8_STRING_STREAM_H_ 5 #ifndef V8_STRING_STREAM_H_
6 #define V8_STRING_STREAM_H_ 6 #define V8_STRING_STREAM_H_
7 7
8 #include "src/handles.h" 8 #include "src/handles.h"
9 9
10 namespace v8 { 10 namespace v8 {
(...skipping 17 matching lines...) Expand all
28 public: 28 public:
29 ~HeapStringAllocator() { DeleteArray(space_); } 29 ~HeapStringAllocator() { DeleteArray(space_); }
30 char* allocate(unsigned bytes) override; 30 char* allocate(unsigned bytes) override;
31 char* grow(unsigned* bytes) override; 31 char* grow(unsigned* bytes) override;
32 32
33 private: 33 private:
34 char* space_; 34 char* space_;
35 }; 35 };
36 36
37 37
38 class FixedStringAllocator final : public StringAllocator {
39 public:
40 FixedStringAllocator(char* buffer, unsigned length)
41 : buffer_(buffer), length_(length) {}
42 ~FixedStringAllocator() override{};
43 char* allocate(unsigned bytes) override;
44 char* grow(unsigned* bytes) override;
45
46 private:
47 char* buffer_;
48 unsigned length_;
49 DISALLOW_COPY_AND_ASSIGN(FixedStringAllocator);
50 };
51
52
38 class FmtElm final { 53 class FmtElm final {
39 public: 54 public:
40 FmtElm(int value) : type_(INT) { // NOLINT 55 FmtElm(int value) : type_(INT) { // NOLINT
41 data_.u_int_ = value; 56 data_.u_int_ = value;
42 } 57 }
43 explicit FmtElm(double value) : type_(DOUBLE) { 58 explicit FmtElm(double value) : type_(DOUBLE) {
44 data_.u_double_ = value; 59 data_.u_double_ = value;
45 } 60 }
46 FmtElm(const char* value) : type_(C_STR) { // NOLINT 61 FmtElm(const char* value) : type_(C_STR) { // NOLINT
47 data_.u_c_str_ = value; 62 data_.u_c_str_ = value;
(...skipping 22 matching lines...) Expand all
70 const Vector<const uc16>* u_lc_str_; 85 const Vector<const uc16>* u_lc_str_;
71 Object* u_obj_; 86 Object* u_obj_;
72 Object** u_handle_; 87 Object** u_handle_;
73 void* u_pointer_; 88 void* u_pointer_;
74 } data_; 89 } data_;
75 }; 90 };
76 91
77 92
78 class StringStream final { 93 class StringStream final {
79 public: 94 public:
80 explicit StringStream(StringAllocator* allocator): 95 enum ObjectPrintMode { kPrintObjectConcise, kPrintObjectVerbose };
81 allocator_(allocator), 96 StringStream(StringAllocator* allocator,
82 capacity_(kInitialCapacity), 97 ObjectPrintMode object_print_mode = kPrintObjectConcise)
83 length_(0), 98 : allocator_(allocator),
84 buffer_(allocator_->allocate(kInitialCapacity)) { 99 object_print_mode_(object_print_mode),
100 capacity_(kInitialCapacity),
101 length_(0),
102 buffer_(allocator_->allocate(kInitialCapacity)) {
85 buffer_[0] = 0; 103 buffer_[0] = 0;
86 } 104 }
87 105
88 bool Put(char c); 106 bool Put(char c);
89 bool Put(String* str); 107 bool Put(String* str);
90 bool Put(String* str, int start, int end); 108 bool Put(String* str, int start, int end);
91 void Add(Vector<const char> format, Vector<FmtElm> elms); 109 void Add(Vector<const char> format, Vector<FmtElm> elms);
92 void Add(const char* format); 110 void Add(const char* format);
93 void Add(Vector<const char> format); 111 void Add(Vector<const char> format);
94 void Add(const char* format, FmtElm arg0); 112 void Add(const char* format, FmtElm arg0);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 // Reset the stream. 145 // Reset the stream.
128 void Reset() { 146 void Reset() {
129 length_ = 0; 147 length_ = 0;
130 buffer_[0] = 0; 148 buffer_[0] = 0;
131 } 149 }
132 150
133 // Mentioned object cache support. 151 // Mentioned object cache support.
134 void PrintMentionedObjectCache(Isolate* isolate); 152 void PrintMentionedObjectCache(Isolate* isolate);
135 static void ClearMentionedObjectCache(Isolate* isolate); 153 static void ClearMentionedObjectCache(Isolate* isolate);
136 #ifdef DEBUG 154 #ifdef DEBUG
137 static bool IsMentionedObjectCacheClear(Isolate* isolate); 155 bool IsMentionedObjectCacheClear(Isolate* isolate);
138 #endif 156 #endif
139 157
140 static const int kInitialCapacity = 16; 158 static const int kInitialCapacity = 16;
141 159
142 private: 160 private:
143 void PrintObject(Object* obj); 161 void PrintObject(Object* obj);
144 162
145 StringAllocator* allocator_; 163 StringAllocator* allocator_;
164 ObjectPrintMode object_print_mode_;
146 unsigned capacity_; 165 unsigned capacity_;
147 unsigned length_; // does not include terminating 0-character 166 unsigned length_; // does not include terminating 0-character
148 char* buffer_; 167 char* buffer_;
149 168
150 bool full() const { return (capacity_ - length_) == 1; } 169 bool full() const { return (capacity_ - length_) == 1; }
151 int space() const { return capacity_ - length_; } 170 int space() const { return capacity_ - length_; }
152 171
153 DISALLOW_IMPLICIT_CONSTRUCTORS(StringStream); 172 DISALLOW_IMPLICIT_CONSTRUCTORS(StringStream);
154 }; 173 };
155 174
156 } } // namespace v8::internal 175 } } // namespace v8::internal
157 176
158 #endif // V8_STRING_STREAM_H_ 177 #endif // V8_STRING_STREAM_H_
OLDNEW
« no previous file with comments | « src/isolate.cc ('k') | src/string-stream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698