001/*
002 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation.
008 *
009 * This code is distributed in the hope that it will be useful, but WITHOUT
010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
011 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
012 * version 2 for more details (a copy is included in the LICENSE file that
013 * accompanied this code).
014 *
015 * You should have received a copy of the GNU General Public License version
016 * 2 along with this work; if not, write to the Free Software Foundation,
017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
018 *
019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
020 * or visit www.oracle.com if you need additional information or have any
021 * questions.
022 */
023package jdk.internal.jvmci.hotspot.events;
024
025/**
026 * A provider that provides a specific implementation for events that can be logged in the compiler.
027 */
028public interface EventProvider {
029
030    /**
031     * An instant event is an event that is not considered to have taken any time.
032     */
033    interface InstantEvent {
034        /**
035         * Commits the event.
036         */
037        void commit();
038
039        /**
040         * Determines if this particular event instance would be committed to the data stream right
041         * now if application called {@link #commit()}. This in turn depends on whether the event is
042         * enabled and possible other factors.
043         *
044         * @return if this event would be committed on a call to {@link #commit()}.
045         */
046        boolean shouldWrite();
047    }
048
049    /**
050     * Timed events describe an operation that somehow consumes time.
051     */
052    interface TimedEvent extends InstantEvent {
053        /**
054         * Starts the timing for this event.
055         */
056        void begin();
057
058        /**
059         * Ends the timing period for this event.
060         */
061        void end();
062    }
063
064    /**
065     * Creates a new {@link CompilationEvent}.
066     *
067     * @return a compilation event
068     */
069    CompilationEvent newCompilationEvent();
070
071    /**
072     * A compilation event.
073     */
074    interface CompilationEvent extends TimedEvent {
075        void setMethod(String method);
076
077        void setCompileId(int compileId);
078
079        void setCompileLevel(int compileLevel);
080
081        void setSucceeded(boolean succeeded);
082
083        void setIsOsr(boolean isOsr);
084
085        void setCodeSize(int codeSize);
086
087        void setInlinedBytes(int inlinedBytes);
088    }
089
090    /**
091     * Creates a new {@link CompilerFailureEvent}.
092     *
093     * @return a compiler failure event
094     */
095    CompilerFailureEvent newCompilerFailureEvent();
096
097    /**
098     * A compiler failure event.
099     */
100    interface CompilerFailureEvent extends InstantEvent {
101        void setCompileId(int compileId);
102
103        void setMessage(String message);
104    }
105}