annotate src/share/vm/ci/ciStreams.hpp @ 6725:da91efe96a93

6964458: Reimplement class meta-data storage to use native memory Summary: Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland Contributed-by: jmasa <jon.masamitsu@oracle.com>, stefank <stefan.karlsson@oracle.com>, mgerdin <mikael.gerdin@oracle.com>, never <tom.rodriguez@oracle.com>
author coleenp
date Sat, 01 Sep 2012 13:25:18 -0400
parents 7f813940ac35
children f6b0eb4e44cf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6634
diff changeset
2 * Copyright (c) 1999, 2012, 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: 1138
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1138
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: 1138
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
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1602
diff changeset
25 #ifndef SHARE_VM_CI_CISTREAMS_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1602
diff changeset
26 #define SHARE_VM_CI_CISTREAMS_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1602
diff changeset
27
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1602
diff changeset
28 #include "ci/ciClassList.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1602
diff changeset
29 #include "ci/ciExceptionHandler.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1602
diff changeset
30 #include "ci/ciInstanceKlass.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1602
diff changeset
31 #include "ci/ciMethod.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1602
diff changeset
32 #include "interpreter/bytecode.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1602
diff changeset
33
0
a61af66fc99e Initial load
duke
parents:
diff changeset
34 // ciBytecodeStream
a61af66fc99e Initial load
duke
parents:
diff changeset
35 //
a61af66fc99e Initial load
duke
parents:
diff changeset
36 // The class is used to iterate over the bytecodes of a method.
a61af66fc99e Initial load
duke
parents:
diff changeset
37 // It hides the details of constant pool structure/access by
a61af66fc99e Initial load
duke
parents:
diff changeset
38 // providing accessors for constant pool items. It returns only pure
a61af66fc99e Initial load
duke
parents:
diff changeset
39 // Java bytecodes; VM-internal _fast bytecodes are translated back to
a61af66fc99e Initial load
duke
parents:
diff changeset
40 // their original form during iteration.
a61af66fc99e Initial load
duke
parents:
diff changeset
41 class ciBytecodeStream : StackObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
42 private:
1565
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
43 // Handling for the weird bytecodes
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
44 Bytecodes::Code next_wide_or_table(Bytecodes::Code); // Handle _wide & complicated inline table
0
a61af66fc99e Initial load
duke
parents:
diff changeset
45
a61af66fc99e Initial load
duke
parents:
diff changeset
46 static Bytecodes::Code check_java(Bytecodes::Code c) {
a61af66fc99e Initial load
duke
parents:
diff changeset
47 assert(Bytecodes::is_java_code(c), "should not return _fast bytecodes");
a61af66fc99e Initial load
duke
parents:
diff changeset
48 return c;
a61af66fc99e Initial load
duke
parents:
diff changeset
49 }
a61af66fc99e Initial load
duke
parents:
diff changeset
50
1565
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
51 static Bytecodes::Code check_defined(Bytecodes::Code c) {
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
52 assert(Bytecodes::is_defined(c), "");
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
53 return c;
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
54 }
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
55
0
a61af66fc99e Initial load
duke
parents:
diff changeset
56 ciMethod* _method; // the method
a61af66fc99e Initial load
duke
parents:
diff changeset
57 ciInstanceKlass* _holder;
a61af66fc99e Initial load
duke
parents:
diff changeset
58 address _bc_start; // Start of current bytecode for table
a61af66fc99e Initial load
duke
parents:
diff changeset
59 address _was_wide; // Address past last wide bytecode
a61af66fc99e Initial load
duke
parents:
diff changeset
60 jint* _table_base; // Aligned start of last table or switch
a61af66fc99e Initial load
duke
parents:
diff changeset
61
a61af66fc99e Initial load
duke
parents:
diff changeset
62 address _start; // Start of bytecodes
a61af66fc99e Initial load
duke
parents:
diff changeset
63 address _end; // Past end of bytecodes
a61af66fc99e Initial load
duke
parents:
diff changeset
64 address _pc; // Current PC
a61af66fc99e Initial load
duke
parents:
diff changeset
65 Bytecodes::Code _bc; // Current bytecode
1565
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
66 Bytecodes::Code _raw_bc; // Current bytecode, raw form
0
a61af66fc99e Initial load
duke
parents:
diff changeset
67
a61af66fc99e Initial load
duke
parents:
diff changeset
68 void reset( address base, unsigned int size ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
69 _bc_start =_was_wide = 0;
1602
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
70 _start = _pc = base; _end = base + size;
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
71 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
72
1565
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
73 void assert_wide(bool require_wide) const {
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
74 if (require_wide)
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
75 { assert(is_wide(), "must be a wide instruction"); }
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
76 else { assert(!is_wide(), "must not be a wide instruction"); }
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
77 }
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
78
2142
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
79 Bytecode bytecode() const { return Bytecode(this, _bc_start); }
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
80 Bytecode next_bytecode() const { return Bytecode(this, _pc); }
1565
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
81
0
a61af66fc99e Initial load
duke
parents:
diff changeset
82 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
83 // End-Of-Bytecodes
a61af66fc99e Initial load
duke
parents:
diff changeset
84 static Bytecodes::Code EOBC() {
a61af66fc99e Initial load
duke
parents:
diff changeset
85 return Bytecodes::_illegal;
a61af66fc99e Initial load
duke
parents:
diff changeset
86 }
a61af66fc99e Initial load
duke
parents:
diff changeset
87
a61af66fc99e Initial load
duke
parents:
diff changeset
88 ciBytecodeStream(ciMethod* m) {
a61af66fc99e Initial load
duke
parents:
diff changeset
89 reset_to_method(m);
a61af66fc99e Initial load
duke
parents:
diff changeset
90 }
a61af66fc99e Initial load
duke
parents:
diff changeset
91
a61af66fc99e Initial load
duke
parents:
diff changeset
92 ciBytecodeStream() {
a61af66fc99e Initial load
duke
parents:
diff changeset
93 reset_to_method(NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
94 }
a61af66fc99e Initial load
duke
parents:
diff changeset
95
a61af66fc99e Initial load
duke
parents:
diff changeset
96 ciMethod* method() const { return _method; }
a61af66fc99e Initial load
duke
parents:
diff changeset
97
a61af66fc99e Initial load
duke
parents:
diff changeset
98 void reset_to_method(ciMethod* m) {
a61af66fc99e Initial load
duke
parents:
diff changeset
99 _method = m;
a61af66fc99e Initial load
duke
parents:
diff changeset
100 if (m == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
101 _holder = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
102 reset(NULL, 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
103 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
104 _holder = m->holder();
a61af66fc99e Initial load
duke
parents:
diff changeset
105 reset(m->code(), m->code_size());
a61af66fc99e Initial load
duke
parents:
diff changeset
106 }
a61af66fc99e Initial load
duke
parents:
diff changeset
107 }
a61af66fc99e Initial load
duke
parents:
diff changeset
108
a61af66fc99e Initial load
duke
parents:
diff changeset
109 void reset_to_bci( int bci );
a61af66fc99e Initial load
duke
parents:
diff changeset
110
a61af66fc99e Initial load
duke
parents:
diff changeset
111 // Force the iterator to report a certain bci.
a61af66fc99e Initial load
duke
parents:
diff changeset
112 void force_bci(int bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
113
a61af66fc99e Initial load
duke
parents:
diff changeset
114 void set_max_bci( int max ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
115 _end = _start + max;
a61af66fc99e Initial load
duke
parents:
diff changeset
116 }
a61af66fc99e Initial load
duke
parents:
diff changeset
117
726
be93aad57795 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 0
diff changeset
118 address cur_bcp() const { return _bc_start; } // Returns bcp to current instruction
1565
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
119 int next_bci() const { return _pc - _start; }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
120 int cur_bci() const { return _bc_start - _start; }
726
be93aad57795 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 0
diff changeset
121 int instruction_size() const { return _pc - _bc_start; }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
122
a61af66fc99e Initial load
duke
parents:
diff changeset
123 Bytecodes::Code cur_bc() const{ return check_java(_bc); }
1565
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
124 Bytecodes::Code cur_bc_raw() const { return check_defined(_raw_bc); }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
125 Bytecodes::Code next_bc() { return Bytecodes::java_code((Bytecodes::Code)* _pc); }
a61af66fc99e Initial load
duke
parents:
diff changeset
126
a61af66fc99e Initial load
duke
parents:
diff changeset
127 // Return current ByteCode and increment PC to next bytecode, skipping all
a61af66fc99e Initial load
duke
parents:
diff changeset
128 // intermediate constants. Returns EOBC at end.
a61af66fc99e Initial load
duke
parents:
diff changeset
129 // Expected usage:
3897
de847cac9235 7078382: JSR 292: don't count method handle adapters against inlining budgets
twisti
parents: 2142
diff changeset
130 // ciBytecodeStream iter(m);
de847cac9235 7078382: JSR 292: don't count method handle adapters against inlining budgets
twisti
parents: 2142
diff changeset
131 // while (iter.next() != ciBytecodeStream::EOBC()) { ... }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
132 Bytecodes::Code next() {
a61af66fc99e Initial load
duke
parents:
diff changeset
133 _bc_start = _pc; // Capture start of bc
a61af66fc99e Initial load
duke
parents:
diff changeset
134 if( _pc >= _end ) return EOBC(); // End-Of-Bytecodes
a61af66fc99e Initial load
duke
parents:
diff changeset
135
a61af66fc99e Initial load
duke
parents:
diff changeset
136 // Fetch Java bytecode
a61af66fc99e Initial load
duke
parents:
diff changeset
137 // All rewritten bytecodes maintain the size of original bytecode.
1565
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
138 _bc = Bytecodes::java_code(_raw_bc = (Bytecodes::Code)*_pc);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
139 int csize = Bytecodes::length_for(_bc); // Expected size
1565
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
140 _pc += csize; // Bump PC past bytecode
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
141 if (csize == 0) {
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
142 _bc = next_wide_or_table(_bc);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
143 }
a61af66fc99e Initial load
duke
parents:
diff changeset
144 return check_java(_bc);
a61af66fc99e Initial load
duke
parents:
diff changeset
145 }
a61af66fc99e Initial load
duke
parents:
diff changeset
146
726
be93aad57795 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 0
diff changeset
147 bool is_wide() const { return ( _pc == _was_wide ); }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
148
1565
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
149 // Does this instruction contain an index which refes into the CP cache?
1602
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
150 bool has_cache_index() const { return Bytecodes::uses_cp_cache(cur_bc_raw()); }
1565
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
151
6634
7f813940ac35 7192406: JSR 292: C2 needs exact return type information for invokedynamic and invokehandle call sites
twisti
parents: 6266
diff changeset
152 bool has_optional_appendix() { return Bytecodes::has_optional_appendix(cur_bc_raw()); }
7f813940ac35 7192406: JSR 292: C2 needs exact return type information for invokedynamic and invokehandle call sites
twisti
parents: 6266
diff changeset
153
1565
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
154 int get_index_u1() const {
2142
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
155 return bytecode().get_index_u1(cur_bc_raw());
1565
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
156 }
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
157
1602
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
158 int get_index_u1_cpcache() const {
2142
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
159 return bytecode().get_index_u1_cpcache(cur_bc_raw());
1602
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
160 }
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
161
0
a61af66fc99e Initial load
duke
parents:
diff changeset
162 // Get a byte index following this bytecode.
a61af66fc99e Initial load
duke
parents:
diff changeset
163 // If prefixed with a wide bytecode, get a wide index.
a61af66fc99e Initial load
duke
parents:
diff changeset
164 int get_index() const {
1602
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
165 assert(!has_cache_index(), "else use cpcache variant");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
166 return (_pc == _was_wide) // was widened?
1565
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
167 ? get_index_u2(true) // yes, return wide index
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
168 : get_index_u1(); // no, return narrow index
0
a61af66fc99e Initial load
duke
parents:
diff changeset
169 }
a61af66fc99e Initial load
duke
parents:
diff changeset
170
1565
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
171 // Get 2-byte index (byte swapping depending on which bytecode)
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
172 int get_index_u2(bool is_wide = false) const {
2142
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
173 return bytecode().get_index_u2(cur_bc_raw(), is_wide);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
174 }
a61af66fc99e Initial load
duke
parents:
diff changeset
175
1565
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
176 // Get 2-byte index in native byte order. (Rewriter::rewrite makes these.)
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
177 int get_index_u2_cpcache() const {
2142
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
178 return bytecode().get_index_u2_cpcache(cur_bc_raw());
726
be93aad57795 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 0
diff changeset
179 }
be93aad57795 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 0
diff changeset
180
be93aad57795 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 0
diff changeset
181 // Get 4-byte index, for invokedynamic.
1565
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
182 int get_index_u4() const {
2142
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
183 return bytecode().get_index_u4(cur_bc_raw());
726
be93aad57795 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 0
diff changeset
184 }
be93aad57795 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 0
diff changeset
185
1565
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
186 bool has_index_u4() const {
2142
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
187 return bytecode().has_index_u4(cur_bc_raw());
1565
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
188 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
189
a61af66fc99e Initial load
duke
parents:
diff changeset
190 // Get dimensions byte (multinewarray)
a61af66fc99e Initial load
duke
parents:
diff changeset
191 int get_dimensions() const { return *(unsigned char*)(_pc-1); }
a61af66fc99e Initial load
duke
parents:
diff changeset
192
a61af66fc99e Initial load
duke
parents:
diff changeset
193 // Sign-extended index byte/short, no widening
2142
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
194 int get_constant_u1() const { return bytecode().get_constant_u1(instruction_size()-1, cur_bc_raw()); }
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
195 int get_constant_u2(bool is_wide = false) const { return bytecode().get_constant_u2(instruction_size()-2, cur_bc_raw(), is_wide); }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
196
a61af66fc99e Initial load
duke
parents:
diff changeset
197 // Get a byte signed constant for "iinc". Invalid for other bytecodes.
a61af66fc99e Initial load
duke
parents:
diff changeset
198 // If prefixed with a wide bytecode, get a wide constant
1565
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
199 int get_iinc_con() const {return (_pc==_was_wide) ? (jshort) get_constant_u2(true) : (jbyte) get_constant_u1();}
0
a61af66fc99e Initial load
duke
parents:
diff changeset
200
a61af66fc99e Initial load
duke
parents:
diff changeset
201 // 2-byte branch offset from current pc
1565
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
202 int get_dest() const {
2142
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
203 return cur_bci() + bytecode().get_offset_s2(cur_bc_raw());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
204 }
a61af66fc99e Initial load
duke
parents:
diff changeset
205
a61af66fc99e Initial load
duke
parents:
diff changeset
206 // 2-byte branch offset from next pc
1565
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
207 int next_get_dest() const {
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
208 assert(_pc < _end, "");
2142
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
209 return next_bci() + next_bytecode().get_offset_s2(Bytecodes::_ifeq);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
210 }
a61af66fc99e Initial load
duke
parents:
diff changeset
211
a61af66fc99e Initial load
duke
parents:
diff changeset
212 // 4-byte branch offset from current pc
1565
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
213 int get_far_dest() const {
2142
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
214 return cur_bci() + bytecode().get_offset_s4(cur_bc_raw());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
215 }
a61af66fc99e Initial load
duke
parents:
diff changeset
216
a61af66fc99e Initial load
duke
parents:
diff changeset
217 // For a lookup or switch table, return target destination
a61af66fc99e Initial load
duke
parents:
diff changeset
218 int get_int_table( int index ) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
219 return Bytes::get_Java_u4((address)&_table_base[index]); }
a61af66fc99e Initial load
duke
parents:
diff changeset
220
a61af66fc99e Initial load
duke
parents:
diff changeset
221 // For tableswitch - get length of offset part
a61af66fc99e Initial load
duke
parents:
diff changeset
222 int get_tableswitch_length() { return get_int_table(2)-get_int_table(1)+1; }
a61af66fc99e Initial load
duke
parents:
diff changeset
223
a61af66fc99e Initial load
duke
parents:
diff changeset
224 int get_dest_table( int index ) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
225 return cur_bci() + get_int_table(index); }
a61af66fc99e Initial load
duke
parents:
diff changeset
226
a61af66fc99e Initial load
duke
parents:
diff changeset
227 // --- Constant pool access ---
1602
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
228 int get_constant_raw_index() const;
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
229 int get_constant_pool_index() const;
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
230 int get_constant_cache_index() const;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
231 int get_field_index();
a61af66fc99e Initial load
duke
parents:
diff changeset
232 int get_method_index();
a61af66fc99e Initial load
duke
parents:
diff changeset
233
a61af66fc99e Initial load
duke
parents:
diff changeset
234 // If this bytecode is a new, newarray, multianewarray, instanceof,
a61af66fc99e Initial load
duke
parents:
diff changeset
235 // or checkcast, get the referenced klass.
a61af66fc99e Initial load
duke
parents:
diff changeset
236 ciKlass* get_klass(bool& will_link);
a61af66fc99e Initial load
duke
parents:
diff changeset
237 int get_klass_index() const;
a61af66fc99e Initial load
duke
parents:
diff changeset
238
a61af66fc99e Initial load
duke
parents:
diff changeset
239 // If this bytecode is one of the ldc variants, get the referenced
1602
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
240 // constant. Do not attempt to resolve it, since that would require
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
241 // execution of Java code. If it is not resolved, return an unloaded
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
242 // object (ciConstant.as_object()->is_loaded() == false).
0
a61af66fc99e Initial load
duke
parents:
diff changeset
243 ciConstant get_constant();
1602
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
244 constantTag get_constant_pool_tag(int index) const;
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
245
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
246 // True if the klass-using bytecode points to an unresolved klass
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
247 bool is_unresolved_klass() const {
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
248 constantTag tag = get_constant_pool_tag(get_klass_index());
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
249 return tag.is_unresolved_klass();
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
250 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
251
a61af66fc99e Initial load
duke
parents:
diff changeset
252 // If this bytecode is one of get_field, get_static, put_field,
a61af66fc99e Initial load
duke
parents:
diff changeset
253 // or put_static, get the referenced field.
a61af66fc99e Initial load
duke
parents:
diff changeset
254 ciField* get_field(bool& will_link);
a61af66fc99e Initial load
duke
parents:
diff changeset
255
a61af66fc99e Initial load
duke
parents:
diff changeset
256 ciInstanceKlass* get_declared_field_holder();
a61af66fc99e Initial load
duke
parents:
diff changeset
257 int get_field_holder_index();
a61af66fc99e Initial load
duke
parents:
diff changeset
258 int get_field_signature_index();
a61af66fc99e Initial load
duke
parents:
diff changeset
259
6634
7f813940ac35 7192406: JSR 292: C2 needs exact return type information for invokedynamic and invokehandle call sites
twisti
parents: 6266
diff changeset
260 ciMethod* get_method(bool& will_link, ciSignature* *declared_signature_result);
6266
1d7922586cf6 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 3897
diff changeset
261 bool has_appendix();
1d7922586cf6 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 3897
diff changeset
262 ciObject* get_appendix();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
263 ciKlass* get_declared_method_holder();
a61af66fc99e Initial load
duke
parents:
diff changeset
264 int get_method_holder_index();
a61af66fc99e Initial load
duke
parents:
diff changeset
265 int get_method_signature_index();
726
be93aad57795 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 0
diff changeset
266
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6634
diff changeset
267 // Get the resolved references arrays from the constant pool
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6634
diff changeset
268 ciObjArray* get_resolved_references();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
269 };
a61af66fc99e Initial load
duke
parents:
diff changeset
270
a61af66fc99e Initial load
duke
parents:
diff changeset
271
a61af66fc99e Initial load
duke
parents:
diff changeset
272 // ciSignatureStream
a61af66fc99e Initial load
duke
parents:
diff changeset
273 //
a61af66fc99e Initial load
duke
parents:
diff changeset
274 // The class is used to iterate over the elements of a method signature.
a61af66fc99e Initial load
duke
parents:
diff changeset
275 class ciSignatureStream : public StackObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
276 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
277 ciSignature* _sig;
a61af66fc99e Initial load
duke
parents:
diff changeset
278 int _pos;
a61af66fc99e Initial load
duke
parents:
diff changeset
279 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
280 ciSignatureStream(ciSignature* signature) {
a61af66fc99e Initial load
duke
parents:
diff changeset
281 _sig = signature;
a61af66fc99e Initial load
duke
parents:
diff changeset
282 _pos = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
283 }
a61af66fc99e Initial load
duke
parents:
diff changeset
284
a61af66fc99e Initial load
duke
parents:
diff changeset
285 bool at_return_type() { return _pos == _sig->count(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
286
a61af66fc99e Initial load
duke
parents:
diff changeset
287 bool is_done() { return _pos > _sig->count(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
288
a61af66fc99e Initial load
duke
parents:
diff changeset
289 void next() {
a61af66fc99e Initial load
duke
parents:
diff changeset
290 if (_pos <= _sig->count()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
291 _pos++;
a61af66fc99e Initial load
duke
parents:
diff changeset
292 }
a61af66fc99e Initial load
duke
parents:
diff changeset
293 }
a61af66fc99e Initial load
duke
parents:
diff changeset
294
a61af66fc99e Initial load
duke
parents:
diff changeset
295 ciType* type() {
a61af66fc99e Initial load
duke
parents:
diff changeset
296 if (at_return_type()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
297 return _sig->return_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
298 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
299 return _sig->type_at(_pos);
a61af66fc99e Initial load
duke
parents:
diff changeset
300 }
a61af66fc99e Initial load
duke
parents:
diff changeset
301 }
a61af66fc99e Initial load
duke
parents:
diff changeset
302 };
a61af66fc99e Initial load
duke
parents:
diff changeset
303
a61af66fc99e Initial load
duke
parents:
diff changeset
304
a61af66fc99e Initial load
duke
parents:
diff changeset
305 // ciExceptionHandlerStream
a61af66fc99e Initial load
duke
parents:
diff changeset
306 //
a61af66fc99e Initial load
duke
parents:
diff changeset
307 // The class is used to iterate over the exception handlers of
a61af66fc99e Initial load
duke
parents:
diff changeset
308 // a method.
a61af66fc99e Initial load
duke
parents:
diff changeset
309 class ciExceptionHandlerStream : public StackObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
310 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
311 // The method whose handlers we are traversing
a61af66fc99e Initial load
duke
parents:
diff changeset
312 ciMethod* _method;
a61af66fc99e Initial load
duke
parents:
diff changeset
313
a61af66fc99e Initial load
duke
parents:
diff changeset
314 // Our current position in the list of handlers
a61af66fc99e Initial load
duke
parents:
diff changeset
315 int _pos;
a61af66fc99e Initial load
duke
parents:
diff changeset
316 int _end;
a61af66fc99e Initial load
duke
parents:
diff changeset
317
a61af66fc99e Initial load
duke
parents:
diff changeset
318 ciInstanceKlass* _exception_klass;
a61af66fc99e Initial load
duke
parents:
diff changeset
319 int _bci;
a61af66fc99e Initial load
duke
parents:
diff changeset
320 bool _is_exact;
a61af66fc99e Initial load
duke
parents:
diff changeset
321
a61af66fc99e Initial load
duke
parents:
diff changeset
322 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
323 ciExceptionHandlerStream(ciMethod* method) {
a61af66fc99e Initial load
duke
parents:
diff changeset
324 _method = method;
a61af66fc99e Initial load
duke
parents:
diff changeset
325
a61af66fc99e Initial load
duke
parents:
diff changeset
326 // Force loading of method code and handlers.
a61af66fc99e Initial load
duke
parents:
diff changeset
327 _method->code();
a61af66fc99e Initial load
duke
parents:
diff changeset
328
a61af66fc99e Initial load
duke
parents:
diff changeset
329 _pos = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
330 _end = _method->_handler_count;
a61af66fc99e Initial load
duke
parents:
diff changeset
331 _exception_klass = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
332 _bci = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
333 _is_exact = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
334 }
a61af66fc99e Initial load
duke
parents:
diff changeset
335
a61af66fc99e Initial load
duke
parents:
diff changeset
336 ciExceptionHandlerStream(ciMethod* method, int bci,
a61af66fc99e Initial load
duke
parents:
diff changeset
337 ciInstanceKlass* exception_klass = NULL,
a61af66fc99e Initial load
duke
parents:
diff changeset
338 bool is_exact = false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
339 _method = method;
a61af66fc99e Initial load
duke
parents:
diff changeset
340
a61af66fc99e Initial load
duke
parents:
diff changeset
341 // Force loading of method code and handlers.
a61af66fc99e Initial load
duke
parents:
diff changeset
342 _method->code();
a61af66fc99e Initial load
duke
parents:
diff changeset
343
a61af66fc99e Initial load
duke
parents:
diff changeset
344 _pos = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
345 _end = _method->_handler_count + 1; // include the rethrow handler
a61af66fc99e Initial load
duke
parents:
diff changeset
346 _exception_klass = (exception_klass != NULL && exception_klass->is_loaded()
a61af66fc99e Initial load
duke
parents:
diff changeset
347 ? exception_klass
a61af66fc99e Initial load
duke
parents:
diff changeset
348 : NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
349 _bci = bci;
a61af66fc99e Initial load
duke
parents:
diff changeset
350 assert(_bci >= 0, "bci out of range");
a61af66fc99e Initial load
duke
parents:
diff changeset
351 _is_exact = is_exact;
a61af66fc99e Initial load
duke
parents:
diff changeset
352 next();
a61af66fc99e Initial load
duke
parents:
diff changeset
353 }
a61af66fc99e Initial load
duke
parents:
diff changeset
354
a61af66fc99e Initial load
duke
parents:
diff changeset
355 // These methods are currently implemented in an odd way.
a61af66fc99e Initial load
duke
parents:
diff changeset
356 // Count the number of handlers the iterator has ever produced
a61af66fc99e Initial load
duke
parents:
diff changeset
357 // or will ever produce. Do not include the final rethrow handler.
a61af66fc99e Initial load
duke
parents:
diff changeset
358 // That is, a trivial exception handler stream will have a count
a61af66fc99e Initial load
duke
parents:
diff changeset
359 // of zero and produce just the rethrow handler.
a61af66fc99e Initial load
duke
parents:
diff changeset
360 int count();
a61af66fc99e Initial load
duke
parents:
diff changeset
361
a61af66fc99e Initial load
duke
parents:
diff changeset
362 // Count the number of handlers this stream will produce from now on.
a61af66fc99e Initial load
duke
parents:
diff changeset
363 // Include the current handler, and the final rethrow handler.
a61af66fc99e Initial load
duke
parents:
diff changeset
364 // The remaining count will be zero iff is_done() is true,
a61af66fc99e Initial load
duke
parents:
diff changeset
365 int count_remaining();
a61af66fc99e Initial load
duke
parents:
diff changeset
366
a61af66fc99e Initial load
duke
parents:
diff changeset
367 bool is_done() {
a61af66fc99e Initial load
duke
parents:
diff changeset
368 return (_pos >= _end);
a61af66fc99e Initial load
duke
parents:
diff changeset
369 }
a61af66fc99e Initial load
duke
parents:
diff changeset
370
a61af66fc99e Initial load
duke
parents:
diff changeset
371 void next() {
a61af66fc99e Initial load
duke
parents:
diff changeset
372 _pos++;
a61af66fc99e Initial load
duke
parents:
diff changeset
373 if (_bci != -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
374 // We are not iterating over all handlers...
a61af66fc99e Initial load
duke
parents:
diff changeset
375 while (!is_done()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
376 ciExceptionHandler* handler = _method->_exception_handlers[_pos];
a61af66fc99e Initial load
duke
parents:
diff changeset
377 if (handler->is_in_range(_bci)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
378 if (handler->is_catch_all()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
379 // Found final active catch block.
a61af66fc99e Initial load
duke
parents:
diff changeset
380 _end = _pos+1;
a61af66fc99e Initial load
duke
parents:
diff changeset
381 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
382 } else if (_exception_klass == NULL || !handler->catch_klass()->is_loaded()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
383 // We cannot do any type analysis here. Must conservatively assume
a61af66fc99e Initial load
duke
parents:
diff changeset
384 // catch block is reachable.
a61af66fc99e Initial load
duke
parents:
diff changeset
385 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
386 } else if (_exception_klass->is_subtype_of(handler->catch_klass())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
387 // This catch clause will definitely catch the exception.
a61af66fc99e Initial load
duke
parents:
diff changeset
388 // Final candidate.
a61af66fc99e Initial load
duke
parents:
diff changeset
389 _end = _pos+1;
a61af66fc99e Initial load
duke
parents:
diff changeset
390 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
391 } else if (!_is_exact &&
a61af66fc99e Initial load
duke
parents:
diff changeset
392 handler->catch_klass()->is_subtype_of(_exception_klass)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
393 // This catch block may be reachable.
a61af66fc99e Initial load
duke
parents:
diff changeset
394 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
395 }
a61af66fc99e Initial load
duke
parents:
diff changeset
396 }
a61af66fc99e Initial load
duke
parents:
diff changeset
397
a61af66fc99e Initial load
duke
parents:
diff changeset
398 // The catch block was not pertinent. Go on.
a61af66fc99e Initial load
duke
parents:
diff changeset
399 _pos++;
a61af66fc99e Initial load
duke
parents:
diff changeset
400 }
a61af66fc99e Initial load
duke
parents:
diff changeset
401 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
402 // This is an iteration over all handlers.
a61af66fc99e Initial load
duke
parents:
diff changeset
403 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
404 }
a61af66fc99e Initial load
duke
parents:
diff changeset
405 }
a61af66fc99e Initial load
duke
parents:
diff changeset
406
a61af66fc99e Initial load
duke
parents:
diff changeset
407 ciExceptionHandler* handler() {
a61af66fc99e Initial load
duke
parents:
diff changeset
408 return _method->_exception_handlers[_pos];
a61af66fc99e Initial load
duke
parents:
diff changeset
409 }
a61af66fc99e Initial load
duke
parents:
diff changeset
410 };
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1602
diff changeset
411
2142
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
412
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
413
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
414 // Implementation for declarations in bytecode.hpp
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
415 Bytecode::Bytecode(const ciBytecodeStream* stream, address bcp): _bcp(bcp != NULL ? bcp : stream->cur_bcp()), _code(Bytecodes::code_at(NULL, addr_at(0))) {}
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
416 Bytecode_lookupswitch::Bytecode_lookupswitch(const ciBytecodeStream* stream): Bytecode(stream) { verify(); }
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
417 Bytecode_tableswitch::Bytecode_tableswitch(const ciBytecodeStream* stream): Bytecode(stream) { verify(); }
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
418
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1602
diff changeset
419 #endif // SHARE_VM_CI_CISTREAMS_HPP