src/share/vm/runtime/compilationPolicy.hpp

Fri, 03 Sep 2010 17:51:07 -0700

author
iveresov
date
Fri, 03 Sep 2010 17:51:07 -0700
changeset 2138
d5d065957597
parent 1907
c18cbe5936b8
child 2314
f95d63e2154a
permissions
-rw-r--r--

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

duke@435 1 /*
iveresov@2138 2 * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 // The CompilationPolicy selects which method (if any) should be compiled.
duke@435 26 // It also decides which methods must always be compiled (i.e., are never
duke@435 27 // interpreted).
iveresov@2138 28 class CompileTask;
iveresov@2138 29 class CompileQueue;
duke@435 30
duke@435 31 class CompilationPolicy : public CHeapObj {
duke@435 32 static CompilationPolicy* _policy;
duke@435 33 // Accumulated time
duke@435 34 static elapsedTimer _accumulated_time;
duke@435 35
duke@435 36 static bool _in_vm_startup;
iveresov@2138 37 public:
duke@435 38 static void set_in_vm_startup(bool in_vm_startup) { _in_vm_startup = in_vm_startup; }
duke@435 39 static void completed_vm_startup();
iveresov@2138 40 static bool delay_compilation_during_startup() { return _in_vm_startup; }
duke@435 41
iveresov@2138 42 // m must be compiled before executing it
iveresov@2138 43 static bool must_be_compiled(methodHandle m, int comp_level = CompLevel_all);
iveresov@2138 44 // m is allowed to be compiled
iveresov@2138 45 static bool can_be_compiled(methodHandle m, int comp_level = CompLevel_all);
iveresov@2138 46 static bool is_compilation_enabled();
duke@435 47 static void set_policy(CompilationPolicy* policy) { _policy = policy; }
iveresov@2138 48 static CompilationPolicy* policy() { return _policy; }
duke@435 49
duke@435 50 // Profiling
duke@435 51 elapsedTimer* accumulated_time() { return &_accumulated_time; }
duke@435 52 void print_time() PRODUCT_RETURN;
iveresov@2138 53 virtual int compiler_count(CompLevel comp_level) = 0;
iveresov@2138 54 // main notification entry, return a pointer to an nmethod if the OSR is required,
iveresov@2138 55 // returns NULL otherwise.
iveresov@2138 56 virtual nmethod* event(methodHandle method, methodHandle inlinee, int branch_bci, int bci, CompLevel comp_level, TRAPS) = 0;
iveresov@2138 57 // safepoint() is called at the end of the safepoint
iveresov@2138 58 virtual void do_safepoint_work() = 0;
iveresov@2138 59 // reprofile request
iveresov@2138 60 virtual void reprofile(ScopeDesc* trap_scope, bool is_osr) = 0;
iveresov@2138 61 // delay_compilation(method) can be called by any component of the runtime to notify the policy
iveresov@2138 62 // that it's recommended to delay the complation of this method.
iveresov@2138 63 virtual void delay_compilation(methodOop method) = 0;
iveresov@2138 64 // disable_compilation() is called whenever the runtime decides to disable compilation of the
iveresov@2138 65 // specified method.
iveresov@2138 66 virtual void disable_compilation(methodOop method) = 0;
iveresov@2138 67 // Select task is called by CompileBroker. The queue is guaranteed to have at least one
iveresov@2138 68 // element and is locked. The function should select one and return it.
iveresov@2138 69 virtual CompileTask* select_task(CompileQueue* compile_queue) = 0;
iveresov@2138 70 // Tell the runtime if we think a given method is adequately profiled.
iveresov@2138 71 virtual bool is_mature(methodOop method) = 0;
iveresov@2138 72 // Do policy initialization
iveresov@2138 73 virtual void initialize() = 0;
duke@435 74 };
duke@435 75
iveresov@2138 76 // A base class for baseline policies.
iveresov@2138 77 class NonTieredCompPolicy : public CompilationPolicy {
iveresov@2138 78 int _compiler_count;
iveresov@2138 79 protected:
iveresov@2138 80 static void trace_frequency_counter_overflow(methodHandle m, int branch_bci, int bci);
iveresov@2138 81 static void trace_osr_request(methodHandle method, nmethod* osr, int bci);
iveresov@2138 82 static void trace_osr_completion(nmethod* osr_nm);
iveresov@2138 83 void reset_counter_for_invocation_event(methodHandle method);
iveresov@2138 84 void reset_counter_for_back_branch_event(methodHandle method);
iveresov@2138 85 public:
iveresov@2138 86 NonTieredCompPolicy() : _compiler_count(0) { }
iveresov@2138 87 virtual int compiler_count(CompLevel comp_level);
iveresov@2138 88 virtual void do_safepoint_work();
iveresov@2138 89 virtual void reprofile(ScopeDesc* trap_scope, bool is_osr);
iveresov@2138 90 virtual void delay_compilation(methodOop method);
iveresov@2138 91 virtual void disable_compilation(methodOop method);
iveresov@2138 92 virtual bool is_mature(methodOop method);
iveresov@2138 93 virtual void initialize();
iveresov@2138 94 virtual CompileTask* select_task(CompileQueue* compile_queue);
iveresov@2138 95 virtual nmethod* event(methodHandle method, methodHandle inlinee, int branch_bci, int bci, CompLevel comp_level, TRAPS);
iveresov@2138 96 virtual void method_invocation_event(methodHandle m, TRAPS) = 0;
iveresov@2138 97 virtual void method_back_branch_event(methodHandle m, int bci, TRAPS) = 0;
iveresov@2138 98 };
iveresov@2138 99
iveresov@2138 100 class SimpleCompPolicy : public NonTieredCompPolicy {
duke@435 101 public:
iveresov@2138 102 virtual void method_invocation_event(methodHandle m, TRAPS);
iveresov@2138 103 virtual void method_back_branch_event(methodHandle m, int bci, TRAPS);
duke@435 104 };
duke@435 105
duke@435 106 // StackWalkCompPolicy - existing C2 policy
duke@435 107
duke@435 108 #ifdef COMPILER2
iveresov@2138 109 class StackWalkCompPolicy : public NonTieredCompPolicy {
duke@435 110 public:
iveresov@2138 111 virtual void method_invocation_event(methodHandle m, TRAPS);
iveresov@2138 112 virtual void method_back_branch_event(methodHandle m, int bci, TRAPS);
duke@435 113
duke@435 114 private:
duke@435 115 RFrame* findTopInlinableFrame(GrowableArray<RFrame*>* stack);
duke@435 116 RFrame* senderOf(RFrame* rf, GrowableArray<RFrame*>* stack);
duke@435 117
duke@435 118 // the following variables hold values computed by the last inlining decision
duke@435 119 // they are used for performance debugging only (print better messages)
duke@435 120 static const char* _msg; // reason for not inlining
duke@435 121
duke@435 122 static const char* shouldInline (methodHandle callee, float frequency, int cnt);
duke@435 123 // positive filter: should send be inlined? returns NULL (--> yes) or rejection msg
duke@435 124 static const char* shouldNotInline(methodHandle callee);
duke@435 125 // negative filter: should send NOT be inlined? returns NULL (--> inline) or rejection msg
duke@435 126
duke@435 127 };
duke@435 128 #endif

mercurial