comparison agent/src/share/classes/sun/jvm/hotspot/interpreter/BytecodeTableswitch.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.utilities.*;
29
30 public class BytecodeTableswitch extends Bytecode {
31 BytecodeTableswitch(Method method, int bci) {
32 super(method, bci);
33 }
34
35
36 // Attributes
37 public int defaultOffset() { return javaSignedWordAt(alignedOffset(1 + 0*jintSize)); }
38 public int lowKey() { return javaSignedWordAt(alignedOffset(1 + 1*jintSize)); }
39 public int highKey() { return javaSignedWordAt(alignedOffset(1 + 2*jintSize)); }
40 public int length() { return highKey()-lowKey()+1; }
41 public int destOffsetAt(int i) {
42 int x2 = alignedOffset(1 + (3 + i)*jintSize);
43 int val = javaSignedWordAt(x2);
44 return javaSignedWordAt(alignedOffset(1 + (3 + i)*jintSize));
45 }
46
47 public void verify() {
48 if (Assert.ASSERTS_ENABLED) {
49 Assert.that(isValid(), "check tableswitch");
50 }
51 }
52
53 public boolean isValid() {
54 boolean result = javaCode() == Bytecodes._tableswitch;
55 if (result == false) return false;
56 int lo = lowKey();
57 int hi = highKey();
58 if (hi < lo) // incorrect hi/lo values in tableswitch
59 return false;
60
61 int i = hi - lo - 1 ;
62 while (i-- > 0) {
63 // no special check needed
64 }
65 return true;
66 }
67
68 public static BytecodeTableswitch at(Method method, int bci) {
69 BytecodeTableswitch b = new BytecodeTableswitch(method, bci);
70 if (Assert.ASSERTS_ENABLED) {
71 b.verify();
72 }
73 return b;
74 }
75
76 /** Like at, but returns null if the BCI is not at tableswitch */
77 public static BytecodeTableswitch atCheck(Method method, int bci) {
78 BytecodeTableswitch b = new BytecodeTableswitch(method, bci);
79 return (b.isValid() ? b : null);
80 }
81
82 public static BytecodeTableswitch at(BytecodeStream bcs) {
83 return new BytecodeTableswitch(bcs.method(), bcs.bci());
84 }
85
86 public String toString() {
87 StringBuffer buf = new StringBuffer();
88 buf.append("tableswitch");
89 buf.append(spaces);
90 buf.append("default: ");
91 buf.append(Integer.toString(bci() + defaultOffset()));
92 buf.append(comma);
93 int lo = lowKey();
94 int hi = highKey();
95 int i = hi - lo - 1 ;
96 while (i-- > 0) {
97 buf.append("case ");
98 buf.append(Integer.toString(lo + i));
99 buf.append(':');
100 buf.append(Integer.toString(bci() + destOffsetAt(i)));
101 buf.append(comma);
102 }
103 return buf.toString();
104 }
105 }