comparison src/share/vm/runtime/compilationPolicy.hpp @ 1930:2d26b0046e0d

Merge.
author Thomas Wuerthinger <wuerthinger@ssw.jku.at>
date Tue, 30 Nov 2010 14:53:30 +0100
parents d5d065957597
children f95d63e2154a
comparison
equal deleted inserted replaced
1484:6b7001391c97 1930:2d26b0046e0d
1 /* 1 /*
2 * Copyright 2000-2006 Sun Microsystems, Inc. All Rights Reserved. 2 * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 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 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
14 * 14 *
15 * You should have received a copy of the GNU General Public License version 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, 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. 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 * 18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * CA 95054 USA or visit www.sun.com if you need additional information or 20 * or visit www.oracle.com if you need additional information or have any
21 * have any questions. 21 * questions.
22 * 22 *
23 */ 23 */
24 24
25 // The CompilationPolicy selects which method (if any) should be compiled. 25 // The CompilationPolicy selects which method (if any) should be compiled.
26 // It also decides which methods must always be compiled (i.e., are never 26 // It also decides which methods must always be compiled (i.e., are never
27 // interpreted). 27 // interpreted).
28 class CompileTask;
29 class CompileQueue;
28 30
29 class CompilationPolicy : public CHeapObj { 31 class CompilationPolicy : public CHeapObj {
30 private:
31 static CompilationPolicy* _policy; 32 static CompilationPolicy* _policy;
32 // Accumulated time 33 // Accumulated time
33 static elapsedTimer _accumulated_time; 34 static elapsedTimer _accumulated_time;
34 35
35 static bool _in_vm_startup; 36 static bool _in_vm_startup;
36 37 public:
37 public:
38 virtual void method_invocation_event(methodHandle m, TRAPS) = 0;
39 virtual void method_back_branch_event(methodHandle m, int branch_bci, int loop_top_bci, TRAPS) = 0;
40 virtual int compilation_level(methodHandle m, int branch_bci) = 0;
41
42 void reset_counter_for_invocation_event(methodHandle method);
43 void reset_counter_for_back_branch_event(methodHandle method);
44
45 static void set_in_vm_startup(bool in_vm_startup) { _in_vm_startup = in_vm_startup; } 38 static void set_in_vm_startup(bool in_vm_startup) { _in_vm_startup = in_vm_startup; }
46 static void completed_vm_startup(); 39 static void completed_vm_startup();
47 static bool delayCompilationDuringStartup() { return _in_vm_startup; } 40 static bool delay_compilation_during_startup() { return _in_vm_startup; }
48 41
49 static bool mustBeCompiled(methodHandle m); // m must be compiled before executing it 42 // m must be compiled before executing it
50 static bool canBeCompiled(methodHandle m); // m is allowed to be compiled 43 static bool must_be_compiled(methodHandle m, int comp_level = CompLevel_all);
51 44 // m is allowed to be compiled
45 static bool can_be_compiled(methodHandle m, int comp_level = CompLevel_all);
46 static bool is_compilation_enabled();
52 static void set_policy(CompilationPolicy* policy) { _policy = policy; } 47 static void set_policy(CompilationPolicy* policy) { _policy = policy; }
53 static CompilationPolicy* policy() { return _policy; } 48 static CompilationPolicy* policy() { return _policy; }
54 49
55 // Profiling 50 // Profiling
56 elapsedTimer* accumulated_time() { return &_accumulated_time; } 51 elapsedTimer* accumulated_time() { return &_accumulated_time; }
57 void print_time() PRODUCT_RETURN; 52 void print_time() PRODUCT_RETURN;
53 virtual int compiler_count(CompLevel comp_level) = 0;
54 // main notification entry, return a pointer to an nmethod if the OSR is required,
55 // returns NULL otherwise.
56 virtual nmethod* event(methodHandle method, methodHandle inlinee, int branch_bci, int bci, CompLevel comp_level, TRAPS) = 0;
57 // safepoint() is called at the end of the safepoint
58 virtual void do_safepoint_work() = 0;
59 // reprofile request
60 virtual void reprofile(ScopeDesc* trap_scope, bool is_osr) = 0;
61 // delay_compilation(method) can be called by any component of the runtime to notify the policy
62 // that it's recommended to delay the complation of this method.
63 virtual void delay_compilation(methodOop method) = 0;
64 // disable_compilation() is called whenever the runtime decides to disable compilation of the
65 // specified method.
66 virtual void disable_compilation(methodOop method) = 0;
67 // Select task is called by CompileBroker. The queue is guaranteed to have at least one
68 // element and is locked. The function should select one and return it.
69 virtual CompileTask* select_task(CompileQueue* compile_queue) = 0;
70 // Tell the runtime if we think a given method is adequately profiled.
71 virtual bool is_mature(methodOop method) = 0;
72 // Do policy initialization
73 virtual void initialize() = 0;
58 }; 74 };
59 75
60 class SimpleCompPolicy : public CompilationPolicy { 76 // A base class for baseline policies.
77 class NonTieredCompPolicy : public CompilationPolicy {
78 int _compiler_count;
79 protected:
80 static void trace_frequency_counter_overflow(methodHandle m, int branch_bci, int bci);
81 static void trace_osr_request(methodHandle method, nmethod* osr, int bci);
82 static void trace_osr_completion(nmethod* osr_nm);
83 void reset_counter_for_invocation_event(methodHandle method);
84 void reset_counter_for_back_branch_event(methodHandle method);
85 public:
86 NonTieredCompPolicy() : _compiler_count(0) { }
87 virtual int compiler_count(CompLevel comp_level);
88 virtual void do_safepoint_work();
89 virtual void reprofile(ScopeDesc* trap_scope, bool is_osr);
90 virtual void delay_compilation(methodOop method);
91 virtual void disable_compilation(methodOop method);
92 virtual bool is_mature(methodOop method);
93 virtual void initialize();
94 virtual CompileTask* select_task(CompileQueue* compile_queue);
95 virtual nmethod* event(methodHandle method, methodHandle inlinee, int branch_bci, int bci, CompLevel comp_level, TRAPS);
96 virtual void method_invocation_event(methodHandle m, TRAPS) = 0;
97 virtual void method_back_branch_event(methodHandle m, int bci, TRAPS) = 0;
98 };
99
100 class SimpleCompPolicy : public NonTieredCompPolicy {
61 public: 101 public:
62 void method_invocation_event( methodHandle m, TRAPS); 102 virtual void method_invocation_event(methodHandle m, TRAPS);
63 void method_back_branch_event(methodHandle m, int branch_bci, int loop_top_bci, TRAPS); 103 virtual void method_back_branch_event(methodHandle m, int bci, TRAPS);
64 int compilation_level(methodHandle m, int branch_bci);
65 }; 104 };
66 105
67 // StackWalkCompPolicy - existing C2 policy 106 // StackWalkCompPolicy - existing C2 policy
68 107
69 #ifdef COMPILER2 108 #ifdef COMPILER2
70 class StackWalkCompPolicy : public CompilationPolicy { 109 class StackWalkCompPolicy : public NonTieredCompPolicy {
71 public: 110 public:
72 void method_invocation_event(methodHandle m, TRAPS); 111 virtual void method_invocation_event(methodHandle m, TRAPS);
73 void method_back_branch_event(methodHandle m, int branch_bci, int loop_top_bci, TRAPS); 112 virtual void method_back_branch_event(methodHandle m, int bci, TRAPS);
74 int compilation_level(methodHandle m, int branch_bci);
75 113
76 private: 114 private:
77 RFrame* findTopInlinableFrame(GrowableArray<RFrame*>* stack); 115 RFrame* findTopInlinableFrame(GrowableArray<RFrame*>* stack);
78 RFrame* senderOf(RFrame* rf, GrowableArray<RFrame*>* stack); 116 RFrame* senderOf(RFrame* rf, GrowableArray<RFrame*>* stack);
79 117