# HG changeset patch # User attila # Date 1415719057 -3600 # Node ID 628304057fce59372245d34a8a9e936125d25a8e # Parent 99571b7922c0d98145d4dca01dde5d07e79a715a 8064467: type info persistence failed to calculate directory name Reviewed-by: hannesw, lagergren diff -r 99571b7922c0 -r 628304057fce make/build.xml --- a/make/build.xml Mon Nov 03 09:49:52 2014 +0100 +++ b/make/build.xml Tue Nov 11 16:17:37 2014 +0100 @@ -155,6 +155,7 @@ + ${line.separator} diff -r 99571b7922c0 -r 628304057fce src/jdk/nashorn/internal/codegen/OptimisticTypesPersistence.java --- a/src/jdk/nashorn/internal/codegen/OptimisticTypesPersistence.java Mon Nov 03 09:49:52 2014 +0100 +++ b/src/jdk/nashorn/internal/codegen/OptimisticTypesPersistence.java Tue Nov 11 16:17:37 2014 +0100 @@ -33,6 +33,8 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.io.PrintWriter; +import java.io.StringWriter; import java.net.URL; import java.nio.file.Files; import java.nio.file.Path; @@ -221,11 +223,37 @@ private static void reportError(final String msg, final File file, final Exception e) { final long now = System.currentTimeMillis(); if(now - lastReportedError > ERROR_REPORT_THRESHOLD) { - getLogger().warning(String.format("Failed to %s %s", msg, file), e); + reportError(String.format("Failed to %s %s", msg, file), e); lastReportedError = now; } } + /** + * Logs an error message with warning severity (reasoning being that we're reporting an error that'll disable the + * type info cache, but it's only logged as a warning because that doesn't prevent Nashorn from running, it just + * disables a performance-enhancing cache). + * @param msg the message to log + * @param e the exception that represents the error. + */ + private static void reportError(final String msg, final Exception e) { + getLogger().warning(msg, "\n", exceptionToString(e)); + } + + /** + * A helper that prints an exception stack trace into a string. We have to do this as if we just pass the exception + * to {@link DebugLogger#warning(Object...)}, it will only log the exception message and not the stack, making + * problems harder to diagnose. + * @param e the exception + * @return the string representation of {@link Exception#printStackTrace()} output. + */ + private static String exceptionToString(final Exception e) { + final StringWriter sw = new StringWriter(); + final PrintWriter pw = new PrintWriter(sw, false); + e.printStackTrace(pw); + pw.flush(); + return sw.toString(); + } + private static File createBaseCacheDir() { if(MAX_FILES == 0 || Options.getBooleanProperty("nashorn.typeInfo.disabled")) { return null; @@ -233,7 +261,7 @@ try { return createBaseCacheDirPrivileged(); } catch(final Exception e) { - getLogger().warning("Failed to create cache dir", e); + reportError("Failed to create cache dir", e); return null; } } @@ -267,7 +295,7 @@ try { return createCacheDirPrivileged(baseDir); } catch(final Exception e) { - getLogger().warning("Failed to create cache dir", e); + reportError("Failed to create cache dir", e); return null; } } @@ -280,7 +308,7 @@ try { versionDirName = getVersionDirName(); } catch(final Exception e) { - getLogger().warning("Failed to calculate version dir name", e); + reportError("Failed to calculate version dir name", e); return null; } final File versionDir = new File(baseDir, versionDirName); @@ -328,7 +356,12 @@ * @throws Exception if digest could not be created */ public static String getVersionDirName() throws Exception { - final URL url = OptimisticTypesPersistence.class.getResource(""); + // NOTE: getResource("") won't work if the JAR file doesn't have directory entries (and JAR files in JDK distro + // don't, or at least it's a bad idea counting on it). Alternatively, we could've tried + // getResource("OptimisticTypesPersistence.class") but behavior of getResource with regard to its willingness + // to hand out URLs to .class files is also unspecified. Therefore, the most robust way to obtain an URL to our + // package is to have a small non-class anchor file and start out from its URL. + final URL url = OptimisticTypesPersistence.class.getResource("anchor.properties"); final String protocol = url.getProtocol(); if (protocol.equals("jar")) { // Normal deployment: nashorn.jar diff -r 99571b7922c0 -r 628304057fce src/jdk/nashorn/internal/codegen/anchor.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/jdk/nashorn/internal/codegen/anchor.properties Tue Nov 11 16:17:37 2014 +0100 @@ -0,0 +1,27 @@ +# +# Copyright (c) 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. Oracle designates this +# particular file as subject to the "Classpath" exception as provided +# by Oracle in the LICENSE file that accompanied this code. +# +# 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. +# + + +# This file exists only so OptimisticTypesPersistence.getVersionDirName() can take its URL.