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: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.debugger.jpda.heapwalk;
043:
044: import org.netbeans.lib.profiler.heap.GCRoot;
045: import org.netbeans.lib.profiler.heap.Heap;
046: import org.netbeans.lib.profiler.heap.HeapSummary;
047: import org.netbeans.lib.profiler.heap.Instance;
048: import org.netbeans.lib.profiler.heap.JavaClass;
049:
050: import java.util.ArrayList;
051: import java.util.Collection;
052: import java.util.Collections;
053: import java.util.List;
054: import java.util.Properties;
055:
056: import org.netbeans.api.debugger.jpda.JPDAClassType;
057: import org.netbeans.api.debugger.jpda.JPDADebugger;
058:
059: /**
060: *
061: * @author Martin Entlicher
062: */
063: public class HeapImpl implements Heap {
064:
065: private JPDADebugger debugger;
066:
067: /** Creates a new instance of HeapImpl */
068: public HeapImpl(JPDADebugger debugger) {
069: this .debugger = debugger;
070: }
071:
072: public JPDADebugger getDebugger() {
073: return debugger;
074: }
075:
076: public HeapSummary getSummary() {
077: return new DebuggerHeapSummary(debugger);
078: }
079:
080: public List<JavaClass> getAllClasses() {
081: List<JPDAClassType> allClasses = debugger.getAllClasses();
082: long[] counts = debugger.getInstanceCounts(allClasses);
083: List<JavaClass> javaClasses = new ArrayList<JavaClass>(
084: allClasses.size());
085: int i = 0;
086: for (JPDAClassType clazz : allClasses) {
087: javaClasses
088: .add(new JavaClassImpl(this , clazz, counts[i++]));
089: }
090: return javaClasses;
091: }
092:
093: public Instance getInstanceByID(long id) {
094: return null;
095: }
096:
097: public JavaClass getJavaClassByID(long id) {
098: return null;
099: }
100:
101: public JavaClass getJavaClassByName(String name) {
102: List<JPDAClassType> classes = debugger.getClassesByName(name);
103: if (classes.size() == 0) {
104: return null;
105: }
106: return new JavaClassImpl(this , classes.get(0), classes.get(0)
107: .getInstanceCount());
108: }
109:
110: public Collection getGCRoots() {
111: return Collections.emptyList();
112: }
113:
114: public GCRoot getGCRoot(Instance instance) {
115: return null;
116: }
117:
118: public Properties getSystemProperties() {
119: // TODO
120: return null;
121: }
122:
123: private static final class DebuggerHeapSummary implements
124: HeapSummary {
125:
126: private JPDADebugger debugger;
127:
128: public DebuggerHeapSummary(JPDADebugger debugger) {
129: this .debugger = debugger;
130: }
131:
132: public int getTotalLiveBytes() {
133: return -1;
134: }
135:
136: public int getTotalLiveInstances() {
137: long[] counts = debugger.getInstanceCounts(debugger
138: .getAllClasses());
139: int sum = 0;
140: for (long c : counts) {
141: sum += (int) c;
142: }
143: return sum;
144: }
145:
146: public long getTotalAllocatedBytes() {
147: return -1L;
148: }
149:
150: public long getTotalAllocatedInstances() {
151: return -1L;
152: }
153:
154: public long getTime() {
155: return System.currentTimeMillis();
156: }
157:
158: }
159:
160: }
|