annotate src/share/vm/runtime/compilationPolicy.hpp @ 1783:d5d065957597

6953144: Tiered compilation Summary: Infrastructure for tiered compilation support (interpreter + c1 + c2) for 32 and 64 bit. Simple tiered policy implementation. Reviewed-by: kvn, never, phh, twisti
author iveresov
date Fri, 03 Sep 2010 17:51:07 -0700
parents c18cbe5936b8
children f95d63e2154a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1783
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
2 * Copyright (c) 2000, 2010, 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
a61af66fc99e Initial load
duke
parents:
diff changeset
25 // The CompilationPolicy selects which method (if any) should be compiled.
a61af66fc99e Initial load
duke
parents:
diff changeset
26 // It also decides which methods must always be compiled (i.e., are never
a61af66fc99e Initial load
duke
parents:
diff changeset
27 // interpreted).
1783
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
28 class CompileTask;
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
29 class CompileQueue;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
30
a61af66fc99e Initial load
duke
parents:
diff changeset
31 class CompilationPolicy : public CHeapObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
32 static CompilationPolicy* _policy;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 // Accumulated time
a61af66fc99e Initial load
duke
parents:
diff changeset
34 static elapsedTimer _accumulated_time;
a61af66fc99e Initial load
duke
parents:
diff changeset
35
a61af66fc99e Initial load
duke
parents:
diff changeset
36 static bool _in_vm_startup;
1783
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
37 public:
0
a61af66fc99e Initial load
duke
parents:
diff changeset
38 static void set_in_vm_startup(bool in_vm_startup) { _in_vm_startup = in_vm_startup; }
a61af66fc99e Initial load
duke
parents:
diff changeset
39 static void completed_vm_startup();
1783
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
40 static bool delay_compilation_during_startup() { return _in_vm_startup; }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
41
1783
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
42 // m must be compiled before executing it
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
43 static bool must_be_compiled(methodHandle m, int comp_level = CompLevel_all);
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
44 // m is allowed to be compiled
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
45 static bool can_be_compiled(methodHandle m, int comp_level = CompLevel_all);
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
46 static bool is_compilation_enabled();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
47 static void set_policy(CompilationPolicy* policy) { _policy = policy; }
1783
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
48 static CompilationPolicy* policy() { return _policy; }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
49
a61af66fc99e Initial load
duke
parents:
diff changeset
50 // Profiling
a61af66fc99e Initial load
duke
parents:
diff changeset
51 elapsedTimer* accumulated_time() { return &_accumulated_time; }
a61af66fc99e Initial load
duke
parents:
diff changeset
52 void print_time() PRODUCT_RETURN;
1783
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
53 virtual int compiler_count(CompLevel comp_level) = 0;
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
54 // main notification entry, return a pointer to an nmethod if the OSR is required,
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
55 // returns NULL otherwise.
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
56 virtual nmethod* event(methodHandle method, methodHandle inlinee, int branch_bci, int bci, CompLevel comp_level, TRAPS) = 0;
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
57 // safepoint() is called at the end of the safepoint
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
58 virtual void do_safepoint_work() = 0;
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
59 // reprofile request
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
60 virtual void reprofile(ScopeDesc* trap_scope, bool is_osr) = 0;
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
61 // delay_compilation(method) can be called by any component of the runtime to notify the policy
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
62 // that it's recommended to delay the complation of this method.
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
63 virtual void delay_compilation(methodOop method) = 0;
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
64 // disable_compilation() is called whenever the runtime decides to disable compilation of the
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
65 // specified method.
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
66 virtual void disable_compilation(methodOop method) = 0;
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
67 // Select task is called by CompileBroker. The queue is guaranteed to have at least one
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
68 // element and is locked. The function should select one and return it.
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
69 virtual CompileTask* select_task(CompileQueue* compile_queue) = 0;
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
70 // Tell the runtime if we think a given method is adequately profiled.
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
71 virtual bool is_mature(methodOop method) = 0;
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
72 // Do policy initialization
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
73 virtual void initialize() = 0;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
74 };
a61af66fc99e Initial load
duke
parents:
diff changeset
75
1783
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
76 // A base class for baseline policies.
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
77 class NonTieredCompPolicy : public CompilationPolicy {
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
78 int _compiler_count;
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
79 protected:
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
80 static void trace_frequency_counter_overflow(methodHandle m, int branch_bci, int bci);
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
81 static void trace_osr_request(methodHandle method, nmethod* osr, int bci);
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
82 static void trace_osr_completion(nmethod* osr_nm);
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
83 void reset_counter_for_invocation_event(methodHandle method);
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
84 void reset_counter_for_back_branch_event(methodHandle method);
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
85 public:
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
86 NonTieredCompPolicy() : _compiler_count(0) { }
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
87 virtual int compiler_count(CompLevel comp_level);
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
88 virtual void do_safepoint_work();
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
89 virtual void reprofile(ScopeDesc* trap_scope, bool is_osr);
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
90 virtual void delay_compilation(methodOop method);
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
91 virtual void disable_compilation(methodOop method);
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
92 virtual bool is_mature(methodOop method);
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
93 virtual void initialize();
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
94 virtual CompileTask* select_task(CompileQueue* compile_queue);
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
95 virtual nmethod* event(methodHandle method, methodHandle inlinee, int branch_bci, int bci, CompLevel comp_level, TRAPS);
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
96 virtual void method_invocation_event(methodHandle m, TRAPS) = 0;
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
97 virtual void method_back_branch_event(methodHandle m, int bci, TRAPS) = 0;
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
98 };
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
99
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
100 class SimpleCompPolicy : public NonTieredCompPolicy {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
101 public:
1783
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
102 virtual void method_invocation_event(methodHandle m, TRAPS);
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
103 virtual void method_back_branch_event(methodHandle m, int bci, TRAPS);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
104 };
a61af66fc99e Initial load
duke
parents:
diff changeset
105
a61af66fc99e Initial load
duke
parents:
diff changeset
106 // StackWalkCompPolicy - existing C2 policy
a61af66fc99e Initial load
duke
parents:
diff changeset
107
a61af66fc99e Initial load
duke
parents:
diff changeset
108 #ifdef COMPILER2
1783
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
109 class StackWalkCompPolicy : public NonTieredCompPolicy {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
110 public:
1783
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
111 virtual void method_invocation_event(methodHandle m, TRAPS);
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1552
diff changeset
112 virtual void method_back_branch_event(methodHandle m, int bci, TRAPS);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
113
a61af66fc99e Initial load
duke
parents:
diff changeset
114 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
115 RFrame* findTopInlinableFrame(GrowableArray<RFrame*>* stack);
a61af66fc99e Initial load
duke
parents:
diff changeset
116 RFrame* senderOf(RFrame* rf, GrowableArray<RFrame*>* stack);
a61af66fc99e Initial load
duke
parents:
diff changeset
117
a61af66fc99e Initial load
duke
parents:
diff changeset
118 // the following variables hold values computed by the last inlining decision
a61af66fc99e Initial load
duke
parents:
diff changeset
119 // they are used for performance debugging only (print better messages)
a61af66fc99e Initial load
duke
parents:
diff changeset
120 static const char* _msg; // reason for not inlining
a61af66fc99e Initial load
duke
parents:
diff changeset
121
a61af66fc99e Initial load
duke
parents:
diff changeset
122 static const char* shouldInline (methodHandle callee, float frequency, int cnt);
a61af66fc99e Initial load
duke
parents:
diff changeset
123 // positive filter: should send be inlined? returns NULL (--> yes) or rejection msg
a61af66fc99e Initial load
duke
parents:
diff changeset
124 static const char* shouldNotInline(methodHandle callee);
a61af66fc99e Initial load
duke
parents:
diff changeset
125 // negative filter: should send NOT be inlined? returns NULL (--> inline) or rejection msg
a61af66fc99e Initial load
duke
parents:
diff changeset
126
a61af66fc99e Initial load
duke
parents:
diff changeset
127 };
a61af66fc99e Initial load
duke
parents:
diff changeset
128 #endif