annotate src/share/vm/runtime/compilationPolicy.hpp @ 14518:d8041d695d19

Merged with jdk9/dev/hotspot changeset 3812c088b945
author twisti
date Tue, 11 Mar 2014 18:45:59 -0700
parents 9161ed8ce796 63a4eb8bcd23
children 10c4df6767c4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
14223
de6a9e811145 8029233: Update copyright year to match last edit in jdk8 hotspot repository for 2013
mikael
parents: 12073
diff changeset
2 * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1783
diff changeset
25 #ifndef SHARE_VM_RUNTIME_COMPILATIONPOLICY_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1783
diff changeset
26 #define SHARE_VM_RUNTIME_COMPILATIONPOLICY_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1783
diff changeset
27
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1783
diff changeset
28 #include "code/nmethod.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1783
diff changeset
29 #include "compiler/compileBroker.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1783
diff changeset
30 #include "memory/allocation.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1783
diff changeset
31 #include "runtime/vm_operations.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1783
diff changeset
32 #include "utilities/growableArray.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1783
diff changeset
33
0
a61af66fc99e Initial load
duke
parents:
diff changeset
34 // The CompilationPolicy selects which method (if any) should be compiled.
a61af66fc99e Initial load
duke
parents:
diff changeset
35 // It also decides which methods must always be compiled (i.e., are never
a61af66fc99e Initial load
duke
parents:
diff changeset
36 // interpreted).
1783
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
37 class CompileTask;
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
38 class CompileQueue;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
39
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 4825
diff changeset
40 class CompilationPolicy : public CHeapObj<mtCompiler> {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
41 static CompilationPolicy* _policy;
a61af66fc99e Initial load
duke
parents:
diff changeset
42 // Accumulated time
a61af66fc99e Initial load
duke
parents:
diff changeset
43 static elapsedTimer _accumulated_time;
a61af66fc99e Initial load
duke
parents:
diff changeset
44
a61af66fc99e Initial load
duke
parents:
diff changeset
45 static bool _in_vm_startup;
1783
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
46 public:
0
a61af66fc99e Initial load
duke
parents:
diff changeset
47 static void set_in_vm_startup(bool in_vm_startup) { _in_vm_startup = in_vm_startup; }
a61af66fc99e Initial load
duke
parents:
diff changeset
48 static void completed_vm_startup();
1783
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
49 static bool delay_compilation_during_startup() { return _in_vm_startup; }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
50
1783
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
51 // m must be compiled before executing it
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
52 static bool must_be_compiled(methodHandle m, int comp_level = CompLevel_all);
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
53 // m is allowed to be compiled
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
54 static bool can_be_compiled(methodHandle m, int comp_level = CompLevel_all);
12073
f99558245e5c 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 9080
diff changeset
55 // m is allowed to be osr compiled
f99558245e5c 8022832: Add WB APIs for OSR compilation
iignatyev
parents: 9080
diff changeset
56 static bool can_be_osr_compiled(methodHandle m, int comp_level = CompLevel_all);
1783
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
57 static bool is_compilation_enabled();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
58 static void set_policy(CompilationPolicy* policy) { _policy = policy; }
1783
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
59 static CompilationPolicy* policy() { return _policy; }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
60
13731
9161ed8ce796 Add graal-specific option -XX:+GPUOffload to trigger all GPU offload functionality. Cleanup function to decide GPU offload. Exclude GPU sources from nongraal builds.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 12356
diff changeset
61 // m is allowed to be offloaded to a gpu
9161ed8ce796 Add graal-specific option -XX:+GPUOffload to trigger all GPU offload functionality. Cleanup function to decide GPU offload. Exclude GPU sources from nongraal builds.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 12356
diff changeset
62 static bool can_be_offloaded_to_gpu(methodHandle m);
9161ed8ce796 Add graal-specific option -XX:+GPUOffload to trigger all GPU offload functionality. Cleanup function to decide GPU offload. Exclude GPU sources from nongraal builds.
S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
parents: 12356
diff changeset
63
0
a61af66fc99e Initial load
duke
parents:
diff changeset
64 // Profiling
a61af66fc99e Initial load
duke
parents:
diff changeset
65 elapsedTimer* accumulated_time() { return &_accumulated_time; }
a61af66fc99e Initial load
duke
parents:
diff changeset
66 void print_time() PRODUCT_RETURN;
3837
43f9d800f276 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 3791
diff changeset
67 // Return initial compile level that is used with Xcomp
43f9d800f276 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 3791
diff changeset
68 virtual CompLevel initial_compile_level() = 0;
1783
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
69 virtual int compiler_count(CompLevel comp_level) = 0;
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
70 // main notification entry, return a pointer to an nmethod if the OSR is required,
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
71 // returns NULL otherwise.
4825
20334ed5ed3c 7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents: 3837
diff changeset
72 virtual nmethod* event(methodHandle method, methodHandle inlinee, int branch_bci, int bci, CompLevel comp_level, nmethod* nm, JavaThread* thread) = 0;
1783
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
73 // safepoint() is called at the end of the safepoint
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
74 virtual void do_safepoint_work() = 0;
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
75 // reprofile request
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
76 virtual void reprofile(ScopeDesc* trap_scope, bool is_osr) = 0;
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
77 // delay_compilation(method) can be called by any component of the runtime to notify the policy
14309
63a4eb8bcd23 8025856: Fix typos in the GC code
jwilhelm
parents: 14223
diff changeset
78 // that it's recommended to delay the compilation of this method.
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
79 virtual void delay_compilation(Method* method) = 0;
1783
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
80 // disable_compilation() is called whenever the runtime decides to disable compilation of the
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
81 // specified method.
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
82 virtual void disable_compilation(Method* method) = 0;
1783
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
83 // Select task is called by CompileBroker. The queue is guaranteed to have at least one
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
84 // element and is locked. The function should select one and return it.
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
85 virtual CompileTask* select_task(CompileQueue* compile_queue) = 0;
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
86 // Tell the runtime if we think a given method is adequately profiled.
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
87 virtual bool is_mature(Method* method) = 0;
1783
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
88 // Do policy initialization
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
89 virtual void initialize() = 0;
3791
2c359f27615c 7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents: 1972
diff changeset
90 virtual bool should_not_inline(ciEnv* env, ciMethod* method) { return false; }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
91 };
a61af66fc99e Initial load
duke
parents:
diff changeset
92
1783
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
93 // A base class for baseline policies.
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
94 class NonTieredCompPolicy : public CompilationPolicy {
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
95 int _compiler_count;
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
96 protected:
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
97 static void trace_frequency_counter_overflow(methodHandle m, int branch_bci, int bci);
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
98 static void trace_osr_request(methodHandle method, nmethod* osr, int bci);
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
99 static void trace_osr_completion(nmethod* osr_nm);
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
100 void reset_counter_for_invocation_event(methodHandle method);
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
101 void reset_counter_for_back_branch_event(methodHandle method);
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
102 public:
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
103 NonTieredCompPolicy() : _compiler_count(0) { }
9080
b84fd7d73702 8007288: Additional WB API for compiler's testing
iignatyev
parents: 6725
diff changeset
104 virtual CompLevel initial_compile_level() { return CompLevel_highest_tier; }
1783
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
105 virtual int compiler_count(CompLevel comp_level);
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
106 virtual void do_safepoint_work();
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
107 virtual void reprofile(ScopeDesc* trap_scope, bool is_osr);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
108 virtual void delay_compilation(Method* method);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
109 virtual void disable_compilation(Method* method);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
110 virtual bool is_mature(Method* method);
1783
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
111 virtual void initialize();
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
112 virtual CompileTask* select_task(CompileQueue* compile_queue);
4825
20334ed5ed3c 7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents: 3837
diff changeset
113 virtual nmethod* event(methodHandle method, methodHandle inlinee, int branch_bci, int bci, CompLevel comp_level, nmethod* nm, JavaThread* thread);
20334ed5ed3c 7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents: 3837
diff changeset
114 virtual void method_invocation_event(methodHandle m, JavaThread* thread) = 0;
20334ed5ed3c 7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents: 3837
diff changeset
115 virtual void method_back_branch_event(methodHandle m, int bci, JavaThread* thread) = 0;
1783
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
116 };
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
117
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
118 class SimpleCompPolicy : public NonTieredCompPolicy {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
119 public:
4825
20334ed5ed3c 7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents: 3837
diff changeset
120 virtual void method_invocation_event(methodHandle m, JavaThread* thread);
20334ed5ed3c 7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents: 3837
diff changeset
121 virtual void method_back_branch_event(methodHandle m, int bci, JavaThread* thread);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
122 };
a61af66fc99e Initial load
duke
parents:
diff changeset
123
a61af66fc99e Initial load
duke
parents:
diff changeset
124 // StackWalkCompPolicy - existing C2 policy
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126 #ifdef COMPILER2
1783
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
127 class StackWalkCompPolicy : public NonTieredCompPolicy {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
128 public:
4825
20334ed5ed3c 7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents: 3837
diff changeset
129 virtual void method_invocation_event(methodHandle m, JavaThread* thread);
20334ed5ed3c 7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents: 3837
diff changeset
130 virtual void method_back_branch_event(methodHandle m, int bci, JavaThread* thread);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
131
a61af66fc99e Initial load
duke
parents:
diff changeset
132 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
133 RFrame* findTopInlinableFrame(GrowableArray<RFrame*>* stack);
a61af66fc99e Initial load
duke
parents:
diff changeset
134 RFrame* senderOf(RFrame* rf, GrowableArray<RFrame*>* stack);
a61af66fc99e Initial load
duke
parents:
diff changeset
135
a61af66fc99e Initial load
duke
parents:
diff changeset
136 // the following variables hold values computed by the last inlining decision
a61af66fc99e Initial load
duke
parents:
diff changeset
137 // they are used for performance debugging only (print better messages)
a61af66fc99e Initial load
duke
parents:
diff changeset
138 static const char* _msg; // reason for not inlining
a61af66fc99e Initial load
duke
parents:
diff changeset
139
a61af66fc99e Initial load
duke
parents:
diff changeset
140 static const char* shouldInline (methodHandle callee, float frequency, int cnt);
a61af66fc99e Initial load
duke
parents:
diff changeset
141 // positive filter: should send be inlined? returns NULL (--> yes) or rejection msg
a61af66fc99e Initial load
duke
parents:
diff changeset
142 static const char* shouldNotInline(methodHandle callee);
a61af66fc99e Initial load
duke
parents:
diff changeset
143 // negative filter: should send NOT be inlined? returns NULL (--> inline) or rejection msg
a61af66fc99e Initial load
duke
parents:
diff changeset
144
a61af66fc99e Initial load
duke
parents:
diff changeset
145 };
a61af66fc99e Initial load
duke
parents:
diff changeset
146 #endif
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1783
diff changeset
147
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1783
diff changeset
148 #endif // SHARE_VM_RUNTIME_COMPILATIONPOLICY_HPP