annotate agent/src/share/classes/sun/jvm/hotspot/interpreter/BytecodeStream.java @ 2177:3582bf76420e

6990754: Use native memory and reference counting to implement SymbolTable Summary: move symbols from permgen into C heap and reference count them Reviewed-by: never, acorn, jmasa, stefank
author coleenp
date Thu, 27 Jan 2011 16:11:27 -0800
parents c18cbe5936b8
children 6a991dcb52bb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
2 * Copyright (c) 2001, 2002, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 package sun.jvm.hotspot.interpreter;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import sun.jvm.hotspot.oops.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import sun.jvm.hotspot.runtime.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import sun.jvm.hotspot.utilities.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30
a61af66fc99e Initial load
duke
parents:
diff changeset
31 public class BytecodeStream {
a61af66fc99e Initial load
duke
parents:
diff changeset
32 private Method _method;
a61af66fc99e Initial load
duke
parents:
diff changeset
33
a61af66fc99e Initial load
duke
parents:
diff changeset
34 // reading position
a61af66fc99e Initial load
duke
parents:
diff changeset
35 private int _bci; // bci if current bytecode
a61af66fc99e Initial load
duke
parents:
diff changeset
36 private int _next_bci; // bci of next bytecode
a61af66fc99e Initial load
duke
parents:
diff changeset
37 private int _end_bci; // bci after the current iteration interval
a61af66fc99e Initial load
duke
parents:
diff changeset
38
a61af66fc99e Initial load
duke
parents:
diff changeset
39 // last bytecode read
a61af66fc99e Initial load
duke
parents:
diff changeset
40 private int _code;
a61af66fc99e Initial load
duke
parents:
diff changeset
41 private boolean _is_wide;
a61af66fc99e Initial load
duke
parents:
diff changeset
42
a61af66fc99e Initial load
duke
parents:
diff changeset
43 // Construction
a61af66fc99e Initial load
duke
parents:
diff changeset
44 public BytecodeStream(Method method) {
a61af66fc99e Initial load
duke
parents:
diff changeset
45 _method = method;
a61af66fc99e Initial load
duke
parents:
diff changeset
46 setInterval(0, (int) method.getCodeSize());
a61af66fc99e Initial load
duke
parents:
diff changeset
47 }
a61af66fc99e Initial load
duke
parents:
diff changeset
48
a61af66fc99e Initial load
duke
parents:
diff changeset
49 // Iteration control
a61af66fc99e Initial load
duke
parents:
diff changeset
50 public void setInterval(int beg_bci, int end_bci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
51 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
52 Assert.that(0 <= beg_bci && beg_bci <= _method.getCodeSize(), "illegal beg_bci");
a61af66fc99e Initial load
duke
parents:
diff changeset
53 Assert.that(0 <= end_bci && end_bci <= _method.getCodeSize(), "illegal end_bci");
a61af66fc99e Initial load
duke
parents:
diff changeset
54 }
a61af66fc99e Initial load
duke
parents:
diff changeset
55 // setup of iteration pointers
a61af66fc99e Initial load
duke
parents:
diff changeset
56 _bci = beg_bci;
a61af66fc99e Initial load
duke
parents:
diff changeset
57 _next_bci = beg_bci;
a61af66fc99e Initial load
duke
parents:
diff changeset
58 _end_bci = end_bci;
a61af66fc99e Initial load
duke
parents:
diff changeset
59 }
a61af66fc99e Initial load
duke
parents:
diff changeset
60
a61af66fc99e Initial load
duke
parents:
diff changeset
61 public void setStart(int beg_bci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
62 setInterval(beg_bci, (int) _method.getCodeSize());
a61af66fc99e Initial load
duke
parents:
diff changeset
63 }
a61af66fc99e Initial load
duke
parents:
diff changeset
64
a61af66fc99e Initial load
duke
parents:
diff changeset
65 // Iteration
a61af66fc99e Initial load
duke
parents:
diff changeset
66 public int next() {
a61af66fc99e Initial load
duke
parents:
diff changeset
67 int code;
a61af66fc99e Initial load
duke
parents:
diff changeset
68 // set reading position
a61af66fc99e Initial load
duke
parents:
diff changeset
69 _bci = _next_bci;
a61af66fc99e Initial load
duke
parents:
diff changeset
70 if (isLastBytecode()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
71 // indicate end of bytecode stream
a61af66fc99e Initial load
duke
parents:
diff changeset
72 code = Bytecodes._illegal;
a61af66fc99e Initial load
duke
parents:
diff changeset
73 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
74 // get bytecode
a61af66fc99e Initial load
duke
parents:
diff changeset
75 int rawCode = Bytecodes.codeAt(_method, _bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
76 code = 0; // Make javac happy
a61af66fc99e Initial load
duke
parents:
diff changeset
77 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
78 code = Bytecodes.javaCode(rawCode);
a61af66fc99e Initial load
duke
parents:
diff changeset
79 } catch (AssertionFailure e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
80 e.printStackTrace();
a61af66fc99e Initial load
duke
parents:
diff changeset
81 Assert.that(false, "Failure occurred at bci " + _bci + " in method " + _method.externalNameAndSignature());
a61af66fc99e Initial load
duke
parents:
diff changeset
82 }
a61af66fc99e Initial load
duke
parents:
diff changeset
83
a61af66fc99e Initial load
duke
parents:
diff changeset
84 // set next bytecode position
a61af66fc99e Initial load
duke
parents:
diff changeset
85 //
a61af66fc99e Initial load
duke
parents:
diff changeset
86 int l = Bytecodes.lengthFor(code);
a61af66fc99e Initial load
duke
parents:
diff changeset
87 if (l == 0) l = Bytecodes.lengthAt(_method, _bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
88 _next_bci += l;
a61af66fc99e Initial load
duke
parents:
diff changeset
89 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
90 Assert.that(_bci < _next_bci, "length must be > 0");
a61af66fc99e Initial load
duke
parents:
diff changeset
91 }
a61af66fc99e Initial load
duke
parents:
diff changeset
92 // set attributes
a61af66fc99e Initial load
duke
parents:
diff changeset
93 _is_wide = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
94 // check for special (uncommon) cases
a61af66fc99e Initial load
duke
parents:
diff changeset
95 if (code == Bytecodes._wide) {
a61af66fc99e Initial load
duke
parents:
diff changeset
96 code = _method.getBytecodeOrBPAt(_bci + 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
97 _is_wide = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
98 }
a61af66fc99e Initial load
duke
parents:
diff changeset
99 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
100 Assert.that(Bytecodes.isJavaCode(code), "sanity check");
a61af66fc99e Initial load
duke
parents:
diff changeset
101 }
a61af66fc99e Initial load
duke
parents:
diff changeset
102 }
a61af66fc99e Initial load
duke
parents:
diff changeset
103 _code = code;
a61af66fc99e Initial load
duke
parents:
diff changeset
104 return _code;
a61af66fc99e Initial load
duke
parents:
diff changeset
105 }
a61af66fc99e Initial load
duke
parents:
diff changeset
106
a61af66fc99e Initial load
duke
parents:
diff changeset
107 // Stream attributes
a61af66fc99e Initial load
duke
parents:
diff changeset
108 public Method method() { return _method; }
a61af66fc99e Initial load
duke
parents:
diff changeset
109 public int bci() { return _bci; }
a61af66fc99e Initial load
duke
parents:
diff changeset
110 public int nextBCI() { return _next_bci; }
a61af66fc99e Initial load
duke
parents:
diff changeset
111 public int endBCI() { return _end_bci; }
a61af66fc99e Initial load
duke
parents:
diff changeset
112 public int code() { return _code; }
a61af66fc99e Initial load
duke
parents:
diff changeset
113 public boolean isWide() { return _is_wide; }
a61af66fc99e Initial load
duke
parents:
diff changeset
114 public boolean isActiveBreakpoint() { return Bytecodes.isActiveBreakpointAt(_method, _bci); }
a61af66fc99e Initial load
duke
parents:
diff changeset
115 public boolean isLastBytecode() { return _next_bci >= _end_bci; }
a61af66fc99e Initial load
duke
parents:
diff changeset
116
a61af66fc99e Initial load
duke
parents:
diff changeset
117 // State changes
a61af66fc99e Initial load
duke
parents:
diff changeset
118 public void setNextBCI(int bci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
119 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
120 Assert.that(0 <= bci && bci <= _method.getCodeSize(), "illegal bci");
a61af66fc99e Initial load
duke
parents:
diff changeset
121 }
a61af66fc99e Initial load
duke
parents:
diff changeset
122 _next_bci = bci;
a61af66fc99e Initial load
duke
parents:
diff changeset
123 }
a61af66fc99e Initial load
duke
parents:
diff changeset
124
a61af66fc99e Initial load
duke
parents:
diff changeset
125 // Bytecode-specific attributes
a61af66fc99e Initial load
duke
parents:
diff changeset
126 public int dest() { return bci() + _method.getBytecodeShortArg(bci() + 1); }
a61af66fc99e Initial load
duke
parents:
diff changeset
127 public int dest_w() { return bci() + _method.getBytecodeIntArg(bci() + 1); }
a61af66fc99e Initial load
duke
parents:
diff changeset
128
a61af66fc99e Initial load
duke
parents:
diff changeset
129 // Unsigned indices, widening
a61af66fc99e Initial load
duke
parents:
diff changeset
130 public int getIndex() { return (isWide())
a61af66fc99e Initial load
duke
parents:
diff changeset
131 ? (_method.getBytecodeShortArg(bci() + 2) & 0xFFFF)
a61af66fc99e Initial load
duke
parents:
diff changeset
132 : (_method.getBytecodeOrBPAt(bci() + 1) & 0xFF); }
a61af66fc99e Initial load
duke
parents:
diff changeset
133 public int getIndexBig() { return _method.getBytecodeShortArg(bci() + 1); }
a61af66fc99e Initial load
duke
parents:
diff changeset
134
a61af66fc99e Initial load
duke
parents:
diff changeset
135 // Fetch at absolute BCI (for manual parsing of certain bytecodes)
a61af66fc99e Initial load
duke
parents:
diff changeset
136 public int codeAt(int bci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
137 return _method.getBytecodeOrBPAt(bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
138 }
a61af66fc99e Initial load
duke
parents:
diff changeset
139 }