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