Mercurial > people > rkennke > jdk9-shenandoah-final > nashorn
changeset 1260:a9b03ce75736
8078612: Persistent code cache should support more configurations
Reviewed-by: lagergren, attila
line wrap: on
line diff
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/CodeStore.java Tue May 05 14:23:43 2015 +0200 +++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/CodeStore.java Tue May 05 14:30:00 2015 +0200 @@ -189,7 +189,7 @@ * @param paramTypes parameter types * @return a string representing the function */ - public static String getCacheKey(final int functionId, final Type[] paramTypes) { + public static String getCacheKey(final Object functionId, final Type[] paramTypes) { final StringBuilder b = new StringBuilder().append(functionId); if(paramTypes != null && paramTypes.length > 0) { b.append('-'); @@ -275,7 +275,7 @@ @Override public StoredScript load(final Source source, final String functionKey) { - if (source.getLength() < minSize) { + if (belowThreshold(source)) { return null; }
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Context.java Tue May 05 14:23:43 2015 +0200 +++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Context.java Tue May 05 14:30:00 2015 +0200 @@ -1228,10 +1228,11 @@ StoredScript storedScript = null; 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 = codeStore != null && !env._parse_only && !env._optimistic_types; - final String cacheKey = useCodeStore ? CodeStore.getCacheKey(0, null) : null; + // Don't use code store if optimistic types is enabled but lazy compilation is not. + // This would store a full script compilation with many wrong optimistic assumptions that would + // do more harm than good on later runs with both optimistic types and lazy compilation enabled. + final boolean useCodeStore = codeStore != null && !env._parse_only && (!env._optimistic_types || env._lazy_compilation); + final String cacheKey = useCodeStore ? CodeStore.getCacheKey("script", null) : null; if (useCodeStore) { storedScript = codeStore.load(source, cacheKey);
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ErrorManager.java Tue May 05 14:23:43 2015 +0200 +++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ErrorManager.java Tue May 05 14:30:00 2015 +0200 @@ -113,7 +113,7 @@ // Pointer to column. for (int i = 0; i < column; i++) { - if (sourceLine.charAt(i) == '\t') { + if (i < sourceLine.length() && sourceLine.charAt(i) == '\t') { sb.append('\t'); } else { sb.append(' ');
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/RecompilableScriptFunctionData.java Tue May 05 14:23:43 2015 +0200 +++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/RecompilableScriptFunctionData.java Tue May 05 14:30:00 2015 +0200 @@ -491,7 +491,7 @@ log.info("Parameter type specialization of '", functionName, "' signature: ", actualCallSiteType); } - final boolean persistentCache = usePersistentCodeCache() && persist; + final boolean persistentCache = persist && usePersistentCodeCache(); String cacheKey = null; if (persistentCache) { final TypeMap typeMap = typeMap(actualCallSiteType); @@ -518,8 +518,7 @@ } boolean usePersistentCodeCache() { - final ScriptEnvironment env = installer.getOwner(); - return env._persistent_cache && env._optimistic_types; + return installer != null && installer.getOwner()._persistent_cache; } private MethodType explicitParams(final MethodType callSiteType) {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/basic/JDK-8078612_eager_1a.js Tue May 05 14:30:00 2015 +0200 @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * JDK-8078612: Persistent code cache should support more configurations + * + * @test + * @runif external.prototype + * @option -pcc + * @option --lazy-compilation=false + * @option -Dnashorn.persistent.code.cache=build/nashorn_code_cache + * @fork + */ + +load(__DIR__ + 'prototype.js');
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/basic/JDK-8078612_eager_1a.js.EXPECTED Tue May 05 14:30:00 2015 +0200 @@ -0,0 +1,1 @@ +parsed and compiled ok prototype.js
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/basic/JDK-8078612_eager_1b.js Tue May 05 14:30:00 2015 +0200 @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * JDK-8078612: Persistent code cache should support more configurations + * + * @test + * @runif external.prototype + * @option -pcc + * @option --lazy-compilation=false + * @option -Dnashorn.persistent.code.cache=build/nashorn_code_cache + * @fork + */ + +load(__DIR__ + 'prototype.js');
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/basic/JDK-8078612_eager_1b.js.EXPECTED Tue May 05 14:30:00 2015 +0200 @@ -0,0 +1,1 @@ +parsed and compiled ok prototype.js
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/basic/JDK-8078612_eager_2a.js Tue May 05 14:30:00 2015 +0200 @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * JDK-8078612: Persistent code cache should support more configurations + * + * @test + * @runif external.yui + * @option -pcc + * @option --lazy-compilation=false + * @option -Dnashorn.persistent.code.cache=build/nashorn_code_cache + * @fork + */ + +load(__DIR__ + 'yui.js');
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/basic/JDK-8078612_eager_2a.js.EXPECTED Tue May 05 14:30:00 2015 +0200 @@ -0,0 +1,2 @@ +parsed and compiled ok yui-min.js +parsed and compiled ok yui.js
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/basic/JDK-8078612_eager_2b.js Tue May 05 14:30:00 2015 +0200 @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * JDK-8078612: Persistent code cache should support more configurations + * + * @test + * @runif external.yui + * @option -pcc + * @option --lazy-compilation=false + * @option -Dnashorn.persistent.code.cache=build/nashorn_code_cache + * @fork + */ + +load(__DIR__ + 'yui.js');
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/basic/JDK-8078612_eager_2b.js.EXPECTED Tue May 05 14:30:00 2015 +0200 @@ -0,0 +1,2 @@ +parsed and compiled ok yui-min.js +parsed and compiled ok yui.js
--- a/test/src/jdk/nashorn/internal/runtime/test/CodeStoreAndPathTest.java Tue May 05 14:23:43 2015 +0200 +++ b/test/src/jdk/nashorn/internal/runtime/test/CodeStoreAndPathTest.java Tue May 05 14:30:00 2015 +0200 @@ -162,7 +162,7 @@ e.eval(code3);// less than minimum size for storing // adding code1 and code2. final DirectoryStream<Path> stream = Files.newDirectoryStream(codeCachePath); - checkCompiledScripts(stream, 2); + checkCompiledScripts(stream, 4); } private static Path getCodeCachePath(final boolean optimistic) {