8078612: Persistent code cache should support more configurations

Tue, 05 May 2015 14:30:00 +0200

author
hannesw
date
Tue, 05 May 2015 14:30:00 +0200
changeset 1342
10e350c05d09
parent 1341
03a7733b95ed
child 1343
5bc0bcefed54

8078612: Persistent code cache should support more configurations
Reviewed-by: lagergren, attila

src/jdk/nashorn/internal/runtime/CodeStore.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/Context.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/ErrorManager.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/RecompilableScriptFunctionData.java file | annotate | diff | comparison | revisions
test/script/basic/JDK-8078612_eager_1a.js file | annotate | diff | comparison | revisions
test/script/basic/JDK-8078612_eager_1a.js.EXPECTED file | annotate | diff | comparison | revisions
test/script/basic/JDK-8078612_eager_1b.js file | annotate | diff | comparison | revisions
test/script/basic/JDK-8078612_eager_1b.js.EXPECTED file | annotate | diff | comparison | revisions
test/script/basic/JDK-8078612_eager_2a.js file | annotate | diff | comparison | revisions
test/script/basic/JDK-8078612_eager_2a.js.EXPECTED file | annotate | diff | comparison | revisions
test/script/basic/JDK-8078612_eager_2b.js file | annotate | diff | comparison | revisions
test/script/basic/JDK-8078612_eager_2b.js.EXPECTED file | annotate | diff | comparison | revisions
test/src/jdk/nashorn/internal/runtime/test/CodeStoreAndPathTest.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/jdk/nashorn/internal/runtime/CodeStore.java	Tue May 05 14:23:43 2015 +0200
     1.2 +++ b/src/jdk/nashorn/internal/runtime/CodeStore.java	Tue May 05 14:30:00 2015 +0200
     1.3 @@ -189,7 +189,7 @@
     1.4       * @param paramTypes parameter types
     1.5       * @return a string representing the function
     1.6       */
     1.7 -    public static String getCacheKey(final int functionId, final Type[] paramTypes) {
     1.8 +    public static String getCacheKey(final Object functionId, final Type[] paramTypes) {
     1.9          final StringBuilder b = new StringBuilder().append(functionId);
    1.10          if(paramTypes != null && paramTypes.length > 0) {
    1.11              b.append('-');
    1.12 @@ -275,7 +275,7 @@
    1.13  
    1.14          @Override
    1.15          public StoredScript load(final Source source, final String functionKey) {
    1.16 -            if (source.getLength() < minSize) {
    1.17 +            if (belowThreshold(source)) {
    1.18                  return null;
    1.19              }
    1.20  
     2.1 --- a/src/jdk/nashorn/internal/runtime/Context.java	Tue May 05 14:23:43 2015 +0200
     2.2 +++ b/src/jdk/nashorn/internal/runtime/Context.java	Tue May 05 14:30:00 2015 +0200
     2.3 @@ -1228,10 +1228,11 @@
     2.4  
     2.5          StoredScript storedScript = null;
     2.6          FunctionNode functionNode = null;
     2.7 -        // We only use the code store here if optimistic types are disabled. With optimistic types, initial compilation
     2.8 -        // just creates a thin wrapper, and actual code is stored per function in RecompilableScriptFunctionData.
     2.9 -        final boolean useCodeStore = codeStore != null && !env._parse_only && !env._optimistic_types;
    2.10 -        final String cacheKey = useCodeStore ? CodeStore.getCacheKey(0, null) : null;
    2.11 +        // Don't use code store if optimistic types is enabled but lazy compilation is not.
    2.12 +        // This would store a full script compilation with many wrong optimistic assumptions that would
    2.13 +        // do more harm than good on later runs with both optimistic types and lazy compilation enabled.
    2.14 +        final boolean useCodeStore = codeStore != null && !env._parse_only && (!env._optimistic_types || env._lazy_compilation);
    2.15 +        final String cacheKey = useCodeStore ? CodeStore.getCacheKey("script", null) : null;
    2.16  
    2.17          if (useCodeStore) {
    2.18              storedScript = codeStore.load(source, cacheKey);
     3.1 --- a/src/jdk/nashorn/internal/runtime/ErrorManager.java	Tue May 05 14:23:43 2015 +0200
     3.2 +++ b/src/jdk/nashorn/internal/runtime/ErrorManager.java	Tue May 05 14:30:00 2015 +0200
     3.3 @@ -113,7 +113,7 @@
     3.4  
     3.5          // Pointer to column.
     3.6          for (int i = 0; i < column; i++) {
     3.7 -            if (sourceLine.charAt(i) == '\t') {
     3.8 +            if (i < sourceLine.length() && sourceLine.charAt(i) == '\t') {
     3.9                  sb.append('\t');
    3.10              } else {
    3.11                  sb.append(' ');
     4.1 --- a/src/jdk/nashorn/internal/runtime/RecompilableScriptFunctionData.java	Tue May 05 14:23:43 2015 +0200
     4.2 +++ b/src/jdk/nashorn/internal/runtime/RecompilableScriptFunctionData.java	Tue May 05 14:30:00 2015 +0200
     4.3 @@ -491,7 +491,7 @@
     4.4              log.info("Parameter type specialization of '", functionName, "' signature: ", actualCallSiteType);
     4.5          }
     4.6  
     4.7 -        final boolean persistentCache = usePersistentCodeCache() && persist;
     4.8 +        final boolean persistentCache = persist && usePersistentCodeCache();
     4.9          String cacheKey = null;
    4.10          if (persistentCache) {
    4.11              final TypeMap typeMap = typeMap(actualCallSiteType);
    4.12 @@ -518,8 +518,7 @@
    4.13      }
    4.14  
    4.15      boolean usePersistentCodeCache() {
    4.16 -        final ScriptEnvironment env = installer.getOwner();
    4.17 -        return env._persistent_cache && env._optimistic_types;
    4.18 +        return installer != null && installer.getOwner()._persistent_cache;
    4.19      }
    4.20  
    4.21      private MethodType explicitParams(final MethodType callSiteType) {
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/test/script/basic/JDK-8078612_eager_1a.js	Tue May 05 14:30:00 2015 +0200
     5.3 @@ -0,0 +1,35 @@
     5.4 +/*
     5.5 + * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
     5.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     5.7 + * 
     5.8 + * This code is free software; you can redistribute it and/or modify it
     5.9 + * under the terms of the GNU General Public License version 2 only, as
    5.10 + * published by the Free Software Foundation.
    5.11 + * 
    5.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    5.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    5.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    5.15 + * version 2 for more details (a copy is included in the LICENSE file that
    5.16 + * accompanied this code).
    5.17 + * 
    5.18 + * You should have received a copy of the GNU General Public License version
    5.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    5.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    5.21 + * 
    5.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    5.23 + * or visit www.oracle.com if you need additional information or have any
    5.24 + * questions.
    5.25 + */
    5.26 +
    5.27 +/**
    5.28 + * JDK-8078612: Persistent code cache should support more configurations
    5.29 + *
    5.30 + * @test
    5.31 + * @runif external.prototype
    5.32 + * @option -pcc
    5.33 + * @option --lazy-compilation=false
    5.34 + * @option -Dnashorn.persistent.code.cache=build/nashorn_code_cache
    5.35 + * @fork
    5.36 + */
    5.37 +
    5.38 +load(__DIR__ + 'prototype.js');
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/test/script/basic/JDK-8078612_eager_1a.js.EXPECTED	Tue May 05 14:30:00 2015 +0200
     6.3 @@ -0,0 +1,1 @@
     6.4 +parsed and compiled ok prototype.js
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/test/script/basic/JDK-8078612_eager_1b.js	Tue May 05 14:30:00 2015 +0200
     7.3 @@ -0,0 +1,35 @@
     7.4 +/*
     7.5 + * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
     7.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     7.7 + * 
     7.8 + * This code is free software; you can redistribute it and/or modify it
     7.9 + * under the terms of the GNU General Public License version 2 only, as
    7.10 + * published by the Free Software Foundation.
    7.11 + * 
    7.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    7.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    7.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    7.15 + * version 2 for more details (a copy is included in the LICENSE file that
    7.16 + * accompanied this code).
    7.17 + * 
    7.18 + * You should have received a copy of the GNU General Public License version
    7.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    7.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    7.21 + * 
    7.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    7.23 + * or visit www.oracle.com if you need additional information or have any
    7.24 + * questions.
    7.25 + */
    7.26 +
    7.27 +/**
    7.28 + * JDK-8078612: Persistent code cache should support more configurations
    7.29 + *
    7.30 + * @test
    7.31 + * @runif external.prototype
    7.32 + * @option -pcc
    7.33 + * @option --lazy-compilation=false
    7.34 + * @option -Dnashorn.persistent.code.cache=build/nashorn_code_cache
    7.35 + * @fork
    7.36 + */
    7.37 +
    7.38 +load(__DIR__ + 'prototype.js');
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/test/script/basic/JDK-8078612_eager_1b.js.EXPECTED	Tue May 05 14:30:00 2015 +0200
     8.3 @@ -0,0 +1,1 @@
     8.4 +parsed and compiled ok prototype.js
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/test/script/basic/JDK-8078612_eager_2a.js	Tue May 05 14:30:00 2015 +0200
     9.3 @@ -0,0 +1,35 @@
     9.4 +/*
     9.5 + * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
     9.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     9.7 + * 
     9.8 + * This code is free software; you can redistribute it and/or modify it
     9.9 + * under the terms of the GNU General Public License version 2 only, as
    9.10 + * published by the Free Software Foundation.
    9.11 + * 
    9.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    9.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    9.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    9.15 + * version 2 for more details (a copy is included in the LICENSE file that
    9.16 + * accompanied this code).
    9.17 + * 
    9.18 + * You should have received a copy of the GNU General Public License version
    9.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    9.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    9.21 + * 
    9.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    9.23 + * or visit www.oracle.com if you need additional information or have any
    9.24 + * questions.
    9.25 + */
    9.26 +
    9.27 +/**
    9.28 + * JDK-8078612: Persistent code cache should support more configurations
    9.29 + *
    9.30 + * @test
    9.31 + * @runif external.yui
    9.32 + * @option -pcc
    9.33 + * @option --lazy-compilation=false
    9.34 + * @option -Dnashorn.persistent.code.cache=build/nashorn_code_cache
    9.35 + * @fork
    9.36 + */
    9.37 +
    9.38 +load(__DIR__ + 'yui.js');
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/test/script/basic/JDK-8078612_eager_2a.js.EXPECTED	Tue May 05 14:30:00 2015 +0200
    10.3 @@ -0,0 +1,2 @@
    10.4 +parsed and compiled ok yui-min.js
    10.5 +parsed and compiled ok yui.js
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/test/script/basic/JDK-8078612_eager_2b.js	Tue May 05 14:30:00 2015 +0200
    11.3 @@ -0,0 +1,35 @@
    11.4 +/*
    11.5 + * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
    11.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    11.7 + * 
    11.8 + * This code is free software; you can redistribute it and/or modify it
    11.9 + * under the terms of the GNU General Public License version 2 only, as
   11.10 + * published by the Free Software Foundation.
   11.11 + * 
   11.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   11.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   11.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   11.15 + * version 2 for more details (a copy is included in the LICENSE file that
   11.16 + * accompanied this code).
   11.17 + * 
   11.18 + * You should have received a copy of the GNU General Public License version
   11.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   11.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   11.21 + * 
   11.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   11.23 + * or visit www.oracle.com if you need additional information or have any
   11.24 + * questions.
   11.25 + */
   11.26 +
   11.27 +/**
   11.28 + * JDK-8078612: Persistent code cache should support more configurations
   11.29 + *
   11.30 + * @test
   11.31 + * @runif external.yui
   11.32 + * @option -pcc
   11.33 + * @option --lazy-compilation=false
   11.34 + * @option -Dnashorn.persistent.code.cache=build/nashorn_code_cache
   11.35 + * @fork
   11.36 + */
   11.37 +
   11.38 +load(__DIR__ + 'yui.js');
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/test/script/basic/JDK-8078612_eager_2b.js.EXPECTED	Tue May 05 14:30:00 2015 +0200
    12.3 @@ -0,0 +1,2 @@
    12.4 +parsed and compiled ok yui-min.js
    12.5 +parsed and compiled ok yui.js
    13.1 --- a/test/src/jdk/nashorn/internal/runtime/test/CodeStoreAndPathTest.java	Tue May 05 14:23:43 2015 +0200
    13.2 +++ b/test/src/jdk/nashorn/internal/runtime/test/CodeStoreAndPathTest.java	Tue May 05 14:30:00 2015 +0200
    13.3 @@ -162,7 +162,7 @@
    13.4          e.eval(code3);// less than minimum size for storing
    13.5          // adding code1 and code2.
    13.6          final DirectoryStream<Path> stream = Files.newDirectoryStream(codeCachePath);
    13.7 -        checkCompiledScripts(stream, 2);
    13.8 +        checkCompiledScripts(stream, 4);
    13.9      }
   13.10  
   13.11      private static Path getCodeCachePath(final boolean optimistic) {

mercurial