1 /* 2 * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package jdk.jfr.api.metadata.annotations; 27 28 import jdk.jfr.Event; 29 import jdk.jfr.EventType; 30 import jdk.jfr.Frequency; 31 import jdk.jfr.MemoryAddress; 32 import jdk.jfr.DataAmount; 33 import jdk.jfr.Percentage; 34 import jdk.jfr.Timespan; 35 import jdk.jfr.Timestamp; 36 import jdk.jfr.TransitionFrom; 37 import jdk.jfr.TransitionTo; 38 import jdk.jfr.Unsigned; 39 import jdk.jfr.ValueDescriptor; 40 import jdk.test.lib.jfr.Events; 41 42 /** 43 * @test 44 * @key jfr 45 * 46 * @library /lib / 47 * @run main/othervm jdk.jfr.api.metadata.annotations.TestFieldAnnotations 48 */ 49 public class TestFieldAnnotations { 50 51 static class FieldAnnotationEvent extends Event { 52 @DataAmount 53 int memoryAmount; 54 55 @Frequency 56 float frequency; 57 58 @MemoryAddress 59 long memoryAddress; 60 61 @Percentage 62 float percentage; 63 64 @TransitionFrom 65 Thread fromThread; 66 67 @TransitionTo 68 Thread toThread; 69 70 @Unsigned 71 long unsigned; 72 73 @Timespan(Timespan.MILLISECONDS) 74 long timespan; 75 76 @Timestamp(Timestamp.MILLISECONDS_SINCE_EPOCH) 77 long timestamp; 78 } 79 80 public static void main(String[] args) throws Exception { 81 EventType t = EventType.getEventType(FieldAnnotationEvent.class); 82 83 ValueDescriptor field = t.getField("memoryAmount"); 84 Events.hasAnnotation(field, DataAmount.class); 85 86 field = t.getField("frequency"); 87 Events.hasAnnotation(field, Frequency.class); 88 89 field = t.getField("memoryAddress"); 90 Events.hasAnnotation(field, MemoryAddress.class); 91 92 field = t.getField("percentage"); 93 Events.hasAnnotation(field, Percentage.class); 94 95 field = t.getField("fromThread"); 96 Events.hasAnnotation(field, TransitionFrom.class); 97 98 field = t.getField("toThread"); 99 Events.hasAnnotation(field, TransitionTo.class); 100 101 field = t.getField("unsigned"); 102 Events.hasAnnotation(field, Unsigned.class); 103 104 field = t.getField("timespan"); 105 Events.assertAnnotation(field, Timespan.class, Timespan.MILLISECONDS); 106 107 field = t.getField("timestamp"); 108 Events.assertAnnotation(field, Timestamp.class, Timestamp.MILLISECONDS_SINCE_EPOCH); 109 } 110 }