src/share/vm/runtime/simpleThresholdPolicy.hpp

Mon, 12 Aug 2019 18:30:40 +0300

author
apetushkov
date
Mon, 12 Aug 2019 18:30:40 +0300
changeset 9858
b985cbb00e68
parent 4037
da91efe96a93
child 6876
710a3c8b516e
permissions
-rw-r--r--

8223147: JFR Backport
8199712: Flight Recorder
8203346: JFR: Inconsistent signature of jfr_add_string_constant
8195817: JFR.stop should require name of recording
8195818: JFR.start should increase autogenerated name by one
8195819: Remove recording=x from jcmd JFR.check output
8203921: JFR thread sampling is missing fixes from JDK-8194552
8203929: Limit amount of data for JFR.dump
8203664: JFR start failure after AppCDS archive created with JFR StartFlightRecording
8003209: JFR events for network utilization
8207392: [PPC64] Implement JFR profiling
8202835: jfr/event/os/TestSystemProcess.java fails on missing events
Summary: Backport JFR from JDK11. Initial integration
Reviewed-by: neugens

iveresov@2138 1 /*
coleenp@4037 2 * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
iveresov@2138 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
iveresov@2138 4 *
iveresov@2138 5 * This code is free software; you can redistribute it and/or modify it
iveresov@2138 6 * under the terms of the GNU General Public License version 2 only, as
iveresov@2138 7 * published by the Free Software Foundation.
iveresov@2138 8 *
iveresov@2138 9 * This code is distributed in the hope that it will be useful, but WITHOUT
iveresov@2138 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
iveresov@2138 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
iveresov@2138 12 * version 2 for more details (a copy is included in the LICENSE file that
iveresov@2138 13 * accompanied this code).
iveresov@2138 14 *
iveresov@2138 15 * You should have received a copy of the GNU General Public License version
iveresov@2138 16 * 2 along with this work; if not, write to the Free Software Foundation,
iveresov@2138 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
iveresov@2138 18 *
iveresov@2138 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
iveresov@2138 20 * or visit www.oracle.com if you need additional information or have any
iveresov@2138 21 * questions.
iveresov@2138 22 *
iveresov@2138 23 */
iveresov@2138 24
stefank@2314 25 #ifndef SHARE_VM_RUNTIME_SIMPLETHRESHOLDPOLICY_HPP
stefank@2314 26 #define SHARE_VM_RUNTIME_SIMPLETHRESHOLDPOLICY_HPP
stefank@2314 27
stefank@2314 28 #include "code/nmethod.hpp"
coleenp@4037 29 #include "oops/methodData.hpp"
stefank@2314 30 #include "runtime/compilationPolicy.hpp"
stefank@2314 31 #include "utilities/globalDefinitions.hpp"
stefank@2314 32
iveresov@2138 33 class CompileTask;
iveresov@2138 34 class CompileQueue;
iveresov@2138 35
iveresov@2138 36 class SimpleThresholdPolicy : public CompilationPolicy {
iveresov@2138 37 int _c1_count, _c2_count;
iveresov@2138 38
iveresov@2138 39 // Check if the counter is big enough and set carry (effectively infinity).
iveresov@2138 40 inline void set_carry_if_necessary(InvocationCounter *counter);
coleenp@4037 41 // Set carry flags in the counters (in Method* and MDO).
coleenp@4037 42 inline void handle_counter_overflow(Method* method);
iveresov@2138 43 // Call and loop predicates determine whether a transition to a higher compilation
iveresov@2138 44 // level should be performed (pointers to predicate functions are passed to common_TF().
iveresov@2138 45 // Predicates also take compiler load into account.
iveresov@2138 46 typedef bool (SimpleThresholdPolicy::*Predicate)(int i, int b, CompLevel cur_level);
iveresov@2138 47 bool call_predicate(int i, int b, CompLevel cur_level);
iveresov@2138 48 bool loop_predicate(int i, int b, CompLevel cur_level);
iveresov@2138 49 // Common transition function. Given a predicate determines if a method should transition to another level.
coleenp@4037 50 CompLevel common(Predicate p, Method* method, CompLevel cur_level);
iveresov@2138 51 // Transition functions.
iveresov@2138 52 // call_event determines if a method should be compiled at a different
iveresov@2138 53 // level with a regular invocation entry.
coleenp@4037 54 CompLevel call_event(Method* method, CompLevel cur_level);
iveresov@2138 55 // loop_event checks if a method should be OSR compiled at a different
iveresov@2138 56 // level.
coleenp@4037 57 CompLevel loop_event(Method* method, CompLevel cur_level);
iveresov@3312 58 void print_counters(const char* prefix, methodHandle mh);
iveresov@2138 59 protected:
iveresov@2138 60 int c1_count() const { return _c1_count; }
iveresov@2138 61 int c2_count() const { return _c2_count; }
iveresov@2138 62 void set_c1_count(int x) { _c1_count = x; }
iveresov@2138 63 void set_c2_count(int x) { _c2_count = x; }
iveresov@2138 64
iveresov@2988 65 enum EventType { CALL, LOOP, COMPILE, REMOVE_FROM_QUEUE, UPDATE_IN_QUEUE, REPROFILE, MAKE_NOT_ENTRANT };
iveresov@2138 66 void print_event(EventType type, methodHandle mh, methodHandle imh, int bci, CompLevel level);
iveresov@2138 67 // Print policy-specific information if necessary
iveresov@2138 68 virtual void print_specific(EventType type, methodHandle mh, methodHandle imh, int bci, CompLevel level) { }
iveresov@2138 69 // Check if the method can be compiled, change level if necessary
iveresov@3452 70 void compile(methodHandle mh, int bci, CompLevel level, JavaThread* thread);
iveresov@2138 71 // Submit a given method for compilation
iveresov@3452 72 virtual void submit_compile(methodHandle mh, int bci, CompLevel level, JavaThread* thread);
iveresov@2138 73 // Simple methods are as good being compiled with C1 as C2.
iveresov@2138 74 // This function tells if it's such a function.
coleenp@4037 75 inline bool is_trivial(Method* method);
iveresov@2138 76
iveresov@2138 77 // Predicate helpers are used by .*_predicate() methods as well as others.
iveresov@2138 78 // They check the given counter values, multiplied by the scale against the thresholds.
iveresov@2138 79 template<CompLevel level> static inline bool call_predicate_helper(int i, int b, double scale);
iveresov@2138 80 template<CompLevel level> static inline bool loop_predicate_helper(int i, int b, double scale);
iveresov@2138 81
iveresov@2138 82 // Get a compilation level for a given method.
coleenp@4037 83 static CompLevel comp_level(Method* method) {
iveresov@2138 84 nmethod *nm = method->code();
iveresov@2138 85 if (nm != NULL && nm->is_in_use()) {
iveresov@2138 86 return (CompLevel)nm->comp_level();
iveresov@2138 87 }
iveresov@2138 88 return CompLevel_none;
iveresov@2138 89 }
iveresov@2138 90 virtual void method_invocation_event(methodHandle method, methodHandle inlinee,
iveresov@3452 91 CompLevel level, nmethod* nm, JavaThread* thread);
iveresov@2138 92 virtual void method_back_branch_event(methodHandle method, methodHandle inlinee,
iveresov@3452 93 int bci, CompLevel level, nmethod* nm, JavaThread* thread);
iveresov@2138 94 public:
iveresov@2138 95 SimpleThresholdPolicy() : _c1_count(0), _c2_count(0) { }
iveresov@2138 96 virtual int compiler_count(CompLevel comp_level) {
iveresov@2138 97 if (is_c1_compile(comp_level)) return c1_count();
iveresov@2138 98 if (is_c2_compile(comp_level)) return c2_count();
iveresov@2138 99 return 0;
iveresov@2138 100 }
iveresov@3035 101 virtual CompLevel initial_compile_level() { return MIN2((CompLevel)TieredStopAtLevel, CompLevel_initial_compile); }
iveresov@2138 102 virtual void do_safepoint_work() { }
coleenp@4037 103 virtual void delay_compilation(Method* method) { }
coleenp@4037 104 virtual void disable_compilation(Method* method) { }
iveresov@2559 105 virtual void reprofile(ScopeDesc* trap_scope, bool is_osr);
iveresov@2138 106 virtual nmethod* event(methodHandle method, methodHandle inlinee,
iveresov@3452 107 int branch_bci, int bci, CompLevel comp_level, nmethod* nm, JavaThread* thread);
iveresov@2138 108 // Select task is called by CompileBroker. We should return a task or NULL.
iveresov@2138 109 virtual CompileTask* select_task(CompileQueue* compile_queue);
iveresov@2138 110 // Tell the runtime if we think a given method is adequately profiled.
coleenp@4037 111 virtual bool is_mature(Method* method);
iveresov@2138 112 // Initialize: set compiler thread count
iveresov@2138 113 virtual void initialize();
iveresov@2988 114 virtual bool should_not_inline(ciEnv* env, ciMethod* callee) {
iveresov@2988 115 return (env->comp_level() == CompLevel_limited_profile ||
iveresov@2988 116 env->comp_level() == CompLevel_full_profile) &&
iveresov@2988 117 callee->has_loops();
iveresov@2988 118 }
iveresov@2138 119 };
stefank@2314 120
stefank@2314 121 #endif // SHARE_VM_RUNTIME_SIMPLETHRESHOLDPOLICY_HPP

mercurial