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

Side by Side Diff: src/api.cc

Issue 2139873002: V8: Add API to report OOM to embedder. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 5 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
« include/v8.h ('K') | « src/api.h ('k') | src/isolate.h » ('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 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 #include "src/api.h" 5 #include "src/api.h"
6 6
7 #include <string.h> // For memcpy, strlen. 7 #include <string.h> // For memcpy, strlen.
8 #ifdef V8_USE_ADDRESS_SANITIZER 8 #ifdef V8_USE_ADDRESS_SANITIZER
9 #include <sanitizer/asan_interface.h> 9 #include <sanitizer/asan_interface.h>
10 #endif // V8_USE_ADDRESS_SANITIZER 10 #endif // V8_USE_ADDRESS_SANITIZER
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 236
237 // --- E x c e p t i o n B e h a v i o r --- 237 // --- E x c e p t i o n B e h a v i o r ---
238 238
239 239
240 void i::FatalProcessOutOfMemory(const char* location) { 240 void i::FatalProcessOutOfMemory(const char* location) {
241 i::V8::FatalProcessOutOfMemory(location, false); 241 i::V8::FatalProcessOutOfMemory(location, false);
242 } 242 }
243 243
244 244
245 // When V8 cannot allocated memory FatalProcessOutOfMemory is called. 245 // When V8 cannot allocated memory FatalProcessOutOfMemory is called.
246 // The default fatal error handler is called and execution is stopped. 246 // The default OOM error handler is called and execution is stopped.
247 void i::V8::FatalProcessOutOfMemory(const char* location, bool is_heap_oom) { 247 void i::V8::FatalProcessOutOfMemory(const char* location, bool is_heap_oom) {
248 i::Isolate* isolate = i::Isolate::Current(); 248 i::Isolate* isolate = i::Isolate::Current();
249 char last_few_messages[Heap::kTraceRingBufferSize + 1]; 249 char last_few_messages[Heap::kTraceRingBufferSize + 1];
250 char js_stacktrace[Heap::kStacktraceBufferSize + 1]; 250 char js_stacktrace[Heap::kStacktraceBufferSize + 1];
251 memset(last_few_messages, 0, Heap::kTraceRingBufferSize + 1); 251 memset(last_few_messages, 0, Heap::kTraceRingBufferSize + 1);
252 memset(js_stacktrace, 0, Heap::kStacktraceBufferSize + 1); 252 memset(js_stacktrace, 0, Heap::kStacktraceBufferSize + 1);
253 253
254 i::HeapStats heap_stats; 254 i::HeapStats heap_stats;
255 int start_marker; 255 int start_marker;
256 heap_stats.start_marker = &start_marker; 256 heap_stats.start_marker = &start_marker;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 if (isolate->heap()->HasBeenSetUp()) { 299 if (isolate->heap()->HasBeenSetUp()) {
300 // BUG(1718): Don't use the take_snapshot since we don't support 300 // BUG(1718): Don't use the take_snapshot since we don't support
301 // HeapIterator here without doing a special GC. 301 // HeapIterator here without doing a special GC.
302 isolate->heap()->RecordStats(&heap_stats, false); 302 isolate->heap()->RecordStats(&heap_stats, false);
303 char* first_newline = strchr(last_few_messages, '\n'); 303 char* first_newline = strchr(last_few_messages, '\n');
304 if (first_newline == NULL || first_newline[1] == '\0') 304 if (first_newline == NULL || first_newline[1] == '\0')
305 first_newline = last_few_messages; 305 first_newline = last_few_messages;
306 PrintF("\n<--- Last few GCs --->\n%s\n", first_newline); 306 PrintF("\n<--- Last few GCs --->\n%s\n", first_newline);
307 PrintF("\n<--- JS stacktrace --->\n%s\n", js_stacktrace); 307 PrintF("\n<--- JS stacktrace --->\n%s\n", js_stacktrace);
308 } 308 }
309 Utils::ApiCheck(false, location, is_heap_oom 309 Utils::ReportOOMFailure(location, is_heap_oom);
310 ? "Allocation failed - JavaScript heap out of memory"
311 : "Allocation failed - process out of memory");
312 // If the fatal error handler returns, we stop execution. 310 // If the fatal error handler returns, we stop execution.
313 FATAL("API fatal error handler returned after process out of memory"); 311 FATAL("API fatal error handler returned after process out of memory");
314 } 312 }
315 313
316 314
317 void Utils::ReportApiFailure(const char* location, const char* message) { 315 void Utils::ReportApiFailure(const char* location, const char* message) {
318 i::Isolate* isolate = i::Isolate::Current(); 316 i::Isolate* isolate = i::Isolate::Current();
319 FatalErrorCallback callback = isolate->exception_behavior(); 317 FatalErrorCallback callback = isolate->exception_behavior();
320 if (callback == NULL) { 318 if (callback == NULL) {
321 base::OS::PrintError("\n#\n# Fatal error in %s\n# %s\n#\n\n", location, 319 base::OS::PrintError("\n#\n# Fatal error in %s\n# %s\n#\n\n", location,
322 message); 320 message);
323 base::OS::Abort(); 321 base::OS::Abort();
324 } else { 322 } else {
325 callback(location, message); 323 callback(location, message);
326 } 324 }
327 isolate->SignalFatalError(); 325 isolate->SignalFatalError();
328 } 326 }
329 327
330 328
329 void Utils::ReportOOMFailure(const char* location, bool is_heap_oom) {
330 i::Isolate* isolate = i::Isolate::Current();
331 OOMErrorCallback callback = isolate->oom_behavior();
332 if (callback == NULL) {
jochen (gone - plz use gerrit) 2016/07/12 15:11:30 nullptr
Will Harris 2016/07/12 15:42:53 Done.
333 base::OS::PrintError("\n#\n# Fatal %s OOM in %s\n#\n\n",
334 is_heap_oom ? "javascript" : "process", location);
335 base::OS::Abort();
336 } else {
337 callback(location, is_heap_oom);
338 }
339 isolate->SignalFatalError();
340 }
341
331 static inline bool IsExecutionTerminatingCheck(i::Isolate* isolate) { 342 static inline bool IsExecutionTerminatingCheck(i::Isolate* isolate) {
332 if (isolate->has_scheduled_exception()) { 343 if (isolate->has_scheduled_exception()) {
333 return isolate->scheduled_exception() == 344 return isolate->scheduled_exception() ==
334 isolate->heap()->termination_exception(); 345 isolate->heap()->termination_exception();
335 } 346 }
336 return false; 347 return false;
337 } 348 }
338 349
339 350
340 void V8::SetNativesDataBlob(StartupData* natives_blob) { 351 void V8::SetNativesDataBlob(StartupData* natives_blob) {
(...skipping 7559 matching lines...) Expand 10 before | Expand all | Expand 10 after
7900 *length_in_bytes = 0; 7911 *length_in_bytes = 0;
7901 } 7912 }
7902 } 7913 }
7903 7914
7904 7915
7905 void Isolate::SetFatalErrorHandler(FatalErrorCallback that) { 7916 void Isolate::SetFatalErrorHandler(FatalErrorCallback that) {
7906 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); 7917 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
7907 isolate->set_exception_behavior(that); 7918 isolate->set_exception_behavior(that);
7908 } 7919 }
7909 7920
7921 void Isolate::SetOOMErrorHandler(OOMErrorCallback that) {
7922 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
7923 isolate->set_oom_behavior(that);
7924 }
7910 7925
7911 void Isolate::SetAllowCodeGenerationFromStringsCallback( 7926 void Isolate::SetAllowCodeGenerationFromStringsCallback(
7912 AllowCodeGenerationFromStringsCallback callback) { 7927 AllowCodeGenerationFromStringsCallback callback) {
7913 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); 7928 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
7914 isolate->set_allow_code_gen_callback(callback); 7929 isolate->set_allow_code_gen_callback(callback);
7915 } 7930 }
7916 7931
7917 7932
7918 bool Isolate::IsDead() { 7933 bool Isolate::IsDead() {
7919 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); 7934 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
(...skipping 1089 matching lines...) Expand 10 before | Expand all | Expand 10 after
9009 Address callback_address = 9024 Address callback_address =
9010 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 9025 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
9011 VMState<EXTERNAL> state(isolate); 9026 VMState<EXTERNAL> state(isolate);
9012 ExternalCallbackScope call_scope(isolate, callback_address); 9027 ExternalCallbackScope call_scope(isolate, callback_address);
9013 callback(info); 9028 callback(info);
9014 } 9029 }
9015 9030
9016 9031
9017 } // namespace internal 9032 } // namespace internal
9018 } // namespace v8 9033 } // namespace v8
OLDNEW
« include/v8.h ('K') | « src/api.h ('k') | src/isolate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698