1 /* 2 * Copyright (C) 2018 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 the reachability of an instance. 21 * See {@link java.lang.ref} for a specification of the various kinds of 22 * reachibility. The enum constants are specified in decreasing order of 23 * strength. 24 */ 25 public enum Reachability { 26 /** 27 * The instance is strongly reachable. 28 */ 29 STRONG("strong"), 30 31 /** 32 * The instance is softly reachable. 33 */ 34 SOFT("soft"), 35 36 /** 37 * The instance is finalizer reachable, but is neither strongly nor softly 38 * reachable. 39 */ 40 FINALIZER("finalizer"), 41 42 /** 43 * The instance is weakly reachable. 44 */ 45 WEAK("weak"), 46 47 /** 48 * The instance is phantom reachable. 49 */ 50 PHANTOM("phantom"), 51 52 /** 53 * The instance is unreachable. 54 */ 55 UNREACHABLE("unreachable"); 56 57 /** 58 * The name of the reachibility. 59 */ 60 private final String name; 61 Reachability(String name)62 Reachability(String name) { 63 this.name = name; 64 } 65 66 @Override toString()67 public String toString() { 68 return name; 69 } 70 71 /** 72 * Returns true if this reachability is the same or stronger than the 73 * <code>other</code> reachability. 74 * 75 * @param other the other reachability to compare this against 76 * @return true if this reachability is not weaker than <code>other</code> 77 */ notWeakerThan(Reachability other)78 public boolean notWeakerThan(Reachability other) { 79 return ordinal() <= other.ordinal(); 80 } 81 } 82