1
|
1 |
/*
|
|
2 |
* Copyright 1999-2006 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 |
* have any questions.
|
|
22 |
*
|
|
23 |
*/
|
|
24 |
|
|
25 |
// ciCallProfile
|
|
26 |
//
|
|
27 |
// This class is used to determine the frequently called method
|
|
28 |
// at some call site
|
|
29 |
class ciCallProfile : StackObj {
|
|
30 |
private:
|
|
31 |
// Fields are initialized directly by ciMethod::call_profile_at_bci.
|
|
32 |
friend class ciMethod;
|
|
33 |
|
|
34 |
enum { MorphismLimit = 2 }; // Max call site's morphism we care about
|
|
35 |
int _limit; // number of receivers have been determined
|
|
36 |
int _morphism; // determined call site's morphism
|
|
37 |
int _count; // # times has this call been executed
|
|
38 |
int _receiver_count[MorphismLimit + 1]; // # times receivers have been seen
|
|
39 |
ciMethod* _method[MorphismLimit + 1]; // receivers methods
|
|
40 |
ciKlass* _receiver[MorphismLimit + 1]; // receivers (exact)
|
|
41 |
|
|
42 |
ciCallProfile() {
|
|
43 |
_limit = 0;
|
|
44 |
_morphism = 0;
|
|
45 |
_count = -1;
|
|
46 |
_receiver_count[0] = -1;
|
|
47 |
_method[0] = NULL;
|
|
48 |
_receiver[0] = NULL;
|
|
49 |
}
|
|
50 |
|
|
51 |
void add_receiver(ciKlass* receiver, int receiver_count);
|
|
52 |
|
|
53 |
public:
|
|
54 |
// Note: The following predicates return false for invalid profiles:
|
|
55 |
bool has_receiver(int i) { return _limit > i; }
|
|
56 |
int morphism() { return _morphism; }
|
|
57 |
|
|
58 |
int count() { return _count; }
|
|
59 |
int receiver_count(int i) {
|
|
60 |
assert(i < _limit, "out of Call Profile MorphismLimit");
|
|
61 |
return _receiver_count[i];
|
|
62 |
}
|
|
63 |
float receiver_prob(int i) {
|
|
64 |
assert(i < _limit, "out of Call Profile MorphismLimit");
|
|
65 |
return (float)_receiver_count[i]/(float)_count;
|
|
66 |
}
|
|
67 |
ciMethod* method(int i) {
|
|
68 |
assert(i < _limit, "out of Call Profile MorphismLimit");
|
|
69 |
return _method[i];
|
|
70 |
}
|
|
71 |
ciKlass* receiver(int i) {
|
|
72 |
assert(i < _limit, "out of Call Profile MorphismLimit");
|
|
73 |
return _receiver[i];
|
|
74 |
}
|
|
75 |
};
|