| 1 | /* |
| 2 | * Copyright 2008 Eric Caspole |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this |
| 5 | * file except in compliance with the License. You may obtain a copy of the License at |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software distributed under |
| 10 | * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 11 | * KIND, either express or implied. See the License for the specific language governing |
| 12 | * permissions and limitations under the License. |
| 13 | */ |
| 14 | package net.sf.madmap; |
| 15 | |
| 16 | import java.util.*; |
| 17 | |
| 18 | /** |
| 19 | * HprofHeapAllocation is the base class for objects and arrays, holding some |
| 20 | * common methods for managing the contained refs. Each HprofHeapAllocation |
| 21 | * has a ref to a HprofClassElement which is the java class for the object. |
| 22 | * |
| 23 | * @author ecaspole |
| 24 | * |
| 25 | */ |
| 26 | public abstract class HprofHeapAllocation extends HprofHeapCollectable { |
| 27 | HprofClassElement _class_addr; |
| 28 | long[] _elems = null; |
| 29 | int _trace; |
| 30 | |
| 31 | public HprofHeapAllocation( long addr, int trace, HprofClassElement cls_addr ) { |
| 32 | super( addr ); |
| 33 | _class_addr = cls_addr; |
| 34 | _trace = trace; |
| 35 | } |
| 36 | |
| 37 | |
| 38 | public HprofHeapAllocation( long addr ) { |
| 39 | super( addr ); |
| 40 | } |
| 41 | |
| 42 | public long children_size() { |
| 43 | if ( _elems != null ) { |
| 44 | return _elems.length; |
| 45 | } |
| 46 | return 0; |
| 47 | } |
| 48 | |
| 49 | public void set_children( long[] elems ) { _elems = elems; } |
| 50 | public long[] children() { return _elems; } |
| 51 | |
| 52 | public int getStackTrace() { return _trace; } |
| 53 | public int setStackTrace( int x ) { return _trace = x; } |
| 54 | |
| 55 | abstract public long size(); |
| 56 | public HprofClassElement class_addr() { return _class_addr; } |
| 57 | public void set_class_addr( HprofClassElement new_addr ) { _class_addr = new_addr; } |
| 58 | |
| 59 | public HprofClassElement getActualClass() { |
| 60 | return class_addr(); |
| 61 | } |
| 62 | |
| 63 | public String className() { |
| 64 | return class_addr().className(); |
| 65 | } |
| 66 | } |