MethodNode.java revision 1472:c18cbe5936b8
1/*
2 * Copyright (c) 2008, 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 com.sun.hotspot.igv.bytecodes;
25
26import com.sun.hotspot.igv.data.InputBytecode;
27import com.sun.hotspot.igv.data.InputGraph;
28import com.sun.hotspot.igv.data.InputMethod;
29import java.awt.Image;
30import org.openide.nodes.AbstractNode;
31import org.openide.nodes.Children;
32import org.openide.nodes.Node;
33import org.openide.util.Utilities;
34
35/**
36 *
37 * @author Thomas Wuerthinger
38 */
39public class MethodNode extends AbstractNode {
40
41    private static class MethodNodeChildren extends Children.Keys {
42
43        private InputMethod method;
44        private InputGraph graph;
45        private String bciString;
46
47        public MethodNodeChildren(InputMethod method, InputGraph graph, String bciString) {
48            this.method = method;
49            this.bciString = bciString;
50            this.graph = graph;
51        }
52
53        protected Node[] createNodes(Object object) {
54            assert object instanceof InputBytecode;
55            InputBytecode bc = (InputBytecode) object;
56            if (bc.getInlined() == null) {
57                return new Node[]{new BytecodeNode(bc, graph, bciString)};
58            } else {
59                return new Node[]{new BytecodeNode(bc, graph, bciString), new MethodNode(bc.getInlined(), graph, bc.getBci() + " " + bciString)};
60            }
61        }
62
63        @Override
64        public void addNotify() {
65            if (method != null) {
66                setKeys(method.getBytecodes());
67            }
68        }
69
70        public void setMethod(InputMethod method, InputGraph graph) {
71            this.method = method;
72            this.graph = graph;
73            addNotify();
74        }
75    }
76
77    /** Creates a new instance of MethodNode */
78    public MethodNode(InputMethod method, InputGraph graph, String bciString) {
79        super((method != null && method.getBytecodes().size() == 0) ? Children.LEAF : new MethodNodeChildren(method, graph, bciString));
80        if (method != null) {
81            this.setDisplayName(method.getName());
82        }
83    }
84
85    @Override
86    public Image getIcon(int i) {
87        return Utilities.loadImage("com/sun/hotspot/igv/bytecodes/images/method.gif");
88    }
89
90    @Override
91    public Image getOpenedIcon(int i) {
92        return getIcon(i);
93    }
94
95    public void update(InputGraph graph, InputMethod method) {
96        ((MethodNodeChildren) this.getChildren()).setMethod(method, graph);
97        if (method != null) {
98            this.setDisplayName(method.getName());
99        }
100
101    }
102}
103