8064789: Nashorn should just warn on code store instantiation error
authorhannesw
Thu, 13 Nov 2014 15:29:22 +0100
changeset 27530 518b8ae2dbb9
parent 27529 eafb7de4648e
child 27531 e8813093f603
8064789: Nashorn should just warn on code store instantiation error Reviewed-by: attila, lagergren
nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/CodeStore.java
nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Context.java
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/CodeStore.java	Wed Nov 12 17:19:04 2014 +0100
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/CodeStore.java	Thu Nov 13 15:29:22 2014 +0100
@@ -82,10 +82,9 @@
      * Returns a new code store instance.
      *
      * @param context the current context
-     * @return The instance
-     * @throws IOException If an error occurs
+     * @return The instance, or null if code store could not be created
      */
-    public static CodeStore newCodeStore(final Context context) throws IOException {
+    public static CodeStore newCodeStore(final Context context) {
         final Class<CodeStore> baseClass = CodeStore.class;
         try {
             // security check first
@@ -103,9 +102,14 @@
         } catch (final AccessControlException e) {
             context.getLogger(CodeStore.class).warning("failed to load code store provider ", e);
         }
-        final CodeStore store = new DirectoryCodeStore(context);
-        store.initLogger(context);
-        return store;
+        try {
+            final CodeStore store = new DirectoryCodeStore(context);
+            store.initLogger(context);
+            return store;
+        } catch (final IOException e) {
+            context.getLogger(CodeStore.class).warning("failed to create cache directory ", e);
+            return null;
+        }
     }
 
 
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Context.java	Wed Nov 12 17:19:04 2014 +0100
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Context.java	Thu Nov 13 15:29:22 2014 +0100
@@ -509,11 +509,7 @@
         }
 
         if (env._persistent_cache) {
-            try {
-                codeStore = newCodeStore(this);
-            } catch (final IOException e) {
-                throw new RuntimeException("Error initializing code cache", e);
-            }
+            codeStore = newCodeStore(this);
         }
 
         // print version info if asked.
@@ -1200,7 +1196,7 @@
         FunctionNode functionNode = null;
         // We only use the code store here if optimistic types are disabled. With optimistic types, initial compilation
         // just creates a thin wrapper, and actual code is stored per function in RecompilableScriptFunctionData.
-        final boolean useCodeStore = env._persistent_cache && !env._parse_only && !env._optimistic_types;
+        final boolean useCodeStore = codeStore != null && !env._parse_only && !env._optimistic_types;
         final String cacheKey = useCodeStore ? CodeStore.getCacheKey(0, null) : null;
 
         if (useCodeStore) {