001: /*
002: *
003: *
004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package com.sun.cldchi.tools.memoryprofiler.data;
028:
029: import java.util.Collection;
030: import java.util.ArrayList;
031: import java.util.HashMap;
032:
033: /**
034: * This class is container for Java Object information. It contains all object data.
035: *
036: * @see com.sun.cldchi.tools.memoryprofiler.data.MPDataProvider
037: *
038: */
039: public class JavaObject {
040: /**
041: * address of the java object
042: */
043: public final int address;
044:
045: /**
046: * unique id of class of the java object
047: */
048: final int class_id;
049:
050: /**
051: * size of the java object
052: */
053: public final int size;
054:
055: public final int object_type;
056: private int root_distance = -1;
057:
058: /**
059: * these fields are used only for stacks
060: */
061: final int _stack_id;
062: final HashMap _stack_offsets;
063:
064: /**
065: * addresses of the objects which are referenced by this object
066: */
067: final int[] _references_addresses;
068: private Collection _references = new ArrayList();
069: private Collection _referees = new ArrayList();
070:
071: /**
072: * return the array of objects which are referenced by this object
073: *
074: * @return array of JavaObject
075: */
076: public Object[] get_references() {
077: return _references.toArray();
078: }
079:
080: public void add_reference(JavaObject reference) {
081: _references.add(reference);
082: }
083:
084: /**
085: * return the array of objects which are reference this object
086: *
087: * @return array of JavaObject
088: */
089: public Object[] get_referees() {
090: return _referees.toArray();
091: }
092:
093: public void add_referee(JavaObject referee) {
094: _referees.add(referee);
095: }
096:
097: JavaObject(int p_address, int p_class_id, int p_size,
098: int[] references, int p_obj_type) {
099: this (p_address, p_class_id, p_size, references, p_obj_type,
100: null, -1);
101: }
102:
103: JavaObject(int p_address, int p_class_id, int p_size,
104: int[] references, int p_obj_tp, HashMap offsets,
105: int stack_id) {
106: address = p_address;
107: class_id = p_class_id;
108: size = p_size;
109: object_type = p_obj_tp;
110: _references_addresses = references;
111: _stack_offsets = offsets;
112: _stack_id = stack_id;
113: }
114:
115: public String toString() {
116: return /*Integer.toString(root_distance) + */"0x"
117: + Integer.toHexString(address);
118: }
119:
120: /**
121: * set the minimal size of a chain of linked objects started from
122: * a root object and finished in this object
123: */
124: void setRootDistance(int dist) {
125: root_distance = dist;
126: }
127:
128: /**
129: * return minimal size of a chain of linked objects started from
130: * a root object and finished in this object
131: */
132: public int getRootDistance() {
133: return root_distance;
134: }
135:
136: /**
137: * return true, if there is a chain of linked objects started from
138: * a root object and finished in this object
139: *
140: * @return true if it is a live object
141: */
142: public boolean alive() {
143: return root_distance != -1;
144: }
145: }
|