• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.ahat.heapdump;
18 
19 /**
20  * Enum corresponding to basic types from the binary heap dump format.
21  */
22 public enum Type {
23   /**
24    * Type used for any Java object.
25    */
26   OBJECT("Object", 0),    // size is 0 to indicate it depends on the size of references
27 
28   /**
29    * The primitive boolean type.
30    */
31   BOOLEAN("boolean", 1),
32 
33   /**
34    * The primitive char type.
35    */
36   CHAR("char", 2),
37 
38   /**
39    * The primitive float type.
40    */
41   FLOAT("float", 4),
42 
43   /**
44    * The primitive double type.
45    */
46   DOUBLE("double", 8),
47 
48   /**
49    * The primitive byte type.
50    */
51   BYTE("byte", 1),
52 
53   /**
54    * The primitive short type.
55    */
56   SHORT("short", 2),
57 
58   /**
59    * The primitive int type.
60    */
61   INT("int", 4),
62 
63   /**
64    * The primitive long type.
65    */
66   LONG("long", 8);
67 
68   /**
69    * The name of the type.
70    */
71   public final String name;
72 
73   /**
74    * The number of bytes taken up by values of this type in the Java heap.
75    */
76   private final int size;
77 
78   /**
79    * Get the number of bytes taken up by values of this type in the Java heap.
80    *
81    * @param refSize the size of object references as specified in the heap dump
82    */
size(int refSize)83   int size(int refSize) {
84     return size == 0 ? refSize : size;
85   }
86 
Type(String name, int size)87   Type(String name, int size) {
88     this.name = name;
89     this.size = size;
90   }
91 
92   @Override
toString()93   public String toString() {
94     return name;
95   }
96 }
97