duke@435: /* duke@435: * Copyright 2000-2006 Sun Microsystems, Inc. All Rights Reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * duke@435: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, duke@435: * CA 95054 USA or visit www.sun.com if you need additional information or duke@435: * have any questions. duke@435: * duke@435: */ duke@435: duke@435: // The CompilationPolicy selects which method (if any) should be compiled. duke@435: // It also decides which methods must always be compiled (i.e., are never duke@435: // interpreted). duke@435: duke@435: class CompilationPolicy : public CHeapObj { duke@435: private: duke@435: static CompilationPolicy* _policy; duke@435: // Accumulated time duke@435: static elapsedTimer _accumulated_time; duke@435: duke@435: static bool _in_vm_startup; duke@435: duke@435: public: duke@435: virtual void method_invocation_event(methodHandle m, TRAPS) = 0; duke@435: virtual void method_back_branch_event(methodHandle m, int branch_bci, int loop_top_bci, TRAPS) = 0; duke@435: virtual int compilation_level(methodHandle m, int branch_bci) = 0; duke@435: duke@435: void reset_counter_for_invocation_event(methodHandle method); duke@435: void reset_counter_for_back_branch_event(methodHandle method); duke@435: duke@435: static void set_in_vm_startup(bool in_vm_startup) { _in_vm_startup = in_vm_startup; } duke@435: static void completed_vm_startup(); duke@435: static bool delayCompilationDuringStartup() { return _in_vm_startup; } duke@435: duke@435: static bool mustBeCompiled(methodHandle m); // m must be compiled before executing it duke@435: static bool canBeCompiled(methodHandle m); // m is allowed to be compiled duke@435: duke@435: static void set_policy(CompilationPolicy* policy) { _policy = policy; } duke@435: static CompilationPolicy* policy() { return _policy; } duke@435: duke@435: // Profiling duke@435: elapsedTimer* accumulated_time() { return &_accumulated_time; } duke@435: void print_time() PRODUCT_RETURN; duke@435: }; duke@435: duke@435: class SimpleCompPolicy : public CompilationPolicy { duke@435: public: duke@435: void method_invocation_event( methodHandle m, TRAPS); duke@435: void method_back_branch_event(methodHandle m, int branch_bci, int loop_top_bci, TRAPS); duke@435: int compilation_level(methodHandle m, int branch_bci); duke@435: }; duke@435: duke@435: // StackWalkCompPolicy - existing C2 policy duke@435: duke@435: #ifdef COMPILER2 duke@435: class StackWalkCompPolicy : public CompilationPolicy { duke@435: public: duke@435: void method_invocation_event(methodHandle m, TRAPS); duke@435: void method_back_branch_event(methodHandle m, int branch_bci, int loop_top_bci, TRAPS); duke@435: int compilation_level(methodHandle m, int branch_bci); duke@435: duke@435: private: duke@435: RFrame* findTopInlinableFrame(GrowableArray* stack); duke@435: RFrame* senderOf(RFrame* rf, GrowableArray* stack); duke@435: duke@435: // the following variables hold values computed by the last inlining decision duke@435: // they are used for performance debugging only (print better messages) duke@435: static const char* _msg; // reason for not inlining duke@435: duke@435: static const char* shouldInline (methodHandle callee, float frequency, int cnt); duke@435: // positive filter: should send be inlined? returns NULL (--> yes) or rejection msg duke@435: static const char* shouldNotInline(methodHandle callee); duke@435: // negative filter: should send NOT be inlined? returns NULL (--> inline) or rejection msg duke@435: duke@435: }; duke@435: #endif