1 /*
2  * Copyright (c) 2014, 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 package sun.jvm.hotspot.oops;
26 
27 import java.io.*;
28 import java.util.*;
29 import sun.jvm.hotspot.debugger.*;
30 import sun.jvm.hotspot.runtime.*;
31 import sun.jvm.hotspot.types.*;
32 import sun.jvm.hotspot.utilities.*;
33 
34 // VirtualCallTypeData
35 //
36 // A VirtualCallTypeData is used to access profiling information about
37 // a virtual call for which we collect type information about
38 // arguments and return value.
39 public class VirtualCallTypeData<K,M> extends VirtualCallData implements CallTypeDataInterface<K> {
40   final TypeStackSlotEntries<K,M> args;
41   final ReturnTypeEntry<K,M> ret;
42 
cellCountGlobalOffset()43   int cellCountGlobalOffset() {
44     return VirtualCallData.staticCellCount() + TypeEntriesAtCall.cellCountLocalOffset();
45   }
46 
cellCountNoHeader()47   int cellCountNoHeader() {
48     return uintAt(cellCountGlobalOffset());
49   }
50 
VirtualCallTypeData(MethodDataInterface<K,M> methodData, DataLayout layout)51   public VirtualCallTypeData(MethodDataInterface<K,M> methodData, DataLayout layout) {
52     super(methodData, layout);
53     args = new TypeStackSlotEntries<K,M>(methodData, this, VirtualCallData.staticCellCount()+TypeEntriesAtCall.headerCellCount(), numberOfArguments());
54     ret = new ReturnTypeEntry<K,M>(methodData, this, cellCount() - ReturnTypeEntry.staticCellCount());
55   }
56 
staticCellCount()57   static int staticCellCount() {
58     return -1;
59   }
60 
cellCount()61   public int cellCount() {
62     return VirtualCallData.staticCellCount() +
63       TypeEntriesAtCall.headerCellCount() +
64       intAt(cellCountGlobalOffset());
65   }
66 
numberOfArguments()67   public int numberOfArguments() {
68     return cellCountNoHeader() / TypeStackSlotEntries.perArgCount();
69   }
70 
hasArguments()71   public boolean hasArguments() {
72     return cellCountNoHeader() >= TypeStackSlotEntries.perArgCount();
73   }
74 
argumentType(int i)75   public K argumentType(int i) {
76     return args.type(i);
77   }
78 
hasReturn()79   public boolean hasReturn() {
80     return (cellCountNoHeader() % TypeStackSlotEntries.perArgCount()) != 0;
81   }
82 
returnType()83   public K returnType() {
84     return ret.type();
85   }
86 
argumentTypeIndex(int i)87   public int argumentTypeIndex(int i) {
88     return args.typeIndex(i);
89   }
90 
returnTypeIndex()91   public int returnTypeIndex() {
92     return ret.typeIndex();
93   }
94 
printDataOn(PrintStream st)95   public void printDataOn(PrintStream st) {
96     super.printDataOn(st);
97     if (hasArguments()) {
98       tab(st);
99       st.print("argument types");
100       args.printDataOn(st);
101     }
102     if (hasReturn()) {
103       tab(st);
104       st.print("return type");
105       ret.printDataOn(st);
106     }
107   }
108 };
109