1/*
2 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24package gc.g1.humongousObjects.objectGraphTest;
25
26import java.lang.ref.Reference;
27
28/**
29 * Immutable structure that holds the following information about graph's node
30 * reference - weak/soft reference to graph's node
31 * graphId and nodeId - graph's and node's ids - we need this for error handling
32 * softlyReachable - is node effectively referenced by external soft reference. It could be when external
33 * soft reference or when this node is reachable from node that externally referenced by soft reference
34 * effectiveHumongous - if node behaves effectively humongous.  It could be when node is humongous
35 * or when this node is reachable from humongous node.
36 *
37 * @param <T> - actual type of node
38 */
39public class ReferenceInfo<T> {
40    public final Reference<T> reference;
41    public final String graphId;
42    public final String nodeId;
43    public final boolean softlyReachable;
44    public final boolean effectiveHumongous;
45
46    public ReferenceInfo(Reference<T> reference, String graphId, String nodeId, boolean softlyReachable,
47                         boolean effectiveHumongous) {
48        this.reference = reference;
49        this.graphId = graphId;
50        this.nodeId = nodeId;
51        this.softlyReachable = softlyReachable;
52        this.effectiveHumongous = effectiveHumongous;
53    }
54
55    @Override
56    public String toString() {
57        return String.format("Node %s is effectively %shumongous and effectively %ssoft referenced\n"
58                        + "\tReference type is %s and it points to %s", nodeId,
59                (effectiveHumongous ? "" : "non-"), (softlyReachable ? "" : "non-"),
60                reference.getClass().getSimpleName(), reference.get());
61    }
62}
63