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 // Type entries used for arguments passed at a call and parameters on
35 // method entry. 2 cells per entry: one for the type encoded as in
36 // TypeEntries and one initialized with the stack slot where the
37 // profiled object is to be found so that the interpreter can locate
38 // it quickly.
39 public class TypeStackSlotEntries<K,M> extends TypeEntries<K,M> {
40   static final int stackSlotEntry = 0;
41   static final int typeEntry = 1;
42   static final int perArgCellCount = 2;
43 
stackSlotOffset(int i)44   int stackSlotOffset(int i) {
45     return baseOff + stackSlotLocalOffset(i);
46   }
47 
48   final int numberOfEntries;
49 
typeOffsetInCells(int i)50   int typeOffsetInCells(int i) {
51     return baseOff + typeLocalOffset(i);
52   }
53 
TypeStackSlotEntries(MethodDataInterface<K,M> methodData, ProfileData pd, int baseOff, int nbEntries)54   TypeStackSlotEntries(MethodDataInterface<K,M> methodData, ProfileData pd, int baseOff, int nbEntries) {
55     super(methodData, pd, baseOff);
56     numberOfEntries = nbEntries;
57   }
58 
stackSlotLocalOffset(int i)59   static int stackSlotLocalOffset(int i) {
60     return i * perArgCellCount + stackSlotEntry;
61   }
62 
typeLocalOffset(int i)63   static int typeLocalOffset(int i) {
64     return i * perArgCellCount + typeEntry;
65   }
66 
stackSlot(int i)67   int stackSlot(int i) {
68     return pd.uintAt(stackSlotOffset(i));
69   }
70 
type(int i)71   K type(int i) {
72     return validKlass(typeOffsetInCells(i));
73   }
74 
perArgCount()75   static int perArgCount() {
76     return perArgCellCount;
77   }
78 
typeIndex(int i)79   int typeIndex(int i) {
80     return typeOffsetInCells(i);
81   }
82 
printDataOn(PrintStream st)83   void printDataOn(PrintStream st) {
84     for (int i = 0; i < numberOfEntries; i++) {
85       pd.tab(st);
86       st.print(i + ": stack(" + stackSlot(i)+ ") ");
87       printKlass(st, typeOffsetInCells(i));
88       st.println();
89     }
90   }
91 }
92