Java Code Examples for jdk.jfr.internal.instrument.JDKEvents#retransformCallback()

The following examples show how to use jdk.jfr.internal.instrument.JDKEvents#retransformCallback() . 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: JVMUpcalls.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Called by the JVM when a retransform happens on a tagged class
 *
 * @param traceId
 *            Id of the class
 * @param dummy
 *            (not used but needed since invoke infrastructure in native
 *            uses same signature bytesForEagerInstrumentation)
 * @param clazz
 *            class being retransformed
 * @param oldBytes
 *            byte code
 * @return byte code to use
 * @throws Throwable
 */
static byte[] onRetransform(long traceId, boolean dummy, Class<?> clazz, byte[] oldBytes) throws Throwable {
    try {
        if (Event.class.isAssignableFrom(clazz) && !Modifier.isAbstract(clazz.getModifiers())) {
            EventHandler handler = Utils.getHandler(clazz.asSubclass(Event.class));
            if (handler == null) {
                Logger.log(LogTag.JFR_SYSTEM, LogLevel.INFO, "No event handler found for " + clazz.getName() + ". Ignoring instrumentation request.");
                // Probably triggered by some other agent
                return oldBytes;
            }
            Logger.log(LogTag.JFR_SYSTEM, LogLevel.INFO, "Adding instrumentation to event class " + clazz.getName() + " using retransform");
            EventInstrumentation ei = new EventInstrumentation(clazz.getSuperclass(), oldBytes, traceId);
            byte[] bytes = ei.buildInstrumented();
            ASMToolkit.logASM(clazz.getName(), bytes);
            return bytes;
        }
        return JDKEvents.retransformCallback(clazz, oldBytes);
    } catch (Throwable t) {
        Logger.log(LogTag.JFR_SYSTEM, LogLevel.WARN, "Unexpected error when adding instrumentation to event class " + clazz.getName());
    }
    return oldBytes;

}
 
Example 2
Source File: JVMUpcalls.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Called by the JVM when a retransform happens on a tagged class
 *
 * @param traceId
 *            Id of the class
 * @param dummy
 *            (not used but needed since invoke infrastructure in native
 *            uses same signature bytesForEagerInstrumentation)
 * @param clazz
 *            class being retransformed
 * @param oldBytes
 *            byte code
 * @return byte code to use
 * @throws Throwable
 */
static byte[] onRetransform(long traceId, boolean dummy, Class<?> clazz, byte[] oldBytes) throws Throwable {
    try {
        if (Event.class.isAssignableFrom(clazz) && !Modifier.isAbstract(clazz.getModifiers())) {
            EventHandler handler = Utils.getHandler(clazz.asSubclass(Event.class));
            if (handler == null) {
                Logger.log(LogTag.JFR_SYSTEM, LogLevel.INFO, "No event handler found for " + clazz.getName() + ". Ignoring instrumentation request.");
                // Probably triggered by some other agent
                return oldBytes;
            }
            Logger.log(LogTag.JFR_SYSTEM, LogLevel.INFO, "Adding instrumentation to event class " + clazz.getName() + " using retransform");
            EventInstrumentation ei = new EventInstrumentation(clazz.getSuperclass(), oldBytes, traceId);
            byte[] bytes = ei.buildInstrumented();
            ASMToolkit.logASM(clazz.getName(), bytes);
            return bytes;
        }
        return JDKEvents.retransformCallback(clazz, oldBytes);
    } catch (Throwable t) {
        Logger.log(LogTag.JFR_SYSTEM, LogLevel.WARN, "Unexpected error when adding instrumentation to event class " + clazz.getName());
    }
    return oldBytes;

}
 
Example 3
Source File: JVMUpcalls.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Called by the JVM when a retransform happens on a tagged class
 *
 * @param traceId
 *            Id of the class
 * @param dummy
 *            (not used but needed since invoke infrastructure in native
 *            uses same signature bytesForEagerInstrumentation)
 * @param clazz
 *            class being retransformed
 * @param oldBytes
 *            byte code
 * @return byte code to use
 * @throws Throwable
 */
static byte[] onRetransform(long traceId, boolean dummy, Class<?> clazz, byte[] oldBytes) throws Throwable {
    try {
        if (Event.class.isAssignableFrom(clazz) && !Modifier.isAbstract(clazz.getModifiers())) {
            EventHandler handler = Utils.getHandler(clazz.asSubclass(Event.class));
            if (handler == null) {
                Logger.log(LogTag.JFR_SYSTEM, LogLevel.INFO, "No event handler found for " + clazz.getName() + ". Ignoring instrumentation request.");
                // Probably triggered by some other agent
                return oldBytes;
            }
            Logger.log(LogTag.JFR_SYSTEM, LogLevel.INFO, "Adding instrumentation to event class " + clazz.getName() + " using retransform");
            EventInstrumentation ei = new EventInstrumentation(clazz.getSuperclass(), oldBytes, traceId);
            byte[] bytes = ei.buildInstrumented();
            ASMToolkit.logASM(clazz.getName(), bytes);
            return bytes;
        }
        return JDKEvents.retransformCallback(clazz, oldBytes);
    } catch (Throwable t) {
        Logger.log(LogTag.JFR_SYSTEM, LogLevel.WARN, "Unexpected error when adding instrumentation to event class " + clazz.getName());
    }
    return oldBytes;

}