iveresov@2138: /* iveresov@2138: * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. iveresov@2138: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. iveresov@2138: * iveresov@2138: * This code is free software; you can redistribute it and/or modify it iveresov@2138: * under the terms of the GNU General Public License version 2 only, as iveresov@2138: * published by the Free Software Foundation. iveresov@2138: * iveresov@2138: * This code is distributed in the hope that it will be useful, but WITHOUT iveresov@2138: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or iveresov@2138: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License iveresov@2138: * version 2 for more details (a copy is included in the LICENSE file that iveresov@2138: * accompanied this code). iveresov@2138: * iveresov@2138: * You should have received a copy of the GNU General Public License version iveresov@2138: * 2 along with this work; if not, write to the Free Software Foundation, iveresov@2138: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. iveresov@2138: * iveresov@2138: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA iveresov@2138: * or visit www.oracle.com if you need additional information or have any iveresov@2138: * questions. iveresov@2138: * iveresov@2138: */ iveresov@2138: stefank@2314: #ifndef SHARE_VM_RUNTIME_SIMPLETHRESHOLDPOLICY_HPP stefank@2314: #define SHARE_VM_RUNTIME_SIMPLETHRESHOLDPOLICY_HPP stefank@2314: stefank@2314: #include "code/nmethod.hpp" stefank@2314: #include "oops/methodDataOop.hpp" stefank@2314: #include "runtime/compilationPolicy.hpp" stefank@2314: #include "utilities/globalDefinitions.hpp" stefank@2314: iveresov@2138: class CompileTask; iveresov@2138: class CompileQueue; iveresov@2138: iveresov@2138: class SimpleThresholdPolicy : public CompilationPolicy { iveresov@2138: int _c1_count, _c2_count; iveresov@2138: iveresov@2138: // Check if the counter is big enough and set carry (effectively infinity). iveresov@2138: inline void set_carry_if_necessary(InvocationCounter *counter); iveresov@2138: // Set carry flags in the counters (in methodOop and MDO). iveresov@2138: inline void handle_counter_overflow(methodOop method); iveresov@2138: // Call and loop predicates determine whether a transition to a higher compilation iveresov@2138: // level should be performed (pointers to predicate functions are passed to common_TF(). iveresov@2138: // Predicates also take compiler load into account. iveresov@2138: typedef bool (SimpleThresholdPolicy::*Predicate)(int i, int b, CompLevel cur_level); iveresov@2138: bool call_predicate(int i, int b, CompLevel cur_level); iveresov@2138: bool loop_predicate(int i, int b, CompLevel cur_level); iveresov@2138: // Common transition function. Given a predicate determines if a method should transition to another level. iveresov@2138: CompLevel common(Predicate p, methodOop method, CompLevel cur_level); iveresov@2138: // Transition functions. iveresov@2138: // call_event determines if a method should be compiled at a different iveresov@2138: // level with a regular invocation entry. iveresov@2138: CompLevel call_event(methodOop method, CompLevel cur_level); iveresov@2138: // loop_event checks if a method should be OSR compiled at a different iveresov@2138: // level. iveresov@2138: CompLevel loop_event(methodOop method, CompLevel cur_level); iveresov@2138: iveresov@2138: protected: iveresov@2138: int c1_count() const { return _c1_count; } iveresov@2138: int c2_count() const { return _c2_count; } iveresov@2138: void set_c1_count(int x) { _c1_count = x; } iveresov@2138: void set_c2_count(int x) { _c2_count = x; } iveresov@2138: iveresov@2138: enum EventType { CALL, LOOP, COMPILE }; iveresov@2138: void print_event(EventType type, methodHandle mh, methodHandle imh, int bci, CompLevel level); iveresov@2138: // Print policy-specific information if necessary iveresov@2138: virtual void print_specific(EventType type, methodHandle mh, methodHandle imh, int bci, CompLevel level) { } iveresov@2138: // Check if the method can be compiled, change level if necessary iveresov@2138: void compile(methodHandle mh, int bci, CompLevel level, TRAPS); iveresov@2138: // Submit a given method for compilation iveresov@2138: virtual void submit_compile(methodHandle mh, int bci, CompLevel level, TRAPS); iveresov@2138: // Simple methods are as good being compiled with C1 as C2. iveresov@2138: // This function tells if it's such a function. iveresov@2138: inline bool is_trivial(methodOop method); iveresov@2138: iveresov@2138: // Predicate helpers are used by .*_predicate() methods as well as others. iveresov@2138: // They check the given counter values, multiplied by the scale against the thresholds. iveresov@2138: template static inline bool call_predicate_helper(int i, int b, double scale); iveresov@2138: template static inline bool loop_predicate_helper(int i, int b, double scale); iveresov@2138: iveresov@2138: // Get a compilation level for a given method. iveresov@2138: static CompLevel comp_level(methodOop method) { iveresov@2138: nmethod *nm = method->code(); iveresov@2138: if (nm != NULL && nm->is_in_use()) { iveresov@2138: return (CompLevel)nm->comp_level(); iveresov@2138: } iveresov@2138: return CompLevel_none; iveresov@2138: } iveresov@2138: virtual void method_invocation_event(methodHandle method, methodHandle inlinee, iveresov@2138: CompLevel level, TRAPS); iveresov@2138: virtual void method_back_branch_event(methodHandle method, methodHandle inlinee, iveresov@2138: int bci, CompLevel level, TRAPS); iveresov@2138: public: iveresov@2138: SimpleThresholdPolicy() : _c1_count(0), _c2_count(0) { } iveresov@2138: virtual int compiler_count(CompLevel comp_level) { iveresov@2138: if (is_c1_compile(comp_level)) return c1_count(); iveresov@2138: if (is_c2_compile(comp_level)) return c2_count(); iveresov@2138: return 0; iveresov@2138: } iveresov@2138: virtual void do_safepoint_work() { } iveresov@2138: virtual void delay_compilation(methodOop method) { } iveresov@2138: virtual void disable_compilation(methodOop method) { } iveresov@2138: // TODO: we should honour reprofiling requests in the future. Currently reprofiling iveresov@2138: // would happen but not to the extent we would ideally like. iveresov@2138: virtual void reprofile(ScopeDesc* trap_scope, bool is_osr) { } iveresov@2138: virtual nmethod* event(methodHandle method, methodHandle inlinee, iveresov@2138: int branch_bci, int bci, CompLevel comp_level, TRAPS); iveresov@2138: // Select task is called by CompileBroker. We should return a task or NULL. iveresov@2138: virtual CompileTask* select_task(CompileQueue* compile_queue); iveresov@2138: // Tell the runtime if we think a given method is adequately profiled. iveresov@2138: virtual bool is_mature(methodOop method); iveresov@2138: // Initialize: set compiler thread count iveresov@2138: virtual void initialize(); iveresov@2138: }; stefank@2314: stefank@2314: #endif // SHARE_VM_RUNTIME_SIMPLETHRESHOLDPOLICY_HPP