Java Code Examples for jdk.jfr.internal.JVMSupport#isNotAvailable()

The following examples show how to use jdk.jfr.internal.JVMSupport#isNotAvailable() . 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 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 2
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 3
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 4
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 5
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 6
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 7
Source File: FlightRecorder.java    From TencentKona-8 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 8
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 9
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 10
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 11
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 12
Source File: FlightRecorder.java    From TencentKona-8 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 13
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 14
Source File: FlightRecorder.java    From TencentKona-8 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 15
Source File: FlightRecorder.java    From dragonwell8_jdk 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: 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);
}
 
Example 17
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 18
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 19
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 20
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);
}