comparison visualizer/Data/src/com/sun/hotspot/igv/data/InputMethod.java @ 4512:015fb895586b

Moved visualizer to new directory.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Tue, 07 Feb 2012 22:41:09 +0100
parents
children eca97d497f5d
comparison
equal deleted inserted replaced
4511:6cb549627941 4512:015fb895586b
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 */
24 package com.sun.hotspot.igv.data;
25
26 import java.util.ArrayList;
27 import java.util.Collections;
28 import java.util.List;
29
30 /**
31 *
32 * @author Thomas Wuerthinger
33 */
34 public class InputMethod extends Properties.Entity {
35
36 private String name;
37 private int bci;
38 private String shortName;
39 private List<InputMethod> inlined;
40 private InputMethod parentMethod;
41 private Group group;
42 private List<InputBytecode> bytecodes;
43
44 @Override
45 public int hashCode() {
46 int result = name.hashCode();
47 result = result * 31 + bci;
48 result = result * 31 + shortName.hashCode();
49 result = result * 31 + inlined.hashCode();
50 result = result * 31 + bytecodes.hashCode();
51 return result;
52 }
53
54 @Override
55 public boolean equals(Object o) {
56 if (o == null || (!(o instanceof InputMethod))) {
57 return false;
58 }
59
60 final InputMethod im = (InputMethod)o;
61 return name.equals(im.name) && bci == im.bci && shortName.equals(im.shortName) &&
62 inlined.equals(im.inlined) && bytecodes.equals(im.bytecodes);
63 }
64
65
66
67 /** Creates a new instance of InputMethod */
68 public InputMethod(Group parent, String name, String shortName, int bci) {
69 this.group = parent;
70 this.name = name;
71 this.bci = bci;
72 this.shortName = shortName;
73 inlined = new ArrayList<>();
74 bytecodes = new ArrayList<>();
75 }
76
77 public List<InputBytecode> getBytecodes() {
78 return Collections.unmodifiableList(bytecodes);
79 }
80
81 public List<InputMethod> getInlined() {
82 return Collections.unmodifiableList(inlined);
83 }
84
85 public void addInlined(InputMethod m) {
86
87 // assert bci unique
88 for (InputMethod m2 : inlined) {
89 assert m2.getBci() != m.getBci();
90 }
91
92 inlined.add(m);
93 assert m.parentMethod == null;
94 m.parentMethod = this;
95
96 for (InputBytecode bc : bytecodes) {
97 if (bc.getBci() == m.getBci()) {
98 bc.setInlined(m);
99 }
100 }
101 }
102
103 public Group getGroup() {
104 return group;
105 }
106
107 public String getShortName() {
108 return shortName;
109 }
110
111 public void setBytecodes(String text) {
112
113 String[] strings = text.split("\n");
114 int oldNumber = -1;
115 for (String s : strings) {
116
117 if (s.length() > 0 && Character.isDigit(s.charAt(0))) {
118 s = s.trim();
119 int spaceIndex = s.indexOf(' ');
120 String numberString = s.substring(0, spaceIndex);
121 String tmpName = s.substring(spaceIndex + 1, s.length());
122
123 int number = -1;
124 number = Integer.parseInt(numberString);
125
126 // assert correct order of bytecodes
127 assert number > oldNumber;
128
129 InputBytecode bc = new InputBytecode(number, tmpName);
130 bytecodes.add(bc);
131
132 for (InputMethod m : inlined) {
133 if (m.getBci() == number) {
134 bc.setInlined(m);
135 break;
136 }
137 }
138 }
139 }
140 }
141
142 public String getName() {
143 return name;
144 }
145
146 public int getBci() {
147 return bci;
148 }
149 }