1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/runtime/simpleThresholdPolicy.hpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,121 @@ 1.4 +/* 1.5 + * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#ifndef SHARE_VM_RUNTIME_SIMPLETHRESHOLDPOLICY_HPP 1.29 +#define SHARE_VM_RUNTIME_SIMPLETHRESHOLDPOLICY_HPP 1.30 + 1.31 +#include "code/nmethod.hpp" 1.32 +#include "oops/methodData.hpp" 1.33 +#include "runtime/compilationPolicy.hpp" 1.34 +#include "utilities/globalDefinitions.hpp" 1.35 + 1.36 +class CompileTask; 1.37 +class CompileQueue; 1.38 + 1.39 +class SimpleThresholdPolicy : public CompilationPolicy { 1.40 + int _c1_count, _c2_count; 1.41 + 1.42 + // Check if the counter is big enough and set carry (effectively infinity). 1.43 + inline void set_carry_if_necessary(InvocationCounter *counter); 1.44 + // Set carry flags in the counters (in Method* and MDO). 1.45 + inline void handle_counter_overflow(Method* method); 1.46 + // Call and loop predicates determine whether a transition to a higher compilation 1.47 + // level should be performed (pointers to predicate functions are passed to common_TF(). 1.48 + // Predicates also take compiler load into account. 1.49 + typedef bool (SimpleThresholdPolicy::*Predicate)(int i, int b, CompLevel cur_level); 1.50 + bool call_predicate(int i, int b, CompLevel cur_level); 1.51 + bool loop_predicate(int i, int b, CompLevel cur_level); 1.52 + // Common transition function. Given a predicate determines if a method should transition to another level. 1.53 + CompLevel common(Predicate p, Method* method, CompLevel cur_level); 1.54 + // Transition functions. 1.55 + // call_event determines if a method should be compiled at a different 1.56 + // level with a regular invocation entry. 1.57 + CompLevel call_event(Method* method, CompLevel cur_level); 1.58 + // loop_event checks if a method should be OSR compiled at a different 1.59 + // level. 1.60 + CompLevel loop_event(Method* method, CompLevel cur_level); 1.61 + void print_counters(const char* prefix, methodHandle mh); 1.62 +protected: 1.63 + int c1_count() const { return _c1_count; } 1.64 + int c2_count() const { return _c2_count; } 1.65 + void set_c1_count(int x) { _c1_count = x; } 1.66 + void set_c2_count(int x) { _c2_count = x; } 1.67 + 1.68 + enum EventType { CALL, LOOP, COMPILE, REMOVE_FROM_QUEUE, UPDATE_IN_QUEUE, REPROFILE, MAKE_NOT_ENTRANT }; 1.69 + void print_event(EventType type, methodHandle mh, methodHandle imh, int bci, CompLevel level); 1.70 + // Print policy-specific information if necessary 1.71 + virtual void print_specific(EventType type, methodHandle mh, methodHandle imh, int bci, CompLevel level) { } 1.72 + // Check if the method can be compiled, change level if necessary 1.73 + void compile(methodHandle mh, int bci, CompLevel level, JavaThread* thread); 1.74 + // Submit a given method for compilation 1.75 + virtual void submit_compile(methodHandle mh, int bci, CompLevel level, JavaThread* thread); 1.76 + // Simple methods are as good being compiled with C1 as C2. 1.77 + // This function tells if it's such a function. 1.78 + inline bool is_trivial(Method* method); 1.79 + 1.80 + // Predicate helpers are used by .*_predicate() methods as well as others. 1.81 + // They check the given counter values, multiplied by the scale against the thresholds. 1.82 + template<CompLevel level> static inline bool call_predicate_helper(int i, int b, double scale); 1.83 + template<CompLevel level> static inline bool loop_predicate_helper(int i, int b, double scale); 1.84 + 1.85 + // Get a compilation level for a given method. 1.86 + static CompLevel comp_level(Method* method) { 1.87 + nmethod *nm = method->code(); 1.88 + if (nm != NULL && nm->is_in_use()) { 1.89 + return (CompLevel)nm->comp_level(); 1.90 + } 1.91 + return CompLevel_none; 1.92 + } 1.93 + virtual void method_invocation_event(methodHandle method, methodHandle inlinee, 1.94 + CompLevel level, nmethod* nm, JavaThread* thread); 1.95 + virtual void method_back_branch_event(methodHandle method, methodHandle inlinee, 1.96 + int bci, CompLevel level, nmethod* nm, JavaThread* thread); 1.97 +public: 1.98 + SimpleThresholdPolicy() : _c1_count(0), _c2_count(0) { } 1.99 + virtual int compiler_count(CompLevel comp_level) { 1.100 + if (is_c1_compile(comp_level)) return c1_count(); 1.101 + if (is_c2_compile(comp_level)) return c2_count(); 1.102 + return 0; 1.103 + } 1.104 + virtual CompLevel initial_compile_level() { return MIN2((CompLevel)TieredStopAtLevel, CompLevel_initial_compile); } 1.105 + virtual void do_safepoint_work() { } 1.106 + virtual void delay_compilation(Method* method) { } 1.107 + virtual void disable_compilation(Method* method) { } 1.108 + virtual void reprofile(ScopeDesc* trap_scope, bool is_osr); 1.109 + virtual nmethod* event(methodHandle method, methodHandle inlinee, 1.110 + int branch_bci, int bci, CompLevel comp_level, nmethod* nm, JavaThread* thread); 1.111 + // Select task is called by CompileBroker. We should return a task or NULL. 1.112 + virtual CompileTask* select_task(CompileQueue* compile_queue); 1.113 + // Tell the runtime if we think a given method is adequately profiled. 1.114 + virtual bool is_mature(Method* method); 1.115 + // Initialize: set compiler thread count 1.116 + virtual void initialize(); 1.117 + virtual bool should_not_inline(ciEnv* env, ciMethod* callee) { 1.118 + return (env->comp_level() == CompLevel_limited_profile || 1.119 + env->comp_level() == CompLevel_full_profile) && 1.120 + callee->has_loops(); 1.121 + } 1.122 +}; 1.123 + 1.124 +#endif // SHARE_VM_RUNTIME_SIMPLETHRESHOLDPOLICY_HPP