Mercurial > hg > truffle
comparison agent/src/share/classes/sun/jvm/hotspot/interpreter/BytecodeInvoke.java @ 0:a61af66fc99e jdk7-b24
Initial load
author | duke |
---|---|
date | Sat, 01 Dec 2007 00:00:00 +0000 |
parents | |
children | c18cbe5936b8 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:a61af66fc99e |
---|---|
1 /* | |
2 * Copyright 2001-2003 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
20 * CA 95054 USA or visit www.sun.com if you need additional information or | |
21 * have any questions. | |
22 * | |
23 */ | |
24 | |
25 package sun.jvm.hotspot.interpreter; | |
26 | |
27 import sun.jvm.hotspot.oops.*; | |
28 import sun.jvm.hotspot.runtime.*; | |
29 import sun.jvm.hotspot.utilities.*; | |
30 | |
31 public class BytecodeInvoke extends BytecodeWithCPIndex { | |
32 BytecodeInvoke(Method method, int bci) { | |
33 super(method, bci); | |
34 } | |
35 | |
36 public static BytecodeInvoke at(Method method, int bci) { | |
37 BytecodeInvoke b = new BytecodeInvoke(method, bci); | |
38 if (Assert.ASSERTS_ENABLED) { | |
39 b.verify(); | |
40 } | |
41 return b; | |
42 } | |
43 | |
44 /** Like at, but returns null if the BCI is not at an invoke */ | |
45 public static BytecodeInvoke atCheck(Method method, int bci) { | |
46 BytecodeInvoke b = new BytecodeInvoke(method, bci); | |
47 return (b.isValid() ? b : null); | |
48 } | |
49 | |
50 public static BytecodeInvoke at(BytecodeStream bcs) { | |
51 return new BytecodeInvoke(bcs.method(), bcs.bci()); | |
52 } | |
53 | |
54 // returns the name of the invoked method | |
55 public Symbol name() { | |
56 ConstantPool cp = method().getConstants(); | |
57 return cp.getNameRefAt(index()); | |
58 } | |
59 | |
60 // returns the signature of the invoked method | |
61 public Symbol signature() { | |
62 ConstantPool cp = method().getConstants(); | |
63 return cp.getSignatureRefAt(index()); | |
64 } | |
65 | |
66 public Method getInvokedMethod() { | |
67 return method().getConstants().getMethodRefAt(index()); | |
68 } | |
69 | |
70 // returns the result type (see BasicType.java) of the invoke | |
71 public int resultType() { | |
72 ResultTypeFinder rts = new ResultTypeFinder(signature()); | |
73 rts.iterate(); | |
74 return rts.type(); | |
75 } | |
76 | |
77 public int adjustedInvokeCode() { | |
78 return javaCode(); | |
79 } | |
80 | |
81 // "specified" method (from constant pool) | |
82 // FIXME: elided for now | |
83 // public Method staticTarget(); | |
84 | |
85 // Testers | |
86 public boolean isInvokeinterface() { return adjustedInvokeCode() == Bytecodes._invokeinterface; } | |
87 public boolean isInvokevirtual() { return adjustedInvokeCode() == Bytecodes._invokevirtual; } | |
88 public boolean isInvokestatic() { return adjustedInvokeCode() == Bytecodes._invokestatic; } | |
89 public boolean isInvokespecial() { return adjustedInvokeCode() == Bytecodes._invokespecial; } | |
90 | |
91 public boolean isValid() { return isInvokeinterface() || | |
92 isInvokevirtual() || | |
93 isInvokestatic() || | |
94 isInvokespecial(); } | |
95 public void verify() { | |
96 if (Assert.ASSERTS_ENABLED) { | |
97 Assert.that(isValid(), "check invoke"); | |
98 } | |
99 } | |
100 | |
101 public String toString() { | |
102 StringBuffer buf = new StringBuffer(); | |
103 buf.append(getJavaBytecodeName()); | |
104 buf.append(spaces); | |
105 buf.append('#'); | |
106 buf.append(Integer.toString(indexForFieldOrMethod())); | |
107 buf.append(" [Method "); | |
108 StringBuffer sigBuf = new StringBuffer(); | |
109 new SignatureConverter(signature(), sigBuf).iterateReturntype(); | |
110 buf.append(sigBuf.toString().replace('/', '.')); | |
111 buf.append(spaces); | |
112 buf.append(name().asString()); | |
113 buf.append('('); | |
114 sigBuf = new StringBuffer(); | |
115 new SignatureConverter(signature(), sigBuf).iterateParameters(); | |
116 buf.append(sigBuf.toString().replace('/', '.')); | |
117 buf.append(')'); | |
118 buf.append(']'); | |
119 if (code() != javaCode()) { | |
120 buf.append(spaces); | |
121 buf.append('['); | |
122 buf.append(getBytecodeName()); | |
123 buf.append(']'); | |
124 } | |
125 return buf.toString(); | |
126 } | |
127 } |