1 /*
2 * Copyright (c) 2010, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
65 void set_c2_count(int x) { _c2_count = x; }
66
67 enum EventType { CALL, LOOP, COMPILE, REMOVE_FROM_QUEUE, UPDATE_IN_QUEUE, REPROFILE, MAKE_NOT_ENTRANT };
68 void print_event(EventType type, const methodHandle& mh, const methodHandle& imh, int bci, CompLevel level);
69 // Print policy-specific information if necessary
70 virtual void print_specific(EventType type, const methodHandle& mh, const methodHandle& imh, int bci, CompLevel level) { }
71 // Check if the method can be compiled, change level if necessary
72 void compile(const methodHandle& mh, int bci, CompLevel level, JavaThread* thread);
73 // Submit a given method for compilation
74 virtual void submit_compile(const methodHandle& mh, int bci, CompLevel level, JavaThread* thread);
75 // Simple methods are as good being compiled with C1 as C2.
76 // This function tells if it's such a function.
77 inline bool is_trivial(Method* method);
78
79 // Predicate helpers are used by .*_predicate() methods as well as others.
80 // They check the given counter values, multiplied by the scale against the thresholds.
81 template<CompLevel level> static inline bool call_predicate_helper(int i, int b, double scale, Method* method);
82 template<CompLevel level> static inline bool loop_predicate_helper(int i, int b, double scale, Method* method);
83
84 // Get a compilation level for a given method.
85 static CompLevel comp_level(Method* method) {
86 CompiledMethod *nm = method->code();
87 if (nm != NULL && nm->is_in_use()) {
88 return (CompLevel)nm->comp_level();
89 }
90 return CompLevel_none;
91 }
92 virtual void method_invocation_event(const methodHandle& method, const methodHandle& inlinee,
93 CompLevel level, CompiledMethod* nm, JavaThread* thread);
94 virtual void method_back_branch_event(const methodHandle& method, const methodHandle& inlinee,
95 int bci, CompLevel level, CompiledMethod* nm, JavaThread* thread);
96 public:
97 SimpleThresholdPolicy() : _c1_count(0), _c2_count(0) { }
98 virtual int compiler_count(CompLevel comp_level) {
99 if (is_c1_compile(comp_level)) return c1_count();
100 if (is_c2_compile(comp_level)) return c2_count();
101 return 0;
102 }
103 virtual CompLevel initial_compile_level() { return MIN2((CompLevel)TieredStopAtLevel, CompLevel_initial_compile); }
104 virtual void do_safepoint_work() { }
105 virtual void delay_compilation(Method* method) { }
106 virtual void disable_compilation(Method* method) { }
107 virtual void reprofile(ScopeDesc* trap_scope, bool is_osr);
108 virtual nmethod* event(const methodHandle& method, const methodHandle& inlinee,
109 int branch_bci, int bci, CompLevel comp_level, CompiledMethod* nm, JavaThread* thread);
110 // Select task is called by CompileBroker. We should return a task or NULL.
111 virtual CompileTask* select_task(CompileQueue* compile_queue);
|
1 /*
2 * Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
65 void set_c2_count(int x) { _c2_count = x; }
66
67 enum EventType { CALL, LOOP, COMPILE, REMOVE_FROM_QUEUE, UPDATE_IN_QUEUE, REPROFILE, MAKE_NOT_ENTRANT };
68 void print_event(EventType type, const methodHandle& mh, const methodHandle& imh, int bci, CompLevel level);
69 // Print policy-specific information if necessary
70 virtual void print_specific(EventType type, const methodHandle& mh, const methodHandle& imh, int bci, CompLevel level) { }
71 // Check if the method can be compiled, change level if necessary
72 void compile(const methodHandle& mh, int bci, CompLevel level, JavaThread* thread);
73 // Submit a given method for compilation
74 virtual void submit_compile(const methodHandle& mh, int bci, CompLevel level, JavaThread* thread);
75 // Simple methods are as good being compiled with C1 as C2.
76 // This function tells if it's such a function.
77 inline bool is_trivial(Method* method);
78
79 // Predicate helpers are used by .*_predicate() methods as well as others.
80 // They check the given counter values, multiplied by the scale against the thresholds.
81 template<CompLevel level> static inline bool call_predicate_helper(int i, int b, double scale, Method* method);
82 template<CompLevel level> static inline bool loop_predicate_helper(int i, int b, double scale, Method* method);
83
84 // Get a compilation level for a given method.
85 static CompLevel comp_level(Method* method);
86 virtual void method_invocation_event(const methodHandle& method, const methodHandle& inlinee,
87 CompLevel level, CompiledMethod* nm, JavaThread* thread);
88 virtual void method_back_branch_event(const methodHandle& method, const methodHandle& inlinee,
89 int bci, CompLevel level, CompiledMethod* nm, JavaThread* thread);
90 public:
91 SimpleThresholdPolicy() : _c1_count(0), _c2_count(0) { }
92 virtual int compiler_count(CompLevel comp_level) {
93 if (is_c1_compile(comp_level)) return c1_count();
94 if (is_c2_compile(comp_level)) return c2_count();
95 return 0;
96 }
97 virtual CompLevel initial_compile_level() { return MIN2((CompLevel)TieredStopAtLevel, CompLevel_initial_compile); }
98 virtual void do_safepoint_work() { }
99 virtual void delay_compilation(Method* method) { }
100 virtual void disable_compilation(Method* method) { }
101 virtual void reprofile(ScopeDesc* trap_scope, bool is_osr);
102 virtual nmethod* event(const methodHandle& method, const methodHandle& inlinee,
103 int branch_bci, int bci, CompLevel comp_level, CompiledMethod* nm, JavaThread* thread);
104 // Select task is called by CompileBroker. We should return a task or NULL.
105 virtual CompileTask* select_task(CompileQueue* compile_queue);
|