jdk.jfr.Event Java Examples

The following examples show how to use jdk.jfr.Event. 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: TestGetAllEventClasses.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@SafeVarargs
private static void assertEvents(JVM jvm, boolean inclusion, Class<? extends Event>... targetEvents) {
    final List<Class<? extends Event>> list = jvm.getAllEventClasses();
    for (Class<? extends Event> ev : targetEvents) {
       if (list.contains(ev)) {
           if (inclusion) {
               continue;
           }
           throw new AssertionError(ev.getName() + " in list but should not be!");
       }
       if (!inclusion) {
           continue;
       }
       throw new AssertionError(ev.getName() + " in not in list but should be!");
   }
}
 
Example #2
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 #3
Source File: TestGetAllEventClasses.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@SafeVarargs
private static void assertEvents(JVM jvm, boolean inclusion, Class<? extends Event>... targetEvents) {
    final List<Class<? extends Event>> list = jvm.getAllEventClasses();
    for (Class<? extends Event> ev : targetEvents) {
       if (list.contains(ev)) {
           if (inclusion) {
               continue;
           }
           throw new AssertionError(ev.getName() + " in list but should not be!");
       }
       if (!inclusion) {
           continue;
       }
       throw new AssertionError(ev.getName() + " in not in list but should be!");
   }
}
 
Example #4
Source File: MetadataRepository.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public synchronized EventType register(Class<? extends Event> eventClass, List<AnnotationElement> dynamicAnnotations, List<ValueDescriptor> dynamicFields) {
    Utils.checkRegisterPermission();
    EventHandler handler = getHandler(eventClass);
    if (handler == null) {
        handler = makeHandler(eventClass, dynamicAnnotations, dynamicFields);
    }
    handler.setRegistered(true);
    typeLibrary.addType(handler.getPlatformEventType());
    if (jvm.isRecording()) {
        storeDescriptorInJVM(); // needed for emergency dump
        settingsManager.setEventControl(handler.getEventControl());
        settingsManager.updateRetransform(Collections.singletonList((eventClass)));
    } else {
        setStaleMetadata();
    }
    return handler.getEventType();
}
 
Example #5
Source File: SettingsManager.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public void updateRetransform(List<Class<? extends Event>> eventClasses) {
    List<Class<?>> classes = new ArrayList<>();
    for(Class<? extends Event> eventClass: eventClasses) {
        EventHandler eh = Utils.getHandler(eventClass);
        if (eh != null ) {
            PlatformEventType eventType = eh.getPlatformEventType();
            if (eventType.isMarkedForInstrumentation()) {
                classes.add(eventClass);
                eventType.markForInstrumentation(false);
                // A bit premature to set it here, but hard to check
                // after call to retransformClasses.
                eventType.setInstrumented();
            }
        }
    }
    if (!classes.isEmpty()) {
        JVM.getJVM().retransformClasses(classes.toArray(new Class<?>[0]));
    }
}
 
Example #6
Source File: SettingsManager.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public void updateRetransform(List<Class<? extends Event>> eventClasses) {
    List<Class<?>> classes = new ArrayList<>();
    for(Class<? extends Event> eventClass: eventClasses) {
        EventHandler eh = Utils.getHandler(eventClass);
        if (eh != null ) {
            PlatformEventType eventType = eh.getPlatformEventType();
            if (eventType.isMarkedForInstrumentation()) {
                classes.add(eventClass);
                eventType.markForInstrumentation(false);
                // A bit premature to set it here, but hard to check
                // after call to retransformClasses.
                eventType.setInstrumented();
            }
        }
    }
    if (!classes.isEmpty()) {
        JVM.getJVM().retransformClasses(classes.toArray(new Class<?>[0]));
    }
}
 
Example #7
Source File: MetadataRepository.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private void unregisterUnloaded() {
    long unloaded = jvm.getUnloadedEventClassCount();
    if (this.lastUnloaded != unloaded) {
        this.lastUnloaded = unloaded;
        List<Class<? extends Event>> eventClasses = jvm.getAllEventClasses();
        HashSet<Long> knownIds = new HashSet<>(eventClasses.size());
        for (Class<? extends Event>  ec: eventClasses) {
            knownIds.add(Type.getTypeId(ec));
        }
        for (Type type : typeLibrary.getTypes()) {
            if (type instanceof PlatformEventType) {
                if (!knownIds.contains(type.getId())) {
                    PlatformEventType pe = (PlatformEventType) type;
                    if (!pe.isJVM()) {
                        pe.setRegistered(false);
                    }
                }
            }
        }
    }
}
 
Example #8
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 #9
Source File: TestGetAllEventClasses.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@SafeVarargs
private static void assertEvents(JVM jvm, boolean inclusion, Class<? extends Event>... targetEvents) {
    final List<Class<? extends Event>> list = jvm.getAllEventClasses();
    for (Class<? extends Event> ev : targetEvents) {
       if (list.contains(ev)) {
           if (inclusion) {
               continue;
           }
           throw new AssertionError(ev.getName() + " in list but should not be!");
       }
       if (!inclusion) {
           continue;
       }
       throw new AssertionError(ev.getName() + " in not in list but should be!");
   }
}
 
Example #10
Source File: TestLoadEventAfterStart.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Throwable {
    Recording r = new Recording();
    r.start();

    ClassLoader classLoader = TestLoadEventAfterStart.class.getClassLoader();
    Class<? extends Event> eventClass =
        classLoader.loadClass("jdk.testlibrary.jfr.SimpleEvent").asSubclass(Event.class);

    r.enable(eventClass).withThreshold(Duration.ofMillis(0)).withoutStackTrace();
    createEvent(eventClass, 1);
    r.disable(eventClass);
    createEvent(eventClass, 2);
    r.enable(eventClass).withThreshold(Duration.ofMillis(0)).withoutStackTrace();
    createEvent(eventClass, 3);

    r.stop();
    verifyEvents(r, 1, 3);
}
 
Example #11
Source File: MetadataRepository.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private void unregisterUnloaded() {
    long unloaded = jvm.getUnloadedEventClassCount();
    if (this.lastUnloaded != unloaded) {
        this.lastUnloaded = unloaded;
        List<Class<? extends Event>> eventClasses = jvm.getAllEventClasses();
        HashSet<Long> knownIds = new HashSet<>(eventClasses.size());
        for (Class<? extends Event>  ec: eventClasses) {
            knownIds.add(Type.getTypeId(ec));
        }
        for (Type type : typeLibrary.getTypes()) {
            if (type instanceof PlatformEventType) {
                if (!knownIds.contains(type.getId())) {
                    PlatformEventType pe = (PlatformEventType) type;
                    if (!pe.isJVM()) {
                        pe.setRegistered(false);
                    }
                }
            }
        }
    }
}
 
Example #12
Source File: EventClassBuilder.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private void buildClassInfo() {
    String internalSuperName = ASMToolkit.getInternalName(Event.class.getName());
    String internalClassName = type.getInternalName();
    classWriter.visit(52, Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_SUPER, internalClassName, null, internalSuperName, null);

    for (AnnotationElement a : annotationElements) {
        String descriptor = ASMToolkit.getDescriptor(a.getTypeName());
        AnnotationVisitor av = classWriter.visitAnnotation(descriptor, true);
        for (ValueDescriptor v : a.getValueDescriptors()) {
            Object value = a.getValue(v.getName());
            String name = v.getName();
            if (v.isArray()) {
                AnnotationVisitor arrayVisitor = av.visitArray(name);
                Object[] array = (Object[]) value;
                for (int i = 0; i < array.length; i++) {
                    arrayVisitor.visit(null, array[i]);
                }
                arrayVisitor.visitEnd();
            } else {
                av.visit(name, value);
            }
        }
        av.visitEnd();
    }
}
 
Example #13
Source File: EventHandlerCreator.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public Class<? extends EventHandler> makeEventHandlerClass() {
    buildClassInfo();
    buildConstructor();
    buildWriteMethod();
    byte[] bytes = classWriter.toByteArray();
    ASMToolkit.logASM(className, bytes);
    return SecuritySupport.defineClass(className, bytes, Event.class.getClassLoader()).asSubclass(EventHandler.class);
}
 
Example #14
Source File: Utils.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
static synchronized EventHandler getHandler(Class<? extends Event> eventClass) {
    Utils.ensureValidEventSubclass(eventClass);
    try {
        Field f = eventClass.getDeclaredField(EventInstrumentation.FIELD_EVENT_HANDLER);
        SecuritySupport.setAccessible(f);
        return (EventHandler) f.get(null);
    } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
        throw new InternalError("Could not access event handler");
    }
}
 
Example #15
Source File: EventHandlerCreator.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public Class<? extends EventHandler> makeEventHandlerClass() {
    buildClassInfo();
    buildConstructor();
    buildWriteMethod();
    byte[] bytes = classWriter.toByteArray();
    ASMToolkit.logASM(className, bytes);
    return SecuritySupport.defineClass(className, bytes, Event.class.getClassLoader()).asSubclass(EventHandler.class);
}
 
Example #16
Source File: EventHandlerCreator.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static List<FieldInfo> createFieldInfos(Class<? extends Event> eventClass, EventType type) throws Error {
    List<FieldInfo> fieldInfos = new ArrayList<>();
    for (ValueDescriptor v : type.getFields()) {
        // Only value descriptors that are not fields on the event class.
        if (v != TypeLibrary.STACK_TRACE_FIELD && v != TypeLibrary.THREAD_FIELD) {
            String fieldName = PrivateAccess.getInstance().getFieldName(v);
            String fieldDescriptor = ASMToolkit.getDescriptor(v.getTypeName());
            Class<?> c = eventClass;
            String internalName = null;
            while (c != Event.class) {
                try {
                    Field field = c.getDeclaredField(fieldName);
                    if (c == eventClass || !Modifier.isPrivate(field.getModifiers())) {
                        internalName = ASMToolkit.getInternalName(c.getName());
                        break;
                    }
                } catch (NoSuchFieldException | SecurityException e) {
                    // ignore
                }
                c = c.getSuperclass();
            }
            if (internalName != null) {
                fieldInfos.add(new FieldInfo(fieldName, fieldDescriptor, internalName));
            } else {
                throw new InternalError("Could not locate field " + fieldName + " for event type" + type.getName());
            }
        }
    }
    return fieldInfos;
}
 
Example #17
Source File: EventClassBuilder.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public Class<? extends Event> build() {
    buildClassInfo();
    buildConstructor();
    buildFields();
    buildSetMethod();
    endClass();
    byte[] bytes = classWriter.toByteArray();
    ASMToolkit.logASM(fullClassName, bytes);
    return SecuritySupport.defineClass(type.getInternalName(), bytes, Event.class.getClassLoader()).asSubclass(Event.class);
}
 
Example #18
Source File: Utils.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
static synchronized void setHandler(Class<? extends Event> eventClass, EventHandler handler) {
    Utils.ensureValidEventSubclass(eventClass);
    try {
        Field field = eventClass.getDeclaredField(EventInstrumentation.FIELD_EVENT_HANDLER);
        SecuritySupport.setAccessible(field);
        field.set(null, handler);
    } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
        throw new InternalError("Could not access event handler");
    }
}
 
Example #19
Source File: MetadataRepository.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public synchronized EventType getEventType(Class<? extends Event> eventClass) {
    EventHandler h = getHandler(eventClass);
    if (h != null && h.isRegistered()) {
        return h.getEventType();
    }
    throw new IllegalStateException("Event class " + eventClass.getName() + " is not registered");
}
 
Example #20
Source File: Utils.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
static List<Field> getVisibleEventFields(Class<?> clazz) {
    Utils.ensureValidEventSubclass(clazz);
    List<Field> fields = new ArrayList<>();
    for (Class<?> c = clazz; c != Event.class; c = c.getSuperclass()) {
        for (Field field : c.getDeclaredFields()) {
            // skip private field in base classes
            if (c == clazz || !Modifier.isPrivate(field.getModifiers())) {
                fields.add(field);
            }
        }
    }
    return fields;
}
 
Example #21
Source File: Utils.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void ensureValidEventSubclass(Class<?> eventClass) {
    if (Event.class.isAssignableFrom(eventClass) && Modifier.isAbstract(eventClass.getModifiers())) {
        throw new IllegalArgumentException("Abstract event classes are not allowed");
    }
    if (eventClass == Event.class || !Event.class.isAssignableFrom(eventClass)) {
        throw new IllegalArgumentException("Must be a subclass to " + Event.class.getName());
    }
}
 
Example #22
Source File: TestGetAllEventClasses.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String... args) throws ClassNotFoundException {
    JVM jvm = JVM.getJVM();
    // before creating  native
    assertEmptyEventList(jvm);
    jvm.createNativeJFR();
    // after creating native
    assertEmptyEventList(jvm);

    // Test event class load is triggered and only once
    Class<? extends Event> clazz = initialize("jdk.jfr.jvm.HelloWorldEvent1");
    // check that the event class is registered
    assertEventsIncluded(jvm, clazz);
    // second active use of the same event class should not add another class
    // to the list - it would already be loaded
    clazz = initialize(clazz);
    assertEventsIncluded(jvm, clazz);

    // second event class
    Class<? extends Event> clazz2 = initialize("jdk.jfr.jvm.HelloWorldEvent2");
    // the list of event classes should now have two classes registered
    assertEventsIncluded(jvm, clazz, clazz2);

    // verify that an abstract event class is not included
    Class<? extends Event> abstractClass = initialize(MyAbstractEvent.class); // to run <clinit>
    assertEventsExcluded(jvm, abstractClass);

    // verify that a class that is yet to run its <clinit> is not included in the list of event classes
    assertEventsExcluded(jvm, MyUnInitializedEvent.class);

    // ensure old classes are not lost
    assertEventsIncluded(jvm, clazz, clazz2);

    jvm.destroyNativeJFR();
}
 
Example #23
Source File: TestLoadEventAfterStart.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void createEvent(Class<? extends Event> eventClass, int id) throws Exception {
    Constructor<? extends Event> constructor = eventClass.getConstructor();
    Event event = (Event) constructor.newInstance();
    event.begin();
    eventClass.getDeclaredField("id").setInt(event, id);
    event.end();
    event.commit();
}
 
Example #24
Source File: Utils.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
static synchronized EventHandler getHandler(Class<? extends Event> eventClass) {
    Utils.ensureValidEventSubclass(eventClass);
    try {
        Field f = eventClass.getDeclaredField(EventInstrumentation.FIELD_EVENT_HANDLER);
        SecuritySupport.setAccessible(f);
        return (EventHandler) f.get(null);
    } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
        throw new InternalError("Could not access event handler");
    }
}
 
Example #25
Source File: TestUnloadEventClassCount.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static MyClassLoader createClassLoaderWithEventClass() throws Exception {
    String resourceName = EVENT_NAME.replace('.', '/') + ".class";
    try (InputStream is = TestUnloadEventClassCount.class.getClassLoader().getResourceAsStream(resourceName)) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        byte[] buffer = new byte[4096];
        int byteValue = 0;
        while ((byteValue = is.read(buffer, 0, buffer.length)) != -1) {
            baos.write(buffer, 0, byteValue);
        }
        baos.flush();
        MyClassLoader myClassLoader = new MyClassLoader();
        Class<?> eventClass = myClassLoader.defineClass(EVENT_NAME, baos.toByteArray());
        if (eventClass == null) {
            throw new Exception("Could not define test class");
        }
        if (eventClass.getSuperclass() != Event.class) {
            throw new Exception("Superclass should be jdk.jfr.Event");
        }
        if (eventClass.getSuperclass().getClassLoader() != null) {
            throw new Exception("Class loader of jdk.jfr.Event should be null");
        }
        if (eventClass.getClassLoader() != myClassLoader) {
            throw new Exception("Incorrect class loader for event class");
        }
        eventClass.newInstance(); // force <clinit>
        return myClassLoader;
    }
}
 
Example #26
Source File: TestEventFactory.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Throwable {
    Recording r = new Recording();
    r.enable(EVENT_TYPE_SHOULD_COMMIT.getName()).withoutStackTrace();
    r.enable(EVENT_TYPE_SHOULD_NOT_COMMIT.getName()).withoutStackTrace();

    // Commit before start, should not be included
    ef1 = EventFactory.create(EVENT_TYPE_SHOULD_NOT_COMMIT.getAnnotations(), EVENT_TYPE_SHOULD_NOT_COMMIT.getFields());

    Event event1 = ef1.newEvent();

    setEventValues(event1, ef1, EVENT_TYPE_SHOULD_NOT_COMMIT);
    event1.commit();

    r.start();
    // Commit after start, should be included
    ef2 = EventFactory.create(EVENT_TYPE_SHOULD_COMMIT.getAnnotations(),  EVENT_TYPE_SHOULD_COMMIT.getFields());

    Event event2 = ef2.newEvent();
    setEventValues(event2, ef2, EVENT_TYPE_SHOULD_COMMIT);
    event2.commit();

    r.stop();

    RecordingFile es = Events.copyTo(r);
    EventType e1 = findEventType(es.readEventTypes(), EVENT_TYPE_SHOULD_NOT_COMMIT.getName());
    assertEquals(e1, ef1.getEventType());

    EventType e2 = findEventType(es.readEventTypes(), EVENT_TYPE_SHOULD_COMMIT.getName());
    assertEquals(e2, ef2.getEventType());

    verifyEvent(es);
}
 
Example #27
Source File: TestDynamicAnnotations.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void testArray() throws Exception {
    List<AnnotationElement> annotations = new ArrayList<>();
    Map<String, Object> values = new HashMap<>();
    values.put("stringArray", new String[] {"zero", "one"});
    values.put("intArray", new int[] {0, 1});
    values.put("longArray", new long[] {0L, 1L});
    values.put("floatArray", new float[] {0.0f, 1.0f});
    values.put("doubleArray", new double[] {0.0, 1.0});
    values.put("booleanArray", new boolean[] {false, true});
    values.put("shortArray", new short[] {(short)0, (short)1});
    values.put("byteArray", new byte[] {(byte)0, (byte)1});
    values.put("charArray", new char[] {'0','1'});

    annotations.add(new AnnotationElement(Array.class, values));
    EventFactory f = EventFactory.create(annotations, Collections.emptyList());
    Array a = f.getEventType().getAnnotation(Array.class);
    if (a == null) {
        throw new Exception("Missing array annotation");
    }
    verifyArrayAnnotation(a);
    System.out.println("Event metadata is correct");
    try (Recording r = new Recording()) {
        r.start();
        Event e = f.newEvent();
        e.commit();
        r.stop();
        List<RecordedEvent> events = Events.fromRecording(r);
        Events.hasEvents(events);
        RecordedEvent re = events.get(0);
        Array arrayAnnotation = re.getEventType().getAnnotation(Array.class);
        if (arrayAnnotation== null) {
            throw new Exception("Missing array annotation");
        }
        verifyArrayAnnotation(arrayAnnotation);
        System.out.println("Persisted event metadata is correct");
    }
}
 
Example #28
Source File: MetadataRepository.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public synchronized EventType getEventType(Class<? extends Event> eventClass) {
    EventHandler h = getHandler(eventClass);
    if (h != null && h.isRegistered()) {
        return h.getEventType();
    }
    throw new IllegalStateException("Event class " + eventClass.getName() + " is not registered");
}
 
Example #29
Source File: TestDynamicAnnotations.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void testArray() throws Exception {
    List<AnnotationElement> annotations = new ArrayList<>();
    Map<String, Object> values = new HashMap<>();
    values.put("stringArray", new String[] {"zero", "one"});
    values.put("intArray", new int[] {0, 1});
    values.put("longArray", new long[] {0L, 1L});
    values.put("floatArray", new float[] {0.0f, 1.0f});
    values.put("doubleArray", new double[] {0.0, 1.0});
    values.put("booleanArray", new boolean[] {false, true});
    values.put("shortArray", new short[] {(short)0, (short)1});
    values.put("byteArray", new byte[] {(byte)0, (byte)1});
    values.put("charArray", new char[] {'0','1'});

    annotations.add(new AnnotationElement(Array.class, values));
    EventFactory f = EventFactory.create(annotations, Collections.emptyList());
    Array a = f.getEventType().getAnnotation(Array.class);
    if (a == null) {
        throw new Exception("Missing array annotation");
    }
    verifyArrayAnnotation(a);
    System.out.println("Event metadata is correct");
    try (Recording r = new Recording()) {
        r.start();
        Event e = f.newEvent();
        e.commit();
        r.stop();
        List<RecordedEvent> events = Events.fromRecording(r);
        Events.hasEvents(events);
        RecordedEvent re = events.get(0);
        Array arrayAnnotation = re.getEventType().getAnnotation(Array.class);
        if (arrayAnnotation== null) {
            throw new Exception("Missing array annotation");
        }
        verifyArrayAnnotation(arrayAnnotation);
        System.out.println("Persisted event metadata is correct");
    }
}
 
Example #30
Source File: RequestEngine.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void addTrustedJDKHook(Class<? extends Event> eventClass, Runnable runnable) {
    if (eventClass.getClassLoader() != null) {
        throw new SecurityException("Hook can only be registered for event classes that are loaded by the bootstrap class loader");
    }
    if (runnable.getClass().getClassLoader() != null) {
        throw new SecurityException("Runnable hook class must be loaded by the bootstrap class loader");
    }
    EventType eType = MetadataRepository.getInstance().getEventType(eventClass);
    PlatformEventType pType = PrivateAccess.getInstance().getPlatformEventType(eType);
    addHookInternal(null, pType, runnable);
}