Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 |
| 328 void Utils::ReportOOMFailure(const char* location, bool is_heap_oom) { | |
| 329 i::Isolate* isolate = i::Isolate::Current(); | |
| 330 OOMErrorCallback callback = isolate->oom_behavior(); | |
| 331 if (callback == nullptr) { | |
|
Will Harris
2016/07/12 15:46:10
This will change the signature of OOM errors in v8
Hannes Payer (out of office)
2016/07/13 09:21:11
After landing 2130293003 the signature will change
Will Harris
2016/07/13 20:09:45
now it will fall back to previous behavior if the
| |
| 332 base::OS::PrintError("\n#\n# Fatal %s OOM in %s\n#\n\n", | |
| 333 is_heap_oom ? "javascript" : "process", location); | |
| 334 base::OS::Abort(); | |
| 335 } else { | |
| 336 callback(location, is_heap_oom); | |
| 337 } | |
| 338 isolate->SignalFatalError(); | |
| 339 } | |
| 330 | 340 |
| 331 static inline bool IsExecutionTerminatingCheck(i::Isolate* isolate) { | 341 static inline bool IsExecutionTerminatingCheck(i::Isolate* isolate) { |
| 332 if (isolate->has_scheduled_exception()) { | 342 if (isolate->has_scheduled_exception()) { |
| 333 return isolate->scheduled_exception() == | 343 return isolate->scheduled_exception() == |
| 334 isolate->heap()->termination_exception(); | 344 isolate->heap()->termination_exception(); |
| 335 } | 345 } |
| 336 return false; | 346 return false; |
| 337 } | 347 } |
| 338 | 348 |
| 339 | 349 |
| (...skipping 7560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7900 *length_in_bytes = 0; | 7910 *length_in_bytes = 0; |
| 7901 } | 7911 } |
| 7902 } | 7912 } |
| 7903 | 7913 |
| 7904 | 7914 |
| 7905 void Isolate::SetFatalErrorHandler(FatalErrorCallback that) { | 7915 void Isolate::SetFatalErrorHandler(FatalErrorCallback that) { |
| 7906 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); | 7916 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 7907 isolate->set_exception_behavior(that); | 7917 isolate->set_exception_behavior(that); |
| 7908 } | 7918 } |
| 7909 | 7919 |
| 7920 void Isolate::SetOOMErrorHandler(OOMErrorCallback that) { | |
| 7921 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); | |
| 7922 isolate->set_oom_behavior(that); | |
| 7923 } | |
| 7910 | 7924 |
| 7911 void Isolate::SetAllowCodeGenerationFromStringsCallback( | 7925 void Isolate::SetAllowCodeGenerationFromStringsCallback( |
| 7912 AllowCodeGenerationFromStringsCallback callback) { | 7926 AllowCodeGenerationFromStringsCallback callback) { |
| 7913 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); | 7927 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 7914 isolate->set_allow_code_gen_callback(callback); | 7928 isolate->set_allow_code_gen_callback(callback); |
| 7915 } | 7929 } |
| 7916 | 7930 |
| 7917 | 7931 |
| 7918 bool Isolate::IsDead() { | 7932 bool Isolate::IsDead() { |
| 7919 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); | 7933 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| (...skipping 1089 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9009 Address callback_address = | 9023 Address callback_address = |
| 9010 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 9024 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
| 9011 VMState<EXTERNAL> state(isolate); | 9025 VMState<EXTERNAL> state(isolate); |
| 9012 ExternalCallbackScope call_scope(isolate, callback_address); | 9026 ExternalCallbackScope call_scope(isolate, callback_address); |
| 9013 callback(info); | 9027 callback(info); |
| 9014 } | 9028 } |
| 9015 | 9029 |
| 9016 | 9030 |
| 9017 } // namespace internal | 9031 } // namespace internal |
| 9018 } // namespace v8 | 9032 } // namespace v8 |
| OLD | NEW |