jdk.nashorn.internal.runtime.logging.DebugLogger Java Examples

The following examples show how to use jdk.nashorn.internal.runtime.logging.DebugLogger. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ApplySpecialization.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private boolean hasApplies(final FunctionNode functionNode) {
    try {
        functionNode.accept(new SimpleNodeVisitor() {
            @Override
            public boolean enterFunctionNode(final FunctionNode fn) {
                return fn == functionNode;
            }

            @Override
            public boolean enterCallNode(final CallNode callNode) {
                if (isApply(callNode)) {
                    throw HAS_APPLIES;
                }
                return true;
            }
        });
    } catch (final AppliesFoundException e) {
        return true;
    }

    log.fine("There are no applies in ", DebugLogger.quote(functionNode.getName()), " - nothing to do.");
    return false; // no applies
}
 
Example #2
Source File: ApplySpecialization.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private boolean hasApplies(final FunctionNode functionNode) {
    try {
        functionNode.accept(new SimpleNodeVisitor() {
            @Override
            public boolean enterFunctionNode(final FunctionNode fn) {
                return fn == functionNode;
            }

            @Override
            public boolean enterCallNode(final CallNode callNode) {
                if (isApply(callNode)) {
                    throw HAS_APPLIES;
                }
                return true;
            }
        });
    } catch (final AppliesFoundException e) {
        return true;
    }

    log.fine("There are no applies in ", DebugLogger.quote(functionNode.getName()), " - nothing to do.");
    return false; // no applies
}
 
Example #3
Source File: CompiledFunction.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
CompiledFunction(final MethodHandle invoker, final MethodHandle constructor, final int flags, final MethodType callSiteType, final Specialization specialization, final DebugLogger log) {
    this.specialization = specialization;
    if (specialization != null && specialization.isOptimistic()) {
        /*
         * An optimistic builtin with isOptimistic=true works like any optimistic generated function, i.e. it
         * can throw unwarranted optimism exceptions. As native functions trivially can't have parts of them
         * regenerated as "restOf" methods, this only works if the methods are atomic/functional in their behavior
         * and doesn't modify state before an UOE can be thrown. If they aren't, we can reexecute a wider version
         * of the same builtin in a recompilation handler for FinalScriptFunctionData. There are several
         * candidate methods in Native* that would benefit from this, but I haven't had time to implement any
         * of them currently. In order to fit in with the relinking framework, the current thinking is
         * that the methods still take a program point to fit in with other optimistic functions, but
         * it is set to "first", which is the beginning of the method. The relinker can tell the difference
         * between builtin and JavaScript functions. This might change. TODO
         */
        this.invoker = MH.insertArguments(invoker, invoker.type().parameterCount() - 1, UnwarrantedOptimismException.FIRST_PROGRAM_POINT);
        throw new AssertionError("Optimistic (UnwarrantedOptimismException throwing) builtin functions are currently not in use");
    }
    this.invoker = invoker;
    this.constructor = constructor;
    this.flags = flags;
    this.callSiteType = callSiteType;
    this.log = log;
}
 
Example #4
Source File: MethodHandleFactory.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tracer that is applied before a function is called, printing the arguments
 *
 * @param tag  tag to start the debug printout string
 * @param paramStart param index to start outputting from
 * @param args arguments to the function
 */
static void traceArgs(final DebugLogger logger, final String tag, final int paramStart, final Object... args) {
    final StringBuilder sb = new StringBuilder();

    sb.append(tag);

    for (int i = paramStart; i < args.length; i++) {
        if (i == paramStart) {
            sb.append(" => args: ");
        }

        sb.append('\'').
            append(stripName(argString(args[i]))).
            append('\'').
            append(' ').
            append('[').
            append("type=").
            append(args[i] == null ? "null" : stripName(args[i].getClass())).
            append(']');

        if (i + 1 < args.length) {
            sb.append(", ");
        }
    }

    if (logger == null) {
        err(sb.toString());
    } else {
        logger.log(TRACE_LEVEL, sb);
    }
    stacktrace(logger);
}
 
Example #5
Source File: Compiler.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
@Override
public DebugLogger initLogger(final Context ctxt) {
    final boolean optimisticTypes = env._optimistic_types;
    final boolean lazyCompilation = env._lazy_compilation;

    return ctxt.getLogger(this.getClass(), new Consumer<DebugLogger>() {
        @Override
        public void accept(final DebugLogger newLogger) {
            if (!lazyCompilation) {
                newLogger.warning("WARNING: Running with lazy compilation switched off. This is not a default setting.");
            }
            newLogger.warning("Optimistic types are ", optimisticTypes ? "ENABLED." : "DISABLED.");
        }
    });
}
 
Example #6
Source File: OptimisticTypesPersistence.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static DebugLogger getLogger() {
    try {
        return Context.getContext().getLogger(RecompilableScriptFunctionData.class);
    } catch (final Exception e) {
        e.printStackTrace();
        return DebugLogger.DISABLED_LOGGER;
    }
}
 
Example #7
Source File: MethodHandleFactory.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tracer that is applied before a value is returned from the traced function. It will output the return
 * value and its class
 *
 * @param value return value for filter
 * @return return value unmodified
 */
static Object traceReturn(final DebugLogger logger, final Object value) {
    final String str = "    return" +
            (VOID_TAG.equals(value) ?
                    ";" :
                        " " + stripName(value) + "; // [type=" + (value == null ? "null]" : stripName(value.getClass()) + ']'));
    if (logger == null) {
        err(str);
    } else if (logger.isEnabled()) {
        logger.log(TRACE_LEVEL, str);
    }

    return value;
}
 
Example #8
Source File: MethodHandleFactory.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tracer that is applied before a value is returned from the traced function. It will output the return
 * value and its class
 *
 * @param value return value for filter
 * @return return value unmodified
 */
static Object traceReturn(final DebugLogger logger, final Object value) {
    final String str = "    return" +
            (VOID_TAG.equals(value) ?
                    ";" :
                        " " + stripName(value) + "; // [type=" + (value == null ? "null]" : stripName(value.getClass()) + ']'));
    if (logger == null) {
        err(str);
    } else if (logger.isEnabled()) {
        logger.log(TRACE_LEVEL, str);
    }

    return value;
}
 
Example #9
Source File: MethodHandleFactory.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tracer that is applied before a function is called, printing the arguments
 *
 * @param tag  tag to start the debug printout string
 * @param paramStart param index to start outputting from
 * @param args arguments to the function
 */
static void traceArgs(final DebugLogger logger, final String tag, final int paramStart, final Object... args) {
    final StringBuilder sb = new StringBuilder();

    sb.append(tag);

    for (int i = paramStart; i < args.length; i++) {
        if (i == paramStart) {
            sb.append(" => args: ");
        }

        sb.append('\'').
        append(stripName(argString(args[i]))).
        append('\'').
        append(' ').
        append('[').
        append("type=").
        append(args[i] == null ? "null" : stripName(args[i].getClass())).
        append(']');

        if (i + 1 < args.length) {
            sb.append(", ");
        }
    }

    if (logger == null) {
        err(sb.toString());
    } else {
        logger.log(TRACE_LEVEL, sb);
    }
    stacktrace(logger);
}
 
Example #10
Source File: MethodHandleFactory.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tracer that is applied before a function is called, printing the arguments
 *
 * @param tag  tag to start the debug printout string
 * @param paramStart param index to start outputting from
 * @param args arguments to the function
 */
static void traceArgs(final DebugLogger logger, final String tag, final int paramStart, final Object... args) {
    final StringBuilder sb = new StringBuilder();

    sb.append(tag);

    for (int i = paramStart; i < args.length; i++) {
        if (i == paramStart) {
            sb.append(" => args: ");
        }

        sb.append('\'').
        append(stripName(argString(args[i]))).
        append('\'').
        append(' ').
        append('[').
        append("type=").
        append(args[i] == null ? "null" : stripName(args[i].getClass())).
        append(']');

        if (i + 1 < args.length) {
            sb.append(", ");
        }
    }

    if (logger == null) {
        err(sb.toString());
    } else {
        logger.log(TRACE_LEVEL, sb);
    }
    stacktrace(logger);
}
 
Example #11
Source File: CompiledFunction.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private void logRecompile(final String reason, final FunctionNode fn, final MethodType type, final Map<Integer, Type> ipp) {
    if (log.isEnabled()) {
        log.info(reason, DebugLogger.quote(fn.getName()), " signature: ", type);
        log.indent();
        for (final String str : toStringInvalidations(ipp)) {
            log.fine(str);
        }
        log.unindent();
    }
}
 
Example #12
Source File: OptimisticTypesPersistence.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static DebugLogger getLogger() {
    try {
        return Context.getContext().getLogger(RecompilableScriptFunctionData.class);
    } catch (final Exception e) {
        e.printStackTrace();
        return DebugLogger.DISABLED_LOGGER;
    }
}
 
Example #13
Source File: ApplySpecialization.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveCallNode(final CallNode callNode) {
    //apply needs to be a global symbol or we don't allow it

    final List<IdentNode> newParams = explodedArguments.peek();
    if (isApply(callNode)) {
        final List<Expression> newArgs = new ArrayList<>();
        for (final Expression arg : callNode.getArgs()) {
            if (arg instanceof IdentNode && ARGUMENTS.equals(((IdentNode)arg).getName())) {
                newArgs.addAll(newParams);
            } else {
                newArgs.add(arg);
            }
        }

        changed.add(lc.getCurrentFunction().getId());

        final CallNode newCallNode = callNode.setArgs(newArgs).setIsApplyToCall();

        if (log.isEnabled()) {
            log.fine("Transformed ",
                    callNode,
                    " from apply to call => ",
                    newCallNode,
                    " in ",
                    DebugLogger.quote(lc.getCurrentFunction().getName()));
        }

        return newCallNode;
    }

    return callNode;
}
 
Example #14
Source File: MethodHandleFactory.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add a debug printout to a method handle, tracing parameters and return values
 *
 * @param logger a specific logger to which to write the output
 * @param level level over which to print
 * @param mh  method handle to trace
 * @param paramStart first param to print/trace
 * @param printReturnValue should we print/trace return value if available?
 * @param tag start of trace message
 * @return  traced method handle
 */
public static MethodHandle addDebugPrintout(final DebugLogger logger, final Level level, final MethodHandle mh, final int paramStart, final boolean printReturnValue, final Object tag) {
    final MethodType type = mh.type();

    //if there is no logger, or if it's set to log only coarser events
    //than the trace level, skip and return
    if (logger == null || !logger.isLoggable(level)) {
        return mh;
    }

    assert TRACE != null;

    MethodHandle trace = MethodHandles.insertArguments(TRACE, 0, logger, tag, paramStart);

    trace = MethodHandles.foldArguments(
            mh,
            trace.asCollector(
                    Object[].class,
                    type.parameterCount()).
                    asType(type.changeReturnType(void.class)));

    final Class<?> retType = type.returnType();
    if (printReturnValue) {
        if (retType != void.class) {
            final MethodHandle traceReturn = MethodHandles.insertArguments(TRACE_RETURN, 0, logger);
            trace = MethodHandles.filterReturnValue(trace,
                    traceReturn.asType(
                            traceReturn.type().changeParameterType(0, retType).changeReturnType(retType)));
        } else {
            trace = MethodHandles.filterReturnValue(trace, MethodHandles.insertArguments(TRACE_RETURN_VOID, 0, logger));
        }
    }

    return trace;
}
 
Example #15
Source File: CompiledFunction.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private void logRecompile(final String reason, final FunctionNode fn, final MethodType type, final Map<Integer, Type> ipp) {
    if (log.isEnabled()) {
        log.info(reason, DebugLogger.quote(fn.getName()), " signature: ", type);
        log.indent();
        for (final String str : toStringInvalidations(ipp)) {
            log.fine(str);
        }
        log.unindent();
    }
}
 
Example #16
Source File: Compiler.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public DebugLogger initLogger(final Context ctxt) {
    final boolean optimisticTypes = env._optimistic_types;
    final boolean lazyCompilation = env._lazy_compilation;

    return ctxt.getLogger(this.getClass(), new Consumer<DebugLogger>() {
        @Override
        public void accept(final DebugLogger newLogger) {
            if (!lazyCompilation) {
                newLogger.warning("WARNING: Running with lazy compilation switched off. This is not a default setting.");
            }
            newLogger.warning("Optimistic types are ", optimisticTypes ? "ENABLED." : "DISABLED.");
        }
    });
}
 
Example #17
Source File: OptimisticTypesPersistence.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static DebugLogger getLogger() {
    try {
        return Context.getContext().getLogger(RecompilableScriptFunctionData.class);
    } catch (final Exception e) {
        e.printStackTrace();
        return DebugLogger.DISABLED_LOGGER;
    }
}
 
Example #18
Source File: Lower.java    From jdk8u_nashorn with GNU General Public License v2.0 4 votes vote down vote up
@Override
public DebugLogger getLogger() {
    return log;
}
 
Example #19
Source File: Source.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
private static DebugLogger getLoggerStatic() {
    final Context context = Context.getContextTrustedOrNull();
    return context == null ? null : context.getLogger(Source.class);
}
 
Example #20
Source File: Parser.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public DebugLogger getLogger() {
    return log;
}
 
Example #21
Source File: Parser.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public DebugLogger initLogger(final Context context) {
    return context.getLogger(this.getClass());
}
 
Example #22
Source File: Parser.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Override
public DebugLogger getLogger() {
    return log;
}
 
Example #23
Source File: FoldConstants.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public DebugLogger initLogger(final Context context) {
    return context.getLogger(this.getClass());
}
 
Example #24
Source File: ApplySpecialization.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public DebugLogger initLogger(final Context context) {
    return context.getLogger(this.getClass());
}
 
Example #25
Source File: RecompilableScriptFunctionData.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Override
public DebugLogger initLogger(final Context ctxt) {
    return ctxt.getLogger(this.getClass());
}
 
Example #26
Source File: FindScopeDepths.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Override
public DebugLogger getLogger() {
    return log;
}
 
Example #27
Source File: Splitter.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Override
public DebugLogger initLogger(final Context context) {
    return context.getLogger(this.getClass());
}
 
Example #28
Source File: Compiler.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public DebugLogger getLogger() {
    return log;
}
 
Example #29
Source File: ObjectClassGenerator.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public DebugLogger initLogger(final Context ctxt) {
    return ctxt.getLogger(this.getClass());
}
 
Example #30
Source File: MethodHandleFactory.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
static void traceReturnVoid(final DebugLogger logger) {
    traceReturn(logger, VOID_TAG);
}