jdk.jfr.internal.JVMSupport Java Examples

The following examples show how to use jdk.jfr.internal.JVMSupport. 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: ManagementSupport.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static List<EventType> getEventTypes() {
    // would normally be checked when a Flight Recorder instance is created
    Utils.checkAccessFlightRecorder();
    if (JVMSupport.isNotAvailable()) {
        return new ArrayList<>();
    }
    JDKEvents.initialize(); // make sure JDK events are available
    return Collections.unmodifiableList(MetadataRepository.getInstance().getRegisteredEventTypes());
}
 
Example #2
Source File: Configuration.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns an immutable list of predefined configurations for this JVM.
 *
 * @return the list of predefined configurations, not {@code null}
 */
public static List<Configuration> getConfigurations() {
    if (JVMSupport.isNotAvailable()) {
        return new ArrayList<>();
    }
    return Collections.unmodifiableList(JFC.getConfigurations());
}
 
Example #3
Source File: FlightRecorder.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Removes a hook for a periodic event.
 *
 * @param hook the hook to remove, not {@code null}
 * @return {@code true} if hook is removed, {@code false} otherwise
 * @throws SecurityException if a security manager exists and the caller
 *         does not have {@code FlightRecorderPermission("registerEvent")}
 */
public static boolean removePeriodicEvent(Runnable hook) throws SecurityException {
    Objects.requireNonNull(hook);
    Utils.checkRegisterPermission();
    if (JVMSupport.isNotAvailable()) {
        return false;
    }
    return RequestEngine.removeHook(hook);
}
 
Example #4
Source File: FlightRecorder.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the Flight Recorder for the platform.
 *
 * @return a Flight Recorder instance, not {@code null}
 *
 * @throws IllegalStateException if the platform Flight Recorder couldn't be
 *         created (for example, if the file repository can't be created or
 *         accessed)
 *
 * @throws SecurityException if a security manager exists and the caller does
 *         not have {@code FlightRecorderPermission("accessFlightRecorder")}
 */
public static FlightRecorder getFlightRecorder() throws IllegalStateException, SecurityException {
    synchronized (PlatformRecorder.class) {
        Utils.checkAccessFlightRecorder();
        JVMSupport.ensureWithIllegalStateException();
        if (platformRecorder == null) {
            try {
                platformRecorder = new FlightRecorder(new PlatformRecorder());
            } catch (IllegalStateException ise) {
                throw ise;
            } catch (Exception e) {
                throw new IllegalStateException("Can't create Flight Recorder. " + e.getMessage(), e);
            }
            // Must be in synchronized block to prevent instance leaking out
            // before initialization is done
            initialized = true;
            Logger.log(JFR, INFO, "Flight Recorder initialized");
            Logger.log(JFR, DEBUG, "maxchunksize: " + Options.getMaxChunkSize()+ " bytes");
            Logger.log(JFR, DEBUG, "memorysize: " + Options.getMemorySize()+ " bytes");
            Logger.log(JFR, DEBUG, "globalbuffersize: " + Options.getGlobalBufferSize()+ " bytes");
            Logger.log(JFR, DEBUG, "globalbuffercount: " + Options.getGlobalBufferCount());
            Logger.log(JFR, DEBUG, "dumppath: " + Options.getDumpPath());
            Logger.log(JFR, DEBUG, "samplethreads: " + Options.getSampleThreads());
            Logger.log(JFR, DEBUG, "stackdepth: " + Options.getStackDepth());
            Logger.log(JFR, DEBUG, "threadbuffersize: " + Options.getThreadBufferSize());
            Logger.log(JFR, LogLevel.INFO, "Created repository " + Repository.getRepository().getRepositoryPath().toString());
            PlatformRecorder.notifyRecorderInitialized(platformRecorder);
        }
    }
    return platformRecorder;
}
 
Example #5
Source File: FlightRecorder.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the Flight Recorder for the platform.
 *
 * @return a Flight Recorder instance, not {@code null}
 *
 * @throws IllegalStateException if Flight Recorder can't be created (for
 *         example, if the Java Virtual Machine (JVM) lacks Flight Recorder
 *         support, or if the file repository can't be created or accessed)
 *
 * @throws SecurityException if a security manager exists and the caller does
 *         not have {@code FlightRecorderPermission("accessFlightRecorder")}
 */
public static FlightRecorder getFlightRecorder() throws IllegalStateException, SecurityException {
    synchronized (PlatformRecorder.class) {
        Utils.checkAccessFlightRecorder();
        JVMSupport.ensureWithIllegalStateException();
        if (platformRecorder == null) {
            try {
                platformRecorder = new FlightRecorder(new PlatformRecorder());
            } catch (IllegalStateException ise) {
                throw ise;
            } catch (Exception e) {
                throw new IllegalStateException("Can't create Flight Recorder. " + e.getMessage(), e);
            }
            // Must be in synchronized block to prevent instance leaking out
            // before initialization is done
            initialized = true;
            Logger.log(JFR, INFO, "Flight Recorder initialized");
            Logger.log(JFR, DEBUG, "maxchunksize: " + Options.getMaxChunkSize()+ " bytes");
            Logger.log(JFR, DEBUG, "memorysize: " + Options.getMemorySize()+ " bytes");
            Logger.log(JFR, DEBUG, "globalbuffersize: " + Options.getGlobalBufferSize()+ " bytes");
            Logger.log(JFR, DEBUG, "globalbuffercount: " + Options.getGlobalBufferCount());
            Logger.log(JFR, DEBUG, "dumppath: " + Options.getDumpPath());
            Logger.log(JFR, DEBUG, "samplethreads: " + Options.getSampleThreads());
            Logger.log(JFR, DEBUG, "stackdepth: " + Options.getStackDepth());
            Logger.log(JFR, DEBUG, "threadbuffersize: " + Options.getThreadBufferSize());
            Logger.log(JFR, LogLevel.INFO, "Created repository " + Repository.getRepository().getRepositoryPath().toString());
            PlatformRecorder.notifyRecorderInitialized(platformRecorder);
        }
    }
    return platformRecorder;
}
 
Example #6
Source File: FlightRecorder.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Removes a callback hook for a periodic event.
 *
 * @param hook the hook to remove, not {@code null}
 * @return {@code true} if hook is removed, {@code false} otherwise
 * @throws SecurityException if a security manager exists and the caller
 *         does not have {@code FlightRecorderPermission("registerEvent")}
 */
public static boolean removePeriodicEvent(Runnable hook) throws SecurityException {
    Objects.requireNonNull(hook);
    Utils.checkRegisterPermission();
    if (JVMSupport.isNotAvailable()) {
        return false;
    }
    return RequestEngine.removeHook(hook);
}
 
Example #7
Source File: FlightRecorder.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Removes a hook for a periodic event.
 *
 * @param hook the hook to remove, not {@code null}
 * @return {@code true} if hook is removed, {@code false} otherwise
 * @throws SecurityException if a security manager exists and the caller
 *         does not have {@code FlightRecorderPermission("registerEvent")}
 */
public static boolean removePeriodicEvent(Runnable hook) throws SecurityException {
    Objects.requireNonNull(hook);
    Utils.checkRegisterPermission();
    if (JVMSupport.isNotAvailable()) {
        return false;
    }
    return RequestEngine.removeHook(hook);
}
 
Example #8
Source File: ManagementSupport.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static List<EventType> getEventTypes() {
    // would normally be checked when a Flight Recorder instance is created
    Utils.checkAccessFlightRecorder();
    if (JVMSupport.isNotAvailable()) {
        return new ArrayList<>();
    }
    JDKEvents.initialize(); // make sure JDK events are available
    return Collections.unmodifiableList(MetadataRepository.getInstance().getRegisteredEventTypes());
}
 
Example #9
Source File: FlightRecorder.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the Flight Recorder for the platform.
 *
 * @return a Flight Recorder instance, not {@code null}
 *
 * @throws IllegalStateException if Flight Recorder can't be created (for
 *         example, if the Java Virtual Machine (JVM) lacks Flight Recorder
 *         support, or if the file repository can't be created or accessed)
 *
 * @throws SecurityException if a security manager exists and the caller does
 *         not have {@code FlightRecorderPermission("accessFlightRecorder")}
 */
public static FlightRecorder getFlightRecorder() throws IllegalStateException, SecurityException {
    synchronized (PlatformRecorder.class) {
        Utils.checkAccessFlightRecorder();
        JVMSupport.ensureWithIllegalStateException();
        if (platformRecorder == null) {
            try {
                platformRecorder = new FlightRecorder(new PlatformRecorder());
            } catch (IllegalStateException ise) {
                throw ise;
            } catch (Exception e) {
                throw new IllegalStateException("Can't create Flight Recorder. " + e.getMessage(), e);
            }
            // Must be in synchronized block to prevent instance leaking out
            // before initialization is done
            initialized = true;
            Logger.log(JFR, INFO, "Flight Recorder initialized");
            Logger.log(JFR, DEBUG, "maxchunksize: " + Options.getMaxChunkSize()+ " bytes");
            Logger.log(JFR, DEBUG, "memorysize: " + Options.getMemorySize()+ " bytes");
            Logger.log(JFR, DEBUG, "globalbuffersize: " + Options.getGlobalBufferSize()+ " bytes");
            Logger.log(JFR, DEBUG, "globalbuffercount: " + Options.getGlobalBufferCount());
            Logger.log(JFR, DEBUG, "dumppath: " + Options.getDumpPath());
            Logger.log(JFR, DEBUG, "samplethreads: " + Options.getSampleThreads());
            Logger.log(JFR, DEBUG, "stackdepth: " + Options.getStackDepth());
            Logger.log(JFR, DEBUG, "threadbuffersize: " + Options.getThreadBufferSize());
            Logger.log(JFR, LogLevel.INFO, "Created repository " + Repository.getRepository().getRepositoryPath().toString());
            PlatformRecorder.notifyRecorderInitialized(platformRecorder);
        }
    }
    return platformRecorder;
}
 
Example #10
Source File: ManagementSupport.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static List<EventType> getEventTypes() {
    // would normally be checked when a Flight Recorder instance is created
    Utils.checkAccessFlightRecorder();
    if (JVMSupport.isNotAvailable()) {
        return new ArrayList<>();
    }
    JDKEvents.initialize(); // make sure JDK events are available
    return Collections.unmodifiableList(MetadataRepository.getInstance().getRegisteredEventTypes());
}
 
Example #11
Source File: Configuration.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns an immutable list of predefined configurations for this Java Virtual Machine (JVM).
 *
 * @return the list of predefined configurations, not {@code null}
 */
public static List<Configuration> getConfigurations() {
    if (JVMSupport.isNotAvailable()) {
        return new ArrayList<>();
    }
    return Collections.unmodifiableList(JFC.getConfigurations());
}
 
Example #12
Source File: Configuration.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns an immutable list of predefined configurations for this Java Virtual Machine (JVM).
 *
 * @return the list of predefined configurations, not {@code null}
 */
public static List<Configuration> getConfigurations() {
    if (JVMSupport.isNotAvailable()) {
        return new ArrayList<>();
    }
    return Collections.unmodifiableList(JFC.getConfigurations());
}
 
Example #13
Source File: FlightRecorder.java    From TencentKona-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Removes a recorder listener.
 * <p>
 * If the same listener is added multiple times, only one instance is
 * removed.
 *
 * @param changeListener listener to remove, not {@code null}
 *
 * @throws SecurityException if a security manager exists and the caller
 *         does not have
 *         {@code FlightRecorderPermission("accessFlightRecorder")}
 *
 * @return {@code true}, if the listener could be removed, {@code false}
 *         otherwise
 */
public static boolean removeListener(FlightRecorderListener changeListener) {
    Objects.requireNonNull(changeListener);
    Utils.checkAccessFlightRecorder();
    if (JVMSupport.isNotAvailable()) {
        return false;
    }

    return PlatformRecorder.removeListener(changeListener);
}
 
Example #14
Source File: FlightRecorder.java    From TencentKona-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Adds a hook for a periodic event.
 * <p>
 * The implementation of the hook should return as soon as possible, to
 * avoid blocking other Flight Recorder operations. The hook should emit
 * one or more events of the specified type. When a hook is added, the
 * interval at which the call is invoked is configurable using the
 * {@code "period"} setting.
 *
 * @param eventClass the class that the hook should run for, not {@code null}
 * @param hook the hook, not {@code null}
 * @throws IllegalArgumentException if a class is not a subclass of
 *         {@link Event}, is abstract, or the hook is already added
 * @throws IllegalStateException if the event class has the
 *         {@code Registered(false)} annotation and is not registered manually
 * @throws SecurityException if a security manager exists and the caller
 *         does not have {@code FlightRecorderPermission("registerEvent")}
 */
public static void addPeriodicEvent(Class<? extends Event> eventClass, Runnable hook) throws SecurityException {
    Objects.requireNonNull(eventClass);
    Objects.requireNonNull(hook);
    if (JVMSupport.isNotAvailable()) {
        return;
    }

    Utils.ensureValidEventSubclass(eventClass);
    Utils.checkRegisterPermission();
    AccessControlContext acc = AccessController.getContext();
    RequestEngine.addHook(acc, EventType.getEventType(eventClass).getPlatformEventType(), hook);
}
 
Example #15
Source File: FlightRecorder.java    From TencentKona-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns {@code true} if the Java Virtual Machine (JVM) has Flight Recorder capabilities.
 * <p>
 * This method can quickly check whether Flight Recorder can be
 * initialized, without actually doing the initialization work. The value may
 * change during runtime and it is not safe to cache it.
 *
 * @return {@code true}, if Flight Recorder is available, {@code false}
 *         otherwise
 *
 * @see FlightRecorderListener for callback when Flight Recorder is
 *      initialized
 */
public static boolean isAvailable() {
    if (JVMSupport.isNotAvailable()) {
        return false;
    }
    return JVM.getJVM().isAvailable();
}
 
Example #16
Source File: EventType.java    From TencentKona-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns the event type for an event class, or {@code null} if it doesn't
 * exist.
 *
 * @param eventClass the event class, not {@code null}
 * @return the event class, or null if class doesn't exist
 *
 * @throws IllegalArgumentException if {@code eventClass} is an abstract class
 *
 * @throws IllegalStateException if the class is annotated with
 *         {@code Registered(false)}, but not manually registered
 */
public static EventType getEventType(Class<? extends Event> eventClass) {
    Objects.requireNonNull(eventClass);
    Utils.ensureValidEventSubclass(eventClass);
    JVMSupport.ensureWithInternalError();
    return MetadataRepository.getInstance().getEventType(eventClass);
}
 
Example #17
Source File: Configuration.java    From openjdk-jdk8u with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Reads a configuration from a file.
 *
 * @param path the file that contains the configuration, not {@code null}
 * @return the read {@link Configuration}, not {@code null}
 * @throws ParseException if the file can't be parsed
 * @throws IOException if the file can't be read
 * @throws SecurityException if a security manager exists and its
 *         {@code checkRead} method denies read access to the file.
 *
 * @see java.io.File#getPath()
 * @see java.lang.SecurityManager#checkRead(java.lang.String)
 */
public static Configuration create(Path path) throws IOException, ParseException {
    Objects.requireNonNull(path);
    JVMSupport.ensureWithIOException();
    try (Reader reader = Files.newBufferedReader(path)) {
        return JFC.create(JFC.nameFromPath(path), reader);
    }
}
 
Example #18
Source File: FlightRecorder.java    From openjdk-jdk8u with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Registers an event class.
 * <p>
 * If the event class is already registered, then the invocation of this method is
 * ignored.
 *
 * @param eventClass the event class to register, not {@code null}
 *
 * @throws IllegalArgumentException if class is abstract or not a subclass
 *         of {@link Event}
 * @throws SecurityException if a security manager exists and the caller
 *         does not have {@code FlightRecorderPermission("registerEvent")}
 */
public static void register(Class<? extends Event> eventClass) {
    Objects.requireNonNull(eventClass);
    if (JVMSupport.isNotAvailable()) {
        return;
    }
    Utils.ensureValidEventSubclass(eventClass);
    MetadataRepository.getInstance().register(eventClass);
}
 
Example #19
Source File: FlightRecorder.java    From openjdk-jdk8u with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Unregisters an event class.
 * <p>
 * If the event class is not registered, then the invocation of this method is
 * ignored.
 *
 * @param eventClass the event class to unregistered, not {@code null}
 * @throws IllegalArgumentException if a class is abstract or not a subclass
 *         of {@link Event}
 *
 * @throws SecurityException if a security manager exists and the caller
 *         does not have {@code FlightRecorderPermission("registerEvent")}
 */
public static void unregister(Class<? extends Event> eventClass) {
    Objects.requireNonNull(eventClass);
    if (JVMSupport.isNotAvailable()) {
        return;
    }
    Utils.ensureValidEventSubclass(eventClass);
    MetadataRepository.getInstance().unregister(eventClass);
}
 
Example #20
Source File: FlightRecorder.java    From openjdk-jdk8u with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Adds a hook for a periodic event.
 * <p>
 * The implementation of the hook should return as soon as possible, to
 * avoid blocking other Flight Recorder operations. The hook should emit
 * one or more events of the specified type. When a hook is added, the
 * interval at which the call is invoked is configurable using the
 * {@code "period"} setting.
 *
 * @param eventClass the class that the hook should run for, not {@code null}
 * @param hook the hook, not {@code null}
 * @throws IllegalArgumentException if a class is not a subclass of
 *         {@link Event}, is abstract, or the hook is already added
 * @throws IllegalStateException if the event class has the
 *         {@code Registered(false)} annotation and is not registered manually
 * @throws SecurityException if a security manager exists and the caller
 *         does not have {@code FlightRecorderPermission("registerEvent")}
 */
public static void addPeriodicEvent(Class<? extends Event> eventClass, Runnable hook) throws SecurityException {
    Objects.requireNonNull(eventClass);
    Objects.requireNonNull(hook);
    if (JVMSupport.isNotAvailable()) {
        return;
    }

    Utils.ensureValidEventSubclass(eventClass);
    Utils.checkRegisterPermission();
    AccessControlContext acc = AccessController.getContext();
    RequestEngine.addHook(acc, EventType.getEventType(eventClass).getPlatformEventType(), hook);
}
 
Example #21
Source File: FlightRecorder.java    From openjdk-jdk8u with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Adds a recorder listener and captures the {@code AccessControlContext} to
 * use when invoking the listener.
 * <p>
 * If Flight Recorder is already initialized when the listener is added, then the method
 * {@link FlightRecorderListener#recorderInitialized(FlightRecorder)} method is
 * invoked before returning from this method.
 *
 * @param changeListener the listener to add, not {@code null}
 *
 * @throws SecurityException if a security manager exists and the caller
 *         does not have
 *         {@code FlightRecorderPermission("accessFlightRecorder")}
 */
public static void addListener(FlightRecorderListener changeListener) {
    Objects.requireNonNull(changeListener);
    Utils.checkAccessFlightRecorder();
    if (JVMSupport.isNotAvailable()) {
        return;
    }
    PlatformRecorder.addListener(changeListener);
}
 
Example #22
Source File: FlightRecorder.java    From openjdk-jdk8u with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Removes a recorder listener.
 * <p>
 * If the same listener is added multiple times, only one instance is
 * removed.
 *
 * @param changeListener listener to remove, not {@code null}
 *
 * @throws SecurityException if a security manager exists and the caller
 *         does not have
 *         {@code FlightRecorderPermission("accessFlightRecorder")}
 *
 * @return {@code true}, if the listener could be removed, {@code false}
 *         otherwise
 */
public static boolean removeListener(FlightRecorderListener changeListener) {
    Objects.requireNonNull(changeListener);
    Utils.checkAccessFlightRecorder();
    if (JVMSupport.isNotAvailable()) {
        return false;
    }

    return PlatformRecorder.removeListener(changeListener);
}
 
Example #23
Source File: FlightRecorder.java    From openjdk-jdk8u with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns {@code true} if the Java Virtual Machine (JVM) has Flight Recorder capabilities.
 * <p>
 * This method can quickly check whether Flight Recorder can be
 * initialized, without actually doing the initialization work. The value may
 * change during runtime and it is not safe to cache it.
 *
 * @return {@code true}, if Flight Recorder is available, {@code false}
 *         otherwise
 *
 * @see FlightRecorderListener for callback when Flight Recorder is
 *      initialized
 */
public static boolean isAvailable() {
    if (JVMSupport.isNotAvailable()) {
        return false;
    }
    return JVM.getJVM().isAvailable();
}
 
Example #24
Source File: EventType.java    From openjdk-jdk8u with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns the event type for an event class, or {@code null} if it doesn't
 * exist.
 *
 * @param eventClass the event class, not {@code null}
 * @return the event class, or null if class doesn't exist
 *
 * @throws IllegalArgumentException if {@code eventClass} is an abstract class
 *
 * @throws IllegalStateException if the class is annotated with
 *         {@code Registered(false)}, but not manually registered
 */
public static EventType getEventType(Class<? extends Event> eventClass) {
    Objects.requireNonNull(eventClass);
    Utils.ensureValidEventSubclass(eventClass);
    JVMSupport.ensureWithInternalError();
    return MetadataRepository.getInstance().getEventType(eventClass);
}
 
Example #25
Source File: Configuration.java    From dragonwell8_jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Reads a configuration from a file.
 *
 * @param path the file that contains the configuration, not {@code null}
 * @return the read {@link Configuration}, not {@code null}
 * @throws ParseException if the file can't be parsed
 * @throws IOException if the file can't be read
 * @throws SecurityException if a security manager exists and its
 *         {@code checkRead} method denies read access to the file.
 *
 * @see java.io.File#getPath()
 * @see java.lang.SecurityManager#checkRead(java.lang.String)
 */
public static Configuration create(Path path) throws IOException, ParseException {
    Objects.requireNonNull(path);
    JVMSupport.ensureWithIOException();
    try (Reader reader = Files.newBufferedReader(path)) {
        return JFC.create(JFC.nameFromPath(path), reader);
    }
}
 
Example #26
Source File: FlightRecorder.java    From dragonwell8_jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Registers an event class.
 * <p>
 * If the event class is already registered, then the invocation of this method is
 * ignored.
 *
 * @param eventClass the event class to register, not {@code null}
 *
 * @throws IllegalArgumentException if class is abstract or not a subclass
 *         of {@link Event}
 * @throws SecurityException if a security manager exists and the caller
 *         does not have {@code FlightRecorderPermission("registerEvent")}
 */
public static void register(Class<? extends Event> eventClass) {
    Objects.requireNonNull(eventClass);
    if (JVMSupport.isNotAvailable()) {
        return;
    }
    Utils.ensureValidEventSubclass(eventClass);
    MetadataRepository.getInstance().register(eventClass);
}
 
Example #27
Source File: FlightRecorder.java    From dragonwell8_jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Unregisters an event class.
 * <p>
 * If the event class is not registered, then the invocation of this method is
 * ignored.
 *
 * @param eventClass the event class to unregistered, not {@code null}
 * @throws IllegalArgumentException if a class is abstract or not a subclass
 *         of {@link Event}
 *
 * @throws SecurityException if a security manager exists and the caller
 *         does not have {@code FlightRecorderPermission("registerEvent")}
 */
public static void unregister(Class<? extends Event> eventClass) {
    Objects.requireNonNull(eventClass);
    if (JVMSupport.isNotAvailable()) {
        return;
    }
    Utils.ensureValidEventSubclass(eventClass);
    MetadataRepository.getInstance().unregister(eventClass);
}
 
Example #28
Source File: FlightRecorder.java    From dragonwell8_jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Adds a callback for a periodic event.
 * <p>
 * The implementation of the hook should return as soon as possible, to
 * avoid blocking other Flight Recorder operations. The hook should emit
 * one or more events of the specified type. When a hook is added, the
 * interval at which the call is invoked is configurable using the
 * {@code "period"} setting.
 *
 * @param eventClass the class that the hook should run for, not {@code null}
 * @param hook the hook, not {@code null}
 * @throws IllegalArgumentException if a class is not a subclass of
 *         {@link Event}, is abstract, or the hook is already added
 * @throws IllegalStateException if the event class has the
 *         {@code Registered(false)} annotation and is not registered manually
 * @throws SecurityException if a security manager exists and the caller
 *         does not have {@code FlightRecorderPermission("registerEvent")}
 */
public static void addPeriodicEvent(Class<? extends Event> eventClass, Runnable hook) throws SecurityException {
    Objects.requireNonNull(eventClass);
    Objects.requireNonNull(hook);
    if (JVMSupport.isNotAvailable()) {
        return;
    }

    Utils.ensureValidEventSubclass(eventClass);
    Utils.checkRegisterPermission();
    AccessControlContext acc = AccessController.getContext();
    RequestEngine.addHook(acc, EventType.getEventType(eventClass).getPlatformEventType(), hook);
}
 
Example #29
Source File: FlightRecorder.java    From dragonwell8_jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Adds a recorder listener and captures the {@code AccessControlContext} to
 * use when invoking the listener.
 * <p>
 * If Flight Recorder is already initialized when the listener is added, the the method
 * {@link FlightRecorderListener#recorderInitialized(FlightRecorder)} method is
 * invoked before returning from this method.
 *
 * @param changeListener the listener to add, not {@code null}
 *
 * @throws SecurityException if a security manager exists and the caller
 *         does not have
 *         {@code FlightRecorderPermission("accessFlightRecorder")}
 */
public static void addListener(FlightRecorderListener changeListener) {
    Objects.requireNonNull(changeListener);
    Utils.checkAccessFlightRecorder();
    if (JVMSupport.isNotAvailable()) {
        return;
    }
    PlatformRecorder.addListener(changeListener);
}
 
Example #30
Source File: FlightRecorder.java    From dragonwell8_jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Removes a recorder listener.
 * <p>
 * If the same listener is added multiple times, only one instance is
 * removed.
 *
 * @param changeListener listener to remove, not {@code null}
 *
 * @throws SecurityException if a security manager exists and the caller
 *         does not have
 *         {@code FlightRecorderPermission("accessFlightRecorder")}
 *
 * @return {@code true}, if the listener could be removed, {@code false}
 *         otherwise
 */
public static boolean removeListener(FlightRecorderListener changeListener) {
    Objects.requireNonNull(changeListener);
    Utils.checkAccessFlightRecorder();
    if (JVMSupport.isNotAvailable()) {
        return false;
    }

    return PlatformRecorder.removeListener(changeListener);
}