提交 d5ec76cf 编写于 作者: L lagergren

8046898: Make sure that lazy compilation is the default, remove redundant...

8046898: Make sure that lazy compilation is the default, remove redundant "enable lazy compilation" flags, added warning message if compile logging is enabled and lazy is switched off. Verified existing test suite code coverage equivalence between lazy and eager.
Reviewed-by: attila, hannesw
上级 30812584
......@@ -412,6 +412,10 @@ public final class MemberInfo implements Cloneable {
}
}
}
break;
default:
break;
}
}
......@@ -450,7 +454,7 @@ public final class MemberInfo implements Cloneable {
if (type.getSort() == Type.OBJECT) {
try {
final Class clazz = Class.forName(type.getClassName(), false, myLoader);
final Class<?> clazz = Class.forName(type.getClassName(), false, myLoader);
return ScriptObject.class.isAssignableFrom(clazz);
} catch (final ClassNotFoundException cnfe) {
return false;
......
......@@ -283,7 +283,7 @@ run.test.jvmargs.common=\
-XX:+HeapDumpOnOutOfMemoryError
# turn on assertions for tests
run.test.jvmargs.main=${run.test.jvmargs.common} -ea -Dnashorn.lazy
run.test.jvmargs.main=${run.test.jvmargs.common} -ea
# extra jvmargs that might be useful for debugging
#
......@@ -305,7 +305,7 @@ run.test.jvmargs.main=${run.test.jvmargs.common} -ea -Dnashorn.lazy
# -XX:+PrintNMethods
# Use best known performance options for octane
run.test.jvmargs.octane.main=${run.test.jvmargs.common} -Dnashorn.lazy -XX:+UnlockDiagnosticVMOptions -XX:+UseNewCode -XX:TypeProfileLevel=222
run.test.jvmargs.octane.main=${run.test.jvmargs.common} -XX:+UnlockDiagnosticVMOptions -XX:+UseNewCode -XX:TypeProfileLevel=222
# Security manager args - make sure that we run with the nashorn.policy that the build creates
run.test.jvmsecurityargs=-Xverify:all -Djava.security.manager -Djava.security.policy=${basedir}/build/nashorn.policy
......
......@@ -47,7 +47,9 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
import java.util.logging.Level;
import jdk.internal.dynalink.support.NameCodec;
import jdk.nashorn.internal.codegen.ClassEmitter.Flag;
import jdk.nashorn.internal.codegen.types.Type;
......@@ -421,7 +423,14 @@ public final class Compiler implements Loggable {
@Override
public DebugLogger initLogger(final Context ctxt) {
return ctxt.getLogger(this.getClass());
return ctxt.getLogger(this.getClass(), new Consumer<DebugLogger>() {
@Override
public void accept(final DebugLogger newLogger) {
if (!Compiler.this.getScriptEnvironment()._lazy_compilation) {
newLogger.warning("WARNING: Running with lazy compilation switched off. This is not a default setting.");
}
}
});
}
ScriptEnvironment getScriptEnvironment() {
......
......@@ -45,7 +45,7 @@ import jdk.nashorn.internal.parser.TokenType;
public final class BinaryNode extends Expression implements Assignment<Expression>, Optimistic {
// Placeholder for "undecided optimistic ADD type". Unfortunately, we can't decide the type of ADD during optimistic
// type calculation as it can have local variables as its operands that will decide its ultimate type.
private static final Type OPTIMISTIC_UNDECIDED_TYPE = Type.typeFor(new Object(){}.getClass());
private static final Type OPTIMISTIC_UNDECIDED_TYPE = Type.typeFor(new Object(){/*empty*/}.getClass());
/** Left hand side argument. */
private final Expression lhs;
......
......@@ -99,7 +99,7 @@ public final class FunctionNode extends LexicalContextExpression implements Flag
BYTECODE_GENERATED,
/** method has been installed */
BYTECODE_INSTALLED
};
}
/** Source of entity. */
private final Source source;
......@@ -388,10 +388,11 @@ public final class FunctionNode extends LexicalContextExpression implements Flag
}
/**
* static source name getter
* Static source name getter
*
* @param source
* @param sourceURL
* @return
* @return source name
*/
public static String getSourceName(final Source source, final String sourceURL) {
return sourceURL != null ? sourceURL : source.getName();
......
......@@ -75,7 +75,10 @@ import jdk.nashorn.internal.runtime.linker.NashornBeansLinker;
*/
@ScriptClass("Object")
public final class NativeObject {
/** Methodhandle to proto getter */
public static final MethodHandle GET__PROTO__ = findOwnMH("get__proto__", ScriptObject.class, Object.class);
/** Methodhandle to proto setter */
public static final MethodHandle SET__PROTO__ = findOwnMH("set__proto__", Object.class, Object.class, Object.class);
private static final Object TO_STRING = new Object();
......
......@@ -1236,6 +1236,16 @@ public final class Context {
* @return debuglogger associated with that class
*/
public DebugLogger getLogger(final Class<? extends Loggable> clazz) {
return getLogger(clazz, null);
}
/**
* Get a logger, given a loggable class
* @param clazz a Loggable class
* @param initHook an init hook - if this is the first time the logger is created in the context, run the init hook
* @return debuglogger associated with that class
*/
public DebugLogger getLogger(final Class<? extends Loggable> clazz, final Consumer<DebugLogger> initHook) {
final String name = getLoggerName(clazz);
DebugLogger logger = loggers.get(name);
if (logger == null) {
......@@ -1244,6 +1254,9 @@ public final class Context {
}
final LoggerInfo info = env._loggers.get(name);
logger = new DebugLogger(name, info.getLevel(), info.isQuiet());
if (initHook != null) {
initHook.accept(logger);
}
loggers.put(name, logger);
}
return logger;
......
......@@ -34,6 +34,8 @@ import java.lang.invoke.MethodType;
*/
final class FinalScriptFunctionData extends ScriptFunctionData {
private static final long serialVersionUID = -930632846167768864L;
/**
* Constructor - used for bind
*
......
......@@ -185,6 +185,7 @@ public final class PropertyMap implements Iterable<Object>, Serializable {
* properties with keys that are valid array indices.</p>
*
* @param properties Collection of initial properties.
* @param className class name
* @param fieldCount Number of fields in use.
* @param fieldMaximum Number of fields available.
* @param spillLength Number of used spill slots.
......
......@@ -54,7 +54,6 @@ import jdk.nashorn.internal.parser.TokenType;
import jdk.nashorn.internal.runtime.logging.DebugLogger;
import jdk.nashorn.internal.runtime.logging.Loggable;
import jdk.nashorn.internal.runtime.logging.Logger;
import jdk.nashorn.internal.runtime.options.Options;
import jdk.nashorn.internal.scripts.JS;
/**
......@@ -65,9 +64,6 @@ import jdk.nashorn.internal.scripts.JS;
*/
@Logger(name="recompile")
public final class RecompilableScriptFunctionData extends ScriptFunctionData implements Loggable {
/** Is lazy compilation enabled? TODO: this should be the default */
public static final boolean LAZY_COMPILATION = Options.getBooleanProperty("nashorn.lazy");
/** Prefix used for all recompiled script classes */
public static final String RECOMPILATION_PREFIX = "Recompilation$";
......@@ -240,6 +236,12 @@ public final class RecompilableScriptFunctionData extends ScriptFunctionData imp
return "function " + (name == null ? "" : name) + "() { [native code] }";
}
/**
* Setter for code and source
*
* @param code map of code, class name to class
* @param source source
*/
public void setCodeAndSource(final Map<String, Class<?>> code, final Source source) {
this.source = source;
if (methodLocator != null) {
......
......@@ -2267,7 +2267,7 @@ public abstract class ScriptObject implements PropertyAccess {
if (mh != null) {
assert func != null;
if (scopeAccess && func != null && func.isStrict()) {
if (scopeAccess && func.isStrict()) {
mh = bindTo(mh, UNDEFINED);
}
return new GuardedInvocation(
......
......@@ -99,12 +99,13 @@ public final class Source implements Loggable {
// Force any access errors
data.checkPermissionAndClose();
return existingSource;
} else {
// All sources in cache must be fully loaded
data.load();
CACHE.put(newSource, newSource);
return newSource;
}
// All sources in cache must be fully loaded
data.load();
CACHE.put(newSource, newSource);
return newSource;
} catch (final RuntimeException e) {
final Throwable cause = e.getCause();
if (cause instanceof IOException) {
......@@ -291,7 +292,9 @@ public final class Source implements Loggable {
}
protected void checkPermissionAndClose() throws IOException {
try (InputStream in = url.openStream()) {}
try (InputStream in = url.openStream()) {
// empty
}
debug("permission checked for ", url);
}
......@@ -366,20 +369,24 @@ public final class Source implements Loggable {
}
/**
* Returns an instance
* Returns a Source instance
*
* @param name source name
* @param content contents as char array
*
* @return source instance
*/
public static Source sourceFor(final String name, final char[] content) {
return new Source(name, baseName(name), new RawData(content));
}
/**
* Returns an instance
* Returns a Source instance
*
* @param name source name
* @param content contents as string
*
* @return source instance
*/
public static Source sourceFor(final String name, final String content) {
return new Source(name, baseName(name), new RawData(content));
......@@ -391,6 +398,8 @@ public final class Source implements Loggable {
* @param name source name
* @param url url from which source can be loaded
*
* @return source instance
*
* @throws IOException if source cannot be loaded
*/
public static Source sourceFor(final String name, final URL url) throws IOException {
......@@ -404,6 +413,8 @@ public final class Source implements Loggable {
* @param url url from which source can be loaded
* @param cs Charset used to convert bytes to chars
*
* @return source instance
*
* @throws IOException if source cannot be loaded
*/
public static Source sourceFor(final String name, final URL url, final Charset cs) throws IOException {
......@@ -416,6 +427,8 @@ public final class Source implements Loggable {
* @param name source name
* @param file file from which source can be loaded
*
* @return source instance
*
* @throws IOException if source cannot be loaded
*/
public static Source sourceFor(final String name, final File file) throws IOException {
......@@ -429,6 +442,8 @@ public final class Source implements Loggable {
* @param file file from which source can be loaded
* @param cs Charset used to convert bytes to chars
*
* @return source instance
*
* @throws IOException if source cannot be loaded
*/
public static Source sourceFor(final String name, final File file, final Charset cs) throws IOException {
......@@ -441,6 +456,9 @@ public final class Source implements Loggable {
*
* @param name source name
* @param reader reader from which source can be loaded
*
* @return source instance
*
* @throws IOException if source cannot be loaded
*/
public static Source sourceFor(final String name, final Reader reader) throws IOException {
......@@ -542,9 +560,9 @@ public final class Source implements Loggable {
* @return Index of first character of line.
*/
private int findBOLN(final int position) {
final char[] data = data();
final char[] d = data();
for (int i = position - 1; i > 0; i--) {
final char ch = data[i];
final char ch = d[i];
if (ch == '\n' || ch == '\r') {
return i + 1;
......@@ -560,10 +578,10 @@ public final class Source implements Loggable {
* @return Index of last character of line.
*/
private int findEOLN(final int position) {
final char[] data = data();
final int length = data.length;
final char[] d = data();
final int length = d.length;
for (int i = position; i < length; i++) {
final char ch = data[i];
final char ch = d[i];
if (ch == '\n' || ch == '\r') {
return i - 1;
......@@ -583,12 +601,12 @@ public final class Source implements Loggable {
* @return Line number.
*/
public int getLine(final int position) {
final char[] data = data();
final char[] d = data();
// Line count starts at 1.
int line = 1;
for (int i = 0; i < position; i++) {
final char ch = data[i];
final char ch = d[i];
// Works for both \n and \r\n.
if (ch == '\n') {
line++;
......
......@@ -141,21 +141,6 @@ abstract class ArrayFilter extends ArrayData {
return this;
}
private static void printTrace(final Throwable t, final String msg) {
final java.io.StringWriter sw = new java.io.StringWriter();
final java.io.PrintWriter pw = new java.io.PrintWriter(sw, false);
pw.println(msg);
final StackTraceElement[] trace = t.getStackTrace();
for(final StackTraceElement e: trace) {
pw.println(" at " + e);
if(e.getClassName().startsWith("jdk.nashorn.")) {
break;
}
}
pw.flush();
System.out.println(sw.toString());
}
@Override
public Type getOptimisticType() {
return underlying.getOptimisticType();
......
......@@ -540,7 +540,7 @@ public final class DebugLogger {
/**
* Shorthand for outputting a log string as log level
* {@link java.util.logging.Level#FINE} on this logger
* {@link java.util.logging.Level#SEVERE} on this logger
* @param objs object array to log - use this to perform lazy concatenation to avoid unconditional toString overhead
*/
public void severe(final Object... objs) {
......
......@@ -23,6 +23,14 @@
* questions.
*/
/**
* Interface for callbacks used by the test suite.
*/
public interface UnnamedPackageTestCallback {
/**
* Call function
* @param s string argument
* @return string
*/
String call(String s);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册