1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/runtime/simpleThresholdPolicy.hpp Fri Sep 03 17:51:07 2010 -0700 1.3 @@ -0,0 +1,107 @@ 1.4 +/* 1.5 + * Copyright (c) 2001, 2010, 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 +class CompileTask; 1.29 +class CompileQueue; 1.30 + 1.31 +class SimpleThresholdPolicy : public CompilationPolicy { 1.32 + int _c1_count, _c2_count; 1.33 + 1.34 + // Check if the counter is big enough and set carry (effectively infinity). 1.35 + inline void set_carry_if_necessary(InvocationCounter *counter); 1.36 + // Set carry flags in the counters (in methodOop and MDO). 1.37 + inline void handle_counter_overflow(methodOop method); 1.38 + // Call and loop predicates determine whether a transition to a higher compilation 1.39 + // level should be performed (pointers to predicate functions are passed to common_TF(). 1.40 + // Predicates also take compiler load into account. 1.41 + typedef bool (SimpleThresholdPolicy::*Predicate)(int i, int b, CompLevel cur_level); 1.42 + bool call_predicate(int i, int b, CompLevel cur_level); 1.43 + bool loop_predicate(int i, int b, CompLevel cur_level); 1.44 + // Common transition function. Given a predicate determines if a method should transition to another level. 1.45 + CompLevel common(Predicate p, methodOop method, CompLevel cur_level); 1.46 + // Transition functions. 1.47 + // call_event determines if a method should be compiled at a different 1.48 + // level with a regular invocation entry. 1.49 + CompLevel call_event(methodOop method, CompLevel cur_level); 1.50 + // loop_event checks if a method should be OSR compiled at a different 1.51 + // level. 1.52 + CompLevel loop_event(methodOop method, CompLevel cur_level); 1.53 + 1.54 +protected: 1.55 + int c1_count() const { return _c1_count; } 1.56 + int c2_count() const { return _c2_count; } 1.57 + void set_c1_count(int x) { _c1_count = x; } 1.58 + void set_c2_count(int x) { _c2_count = x; } 1.59 + 1.60 + enum EventType { CALL, LOOP, COMPILE }; 1.61 + void print_event(EventType type, methodHandle mh, methodHandle imh, int bci, CompLevel level); 1.62 + // Print policy-specific information if necessary 1.63 + virtual void print_specific(EventType type, methodHandle mh, methodHandle imh, int bci, CompLevel level) { } 1.64 + // Check if the method can be compiled, change level if necessary 1.65 + void compile(methodHandle mh, int bci, CompLevel level, TRAPS); 1.66 + // Submit a given method for compilation 1.67 + virtual void submit_compile(methodHandle mh, int bci, CompLevel level, TRAPS); 1.68 + // Simple methods are as good being compiled with C1 as C2. 1.69 + // This function tells if it's such a function. 1.70 + inline bool is_trivial(methodOop method); 1.71 + 1.72 + // Predicate helpers are used by .*_predicate() methods as well as others. 1.73 + // They check the given counter values, multiplied by the scale against the thresholds. 1.74 + template<CompLevel level> static inline bool call_predicate_helper(int i, int b, double scale); 1.75 + template<CompLevel level> static inline bool loop_predicate_helper(int i, int b, double scale); 1.76 + 1.77 + // Get a compilation level for a given method. 1.78 + static CompLevel comp_level(methodOop method) { 1.79 + nmethod *nm = method->code(); 1.80 + if (nm != NULL && nm->is_in_use()) { 1.81 + return (CompLevel)nm->comp_level(); 1.82 + } 1.83 + return CompLevel_none; 1.84 + } 1.85 + virtual void method_invocation_event(methodHandle method, methodHandle inlinee, 1.86 + CompLevel level, TRAPS); 1.87 + virtual void method_back_branch_event(methodHandle method, methodHandle inlinee, 1.88 + int bci, CompLevel level, TRAPS); 1.89 +public: 1.90 + SimpleThresholdPolicy() : _c1_count(0), _c2_count(0) { } 1.91 + virtual int compiler_count(CompLevel comp_level) { 1.92 + if (is_c1_compile(comp_level)) return c1_count(); 1.93 + if (is_c2_compile(comp_level)) return c2_count(); 1.94 + return 0; 1.95 + } 1.96 + virtual void do_safepoint_work() { } 1.97 + virtual void delay_compilation(methodOop method) { } 1.98 + virtual void disable_compilation(methodOop method) { } 1.99 + // TODO: we should honour reprofiling requests in the future. Currently reprofiling 1.100 + // would happen but not to the extent we would ideally like. 1.101 + virtual void reprofile(ScopeDesc* trap_scope, bool is_osr) { } 1.102 + virtual nmethod* event(methodHandle method, methodHandle inlinee, 1.103 + int branch_bci, int bci, CompLevel comp_level, TRAPS); 1.104 + // Select task is called by CompileBroker. We should return a task or NULL. 1.105 + virtual CompileTask* select_task(CompileQueue* compile_queue); 1.106 + // Tell the runtime if we think a given method is adequately profiled. 1.107 + virtual bool is_mature(methodOop method); 1.108 + // Initialize: set compiler thread count 1.109 + virtual void initialize(); 1.110 +};