1/*
2 * Copyright (c) 2011, 2012, 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
25package sun.jvm.hotspot.oops;
26
27import java.io.*;
28import java.util.*;
29import sun.jvm.hotspot.debugger.*;
30import sun.jvm.hotspot.runtime.*;
31import sun.jvm.hotspot.types.*;
32import sun.jvm.hotspot.utilities.*;
33
34public abstract class ProfileData {
35  // This is a pointer to a section of profiling data.
36  private DataLayout _data;
37
38  public DataLayout data() { return _data; }
39
40  // How many cells are in this?
41  public abstract int cellCount();
42
43
44  // Return the size of this data.
45  public int sizeInBytes() {
46    return DataLayout.computeSizeInBytes(cellCount());
47  }
48
49  public int dp() {
50    return data().dp();
51  }
52
53  // Low-level accessors for underlying data
54  int intptrAt(int index) {
55    //assert(0 <= index && index < cellCount(), "oob");
56    return data().cellAt(index);
57  }
58  int intAt(int index) {
59    return (int)intptrAt(index);
60  }
61  int uintAt(int index) {
62    return (int)intptrAt(index);
63  }
64  public Address addressAt(int index) {
65    return data().addressAt(index);
66  }
67
68  boolean flagAt(int flagNumber) {
69    return data().flagAt(flagNumber);
70  }
71
72  // two convenient imports for use by subclasses:
73  public static int cellOffset(int index) {
74    return DataLayout.cellOffset(index);
75  }
76
77  public ProfileData(DataLayout data) {
78    _data = data;
79  }
80
81  // Constructor for invalid ProfileData.
82  ProfileData() {
83    _data = null;
84  }
85
86  int bci() {
87    return data().bci();
88  }
89
90  int trapState() {
91    return data().trapState();
92  }
93  public abstract void printDataOn(PrintStream st);
94
95  void tab(PrintStream st) {
96    st.print("\t");
97  }
98
99  void printShared(PrintStream st, String name) {
100    st.print("bci: " + bci());
101    // st.fillTo(tabWidthOne);
102    st.print(" " +  name + " ");
103    tab(st);
104    int trap = trapState();
105    if (trap != 0) {
106      st.print("trap(" + MethodData.formatTrapState(trap) + ") ");
107    }
108    int flags = data().flags();
109    if (flags != 0)
110      st.print("flags(" + flags + ") ");
111  }
112
113  public String toString() {
114    ByteArrayOutputStream baos = new ByteArrayOutputStream();
115    PrintStream ps = new PrintStream(baos);
116    try {
117      printDataOn(ps);
118    } finally {
119      ps.close();
120    }
121    return baos.toString();
122  }
123}
124