src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/CodeStore.java

Print this page




  65      * Constructor
  66      */
  67     protected CodeStore() {
  68     }
  69 
  70     @Override
  71     public DebugLogger initLogger(final Context context) {
  72         log = context.getLogger(getClass());
  73         return log;
  74     }
  75 
  76     @Override
  77     public DebugLogger getLogger() {
  78         return log;
  79     }
  80 
  81     /**
  82      * Returns a new code store instance.
  83      *
  84      * @param context the current context
  85      * @return The instance
  86      * @throws IOException If an error occurs
  87      */
  88     public static CodeStore newCodeStore(final Context context) throws IOException {
  89         final Class<CodeStore> baseClass = CodeStore.class;
  90         try {
  91             // security check first
  92             final SecurityManager sm = System.getSecurityManager();
  93             if (sm != null) {
  94                 sm.checkPermission(new RuntimePermission(NASHORN_PROVIDE_CODE_STORE));
  95             }
  96             final ServiceLoader<CodeStore> services = ServiceLoader.load(baseClass);
  97             final Iterator<CodeStore> iterator = services.iterator();
  98             if (iterator.hasNext()) {
  99                 final CodeStore store = iterator.next();
 100                 store.initLogger(context).info("using code store provider ", store.getClass().getCanonicalName());
 101                 return store;
 102             }
 103         } catch (final AccessControlException e) {
 104             context.getLogger(CodeStore.class).warning("failed to load code store provider ", e);
 105         }

 106         final CodeStore store = new DirectoryCodeStore(context);
 107         store.initLogger(context);
 108         return store;




 109     }
 110 
 111 
 112     /**
 113      * Store a compiled script in the cache.
 114      *
 115      * @param functionKey   the function key
 116      * @param source        the source
 117      * @param mainClassName the main class name
 118      * @param classBytes    a map of class bytes
 119      * @param initializers  the function initializers
 120      * @param constants     the constants array
 121      * @param compilationId the compilation id
 122      *
 123      * @return stored script
 124      */
 125     public StoredScript store(final String functionKey,
 126                               final Source source,
 127                               final String mainClassName,
 128                               final Map<String, byte[]> classBytes,




  65      * Constructor
  66      */
  67     protected CodeStore() {
  68     }
  69 
  70     @Override
  71     public DebugLogger initLogger(final Context context) {
  72         log = context.getLogger(getClass());
  73         return log;
  74     }
  75 
  76     @Override
  77     public DebugLogger getLogger() {
  78         return log;
  79     }
  80 
  81     /**
  82      * Returns a new code store instance.
  83      *
  84      * @param context the current context
  85      * @return The instance, or null if code store could not be created

  86      */
  87     public static CodeStore newCodeStore(final Context context) {
  88         final Class<CodeStore> baseClass = CodeStore.class;
  89         try {
  90             // security check first
  91             final SecurityManager sm = System.getSecurityManager();
  92             if (sm != null) {
  93                 sm.checkPermission(new RuntimePermission(NASHORN_PROVIDE_CODE_STORE));
  94             }
  95             final ServiceLoader<CodeStore> services = ServiceLoader.load(baseClass);
  96             final Iterator<CodeStore> iterator = services.iterator();
  97             if (iterator.hasNext()) {
  98                 final CodeStore store = iterator.next();
  99                 store.initLogger(context).info("using code store provider ", store.getClass().getCanonicalName());
 100                 return store;
 101             }
 102         } catch (final AccessControlException e) {
 103             context.getLogger(CodeStore.class).warning("failed to load code store provider ", e);
 104         }
 105         try {
 106             final CodeStore store = new DirectoryCodeStore(context);
 107             store.initLogger(context);
 108             return store;
 109         } catch (final IOException e) {
 110             context.getLogger(CodeStore.class).warning("failed to create cache dir", e);
 111             return null;
 112         }
 113     }
 114 
 115 
 116     /**
 117      * Store a compiled script in the cache.
 118      *
 119      * @param functionKey   the function key
 120      * @param source        the source
 121      * @param mainClassName the main class name
 122      * @param classBytes    a map of class bytes
 123      * @param initializers  the function initializers
 124      * @param constants     the constants array
 125      * @param compilationId the compilation id
 126      *
 127      * @return stored script
 128      */
 129     public StoredScript store(final String functionKey,
 130                               final Source source,
 131                               final String mainClassName,
 132                               final Map<String, byte[]> classBytes,