Fri, 08 Oct 2010 09:29:09 -0700
Merge
iveresov@2138 | 1 | /* |
iveresov@2138 | 2 | * Copyright (c) 2001, 2010, 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 | |
iveresov@2138 | 25 | class CompileTask; |
iveresov@2138 | 26 | class CompileQueue; |
iveresov@2138 | 27 | |
iveresov@2138 | 28 | class SimpleThresholdPolicy : public CompilationPolicy { |
iveresov@2138 | 29 | int _c1_count, _c2_count; |
iveresov@2138 | 30 | |
iveresov@2138 | 31 | // Check if the counter is big enough and set carry (effectively infinity). |
iveresov@2138 | 32 | inline void set_carry_if_necessary(InvocationCounter *counter); |
iveresov@2138 | 33 | // Set carry flags in the counters (in methodOop and MDO). |
iveresov@2138 | 34 | inline void handle_counter_overflow(methodOop method); |
iveresov@2138 | 35 | // Call and loop predicates determine whether a transition to a higher compilation |
iveresov@2138 | 36 | // level should be performed (pointers to predicate functions are passed to common_TF(). |
iveresov@2138 | 37 | // Predicates also take compiler load into account. |
iveresov@2138 | 38 | typedef bool (SimpleThresholdPolicy::*Predicate)(int i, int b, CompLevel cur_level); |
iveresov@2138 | 39 | bool call_predicate(int i, int b, CompLevel cur_level); |
iveresov@2138 | 40 | bool loop_predicate(int i, int b, CompLevel cur_level); |
iveresov@2138 | 41 | // Common transition function. Given a predicate determines if a method should transition to another level. |
iveresov@2138 | 42 | CompLevel common(Predicate p, methodOop method, CompLevel cur_level); |
iveresov@2138 | 43 | // Transition functions. |
iveresov@2138 | 44 | // call_event determines if a method should be compiled at a different |
iveresov@2138 | 45 | // level with a regular invocation entry. |
iveresov@2138 | 46 | CompLevel call_event(methodOop method, CompLevel cur_level); |
iveresov@2138 | 47 | // loop_event checks if a method should be OSR compiled at a different |
iveresov@2138 | 48 | // level. |
iveresov@2138 | 49 | CompLevel loop_event(methodOop method, CompLevel cur_level); |
iveresov@2138 | 50 | |
iveresov@2138 | 51 | protected: |
iveresov@2138 | 52 | int c1_count() const { return _c1_count; } |
iveresov@2138 | 53 | int c2_count() const { return _c2_count; } |
iveresov@2138 | 54 | void set_c1_count(int x) { _c1_count = x; } |
iveresov@2138 | 55 | void set_c2_count(int x) { _c2_count = x; } |
iveresov@2138 | 56 | |
iveresov@2138 | 57 | enum EventType { CALL, LOOP, COMPILE }; |
iveresov@2138 | 58 | void print_event(EventType type, methodHandle mh, methodHandle imh, int bci, CompLevel level); |
iveresov@2138 | 59 | // Print policy-specific information if necessary |
iveresov@2138 | 60 | virtual void print_specific(EventType type, methodHandle mh, methodHandle imh, int bci, CompLevel level) { } |
iveresov@2138 | 61 | // Check if the method can be compiled, change level if necessary |
iveresov@2138 | 62 | void compile(methodHandle mh, int bci, CompLevel level, TRAPS); |
iveresov@2138 | 63 | // Submit a given method for compilation |
iveresov@2138 | 64 | virtual void submit_compile(methodHandle mh, int bci, CompLevel level, TRAPS); |
iveresov@2138 | 65 | // Simple methods are as good being compiled with C1 as C2. |
iveresov@2138 | 66 | // This function tells if it's such a function. |
iveresov@2138 | 67 | inline bool is_trivial(methodOop method); |
iveresov@2138 | 68 | |
iveresov@2138 | 69 | // Predicate helpers are used by .*_predicate() methods as well as others. |
iveresov@2138 | 70 | // They check the given counter values, multiplied by the scale against the thresholds. |
iveresov@2138 | 71 | template<CompLevel level> static inline bool call_predicate_helper(int i, int b, double scale); |
iveresov@2138 | 72 | template<CompLevel level> static inline bool loop_predicate_helper(int i, int b, double scale); |
iveresov@2138 | 73 | |
iveresov@2138 | 74 | // Get a compilation level for a given method. |
iveresov@2138 | 75 | static CompLevel comp_level(methodOop method) { |
iveresov@2138 | 76 | nmethod *nm = method->code(); |
iveresov@2138 | 77 | if (nm != NULL && nm->is_in_use()) { |
iveresov@2138 | 78 | return (CompLevel)nm->comp_level(); |
iveresov@2138 | 79 | } |
iveresov@2138 | 80 | return CompLevel_none; |
iveresov@2138 | 81 | } |
iveresov@2138 | 82 | virtual void method_invocation_event(methodHandle method, methodHandle inlinee, |
iveresov@2138 | 83 | CompLevel level, TRAPS); |
iveresov@2138 | 84 | virtual void method_back_branch_event(methodHandle method, methodHandle inlinee, |
iveresov@2138 | 85 | int bci, CompLevel level, TRAPS); |
iveresov@2138 | 86 | public: |
iveresov@2138 | 87 | SimpleThresholdPolicy() : _c1_count(0), _c2_count(0) { } |
iveresov@2138 | 88 | virtual int compiler_count(CompLevel comp_level) { |
iveresov@2138 | 89 | if (is_c1_compile(comp_level)) return c1_count(); |
iveresov@2138 | 90 | if (is_c2_compile(comp_level)) return c2_count(); |
iveresov@2138 | 91 | return 0; |
iveresov@2138 | 92 | } |
iveresov@2138 | 93 | virtual void do_safepoint_work() { } |
iveresov@2138 | 94 | virtual void delay_compilation(methodOop method) { } |
iveresov@2138 | 95 | virtual void disable_compilation(methodOop method) { } |
iveresov@2138 | 96 | // TODO: we should honour reprofiling requests in the future. Currently reprofiling |
iveresov@2138 | 97 | // would happen but not to the extent we would ideally like. |
iveresov@2138 | 98 | virtual void reprofile(ScopeDesc* trap_scope, bool is_osr) { } |
iveresov@2138 | 99 | virtual nmethod* event(methodHandle method, methodHandle inlinee, |
iveresov@2138 | 100 | int branch_bci, int bci, CompLevel comp_level, TRAPS); |
iveresov@2138 | 101 | // Select task is called by CompileBroker. We should return a task or NULL. |
iveresov@2138 | 102 | virtual CompileTask* select_task(CompileQueue* compile_queue); |
iveresov@2138 | 103 | // Tell the runtime if we think a given method is adequately profiled. |
iveresov@2138 | 104 | virtual bool is_mature(methodOop method); |
iveresov@2138 | 105 | // Initialize: set compiler thread count |
iveresov@2138 | 106 | virtual void initialize(); |
iveresov@2138 | 107 | }; |