aoqi@0: /* aoqi@0: * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #ifndef SHARE_VM_CI_CICALLPROFILE_HPP aoqi@0: #define SHARE_VM_CI_CICALLPROFILE_HPP aoqi@0: aoqi@0: #include "ci/ciClassList.hpp" aoqi@0: #include "memory/allocation.hpp" aoqi@0: aoqi@0: // ciCallProfile aoqi@0: // aoqi@0: // This class is used to determine the frequently called method aoqi@0: // at some call site aoqi@0: class ciCallProfile : StackObj { aoqi@0: private: aoqi@0: // Fields are initialized directly by ciMethod::call_profile_at_bci. aoqi@0: friend class ciMethod; aoqi@0: friend class ciMethodHandle; aoqi@0: aoqi@0: enum { MorphismLimit = 2 }; // Max call site's morphism we care about aoqi@0: int _limit; // number of receivers have been determined aoqi@0: int _morphism; // determined call site's morphism aoqi@0: int _count; // # times has this call been executed aoqi@0: int _receiver_count[MorphismLimit + 1]; // # times receivers have been seen aoqi@0: ciMethod* _method[MorphismLimit + 1]; // receivers methods aoqi@0: ciKlass* _receiver[MorphismLimit + 1]; // receivers (exact) aoqi@0: aoqi@0: ciCallProfile() { aoqi@0: _limit = 0; aoqi@0: _morphism = 0; aoqi@0: _count = -1; aoqi@0: _receiver_count[0] = -1; aoqi@0: _method[0] = NULL; aoqi@0: _receiver[0] = NULL; aoqi@0: } aoqi@0: aoqi@0: void add_receiver(ciKlass* receiver, int receiver_count); aoqi@0: aoqi@0: public: aoqi@0: // Note: The following predicates return false for invalid profiles: aoqi@0: bool has_receiver(int i) const { return _limit > i; } aoqi@0: int morphism() const { return _morphism; } aoqi@0: aoqi@0: int count() const { return _count; } aoqi@0: int receiver_count(int i) { aoqi@0: assert(i < _limit, "out of Call Profile MorphismLimit"); aoqi@0: return _receiver_count[i]; aoqi@0: } aoqi@0: float receiver_prob(int i) { aoqi@0: assert(i < _limit, "out of Call Profile MorphismLimit"); aoqi@0: return (float)_receiver_count[i]/(float)_count; aoqi@0: } aoqi@0: ciMethod* method(int i) { aoqi@0: assert(i < _limit, "out of Call Profile MorphismLimit"); aoqi@0: return _method[i]; aoqi@0: } aoqi@0: ciKlass* receiver(int i) { aoqi@0: assert(i < _limit, "out of Call Profile MorphismLimit"); aoqi@0: return _receiver[i]; aoqi@0: } aoqi@0: aoqi@0: // Rescale the current profile based on the incoming scale aoqi@0: ciCallProfile rescale(double scale) { aoqi@0: assert(scale >= 0 && scale <= 1.0, "out of range"); aoqi@0: ciCallProfile call = *this; aoqi@0: call._count = (int)(call._count * scale); aoqi@0: for (int i = 0; i < _morphism; i++) { aoqi@0: call._receiver_count[i] = (int)(call._receiver_count[i] * scale); aoqi@0: } aoqi@0: return call; aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: #endif // SHARE_VM_CI_CICALLPROFILE_HPP