1 /*
   2  * Copyright (c) 2020, 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 
  24 #ifndef SHARE_COMPILER_COMPILEREVENT_HPP
  25 #define SHARE_COMPILER_COMPILEREVENT_HPP
  26 
  27 #include "jni.h"
  28 #include "compiler/compilerDefinitions.hpp"
  29 #include "memory/allocation.hpp"
  30 #include "utilities/macros.hpp"
  31 #include "utilities/ticks.hpp"
  32 
  33 #if INCLUDE_JFR
  34 #include "jfr/utilities/jfrTime.hpp"
  35 #endif
  36 
  37 class ciMethod;
  38 template <typename>
  39 class GrowableArray;
  40 class Method;
  41 class EventCompilation;
  42 class EventCompilationFailure;
  43 class EventCompilerInlining;
  44 class EventCompilerPhase;
  45 struct JfrStructCalleeMethod;
  46 
  47 class CompilerEvent : AllStatic {
  48  public:
  49   static jlong ticksNow() {
  50     // Using Ticks for consistent usage outside JFR folder.
  51     JFR_ONLY(return JfrTime::is_ft_enabled() ? Ticks::now().ft_value() : Ticks::now().value();) NOT_JFR_RETURN_(0L);
  52   }
  53 
  54   class CompilationEvent : AllStatic {
  55    public:
  56     static void post(EventCompilation& event, int compile_id, CompilerType type, Method* method, int compile_level, bool success, bool is_osr, int code_size, int inlined_bytecodes) NOT_JFR_RETURN();
  57   };
  58 
  59   class CompilationFailureEvent : AllStatic {
  60    public:
  61     static void post(EventCompilationFailure& event, int compile_id, const char* reason) NOT_JFR_RETURN();
  62   };
  63 
  64   class PhaseEvent : AllStatic {
  65     friend class CompilerPhaseTypeConstant;
  66    public:
  67     /**
  68      * Register compiler phases for JFR type CompilerPhaseType serialization purposes.
  69      * This method is called during compiler creation or during compilation.
  70      * Registration will serialize the passed in phase constants, supporting bulk and/or incremental registrations.
  71      * This method returns start index of new list that just got appended to phase_names.
  72      * Param new_phases may contain duplicates.
  73      * Return value could be used for mapping purpose at caller site, or caller can assume explicit order of registration.
  74      */
  75     static int register_phases(GrowableArray<const char*>* new_phases) NOT_JFR_RETURN_(-1);
  76 
  77     static void post(EventCompilerPhase& event, const Ticks& start_time, int phase, int compile_id, int level) NOT_JFR_RETURN();
  78     static void post(EventCompilerPhase& event, jlong start_time, int phase, int compile_id, int level) {
  79       JFR_ONLY(post(event, Ticks(start_time), phase, compile_id, level);)
  80     }
  81   };
  82 
  83   class InlineEvent : AllStatic {
  84     static void post(EventCompilerInlining& event, int compile_id, Method* caller, const JfrStructCalleeMethod& callee, bool success, const char* msg, int bci) NOT_JFR_RETURN();
  85    public:
  86     static void post(EventCompilerInlining& event, int compile_id, Method* caller, Method* callee, bool success, const char* msg, int bci) NOT_JFR_RETURN();
  87     static void post(EventCompilerInlining& event, int compile_id, Method* caller, ciMethod* callee, bool success, const char* msg, int bci) NOT_JFR_RETURN();
  88   };
  89 };
  90 #endif // SHARE_COMPILER_COMPILEREVENT_HPP