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 import java.util.AbstractList;
20 import java.util.ArrayList;
21 import java.util.List;
22 
23 class SuperRoot extends AhatInstance {
24   private List<AhatInstance> mRoots = new ArrayList<AhatInstance>();
25   private Object mDominatorsComputationState;
26 
SuperRoot()27   SuperRoot() {
28     super(0);
29   }
30 
addRoot(AhatInstance root)31   void addRoot(AhatInstance root) {
32     mRoots.add(root);
33   }
34 
35   @Override
getExtraJavaSize()36   long getExtraJavaSize() {
37     return 0;
38   }
39 
40   @Override
toString()41   public String toString() {
42     return "SUPER_ROOT";
43   }
44 
45   @Override
getReferences()46   Iterable<Reference> getReferences() {
47     return new AbstractList<Reference>() {
48       @Override
49       public int size() {
50         return mRoots.size();
51       }
52 
53       @Override
54       public Reference get(int index) {
55         String field = ".roots[" + Integer.toString(index) + "]";
56         return new Reference(SuperRoot.this, field, mRoots.get(index), Reachability.STRONG);
57       }
58     };
59   }
60 }
61