ciCallProfile.hpp revision 1879:f95d63e2154a
1/*
2 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
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,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25#ifndef SHARE_VM_CI_CICALLPROFILE_HPP
26#define SHARE_VM_CI_CICALLPROFILE_HPP
27
28#include "ci/ciClassList.hpp"
29
30// ciCallProfile
31//
32// This class is used to determine the frequently called method
33// at some call site
34class ciCallProfile : StackObj {
35private:
36  // Fields are initialized directly by ciMethod::call_profile_at_bci.
37  friend class ciMethod;
38
39  enum { MorphismLimit = 2 }; // Max call site's morphism we care about
40  int  _limit;                // number of receivers have been determined
41  int  _morphism;             // determined call site's morphism
42  int  _count;                // # times has this call been executed
43  int  _receiver_count[MorphismLimit + 1]; // # times receivers have been seen
44  ciMethod* _method[MorphismLimit + 1];    // receivers methods
45  ciKlass*  _receiver[MorphismLimit + 1];  // receivers (exact)
46
47  ciCallProfile() {
48    _limit = 0;
49    _morphism    = 0;
50    _count = -1;
51    _receiver_count[0] = -1;
52    _method[0]   = NULL;
53    _receiver[0] = NULL;
54  }
55
56  void add_receiver(ciKlass* receiver, int receiver_count);
57
58public:
59  // Note:  The following predicates return false for invalid profiles:
60  bool      has_receiver(int i) { return _limit > i; }
61  int       morphism()          { return _morphism; }
62
63  int       count()             { return _count; }
64  int       receiver_count(int i)  {
65    assert(i < _limit, "out of Call Profile MorphismLimit");
66    return _receiver_count[i];
67  }
68  float     receiver_prob(int i)  {
69    assert(i < _limit, "out of Call Profile MorphismLimit");
70    return (float)_receiver_count[i]/(float)_count;
71  }
72  ciMethod* method(int i)          {
73    assert(i < _limit, "out of Call Profile MorphismLimit");
74    return _method[i];
75  }
76  ciKlass*  receiver(int i)        {
77    assert(i < _limit, "out of Call Profile MorphismLimit");
78    return _receiver[i];
79  }
80};
81
82#endif // SHARE_VM_CI_CICALLPROFILE_HPP
83