8078612: Persistent code cache should support more configurations

Reviewed-by: lagergren, attila
This commit is contained in:
Hannes Wallnöfer 2015-05-05 14:30:00 +02:00
parent b3fa231c01
commit 08e8a63ab5
13 changed files with 157 additions and 11 deletions

View File

@ -189,7 +189,7 @@ public abstract class CodeStore implements Loggable {
* @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 @@ public abstract class CodeStore implements Loggable {
@Override
public StoredScript load(final Source source, final String functionKey) {
if (source.getLength() < minSize) {
if (belowThreshold(source)) {
return null;
}

View File

@ -1228,10 +1228,11 @@ public final class Context {
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);

View File

@ -113,7 +113,7 @@ public class ErrorManager {
// 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(' ');

View File

@ -491,7 +491,7 @@ public final class RecompilableScriptFunctionData extends ScriptFunctionData imp
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 @@ public final class RecompilableScriptFunctionData extends ScriptFunctionData imp
}
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) {

View File

@ -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');

View File

@ -0,0 +1 @@
parsed and compiled ok prototype.js

View File

@ -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');

View File

@ -0,0 +1 @@
parsed and compiled ok prototype.js

View File

@ -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');

View File

@ -0,0 +1,2 @@
parsed and compiled ok yui-min.js
parsed and compiled ok yui.js

View File

@ -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');

View File

@ -0,0 +1,2 @@
parsed and compiled ok yui-min.js
parsed and compiled ok yui.js

View File

@ -162,7 +162,7 @@ public class CodeStoreAndPathTest {
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) {