001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: * The Original Software is NetBeans. The Initial Developer of the Original
026: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
027: * Microsystems, Inc. All Rights Reserved.
028: *
029: * If you wish your version of this file to be governed by only the CDDL
030: * or only the GPL Version 2, indicate your decision by adding
031: * "[Contributor] elects to include this software in this distribution
032: * under the [CDDL or GPL Version 2] license." If you do not indicate a
033: * single choice of license, a recipient has the option to distribute
034: * your version of this file under either the CDDL, the GPL Version 2 or
035: * to extend the choice of license to its licensees as provided above.
036: * However, if you add GPL Version 2 code and therefore, elected the GPL
037: * Version 2 license, then the option applies only if the new code is
038: * made subject to such option by the copyright holder.
039: */
040:
041: package org.netbeans.lib.profiler.heap;
042:
043: import java.util.Collection;
044: import java.util.List;
045:
046: /**
047: * This class represents java.lang.Class instances on the heap.
048: * @author Tomas Hurka
049: */
050: public interface JavaClass extends Type {
051: //~ Methods ------------------------------------------------------------------------------------------------------------------
052:
053: /**
054: * Returns a value object that reflects the specified static field of the class
055: * represented by this {@link JavaClass} object.
056: * The name parameter is a String that specifies the simple name of the desired static field.
057: * <br>
058: * Speed: normal
059: * @param name the name of the field
060: * @return @return the value for the specified static field in this class.
061: * If a static field with the specified name is not found <CODE>null</CODE> is returned.
062: * If the field.getType() is {@link Type} object {@link Instance} is returned as field value,
063: * for primitive types its corresponding object wapper (Boolean, Integer, Float, etc.) is returned.
064: */
065: public Object getValueOfStaticField(String name);
066:
067: /**
068: * returns the size of all instances in bytes. For non array classes
069: * this is computed as getInstancesCount()*getInstanceSize().
070: * Instance size of all instances is summed for arrays.
071: * <br>
072: * Speed: normal
073: * @return the size of all instances in bytes
074: */
075: int getAllInstancesSize();
076:
077: /**
078: * returns true if this JavaClass represents array (for examle: java.lang.String[]).
079: * <br>
080: * Speed: fast
081: * @return <CODE>true</CODE> if this class represents array, <CODE>false</CODE> otherwise
082: */
083: boolean isArray();
084:
085: /**
086: * returns {@link Instance} representing class loader of this class.
087: * <br>
088: * Speed: fast
089: * @return class loader
090: */
091: Instance getClassLoader();
092:
093: /**
094: * returns List of instance fields of this {@link JavaClass}.
095: * <br>
096: * Speed: normal
097: * @return list of {@link Field} instance fields
098: */
099: List /*<Field>*/getFields();
100:
101: /**
102: * returns the size of the {@link Instance} in bytes if this JavaClass does
103: * not represent array. For arrays -1 is returned
104: * <br>
105: * Speed: fast
106: * @return returns the size of the {@link Instance} in bytes, for arrays -1 is returned.
107: */
108: int getInstanceSize();
109:
110: /**
111: * computes the list of all {@link Instance} of this class.
112: * The instaces are ordered according to {@link Instance#getInstanceNumber()}
113: * <br>
114: * Speed: slow
115: * @return list {@link Instance} of instances
116: */
117: List /*<Instance>*/getInstances();
118:
119: /**
120: * gets number of instances of this class.
121: * <br>
122: * Speed: first invocation is slow, all subsequent invocations are fast
123: * @return number of instances
124: */
125: int getInstancesCount();
126:
127: /**
128: * gets unique (in whole heap) ID of this {@link JavaClass}.
129: * <br>
130: * Speed: fast
131: * @return ID of this {@link JavaClass}
132: */
133: long getJavaClassId();
134:
135: /**
136: * return human readable name of the class.
137: * Innerclasses are separated by $. Anonymous classes uses $1 $2 etc.
138: * Arrays uses [] after the class or primitive type name
139: * <br>
140: * Speed: fast
141: * @return name of the class
142: */
143: String getName();
144:
145: /**
146: * Returns a {@link Field} object that reflects the specified field of the class
147: * represented by this {@link JavaClass} object.
148: * The name parameter is a String that specifies the simple name of the desired field.
149: * <br>
150: * Speed: normal
151: * @param name the name of the field
152: * @return the {@link Field} object for the specified field in this class.
153: * If a field with the specified name is not found <CODE>null</CODE> is returned.
154: */
155:
156: /* public Field getField(String name); */
157: /**
158: * computes the list of instance field values. The order is fields of this class followed by
159: * super class, etc.
160: * <br>
161: * Speed: normal
162: * @return list of {@link FieldValue} instance field values.
163: */
164: List /*<FieldValue>*/getStaticFieldValues();
165:
166: /**
167: * returns all subclasses of this class. This method works recursivelly
168: * so it returns also subclasses of subclasses etc.
169: * <br>
170: * Speed: slow
171: * @return returns the {@link Collection} of {@link JavaClass}.
172: */
173: Collection /*<JavaClass>*/getSubClasses();
174:
175: /**
176: * returns {@link JavaClass} representing super class of this class.
177: * <br>
178: * Speed: fast
179: * @return super class (super class of java.lang.Object is null)
180: */
181: JavaClass getSuperClass();
182: }
|