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