author | dcubed |
Thu, 07 Apr 2016 12:54:48 -0700 | |
changeset 37429 | 5b1720e87eda |
parent 33593 | 60764a78fa5c |
child 38133 | 78b95467b9f1 |
permissions | -rw-r--r-- |
6453 | 1 |
/* |
33593
60764a78fa5c
8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents:
28650
diff
changeset
|
2 |
* Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved. |
6453 | 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 |
* |
|
23 |
*/ |
|
24 |
||
7397 | 25 |
#ifndef SHARE_VM_RUNTIME_SIMPLETHRESHOLDPOLICY_HPP |
26 |
#define SHARE_VM_RUNTIME_SIMPLETHRESHOLDPOLICY_HPP |
|
27 |
||
28 |
#include "code/nmethod.hpp" |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
11572
diff
changeset
|
29 |
#include "oops/methodData.hpp" |
7397 | 30 |
#include "runtime/compilationPolicy.hpp" |
31 |
#include "utilities/globalDefinitions.hpp" |
|
32 |
||
6453 | 33 |
class CompileTask; |
34 |
class CompileQueue; |
|
35 |
||
36 |
class SimpleThresholdPolicy : public CompilationPolicy { |
|
37 |
int _c1_count, _c2_count; |
|
38 |
||
39 |
// Check if the counter is big enough and set carry (effectively infinity). |
|
40 |
inline void set_carry_if_necessary(InvocationCounter *counter); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
11572
diff
changeset
|
41 |
// Set carry flags in the counters (in Method* and MDO). |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
11572
diff
changeset
|
42 |
inline void handle_counter_overflow(Method* method); |
6453 | 43 |
// Call and loop predicates determine whether a transition to a higher compilation |
44 |
// level should be performed (pointers to predicate functions are passed to common_TF(). |
|
45 |
// Predicates also take compiler load into account. |
|
28650
772aaab2582f
8059606: Enable per-method usage of CompileThresholdScaling (per-method compilation thresholds)
zmajo
parents:
13728
diff
changeset
|
46 |
typedef bool (SimpleThresholdPolicy::*Predicate)(int i, int b, CompLevel cur_level, Method* method); |
772aaab2582f
8059606: Enable per-method usage of CompileThresholdScaling (per-method compilation thresholds)
zmajo
parents:
13728
diff
changeset
|
47 |
bool call_predicate(int i, int b, CompLevel cur_level, Method* method); |
772aaab2582f
8059606: Enable per-method usage of CompileThresholdScaling (per-method compilation thresholds)
zmajo
parents:
13728
diff
changeset
|
48 |
bool loop_predicate(int i, int b, CompLevel cur_level, Method* method); |
6453 | 49 |
// Common transition function. Given a predicate determines if a method should transition to another level. |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
11572
diff
changeset
|
50 |
CompLevel common(Predicate p, Method* method, CompLevel cur_level); |
6453 | 51 |
// Transition functions. |
52 |
// call_event determines if a method should be compiled at a different |
|
53 |
// level with a regular invocation entry. |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
11572
diff
changeset
|
54 |
CompLevel call_event(Method* method, CompLevel cur_level); |
6453 | 55 |
// loop_event checks if a method should be OSR compiled at a different |
56 |
// level. |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
11572
diff
changeset
|
57 |
CompLevel loop_event(Method* method, CompLevel cur_level); |
11192
ff37c2093a0d
7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents:
10250
diff
changeset
|
58 |
void print_counters(const char* prefix, methodHandle mh); |
6453 | 59 |
protected: |
60 |
int c1_count() const { return _c1_count; } |
|
61 |
int c2_count() const { return _c2_count; } |
|
62 |
void set_c1_count(int x) { _c1_count = x; } |
|
63 |
void set_c2_count(int x) { _c2_count = x; } |
|
64 |
||
10014
a5c2141ee857
7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents:
9625
diff
changeset
|
65 |
enum EventType { CALL, LOOP, COMPILE, REMOVE_FROM_QUEUE, UPDATE_IN_QUEUE, REPROFILE, MAKE_NOT_ENTRANT }; |
6453 | 66 |
void print_event(EventType type, methodHandle mh, methodHandle imh, int bci, CompLevel level); |
67 |
// Print policy-specific information if necessary |
|
68 |
virtual void print_specific(EventType type, methodHandle mh, methodHandle imh, int bci, CompLevel level) { } |
|
69 |
// Check if the method can be compiled, change level if necessary |
|
33593
60764a78fa5c
8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents:
28650
diff
changeset
|
70 |
void compile(const methodHandle& mh, int bci, CompLevel level, JavaThread* thread); |
6453 | 71 |
// Submit a given method for compilation |
33593
60764a78fa5c
8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents:
28650
diff
changeset
|
72 |
virtual void submit_compile(const methodHandle& mh, int bci, CompLevel level, JavaThread* thread); |
6453 | 73 |
// Simple methods are as good being compiled with C1 as C2. |
74 |
// This function tells if it's such a function. |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
11572
diff
changeset
|
75 |
inline bool is_trivial(Method* method); |
6453 | 76 |
|
77 |
// Predicate helpers are used by .*_predicate() methods as well as others. |
|
78 |
// They check the given counter values, multiplied by the scale against the thresholds. |
|
28650
772aaab2582f
8059606: Enable per-method usage of CompileThresholdScaling (per-method compilation thresholds)
zmajo
parents:
13728
diff
changeset
|
79 |
template<CompLevel level> static inline bool call_predicate_helper(int i, int b, double scale, Method* method); |
772aaab2582f
8059606: Enable per-method usage of CompileThresholdScaling (per-method compilation thresholds)
zmajo
parents:
13728
diff
changeset
|
80 |
template<CompLevel level> static inline bool loop_predicate_helper(int i, int b, double scale, Method* method); |
6453 | 81 |
|
82 |
// Get a compilation level for a given method. |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
11572
diff
changeset
|
83 |
static CompLevel comp_level(Method* method) { |
6453 | 84 |
nmethod *nm = method->code(); |
85 |
if (nm != NULL && nm->is_in_use()) { |
|
86 |
return (CompLevel)nm->comp_level(); |
|
87 |
} |
|
88 |
return CompLevel_none; |
|
89 |
} |
|
33593
60764a78fa5c
8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents:
28650
diff
changeset
|
90 |
virtual void method_invocation_event(const methodHandle& method, const methodHandle& inlinee, |
11572
84afef481892
7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents:
11192
diff
changeset
|
91 |
CompLevel level, nmethod* nm, JavaThread* thread); |
33593
60764a78fa5c
8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents:
28650
diff
changeset
|
92 |
virtual void method_back_branch_event(const methodHandle& method, const methodHandle& inlinee, |
11572
84afef481892
7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents:
11192
diff
changeset
|
93 |
int bci, CompLevel level, nmethod* nm, JavaThread* thread); |
6453 | 94 |
public: |
95 |
SimpleThresholdPolicy() : _c1_count(0), _c2_count(0) { } |
|
96 |
virtual int compiler_count(CompLevel comp_level) { |
|
97 |
if (is_c1_compile(comp_level)) return c1_count(); |
|
98 |
if (is_c2_compile(comp_level)) return c2_count(); |
|
99 |
return 0; |
|
100 |
} |
|
10250
0794cd144834
7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents:
10014
diff
changeset
|
101 |
virtual CompLevel initial_compile_level() { return MIN2((CompLevel)TieredStopAtLevel, CompLevel_initial_compile); } |
6453 | 102 |
virtual void do_safepoint_work() { } |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
11572
diff
changeset
|
103 |
virtual void delay_compilation(Method* method) { } |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
11572
diff
changeset
|
104 |
virtual void disable_compilation(Method* method) { } |
8322 | 105 |
virtual void reprofile(ScopeDesc* trap_scope, bool is_osr); |
33593
60764a78fa5c
8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents:
28650
diff
changeset
|
106 |
virtual nmethod* event(const methodHandle& method, const methodHandle& inlinee, |
11572
84afef481892
7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents:
11192
diff
changeset
|
107 |
int branch_bci, int bci, CompLevel comp_level, nmethod* nm, JavaThread* thread); |
6453 | 108 |
// Select task is called by CompileBroker. We should return a task or NULL. |
109 |
virtual CompileTask* select_task(CompileQueue* compile_queue); |
|
110 |
// Tell the runtime if we think a given method is adequately profiled. |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
11572
diff
changeset
|
111 |
virtual bool is_mature(Method* method); |
6453 | 112 |
// Initialize: set compiler thread count |
113 |
virtual void initialize(); |
|
10014
a5c2141ee857
7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents:
9625
diff
changeset
|
114 |
virtual bool should_not_inline(ciEnv* env, ciMethod* callee) { |
a5c2141ee857
7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents:
9625
diff
changeset
|
115 |
return (env->comp_level() == CompLevel_limited_profile || |
a5c2141ee857
7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents:
9625
diff
changeset
|
116 |
env->comp_level() == CompLevel_full_profile) && |
a5c2141ee857
7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents:
9625
diff
changeset
|
117 |
callee->has_loops(); |
a5c2141ee857
7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents:
9625
diff
changeset
|
118 |
} |
6453 | 119 |
}; |
7397 | 120 |
|
121 |
#endif // SHARE_VM_RUNTIME_SIMPLETHRESHOLDPOLICY_HPP |