comparison agent/src/share/classes/sun/jvm/hotspot/interpreter/BytecodeLookupswitch.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 BytecodeLookupswitch extends Bytecode {
31 BytecodeLookupswitch(Method method, int bci) {
32 super(method, bci);
33 }
34
35 // Attributes
36 public int defaultOffset() { return javaSignedWordAt(alignedOffset(1 + 0*jintSize)); }
37 public int numberOfPairs() { return javaSignedWordAt(alignedOffset(1 + 1*jintSize)); }
38 public LookupswitchPair pairAt(int i) {
39 if (Assert.ASSERTS_ENABLED) {
40 Assert.that(0 <= i && i < numberOfPairs(), "pair index out of bounds");
41 }
42 return new LookupswitchPair(method, bci + alignedOffset(1 + (1 + i)*2*jintSize));
43 }
44
45 public void verify() {
46 if (Assert.ASSERTS_ENABLED) {
47 Assert.that(isValid(), "check lookupswitch");
48 }
49 }
50
51 public boolean isValid() {
52 boolean result = javaCode() == Bytecodes._lookupswitch;
53 if (result == false) return false;
54 int i = numberOfPairs() - 1;
55 while (i-- > 0) {
56 if(pairAt(i).match() > pairAt(i+1).match())
57 return false; // unsorted lookup table
58 }
59 return true;
60 }
61
62 public static BytecodeLookupswitch at(Method method, int bci) {
63 BytecodeLookupswitch b = new BytecodeLookupswitch(method, bci);
64 if (Assert.ASSERTS_ENABLED) {
65 b.verify();
66 }
67 return b;
68 }
69
70 /** Like at, but returns null if the BCI is not at lookupswitch */
71 public static BytecodeLookupswitch atCheck(Method method, int bci) {
72 BytecodeLookupswitch b = new BytecodeLookupswitch(method, bci);
73 return (b.isValid() ? b : null);
74 }
75
76 public static BytecodeLookupswitch at(BytecodeStream bcs) {
77 return new BytecodeLookupswitch(bcs.method(), bcs.bci());
78 }
79
80 public String toString() {
81 StringBuffer buf = new StringBuffer();
82 buf.append("lookupswitch");
83 buf.append(spaces);
84 buf.append("default: ");
85 buf.append(Integer.toString(bci() + defaultOffset()));
86 buf.append(comma);
87 int i = numberOfPairs() - 1;
88 while (i-- > 0) {
89 LookupswitchPair pair = pairAt(i);
90 buf.append("case ");
91 buf.append(Integer.toString(pair.match()));
92 buf.append(':');
93 buf.append(Integer.toString(bci() + pair.offset()));
94 buf.append(comma);
95 }
96
97 return buf.toString();
98 }
99 }