jdk.nashorn.internal.runtime.events.RuntimeEvent Java Examples

The following examples show how to use jdk.nashorn.internal.runtime.events.RuntimeEvent. 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: NativeDebug.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Remove a specific runtime event from the event queue
 * @param self self reference
 * @param event event to remove
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static void removeRuntimeEvent(final Object self, final Object event) {
    final LinkedList<RuntimeEvent<?>> q  = getEventQueue(self);
    final RuntimeEvent<?>             re = getEvent(event);
    if (!q.remove(re)) {
        throw new IllegalStateException("runtime event " + re + " was not in event queue");
    }
}
 
Example #2
Source File: DebugLogger.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static void logEvent(final RuntimeEvent<?> event) {
    if (event != null) {
        final Global global = Context.getGlobal();
        if (global.has("Debug")) {
            final ScriptObject debug = (ScriptObject)global.get("Debug");
            final ScriptFunction addRuntimeEvent = (ScriptFunction)debug.get("addRuntimeEvent");
            ScriptRuntime.apply(addRuntimeEvent, debug, event);
        }
    }
}
 
Example #3
Source File: NativeDebug.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private static LinkedList<RuntimeEvent<?>> getEventQueue(final Object self) {
    final ScriptObject sobj = (ScriptObject)self;
    LinkedList<RuntimeEvent<?>> q;
    if (sobj.has(EVENT_QUEUE)) {
        q = (LinkedList<RuntimeEvent<?>>)((ScriptObject)self).get(EVENT_QUEUE);
    } else {
        ((ScriptObject)self).set(EVENT_QUEUE, q = new LinkedList<>(), NashornCallSiteDescriptor.CALLSITE_STRICT);
    }
    return q;
}
 
Example #4
Source File: NativeDebug.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add a runtime event to the runtime event queue. The queue has a fixed
 * size {@link RuntimeEvent#RUNTIME_EVENT_QUEUE_SIZE} and the oldest
 * entry will be thrown out of the queue is about to overflow
 * @param self self reference
 * @param event event to add
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static void addRuntimeEvent(final Object self, final Object event) {
    final LinkedList<RuntimeEvent<?>> q = getEventQueue(self);
    final int cap = (Integer)getEventQueueCapacity(self);
    while (q.size() >= cap) {
        q.removeFirst();
    }
    q.addLast(getEvent(event));
}
 
Example #5
Source File: NativeDebug.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the capacity of the event queue
 * @param self self reference
 * @return capacity of event queue as an integer
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static Object getEventQueueCapacity(final Object self) {
    final ScriptObject sobj = (ScriptObject)self;
    Integer cap;
    if (sobj.has(EVENT_QUEUE_CAPACITY)) {
        cap = JSType.toInt32(sobj.get(EVENT_QUEUE_CAPACITY));
    } else {
        setEventQueueCapacity(self, cap = RuntimeEvent.RUNTIME_EVENT_QUEUE_SIZE);
    }
    return cap;
}
 
Example #6
Source File: NativeDebug.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add a runtime event to the runtime event queue. The queue has a fixed
 * size {@link RuntimeEvent#RUNTIME_EVENT_QUEUE_SIZE} and the oldest
 * entry will be thrown out of the queue is about to overflow
 * @param self self reference
 * @param event event to add
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static void addRuntimeEvent(final Object self, final Object event) {
    final LinkedList<RuntimeEvent<?>> q = getEventQueue(self);
    final int cap = (Integer)getEventQueueCapacity(self);
    while (q.size() >= cap) {
        q.removeFirst();
    }
    q.addLast(getEvent(event));
}
 
Example #7
Source File: NativeDebug.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Expands the event queue capacity, or truncates if capacity is lower than
 * current capacity. Then only the newest entries are kept
 * @param self self reference
 * @param newCapacity new capacity
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static void expandEventQueueCapacity(final Object self, final Object newCapacity) {
    final LinkedList<RuntimeEvent<?>> q = getEventQueue(self);
    final int nc = JSType.toInt32(newCapacity);
    while (q.size() > nc) {
        q.removeFirst();
    }
    setEventQueueCapacity(self, nc);
}
 
Example #8
Source File: NativeDebug.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Remove a specific runtime event from the event queue
 * @param self self reference
 * @param event event to remove
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static void removeRuntimeEvent(final Object self, final Object event) {
    final LinkedList<RuntimeEvent<?>> q  = getEventQueue(self);
    final RuntimeEvent<?>             re = getEvent(event);
    if (!q.remove(re)) {
        throw new IllegalStateException("runtime event " + re + " was not in event queue");
    }
}
 
Example #9
Source File: DebugLogger.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static void logEvent(final RuntimeEvent<?> event) {
    if (event != null) {
        final Global global = Context.getGlobal();
        if (global.has("Debug")) {
            final ScriptObject debug = (ScriptObject)global.get("Debug");
            final ScriptFunction addRuntimeEvent = (ScriptFunction)debug.get("addRuntimeEvent");
            ScriptRuntime.apply(addRuntimeEvent, debug, event);
        }
    }
}
 
Example #10
Source File: NativeDebug.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the capacity of the event queue
 * @param self self reference
 * @return capacity of event queue as an integer
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static Object getEventQueueCapacity(final Object self) {
    final ScriptObject sobj = (ScriptObject)self;
    Integer cap;
    if (sobj.has(EVENT_QUEUE_CAPACITY)) {
        cap = JSType.toInt32(sobj.get(EVENT_QUEUE_CAPACITY));
    } else {
        setEventQueueCapacity(self, cap = RuntimeEvent.RUNTIME_EVENT_QUEUE_SIZE);
    }
    return cap;
}
 
Example #11
Source File: NativeDebug.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Expands the event queue capacity, or truncates if capacity is lower than
 * current capacity. Then only the newest entries are kept
 * @param self self reference
 * @param newCapacity new capacity
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static void expandEventQueueCapacity(final Object self, final Object newCapacity) {
    final LinkedList<RuntimeEvent<?>> q = getEventQueue(self);
    final int nc = JSType.toInt32(newCapacity);
    while (q.size() > nc) {
        q.removeFirst();
    }
    setEventQueueCapacity(self, nc);
}
 
Example #12
Source File: NativeDebug.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Remove a specific runtime event from the event queue
 * @param self self reference
 * @param event event to remove
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static void removeRuntimeEvent(final Object self, final Object event) {
    final LinkedList<RuntimeEvent<?>> q  = getEventQueue(self);
    final RuntimeEvent<?>             re = getEvent(event);
    if (!q.remove(re)) {
        throw new IllegalStateException("runtime event " + re + " was not in event queue");
    }
}
 
Example #13
Source File: NativeDebug.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private static LinkedList<RuntimeEvent<?>> getEventQueue(final Object self) {
    final ScriptObject sobj = (ScriptObject)self;
    LinkedList<RuntimeEvent<?>> q;
    if (sobj.has(EVENT_QUEUE)) {
        q = (LinkedList<RuntimeEvent<?>>)((ScriptObject)self).get(EVENT_QUEUE);
    } else {
        ((ScriptObject)self).set(EVENT_QUEUE, q = new LinkedList<>(), NashornCallSiteDescriptor.CALLSITE_STRICT);
    }
    return q;
}
 
Example #14
Source File: DebugLogger.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void logEvent(final RuntimeEvent<?> event) {
    if (event != null) {
        final Global global = Context.getGlobal();
        if (global.has("Debug")) {
            final ScriptObject debug = (ScriptObject)global.get("Debug");
            final ScriptFunction addRuntimeEvent = (ScriptFunction)debug.get("addRuntimeEvent");
            ScriptRuntime.apply(addRuntimeEvent, debug, event);
        }
    }
}
 
Example #15
Source File: NativeDebug.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the capacity of the event queue
 * @param self self reference
 * @return capacity of event queue as an integer
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static Object getEventQueueCapacity(final Object self) {
    final ScriptObject sobj = (ScriptObject)self;
    Integer cap;
    if (sobj.has(EVENT_QUEUE_CAPACITY)) {
        cap = JSType.toInt32(sobj.get(EVENT_QUEUE_CAPACITY));
    } else {
        setEventQueueCapacity(self, cap = RuntimeEvent.RUNTIME_EVENT_QUEUE_SIZE);
    }
    return cap;
}
 
Example #16
Source File: NativeDebug.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private static LinkedList<RuntimeEvent<?>> getEventQueue(final Object self) {
    final ScriptObject sobj = (ScriptObject)self;
    LinkedList<RuntimeEvent<?>> q;
    if (sobj.has(EVENT_QUEUE)) {
        q = (LinkedList<RuntimeEvent<?>>)((ScriptObject)self).get(EVENT_QUEUE);
    } else {
        ((ScriptObject)self).set(EVENT_QUEUE, q = new LinkedList<>(), NashornCallSiteDescriptor.CALLSITE_STRICT);
    }
    return q;
}
 
Example #17
Source File: NativeDebug.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add a runtime event to the runtime event queue. The queue has a fixed
 * size {@link RuntimeEvent#RUNTIME_EVENT_QUEUE_SIZE} and the oldest
 * entry will be thrown out of the queue is about to overflow
 * @param self self reference
 * @param event event to add
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static void addRuntimeEvent(final Object self, final Object event) {
    final LinkedList<RuntimeEvent<?>> q = getEventQueue(self);
    final int cap = (Integer)getEventQueueCapacity(self);
    while (q.size() >= cap) {
        q.removeFirst();
    }
    q.addLast(getEvent(event));
}
 
Example #18
Source File: NativeDebug.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add a runtime event to the runtime event queue. The queue has a fixed
 * size {@link RuntimeEvent#RUNTIME_EVENT_QUEUE_SIZE} and the oldest
 * entry will be thrown out of the queue is about to overflow
 * @param self self reference
 * @param event event to add
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static void addRuntimeEvent(final Object self, final Object event) {
    final LinkedList<RuntimeEvent<?>> q = getEventQueue(self);
    final int cap = (Integer)getEventQueueCapacity(self);
    while (q.size() >= cap) {
        q.removeFirst();
    }
    q.addLast(getEvent(event));
}
 
Example #19
Source File: NativeDebug.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Expands the event queue capacity, or truncates if capacity is lower than
 * current capacity. Then only the newest entries are kept
 * @param self self reference
 * @param newCapacity new capacity
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static void expandEventQueueCapacity(final Object self, final Object newCapacity) {
    final LinkedList<RuntimeEvent<?>> q = getEventQueue(self);
    final int nc = JSType.toInt32(newCapacity);
    while (q.size() > nc) {
        q.removeFirst();
    }
    setEventQueueCapacity(self, nc);
}
 
Example #20
Source File: NativeDebug.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add a runtime event to the runtime event queue. The queue has a fixed
 * size {@link RuntimeEvent#RUNTIME_EVENT_QUEUE_SIZE} and the oldest
 * entry will be thrown out of the queue is about to overflow
 * @param self self reference
 * @param event event to add
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static void addRuntimeEvent(final Object self, final Object event) {
    final LinkedList<RuntimeEvent<?>> q = getEventQueue(self);
    final int cap = (Integer)getEventQueueCapacity(self);
    while (q.size() >= cap) {
        q.removeFirst();
    }
    q.addLast(getEvent(event));
}
 
Example #21
Source File: NativeDebug.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Return all runtime events in the queue as an array
 * @param self self reference
 * @return array of events
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static Object getRuntimeEvents(final Object self) {
    final LinkedList<RuntimeEvent<?>> q = getEventQueue(self);
    return q.toArray(new RuntimeEvent<?>[0]);
}
 
Example #22
Source File: NativeDebug.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Return all runtime events in the queue as an array
 * @param self self reference
 * @return array of events
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static Object getRuntimeEvents(final Object self) {
    final LinkedList<RuntimeEvent<?>> q = getEventQueue(self);
    return q.toArray(new RuntimeEvent<?>[q.size()]);
}
 
Example #23
Source File: NativeDebug.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private static RuntimeEvent<?> getEvent(final Object event) {
    return (RuntimeEvent<?>)event;
}
 
Example #24
Source File: Context.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private synchronized Class<?> compile(final Source source, final ErrorManager errMan, final boolean strict) {
    // start with no errors, no warnings.
    errMan.reset();

    Class<?> script = findCachedClass(source);
    if (script != null) {
        final DebugLogger log = getLogger(Compiler.class);
        if (log.isEnabled()) {
            log.fine(new RuntimeEvent<>(Level.INFO, source), "Code cache hit for ", source, " avoiding recompile.");
        }
        return script;
    }

    StoredScript storedScript = null;
    FunctionNode functionNode = 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);
    }

    if (storedScript == null) {
        if (env._dest_dir != null) {
            source.dump(env._dest_dir);
        }

        functionNode = new Parser(env, source, errMan, strict, getLogger(Parser.class)).parse();

        if (errMan.hasErrors()) {
            return null;
        }

        if (env._print_ast || functionNode.getFlag(FunctionNode.IS_PRINT_AST)) {
            getErr().println(new ASTWriter(functionNode));
        }

        if (env._print_parse || functionNode.getFlag(FunctionNode.IS_PRINT_PARSE)) {
            getErr().println(new PrintVisitor(functionNode, true, false));
        }
    }

    if (env._parse_only) {
        return null;
    }

    final URL          url    = source.getURL();
    final ScriptLoader loader = env._loader_per_compile ? createNewLoader() : scriptLoader;
    final CodeSource   cs     = new CodeSource(url, (CodeSigner[])null);
    final CodeInstaller<ScriptEnvironment> installer = new ContextCodeInstaller(this, loader, cs);

    if (storedScript == null) {
        final CompilationPhases phases = Compiler.CompilationPhases.COMPILE_ALL;

        final Compiler compiler = new Compiler(
                this,
                env,
                installer,
                source,
                errMan,
                strict | functionNode.isStrict());

        final FunctionNode compiledFunction = compiler.compile(functionNode, phases);
        if (errMan.hasErrors()) {
            return null;
        }
        script = compiledFunction.getRootClass();
        compiler.persistClassInfo(cacheKey, compiledFunction);
    } else {
        Compiler.updateCompilationId(storedScript.getCompilationId());
        script = storedScript.installScript(source, installer);
    }

    cacheClass(source, script);
    return script;
}
 
Example #25
Source File: NativeDebug.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Return the last runtime event in the queue
 * @param self self reference
 * @return the freshest event, null if queue is empty
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static Object getLastRuntimeEvent(final Object self) {
    final LinkedList<RuntimeEvent<?>> q = getEventQueue(self);
    return q.isEmpty() ? null : q.getLast();
}
 
Example #26
Source File: NativeDebug.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
private static RuntimeEvent<?> getEvent(final Object event) {
    return (RuntimeEvent<?>)event;
}
 
Example #27
Source File: Context.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
private synchronized Class<?> compile(final Source source, final ErrorManager errMan, final boolean strict) {
    // start with no errors, no warnings.
    errMan.reset();

    Class<?> script = findCachedClass(source);
    if (script != null) {
        final DebugLogger log = getLogger(Compiler.class);
        if (log.isEnabled()) {
            log.fine(new RuntimeEvent<>(Level.INFO, source), "Code cache hit for ", source, " avoiding recompile.");
        }
        return script;
    }

    StoredScript storedScript = null;
    FunctionNode functionNode = 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);
    }

    if (storedScript == null) {
        if (env._dest_dir != null) {
            source.dump(env._dest_dir);
        }

        functionNode = new Parser(env, source, errMan, strict, getLogger(Parser.class)).parse();

        if (errMan.hasErrors()) {
            return null;
        }

        if (env._print_ast || functionNode.getFlag(FunctionNode.IS_PRINT_AST)) {
            getErr().println(new ASTWriter(functionNode));
        }

        if (env._print_parse || functionNode.getFlag(FunctionNode.IS_PRINT_PARSE)) {
            getErr().println(new PrintVisitor(functionNode, true, false));
        }
    }

    if (env._parse_only) {
        return null;
    }

    final URL          url    = source.getURL();
    final ScriptLoader loader = env._loader_per_compile ? createNewLoader() : scriptLoader;
    final CodeSource   cs     = new CodeSource(url, (CodeSigner[])null);
    final CodeInstaller installer = new ContextCodeInstaller(this, loader, cs);

    if (storedScript == null) {
        final CompilationPhases phases = Compiler.CompilationPhases.COMPILE_ALL;

        final Compiler compiler = Compiler.forInitialCompilation(
                installer,
                source,
                errMan,
                strict | functionNode.isStrict());

        final FunctionNode compiledFunction = compiler.compile(functionNode, phases);
        if (errMan.hasErrors()) {
            return null;
        }
        script = compiledFunction.getRootClass();
        compiler.persistClassInfo(cacheKey, compiledFunction);
    } else {
        Compiler.updateCompilationId(storedScript.getCompilationId());
        script = storedScript.installScript(source, installer);
    }

    cacheClass(source, script);
    return script;
}
 
Example #28
Source File: NativeDebug.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Return the last runtime event in the queue
 * @param self self reference
 * @return the freshest event, null if queue is empty
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static Object getLastRuntimeEvent(final Object self) {
    final LinkedList<RuntimeEvent<?>> q = getEventQueue(self);
    return q.isEmpty() ? null : q.getLast();
}
 
Example #29
Source File: NativeDebug.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private static RuntimeEvent<?> getEvent(final Object event) {
    return (RuntimeEvent<?>)event;
}
 
Example #30
Source File: NativeDebug.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private static RuntimeEvent<?> getEvent(final Object event) {
    return (RuntimeEvent<?>)event;
}