Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.jvmci.hotspot.jfr/src/com/oracle/jvmci/hotspot/jfr/events/JFREventProvider.java @ 21631:77acf6ba2fc0
Move EventProvider to jvmci.hotspot, make it a JVMCI Service
author | Gilles Duboscq <gilles.m.duboscq@oracle.com> |
---|---|
date | Mon, 01 Jun 2015 17:03:29 +0200 |
parents | graal/com.oracle.graal.hotspot.jfr/src/com/oracle/graal/hotspot/jfr/events/JFREventProvider.java@93f282187d90 |
children | 5b9adb645217 |
comparison
equal
deleted
inserted
replaced
21630:9cc3571ef51d | 21631:77acf6ba2fc0 |
---|---|
1 /* | |
2 * Copyright (c) 2014, 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. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 */ | |
23 package com.oracle.jvmci.hotspot.jfr.events; | |
24 | |
25 import java.net.*; | |
26 | |
27 import com.oracle.jrockit.jfr.*; | |
28 import com.oracle.jvmci.hotspot.*; | |
29 import com.oracle.jvmci.hotspot.events.*; | |
30 import com.oracle.jvmci.hotspot.events.EmptyEventProvider.EmptyCompilerFailureEvent; | |
31 import com.oracle.jvmci.hotspot.events.EmptyEventProvider.EmptyCompilationEvent; | |
32 import com.oracle.jvmci.service.*; | |
33 | |
34 /** | |
35 * A JFR implementation for {@link EventProvider}. This implementation is used when Flight Recorder | |
36 * is turned on. | |
37 */ | |
38 @ServiceProvider(EventProvider.class) | |
39 public final class JFREventProvider implements EventProvider { | |
40 | |
41 private final boolean enabled; | |
42 | |
43 @SuppressWarnings("deprecation") | |
44 public JFREventProvider() { | |
45 enabled = HotSpotJVMCIRuntime.runtime().getConfig().flightRecorder; | |
46 if (enabled) { | |
47 try { | |
48 /* | |
49 * The "HotSpot JVM" producer is a native producer and we cannot use it. So we | |
50 * create our own. This has the downside that Mission Control is confused and | |
51 * doesn't show Graal's events in the "Code" tab. There are plans to revise the JFR | |
52 * code for JDK 9. | |
53 */ | |
54 Producer producer = new Producer("HotSpot JVM", "Oracle Hotspot JVM", "http://www.oracle.com/hotspot/jvm/"); | |
55 producer.register(); | |
56 // Register event classes with Producer. | |
57 for (Class<?> c : JFREventProvider.class.getDeclaredClasses()) { | |
58 if (c.isAnnotationPresent(EventDefinition.class)) { | |
59 assert com.oracle.jrockit.jfr.InstantEvent.class.isAssignableFrom(c) : c; | |
60 registerEvent(producer, c); | |
61 } | |
62 } | |
63 } catch (URISyntaxException e) { | |
64 throw new InternalError(e); | |
65 } | |
66 } | |
67 } | |
68 | |
69 /** | |
70 * Register an event class with the {@link Producer}. | |
71 * | |
72 * @param c event class | |
73 * @return the {@link EventToken event token} | |
74 */ | |
75 @SuppressWarnings({"deprecation", "javadoc", "unchecked"}) | |
76 private static EventToken registerEvent(Producer producer, Class<?> c) { | |
77 try { | |
78 return producer.addEvent((Class<? extends com.oracle.jrockit.jfr.InstantEvent>) c); | |
79 } catch (InvalidEventDefinitionException | InvalidValueException e) { | |
80 throw new InternalError(e); | |
81 } | |
82 } | |
83 | |
84 public CompilationEvent newCompilationEvent() { | |
85 if (enabled) { | |
86 return new JFRCompilationEvent(); | |
87 } | |
88 return new EmptyCompilationEvent(); | |
89 } | |
90 | |
91 /** | |
92 * A JFR compilation event. | |
93 * | |
94 * <p> | |
95 * See: event {@code Compilation} in {@code src/share/vm/trace/trace.xml} | |
96 */ | |
97 @SuppressWarnings("deprecation") | |
98 @EventDefinition(name = "Compilation", path = "vm/compiler/compilation") | |
99 public static class JFRCompilationEvent extends com.oracle.jrockit.jfr.DurationEvent implements CompilationEvent { | |
100 | |
101 /* | |
102 * FIXME method should be a Method* but we can't express that in Java. | |
103 */ | |
104 @ValueDefinition(name = "Java Method") public String method; | |
105 @ValueDefinition(name = "Compilation ID", relationKey = "COMP_ID") public int compileId; | |
106 @ValueDefinition(name = "Compilation Level") public short compileLevel; | |
107 @ValueDefinition(name = "Succeeded") public boolean succeeded; | |
108 @ValueDefinition(name = "On Stack Replacement") public boolean isOsr; | |
109 @ValueDefinition(name = "Compiled Code Size", contentType = ContentType.Bytes) public int codeSize; | |
110 @ValueDefinition(name = "Inlined Code Size", contentType = ContentType.Bytes) public int inlinedBytes; | |
111 | |
112 public void setMethod(String method) { | |
113 this.method = method; | |
114 } | |
115 | |
116 public void setCompileId(int id) { | |
117 this.compileId = id; | |
118 } | |
119 | |
120 public void setCompileLevel(int compileLevel) { | |
121 this.compileLevel = (short) compileLevel; | |
122 } | |
123 | |
124 public void setSucceeded(boolean succeeded) { | |
125 this.succeeded = succeeded; | |
126 } | |
127 | |
128 public void setIsOsr(boolean isOsr) { | |
129 this.isOsr = isOsr; | |
130 } | |
131 | |
132 public void setCodeSize(int codeSize) { | |
133 this.codeSize = codeSize; | |
134 } | |
135 | |
136 public void setInlinedBytes(int inlinedBytes) { | |
137 this.inlinedBytes = inlinedBytes; | |
138 } | |
139 } | |
140 | |
141 public CompilerFailureEvent newCompilerFailureEvent() { | |
142 if (enabled) { | |
143 return new JFRCompilerFailureEvent(); | |
144 } | |
145 return new EmptyCompilerFailureEvent(); | |
146 } | |
147 | |
148 /** | |
149 * A JFR compiler failure event. | |
150 * | |
151 * <p> | |
152 * See: event {@code CompilerFailure} in {@code src/share/vm/trace/trace.xml} | |
153 */ | |
154 @SuppressWarnings("deprecation") | |
155 @EventDefinition(name = "Compilation Failure", path = "vm/compiler/failure") | |
156 public static class JFRCompilerFailureEvent extends com.oracle.jrockit.jfr.InstantEvent implements CompilerFailureEvent { | |
157 | |
158 @ValueDefinition(name = "Compilation ID", relationKey = "COMP_ID") public int compileId; | |
159 @ValueDefinition(name = "Message", description = "The failure message") public String failure; | |
160 | |
161 public void setCompileId(int id) { | |
162 this.compileId = id; | |
163 } | |
164 | |
165 public void setMessage(String message) { | |
166 this.failure = message; | |
167 } | |
168 } | |
169 | |
170 } |