Exemple #1
0
 private void handleException(Realm realm, StackOverflowError e) {
   // Create script exception with stacktrace from stackoverflow-error.
   ScriptException exception =
       newInternalError(realm.defaultContext(), Messages.Key.StackOverflow);
   exception.setStackTrace(e.getStackTrace());
   handleException(realm, exception);
 }
Exemple #2
0
 private void printScriptStackTrace(Realm realm, ScriptException e) {
   if (options.scriptStacktrace) {
     StringBuilder sb = new StringBuilder();
     printScriptFrames(sb, realm, e, 1);
     if (sb.length() == 0 && e.getCause() != null) {
       printScriptFrames(sb, realm, e.getCause(), 1);
     }
     console.writer().print(sb.toString());
   }
 }
Exemple #3
0
 private void handleException(Realm realm, OutOfMemoryError e) {
   // Try to recover after OOM.
   Runtime rt = Runtime.getRuntime();
   long beforeGc = rt.freeMemory();
   rt.gc();
   long afterGc = rt.freeMemory();
   if (afterGc > beforeGc && (afterGc - beforeGc) < 50_000_000) {
     // Calling gc() cleared less than 50MB, assume unrecoverable OOM and rethrow error.
     throw e;
   }
   // Create script exception with stacktrace from oom-error.
   ScriptException exception =
       newInternalError(realm.defaultContext(), Messages.Key.OutOfMemoryVM);
   exception.setStackTrace(e.getStackTrace());
   handleException(realm, exception);
 }
Exemple #4
0
 private void handleException(Realm realm, ScriptException e) {
   String message = formatMessage("uncaught_exception", e.getMessage(realm.defaultContext()));
   console.printf("%s%n", message);
   printScriptStackTrace(realm, e);
   printStackTrace(e);
 }