test/src/jdk/nashorn/internal/runtime/test/CodeStoreAndPathTest.java

Print this page




 145         final Path codeCachePath = getCodeCachePath(false);
 146         e.eval(code1);
 147         e.eval(code2);
 148         e.eval(code3);// less than minimum size for storing
 149         // adding code1 and code2.
 150         final DirectoryStream<Path> stream = Files.newDirectoryStream(codeCachePath);
 151         checkCompiledScripts(stream, 2);
 152     }
 153 
 154     @Test
 155     public void codeCacheTestOpt() throws ScriptException, IOException {
 156         System.setProperty("nashorn.persistent.code.cache", codeCache);
 157         final NashornScriptEngineFactory fac = new NashornScriptEngineFactory();
 158         final ScriptEngine e = fac.getScriptEngine(ENGINE_OPTIONS_OPT);
 159         final Path codeCachePath = getCodeCachePath(true);
 160         e.eval(code1);
 161         e.eval(code2);
 162         e.eval(code3);// less than minimum size for storing
 163         // adding code1 and code2.
 164         final DirectoryStream<Path> stream = Files.newDirectoryStream(codeCachePath);
 165         checkCompiledScripts(stream, 2);
 166     }
 167 
 168     private static Path getCodeCachePath(final boolean optimistic) {
 169         final String codeCache = System.getProperty("nashorn.persistent.code.cache");
 170         final Path codeCachePath = FileSystems.getDefault().getPath(codeCache).toAbsolutePath();
 171         final String[] files = codeCachePath.toFile().list();
 172         for (final String file : files) {
 173             if (file.endsWith("_opt") == optimistic) {
 174                 return codeCachePath.resolve(file);
 175             }
 176         }
 177         throw new AssertionError("Code cache path not found");
 178     }
 179 
 180     private static void checkCompiledScripts(final DirectoryStream<Path> stream, final int numberOfScripts) throws IOException {
 181         int n = numberOfScripts;
 182         for (@SuppressWarnings("unused") final Path file : stream) {
 183             n--;
 184         }
 185         stream.close();


 145         final Path codeCachePath = getCodeCachePath(false);
 146         e.eval(code1);
 147         e.eval(code2);
 148         e.eval(code3);// less than minimum size for storing
 149         // adding code1 and code2.
 150         final DirectoryStream<Path> stream = Files.newDirectoryStream(codeCachePath);
 151         checkCompiledScripts(stream, 2);
 152     }
 153 
 154     @Test
 155     public void codeCacheTestOpt() throws ScriptException, IOException {
 156         System.setProperty("nashorn.persistent.code.cache", codeCache);
 157         final NashornScriptEngineFactory fac = new NashornScriptEngineFactory();
 158         final ScriptEngine e = fac.getScriptEngine(ENGINE_OPTIONS_OPT);
 159         final Path codeCachePath = getCodeCachePath(true);
 160         e.eval(code1);
 161         e.eval(code2);
 162         e.eval(code3);// less than minimum size for storing
 163         // adding code1 and code2.
 164         final DirectoryStream<Path> stream = Files.newDirectoryStream(codeCachePath);
 165         checkCompiledScripts(stream, 4);
 166     }
 167 
 168     private static Path getCodeCachePath(final boolean optimistic) {
 169         final String codeCache = System.getProperty("nashorn.persistent.code.cache");
 170         final Path codeCachePath = FileSystems.getDefault().getPath(codeCache).toAbsolutePath();
 171         final String[] files = codeCachePath.toFile().list();
 172         for (final String file : files) {
 173             if (file.endsWith("_opt") == optimistic) {
 174                 return codeCachePath.resolve(file);
 175             }
 176         }
 177         throw new AssertionError("Code cache path not found");
 178     }
 179 
 180     private static void checkCompiledScripts(final DirectoryStream<Path> stream, final int numberOfScripts) throws IOException {
 181         int n = numberOfScripts;
 182         for (@SuppressWarnings("unused") final Path file : stream) {
 183             n--;
 184         }
 185         stream.close();