Beispiel #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);
 }
Beispiel #2
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);
 }