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 */
23package jdk.vm.ci.hotspot;
24
25import jdk.vm.ci.hotspot.EmptyEventProvider.EmptyCompilationEvent;
26import jdk.vm.ci.hotspot.EmptyEventProvider.EmptyCompilerFailureEvent;
27
28/**
29 * Service-provider class for logging compiler related events.
30 */
31public interface EventProvider {
32
33    /**
34     * Creates and returns an empty implementation for {@link EventProvider}. This implementation
35     * can be used when no logging is requested.
36     */
37    static EventProvider createEmptyEventProvider() {
38        return new EmptyEventProvider();
39    }
40
41    /**
42     * Creates and returns an empty implementation for {@link CompilationEvent}.
43     */
44    static CompilationEvent createEmptyCompilationEvent() {
45        return new EmptyCompilationEvent();
46    }
47
48    /**
49     * Creates and returns an empty implementation for {@link CompilationEvent}.
50     */
51    static CompilerFailureEvent createEmptyCompilerFailureEvent() {
52        return new EmptyCompilerFailureEvent();
53    }
54
55    /**
56     * An instant event is an event that is not considered to have taken any time.
57     */
58    public interface InstantEvent {
59        /**
60         * Commits the event.
61         */
62        void commit();
63
64        /**
65         * Determines if this particular event instance would be committed to the data stream right
66         * now if application called {@link #commit()}. This in turn depends on whether the event is
67         * enabled and possible other factors.
68         *
69         * @return if this event would be committed on a call to {@link #commit()}.
70         */
71        boolean shouldWrite();
72    }
73
74    /**
75     * Timed events describe an operation that somehow consumes time.
76     */
77    public interface TimedEvent extends InstantEvent {
78        /**
79         * Starts the timing for this event.
80         */
81        void begin();
82
83        /**
84         * Ends the timing period for this event.
85         */
86        void end();
87    }
88
89    /**
90     * Creates a new {@link CompilationEvent}.
91     *
92     * @return a compilation event
93     */
94    public abstract CompilationEvent newCompilationEvent();
95
96    /**
97     * A compilation event.
98     */
99    public interface CompilationEvent extends TimedEvent {
100        void setMethod(String method);
101
102        void setCompileId(int compileId);
103
104        void setCompileLevel(int compileLevel);
105
106        void setSucceeded(boolean succeeded);
107
108        void setIsOsr(boolean isOsr);
109
110        void setCodeSize(int codeSize);
111
112        void setInlinedBytes(int inlinedBytes);
113    }
114
115    /**
116     * Creates a new {@link CompilerFailureEvent}.
117     *
118     * @return a compiler failure event
119     */
120    public abstract CompilerFailureEvent newCompilerFailureEvent();
121
122    /**
123     * A compiler failure event.
124     */
125    public interface CompilerFailureEvent extends InstantEvent {
126        void setCompileId(int compileId);
127
128        void setMessage(String message);
129    }
130}
131