annotate src/share/vm/oops/generateOopMap.cpp @ 17716:cdb71841f4bc

6498581: ThreadInterruptTest3 produces wrong output on Windows Summary: There is race condition between os::interrupt and os::is_interrupted on Windows. In JVM_Sleep(Thread.sleep), check if thread gets interrupted, it may see interrupted but not really interrupted so cause spurious waking up (early return from sleep). Fix by checking if interrupt event really gets set thus prevent false return. For intrinsic of _isInterrupted, on Windows, go fastpath only on bit not set. Reviewed-by: acorn, kvn Contributed-by: david.holmes@oracle.com, yumin.qi@oracle.com
author minqi
date Wed, 26 Feb 2014 15:20:41 -0800
parents 00bcb186fc5a
children 4ca6dc0799b6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
8104
f16e75e0cf11 8000797: NPG: is_pseudo_string_at() doesn't work
coleenp
parents: 6725
diff changeset
2 * Copyright (c) 1997, 2013, 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: 1489
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1489
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: 1489
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: 1910
diff changeset
25 #include "precompiled.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1910
diff changeset
26 #include "interpreter/bytecodeStream.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1910
diff changeset
27 #include "oops/generateOopMap.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1910
diff changeset
28 #include "oops/oop.inline.hpp"
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 2142
diff changeset
29 #include "oops/symbol.hpp"
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1910
diff changeset
30 #include "runtime/handles.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1910
diff changeset
31 #include "runtime/java.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1910
diff changeset
32 #include "runtime/relocator.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1910
diff changeset
33 #include "utilities/bitMap.inline.hpp"
6266
1d7922586cf6 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 6213
diff changeset
34 #include "prims/methodHandles.hpp"
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1910
diff changeset
35
0
a61af66fc99e Initial load
duke
parents:
diff changeset
36 //
a61af66fc99e Initial load
duke
parents:
diff changeset
37 //
a61af66fc99e Initial load
duke
parents:
diff changeset
38 // Compute stack layouts for each instruction in method.
a61af66fc99e Initial load
duke
parents:
diff changeset
39 //
a61af66fc99e Initial load
duke
parents:
diff changeset
40 // Problems:
a61af66fc99e Initial load
duke
parents:
diff changeset
41 // - What to do about jsr with different types of local vars?
a61af66fc99e Initial load
duke
parents:
diff changeset
42 // Need maps that are conditional on jsr path?
a61af66fc99e Initial load
duke
parents:
diff changeset
43 // - Jsr and exceptions should be done more efficiently (the retAddr stuff)
a61af66fc99e Initial load
duke
parents:
diff changeset
44 //
a61af66fc99e Initial load
duke
parents:
diff changeset
45 // Alternative:
a61af66fc99e Initial load
duke
parents:
diff changeset
46 // - Could extend verifier to provide this information.
a61af66fc99e Initial load
duke
parents:
diff changeset
47 // For: one fewer abstract interpreter to maintain. Against: the verifier
a61af66fc99e Initial load
duke
parents:
diff changeset
48 // solves a bigger problem so slower (undesirable to force verification of
a61af66fc99e Initial load
duke
parents:
diff changeset
49 // everything?).
a61af66fc99e Initial load
duke
parents:
diff changeset
50 //
a61af66fc99e Initial load
duke
parents:
diff changeset
51 // Algorithm:
a61af66fc99e Initial load
duke
parents:
diff changeset
52 // Partition bytecodes into basic blocks
a61af66fc99e Initial load
duke
parents:
diff changeset
53 // For each basic block: store entry state (vars, stack). For instructions
a61af66fc99e Initial load
duke
parents:
diff changeset
54 // inside basic blocks we do not store any state (instead we recompute it
a61af66fc99e Initial load
duke
parents:
diff changeset
55 // from state produced by previous instruction).
a61af66fc99e Initial load
duke
parents:
diff changeset
56 //
a61af66fc99e Initial load
duke
parents:
diff changeset
57 // Perform abstract interpretation of bytecodes over this lattice:
a61af66fc99e Initial load
duke
parents:
diff changeset
58 //
a61af66fc99e Initial load
duke
parents:
diff changeset
59 // _--'#'--_
a61af66fc99e Initial load
duke
parents:
diff changeset
60 // / / \ \
a61af66fc99e Initial load
duke
parents:
diff changeset
61 // / / \ \
a61af66fc99e Initial load
duke
parents:
diff changeset
62 // / | | \
a61af66fc99e Initial load
duke
parents:
diff changeset
63 // 'r' 'v' 'p' ' '
a61af66fc99e Initial load
duke
parents:
diff changeset
64 // \ | | /
a61af66fc99e Initial load
duke
parents:
diff changeset
65 // \ \ / /
a61af66fc99e Initial load
duke
parents:
diff changeset
66 // \ \ / /
a61af66fc99e Initial load
duke
parents:
diff changeset
67 // -- '@' --
a61af66fc99e Initial load
duke
parents:
diff changeset
68 //
a61af66fc99e Initial load
duke
parents:
diff changeset
69 // '#' top, result of conflict merge
a61af66fc99e Initial load
duke
parents:
diff changeset
70 // 'r' reference type
a61af66fc99e Initial load
duke
parents:
diff changeset
71 // 'v' value type
a61af66fc99e Initial load
duke
parents:
diff changeset
72 // 'p' pc type for jsr/ret
a61af66fc99e Initial load
duke
parents:
diff changeset
73 // ' ' uninitialized; never occurs on operand stack in Java
a61af66fc99e Initial load
duke
parents:
diff changeset
74 // '@' bottom/unexecuted; initial state each bytecode.
a61af66fc99e Initial load
duke
parents:
diff changeset
75 //
a61af66fc99e Initial load
duke
parents:
diff changeset
76 // Basic block headers are the only merge points. We use this iteration to
a61af66fc99e Initial load
duke
parents:
diff changeset
77 // compute the information:
a61af66fc99e Initial load
duke
parents:
diff changeset
78 //
a61af66fc99e Initial load
duke
parents:
diff changeset
79 // find basic blocks;
a61af66fc99e Initial load
duke
parents:
diff changeset
80 // initialize them with uninitialized state;
a61af66fc99e Initial load
duke
parents:
diff changeset
81 // initialize first BB according to method signature;
a61af66fc99e Initial load
duke
parents:
diff changeset
82 // mark first BB changed
a61af66fc99e Initial load
duke
parents:
diff changeset
83 // while (some BB is changed) do {
a61af66fc99e Initial load
duke
parents:
diff changeset
84 // perform abstract interpration of all bytecodes in BB;
a61af66fc99e Initial load
duke
parents:
diff changeset
85 // merge exit state of BB into entry state of all successor BBs,
a61af66fc99e Initial load
duke
parents:
diff changeset
86 // noting if any of these change;
a61af66fc99e Initial load
duke
parents:
diff changeset
87 // }
a61af66fc99e Initial load
duke
parents:
diff changeset
88 //
a61af66fc99e Initial load
duke
parents:
diff changeset
89 // One additional complication is necessary. The jsr instruction pushes
a61af66fc99e Initial load
duke
parents:
diff changeset
90 // a return PC on the stack (a 'p' type in the abstract interpretation).
a61af66fc99e Initial load
duke
parents:
diff changeset
91 // To be able to process "ret" bytecodes, we keep track of these return
a61af66fc99e Initial load
duke
parents:
diff changeset
92 // PC's in a 'retAddrs' structure in abstract interpreter context (when
a61af66fc99e Initial load
duke
parents:
diff changeset
93 // processing a "ret" bytecodes, it is not sufficient to know that it gets
a61af66fc99e Initial load
duke
parents:
diff changeset
94 // an argument of the right type 'p'; we need to know which address it
a61af66fc99e Initial load
duke
parents:
diff changeset
95 // returns to).
a61af66fc99e Initial load
duke
parents:
diff changeset
96 //
a61af66fc99e Initial load
duke
parents:
diff changeset
97 // (Note this comment is borrowed form the original author of the algorithm)
a61af66fc99e Initial load
duke
parents:
diff changeset
98
a61af66fc99e Initial load
duke
parents:
diff changeset
99 // ComputeCallStack
a61af66fc99e Initial load
duke
parents:
diff changeset
100 //
a61af66fc99e Initial load
duke
parents:
diff changeset
101 // Specialization of SignatureIterator - compute the effects of a call
a61af66fc99e Initial load
duke
parents:
diff changeset
102 //
a61af66fc99e Initial load
duke
parents:
diff changeset
103 class ComputeCallStack : public SignatureIterator {
a61af66fc99e Initial load
duke
parents:
diff changeset
104 CellTypeState *_effect;
a61af66fc99e Initial load
duke
parents:
diff changeset
105 int _idx;
a61af66fc99e Initial load
duke
parents:
diff changeset
106
a61af66fc99e Initial load
duke
parents:
diff changeset
107 void setup();
a61af66fc99e Initial load
duke
parents:
diff changeset
108 void set(CellTypeState state) { _effect[_idx++] = state; }
a61af66fc99e Initial load
duke
parents:
diff changeset
109 int length() { return _idx; };
a61af66fc99e Initial load
duke
parents:
diff changeset
110
a61af66fc99e Initial load
duke
parents:
diff changeset
111 virtual void do_bool () { set(CellTypeState::value); };
a61af66fc99e Initial load
duke
parents:
diff changeset
112 virtual void do_char () { set(CellTypeState::value); };
a61af66fc99e Initial load
duke
parents:
diff changeset
113 virtual void do_float () { set(CellTypeState::value); };
a61af66fc99e Initial load
duke
parents:
diff changeset
114 virtual void do_byte () { set(CellTypeState::value); };
a61af66fc99e Initial load
duke
parents:
diff changeset
115 virtual void do_short () { set(CellTypeState::value); };
a61af66fc99e Initial load
duke
parents:
diff changeset
116 virtual void do_int () { set(CellTypeState::value); };
a61af66fc99e Initial load
duke
parents:
diff changeset
117 virtual void do_void () { set(CellTypeState::bottom);};
a61af66fc99e Initial load
duke
parents:
diff changeset
118 virtual void do_object(int begin, int end) { set(CellTypeState::ref); };
a61af66fc99e Initial load
duke
parents:
diff changeset
119 virtual void do_array (int begin, int end) { set(CellTypeState::ref); };
a61af66fc99e Initial load
duke
parents:
diff changeset
120
a61af66fc99e Initial load
duke
parents:
diff changeset
121 void do_double() { set(CellTypeState::value);
a61af66fc99e Initial load
duke
parents:
diff changeset
122 set(CellTypeState::value); }
a61af66fc99e Initial load
duke
parents:
diff changeset
123 void do_long () { set(CellTypeState::value);
a61af66fc99e Initial load
duke
parents:
diff changeset
124 set(CellTypeState::value); }
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126 public:
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 2142
diff changeset
127 ComputeCallStack(Symbol* signature) : SignatureIterator(signature) {};
0
a61af66fc99e Initial load
duke
parents:
diff changeset
128
a61af66fc99e Initial load
duke
parents:
diff changeset
129 // Compute methods
a61af66fc99e Initial load
duke
parents:
diff changeset
130 int compute_for_parameters(bool is_static, CellTypeState *effect) {
a61af66fc99e Initial load
duke
parents:
diff changeset
131 _idx = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
132 _effect = effect;
a61af66fc99e Initial load
duke
parents:
diff changeset
133
a61af66fc99e Initial load
duke
parents:
diff changeset
134 if (!is_static)
a61af66fc99e Initial load
duke
parents:
diff changeset
135 effect[_idx++] = CellTypeState::ref;
a61af66fc99e Initial load
duke
parents:
diff changeset
136
a61af66fc99e Initial load
duke
parents:
diff changeset
137 iterate_parameters();
a61af66fc99e Initial load
duke
parents:
diff changeset
138
a61af66fc99e Initial load
duke
parents:
diff changeset
139 return length();
a61af66fc99e Initial load
duke
parents:
diff changeset
140 };
a61af66fc99e Initial load
duke
parents:
diff changeset
141
a61af66fc99e Initial load
duke
parents:
diff changeset
142 int compute_for_returntype(CellTypeState *effect) {
a61af66fc99e Initial load
duke
parents:
diff changeset
143 _idx = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
144 _effect = effect;
a61af66fc99e Initial load
duke
parents:
diff changeset
145 iterate_returntype();
a61af66fc99e Initial load
duke
parents:
diff changeset
146 set(CellTypeState::bottom); // Always terminate with a bottom state, so ppush works
a61af66fc99e Initial load
duke
parents:
diff changeset
147
a61af66fc99e Initial load
duke
parents:
diff changeset
148 return length();
a61af66fc99e Initial load
duke
parents:
diff changeset
149 }
a61af66fc99e Initial load
duke
parents:
diff changeset
150 };
a61af66fc99e Initial load
duke
parents:
diff changeset
151
a61af66fc99e Initial load
duke
parents:
diff changeset
152 //=========================================================================================
a61af66fc99e Initial load
duke
parents:
diff changeset
153 // ComputeEntryStack
a61af66fc99e Initial load
duke
parents:
diff changeset
154 //
a61af66fc99e Initial load
duke
parents:
diff changeset
155 // Specialization of SignatureIterator - in order to set up first stack frame
a61af66fc99e Initial load
duke
parents:
diff changeset
156 //
a61af66fc99e Initial load
duke
parents:
diff changeset
157 class ComputeEntryStack : public SignatureIterator {
a61af66fc99e Initial load
duke
parents:
diff changeset
158 CellTypeState *_effect;
a61af66fc99e Initial load
duke
parents:
diff changeset
159 int _idx;
a61af66fc99e Initial load
duke
parents:
diff changeset
160
a61af66fc99e Initial load
duke
parents:
diff changeset
161 void setup();
a61af66fc99e Initial load
duke
parents:
diff changeset
162 void set(CellTypeState state) { _effect[_idx++] = state; }
a61af66fc99e Initial load
duke
parents:
diff changeset
163 int length() { return _idx; };
a61af66fc99e Initial load
duke
parents:
diff changeset
164
a61af66fc99e Initial load
duke
parents:
diff changeset
165 virtual void do_bool () { set(CellTypeState::value); };
a61af66fc99e Initial load
duke
parents:
diff changeset
166 virtual void do_char () { set(CellTypeState::value); };
a61af66fc99e Initial load
duke
parents:
diff changeset
167 virtual void do_float () { set(CellTypeState::value); };
a61af66fc99e Initial load
duke
parents:
diff changeset
168 virtual void do_byte () { set(CellTypeState::value); };
a61af66fc99e Initial load
duke
parents:
diff changeset
169 virtual void do_short () { set(CellTypeState::value); };
a61af66fc99e Initial load
duke
parents:
diff changeset
170 virtual void do_int () { set(CellTypeState::value); };
a61af66fc99e Initial load
duke
parents:
diff changeset
171 virtual void do_void () { set(CellTypeState::bottom);};
a61af66fc99e Initial load
duke
parents:
diff changeset
172 virtual void do_object(int begin, int end) { set(CellTypeState::make_slot_ref(_idx)); }
a61af66fc99e Initial load
duke
parents:
diff changeset
173 virtual void do_array (int begin, int end) { set(CellTypeState::make_slot_ref(_idx)); }
a61af66fc99e Initial load
duke
parents:
diff changeset
174
a61af66fc99e Initial load
duke
parents:
diff changeset
175 void do_double() { set(CellTypeState::value);
a61af66fc99e Initial load
duke
parents:
diff changeset
176 set(CellTypeState::value); }
a61af66fc99e Initial load
duke
parents:
diff changeset
177 void do_long () { set(CellTypeState::value);
a61af66fc99e Initial load
duke
parents:
diff changeset
178 set(CellTypeState::value); }
a61af66fc99e Initial load
duke
parents:
diff changeset
179
a61af66fc99e Initial load
duke
parents:
diff changeset
180 public:
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 2142
diff changeset
181 ComputeEntryStack(Symbol* signature) : SignatureIterator(signature) {};
0
a61af66fc99e Initial load
duke
parents:
diff changeset
182
a61af66fc99e Initial load
duke
parents:
diff changeset
183 // Compute methods
a61af66fc99e Initial load
duke
parents:
diff changeset
184 int compute_for_parameters(bool is_static, CellTypeState *effect) {
a61af66fc99e Initial load
duke
parents:
diff changeset
185 _idx = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
186 _effect = effect;
a61af66fc99e Initial load
duke
parents:
diff changeset
187
a61af66fc99e Initial load
duke
parents:
diff changeset
188 if (!is_static)
a61af66fc99e Initial load
duke
parents:
diff changeset
189 effect[_idx++] = CellTypeState::make_slot_ref(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
190
a61af66fc99e Initial load
duke
parents:
diff changeset
191 iterate_parameters();
a61af66fc99e Initial load
duke
parents:
diff changeset
192
a61af66fc99e Initial load
duke
parents:
diff changeset
193 return length();
a61af66fc99e Initial load
duke
parents:
diff changeset
194 };
a61af66fc99e Initial load
duke
parents:
diff changeset
195
a61af66fc99e Initial load
duke
parents:
diff changeset
196 int compute_for_returntype(CellTypeState *effect) {
a61af66fc99e Initial load
duke
parents:
diff changeset
197 _idx = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
198 _effect = effect;
a61af66fc99e Initial load
duke
parents:
diff changeset
199 iterate_returntype();
a61af66fc99e Initial load
duke
parents:
diff changeset
200 set(CellTypeState::bottom); // Always terminate with a bottom state, so ppush works
a61af66fc99e Initial load
duke
parents:
diff changeset
201
a61af66fc99e Initial load
duke
parents:
diff changeset
202 return length();
a61af66fc99e Initial load
duke
parents:
diff changeset
203 }
a61af66fc99e Initial load
duke
parents:
diff changeset
204 };
a61af66fc99e Initial load
duke
parents:
diff changeset
205
a61af66fc99e Initial load
duke
parents:
diff changeset
206 //=====================================================================================
a61af66fc99e Initial load
duke
parents:
diff changeset
207 //
a61af66fc99e Initial load
duke
parents:
diff changeset
208 // Implementation of RetTable/RetTableEntry
a61af66fc99e Initial load
duke
parents:
diff changeset
209 //
a61af66fc99e Initial load
duke
parents:
diff changeset
210 // Contains function to itereate through all bytecodes
a61af66fc99e Initial load
duke
parents:
diff changeset
211 // and find all return entry points
a61af66fc99e Initial load
duke
parents:
diff changeset
212 //
a61af66fc99e Initial load
duke
parents:
diff changeset
213 int RetTable::_init_nof_entries = 10;
a61af66fc99e Initial load
duke
parents:
diff changeset
214 int RetTableEntry::_init_nof_jsrs = 5;
a61af66fc99e Initial load
duke
parents:
diff changeset
215
a61af66fc99e Initial load
duke
parents:
diff changeset
216 void RetTableEntry::add_delta(int bci, int delta) {
a61af66fc99e Initial load
duke
parents:
diff changeset
217 if (_target_bci > bci) _target_bci += delta;
a61af66fc99e Initial load
duke
parents:
diff changeset
218
a61af66fc99e Initial load
duke
parents:
diff changeset
219 for (int k = 0; k < _jsrs->length(); k++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
220 int jsr = _jsrs->at(k);
a61af66fc99e Initial load
duke
parents:
diff changeset
221 if (jsr > bci) _jsrs->at_put(k, jsr+delta);
a61af66fc99e Initial load
duke
parents:
diff changeset
222 }
a61af66fc99e Initial load
duke
parents:
diff changeset
223 }
a61af66fc99e Initial load
duke
parents:
diff changeset
224
a61af66fc99e Initial load
duke
parents:
diff changeset
225 void RetTable::compute_ret_table(methodHandle method) {
a61af66fc99e Initial load
duke
parents:
diff changeset
226 BytecodeStream i(method);
a61af66fc99e Initial load
duke
parents:
diff changeset
227 Bytecodes::Code bytecode;
a61af66fc99e Initial load
duke
parents:
diff changeset
228
a61af66fc99e Initial load
duke
parents:
diff changeset
229 while( (bytecode = i.next()) >= 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
230 switch (bytecode) {
a61af66fc99e Initial load
duke
parents:
diff changeset
231 case Bytecodes::_jsr:
a61af66fc99e Initial load
duke
parents:
diff changeset
232 add_jsr(i.next_bci(), i.dest());
a61af66fc99e Initial load
duke
parents:
diff changeset
233 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
234 case Bytecodes::_jsr_w:
a61af66fc99e Initial load
duke
parents:
diff changeset
235 add_jsr(i.next_bci(), i.dest_w());
a61af66fc99e Initial load
duke
parents:
diff changeset
236 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
237 }
a61af66fc99e Initial load
duke
parents:
diff changeset
238 }
a61af66fc99e Initial load
duke
parents:
diff changeset
239 }
a61af66fc99e Initial load
duke
parents:
diff changeset
240
a61af66fc99e Initial load
duke
parents:
diff changeset
241 void RetTable::add_jsr(int return_bci, int target_bci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
242 RetTableEntry* entry = _first;
a61af66fc99e Initial load
duke
parents:
diff changeset
243
a61af66fc99e Initial load
duke
parents:
diff changeset
244 // Scan table for entry
a61af66fc99e Initial load
duke
parents:
diff changeset
245 for (;entry && entry->target_bci() != target_bci; entry = entry->next());
a61af66fc99e Initial load
duke
parents:
diff changeset
246
a61af66fc99e Initial load
duke
parents:
diff changeset
247 if (!entry) {
a61af66fc99e Initial load
duke
parents:
diff changeset
248 // Allocate new entry and put in list
a61af66fc99e Initial load
duke
parents:
diff changeset
249 entry = new RetTableEntry(target_bci, _first);
a61af66fc99e Initial load
duke
parents:
diff changeset
250 _first = entry;
a61af66fc99e Initial load
duke
parents:
diff changeset
251 }
a61af66fc99e Initial load
duke
parents:
diff changeset
252
a61af66fc99e Initial load
duke
parents:
diff changeset
253 // Now "entry" is set. Make sure that the entry is initialized
a61af66fc99e Initial load
duke
parents:
diff changeset
254 // and has room for the new jsr.
a61af66fc99e Initial load
duke
parents:
diff changeset
255 entry->add_jsr(return_bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
256 }
a61af66fc99e Initial load
duke
parents:
diff changeset
257
a61af66fc99e Initial load
duke
parents:
diff changeset
258 RetTableEntry* RetTable::find_jsrs_for_target(int targBci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
259 RetTableEntry *cur = _first;
a61af66fc99e Initial load
duke
parents:
diff changeset
260
a61af66fc99e Initial load
duke
parents:
diff changeset
261 while(cur) {
a61af66fc99e Initial load
duke
parents:
diff changeset
262 assert(cur->target_bci() != -1, "sanity check");
a61af66fc99e Initial load
duke
parents:
diff changeset
263 if (cur->target_bci() == targBci) return cur;
a61af66fc99e Initial load
duke
parents:
diff changeset
264 cur = cur->next();
a61af66fc99e Initial load
duke
parents:
diff changeset
265 }
a61af66fc99e Initial load
duke
parents:
diff changeset
266 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
267 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
268 }
a61af66fc99e Initial load
duke
parents:
diff changeset
269
a61af66fc99e Initial load
duke
parents:
diff changeset
270 // The instruction at bci is changing size by "delta". Update the return map.
a61af66fc99e Initial load
duke
parents:
diff changeset
271 void RetTable::update_ret_table(int bci, int delta) {
a61af66fc99e Initial load
duke
parents:
diff changeset
272 RetTableEntry *cur = _first;
a61af66fc99e Initial load
duke
parents:
diff changeset
273 while(cur) {
a61af66fc99e Initial load
duke
parents:
diff changeset
274 cur->add_delta(bci, delta);
a61af66fc99e Initial load
duke
parents:
diff changeset
275 cur = cur->next();
a61af66fc99e Initial load
duke
parents:
diff changeset
276 }
a61af66fc99e Initial load
duke
parents:
diff changeset
277 }
a61af66fc99e Initial load
duke
parents:
diff changeset
278
a61af66fc99e Initial load
duke
parents:
diff changeset
279 //
a61af66fc99e Initial load
duke
parents:
diff changeset
280 // Celltype state
a61af66fc99e Initial load
duke
parents:
diff changeset
281 //
a61af66fc99e Initial load
duke
parents:
diff changeset
282
a61af66fc99e Initial load
duke
parents:
diff changeset
283 CellTypeState CellTypeState::bottom = CellTypeState::make_bottom();
a61af66fc99e Initial load
duke
parents:
diff changeset
284 CellTypeState CellTypeState::uninit = CellTypeState::make_any(uninit_value);
a61af66fc99e Initial load
duke
parents:
diff changeset
285 CellTypeState CellTypeState::ref = CellTypeState::make_any(ref_conflict);
a61af66fc99e Initial load
duke
parents:
diff changeset
286 CellTypeState CellTypeState::value = CellTypeState::make_any(val_value);
a61af66fc99e Initial load
duke
parents:
diff changeset
287 CellTypeState CellTypeState::refUninit = CellTypeState::make_any(ref_conflict | uninit_value);
a61af66fc99e Initial load
duke
parents:
diff changeset
288 CellTypeState CellTypeState::top = CellTypeState::make_top();
a61af66fc99e Initial load
duke
parents:
diff changeset
289 CellTypeState CellTypeState::addr = CellTypeState::make_any(addr_conflict);
a61af66fc99e Initial load
duke
parents:
diff changeset
290
a61af66fc99e Initial load
duke
parents:
diff changeset
291 // Commonly used constants
a61af66fc99e Initial load
duke
parents:
diff changeset
292 static CellTypeState epsilonCTS[1] = { CellTypeState::bottom };
a61af66fc99e Initial load
duke
parents:
diff changeset
293 static CellTypeState refCTS = CellTypeState::ref;
a61af66fc99e Initial load
duke
parents:
diff changeset
294 static CellTypeState valCTS = CellTypeState::value;
a61af66fc99e Initial load
duke
parents:
diff changeset
295 static CellTypeState vCTS[2] = { CellTypeState::value, CellTypeState::bottom };
a61af66fc99e Initial load
duke
parents:
diff changeset
296 static CellTypeState rCTS[2] = { CellTypeState::ref, CellTypeState::bottom };
a61af66fc99e Initial load
duke
parents:
diff changeset
297 static CellTypeState rrCTS[3] = { CellTypeState::ref, CellTypeState::ref, CellTypeState::bottom };
a61af66fc99e Initial load
duke
parents:
diff changeset
298 static CellTypeState vrCTS[3] = { CellTypeState::value, CellTypeState::ref, CellTypeState::bottom };
a61af66fc99e Initial load
duke
parents:
diff changeset
299 static CellTypeState vvCTS[3] = { CellTypeState::value, CellTypeState::value, CellTypeState::bottom };
a61af66fc99e Initial load
duke
parents:
diff changeset
300 static CellTypeState rvrCTS[4] = { CellTypeState::ref, CellTypeState::value, CellTypeState::ref, CellTypeState::bottom };
a61af66fc99e Initial load
duke
parents:
diff changeset
301 static CellTypeState vvrCTS[4] = { CellTypeState::value, CellTypeState::value, CellTypeState::ref, CellTypeState::bottom };
a61af66fc99e Initial load
duke
parents:
diff changeset
302 static CellTypeState vvvCTS[4] = { CellTypeState::value, CellTypeState::value, CellTypeState::value, CellTypeState::bottom };
a61af66fc99e Initial load
duke
parents:
diff changeset
303 static CellTypeState vvvrCTS[5] = { CellTypeState::value, CellTypeState::value, CellTypeState::value, CellTypeState::ref, CellTypeState::bottom };
a61af66fc99e Initial load
duke
parents:
diff changeset
304 static CellTypeState vvvvCTS[5] = { CellTypeState::value, CellTypeState::value, CellTypeState::value, CellTypeState::value, CellTypeState::bottom };
a61af66fc99e Initial load
duke
parents:
diff changeset
305
a61af66fc99e Initial load
duke
parents:
diff changeset
306 char CellTypeState::to_char() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
307 if (can_be_reference()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
308 if (can_be_value() || can_be_address())
a61af66fc99e Initial load
duke
parents:
diff changeset
309 return '#'; // Conflict that needs to be rewritten
a61af66fc99e Initial load
duke
parents:
diff changeset
310 else
a61af66fc99e Initial load
duke
parents:
diff changeset
311 return 'r';
a61af66fc99e Initial load
duke
parents:
diff changeset
312 } else if (can_be_value())
a61af66fc99e Initial load
duke
parents:
diff changeset
313 return 'v';
a61af66fc99e Initial load
duke
parents:
diff changeset
314 else if (can_be_address())
a61af66fc99e Initial load
duke
parents:
diff changeset
315 return 'p';
a61af66fc99e Initial load
duke
parents:
diff changeset
316 else if (can_be_uninit())
a61af66fc99e Initial load
duke
parents:
diff changeset
317 return ' ';
a61af66fc99e Initial load
duke
parents:
diff changeset
318 else
a61af66fc99e Initial load
duke
parents:
diff changeset
319 return '@';
a61af66fc99e Initial load
duke
parents:
diff changeset
320 }
a61af66fc99e Initial load
duke
parents:
diff changeset
321
a61af66fc99e Initial load
duke
parents:
diff changeset
322
a61af66fc99e Initial load
duke
parents:
diff changeset
323 // Print a detailed CellTypeState. Indicate all bits that are set. If
a61af66fc99e Initial load
duke
parents:
diff changeset
324 // the CellTypeState represents an address or a reference, print the
a61af66fc99e Initial load
duke
parents:
diff changeset
325 // value of the additional information.
a61af66fc99e Initial load
duke
parents:
diff changeset
326 void CellTypeState::print(outputStream *os) {
a61af66fc99e Initial load
duke
parents:
diff changeset
327 if (can_be_address()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
328 os->print("(p");
a61af66fc99e Initial load
duke
parents:
diff changeset
329 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
330 os->print("( ");
a61af66fc99e Initial load
duke
parents:
diff changeset
331 }
a61af66fc99e Initial load
duke
parents:
diff changeset
332 if (can_be_reference()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
333 os->print("r");
a61af66fc99e Initial load
duke
parents:
diff changeset
334 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
335 os->print(" ");
a61af66fc99e Initial load
duke
parents:
diff changeset
336 }
a61af66fc99e Initial load
duke
parents:
diff changeset
337 if (can_be_value()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
338 os->print("v");
a61af66fc99e Initial load
duke
parents:
diff changeset
339 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
340 os->print(" ");
a61af66fc99e Initial load
duke
parents:
diff changeset
341 }
a61af66fc99e Initial load
duke
parents:
diff changeset
342 if (can_be_uninit()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
343 os->print("u|");
a61af66fc99e Initial load
duke
parents:
diff changeset
344 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
345 os->print(" |");
a61af66fc99e Initial load
duke
parents:
diff changeset
346 }
a61af66fc99e Initial load
duke
parents:
diff changeset
347 if (is_info_top()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
348 os->print("Top)");
a61af66fc99e Initial load
duke
parents:
diff changeset
349 } else if (is_info_bottom()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
350 os->print("Bot)");
a61af66fc99e Initial load
duke
parents:
diff changeset
351 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
352 if (is_reference()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
353 int info = get_info();
a61af66fc99e Initial load
duke
parents:
diff changeset
354 int data = info & ~(ref_not_lock_bit | ref_slot_bit);
a61af66fc99e Initial load
duke
parents:
diff changeset
355 if (info & ref_not_lock_bit) {
a61af66fc99e Initial load
duke
parents:
diff changeset
356 // Not a monitor lock reference.
a61af66fc99e Initial load
duke
parents:
diff changeset
357 if (info & ref_slot_bit) {
a61af66fc99e Initial load
duke
parents:
diff changeset
358 // slot
a61af66fc99e Initial load
duke
parents:
diff changeset
359 os->print("slot%d)", data);
a61af66fc99e Initial load
duke
parents:
diff changeset
360 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
361 // line
a61af66fc99e Initial load
duke
parents:
diff changeset
362 os->print("line%d)", data);
a61af66fc99e Initial load
duke
parents:
diff changeset
363 }
a61af66fc99e Initial load
duke
parents:
diff changeset
364 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
365 // lock
a61af66fc99e Initial load
duke
parents:
diff changeset
366 os->print("lock%d)", data);
a61af66fc99e Initial load
duke
parents:
diff changeset
367 }
a61af66fc99e Initial load
duke
parents:
diff changeset
368 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
369 os->print("%d)", get_info());
a61af66fc99e Initial load
duke
parents:
diff changeset
370 }
a61af66fc99e Initial load
duke
parents:
diff changeset
371 }
a61af66fc99e Initial load
duke
parents:
diff changeset
372 }
a61af66fc99e Initial load
duke
parents:
diff changeset
373
a61af66fc99e Initial load
duke
parents:
diff changeset
374 //
a61af66fc99e Initial load
duke
parents:
diff changeset
375 // Basicblock handling methods
a61af66fc99e Initial load
duke
parents:
diff changeset
376 //
a61af66fc99e Initial load
duke
parents:
diff changeset
377
a61af66fc99e Initial load
duke
parents:
diff changeset
378 void GenerateOopMap ::initialize_bb() {
a61af66fc99e Initial load
duke
parents:
diff changeset
379 _gc_points = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
380 _bb_count = 0;
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
381 _bb_hdr_bits.clear();
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
382 _bb_hdr_bits.resize(method()->code_size());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
383 }
a61af66fc99e Initial load
duke
parents:
diff changeset
384
a61af66fc99e Initial load
duke
parents:
diff changeset
385 void GenerateOopMap::bb_mark_fct(GenerateOopMap *c, int bci, int *data) {
a61af66fc99e Initial load
duke
parents:
diff changeset
386 assert(bci>= 0 && bci < c->method()->code_size(), "index out of bounds");
a61af66fc99e Initial load
duke
parents:
diff changeset
387 if (c->is_bb_header(bci))
a61af66fc99e Initial load
duke
parents:
diff changeset
388 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
389
a61af66fc99e Initial load
duke
parents:
diff changeset
390 if (TraceNewOopMapGeneration) {
a61af66fc99e Initial load
duke
parents:
diff changeset
391 tty->print_cr("Basicblock#%d begins at: %d", c->_bb_count, bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
392 }
a61af66fc99e Initial load
duke
parents:
diff changeset
393 c->set_bbmark_bit(bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
394 c->_bb_count++;
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 void GenerateOopMap::mark_bbheaders_and_count_gc_points() {
a61af66fc99e Initial load
duke
parents:
diff changeset
399 initialize_bb();
a61af66fc99e Initial load
duke
parents:
diff changeset
400
a61af66fc99e Initial load
duke
parents:
diff changeset
401 bool fellThrough = false; // False to get first BB marked.
a61af66fc99e Initial load
duke
parents:
diff changeset
402
a61af66fc99e Initial load
duke
parents:
diff changeset
403 // First mark all exception handlers as start of a basic-block
6213
8150fa46d2ed 7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents: 3865
diff changeset
404 ExceptionTable excps(method());
8150fa46d2ed 7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents: 3865
diff changeset
405 for(int i = 0; i < excps.length(); i ++) {
8150fa46d2ed 7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents: 3865
diff changeset
406 bb_mark_fct(this, excps.handler_pc(i), NULL);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
407 }
a61af66fc99e Initial load
duke
parents:
diff changeset
408
a61af66fc99e Initial load
duke
parents:
diff changeset
409 // Then iterate through the code
a61af66fc99e Initial load
duke
parents:
diff changeset
410 BytecodeStream bcs(_method);
a61af66fc99e Initial load
duke
parents:
diff changeset
411 Bytecodes::Code bytecode;
a61af66fc99e Initial load
duke
parents:
diff changeset
412
a61af66fc99e Initial load
duke
parents:
diff changeset
413 while( (bytecode = bcs.next()) >= 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
414 int bci = bcs.bci();
a61af66fc99e Initial load
duke
parents:
diff changeset
415
a61af66fc99e Initial load
duke
parents:
diff changeset
416 if (!fellThrough)
a61af66fc99e Initial load
duke
parents:
diff changeset
417 bb_mark_fct(this, bci, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
418
a61af66fc99e Initial load
duke
parents:
diff changeset
419 fellThrough = jump_targets_do(&bcs, &GenerateOopMap::bb_mark_fct, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
420
a61af66fc99e Initial load
duke
parents:
diff changeset
421 /* We will also mark successors of jsr's as basic block headers. */
a61af66fc99e Initial load
duke
parents:
diff changeset
422 switch (bytecode) {
a61af66fc99e Initial load
duke
parents:
diff changeset
423 case Bytecodes::_jsr:
a61af66fc99e Initial load
duke
parents:
diff changeset
424 assert(!fellThrough, "should not happen");
a61af66fc99e Initial load
duke
parents:
diff changeset
425 bb_mark_fct(this, bci + Bytecodes::length_for(bytecode), NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
426 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
427 case Bytecodes::_jsr_w:
a61af66fc99e Initial load
duke
parents:
diff changeset
428 assert(!fellThrough, "should not happen");
a61af66fc99e Initial load
duke
parents:
diff changeset
429 bb_mark_fct(this, bci + Bytecodes::length_for(bytecode), NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
430 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
431 }
a61af66fc99e Initial load
duke
parents:
diff changeset
432
a61af66fc99e Initial load
duke
parents:
diff changeset
433 if (possible_gc_point(&bcs))
a61af66fc99e Initial load
duke
parents:
diff changeset
434 _gc_points++;
a61af66fc99e Initial load
duke
parents:
diff changeset
435 }
a61af66fc99e Initial load
duke
parents:
diff changeset
436 }
a61af66fc99e Initial load
duke
parents:
diff changeset
437
a61af66fc99e Initial load
duke
parents:
diff changeset
438 void GenerateOopMap::reachable_basicblock(GenerateOopMap *c, int bci, int *data) {
a61af66fc99e Initial load
duke
parents:
diff changeset
439 assert(bci>= 0 && bci < c->method()->code_size(), "index out of bounds");
a61af66fc99e Initial load
duke
parents:
diff changeset
440 BasicBlock* bb = c->get_basic_block_at(bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
441 if (bb->is_dead()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
442 bb->mark_as_alive();
a61af66fc99e Initial load
duke
parents:
diff changeset
443 *data = 1; // Mark basicblock as changed
a61af66fc99e Initial load
duke
parents:
diff changeset
444 }
a61af66fc99e Initial load
duke
parents:
diff changeset
445 }
a61af66fc99e Initial load
duke
parents:
diff changeset
446
a61af66fc99e Initial load
duke
parents:
diff changeset
447
a61af66fc99e Initial load
duke
parents:
diff changeset
448 void GenerateOopMap::mark_reachable_code() {
a61af66fc99e Initial load
duke
parents:
diff changeset
449 int change = 1; // int to get function pointers to work
a61af66fc99e Initial load
duke
parents:
diff changeset
450
a61af66fc99e Initial load
duke
parents:
diff changeset
451 // Mark entry basic block as alive and all exception handlers
a61af66fc99e Initial load
duke
parents:
diff changeset
452 _basic_blocks[0].mark_as_alive();
6213
8150fa46d2ed 7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents: 3865
diff changeset
453 ExceptionTable excps(method());
8150fa46d2ed 7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents: 3865
diff changeset
454 for(int i = 0; i < excps.length(); i++) {
8150fa46d2ed 7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents: 3865
diff changeset
455 BasicBlock *bb = get_basic_block_at(excps.handler_pc(i));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
456 // If block is not already alive (due to multiple exception handlers to same bb), then
a61af66fc99e Initial load
duke
parents:
diff changeset
457 // make it alive
a61af66fc99e Initial load
duke
parents:
diff changeset
458 if (bb->is_dead()) bb->mark_as_alive();
a61af66fc99e Initial load
duke
parents:
diff changeset
459 }
a61af66fc99e Initial load
duke
parents:
diff changeset
460
a61af66fc99e Initial load
duke
parents:
diff changeset
461 BytecodeStream bcs(_method);
a61af66fc99e Initial load
duke
parents:
diff changeset
462
a61af66fc99e Initial load
duke
parents:
diff changeset
463 // Iterate through all basic blocks until we reach a fixpoint
a61af66fc99e Initial load
duke
parents:
diff changeset
464 while (change) {
a61af66fc99e Initial load
duke
parents:
diff changeset
465 change = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
466
a61af66fc99e Initial load
duke
parents:
diff changeset
467 for (int i = 0; i < _bb_count; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
468 BasicBlock *bb = &_basic_blocks[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
469 if (bb->is_alive()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
470 // Position bytecodestream at last bytecode in basicblock
a61af66fc99e Initial load
duke
parents:
diff changeset
471 bcs.set_start(bb->_end_bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
472 bcs.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
473 Bytecodes::Code bytecode = bcs.code();
a61af66fc99e Initial load
duke
parents:
diff changeset
474 int bci = bcs.bci();
a61af66fc99e Initial load
duke
parents:
diff changeset
475 assert(bci == bb->_end_bci, "wrong bci");
a61af66fc99e Initial load
duke
parents:
diff changeset
476
a61af66fc99e Initial load
duke
parents:
diff changeset
477 bool fell_through = jump_targets_do(&bcs, &GenerateOopMap::reachable_basicblock, &change);
a61af66fc99e Initial load
duke
parents:
diff changeset
478
a61af66fc99e Initial load
duke
parents:
diff changeset
479 // We will also mark successors of jsr's as alive.
a61af66fc99e Initial load
duke
parents:
diff changeset
480 switch (bytecode) {
a61af66fc99e Initial load
duke
parents:
diff changeset
481 case Bytecodes::_jsr:
a61af66fc99e Initial load
duke
parents:
diff changeset
482 case Bytecodes::_jsr_w:
a61af66fc99e Initial load
duke
parents:
diff changeset
483 assert(!fell_through, "should not happen");
a61af66fc99e Initial load
duke
parents:
diff changeset
484 reachable_basicblock(this, bci + Bytecodes::length_for(bytecode), &change);
a61af66fc99e Initial load
duke
parents:
diff changeset
485 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
486 }
a61af66fc99e Initial load
duke
parents:
diff changeset
487 if (fell_through) {
a61af66fc99e Initial load
duke
parents:
diff changeset
488 // Mark successor as alive
a61af66fc99e Initial load
duke
parents:
diff changeset
489 if (bb[1].is_dead()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
490 bb[1].mark_as_alive();
a61af66fc99e Initial load
duke
parents:
diff changeset
491 change = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
492 }
a61af66fc99e Initial load
duke
parents:
diff changeset
493 }
a61af66fc99e Initial load
duke
parents:
diff changeset
494 }
a61af66fc99e Initial load
duke
parents:
diff changeset
495 }
a61af66fc99e Initial load
duke
parents:
diff changeset
496 }
a61af66fc99e Initial load
duke
parents:
diff changeset
497 }
a61af66fc99e Initial load
duke
parents:
diff changeset
498
a61af66fc99e Initial load
duke
parents:
diff changeset
499 /* If the current instruction in "c" has no effect on control flow,
a61af66fc99e Initial load
duke
parents:
diff changeset
500 returns "true". Otherwise, calls "jmpFct" one or more times, with
a61af66fc99e Initial load
duke
parents:
diff changeset
501 "c", an appropriate "pcDelta", and "data" as arguments, then
a61af66fc99e Initial load
duke
parents:
diff changeset
502 returns "false". There is one exception: if the current
a61af66fc99e Initial load
duke
parents:
diff changeset
503 instruction is a "ret", returns "false" without calling "jmpFct".
a61af66fc99e Initial load
duke
parents:
diff changeset
504 Arrangements for tracking the control flow of a "ret" must be made
a61af66fc99e Initial load
duke
parents:
diff changeset
505 externally. */
a61af66fc99e Initial load
duke
parents:
diff changeset
506 bool GenerateOopMap::jump_targets_do(BytecodeStream *bcs, jmpFct_t jmpFct, int *data) {
a61af66fc99e Initial load
duke
parents:
diff changeset
507 int bci = bcs->bci();
a61af66fc99e Initial load
duke
parents:
diff changeset
508
a61af66fc99e Initial load
duke
parents:
diff changeset
509 switch (bcs->code()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
510 case Bytecodes::_ifeq:
a61af66fc99e Initial load
duke
parents:
diff changeset
511 case Bytecodes::_ifne:
a61af66fc99e Initial load
duke
parents:
diff changeset
512 case Bytecodes::_iflt:
a61af66fc99e Initial load
duke
parents:
diff changeset
513 case Bytecodes::_ifge:
a61af66fc99e Initial load
duke
parents:
diff changeset
514 case Bytecodes::_ifgt:
a61af66fc99e Initial load
duke
parents:
diff changeset
515 case Bytecodes::_ifle:
a61af66fc99e Initial load
duke
parents:
diff changeset
516 case Bytecodes::_if_icmpeq:
a61af66fc99e Initial load
duke
parents:
diff changeset
517 case Bytecodes::_if_icmpne:
a61af66fc99e Initial load
duke
parents:
diff changeset
518 case Bytecodes::_if_icmplt:
a61af66fc99e Initial load
duke
parents:
diff changeset
519 case Bytecodes::_if_icmpge:
a61af66fc99e Initial load
duke
parents:
diff changeset
520 case Bytecodes::_if_icmpgt:
a61af66fc99e Initial load
duke
parents:
diff changeset
521 case Bytecodes::_if_icmple:
a61af66fc99e Initial load
duke
parents:
diff changeset
522 case Bytecodes::_if_acmpeq:
a61af66fc99e Initial load
duke
parents:
diff changeset
523 case Bytecodes::_if_acmpne:
a61af66fc99e Initial load
duke
parents:
diff changeset
524 case Bytecodes::_ifnull:
a61af66fc99e Initial load
duke
parents:
diff changeset
525 case Bytecodes::_ifnonnull:
a61af66fc99e Initial load
duke
parents:
diff changeset
526 (*jmpFct)(this, bcs->dest(), data);
a61af66fc99e Initial load
duke
parents:
diff changeset
527 (*jmpFct)(this, bci + 3, data);
a61af66fc99e Initial load
duke
parents:
diff changeset
528 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
529
a61af66fc99e Initial load
duke
parents:
diff changeset
530 case Bytecodes::_goto:
a61af66fc99e Initial load
duke
parents:
diff changeset
531 (*jmpFct)(this, bcs->dest(), data);
a61af66fc99e Initial load
duke
parents:
diff changeset
532 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
533 case Bytecodes::_goto_w:
a61af66fc99e Initial load
duke
parents:
diff changeset
534 (*jmpFct)(this, bcs->dest_w(), data);
a61af66fc99e Initial load
duke
parents:
diff changeset
535 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
536 case Bytecodes::_tableswitch:
2142
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
537 { Bytecode_tableswitch tableswitch(method(), bcs->bcp());
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
538 int len = tableswitch.length();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
539
2142
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
540 (*jmpFct)(this, bci + tableswitch.default_offset(), data); /* Default. jump address */
0
a61af66fc99e Initial load
duke
parents:
diff changeset
541 while (--len >= 0) {
2142
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
542 (*jmpFct)(this, bci + tableswitch.dest_offset_at(len), data);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
543 }
a61af66fc99e Initial load
duke
parents:
diff changeset
544 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
545 }
a61af66fc99e Initial load
duke
parents:
diff changeset
546
a61af66fc99e Initial load
duke
parents:
diff changeset
547 case Bytecodes::_lookupswitch:
2142
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
548 { Bytecode_lookupswitch lookupswitch(method(), bcs->bcp());
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
549 int npairs = lookupswitch.number_of_pairs();
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
550 (*jmpFct)(this, bci + lookupswitch.default_offset(), data); /* Default. */
0
a61af66fc99e Initial load
duke
parents:
diff changeset
551 while(--npairs >= 0) {
2142
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
552 LookupswitchPair pair = lookupswitch.pair_at(npairs);
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
553 (*jmpFct)(this, bci + pair.offset(), data);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
554 }
a61af66fc99e Initial load
duke
parents:
diff changeset
555 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
556 }
a61af66fc99e Initial load
duke
parents:
diff changeset
557 case Bytecodes::_jsr:
a61af66fc99e Initial load
duke
parents:
diff changeset
558 assert(bcs->is_wide()==false, "sanity check");
a61af66fc99e Initial load
duke
parents:
diff changeset
559 (*jmpFct)(this, bcs->dest(), data);
a61af66fc99e Initial load
duke
parents:
diff changeset
560
a61af66fc99e Initial load
duke
parents:
diff changeset
561
a61af66fc99e Initial load
duke
parents:
diff changeset
562
a61af66fc99e Initial load
duke
parents:
diff changeset
563 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
564 case Bytecodes::_jsr_w:
a61af66fc99e Initial load
duke
parents:
diff changeset
565 (*jmpFct)(this, bcs->dest_w(), data);
a61af66fc99e Initial load
duke
parents:
diff changeset
566 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
567 case Bytecodes::_wide:
a61af66fc99e Initial load
duke
parents:
diff changeset
568 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
569 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
570 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
571 case Bytecodes::_athrow:
a61af66fc99e Initial load
duke
parents:
diff changeset
572 case Bytecodes::_ireturn:
a61af66fc99e Initial load
duke
parents:
diff changeset
573 case Bytecodes::_lreturn:
a61af66fc99e Initial load
duke
parents:
diff changeset
574 case Bytecodes::_freturn:
a61af66fc99e Initial load
duke
parents:
diff changeset
575 case Bytecodes::_dreturn:
a61af66fc99e Initial load
duke
parents:
diff changeset
576 case Bytecodes::_areturn:
a61af66fc99e Initial load
duke
parents:
diff changeset
577 case Bytecodes::_return:
a61af66fc99e Initial load
duke
parents:
diff changeset
578 case Bytecodes::_ret:
a61af66fc99e Initial load
duke
parents:
diff changeset
579 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
580 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
581 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
582 }
a61af66fc99e Initial load
duke
parents:
diff changeset
583 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
584 }
a61af66fc99e Initial load
duke
parents:
diff changeset
585
a61af66fc99e Initial load
duke
parents:
diff changeset
586 /* Requires "pc" to be the head of a basic block; returns that basic
a61af66fc99e Initial load
duke
parents:
diff changeset
587 block. */
a61af66fc99e Initial load
duke
parents:
diff changeset
588 BasicBlock *GenerateOopMap::get_basic_block_at(int bci) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
589 BasicBlock* bb = get_basic_block_containing(bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
590 assert(bb->_bci == bci, "should have found BB");
a61af66fc99e Initial load
duke
parents:
diff changeset
591 return bb;
a61af66fc99e Initial load
duke
parents:
diff changeset
592 }
a61af66fc99e Initial load
duke
parents:
diff changeset
593
a61af66fc99e Initial load
duke
parents:
diff changeset
594 // Requires "pc" to be the start of an instruction; returns the basic
a61af66fc99e Initial load
duke
parents:
diff changeset
595 // block containing that instruction. */
a61af66fc99e Initial load
duke
parents:
diff changeset
596 BasicBlock *GenerateOopMap::get_basic_block_containing(int bci) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
597 BasicBlock *bbs = _basic_blocks;
a61af66fc99e Initial load
duke
parents:
diff changeset
598 int lo = 0, hi = _bb_count - 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
599
a61af66fc99e Initial load
duke
parents:
diff changeset
600 while (lo <= hi) {
a61af66fc99e Initial load
duke
parents:
diff changeset
601 int m = (lo + hi) / 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
602 int mbci = bbs[m]._bci;
a61af66fc99e Initial load
duke
parents:
diff changeset
603 int nbci;
a61af66fc99e Initial load
duke
parents:
diff changeset
604
a61af66fc99e Initial load
duke
parents:
diff changeset
605 if ( m == _bb_count-1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
606 assert( bci >= mbci && bci < method()->code_size(), "sanity check failed");
a61af66fc99e Initial load
duke
parents:
diff changeset
607 return bbs+m;
a61af66fc99e Initial load
duke
parents:
diff changeset
608 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
609 nbci = bbs[m+1]._bci;
a61af66fc99e Initial load
duke
parents:
diff changeset
610 }
a61af66fc99e Initial load
duke
parents:
diff changeset
611
a61af66fc99e Initial load
duke
parents:
diff changeset
612 if ( mbci <= bci && bci < nbci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
613 return bbs+m;
a61af66fc99e Initial load
duke
parents:
diff changeset
614 } else if (mbci < bci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
615 lo = m + 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
616 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
617 assert(mbci > bci, "sanity check");
a61af66fc99e Initial load
duke
parents:
diff changeset
618 hi = m - 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
619 }
a61af66fc99e Initial load
duke
parents:
diff changeset
620 }
a61af66fc99e Initial load
duke
parents:
diff changeset
621
a61af66fc99e Initial load
duke
parents:
diff changeset
622 fatal("should have found BB");
a61af66fc99e Initial load
duke
parents:
diff changeset
623 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
624 }
a61af66fc99e Initial load
duke
parents:
diff changeset
625
a61af66fc99e Initial load
duke
parents:
diff changeset
626 void GenerateOopMap::restore_state(BasicBlock *bb)
a61af66fc99e Initial load
duke
parents:
diff changeset
627 {
a61af66fc99e Initial load
duke
parents:
diff changeset
628 memcpy(_state, bb->_state, _state_len*sizeof(CellTypeState));
a61af66fc99e Initial load
duke
parents:
diff changeset
629 _stack_top = bb->_stack_top;
a61af66fc99e Initial load
duke
parents:
diff changeset
630 _monitor_top = bb->_monitor_top;
a61af66fc99e Initial load
duke
parents:
diff changeset
631 }
a61af66fc99e Initial load
duke
parents:
diff changeset
632
a61af66fc99e Initial load
duke
parents:
diff changeset
633 int GenerateOopMap::next_bb_start_pc(BasicBlock *bb) {
a61af66fc99e Initial load
duke
parents:
diff changeset
634 int bbNum = bb - _basic_blocks + 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
635 if (bbNum == _bb_count)
a61af66fc99e Initial load
duke
parents:
diff changeset
636 return method()->code_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
637
a61af66fc99e Initial load
duke
parents:
diff changeset
638 return _basic_blocks[bbNum]._bci;
a61af66fc99e Initial load
duke
parents:
diff changeset
639 }
a61af66fc99e Initial load
duke
parents:
diff changeset
640
a61af66fc99e Initial load
duke
parents:
diff changeset
641 //
a61af66fc99e Initial load
duke
parents:
diff changeset
642 // CellType handling methods
a61af66fc99e Initial load
duke
parents:
diff changeset
643 //
a61af66fc99e Initial load
duke
parents:
diff changeset
644
11009
f75faf51e8c4 7158805: Better rewriting of nested subroutine calls
hseigel
parents: 8773
diff changeset
645 // Allocate memory and throw LinkageError if failure.
f75faf51e8c4 7158805: Better rewriting of nested subroutine calls
hseigel
parents: 8773
diff changeset
646 #define ALLOC_RESOURCE_ARRAY(var, type, count) \
f75faf51e8c4 7158805: Better rewriting of nested subroutine calls
hseigel
parents: 8773
diff changeset
647 var = NEW_RESOURCE_ARRAY_RETURN_NULL(type, count); \
f75faf51e8c4 7158805: Better rewriting of nested subroutine calls
hseigel
parents: 8773
diff changeset
648 if (var == NULL) { \
f75faf51e8c4 7158805: Better rewriting of nested subroutine calls
hseigel
parents: 8773
diff changeset
649 report_error("Cannot reserve enough memory to analyze this method"); \
f75faf51e8c4 7158805: Better rewriting of nested subroutine calls
hseigel
parents: 8773
diff changeset
650 return; \
f75faf51e8c4 7158805: Better rewriting of nested subroutine calls
hseigel
parents: 8773
diff changeset
651 }
f75faf51e8c4 7158805: Better rewriting of nested subroutine calls
hseigel
parents: 8773
diff changeset
652
f75faf51e8c4 7158805: Better rewriting of nested subroutine calls
hseigel
parents: 8773
diff changeset
653
0
a61af66fc99e Initial load
duke
parents:
diff changeset
654 void GenerateOopMap::init_state() {
a61af66fc99e Initial load
duke
parents:
diff changeset
655 _state_len = _max_locals + _max_stack + _max_monitors;
11009
f75faf51e8c4 7158805: Better rewriting of nested subroutine calls
hseigel
parents: 8773
diff changeset
656 ALLOC_RESOURCE_ARRAY(_state, CellTypeState, _state_len);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
657 memset(_state, 0, _state_len * sizeof(CellTypeState));
11009
f75faf51e8c4 7158805: Better rewriting of nested subroutine calls
hseigel
parents: 8773
diff changeset
658 int count = MAX3(_max_locals, _max_stack, _max_monitors) + 1/*for null terminator char */;
f75faf51e8c4 7158805: Better rewriting of nested subroutine calls
hseigel
parents: 8773
diff changeset
659 ALLOC_RESOURCE_ARRAY(_state_vec_buf, char, count);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
660 }
a61af66fc99e Initial load
duke
parents:
diff changeset
661
a61af66fc99e Initial load
duke
parents:
diff changeset
662 void GenerateOopMap::make_context_uninitialized() {
a61af66fc99e Initial load
duke
parents:
diff changeset
663 CellTypeState* vs = vars();
a61af66fc99e Initial load
duke
parents:
diff changeset
664
a61af66fc99e Initial load
duke
parents:
diff changeset
665 for (int i = 0; i < _max_locals; i++)
a61af66fc99e Initial load
duke
parents:
diff changeset
666 vs[i] = CellTypeState::uninit;
a61af66fc99e Initial load
duke
parents:
diff changeset
667
a61af66fc99e Initial load
duke
parents:
diff changeset
668 _stack_top = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
669 _monitor_top = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
670 }
a61af66fc99e Initial load
duke
parents:
diff changeset
671
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 2142
diff changeset
672 int GenerateOopMap::methodsig_to_effect(Symbol* signature, bool is_static, CellTypeState* effect) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
673 ComputeEntryStack ces(signature);
a61af66fc99e Initial load
duke
parents:
diff changeset
674 return ces.compute_for_parameters(is_static, effect);
a61af66fc99e Initial load
duke
parents:
diff changeset
675 }
a61af66fc99e Initial load
duke
parents:
diff changeset
676
a61af66fc99e Initial load
duke
parents:
diff changeset
677 // Return result of merging cts1 and cts2.
a61af66fc99e Initial load
duke
parents:
diff changeset
678 CellTypeState CellTypeState::merge(CellTypeState cts, int slot) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
679 CellTypeState result;
a61af66fc99e Initial load
duke
parents:
diff changeset
680
a61af66fc99e Initial load
duke
parents:
diff changeset
681 assert(!is_bottom() && !cts.is_bottom(),
a61af66fc99e Initial load
duke
parents:
diff changeset
682 "merge of bottom values is handled elsewhere");
a61af66fc99e Initial load
duke
parents:
diff changeset
683
a61af66fc99e Initial load
duke
parents:
diff changeset
684 result._state = _state | cts._state;
a61af66fc99e Initial load
duke
parents:
diff changeset
685
a61af66fc99e Initial load
duke
parents:
diff changeset
686 // If the top bit is set, we don't need to do any more work.
a61af66fc99e Initial load
duke
parents:
diff changeset
687 if (!result.is_info_top()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
688 assert((result.can_be_address() || result.can_be_reference()),
a61af66fc99e Initial load
duke
parents:
diff changeset
689 "only addresses and references have non-top info");
a61af66fc99e Initial load
duke
parents:
diff changeset
690
a61af66fc99e Initial load
duke
parents:
diff changeset
691 if (!equal(cts)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
692 // The two values being merged are different. Raise to top.
a61af66fc99e Initial load
duke
parents:
diff changeset
693 if (result.is_reference()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
694 result = CellTypeState::make_slot_ref(slot);
a61af66fc99e Initial load
duke
parents:
diff changeset
695 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
696 result._state |= info_conflict;
a61af66fc99e Initial load
duke
parents:
diff changeset
697 }
a61af66fc99e Initial load
duke
parents:
diff changeset
698 }
a61af66fc99e Initial load
duke
parents:
diff changeset
699 }
a61af66fc99e Initial load
duke
parents:
diff changeset
700 assert(result.is_valid_state(), "checking that CTS merge maintains legal state");
a61af66fc99e Initial load
duke
parents:
diff changeset
701
a61af66fc99e Initial load
duke
parents:
diff changeset
702 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
703 }
a61af66fc99e Initial load
duke
parents:
diff changeset
704
a61af66fc99e Initial load
duke
parents:
diff changeset
705 // Merge the variable state for locals and stack from cts into bbts.
a61af66fc99e Initial load
duke
parents:
diff changeset
706 bool GenerateOopMap::merge_local_state_vectors(CellTypeState* cts,
a61af66fc99e Initial load
duke
parents:
diff changeset
707 CellTypeState* bbts) {
a61af66fc99e Initial load
duke
parents:
diff changeset
708 int i;
a61af66fc99e Initial load
duke
parents:
diff changeset
709 int len = _max_locals + _stack_top;
a61af66fc99e Initial load
duke
parents:
diff changeset
710 bool change = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
711
a61af66fc99e Initial load
duke
parents:
diff changeset
712 for (i = len - 1; i >= 0; i--) {
a61af66fc99e Initial load
duke
parents:
diff changeset
713 CellTypeState v = cts[i].merge(bbts[i], i);
a61af66fc99e Initial load
duke
parents:
diff changeset
714 change = change || !v.equal(bbts[i]);
a61af66fc99e Initial load
duke
parents:
diff changeset
715 bbts[i] = v;
a61af66fc99e Initial load
duke
parents:
diff changeset
716 }
a61af66fc99e Initial load
duke
parents:
diff changeset
717
a61af66fc99e Initial load
duke
parents:
diff changeset
718 return change;
a61af66fc99e Initial load
duke
parents:
diff changeset
719 }
a61af66fc99e Initial load
duke
parents:
diff changeset
720
a61af66fc99e Initial load
duke
parents:
diff changeset
721 // Merge the monitor stack state from cts into bbts.
a61af66fc99e Initial load
duke
parents:
diff changeset
722 bool GenerateOopMap::merge_monitor_state_vectors(CellTypeState* cts,
a61af66fc99e Initial load
duke
parents:
diff changeset
723 CellTypeState* bbts) {
a61af66fc99e Initial load
duke
parents:
diff changeset
724 bool change = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
725 if (_max_monitors > 0 && _monitor_top != bad_monitors) {
a61af66fc99e Initial load
duke
parents:
diff changeset
726 // If there are no monitors in the program, or there has been
a61af66fc99e Initial load
duke
parents:
diff changeset
727 // a monitor matching error before this point in the program,
a61af66fc99e Initial load
duke
parents:
diff changeset
728 // then we do not merge in the monitor state.
a61af66fc99e Initial load
duke
parents:
diff changeset
729
a61af66fc99e Initial load
duke
parents:
diff changeset
730 int base = _max_locals + _max_stack;
a61af66fc99e Initial load
duke
parents:
diff changeset
731 int len = base + _monitor_top;
a61af66fc99e Initial load
duke
parents:
diff changeset
732 for (int i = len - 1; i >= base; i--) {
a61af66fc99e Initial load
duke
parents:
diff changeset
733 CellTypeState v = cts[i].merge(bbts[i], i);
a61af66fc99e Initial load
duke
parents:
diff changeset
734
a61af66fc99e Initial load
duke
parents:
diff changeset
735 // Can we prove that, when there has been a change, it will already
a61af66fc99e Initial load
duke
parents:
diff changeset
736 // have been detected at this point? That would make this equal
a61af66fc99e Initial load
duke
parents:
diff changeset
737 // check here unnecessary.
a61af66fc99e Initial load
duke
parents:
diff changeset
738 change = change || !v.equal(bbts[i]);
a61af66fc99e Initial load
duke
parents:
diff changeset
739 bbts[i] = v;
a61af66fc99e Initial load
duke
parents:
diff changeset
740 }
a61af66fc99e Initial load
duke
parents:
diff changeset
741 }
a61af66fc99e Initial load
duke
parents:
diff changeset
742
a61af66fc99e Initial load
duke
parents:
diff changeset
743 return change;
a61af66fc99e Initial load
duke
parents:
diff changeset
744 }
a61af66fc99e Initial load
duke
parents:
diff changeset
745
a61af66fc99e Initial load
duke
parents:
diff changeset
746 void GenerateOopMap::copy_state(CellTypeState *dst, CellTypeState *src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
747 int len = _max_locals + _stack_top;
a61af66fc99e Initial load
duke
parents:
diff changeset
748 for (int i = 0; i < len; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
749 if (src[i].is_nonlock_reference()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
750 dst[i] = CellTypeState::make_slot_ref(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
751 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
752 dst[i] = src[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
753 }
a61af66fc99e Initial load
duke
parents:
diff changeset
754 }
a61af66fc99e Initial load
duke
parents:
diff changeset
755 if (_max_monitors > 0 && _monitor_top != bad_monitors) {
a61af66fc99e Initial load
duke
parents:
diff changeset
756 int base = _max_locals + _max_stack;
a61af66fc99e Initial load
duke
parents:
diff changeset
757 len = base + _monitor_top;
a61af66fc99e Initial load
duke
parents:
diff changeset
758 for (int i = base; i < len; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
759 dst[i] = src[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
760 }
a61af66fc99e Initial load
duke
parents:
diff changeset
761 }
a61af66fc99e Initial load
duke
parents:
diff changeset
762 }
a61af66fc99e Initial load
duke
parents:
diff changeset
763
a61af66fc99e Initial load
duke
parents:
diff changeset
764
a61af66fc99e Initial load
duke
parents:
diff changeset
765 // Merge the states for the current block and the next. As long as a
a61af66fc99e Initial load
duke
parents:
diff changeset
766 // block is reachable the locals and stack must be merged. If the
a61af66fc99e Initial load
duke
parents:
diff changeset
767 // stack heights don't match then this is a verification error and
a61af66fc99e Initial load
duke
parents:
diff changeset
768 // it's impossible to interpret the code. Simultaneously monitor
a61af66fc99e Initial load
duke
parents:
diff changeset
769 // states are being check to see if they nest statically. If monitor
a61af66fc99e Initial load
duke
parents:
diff changeset
770 // depths match up then their states are merged. Otherwise the
a61af66fc99e Initial load
duke
parents:
diff changeset
771 // mismatch is simply recorded and interpretation continues since
a61af66fc99e Initial load
duke
parents:
diff changeset
772 // monitor matching is purely informational and doesn't say anything
a61af66fc99e Initial load
duke
parents:
diff changeset
773 // about the correctness of the code.
a61af66fc99e Initial load
duke
parents:
diff changeset
774 void GenerateOopMap::merge_state_into_bb(BasicBlock *bb) {
8773
2eef6d34833b 8009022: [parfait] Null pointer deference in hotspot/src/share/vm/oops/generateOopMap.cpp
morris
parents: 8104
diff changeset
775 guarantee(bb != NULL, "null basicblock");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
776 assert(bb->is_alive(), "merging state into a dead basicblock");
a61af66fc99e Initial load
duke
parents:
diff changeset
777
a61af66fc99e Initial load
duke
parents:
diff changeset
778 if (_stack_top == bb->_stack_top) {
a61af66fc99e Initial load
duke
parents:
diff changeset
779 // always merge local state even if monitors don't match.
a61af66fc99e Initial load
duke
parents:
diff changeset
780 if (merge_local_state_vectors(_state, bb->_state)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
781 bb->set_changed(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
782 }
a61af66fc99e Initial load
duke
parents:
diff changeset
783 if (_monitor_top == bb->_monitor_top) {
a61af66fc99e Initial load
duke
parents:
diff changeset
784 // monitors still match so continue merging monitor states.
a61af66fc99e Initial load
duke
parents:
diff changeset
785 if (merge_monitor_state_vectors(_state, bb->_state)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
786 bb->set_changed(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
787 }
a61af66fc99e Initial load
duke
parents:
diff changeset
788 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
789 if (TraceMonitorMismatch) {
a61af66fc99e Initial load
duke
parents:
diff changeset
790 report_monitor_mismatch("monitor stack height merge conflict");
a61af66fc99e Initial load
duke
parents:
diff changeset
791 }
a61af66fc99e Initial load
duke
parents:
diff changeset
792 // When the monitor stacks are not matched, we set _monitor_top to
a61af66fc99e Initial load
duke
parents:
diff changeset
793 // bad_monitors. This signals that, from here on, the monitor stack cannot
a61af66fc99e Initial load
duke
parents:
diff changeset
794 // be trusted. In particular, monitorexit bytecodes may throw
a61af66fc99e Initial load
duke
parents:
diff changeset
795 // exceptions. We mark this block as changed so that the change
a61af66fc99e Initial load
duke
parents:
diff changeset
796 // propagates properly.
a61af66fc99e Initial load
duke
parents:
diff changeset
797 bb->_monitor_top = bad_monitors;
a61af66fc99e Initial load
duke
parents:
diff changeset
798 bb->set_changed(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
799 _monitor_safe = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
800 }
a61af66fc99e Initial load
duke
parents:
diff changeset
801 } else if (!bb->is_reachable()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
802 // First time we look at this BB
a61af66fc99e Initial load
duke
parents:
diff changeset
803 copy_state(bb->_state, _state);
a61af66fc99e Initial load
duke
parents:
diff changeset
804 bb->_stack_top = _stack_top;
a61af66fc99e Initial load
duke
parents:
diff changeset
805 bb->_monitor_top = _monitor_top;
a61af66fc99e Initial load
duke
parents:
diff changeset
806 bb->set_changed(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
807 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
808 verify_error("stack height conflict: %d vs. %d", _stack_top, bb->_stack_top);
a61af66fc99e Initial load
duke
parents:
diff changeset
809 }
a61af66fc99e Initial load
duke
parents:
diff changeset
810 }
a61af66fc99e Initial load
duke
parents:
diff changeset
811
a61af66fc99e Initial load
duke
parents:
diff changeset
812 void GenerateOopMap::merge_state(GenerateOopMap *gom, int bci, int* data) {
a61af66fc99e Initial load
duke
parents:
diff changeset
813 gom->merge_state_into_bb(gom->get_basic_block_at(bci));
a61af66fc99e Initial load
duke
parents:
diff changeset
814 }
a61af66fc99e Initial load
duke
parents:
diff changeset
815
a61af66fc99e Initial load
duke
parents:
diff changeset
816 void GenerateOopMap::set_var(int localNo, CellTypeState cts) {
a61af66fc99e Initial load
duke
parents:
diff changeset
817 assert(cts.is_reference() || cts.is_value() || cts.is_address(),
a61af66fc99e Initial load
duke
parents:
diff changeset
818 "wrong celltypestate");
a61af66fc99e Initial load
duke
parents:
diff changeset
819 if (localNo < 0 || localNo > _max_locals) {
a61af66fc99e Initial load
duke
parents:
diff changeset
820 verify_error("variable write error: r%d", localNo);
a61af66fc99e Initial load
duke
parents:
diff changeset
821 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
822 }
a61af66fc99e Initial load
duke
parents:
diff changeset
823 vars()[localNo] = cts;
a61af66fc99e Initial load
duke
parents:
diff changeset
824 }
a61af66fc99e Initial load
duke
parents:
diff changeset
825
a61af66fc99e Initial load
duke
parents:
diff changeset
826 CellTypeState GenerateOopMap::get_var(int localNo) {
1489
cff162798819 6888953: some calls to function-like macros are missing semicolons
jcoomes
parents: 1138
diff changeset
827 assert(localNo < _max_locals + _nof_refval_conflicts, "variable read error");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
828 if (localNo < 0 || localNo > _max_locals) {
a61af66fc99e Initial load
duke
parents:
diff changeset
829 verify_error("variable read error: r%d", localNo);
a61af66fc99e Initial load
duke
parents:
diff changeset
830 return valCTS; // just to pick something;
a61af66fc99e Initial load
duke
parents:
diff changeset
831 }
a61af66fc99e Initial load
duke
parents:
diff changeset
832 return vars()[localNo];
a61af66fc99e Initial load
duke
parents:
diff changeset
833 }
a61af66fc99e Initial load
duke
parents:
diff changeset
834
a61af66fc99e Initial load
duke
parents:
diff changeset
835 CellTypeState GenerateOopMap::pop() {
a61af66fc99e Initial load
duke
parents:
diff changeset
836 if ( _stack_top <= 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
837 verify_error("stack underflow");
a61af66fc99e Initial load
duke
parents:
diff changeset
838 return valCTS; // just to pick something
a61af66fc99e Initial load
duke
parents:
diff changeset
839 }
a61af66fc99e Initial load
duke
parents:
diff changeset
840 return stack()[--_stack_top];
a61af66fc99e Initial load
duke
parents:
diff changeset
841 }
a61af66fc99e Initial load
duke
parents:
diff changeset
842
a61af66fc99e Initial load
duke
parents:
diff changeset
843 void GenerateOopMap::push(CellTypeState cts) {
a61af66fc99e Initial load
duke
parents:
diff changeset
844 if ( _stack_top >= _max_stack) {
a61af66fc99e Initial load
duke
parents:
diff changeset
845 verify_error("stack overflow");
a61af66fc99e Initial load
duke
parents:
diff changeset
846 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
847 }
a61af66fc99e Initial load
duke
parents:
diff changeset
848 stack()[_stack_top++] = cts;
a61af66fc99e Initial load
duke
parents:
diff changeset
849 }
a61af66fc99e Initial load
duke
parents:
diff changeset
850
a61af66fc99e Initial load
duke
parents:
diff changeset
851 CellTypeState GenerateOopMap::monitor_pop() {
a61af66fc99e Initial load
duke
parents:
diff changeset
852 assert(_monitor_top != bad_monitors, "monitor_pop called on error monitor stack");
a61af66fc99e Initial load
duke
parents:
diff changeset
853 if (_monitor_top == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
854 // We have detected a pop of an empty monitor stack.
a61af66fc99e Initial load
duke
parents:
diff changeset
855 _monitor_safe = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
856 _monitor_top = bad_monitors;
a61af66fc99e Initial load
duke
parents:
diff changeset
857
a61af66fc99e Initial load
duke
parents:
diff changeset
858 if (TraceMonitorMismatch) {
a61af66fc99e Initial load
duke
parents:
diff changeset
859 report_monitor_mismatch("monitor stack underflow");
a61af66fc99e Initial load
duke
parents:
diff changeset
860 }
a61af66fc99e Initial load
duke
parents:
diff changeset
861 return CellTypeState::ref; // just to keep the analysis going.
a61af66fc99e Initial load
duke
parents:
diff changeset
862 }
a61af66fc99e Initial load
duke
parents:
diff changeset
863 return monitors()[--_monitor_top];
a61af66fc99e Initial load
duke
parents:
diff changeset
864 }
a61af66fc99e Initial load
duke
parents:
diff changeset
865
a61af66fc99e Initial load
duke
parents:
diff changeset
866 void GenerateOopMap::monitor_push(CellTypeState cts) {
a61af66fc99e Initial load
duke
parents:
diff changeset
867 assert(_monitor_top != bad_monitors, "monitor_push called on error monitor stack");
a61af66fc99e Initial load
duke
parents:
diff changeset
868 if (_monitor_top >= _max_monitors) {
a61af66fc99e Initial load
duke
parents:
diff changeset
869 // Some monitorenter is being executed more than once.
a61af66fc99e Initial load
duke
parents:
diff changeset
870 // This means that the monitor stack cannot be simulated.
a61af66fc99e Initial load
duke
parents:
diff changeset
871 _monitor_safe = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
872 _monitor_top = bad_monitors;
a61af66fc99e Initial load
duke
parents:
diff changeset
873
a61af66fc99e Initial load
duke
parents:
diff changeset
874 if (TraceMonitorMismatch) {
a61af66fc99e Initial load
duke
parents:
diff changeset
875 report_monitor_mismatch("monitor stack overflow");
a61af66fc99e Initial load
duke
parents:
diff changeset
876 }
a61af66fc99e Initial load
duke
parents:
diff changeset
877 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
878 }
a61af66fc99e Initial load
duke
parents:
diff changeset
879 monitors()[_monitor_top++] = cts;
a61af66fc99e Initial load
duke
parents:
diff changeset
880 }
a61af66fc99e Initial load
duke
parents:
diff changeset
881
a61af66fc99e Initial load
duke
parents:
diff changeset
882 //
a61af66fc99e Initial load
duke
parents:
diff changeset
883 // Interpretation handling methods
a61af66fc99e Initial load
duke
parents:
diff changeset
884 //
a61af66fc99e Initial load
duke
parents:
diff changeset
885
a61af66fc99e Initial load
duke
parents:
diff changeset
886 void GenerateOopMap::do_interpretation()
a61af66fc99e Initial load
duke
parents:
diff changeset
887 {
a61af66fc99e Initial load
duke
parents:
diff changeset
888 // "i" is just for debugging, so we can detect cases where this loop is
a61af66fc99e Initial load
duke
parents:
diff changeset
889 // iterated more than once.
a61af66fc99e Initial load
duke
parents:
diff changeset
890 int i = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
891 do {
a61af66fc99e Initial load
duke
parents:
diff changeset
892 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
893 if (TraceNewOopMapGeneration) {
a61af66fc99e Initial load
duke
parents:
diff changeset
894 tty->print("\n\nIteration #%d of do_interpretation loop, method:\n", i);
a61af66fc99e Initial load
duke
parents:
diff changeset
895 method()->print_name(tty);
a61af66fc99e Initial load
duke
parents:
diff changeset
896 tty->print("\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
897 }
a61af66fc99e Initial load
duke
parents:
diff changeset
898 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
899 _conflict = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
900 _monitor_safe = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
901 // init_state is now called from init_basic_blocks. The length of a
a61af66fc99e Initial load
duke
parents:
diff changeset
902 // state vector cannot be determined until we have made a pass through
a61af66fc99e Initial load
duke
parents:
diff changeset
903 // the bytecodes counting the possible monitor entries.
a61af66fc99e Initial load
duke
parents:
diff changeset
904 if (!_got_error) init_basic_blocks();
a61af66fc99e Initial load
duke
parents:
diff changeset
905 if (!_got_error) setup_method_entry_state();
a61af66fc99e Initial load
duke
parents:
diff changeset
906 if (!_got_error) interp_all();
a61af66fc99e Initial load
duke
parents:
diff changeset
907 if (!_got_error) rewrite_refval_conflicts();
a61af66fc99e Initial load
duke
parents:
diff changeset
908 i++;
a61af66fc99e Initial load
duke
parents:
diff changeset
909 } while (_conflict && !_got_error);
a61af66fc99e Initial load
duke
parents:
diff changeset
910 }
a61af66fc99e Initial load
duke
parents:
diff changeset
911
a61af66fc99e Initial load
duke
parents:
diff changeset
912 void GenerateOopMap::init_basic_blocks() {
a61af66fc99e Initial load
duke
parents:
diff changeset
913 // Note: Could consider reserving only the needed space for each BB's state
a61af66fc99e Initial load
duke
parents:
diff changeset
914 // (entry stack may not be of maximal height for every basic block).
a61af66fc99e Initial load
duke
parents:
diff changeset
915 // But cumbersome since we don't know the stack heights yet. (Nor the
a61af66fc99e Initial load
duke
parents:
diff changeset
916 // monitor stack heights...)
a61af66fc99e Initial load
duke
parents:
diff changeset
917
11009
f75faf51e8c4 7158805: Better rewriting of nested subroutine calls
hseigel
parents: 8773
diff changeset
918 ALLOC_RESOURCE_ARRAY(_basic_blocks, BasicBlock, _bb_count);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
919
a61af66fc99e Initial load
duke
parents:
diff changeset
920 // Make a pass through the bytecodes. Count the number of monitorenters.
a61af66fc99e Initial load
duke
parents:
diff changeset
921 // This can be used an upper bound on the monitor stack depth in programs
a61af66fc99e Initial load
duke
parents:
diff changeset
922 // which obey stack discipline with their monitor usage. Initialize the
a61af66fc99e Initial load
duke
parents:
diff changeset
923 // known information about basic blocks.
a61af66fc99e Initial load
duke
parents:
diff changeset
924 BytecodeStream j(_method);
a61af66fc99e Initial load
duke
parents:
diff changeset
925 Bytecodes::Code bytecode;
a61af66fc99e Initial load
duke
parents:
diff changeset
926
a61af66fc99e Initial load
duke
parents:
diff changeset
927 int bbNo = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
928 int monitor_count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
929 int prev_bci = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
930 while( (bytecode = j.next()) >= 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
931 if (j.code() == Bytecodes::_monitorenter) {
a61af66fc99e Initial load
duke
parents:
diff changeset
932 monitor_count++;
a61af66fc99e Initial load
duke
parents:
diff changeset
933 }
a61af66fc99e Initial load
duke
parents:
diff changeset
934
a61af66fc99e Initial load
duke
parents:
diff changeset
935 int bci = j.bci();
a61af66fc99e Initial load
duke
parents:
diff changeset
936 if (is_bb_header(bci)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
937 // Initialize the basicblock structure
a61af66fc99e Initial load
duke
parents:
diff changeset
938 BasicBlock *bb = _basic_blocks + bbNo;
a61af66fc99e Initial load
duke
parents:
diff changeset
939 bb->_bci = bci;
a61af66fc99e Initial load
duke
parents:
diff changeset
940 bb->_max_locals = _max_locals;
a61af66fc99e Initial load
duke
parents:
diff changeset
941 bb->_max_stack = _max_stack;
a61af66fc99e Initial load
duke
parents:
diff changeset
942 bb->set_changed(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
943 bb->_stack_top = BasicBlock::_dead_basic_block; // Initialize all basicblocks are dead.
a61af66fc99e Initial load
duke
parents:
diff changeset
944 bb->_monitor_top = bad_monitors;
a61af66fc99e Initial load
duke
parents:
diff changeset
945
a61af66fc99e Initial load
duke
parents:
diff changeset
946 if (bbNo > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
947 _basic_blocks[bbNo - 1]._end_bci = prev_bci;
a61af66fc99e Initial load
duke
parents:
diff changeset
948 }
a61af66fc99e Initial load
duke
parents:
diff changeset
949
a61af66fc99e Initial load
duke
parents:
diff changeset
950 bbNo++;
a61af66fc99e Initial load
duke
parents:
diff changeset
951 }
a61af66fc99e Initial load
duke
parents:
diff changeset
952 // Remember prevous bci.
a61af66fc99e Initial load
duke
parents:
diff changeset
953 prev_bci = bci;
a61af66fc99e Initial load
duke
parents:
diff changeset
954 }
a61af66fc99e Initial load
duke
parents:
diff changeset
955 // Set
a61af66fc99e Initial load
duke
parents:
diff changeset
956 _basic_blocks[bbNo-1]._end_bci = prev_bci;
a61af66fc99e Initial load
duke
parents:
diff changeset
957
a61af66fc99e Initial load
duke
parents:
diff changeset
958
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
959 // Check that the correct number of basicblocks was found
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
960 if (bbNo !=_bb_count) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
961 if (bbNo < _bb_count) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
962 verify_error("jump into the middle of instruction?");
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
963 return;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
964 } else {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
965 verify_error("extra basic blocks - should not happen?");
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
966 return;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
967 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
968 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
969
0
a61af66fc99e Initial load
duke
parents:
diff changeset
970 _max_monitors = monitor_count;
a61af66fc99e Initial load
duke
parents:
diff changeset
971
a61af66fc99e Initial load
duke
parents:
diff changeset
972 // Now that we have a bound on the depth of the monitor stack, we can
a61af66fc99e Initial load
duke
parents:
diff changeset
973 // initialize the CellTypeState-related information.
a61af66fc99e Initial load
duke
parents:
diff changeset
974 init_state();
a61af66fc99e Initial load
duke
parents:
diff changeset
975
3862
52e4ba46751f 7020373: JSR rewriting can overflow memory address size variables
kamg
parents: 2177
diff changeset
976 // We allocate space for all state-vectors for all basicblocks in one huge
52e4ba46751f 7020373: JSR rewriting can overflow memory address size variables
kamg
parents: 2177
diff changeset
977 // chunk. Then in the next part of the code, we set a pointer in each
52e4ba46751f 7020373: JSR rewriting can overflow memory address size variables
kamg
parents: 2177
diff changeset
978 // _basic_block that points to each piece.
52e4ba46751f 7020373: JSR rewriting can overflow memory address size variables
kamg
parents: 2177
diff changeset
979
52e4ba46751f 7020373: JSR rewriting can overflow memory address size variables
kamg
parents: 2177
diff changeset
980 // The product of bbNo and _state_len can get large if there are lots of
52e4ba46751f 7020373: JSR rewriting can overflow memory address size variables
kamg
parents: 2177
diff changeset
981 // basic blocks and stack/locals/monitors. Need to check to make sure
52e4ba46751f 7020373: JSR rewriting can overflow memory address size variables
kamg
parents: 2177
diff changeset
982 // we don't overflow the capacity of a pointer.
52e4ba46751f 7020373: JSR rewriting can overflow memory address size variables
kamg
parents: 2177
diff changeset
983 if ((unsigned)bbNo > UINTPTR_MAX / sizeof(CellTypeState) / _state_len) {
52e4ba46751f 7020373: JSR rewriting can overflow memory address size variables
kamg
parents: 2177
diff changeset
984 report_error("The amount of memory required to analyze this method "
52e4ba46751f 7020373: JSR rewriting can overflow memory address size variables
kamg
parents: 2177
diff changeset
985 "exceeds addressable range");
52e4ba46751f 7020373: JSR rewriting can overflow memory address size variables
kamg
parents: 2177
diff changeset
986 return;
52e4ba46751f 7020373: JSR rewriting can overflow memory address size variables
kamg
parents: 2177
diff changeset
987 }
52e4ba46751f 7020373: JSR rewriting can overflow memory address size variables
kamg
parents: 2177
diff changeset
988
11009
f75faf51e8c4 7158805: Better rewriting of nested subroutine calls
hseigel
parents: 8773
diff changeset
989 CellTypeState *basicBlockState;
f75faf51e8c4 7158805: Better rewriting of nested subroutine calls
hseigel
parents: 8773
diff changeset
990 ALLOC_RESOURCE_ARRAY(basicBlockState, CellTypeState, bbNo * _state_len);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
991 memset(basicBlockState, 0, bbNo * _state_len * sizeof(CellTypeState));
a61af66fc99e Initial load
duke
parents:
diff changeset
992
a61af66fc99e Initial load
duke
parents:
diff changeset
993 // Make a pass over the basicblocks and assign their state vectors.
a61af66fc99e Initial load
duke
parents:
diff changeset
994 for (int blockNum=0; blockNum < bbNo; blockNum++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
995 BasicBlock *bb = _basic_blocks + blockNum;
a61af66fc99e Initial load
duke
parents:
diff changeset
996 bb->_state = basicBlockState + blockNum * _state_len;
a61af66fc99e Initial load
duke
parents:
diff changeset
997
a61af66fc99e Initial load
duke
parents:
diff changeset
998 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
999 if (blockNum + 1 < bbNo) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1000 address bcp = _method->bcp_from(bb->_end_bci);
2142
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
1001 int bc_len = Bytecodes::java_length_at(_method(), bcp);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1002 assert(bb->_end_bci + bc_len == bb[1]._bci, "unmatched bci info in basicblock");
a61af66fc99e Initial load
duke
parents:
diff changeset
1003 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1004 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
1005 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1006 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
1007 { BasicBlock *bb = &_basic_blocks[bbNo-1];
a61af66fc99e Initial load
duke
parents:
diff changeset
1008 address bcp = _method->bcp_from(bb->_end_bci);
2142
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
1009 int bc_len = Bytecodes::java_length_at(_method(), bcp);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1010 assert(bb->_end_bci + bc_len == _method->code_size(), "wrong end bci");
a61af66fc99e Initial load
duke
parents:
diff changeset
1011 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1012 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
1013
a61af66fc99e Initial load
duke
parents:
diff changeset
1014 // Mark all alive blocks
a61af66fc99e Initial load
duke
parents:
diff changeset
1015 mark_reachable_code();
a61af66fc99e Initial load
duke
parents:
diff changeset
1016 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1017
a61af66fc99e Initial load
duke
parents:
diff changeset
1018 void GenerateOopMap::setup_method_entry_state() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1019
a61af66fc99e Initial load
duke
parents:
diff changeset
1020 // Initialize all locals to 'uninit' and set stack-height to 0
a61af66fc99e Initial load
duke
parents:
diff changeset
1021 make_context_uninitialized();
a61af66fc99e Initial load
duke
parents:
diff changeset
1022
a61af66fc99e Initial load
duke
parents:
diff changeset
1023 // Initialize CellState type of arguments
a61af66fc99e Initial load
duke
parents:
diff changeset
1024 methodsig_to_effect(method()->signature(), method()->is_static(), vars());
a61af66fc99e Initial load
duke
parents:
diff changeset
1025
a61af66fc99e Initial load
duke
parents:
diff changeset
1026 // If some references must be pre-assigned to null, then set that up
a61af66fc99e Initial load
duke
parents:
diff changeset
1027 initialize_vars();
a61af66fc99e Initial load
duke
parents:
diff changeset
1028
a61af66fc99e Initial load
duke
parents:
diff changeset
1029 // This is the start state
a61af66fc99e Initial load
duke
parents:
diff changeset
1030 merge_state_into_bb(&_basic_blocks[0]);
a61af66fc99e Initial load
duke
parents:
diff changeset
1031
a61af66fc99e Initial load
duke
parents:
diff changeset
1032 assert(_basic_blocks[0].changed(), "we are not getting off the ground");
a61af66fc99e Initial load
duke
parents:
diff changeset
1033 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1034
a61af66fc99e Initial load
duke
parents:
diff changeset
1035 // The instruction at bci is changing size by "delta". Update the basic blocks.
a61af66fc99e Initial load
duke
parents:
diff changeset
1036 void GenerateOopMap::update_basic_blocks(int bci, int delta,
a61af66fc99e Initial load
duke
parents:
diff changeset
1037 int new_method_size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1038 assert(new_method_size >= method()->code_size() + delta,
a61af66fc99e Initial load
duke
parents:
diff changeset
1039 "new method size is too small");
a61af66fc99e Initial load
duke
parents:
diff changeset
1040
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
1041 BitMap::bm_word_t* new_bb_hdr_bits =
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
1042 NEW_RESOURCE_ARRAY(BitMap::bm_word_t,
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
1043 BitMap::word_align_up(new_method_size));
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
1044 _bb_hdr_bits.set_map(new_bb_hdr_bits);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
1045 _bb_hdr_bits.set_size(new_method_size);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
1046 _bb_hdr_bits.clear();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1047
a61af66fc99e Initial load
duke
parents:
diff changeset
1048
a61af66fc99e Initial load
duke
parents:
diff changeset
1049 for(int k = 0; k < _bb_count; k++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1050 if (_basic_blocks[k]._bci > bci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1051 _basic_blocks[k]._bci += delta;
a61af66fc99e Initial load
duke
parents:
diff changeset
1052 _basic_blocks[k]._end_bci += delta;
a61af66fc99e Initial load
duke
parents:
diff changeset
1053 }
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
1054 _bb_hdr_bits.at_put(_basic_blocks[k]._bci, true);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1055 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1056 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1057
a61af66fc99e Initial load
duke
parents:
diff changeset
1058 //
a61af66fc99e Initial load
duke
parents:
diff changeset
1059 // Initvars handling
a61af66fc99e Initial load
duke
parents:
diff changeset
1060 //
a61af66fc99e Initial load
duke
parents:
diff changeset
1061
a61af66fc99e Initial load
duke
parents:
diff changeset
1062 void GenerateOopMap::initialize_vars() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1063 for (int k = 0; k < _init_vars->length(); k++)
a61af66fc99e Initial load
duke
parents:
diff changeset
1064 _state[_init_vars->at(k)] = CellTypeState::make_slot_ref(k);
a61af66fc99e Initial load
duke
parents:
diff changeset
1065 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1066
a61af66fc99e Initial load
duke
parents:
diff changeset
1067 void GenerateOopMap::add_to_ref_init_set(int localNo) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1068
a61af66fc99e Initial load
duke
parents:
diff changeset
1069 if (TraceNewOopMapGeneration)
a61af66fc99e Initial load
duke
parents:
diff changeset
1070 tty->print_cr("Added init vars: %d", localNo);
a61af66fc99e Initial load
duke
parents:
diff changeset
1071
a61af66fc99e Initial load
duke
parents:
diff changeset
1072 // Is it already in the set?
a61af66fc99e Initial load
duke
parents:
diff changeset
1073 if (_init_vars->contains(localNo) )
a61af66fc99e Initial load
duke
parents:
diff changeset
1074 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1075
a61af66fc99e Initial load
duke
parents:
diff changeset
1076 _init_vars->append(localNo);
a61af66fc99e Initial load
duke
parents:
diff changeset
1077 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1078
a61af66fc99e Initial load
duke
parents:
diff changeset
1079 //
a61af66fc99e Initial load
duke
parents:
diff changeset
1080 // Interpreration code
a61af66fc99e Initial load
duke
parents:
diff changeset
1081 //
a61af66fc99e Initial load
duke
parents:
diff changeset
1082
a61af66fc99e Initial load
duke
parents:
diff changeset
1083 void GenerateOopMap::interp_all() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1084 bool change = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1085
a61af66fc99e Initial load
duke
parents:
diff changeset
1086 while (change && !_got_error) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1087 change = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1088 for (int i = 0; i < _bb_count && !_got_error; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1089 BasicBlock *bb = &_basic_blocks[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
1090 if (bb->changed()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1091 if (_got_error) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1092 change = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1093 bb->set_changed(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
1094 interp_bb(bb);
a61af66fc99e Initial load
duke
parents:
diff changeset
1095 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1096 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1097 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1098 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1099
a61af66fc99e Initial load
duke
parents:
diff changeset
1100 void GenerateOopMap::interp_bb(BasicBlock *bb) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1101
a61af66fc99e Initial load
duke
parents:
diff changeset
1102 // We do not want to do anything in case the basic-block has not been initialized. This
a61af66fc99e Initial load
duke
parents:
diff changeset
1103 // will happen in the case where there is dead-code hang around in a method.
a61af66fc99e Initial load
duke
parents:
diff changeset
1104 assert(bb->is_reachable(), "should be reachable or deadcode exist");
a61af66fc99e Initial load
duke
parents:
diff changeset
1105 restore_state(bb);
a61af66fc99e Initial load
duke
parents:
diff changeset
1106
a61af66fc99e Initial load
duke
parents:
diff changeset
1107 BytecodeStream itr(_method);
a61af66fc99e Initial load
duke
parents:
diff changeset
1108
a61af66fc99e Initial load
duke
parents:
diff changeset
1109 // Set iterator interval to be the current basicblock
a61af66fc99e Initial load
duke
parents:
diff changeset
1110 int lim_bci = next_bb_start_pc(bb);
a61af66fc99e Initial load
duke
parents:
diff changeset
1111 itr.set_interval(bb->_bci, lim_bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
1112 assert(lim_bci != bb->_bci, "must be at least one instruction in a basicblock");
a61af66fc99e Initial load
duke
parents:
diff changeset
1113 itr.next(); // read first instruction
a61af66fc99e Initial load
duke
parents:
diff changeset
1114
a61af66fc99e Initial load
duke
parents:
diff changeset
1115 // Iterates through all bytecodes except the last in a basic block.
a61af66fc99e Initial load
duke
parents:
diff changeset
1116 // We handle the last one special, since there is controlflow change.
a61af66fc99e Initial load
duke
parents:
diff changeset
1117 while(itr.next_bci() < lim_bci && !_got_error) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1118 if (_has_exceptions || _monitor_top != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1119 // We do not need to interpret the results of exceptional
a61af66fc99e Initial load
duke
parents:
diff changeset
1120 // continuation from this instruction when the method has no
a61af66fc99e Initial load
duke
parents:
diff changeset
1121 // exception handlers and the monitor stack is currently
a61af66fc99e Initial load
duke
parents:
diff changeset
1122 // empty.
a61af66fc99e Initial load
duke
parents:
diff changeset
1123 do_exception_edge(&itr);
a61af66fc99e Initial load
duke
parents:
diff changeset
1124 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1125 interp1(&itr);
a61af66fc99e Initial load
duke
parents:
diff changeset
1126 itr.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
1127 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1128
a61af66fc99e Initial load
duke
parents:
diff changeset
1129 // Handle last instruction.
a61af66fc99e Initial load
duke
parents:
diff changeset
1130 if (!_got_error) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1131 assert(itr.next_bci() == lim_bci, "must point to end");
a61af66fc99e Initial load
duke
parents:
diff changeset
1132 if (_has_exceptions || _monitor_top != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1133 do_exception_edge(&itr);
a61af66fc99e Initial load
duke
parents:
diff changeset
1134 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1135 interp1(&itr);
a61af66fc99e Initial load
duke
parents:
diff changeset
1136
a61af66fc99e Initial load
duke
parents:
diff changeset
1137 bool fall_through = jump_targets_do(&itr, GenerateOopMap::merge_state, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
1138 if (_got_error) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1139
a61af66fc99e Initial load
duke
parents:
diff changeset
1140 if (itr.code() == Bytecodes::_ret) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1141 assert(!fall_through, "cannot be set if ret instruction");
a61af66fc99e Initial load
duke
parents:
diff changeset
1142 // Automatically handles 'wide' ret indicies
a61af66fc99e Initial load
duke
parents:
diff changeset
1143 ret_jump_targets_do(&itr, GenerateOopMap::merge_state, itr.get_index(), NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
1144 } else if (fall_through) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1145 // Hit end of BB, but the instr. was a fall-through instruction,
a61af66fc99e Initial load
duke
parents:
diff changeset
1146 // so perform transition as if the BB ended in a "jump".
a61af66fc99e Initial load
duke
parents:
diff changeset
1147 if (lim_bci != bb[1]._bci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1148 verify_error("bytecodes fell through last instruction");
a61af66fc99e Initial load
duke
parents:
diff changeset
1149 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1150 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1151 merge_state_into_bb(bb + 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1152 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1153 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1154 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1155
a61af66fc99e Initial load
duke
parents:
diff changeset
1156 void GenerateOopMap::do_exception_edge(BytecodeStream* itr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1157 // Only check exception edge, if bytecode can trap
a61af66fc99e Initial load
duke
parents:
diff changeset
1158 if (!Bytecodes::can_trap(itr->code())) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1159 switch (itr->code()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1160 case Bytecodes::_aload_0:
a61af66fc99e Initial load
duke
parents:
diff changeset
1161 // These bytecodes can trap for rewriting. We need to assume that
a61af66fc99e Initial load
duke
parents:
diff changeset
1162 // they do not throw exceptions to make the monitor analysis work.
a61af66fc99e Initial load
duke
parents:
diff changeset
1163 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1164
a61af66fc99e Initial load
duke
parents:
diff changeset
1165 case Bytecodes::_ireturn:
a61af66fc99e Initial load
duke
parents:
diff changeset
1166 case Bytecodes::_lreturn:
a61af66fc99e Initial load
duke
parents:
diff changeset
1167 case Bytecodes::_freturn:
a61af66fc99e Initial load
duke
parents:
diff changeset
1168 case Bytecodes::_dreturn:
a61af66fc99e Initial load
duke
parents:
diff changeset
1169 case Bytecodes::_areturn:
a61af66fc99e Initial load
duke
parents:
diff changeset
1170 case Bytecodes::_return:
a61af66fc99e Initial load
duke
parents:
diff changeset
1171 // If the monitor stack height is not zero when we leave the method,
a61af66fc99e Initial load
duke
parents:
diff changeset
1172 // then we are either exiting with a non-empty stack or we have
a61af66fc99e Initial load
duke
parents:
diff changeset
1173 // found monitor trouble earlier in our analysis. In either case,
a61af66fc99e Initial load
duke
parents:
diff changeset
1174 // assume an exception could be taken here.
a61af66fc99e Initial load
duke
parents:
diff changeset
1175 if (_monitor_top == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1176 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1177 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1178 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1179
a61af66fc99e Initial load
duke
parents:
diff changeset
1180 case Bytecodes::_monitorexit:
a61af66fc99e Initial load
duke
parents:
diff changeset
1181 // If the monitor stack height is bad_monitors, then we have detected a
a61af66fc99e Initial load
duke
parents:
diff changeset
1182 // monitor matching problem earlier in the analysis. If the
a61af66fc99e Initial load
duke
parents:
diff changeset
1183 // monitor stack height is 0, we are about to pop a monitor
a61af66fc99e Initial load
duke
parents:
diff changeset
1184 // off of an empty stack. In either case, the bytecode
a61af66fc99e Initial load
duke
parents:
diff changeset
1185 // could throw an exception.
a61af66fc99e Initial load
duke
parents:
diff changeset
1186 if (_monitor_top != bad_monitors && _monitor_top != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1187 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1188 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1189 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1190 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1191
a61af66fc99e Initial load
duke
parents:
diff changeset
1192 if (_has_exceptions) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1193 int bci = itr->bci();
6213
8150fa46d2ed 7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents: 3865
diff changeset
1194 ExceptionTable exct(method());
8150fa46d2ed 7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents: 3865
diff changeset
1195 for(int i = 0; i< exct.length(); i++) {
8150fa46d2ed 7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents: 3865
diff changeset
1196 int start_pc = exct.start_pc(i);
8150fa46d2ed 7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents: 3865
diff changeset
1197 int end_pc = exct.end_pc(i);
8150fa46d2ed 7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents: 3865
diff changeset
1198 int handler_pc = exct.handler_pc(i);
8150fa46d2ed 7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents: 3865
diff changeset
1199 int catch_type = exct.catch_type_index(i);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1200
a61af66fc99e Initial load
duke
parents:
diff changeset
1201 if (start_pc <= bci && bci < end_pc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1202 BasicBlock *excBB = get_basic_block_at(handler_pc);
8773
2eef6d34833b 8009022: [parfait] Null pointer deference in hotspot/src/share/vm/oops/generateOopMap.cpp
morris
parents: 8104
diff changeset
1203 guarantee(excBB != NULL, "no basic block for exception");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1204 CellTypeState *excStk = excBB->stack();
a61af66fc99e Initial load
duke
parents:
diff changeset
1205 CellTypeState *cOpStck = stack();
a61af66fc99e Initial load
duke
parents:
diff changeset
1206 CellTypeState cOpStck_0 = cOpStck[0];
a61af66fc99e Initial load
duke
parents:
diff changeset
1207 int cOpStackTop = _stack_top;
a61af66fc99e Initial load
duke
parents:
diff changeset
1208
a61af66fc99e Initial load
duke
parents:
diff changeset
1209 // Exception stacks are always the same.
a61af66fc99e Initial load
duke
parents:
diff changeset
1210 assert(method()->max_stack() > 0, "sanity check");
a61af66fc99e Initial load
duke
parents:
diff changeset
1211
a61af66fc99e Initial load
duke
parents:
diff changeset
1212 // We remembered the size and first element of "cOpStck"
a61af66fc99e Initial load
duke
parents:
diff changeset
1213 // above; now we temporarily set them to the appropriate
a61af66fc99e Initial load
duke
parents:
diff changeset
1214 // values for an exception handler. */
a61af66fc99e Initial load
duke
parents:
diff changeset
1215 cOpStck[0] = CellTypeState::make_slot_ref(_max_locals);
a61af66fc99e Initial load
duke
parents:
diff changeset
1216 _stack_top = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
1217
a61af66fc99e Initial load
duke
parents:
diff changeset
1218 merge_state_into_bb(excBB);
a61af66fc99e Initial load
duke
parents:
diff changeset
1219
a61af66fc99e Initial load
duke
parents:
diff changeset
1220 // Now undo the temporary change.
a61af66fc99e Initial load
duke
parents:
diff changeset
1221 cOpStck[0] = cOpStck_0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1222 _stack_top = cOpStackTop;
a61af66fc99e Initial load
duke
parents:
diff changeset
1223
a61af66fc99e Initial load
duke
parents:
diff changeset
1224 // If this is a "catch all" handler, then we do not need to
a61af66fc99e Initial load
duke
parents:
diff changeset
1225 // consider any additional handlers.
a61af66fc99e Initial load
duke
parents:
diff changeset
1226 if (catch_type == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1227 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1228 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1229 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1230 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1231 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1232
a61af66fc99e Initial load
duke
parents:
diff changeset
1233 // It is possible that none of the exception handlers would have caught
a61af66fc99e Initial load
duke
parents:
diff changeset
1234 // the exception. In this case, we will exit the method. We must
a61af66fc99e Initial load
duke
parents:
diff changeset
1235 // ensure that the monitor stack is empty in this case.
a61af66fc99e Initial load
duke
parents:
diff changeset
1236 if (_monitor_top == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1237 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1238 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1239
a61af66fc99e Initial load
duke
parents:
diff changeset
1240 // We pessimistically assume that this exception can escape the
a61af66fc99e Initial load
duke
parents:
diff changeset
1241 // method. (It is possible that it will always be caught, but
a61af66fc99e Initial load
duke
parents:
diff changeset
1242 // we don't care to analyse the types of the catch clauses.)
a61af66fc99e Initial load
duke
parents:
diff changeset
1243
a61af66fc99e Initial load
duke
parents:
diff changeset
1244 // We don't set _monitor_top to bad_monitors because there are no successors
a61af66fc99e Initial load
duke
parents:
diff changeset
1245 // to this exceptional exit.
a61af66fc99e Initial load
duke
parents:
diff changeset
1246
a61af66fc99e Initial load
duke
parents:
diff changeset
1247 if (TraceMonitorMismatch && _monitor_safe) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1248 // We check _monitor_safe so that we only report the first mismatched
a61af66fc99e Initial load
duke
parents:
diff changeset
1249 // exceptional exit.
a61af66fc99e Initial load
duke
parents:
diff changeset
1250 report_monitor_mismatch("non-empty monitor stack at exceptional exit");
a61af66fc99e Initial load
duke
parents:
diff changeset
1251 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1252 _monitor_safe = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1253
a61af66fc99e Initial load
duke
parents:
diff changeset
1254 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1255
a61af66fc99e Initial load
duke
parents:
diff changeset
1256 void GenerateOopMap::report_monitor_mismatch(const char *msg) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1257 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
1258 tty->print(" Monitor mismatch in method ");
a61af66fc99e Initial load
duke
parents:
diff changeset
1259 method()->print_short_name(tty);
a61af66fc99e Initial load
duke
parents:
diff changeset
1260 tty->print_cr(": %s", msg);
a61af66fc99e Initial load
duke
parents:
diff changeset
1261 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
1262 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1263
a61af66fc99e Initial load
duke
parents:
diff changeset
1264 void GenerateOopMap::print_states(outputStream *os,
a61af66fc99e Initial load
duke
parents:
diff changeset
1265 CellTypeState* vec, int num) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1266 for (int i = 0; i < num; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1267 vec[i].print(tty);
a61af66fc99e Initial load
duke
parents:
diff changeset
1268 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1269 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1270
a61af66fc99e Initial load
duke
parents:
diff changeset
1271 // Print the state values at the current bytecode.
a61af66fc99e Initial load
duke
parents:
diff changeset
1272 void GenerateOopMap::print_current_state(outputStream *os,
a61af66fc99e Initial load
duke
parents:
diff changeset
1273 BytecodeStream *currentBC,
a61af66fc99e Initial load
duke
parents:
diff changeset
1274 bool detailed) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1275
a61af66fc99e Initial load
duke
parents:
diff changeset
1276 if (detailed) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1277 os->print(" %4d vars = ", currentBC->bci());
a61af66fc99e Initial load
duke
parents:
diff changeset
1278 print_states(os, vars(), _max_locals);
a61af66fc99e Initial load
duke
parents:
diff changeset
1279 os->print(" %s", Bytecodes::name(currentBC->code()));
a61af66fc99e Initial load
duke
parents:
diff changeset
1280 switch(currentBC->code()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1281 case Bytecodes::_invokevirtual:
a61af66fc99e Initial load
duke
parents:
diff changeset
1282 case Bytecodes::_invokespecial:
a61af66fc99e Initial load
duke
parents:
diff changeset
1283 case Bytecodes::_invokestatic:
726
be93aad57795 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 605
diff changeset
1284 case Bytecodes::_invokedynamic:
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1285 case Bytecodes::_invokeinterface:
1910
d1896d1dda3e 6981788: GC map generator sometimes picks up the wrong kind of instruction operand
jrose
parents: 1681
diff changeset
1286 int idx = currentBC->has_index_u4() ? currentBC->get_index_u4() : currentBC->get_index_u2_cpcache();
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6266
diff changeset
1287 ConstantPool* cp = method()->constants();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1288 int nameAndTypeIdx = cp->name_and_type_ref_index_at(idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1289 int signatureIdx = cp->signature_ref_index_at(nameAndTypeIdx);
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 2142
diff changeset
1290 Symbol* signature = cp->symbol_at(signatureIdx);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1291 os->print("%s", signature->as_C_string());
a61af66fc99e Initial load
duke
parents:
diff changeset
1292 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1293 os->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
1294 os->print(" stack = ");
a61af66fc99e Initial load
duke
parents:
diff changeset
1295 print_states(os, stack(), _stack_top);
a61af66fc99e Initial load
duke
parents:
diff changeset
1296 os->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
1297 if (_monitor_top != bad_monitors) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1298 os->print(" monitors = ");
a61af66fc99e Initial load
duke
parents:
diff changeset
1299 print_states(os, monitors(), _monitor_top);
a61af66fc99e Initial load
duke
parents:
diff changeset
1300 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1301 os->print(" [bad monitor stack]");
a61af66fc99e Initial load
duke
parents:
diff changeset
1302 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1303 os->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
1304 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1305 os->print(" %4d vars = '%s' ", currentBC->bci(), state_vec_to_string(vars(), _max_locals));
a61af66fc99e Initial load
duke
parents:
diff changeset
1306 os->print(" stack = '%s' ", state_vec_to_string(stack(), _stack_top));
a61af66fc99e Initial load
duke
parents:
diff changeset
1307 if (_monitor_top != bad_monitors) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1308 os->print(" monitors = '%s' \t%s", state_vec_to_string(monitors(), _monitor_top), Bytecodes::name(currentBC->code()));
a61af66fc99e Initial load
duke
parents:
diff changeset
1309 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1310 os->print(" [bad monitor stack]");
a61af66fc99e Initial load
duke
parents:
diff changeset
1311 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1312 switch(currentBC->code()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1313 case Bytecodes::_invokevirtual:
a61af66fc99e Initial load
duke
parents:
diff changeset
1314 case Bytecodes::_invokespecial:
a61af66fc99e Initial load
duke
parents:
diff changeset
1315 case Bytecodes::_invokestatic:
726
be93aad57795 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 605
diff changeset
1316 case Bytecodes::_invokedynamic:
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1317 case Bytecodes::_invokeinterface:
1910
d1896d1dda3e 6981788: GC map generator sometimes picks up the wrong kind of instruction operand
jrose
parents: 1681
diff changeset
1318 int idx = currentBC->has_index_u4() ? currentBC->get_index_u4() : currentBC->get_index_u2_cpcache();
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6266
diff changeset
1319 ConstantPool* cp = method()->constants();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1320 int nameAndTypeIdx = cp->name_and_type_ref_index_at(idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1321 int signatureIdx = cp->signature_ref_index_at(nameAndTypeIdx);
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 2142
diff changeset
1322 Symbol* signature = cp->symbol_at(signatureIdx);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1323 os->print("%s", signature->as_C_string());
a61af66fc99e Initial load
duke
parents:
diff changeset
1324 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1325 os->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
1326 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1327 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1328
a61af66fc99e Initial load
duke
parents:
diff changeset
1329 // Sets the current state to be the state after executing the
a61af66fc99e Initial load
duke
parents:
diff changeset
1330 // current instruction, starting in the current state.
a61af66fc99e Initial load
duke
parents:
diff changeset
1331 void GenerateOopMap::interp1(BytecodeStream *itr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1332 if (TraceNewOopMapGeneration) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1333 print_current_state(tty, itr, TraceNewOopMapGenerationDetailed);
a61af66fc99e Initial load
duke
parents:
diff changeset
1334 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1335
a61af66fc99e Initial load
duke
parents:
diff changeset
1336 // Should we report the results? Result is reported *before* the instruction at the current bci is executed.
a61af66fc99e Initial load
duke
parents:
diff changeset
1337 // However, not for calls. For calls we do not want to include the arguments, so we postpone the reporting until
a61af66fc99e Initial load
duke
parents:
diff changeset
1338 // they have been popped (in method ppl).
a61af66fc99e Initial load
duke
parents:
diff changeset
1339 if (_report_result == true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1340 switch(itr->code()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1341 case Bytecodes::_invokevirtual:
a61af66fc99e Initial load
duke
parents:
diff changeset
1342 case Bytecodes::_invokespecial:
a61af66fc99e Initial load
duke
parents:
diff changeset
1343 case Bytecodes::_invokestatic:
726
be93aad57795 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 605
diff changeset
1344 case Bytecodes::_invokedynamic:
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1345 case Bytecodes::_invokeinterface:
a61af66fc99e Initial load
duke
parents:
diff changeset
1346 _itr_send = itr;
a61af66fc99e Initial load
duke
parents:
diff changeset
1347 _report_result_for_send = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1348 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1349 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
1350 fill_stackmap_for_opcodes(itr, vars(), stack(), _stack_top);
a61af66fc99e Initial load
duke
parents:
diff changeset
1351 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1352 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1353 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1354
a61af66fc99e Initial load
duke
parents:
diff changeset
1355 // abstract interpretation of current opcode
a61af66fc99e Initial load
duke
parents:
diff changeset
1356 switch(itr->code()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1357 case Bytecodes::_nop: break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1358 case Bytecodes::_goto: break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1359 case Bytecodes::_goto_w: break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1360 case Bytecodes::_iinc: break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1361 case Bytecodes::_return: do_return_monitor_check();
a61af66fc99e Initial load
duke
parents:
diff changeset
1362 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1363
a61af66fc99e Initial load
duke
parents:
diff changeset
1364 case Bytecodes::_aconst_null:
a61af66fc99e Initial load
duke
parents:
diff changeset
1365 case Bytecodes::_new: ppush1(CellTypeState::make_line_ref(itr->bci()));
a61af66fc99e Initial load
duke
parents:
diff changeset
1366 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1367
a61af66fc99e Initial load
duke
parents:
diff changeset
1368 case Bytecodes::_iconst_m1:
a61af66fc99e Initial load
duke
parents:
diff changeset
1369 case Bytecodes::_iconst_0:
a61af66fc99e Initial load
duke
parents:
diff changeset
1370 case Bytecodes::_iconst_1:
a61af66fc99e Initial load
duke
parents:
diff changeset
1371 case Bytecodes::_iconst_2:
a61af66fc99e Initial load
duke
parents:
diff changeset
1372 case Bytecodes::_iconst_3:
a61af66fc99e Initial load
duke
parents:
diff changeset
1373 case Bytecodes::_iconst_4:
a61af66fc99e Initial load
duke
parents:
diff changeset
1374 case Bytecodes::_iconst_5:
a61af66fc99e Initial load
duke
parents:
diff changeset
1375 case Bytecodes::_fconst_0:
a61af66fc99e Initial load
duke
parents:
diff changeset
1376 case Bytecodes::_fconst_1:
a61af66fc99e Initial load
duke
parents:
diff changeset
1377 case Bytecodes::_fconst_2:
a61af66fc99e Initial load
duke
parents:
diff changeset
1378 case Bytecodes::_bipush:
a61af66fc99e Initial load
duke
parents:
diff changeset
1379 case Bytecodes::_sipush: ppush1(valCTS); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1380
a61af66fc99e Initial load
duke
parents:
diff changeset
1381 case Bytecodes::_lconst_0:
a61af66fc99e Initial load
duke
parents:
diff changeset
1382 case Bytecodes::_lconst_1:
a61af66fc99e Initial load
duke
parents:
diff changeset
1383 case Bytecodes::_dconst_0:
a61af66fc99e Initial load
duke
parents:
diff changeset
1384 case Bytecodes::_dconst_1: ppush(vvCTS); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1385
a61af66fc99e Initial load
duke
parents:
diff changeset
1386 case Bytecodes::_ldc2_w: ppush(vvCTS); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1387
1910
d1896d1dda3e 6981788: GC map generator sometimes picks up the wrong kind of instruction operand
jrose
parents: 1681
diff changeset
1388 case Bytecodes::_ldc: // fall through:
d1896d1dda3e 6981788: GC map generator sometimes picks up the wrong kind of instruction operand
jrose
parents: 1681
diff changeset
1389 case Bytecodes::_ldc_w: do_ldc(itr->bci()); break;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1390
a61af66fc99e Initial load
duke
parents:
diff changeset
1391 case Bytecodes::_iload:
a61af66fc99e Initial load
duke
parents:
diff changeset
1392 case Bytecodes::_fload: ppload(vCTS, itr->get_index()); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1393
a61af66fc99e Initial load
duke
parents:
diff changeset
1394 case Bytecodes::_lload:
a61af66fc99e Initial load
duke
parents:
diff changeset
1395 case Bytecodes::_dload: ppload(vvCTS,itr->get_index()); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1396
a61af66fc99e Initial load
duke
parents:
diff changeset
1397 case Bytecodes::_aload: ppload(rCTS, itr->get_index()); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1398
a61af66fc99e Initial load
duke
parents:
diff changeset
1399 case Bytecodes::_iload_0:
a61af66fc99e Initial load
duke
parents:
diff changeset
1400 case Bytecodes::_fload_0: ppload(vCTS, 0); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1401 case Bytecodes::_iload_1:
a61af66fc99e Initial load
duke
parents:
diff changeset
1402 case Bytecodes::_fload_1: ppload(vCTS, 1); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1403 case Bytecodes::_iload_2:
a61af66fc99e Initial load
duke
parents:
diff changeset
1404 case Bytecodes::_fload_2: ppload(vCTS, 2); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1405 case Bytecodes::_iload_3:
a61af66fc99e Initial load
duke
parents:
diff changeset
1406 case Bytecodes::_fload_3: ppload(vCTS, 3); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1407
a61af66fc99e Initial load
duke
parents:
diff changeset
1408 case Bytecodes::_lload_0:
a61af66fc99e Initial load
duke
parents:
diff changeset
1409 case Bytecodes::_dload_0: ppload(vvCTS, 0); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1410 case Bytecodes::_lload_1:
a61af66fc99e Initial load
duke
parents:
diff changeset
1411 case Bytecodes::_dload_1: ppload(vvCTS, 1); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1412 case Bytecodes::_lload_2:
a61af66fc99e Initial load
duke
parents:
diff changeset
1413 case Bytecodes::_dload_2: ppload(vvCTS, 2); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1414 case Bytecodes::_lload_3:
a61af66fc99e Initial load
duke
parents:
diff changeset
1415 case Bytecodes::_dload_3: ppload(vvCTS, 3); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1416
a61af66fc99e Initial load
duke
parents:
diff changeset
1417 case Bytecodes::_aload_0: ppload(rCTS, 0); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1418 case Bytecodes::_aload_1: ppload(rCTS, 1); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1419 case Bytecodes::_aload_2: ppload(rCTS, 2); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1420 case Bytecodes::_aload_3: ppload(rCTS, 3); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1421
a61af66fc99e Initial load
duke
parents:
diff changeset
1422 case Bytecodes::_iaload:
a61af66fc99e Initial load
duke
parents:
diff changeset
1423 case Bytecodes::_faload:
a61af66fc99e Initial load
duke
parents:
diff changeset
1424 case Bytecodes::_baload:
a61af66fc99e Initial load
duke
parents:
diff changeset
1425 case Bytecodes::_caload:
a61af66fc99e Initial load
duke
parents:
diff changeset
1426 case Bytecodes::_saload: pp(vrCTS, vCTS); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1427
a61af66fc99e Initial load
duke
parents:
diff changeset
1428 case Bytecodes::_laload: pp(vrCTS, vvCTS); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1429 case Bytecodes::_daload: pp(vrCTS, vvCTS); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1430
a61af66fc99e Initial load
duke
parents:
diff changeset
1431 case Bytecodes::_aaload: pp_new_ref(vrCTS, itr->bci()); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1432
a61af66fc99e Initial load
duke
parents:
diff changeset
1433 case Bytecodes::_istore:
a61af66fc99e Initial load
duke
parents:
diff changeset
1434 case Bytecodes::_fstore: ppstore(vCTS, itr->get_index()); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1435
a61af66fc99e Initial load
duke
parents:
diff changeset
1436 case Bytecodes::_lstore:
a61af66fc99e Initial load
duke
parents:
diff changeset
1437 case Bytecodes::_dstore: ppstore(vvCTS, itr->get_index()); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1438
a61af66fc99e Initial load
duke
parents:
diff changeset
1439 case Bytecodes::_astore: do_astore(itr->get_index()); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1440
a61af66fc99e Initial load
duke
parents:
diff changeset
1441 case Bytecodes::_istore_0:
a61af66fc99e Initial load
duke
parents:
diff changeset
1442 case Bytecodes::_fstore_0: ppstore(vCTS, 0); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1443 case Bytecodes::_istore_1:
a61af66fc99e Initial load
duke
parents:
diff changeset
1444 case Bytecodes::_fstore_1: ppstore(vCTS, 1); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1445 case Bytecodes::_istore_2:
a61af66fc99e Initial load
duke
parents:
diff changeset
1446 case Bytecodes::_fstore_2: ppstore(vCTS, 2); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1447 case Bytecodes::_istore_3:
a61af66fc99e Initial load
duke
parents:
diff changeset
1448 case Bytecodes::_fstore_3: ppstore(vCTS, 3); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1449
a61af66fc99e Initial load
duke
parents:
diff changeset
1450 case Bytecodes::_lstore_0:
a61af66fc99e Initial load
duke
parents:
diff changeset
1451 case Bytecodes::_dstore_0: ppstore(vvCTS, 0); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1452 case Bytecodes::_lstore_1:
a61af66fc99e Initial load
duke
parents:
diff changeset
1453 case Bytecodes::_dstore_1: ppstore(vvCTS, 1); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1454 case Bytecodes::_lstore_2:
a61af66fc99e Initial load
duke
parents:
diff changeset
1455 case Bytecodes::_dstore_2: ppstore(vvCTS, 2); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1456 case Bytecodes::_lstore_3:
a61af66fc99e Initial load
duke
parents:
diff changeset
1457 case Bytecodes::_dstore_3: ppstore(vvCTS, 3); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1458
a61af66fc99e Initial load
duke
parents:
diff changeset
1459 case Bytecodes::_astore_0: do_astore(0); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1460 case Bytecodes::_astore_1: do_astore(1); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1461 case Bytecodes::_astore_2: do_astore(2); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1462 case Bytecodes::_astore_3: do_astore(3); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1463
a61af66fc99e Initial load
duke
parents:
diff changeset
1464 case Bytecodes::_iastore:
a61af66fc99e Initial load
duke
parents:
diff changeset
1465 case Bytecodes::_fastore:
a61af66fc99e Initial load
duke
parents:
diff changeset
1466 case Bytecodes::_bastore:
a61af66fc99e Initial load
duke
parents:
diff changeset
1467 case Bytecodes::_castore:
a61af66fc99e Initial load
duke
parents:
diff changeset
1468 case Bytecodes::_sastore: ppop(vvrCTS); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1469 case Bytecodes::_lastore:
a61af66fc99e Initial load
duke
parents:
diff changeset
1470 case Bytecodes::_dastore: ppop(vvvrCTS); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1471 case Bytecodes::_aastore: ppop(rvrCTS); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1472
a61af66fc99e Initial load
duke
parents:
diff changeset
1473 case Bytecodes::_pop: ppop_any(1); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1474 case Bytecodes::_pop2: ppop_any(2); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1475
a61af66fc99e Initial load
duke
parents:
diff changeset
1476 case Bytecodes::_dup: ppdupswap(1, "11"); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1477 case Bytecodes::_dup_x1: ppdupswap(2, "121"); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1478 case Bytecodes::_dup_x2: ppdupswap(3, "1321"); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1479 case Bytecodes::_dup2: ppdupswap(2, "2121"); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1480 case Bytecodes::_dup2_x1: ppdupswap(3, "21321"); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1481 case Bytecodes::_dup2_x2: ppdupswap(4, "214321"); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1482 case Bytecodes::_swap: ppdupswap(2, "12"); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1483
a61af66fc99e Initial load
duke
parents:
diff changeset
1484 case Bytecodes::_iadd:
a61af66fc99e Initial load
duke
parents:
diff changeset
1485 case Bytecodes::_fadd:
a61af66fc99e Initial load
duke
parents:
diff changeset
1486 case Bytecodes::_isub:
a61af66fc99e Initial load
duke
parents:
diff changeset
1487 case Bytecodes::_fsub:
a61af66fc99e Initial load
duke
parents:
diff changeset
1488 case Bytecodes::_imul:
a61af66fc99e Initial load
duke
parents:
diff changeset
1489 case Bytecodes::_fmul:
a61af66fc99e Initial load
duke
parents:
diff changeset
1490 case Bytecodes::_idiv:
a61af66fc99e Initial load
duke
parents:
diff changeset
1491 case Bytecodes::_fdiv:
a61af66fc99e Initial load
duke
parents:
diff changeset
1492 case Bytecodes::_irem:
a61af66fc99e Initial load
duke
parents:
diff changeset
1493 case Bytecodes::_frem:
a61af66fc99e Initial load
duke
parents:
diff changeset
1494 case Bytecodes::_ishl:
a61af66fc99e Initial load
duke
parents:
diff changeset
1495 case Bytecodes::_ishr:
a61af66fc99e Initial load
duke
parents:
diff changeset
1496 case Bytecodes::_iushr:
a61af66fc99e Initial load
duke
parents:
diff changeset
1497 case Bytecodes::_iand:
a61af66fc99e Initial load
duke
parents:
diff changeset
1498 case Bytecodes::_ior:
a61af66fc99e Initial load
duke
parents:
diff changeset
1499 case Bytecodes::_ixor:
a61af66fc99e Initial load
duke
parents:
diff changeset
1500 case Bytecodes::_l2f:
a61af66fc99e Initial load
duke
parents:
diff changeset
1501 case Bytecodes::_l2i:
a61af66fc99e Initial load
duke
parents:
diff changeset
1502 case Bytecodes::_d2f:
a61af66fc99e Initial load
duke
parents:
diff changeset
1503 case Bytecodes::_d2i:
a61af66fc99e Initial load
duke
parents:
diff changeset
1504 case Bytecodes::_fcmpl:
a61af66fc99e Initial load
duke
parents:
diff changeset
1505 case Bytecodes::_fcmpg: pp(vvCTS, vCTS); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1506
a61af66fc99e Initial load
duke
parents:
diff changeset
1507 case Bytecodes::_ladd:
a61af66fc99e Initial load
duke
parents:
diff changeset
1508 case Bytecodes::_dadd:
a61af66fc99e Initial load
duke
parents:
diff changeset
1509 case Bytecodes::_lsub:
a61af66fc99e Initial load
duke
parents:
diff changeset
1510 case Bytecodes::_dsub:
a61af66fc99e Initial load
duke
parents:
diff changeset
1511 case Bytecodes::_lmul:
a61af66fc99e Initial load
duke
parents:
diff changeset
1512 case Bytecodes::_dmul:
a61af66fc99e Initial load
duke
parents:
diff changeset
1513 case Bytecodes::_ldiv:
a61af66fc99e Initial load
duke
parents:
diff changeset
1514 case Bytecodes::_ddiv:
a61af66fc99e Initial load
duke
parents:
diff changeset
1515 case Bytecodes::_lrem:
a61af66fc99e Initial load
duke
parents:
diff changeset
1516 case Bytecodes::_drem:
a61af66fc99e Initial load
duke
parents:
diff changeset
1517 case Bytecodes::_land:
a61af66fc99e Initial load
duke
parents:
diff changeset
1518 case Bytecodes::_lor:
a61af66fc99e Initial load
duke
parents:
diff changeset
1519 case Bytecodes::_lxor: pp(vvvvCTS, vvCTS); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1520
a61af66fc99e Initial load
duke
parents:
diff changeset
1521 case Bytecodes::_ineg:
a61af66fc99e Initial load
duke
parents:
diff changeset
1522 case Bytecodes::_fneg:
a61af66fc99e Initial load
duke
parents:
diff changeset
1523 case Bytecodes::_i2f:
a61af66fc99e Initial load
duke
parents:
diff changeset
1524 case Bytecodes::_f2i:
a61af66fc99e Initial load
duke
parents:
diff changeset
1525 case Bytecodes::_i2c:
a61af66fc99e Initial load
duke
parents:
diff changeset
1526 case Bytecodes::_i2s:
a61af66fc99e Initial load
duke
parents:
diff changeset
1527 case Bytecodes::_i2b: pp(vCTS, vCTS); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1528
a61af66fc99e Initial load
duke
parents:
diff changeset
1529 case Bytecodes::_lneg:
a61af66fc99e Initial load
duke
parents:
diff changeset
1530 case Bytecodes::_dneg:
a61af66fc99e Initial load
duke
parents:
diff changeset
1531 case Bytecodes::_l2d:
a61af66fc99e Initial load
duke
parents:
diff changeset
1532 case Bytecodes::_d2l: pp(vvCTS, vvCTS); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1533
a61af66fc99e Initial load
duke
parents:
diff changeset
1534 case Bytecodes::_lshl:
a61af66fc99e Initial load
duke
parents:
diff changeset
1535 case Bytecodes::_lshr:
a61af66fc99e Initial load
duke
parents:
diff changeset
1536 case Bytecodes::_lushr: pp(vvvCTS, vvCTS); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1537
a61af66fc99e Initial load
duke
parents:
diff changeset
1538 case Bytecodes::_i2l:
a61af66fc99e Initial load
duke
parents:
diff changeset
1539 case Bytecodes::_i2d:
a61af66fc99e Initial load
duke
parents:
diff changeset
1540 case Bytecodes::_f2l:
a61af66fc99e Initial load
duke
parents:
diff changeset
1541 case Bytecodes::_f2d: pp(vCTS, vvCTS); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1542
a61af66fc99e Initial load
duke
parents:
diff changeset
1543 case Bytecodes::_lcmp: pp(vvvvCTS, vCTS); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1544 case Bytecodes::_dcmpl:
a61af66fc99e Initial load
duke
parents:
diff changeset
1545 case Bytecodes::_dcmpg: pp(vvvvCTS, vCTS); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1546
a61af66fc99e Initial load
duke
parents:
diff changeset
1547 case Bytecodes::_ifeq:
a61af66fc99e Initial load
duke
parents:
diff changeset
1548 case Bytecodes::_ifne:
a61af66fc99e Initial load
duke
parents:
diff changeset
1549 case Bytecodes::_iflt:
a61af66fc99e Initial load
duke
parents:
diff changeset
1550 case Bytecodes::_ifge:
a61af66fc99e Initial load
duke
parents:
diff changeset
1551 case Bytecodes::_ifgt:
a61af66fc99e Initial load
duke
parents:
diff changeset
1552 case Bytecodes::_ifle:
a61af66fc99e Initial load
duke
parents:
diff changeset
1553 case Bytecodes::_tableswitch: ppop1(valCTS);
a61af66fc99e Initial load
duke
parents:
diff changeset
1554 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1555 case Bytecodes::_ireturn:
a61af66fc99e Initial load
duke
parents:
diff changeset
1556 case Bytecodes::_freturn: do_return_monitor_check();
a61af66fc99e Initial load
duke
parents:
diff changeset
1557 ppop1(valCTS);
a61af66fc99e Initial load
duke
parents:
diff changeset
1558 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1559 case Bytecodes::_if_icmpeq:
a61af66fc99e Initial load
duke
parents:
diff changeset
1560 case Bytecodes::_if_icmpne:
a61af66fc99e Initial load
duke
parents:
diff changeset
1561 case Bytecodes::_if_icmplt:
a61af66fc99e Initial load
duke
parents:
diff changeset
1562 case Bytecodes::_if_icmpge:
a61af66fc99e Initial load
duke
parents:
diff changeset
1563 case Bytecodes::_if_icmpgt:
a61af66fc99e Initial load
duke
parents:
diff changeset
1564 case Bytecodes::_if_icmple: ppop(vvCTS);
a61af66fc99e Initial load
duke
parents:
diff changeset
1565 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1566
a61af66fc99e Initial load
duke
parents:
diff changeset
1567 case Bytecodes::_lreturn: do_return_monitor_check();
a61af66fc99e Initial load
duke
parents:
diff changeset
1568 ppop(vvCTS);
a61af66fc99e Initial load
duke
parents:
diff changeset
1569 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1570
a61af66fc99e Initial load
duke
parents:
diff changeset
1571 case Bytecodes::_dreturn: do_return_monitor_check();
a61af66fc99e Initial load
duke
parents:
diff changeset
1572 ppop(vvCTS);
a61af66fc99e Initial load
duke
parents:
diff changeset
1573 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1574
a61af66fc99e Initial load
duke
parents:
diff changeset
1575 case Bytecodes::_if_acmpeq:
a61af66fc99e Initial load
duke
parents:
diff changeset
1576 case Bytecodes::_if_acmpne: ppop(rrCTS); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1577
a61af66fc99e Initial load
duke
parents:
diff changeset
1578 case Bytecodes::_jsr: do_jsr(itr->dest()); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1579 case Bytecodes::_jsr_w: do_jsr(itr->dest_w()); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1580
3838
6a991dcb52bb 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 2177
diff changeset
1581 case Bytecodes::_getstatic: do_field(true, true, itr->get_index_u2_cpcache(), itr->bci()); break;
1565
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1489
diff changeset
1582 case Bytecodes::_putstatic: do_field(false, true, itr->get_index_u2_cpcache(), itr->bci()); break;
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1489
diff changeset
1583 case Bytecodes::_getfield: do_field(true, false, itr->get_index_u2_cpcache(), itr->bci()); break;
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1489
diff changeset
1584 case Bytecodes::_putfield: do_field(false, false, itr->get_index_u2_cpcache(), itr->bci()); break;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1585
1138
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 1059
diff changeset
1586 case Bytecodes::_invokevirtual:
1565
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1489
diff changeset
1587 case Bytecodes::_invokespecial: do_method(false, false, itr->get_index_u2_cpcache(), itr->bci()); break;
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1489
diff changeset
1588 case Bytecodes::_invokestatic: do_method(true, false, itr->get_index_u2_cpcache(), itr->bci()); break;
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1489
diff changeset
1589 case Bytecodes::_invokedynamic: do_method(true, false, itr->get_index_u4(), itr->bci()); break;
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1489
diff changeset
1590 case Bytecodes::_invokeinterface: do_method(false, true, itr->get_index_u2_cpcache(), itr->bci()); break;
1138
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 1059
diff changeset
1591 case Bytecodes::_newarray:
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 1059
diff changeset
1592 case Bytecodes::_anewarray: pp_new_ref(vCTS, itr->bci()); break;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1593 case Bytecodes::_checkcast: do_checkcast(); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1594 case Bytecodes::_arraylength:
a61af66fc99e Initial load
duke
parents:
diff changeset
1595 case Bytecodes::_instanceof: pp(rCTS, vCTS); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1596 case Bytecodes::_monitorenter: do_monitorenter(itr->bci()); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1597 case Bytecodes::_monitorexit: do_monitorexit(itr->bci()); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1598
a61af66fc99e Initial load
duke
parents:
diff changeset
1599 case Bytecodes::_athrow: // handled by do_exception_edge() BUT ...
a61af66fc99e Initial load
duke
parents:
diff changeset
1600 // vlh(apple): do_exception_edge() does not get
a61af66fc99e Initial load
duke
parents:
diff changeset
1601 // called if method has no exception handlers
a61af66fc99e Initial load
duke
parents:
diff changeset
1602 if ((!_has_exceptions) && (_monitor_top > 0)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1603 _monitor_safe = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1604 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1605 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1606
a61af66fc99e Initial load
duke
parents:
diff changeset
1607 case Bytecodes::_areturn: do_return_monitor_check();
a61af66fc99e Initial load
duke
parents:
diff changeset
1608 ppop1(refCTS);
a61af66fc99e Initial load
duke
parents:
diff changeset
1609 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1610 case Bytecodes::_ifnull:
a61af66fc99e Initial load
duke
parents:
diff changeset
1611 case Bytecodes::_ifnonnull: ppop1(refCTS); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1612 case Bytecodes::_multianewarray: do_multianewarray(*(itr->bcp()+3), itr->bci()); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1613
a61af66fc99e Initial load
duke
parents:
diff changeset
1614 case Bytecodes::_wide: fatal("Iterator should skip this bytecode"); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1615 case Bytecodes::_ret: break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1616
a61af66fc99e Initial load
duke
parents:
diff changeset
1617 // Java opcodes
a61af66fc99e Initial load
duke
parents:
diff changeset
1618 case Bytecodes::_lookupswitch: ppop1(valCTS); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1619
a61af66fc99e Initial load
duke
parents:
diff changeset
1620 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
1621 tty->print("unexpected opcode: %d\n", itr->code());
a61af66fc99e Initial load
duke
parents:
diff changeset
1622 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
1623 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1624 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1625 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1626
a61af66fc99e Initial load
duke
parents:
diff changeset
1627 void GenerateOopMap::check_type(CellTypeState expected, CellTypeState actual) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1628 if (!expected.equal_kind(actual)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1629 verify_error("wrong type on stack (found: %c expected: %c)", actual.to_char(), expected.to_char());
a61af66fc99e Initial load
duke
parents:
diff changeset
1630 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1631 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1632
a61af66fc99e Initial load
duke
parents:
diff changeset
1633 void GenerateOopMap::ppstore(CellTypeState *in, int loc_no) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1634 while(!(*in).is_bottom()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1635 CellTypeState expected =*in++;
a61af66fc99e Initial load
duke
parents:
diff changeset
1636 CellTypeState actual = pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
1637 check_type(expected, actual);
a61af66fc99e Initial load
duke
parents:
diff changeset
1638 assert(loc_no >= 0, "sanity check");
a61af66fc99e Initial load
duke
parents:
diff changeset
1639 set_var(loc_no++, actual);
a61af66fc99e Initial load
duke
parents:
diff changeset
1640 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1641 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1642
a61af66fc99e Initial load
duke
parents:
diff changeset
1643 void GenerateOopMap::ppload(CellTypeState *out, int loc_no) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1644 while(!(*out).is_bottom()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1645 CellTypeState out1 = *out++;
a61af66fc99e Initial load
duke
parents:
diff changeset
1646 CellTypeState vcts = get_var(loc_no);
a61af66fc99e Initial load
duke
parents:
diff changeset
1647 assert(out1.can_be_reference() || out1.can_be_value(),
a61af66fc99e Initial load
duke
parents:
diff changeset
1648 "can only load refs. and values.");
a61af66fc99e Initial load
duke
parents:
diff changeset
1649 if (out1.is_reference()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1650 assert(loc_no>=0, "sanity check");
a61af66fc99e Initial load
duke
parents:
diff changeset
1651 if (!vcts.is_reference()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1652 // We were asked to push a reference, but the type of the
a61af66fc99e Initial load
duke
parents:
diff changeset
1653 // variable can be something else
a61af66fc99e Initial load
duke
parents:
diff changeset
1654 _conflict = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1655 if (vcts.can_be_uninit()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1656 // It is a ref-uninit conflict (at least). If there are other
a61af66fc99e Initial load
duke
parents:
diff changeset
1657 // problems, we'll get them in the next round
a61af66fc99e Initial load
duke
parents:
diff changeset
1658 add_to_ref_init_set(loc_no);
a61af66fc99e Initial load
duke
parents:
diff changeset
1659 vcts = out1;
a61af66fc99e Initial load
duke
parents:
diff changeset
1660 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1661 // It wasn't a ref-uninit conflict. So must be a
a61af66fc99e Initial load
duke
parents:
diff changeset
1662 // ref-val or ref-pc conflict. Split the variable.
a61af66fc99e Initial load
duke
parents:
diff changeset
1663 record_refval_conflict(loc_no);
a61af66fc99e Initial load
duke
parents:
diff changeset
1664 vcts = out1;
a61af66fc99e Initial load
duke
parents:
diff changeset
1665 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1666 push(out1); // recover...
a61af66fc99e Initial load
duke
parents:
diff changeset
1667 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1668 push(vcts); // preserve reference.
a61af66fc99e Initial load
duke
parents:
diff changeset
1669 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1670 // Otherwise it is a conflict, but one that verification would
a61af66fc99e Initial load
duke
parents:
diff changeset
1671 // have caught if illegal. In particular, it can't be a topCTS
a61af66fc99e Initial load
duke
parents:
diff changeset
1672 // resulting from mergeing two difference pcCTS's since the verifier
a61af66fc99e Initial load
duke
parents:
diff changeset
1673 // would have rejected any use of such a merge.
a61af66fc99e Initial load
duke
parents:
diff changeset
1674 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1675 push(out1); // handle val/init conflict
a61af66fc99e Initial load
duke
parents:
diff changeset
1676 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1677 loc_no++;
a61af66fc99e Initial load
duke
parents:
diff changeset
1678 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1679 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1680
a61af66fc99e Initial load
duke
parents:
diff changeset
1681 void GenerateOopMap::ppdupswap(int poplen, const char *out) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1682 CellTypeState actual[5];
a61af66fc99e Initial load
duke
parents:
diff changeset
1683 assert(poplen < 5, "this must be less than length of actual vector");
a61af66fc99e Initial load
duke
parents:
diff changeset
1684
a61af66fc99e Initial load
duke
parents:
diff changeset
1685 // pop all arguments
a61af66fc99e Initial load
duke
parents:
diff changeset
1686 for(int i = 0; i < poplen; i++) actual[i] = pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
1687
a61af66fc99e Initial load
duke
parents:
diff changeset
1688 // put them back
a61af66fc99e Initial load
duke
parents:
diff changeset
1689 char push_ch = *out++;
a61af66fc99e Initial load
duke
parents:
diff changeset
1690 while (push_ch != '\0') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1691 int idx = push_ch - '1';
a61af66fc99e Initial load
duke
parents:
diff changeset
1692 assert(idx >= 0 && idx < poplen, "wrong arguments");
a61af66fc99e Initial load
duke
parents:
diff changeset
1693 push(actual[idx]);
a61af66fc99e Initial load
duke
parents:
diff changeset
1694 push_ch = *out++;
a61af66fc99e Initial load
duke
parents:
diff changeset
1695 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1696 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1697
a61af66fc99e Initial load
duke
parents:
diff changeset
1698 void GenerateOopMap::ppop1(CellTypeState out) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1699 CellTypeState actual = pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
1700 check_type(out, actual);
a61af66fc99e Initial load
duke
parents:
diff changeset
1701 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1702
a61af66fc99e Initial load
duke
parents:
diff changeset
1703 void GenerateOopMap::ppop(CellTypeState *out) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1704 while (!(*out).is_bottom()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1705 ppop1(*out++);
a61af66fc99e Initial load
duke
parents:
diff changeset
1706 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1707 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1708
a61af66fc99e Initial load
duke
parents:
diff changeset
1709 void GenerateOopMap::ppush1(CellTypeState in) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1710 assert(in.is_reference() | in.is_value(), "sanity check");
a61af66fc99e Initial load
duke
parents:
diff changeset
1711 push(in);
a61af66fc99e Initial load
duke
parents:
diff changeset
1712 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1713
a61af66fc99e Initial load
duke
parents:
diff changeset
1714 void GenerateOopMap::ppush(CellTypeState *in) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1715 while (!(*in).is_bottom()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1716 ppush1(*in++);
a61af66fc99e Initial load
duke
parents:
diff changeset
1717 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1718 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1719
a61af66fc99e Initial load
duke
parents:
diff changeset
1720 void GenerateOopMap::pp(CellTypeState *in, CellTypeState *out) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1721 ppop(in);
a61af66fc99e Initial load
duke
parents:
diff changeset
1722 ppush(out);
a61af66fc99e Initial load
duke
parents:
diff changeset
1723 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1724
a61af66fc99e Initial load
duke
parents:
diff changeset
1725 void GenerateOopMap::pp_new_ref(CellTypeState *in, int bci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1726 ppop(in);
a61af66fc99e Initial load
duke
parents:
diff changeset
1727 ppush1(CellTypeState::make_line_ref(bci));
a61af66fc99e Initial load
duke
parents:
diff changeset
1728 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1729
a61af66fc99e Initial load
duke
parents:
diff changeset
1730 void GenerateOopMap::ppop_any(int poplen) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1731 if (_stack_top >= poplen) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1732 _stack_top -= poplen;
a61af66fc99e Initial load
duke
parents:
diff changeset
1733 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1734 verify_error("stack underflow");
a61af66fc99e Initial load
duke
parents:
diff changeset
1735 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1736 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1737
a61af66fc99e Initial load
duke
parents:
diff changeset
1738 // Replace all occurences of the state 'match' with the state 'replace'
a61af66fc99e Initial load
duke
parents:
diff changeset
1739 // in our current state vector.
a61af66fc99e Initial load
duke
parents:
diff changeset
1740 void GenerateOopMap::replace_all_CTS_matches(CellTypeState match,
a61af66fc99e Initial load
duke
parents:
diff changeset
1741 CellTypeState replace) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1742 int i;
a61af66fc99e Initial load
duke
parents:
diff changeset
1743 int len = _max_locals + _stack_top;
a61af66fc99e Initial load
duke
parents:
diff changeset
1744 bool change = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1745
a61af66fc99e Initial load
duke
parents:
diff changeset
1746 for (i = len - 1; i >= 0; i--) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1747 if (match.equal(_state[i])) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1748 _state[i] = replace;
a61af66fc99e Initial load
duke
parents:
diff changeset
1749 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1750 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1751
a61af66fc99e Initial load
duke
parents:
diff changeset
1752 if (_monitor_top > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1753 int base = _max_locals + _max_stack;
a61af66fc99e Initial load
duke
parents:
diff changeset
1754 len = base + _monitor_top;
a61af66fc99e Initial load
duke
parents:
diff changeset
1755 for (i = len - 1; i >= base; i--) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1756 if (match.equal(_state[i])) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1757 _state[i] = replace;
a61af66fc99e Initial load
duke
parents:
diff changeset
1758 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1759 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1760 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1761 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1762
a61af66fc99e Initial load
duke
parents:
diff changeset
1763 void GenerateOopMap::do_checkcast() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1764 CellTypeState actual = pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
1765 check_type(refCTS, actual);
a61af66fc99e Initial load
duke
parents:
diff changeset
1766 push(actual);
a61af66fc99e Initial load
duke
parents:
diff changeset
1767 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1768
a61af66fc99e Initial load
duke
parents:
diff changeset
1769 void GenerateOopMap::do_monitorenter(int bci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1770 CellTypeState actual = pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
1771 if (_monitor_top == bad_monitors) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1772 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1773 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1774
a61af66fc99e Initial load
duke
parents:
diff changeset
1775 // Bail out when we get repeated locks on an identical monitor. This case
a61af66fc99e Initial load
duke
parents:
diff changeset
1776 // isn't too hard to handle and can be made to work if supporting nested
a61af66fc99e Initial load
duke
parents:
diff changeset
1777 // redundant synchronized statements becomes a priority.
a61af66fc99e Initial load
duke
parents:
diff changeset
1778 //
a61af66fc99e Initial load
duke
parents:
diff changeset
1779 // See also "Note" in do_monitorexit(), below.
a61af66fc99e Initial load
duke
parents:
diff changeset
1780 if (actual.is_lock_reference()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1781 _monitor_top = bad_monitors;
a61af66fc99e Initial load
duke
parents:
diff changeset
1782 _monitor_safe = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1783
a61af66fc99e Initial load
duke
parents:
diff changeset
1784 if (TraceMonitorMismatch) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1785 report_monitor_mismatch("nested redundant lock -- bailout...");
a61af66fc99e Initial load
duke
parents:
diff changeset
1786 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1787 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1788 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1789
a61af66fc99e Initial load
duke
parents:
diff changeset
1790 CellTypeState lock = CellTypeState::make_lock_ref(bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
1791 check_type(refCTS, actual);
a61af66fc99e Initial load
duke
parents:
diff changeset
1792 if (!actual.is_info_top()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1793 replace_all_CTS_matches(actual, lock);
a61af66fc99e Initial load
duke
parents:
diff changeset
1794 monitor_push(lock);
a61af66fc99e Initial load
duke
parents:
diff changeset
1795 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1796 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1797
a61af66fc99e Initial load
duke
parents:
diff changeset
1798 void GenerateOopMap::do_monitorexit(int bci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1799 CellTypeState actual = pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
1800 if (_monitor_top == bad_monitors) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1801 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1802 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1803 check_type(refCTS, actual);
a61af66fc99e Initial load
duke
parents:
diff changeset
1804 CellTypeState expected = monitor_pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
1805 if (!actual.is_lock_reference() || !expected.equal(actual)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1806 // The monitor we are exiting is not verifiably the one
a61af66fc99e Initial load
duke
parents:
diff changeset
1807 // on the top of our monitor stack. This causes a monitor
a61af66fc99e Initial load
duke
parents:
diff changeset
1808 // mismatch.
a61af66fc99e Initial load
duke
parents:
diff changeset
1809 _monitor_top = bad_monitors;
a61af66fc99e Initial load
duke
parents:
diff changeset
1810 _monitor_safe = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1811
a61af66fc99e Initial load
duke
parents:
diff changeset
1812 // We need to mark this basic block as changed so that
a61af66fc99e Initial load
duke
parents:
diff changeset
1813 // this monitorexit will be visited again. We need to
a61af66fc99e Initial load
duke
parents:
diff changeset
1814 // do this to ensure that we have accounted for the
a61af66fc99e Initial load
duke
parents:
diff changeset
1815 // possibility that this bytecode will throw an
a61af66fc99e Initial load
duke
parents:
diff changeset
1816 // exception.
a61af66fc99e Initial load
duke
parents:
diff changeset
1817 BasicBlock* bb = get_basic_block_containing(bci);
8773
2eef6d34833b 8009022: [parfait] Null pointer deference in hotspot/src/share/vm/oops/generateOopMap.cpp
morris
parents: 8104
diff changeset
1818 guarantee(bb != NULL, "no basic block for bci");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1819 bb->set_changed(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1820 bb->_monitor_top = bad_monitors;
a61af66fc99e Initial load
duke
parents:
diff changeset
1821
a61af66fc99e Initial load
duke
parents:
diff changeset
1822 if (TraceMonitorMismatch) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1823 report_monitor_mismatch("improper monitor pair");
a61af66fc99e Initial load
duke
parents:
diff changeset
1824 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1825 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1826 // This code is a fix for the case where we have repeated
a61af66fc99e Initial load
duke
parents:
diff changeset
1827 // locking of the same object in straightline code. We clear
a61af66fc99e Initial load
duke
parents:
diff changeset
1828 // out the lock when it is popped from the monitor stack
a61af66fc99e Initial load
duke
parents:
diff changeset
1829 // and replace it with an unobtrusive reference value that can
a61af66fc99e Initial load
duke
parents:
diff changeset
1830 // be locked again.
a61af66fc99e Initial load
duke
parents:
diff changeset
1831 //
a61af66fc99e Initial load
duke
parents:
diff changeset
1832 // Note: when generateOopMap is fixed to properly handle repeated,
a61af66fc99e Initial load
duke
parents:
diff changeset
1833 // nested, redundant locks on the same object, then this
a61af66fc99e Initial load
duke
parents:
diff changeset
1834 // fix will need to be removed at that time.
a61af66fc99e Initial load
duke
parents:
diff changeset
1835 replace_all_CTS_matches(actual, CellTypeState::make_line_ref(bci));
a61af66fc99e Initial load
duke
parents:
diff changeset
1836 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1837 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1838
a61af66fc99e Initial load
duke
parents:
diff changeset
1839 void GenerateOopMap::do_return_monitor_check() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1840 if (_monitor_top > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1841 // The monitor stack must be empty when we leave the method
a61af66fc99e Initial load
duke
parents:
diff changeset
1842 // for the monitors to be properly matched.
a61af66fc99e Initial load
duke
parents:
diff changeset
1843 _monitor_safe = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1844
a61af66fc99e Initial load
duke
parents:
diff changeset
1845 // Since there are no successors to the *return bytecode, it
a61af66fc99e Initial load
duke
parents:
diff changeset
1846 // isn't necessary to set _monitor_top to bad_monitors.
a61af66fc99e Initial load
duke
parents:
diff changeset
1847
a61af66fc99e Initial load
duke
parents:
diff changeset
1848 if (TraceMonitorMismatch) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1849 report_monitor_mismatch("non-empty monitor stack at return");
a61af66fc99e Initial load
duke
parents:
diff changeset
1850 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1851 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1852 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1853
a61af66fc99e Initial load
duke
parents:
diff changeset
1854 void GenerateOopMap::do_jsr(int targ_bci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1855 push(CellTypeState::make_addr(targ_bci));
a61af66fc99e Initial load
duke
parents:
diff changeset
1856 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1857
a61af66fc99e Initial load
duke
parents:
diff changeset
1858
a61af66fc99e Initial load
duke
parents:
diff changeset
1859
1910
d1896d1dda3e 6981788: GC map generator sometimes picks up the wrong kind of instruction operand
jrose
parents: 1681
diff changeset
1860 void GenerateOopMap::do_ldc(int bci) {
2142
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
1861 Bytecode_loadconstant ldc(method(), bci);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6266
diff changeset
1862 ConstantPool* cp = method()->constants();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6266
diff changeset
1863 constantTag tag = cp->tag_at(ldc.pool_index()); // idx is index in resolved_references
2142
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
1864 BasicType bt = ldc.result_type();
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6266
diff changeset
1865 CellTypeState cts;
17456
00bcb186fc5a 8029351: assert(bt != T_OBJECT) failed: Guard is incorrect in VM:defmeth
drchase
parents: 11009
diff changeset
1866 if (tag.basic_type() == T_OBJECT) {
00bcb186fc5a 8029351: assert(bt != T_OBJECT) failed: Guard is incorrect in VM:defmeth
drchase
parents: 11009
diff changeset
1867 assert(!tag.is_string_index() && !tag.is_klass_index(), "Unexpected index tag");
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6266
diff changeset
1868 assert(bt == T_OBJECT, "Guard is incorrect");
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6266
diff changeset
1869 cts = CellTypeState::make_line_ref(bci);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6266
diff changeset
1870 } else {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6266
diff changeset
1871 assert(bt != T_OBJECT, "Guard is incorrect");
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6266
diff changeset
1872 cts = valCTS;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6266
diff changeset
1873 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1874 ppush1(cts);
a61af66fc99e Initial load
duke
parents:
diff changeset
1875 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1876
a61af66fc99e Initial load
duke
parents:
diff changeset
1877 void GenerateOopMap::do_multianewarray(int dims, int bci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1878 assert(dims >= 1, "sanity check");
a61af66fc99e Initial load
duke
parents:
diff changeset
1879 for(int i = dims -1; i >=0; i--) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1880 ppop1(valCTS);
a61af66fc99e Initial load
duke
parents:
diff changeset
1881 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1882 ppush1(CellTypeState::make_line_ref(bci));
a61af66fc99e Initial load
duke
parents:
diff changeset
1883 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1884
a61af66fc99e Initial load
duke
parents:
diff changeset
1885 void GenerateOopMap::do_astore(int idx) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1886 CellTypeState r_or_p = pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
1887 if (!r_or_p.is_address() && !r_or_p.is_reference()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1888 // We actually expected ref or pc, but we only report that we expected a ref. It does not
a61af66fc99e Initial load
duke
parents:
diff changeset
1889 // really matter (at least for now)
a61af66fc99e Initial load
duke
parents:
diff changeset
1890 verify_error("wrong type on stack (found: %c, expected: {pr})", r_or_p.to_char());
a61af66fc99e Initial load
duke
parents:
diff changeset
1891 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1892 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1893 set_var(idx, r_or_p);
a61af66fc99e Initial load
duke
parents:
diff changeset
1894 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1895
a61af66fc99e Initial load
duke
parents:
diff changeset
1896 // Copies bottom/zero terminated CTS string from "src" into "dst".
a61af66fc99e Initial load
duke
parents:
diff changeset
1897 // Does NOT terminate with a bottom. Returns the number of cells copied.
a61af66fc99e Initial load
duke
parents:
diff changeset
1898 int GenerateOopMap::copy_cts(CellTypeState *dst, CellTypeState *src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1899 int idx = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1900 while (!src[idx].is_bottom()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1901 dst[idx] = src[idx];
a61af66fc99e Initial load
duke
parents:
diff changeset
1902 idx++;
a61af66fc99e Initial load
duke
parents:
diff changeset
1903 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1904 return idx;
a61af66fc99e Initial load
duke
parents:
diff changeset
1905 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1906
a61af66fc99e Initial load
duke
parents:
diff changeset
1907 void GenerateOopMap::do_field(int is_get, int is_static, int idx, int bci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1908 // Dig up signature for field in constant pool
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6266
diff changeset
1909 ConstantPool* cp = method()->constants();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1910 int nameAndTypeIdx = cp->name_and_type_ref_index_at(idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1911 int signatureIdx = cp->signature_ref_index_at(nameAndTypeIdx);
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 2142
diff changeset
1912 Symbol* signature = cp->symbol_at(signatureIdx);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1913
a61af66fc99e Initial load
duke
parents:
diff changeset
1914 // Parse signature (espcially simple for fields)
a61af66fc99e Initial load
duke
parents:
diff changeset
1915 assert(signature->utf8_length() > 0, "field signatures cannot have zero length");
a61af66fc99e Initial load
duke
parents:
diff changeset
1916 // The signature is UFT8 encoded, but the first char is always ASCII for signatures.
a61af66fc99e Initial load
duke
parents:
diff changeset
1917 char sigch = (char)*(signature->base());
a61af66fc99e Initial load
duke
parents:
diff changeset
1918 CellTypeState temp[4];
a61af66fc99e Initial load
duke
parents:
diff changeset
1919 CellTypeState *eff = sigchar_to_effect(sigch, bci, temp);
a61af66fc99e Initial load
duke
parents:
diff changeset
1920
a61af66fc99e Initial load
duke
parents:
diff changeset
1921 CellTypeState in[4];
a61af66fc99e Initial load
duke
parents:
diff changeset
1922 CellTypeState *out;
a61af66fc99e Initial load
duke
parents:
diff changeset
1923 int i = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1924
a61af66fc99e Initial load
duke
parents:
diff changeset
1925 if (is_get) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1926 out = eff;
a61af66fc99e Initial load
duke
parents:
diff changeset
1927 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1928 out = epsilonCTS;
a61af66fc99e Initial load
duke
parents:
diff changeset
1929 i = copy_cts(in, eff);
a61af66fc99e Initial load
duke
parents:
diff changeset
1930 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1931 if (!is_static) in[i++] = CellTypeState::ref;
a61af66fc99e Initial load
duke
parents:
diff changeset
1932 in[i] = CellTypeState::bottom;
a61af66fc99e Initial load
duke
parents:
diff changeset
1933 assert(i<=3, "sanity check");
a61af66fc99e Initial load
duke
parents:
diff changeset
1934 pp(in, out);
a61af66fc99e Initial load
duke
parents:
diff changeset
1935 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1936
a61af66fc99e Initial load
duke
parents:
diff changeset
1937 void GenerateOopMap::do_method(int is_static, int is_interface, int idx, int bci) {
1059
389049f3f393 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 844
diff changeset
1938 // Dig up signature for field in constant pool
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6266
diff changeset
1939 ConstantPool* cp = _method->constants();
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 2142
diff changeset
1940 Symbol* signature = cp->signature_ref_at(idx);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1941
a61af66fc99e Initial load
duke
parents:
diff changeset
1942 // Parse method signature
a61af66fc99e Initial load
duke
parents:
diff changeset
1943 CellTypeState out[4];
a61af66fc99e Initial load
duke
parents:
diff changeset
1944 CellTypeState in[MAXARGSIZE+1]; // Includes result
a61af66fc99e Initial load
duke
parents:
diff changeset
1945 ComputeCallStack cse(signature);
a61af66fc99e Initial load
duke
parents:
diff changeset
1946
a61af66fc99e Initial load
duke
parents:
diff changeset
1947 // Compute return type
a61af66fc99e Initial load
duke
parents:
diff changeset
1948 int res_length= cse.compute_for_returntype(out);
a61af66fc99e Initial load
duke
parents:
diff changeset
1949
a61af66fc99e Initial load
duke
parents:
diff changeset
1950 // Temporary hack.
a61af66fc99e Initial load
duke
parents:
diff changeset
1951 if (out[0].equal(CellTypeState::ref) && out[1].equal(CellTypeState::bottom)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1952 out[0] = CellTypeState::make_line_ref(bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
1953 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1954
a61af66fc99e Initial load
duke
parents:
diff changeset
1955 assert(res_length<=4, "max value should be vv");
a61af66fc99e Initial load
duke
parents:
diff changeset
1956
a61af66fc99e Initial load
duke
parents:
diff changeset
1957 // Compute arguments
a61af66fc99e Initial load
duke
parents:
diff changeset
1958 int arg_length = cse.compute_for_parameters(is_static != 0, in);
a61af66fc99e Initial load
duke
parents:
diff changeset
1959 assert(arg_length<=MAXARGSIZE, "too many locals");
a61af66fc99e Initial load
duke
parents:
diff changeset
1960
a61af66fc99e Initial load
duke
parents:
diff changeset
1961 // Pop arguments
a61af66fc99e Initial load
duke
parents:
diff changeset
1962 for (int i = arg_length - 1; i >= 0; i--) ppop1(in[i]);// Do args in reverse order.
a61af66fc99e Initial load
duke
parents:
diff changeset
1963
a61af66fc99e Initial load
duke
parents:
diff changeset
1964 // Report results
a61af66fc99e Initial load
duke
parents:
diff changeset
1965 if (_report_result_for_send == true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1966 fill_stackmap_for_opcodes(_itr_send, vars(), stack(), _stack_top);
a61af66fc99e Initial load
duke
parents:
diff changeset
1967 _report_result_for_send = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1968 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1969
a61af66fc99e Initial load
duke
parents:
diff changeset
1970 // Push return address
a61af66fc99e Initial load
duke
parents:
diff changeset
1971 ppush(out);
a61af66fc99e Initial load
duke
parents:
diff changeset
1972 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1973
a61af66fc99e Initial load
duke
parents:
diff changeset
1974 // This is used to parse the signature for fields, since they are very simple...
a61af66fc99e Initial load
duke
parents:
diff changeset
1975 CellTypeState *GenerateOopMap::sigchar_to_effect(char sigch, int bci, CellTypeState *out) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1976 // Object and array
a61af66fc99e Initial load
duke
parents:
diff changeset
1977 if (sigch=='L' || sigch=='[') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1978 out[0] = CellTypeState::make_line_ref(bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
1979 out[1] = CellTypeState::bottom;
a61af66fc99e Initial load
duke
parents:
diff changeset
1980 return out;
a61af66fc99e Initial load
duke
parents:
diff changeset
1981 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1982 if (sigch == 'J' || sigch == 'D' ) return vvCTS; // Long and Double
a61af66fc99e Initial load
duke
parents:
diff changeset
1983 if (sigch == 'V' ) return epsilonCTS; // Void
a61af66fc99e Initial load
duke
parents:
diff changeset
1984 return vCTS; // Otherwise
a61af66fc99e Initial load
duke
parents:
diff changeset
1985 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1986
a61af66fc99e Initial load
duke
parents:
diff changeset
1987 long GenerateOopMap::_total_byte_count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1988 elapsedTimer GenerateOopMap::_total_oopmap_time;
a61af66fc99e Initial load
duke
parents:
diff changeset
1989
a61af66fc99e Initial load
duke
parents:
diff changeset
1990 // This function assumes "bcs" is at a "ret" instruction and that the vars
a61af66fc99e Initial load
duke
parents:
diff changeset
1991 // state is valid for that instruction. Furthermore, the ret instruction
a61af66fc99e Initial load
duke
parents:
diff changeset
1992 // must be the last instruction in "bb" (we store information about the
a61af66fc99e Initial load
duke
parents:
diff changeset
1993 // "ret" in "bb").
a61af66fc99e Initial load
duke
parents:
diff changeset
1994 void GenerateOopMap::ret_jump_targets_do(BytecodeStream *bcs, jmpFct_t jmpFct, int varNo, int *data) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1995 CellTypeState ra = vars()[varNo];
a61af66fc99e Initial load
duke
parents:
diff changeset
1996 if (!ra.is_good_address()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1997 verify_error("ret returns from two jsr subroutines?");
a61af66fc99e Initial load
duke
parents:
diff changeset
1998 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1999 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2000 int target = ra.get_info();
a61af66fc99e Initial load
duke
parents:
diff changeset
2001
a61af66fc99e Initial load
duke
parents:
diff changeset
2002 RetTableEntry* rtEnt = _rt.find_jsrs_for_target(target);
a61af66fc99e Initial load
duke
parents:
diff changeset
2003 int bci = bcs->bci();
a61af66fc99e Initial load
duke
parents:
diff changeset
2004 for (int i = 0; i < rtEnt->nof_jsrs(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2005 int target_bci = rtEnt->jsrs(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
2006 // Make sure a jrtRet does not set the changed bit for dead basicblock.
a61af66fc99e Initial load
duke
parents:
diff changeset
2007 BasicBlock* jsr_bb = get_basic_block_containing(target_bci - 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
2008 debug_only(BasicBlock* target_bb = &jsr_bb[1];)
a61af66fc99e Initial load
duke
parents:
diff changeset
2009 assert(target_bb == get_basic_block_at(target_bci), "wrong calc. of successor basicblock");
a61af66fc99e Initial load
duke
parents:
diff changeset
2010 bool alive = jsr_bb->is_alive();
a61af66fc99e Initial load
duke
parents:
diff changeset
2011 if (TraceNewOopMapGeneration) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2012 tty->print("pc = %d, ret -> %d alive: %s\n", bci, target_bci, alive ? "true" : "false");
a61af66fc99e Initial load
duke
parents:
diff changeset
2013 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2014 if (alive) jmpFct(this, target_bci, data);
a61af66fc99e Initial load
duke
parents:
diff changeset
2015 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2016 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2017
a61af66fc99e Initial load
duke
parents:
diff changeset
2018 //
a61af66fc99e Initial load
duke
parents:
diff changeset
2019 // Debug method
a61af66fc99e Initial load
duke
parents:
diff changeset
2020 //
a61af66fc99e Initial load
duke
parents:
diff changeset
2021 char* GenerateOopMap::state_vec_to_string(CellTypeState* vec, int len) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2022 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
2023 int checklen = MAX3(_max_locals, _max_stack, _max_monitors) + 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
2024 assert(len < checklen, "state_vec_buf overflow");
a61af66fc99e Initial load
duke
parents:
diff changeset
2025 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
2026 for (int i = 0; i < len; i++) _state_vec_buf[i] = vec[i].to_char();
a61af66fc99e Initial load
duke
parents:
diff changeset
2027 _state_vec_buf[len] = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
2028 return _state_vec_buf;
a61af66fc99e Initial load
duke
parents:
diff changeset
2029 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2030
a61af66fc99e Initial load
duke
parents:
diff changeset
2031 void GenerateOopMap::print_time() {
a61af66fc99e Initial load
duke
parents:
diff changeset
2032 tty->print_cr ("Accumulated oopmap times:");
a61af66fc99e Initial load
duke
parents:
diff changeset
2033 tty->print_cr ("---------------------------");
a61af66fc99e Initial load
duke
parents:
diff changeset
2034 tty->print_cr (" Total : %3.3f sec.", GenerateOopMap::_total_oopmap_time.seconds());
a61af66fc99e Initial load
duke
parents:
diff changeset
2035 tty->print_cr (" (%3.0f bytecodes per sec) ",
a61af66fc99e Initial load
duke
parents:
diff changeset
2036 GenerateOopMap::_total_byte_count / GenerateOopMap::_total_oopmap_time.seconds());
a61af66fc99e Initial load
duke
parents:
diff changeset
2037 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2038
a61af66fc99e Initial load
duke
parents:
diff changeset
2039 //
a61af66fc99e Initial load
duke
parents:
diff changeset
2040 // ============ Main Entry Point ===========
a61af66fc99e Initial load
duke
parents:
diff changeset
2041 //
a61af66fc99e Initial load
duke
parents:
diff changeset
2042 GenerateOopMap::GenerateOopMap(methodHandle method) {
605
98cb887364d3 6810672: Comment typos
twisti
parents: 342
diff changeset
2043 // We have to initialize all variables here, that can be queried directly
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2044 _method = method;
a61af66fc99e Initial load
duke
parents:
diff changeset
2045 _max_locals=0;
a61af66fc99e Initial load
duke
parents:
diff changeset
2046 _init_vars = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
2047
a61af66fc99e Initial load
duke
parents:
diff changeset
2048 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
2049 // If we are doing a detailed trace, include the regular trace information.
a61af66fc99e Initial load
duke
parents:
diff changeset
2050 if (TraceNewOopMapGenerationDetailed) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2051 TraceNewOopMapGeneration = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
2052 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2053 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
2054 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2055
a61af66fc99e Initial load
duke
parents:
diff changeset
2056 void GenerateOopMap::compute_map(TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2057 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
2058 if (TimeOopMap2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2059 method()->print_short_name(tty);
a61af66fc99e Initial load
duke
parents:
diff changeset
2060 tty->print(" ");
a61af66fc99e Initial load
duke
parents:
diff changeset
2061 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2062 if (TimeOopMap) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2063 _total_byte_count += method()->code_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
2064 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2065 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
2066 TraceTime t_single("oopmap time", TimeOopMap2);
a61af66fc99e Initial load
duke
parents:
diff changeset
2067 TraceTime t_all(NULL, &_total_oopmap_time, TimeOopMap);
a61af66fc99e Initial load
duke
parents:
diff changeset
2068
a61af66fc99e Initial load
duke
parents:
diff changeset
2069 // Initialize values
a61af66fc99e Initial load
duke
parents:
diff changeset
2070 _got_error = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
2071 _conflict = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
2072 _max_locals = method()->max_locals();
a61af66fc99e Initial load
duke
parents:
diff changeset
2073 _max_stack = method()->max_stack();
6213
8150fa46d2ed 7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents: 3865
diff changeset
2074 _has_exceptions = (method()->has_exception_handler());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2075 _nof_refval_conflicts = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
2076 _init_vars = new GrowableArray<intptr_t>(5); // There are seldom more than 5 init_vars
a61af66fc99e Initial load
duke
parents:
diff changeset
2077 _report_result = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
2078 _report_result_for_send = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
2079 _new_var_map = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
2080 _ret_adr_tos = new GrowableArray<intptr_t>(5); // 5 seems like a good number;
a61af66fc99e Initial load
duke
parents:
diff changeset
2081 _did_rewriting = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
2082 _did_relocation = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
2083
a61af66fc99e Initial load
duke
parents:
diff changeset
2084 if (TraceNewOopMapGeneration) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2085 tty->print("Method name: %s\n", method()->name()->as_C_string());
a61af66fc99e Initial load
duke
parents:
diff changeset
2086 if (Verbose) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2087 _method->print_codes();
a61af66fc99e Initial load
duke
parents:
diff changeset
2088 tty->print_cr("Exception table:");
6213
8150fa46d2ed 7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents: 3865
diff changeset
2089 ExceptionTable excps(method());
8150fa46d2ed 7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents: 3865
diff changeset
2090 for(int i = 0; i < excps.length(); i ++) {
8150fa46d2ed 7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents: 3865
diff changeset
2091 tty->print_cr("[%d - %d] -> %d",
8150fa46d2ed 7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents: 3865
diff changeset
2092 excps.start_pc(i), excps.end_pc(i), excps.handler_pc(i));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2093 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2094 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2095 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2096
a61af66fc99e Initial load
duke
parents:
diff changeset
2097 // if no code - do nothing
a61af66fc99e Initial load
duke
parents:
diff changeset
2098 // compiler needs info
a61af66fc99e Initial load
duke
parents:
diff changeset
2099 if (method()->code_size() == 0 || _max_locals + method()->max_stack() == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2100 fill_stackmap_prolog(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
2101 fill_stackmap_epilog();
a61af66fc99e Initial load
duke
parents:
diff changeset
2102 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2103 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2104 // Step 1: Compute all jump targets and their return value
a61af66fc99e Initial load
duke
parents:
diff changeset
2105 if (!_got_error)
a61af66fc99e Initial load
duke
parents:
diff changeset
2106 _rt.compute_ret_table(_method);
a61af66fc99e Initial load
duke
parents:
diff changeset
2107
a61af66fc99e Initial load
duke
parents:
diff changeset
2108 // Step 2: Find all basic blocks and count GC points
a61af66fc99e Initial load
duke
parents:
diff changeset
2109 if (!_got_error)
a61af66fc99e Initial load
duke
parents:
diff changeset
2110 mark_bbheaders_and_count_gc_points();
a61af66fc99e Initial load
duke
parents:
diff changeset
2111
a61af66fc99e Initial load
duke
parents:
diff changeset
2112 // Step 3: Calculate stack maps
a61af66fc99e Initial load
duke
parents:
diff changeset
2113 if (!_got_error)
a61af66fc99e Initial load
duke
parents:
diff changeset
2114 do_interpretation();
a61af66fc99e Initial load
duke
parents:
diff changeset
2115
a61af66fc99e Initial load
duke
parents:
diff changeset
2116 // Step 4:Return results
a61af66fc99e Initial load
duke
parents:
diff changeset
2117 if (!_got_error && report_results())
a61af66fc99e Initial load
duke
parents:
diff changeset
2118 report_result();
a61af66fc99e Initial load
duke
parents:
diff changeset
2119
a61af66fc99e Initial load
duke
parents:
diff changeset
2120 if (_got_error) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2121 THROW_HANDLE(_exception);
a61af66fc99e Initial load
duke
parents:
diff changeset
2122 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2123 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2124
a61af66fc99e Initial load
duke
parents:
diff changeset
2125 // Error handling methods
a61af66fc99e Initial load
duke
parents:
diff changeset
2126 // These methods create an exception for the current thread which is thrown
a61af66fc99e Initial load
duke
parents:
diff changeset
2127 // at the bottom of the call stack, when it returns to compute_map(). The
a61af66fc99e Initial load
duke
parents:
diff changeset
2128 // _got_error flag controls execution. NOT TODO: The VM exception propagation
a61af66fc99e Initial load
duke
parents:
diff changeset
2129 // mechanism using TRAPS/CHECKs could be used here instead but it would need
a61af66fc99e Initial load
duke
parents:
diff changeset
2130 // to be added as a parameter to every function and checked for every call.
a61af66fc99e Initial load
duke
parents:
diff changeset
2131 // The tons of extra code it would generate didn't seem worth the change.
a61af66fc99e Initial load
duke
parents:
diff changeset
2132 //
a61af66fc99e Initial load
duke
parents:
diff changeset
2133 void GenerateOopMap::error_work(const char *format, va_list ap) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2134 _got_error = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
2135 char msg_buffer[512];
a61af66fc99e Initial load
duke
parents:
diff changeset
2136 vsnprintf(msg_buffer, sizeof(msg_buffer), format, ap);
a61af66fc99e Initial load
duke
parents:
diff changeset
2137 // Append method name
a61af66fc99e Initial load
duke
parents:
diff changeset
2138 char msg_buffer2[512];
a61af66fc99e Initial load
duke
parents:
diff changeset
2139 jio_snprintf(msg_buffer2, sizeof(msg_buffer2), "%s in method %s", msg_buffer, method()->name()->as_C_string());
a61af66fc99e Initial load
duke
parents:
diff changeset
2140 _exception = Exceptions::new_exception(Thread::current(),
a61af66fc99e Initial load
duke
parents:
diff changeset
2141 vmSymbols::java_lang_LinkageError(), msg_buffer2);
a61af66fc99e Initial load
duke
parents:
diff changeset
2142 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2143
a61af66fc99e Initial load
duke
parents:
diff changeset
2144 void GenerateOopMap::report_error(const char *format, ...) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2145 va_list ap;
a61af66fc99e Initial load
duke
parents:
diff changeset
2146 va_start(ap, format);
a61af66fc99e Initial load
duke
parents:
diff changeset
2147 error_work(format, ap);
a61af66fc99e Initial load
duke
parents:
diff changeset
2148 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2149
a61af66fc99e Initial load
duke
parents:
diff changeset
2150 void GenerateOopMap::verify_error(const char *format, ...) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2151 // We do not distinguish between different types of errors for verification
a61af66fc99e Initial load
duke
parents:
diff changeset
2152 // errors. Let the verifier give a better message.
a61af66fc99e Initial load
duke
parents:
diff changeset
2153 const char *msg = "Illegal class file encountered. Try running with -Xverify:all";
1681
126ea7725993 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 1579
diff changeset
2154 _got_error = true;
126ea7725993 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 1579
diff changeset
2155 // Append method name
126ea7725993 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 1579
diff changeset
2156 char msg_buffer2[512];
126ea7725993 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 1579
diff changeset
2157 jio_snprintf(msg_buffer2, sizeof(msg_buffer2), "%s in method %s", msg,
126ea7725993 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 1579
diff changeset
2158 method()->name()->as_C_string());
126ea7725993 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 1579
diff changeset
2159 _exception = Exceptions::new_exception(Thread::current(),
126ea7725993 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 1579
diff changeset
2160 vmSymbols::java_lang_LinkageError(), msg_buffer2);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2161 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2162
a61af66fc99e Initial load
duke
parents:
diff changeset
2163 //
a61af66fc99e Initial load
duke
parents:
diff changeset
2164 // Report result opcodes
a61af66fc99e Initial load
duke
parents:
diff changeset
2165 //
a61af66fc99e Initial load
duke
parents:
diff changeset
2166 void GenerateOopMap::report_result() {
a61af66fc99e Initial load
duke
parents:
diff changeset
2167
a61af66fc99e Initial load
duke
parents:
diff changeset
2168 if (TraceNewOopMapGeneration) tty->print_cr("Report result pass");
a61af66fc99e Initial load
duke
parents:
diff changeset
2169
a61af66fc99e Initial load
duke
parents:
diff changeset
2170 // We now want to report the result of the parse
a61af66fc99e Initial load
duke
parents:
diff changeset
2171 _report_result = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
2172
a61af66fc99e Initial load
duke
parents:
diff changeset
2173 // Prolog code
a61af66fc99e Initial load
duke
parents:
diff changeset
2174 fill_stackmap_prolog(_gc_points);
a61af66fc99e Initial load
duke
parents:
diff changeset
2175
a61af66fc99e Initial load
duke
parents:
diff changeset
2176 // Mark everything changed, then do one interpretation pass.
a61af66fc99e Initial load
duke
parents:
diff changeset
2177 for (int i = 0; i<_bb_count; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2178 if (_basic_blocks[i].is_reachable()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2179 _basic_blocks[i].set_changed(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
2180 interp_bb(&_basic_blocks[i]);
a61af66fc99e Initial load
duke
parents:
diff changeset
2181 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2182 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2183
a61af66fc99e Initial load
duke
parents:
diff changeset
2184 // Note: Since we are skipping dead-code when we are reporting results, then
a61af66fc99e Initial load
duke
parents:
diff changeset
2185 // the no. of encountered gc-points might be fewer than the previously number
a61af66fc99e Initial load
duke
parents:
diff changeset
2186 // we have counted. (dead-code is a pain - it should be removed before we get here)
a61af66fc99e Initial load
duke
parents:
diff changeset
2187 fill_stackmap_epilog();
a61af66fc99e Initial load
duke
parents:
diff changeset
2188
a61af66fc99e Initial load
duke
parents:
diff changeset
2189 // Report initvars
a61af66fc99e Initial load
duke
parents:
diff changeset
2190 fill_init_vars(_init_vars);
a61af66fc99e Initial load
duke
parents:
diff changeset
2191
a61af66fc99e Initial load
duke
parents:
diff changeset
2192 _report_result = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
2193 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2194
a61af66fc99e Initial load
duke
parents:
diff changeset
2195 void GenerateOopMap::result_for_basicblock(int bci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2196 if (TraceNewOopMapGeneration) tty->print_cr("Report result pass for basicblock");
a61af66fc99e Initial load
duke
parents:
diff changeset
2197
a61af66fc99e Initial load
duke
parents:
diff changeset
2198 // We now want to report the result of the parse
a61af66fc99e Initial load
duke
parents:
diff changeset
2199 _report_result = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
2200
a61af66fc99e Initial load
duke
parents:
diff changeset
2201 // Find basicblock and report results
a61af66fc99e Initial load
duke
parents:
diff changeset
2202 BasicBlock* bb = get_basic_block_containing(bci);
8773
2eef6d34833b 8009022: [parfait] Null pointer deference in hotspot/src/share/vm/oops/generateOopMap.cpp
morris
parents: 8104
diff changeset
2203 guarantee(bb != NULL, "no basic block for bci");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2204 assert(bb->is_reachable(), "getting result from unreachable basicblock");
a61af66fc99e Initial load
duke
parents:
diff changeset
2205 bb->set_changed(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
2206 interp_bb(bb);
a61af66fc99e Initial load
duke
parents:
diff changeset
2207 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2208
a61af66fc99e Initial load
duke
parents:
diff changeset
2209 //
a61af66fc99e Initial load
duke
parents:
diff changeset
2210 // Conflict handling code
a61af66fc99e Initial load
duke
parents:
diff changeset
2211 //
a61af66fc99e Initial load
duke
parents:
diff changeset
2212
a61af66fc99e Initial load
duke
parents:
diff changeset
2213 void GenerateOopMap::record_refval_conflict(int varNo) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2214 assert(varNo>=0 && varNo< _max_locals, "index out of range");
a61af66fc99e Initial load
duke
parents:
diff changeset
2215
a61af66fc99e Initial load
duke
parents:
diff changeset
2216 if (TraceOopMapRewrites) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2217 tty->print("### Conflict detected (local no: %d)\n", varNo);
a61af66fc99e Initial load
duke
parents:
diff changeset
2218 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2219
a61af66fc99e Initial load
duke
parents:
diff changeset
2220 if (!_new_var_map) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2221 _new_var_map = NEW_RESOURCE_ARRAY(int, _max_locals);
a61af66fc99e Initial load
duke
parents:
diff changeset
2222 for (int k = 0; k < _max_locals; k++) _new_var_map[k] = k;
a61af66fc99e Initial load
duke
parents:
diff changeset
2223 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2224
a61af66fc99e Initial load
duke
parents:
diff changeset
2225 if ( _new_var_map[varNo] == varNo) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2226 // Check if max. number of locals has been reached
a61af66fc99e Initial load
duke
parents:
diff changeset
2227 if (_max_locals + _nof_refval_conflicts >= MAX_LOCAL_VARS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2228 report_error("Rewriting exceeded local variable limit");
a61af66fc99e Initial load
duke
parents:
diff changeset
2229 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2230 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2231 _new_var_map[varNo] = _max_locals + _nof_refval_conflicts;
a61af66fc99e Initial load
duke
parents:
diff changeset
2232 _nof_refval_conflicts++;
a61af66fc99e Initial load
duke
parents:
diff changeset
2233 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2234 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2235
a61af66fc99e Initial load
duke
parents:
diff changeset
2236 void GenerateOopMap::rewrite_refval_conflicts()
a61af66fc99e Initial load
duke
parents:
diff changeset
2237 {
a61af66fc99e Initial load
duke
parents:
diff changeset
2238 // We can get here two ways: Either a rewrite conflict was detected, or
a61af66fc99e Initial load
duke
parents:
diff changeset
2239 // an uninitialize reference was detected. In the second case, we do not
a61af66fc99e Initial load
duke
parents:
diff changeset
2240 // do any rewriting, we just want to recompute the reference set with the
a61af66fc99e Initial load
duke
parents:
diff changeset
2241 // new information
a61af66fc99e Initial load
duke
parents:
diff changeset
2242
a61af66fc99e Initial load
duke
parents:
diff changeset
2243 int nof_conflicts = 0; // Used for debugging only
a61af66fc99e Initial load
duke
parents:
diff changeset
2244
a61af66fc99e Initial load
duke
parents:
diff changeset
2245 if ( _nof_refval_conflicts == 0 )
a61af66fc99e Initial load
duke
parents:
diff changeset
2246 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2247
a61af66fc99e Initial load
duke
parents:
diff changeset
2248 // Check if rewrites are allowed in this parse.
a61af66fc99e Initial load
duke
parents:
diff changeset
2249 if (!allow_rewrites() && !IgnoreRewrites) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2250 fatal("Rewriting method not allowed at this stage");
a61af66fc99e Initial load
duke
parents:
diff changeset
2251 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2252
a61af66fc99e Initial load
duke
parents:
diff changeset
2253
a61af66fc99e Initial load
duke
parents:
diff changeset
2254 // This following flag is to tempoary supress rewrites. The locals that might conflict will
a61af66fc99e Initial load
duke
parents:
diff changeset
2255 // all be set to contain values. This is UNSAFE - however, until the rewriting has been completely
a61af66fc99e Initial load
duke
parents:
diff changeset
2256 // tested it is nice to have.
a61af66fc99e Initial load
duke
parents:
diff changeset
2257 if (IgnoreRewrites) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2258 if (Verbose) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2259 tty->print("rewrites suppressed for local no. ");
a61af66fc99e Initial load
duke
parents:
diff changeset
2260 for (int l = 0; l < _max_locals; l++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2261 if (_new_var_map[l] != l) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2262 tty->print("%d ", l);
a61af66fc99e Initial load
duke
parents:
diff changeset
2263 vars()[l] = CellTypeState::value;
a61af66fc99e Initial load
duke
parents:
diff changeset
2264 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2265 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2266 tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
2267 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2268
a61af66fc99e Initial load
duke
parents:
diff changeset
2269 // That was that...
a61af66fc99e Initial load
duke
parents:
diff changeset
2270 _new_var_map = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
2271 _nof_refval_conflicts = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
2272 _conflict = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
2273
a61af66fc99e Initial load
duke
parents:
diff changeset
2274 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2275 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2276
a61af66fc99e Initial load
duke
parents:
diff changeset
2277 // Tracing flag
a61af66fc99e Initial load
duke
parents:
diff changeset
2278 _did_rewriting = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
2279
a61af66fc99e Initial load
duke
parents:
diff changeset
2280 if (TraceOopMapRewrites) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2281 tty->print_cr("ref/value conflict for method %s - bytecodes are getting rewritten", method()->name()->as_C_string());
a61af66fc99e Initial load
duke
parents:
diff changeset
2282 method()->print();
a61af66fc99e Initial load
duke
parents:
diff changeset
2283 method()->print_codes();
a61af66fc99e Initial load
duke
parents:
diff changeset
2284 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2285
a61af66fc99e Initial load
duke
parents:
diff changeset
2286 assert(_new_var_map!=NULL, "nothing to rewrite");
a61af66fc99e Initial load
duke
parents:
diff changeset
2287 assert(_conflict==true, "We should not be here");
a61af66fc99e Initial load
duke
parents:
diff changeset
2288
a61af66fc99e Initial load
duke
parents:
diff changeset
2289 compute_ret_adr_at_TOS();
a61af66fc99e Initial load
duke
parents:
diff changeset
2290 if (!_got_error) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2291 for (int k = 0; k < _max_locals && !_got_error; k++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2292 if (_new_var_map[k] != k) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2293 if (TraceOopMapRewrites) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2294 tty->print_cr("Rewriting: %d -> %d", k, _new_var_map[k]);
a61af66fc99e Initial load
duke
parents:
diff changeset
2295 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2296 rewrite_refval_conflict(k, _new_var_map[k]);
a61af66fc99e Initial load
duke
parents:
diff changeset
2297 if (_got_error) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2298 nof_conflicts++;
a61af66fc99e Initial load
duke
parents:
diff changeset
2299 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2300 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2301 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2302
a61af66fc99e Initial load
duke
parents:
diff changeset
2303 assert(nof_conflicts == _nof_refval_conflicts, "sanity check");
a61af66fc99e Initial load
duke
parents:
diff changeset
2304
a61af66fc99e Initial load
duke
parents:
diff changeset
2305 // Adjust the number of locals
a61af66fc99e Initial load
duke
parents:
diff changeset
2306 method()->set_max_locals(_max_locals+_nof_refval_conflicts);
a61af66fc99e Initial load
duke
parents:
diff changeset
2307 _max_locals += _nof_refval_conflicts;
a61af66fc99e Initial load
duke
parents:
diff changeset
2308
a61af66fc99e Initial load
duke
parents:
diff changeset
2309 // That was that...
a61af66fc99e Initial load
duke
parents:
diff changeset
2310 _new_var_map = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
2311 _nof_refval_conflicts = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
2312 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2313
a61af66fc99e Initial load
duke
parents:
diff changeset
2314 void GenerateOopMap::rewrite_refval_conflict(int from, int to) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2315 bool startOver;
a61af66fc99e Initial load
duke
parents:
diff changeset
2316 do {
a61af66fc99e Initial load
duke
parents:
diff changeset
2317 // Make sure that the BytecodeStream is constructed in the loop, since
a61af66fc99e Initial load
duke
parents:
diff changeset
2318 // during rewriting a new method oop is going to be used, and the next time
a61af66fc99e Initial load
duke
parents:
diff changeset
2319 // around we want to use that.
a61af66fc99e Initial load
duke
parents:
diff changeset
2320 BytecodeStream bcs(_method);
a61af66fc99e Initial load
duke
parents:
diff changeset
2321 startOver = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
2322
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6266
diff changeset
2323 while( !startOver && !_got_error &&
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6266
diff changeset
2324 // test bcs in case method changed and it became invalid
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6266
diff changeset
2325 bcs.next() >=0) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2326 startOver = rewrite_refval_conflict_inst(&bcs, from, to);
a61af66fc99e Initial load
duke
parents:
diff changeset
2327 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2328 } while (startOver && !_got_error);
a61af66fc99e Initial load
duke
parents:
diff changeset
2329 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2330
a61af66fc99e Initial load
duke
parents:
diff changeset
2331 /* If the current instruction is one that uses local variable "from"
a61af66fc99e Initial load
duke
parents:
diff changeset
2332 in a ref way, change it to use "to". There's a subtle reason why we
a61af66fc99e Initial load
duke
parents:
diff changeset
2333 renumber the ref uses and not the non-ref uses: non-ref uses may be
a61af66fc99e Initial load
duke
parents:
diff changeset
2334 2 slots wide (double, long) which would necessitate keeping track of
a61af66fc99e Initial load
duke
parents:
diff changeset
2335 whether we should add one or two variables to the method. If the change
a61af66fc99e Initial load
duke
parents:
diff changeset
2336 affected the width of some instruction, returns "TRUE"; otherwise, returns "FALSE".
a61af66fc99e Initial load
duke
parents:
diff changeset
2337 Another reason for moving ref's value is for solving (addr, ref) conflicts, which
a61af66fc99e Initial load
duke
parents:
diff changeset
2338 both uses aload/astore methods.
a61af66fc99e Initial load
duke
parents:
diff changeset
2339 */
a61af66fc99e Initial load
duke
parents:
diff changeset
2340 bool GenerateOopMap::rewrite_refval_conflict_inst(BytecodeStream *itr, int from, int to) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2341 Bytecodes::Code bc = itr->code();
a61af66fc99e Initial load
duke
parents:
diff changeset
2342 int index;
a61af66fc99e Initial load
duke
parents:
diff changeset
2343 int bci = itr->bci();
a61af66fc99e Initial load
duke
parents:
diff changeset
2344
a61af66fc99e Initial load
duke
parents:
diff changeset
2345 if (is_aload(itr, &index) && index == from) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2346 if (TraceOopMapRewrites) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2347 tty->print_cr("Rewriting aload at bci: %d", bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
2348 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2349 return rewrite_load_or_store(itr, Bytecodes::_aload, Bytecodes::_aload_0, to);
a61af66fc99e Initial load
duke
parents:
diff changeset
2350 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2351
a61af66fc99e Initial load
duke
parents:
diff changeset
2352 if (is_astore(itr, &index) && index == from) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2353 if (!stack_top_holds_ret_addr(bci)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2354 if (TraceOopMapRewrites) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2355 tty->print_cr("Rewriting astore at bci: %d", bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
2356 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2357 return rewrite_load_or_store(itr, Bytecodes::_astore, Bytecodes::_astore_0, to);
a61af66fc99e Initial load
duke
parents:
diff changeset
2358 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
2359 if (TraceOopMapRewrites) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2360 tty->print_cr("Supress rewriting of astore at bci: %d", bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
2361 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2362 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2363 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2364
a61af66fc99e Initial load
duke
parents:
diff changeset
2365 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
2366 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2367
a61af66fc99e Initial load
duke
parents:
diff changeset
2368 // The argument to this method is:
a61af66fc99e Initial load
duke
parents:
diff changeset
2369 // bc : Current bytecode
a61af66fc99e Initial load
duke
parents:
diff changeset
2370 // bcN : either _aload or _astore
a61af66fc99e Initial load
duke
parents:
diff changeset
2371 // bc0 : either _aload_0 or _astore_0
a61af66fc99e Initial load
duke
parents:
diff changeset
2372 bool GenerateOopMap::rewrite_load_or_store(BytecodeStream *bcs, Bytecodes::Code bcN, Bytecodes::Code bc0, unsigned int varNo) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2373 assert(bcN == Bytecodes::_astore || bcN == Bytecodes::_aload, "wrong argument (bcN)");
a61af66fc99e Initial load
duke
parents:
diff changeset
2374 assert(bc0 == Bytecodes::_astore_0 || bc0 == Bytecodes::_aload_0, "wrong argument (bc0)");
2142
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
2375 int ilen = Bytecodes::length_at(_method(), bcs->bcp());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2376 int newIlen;
a61af66fc99e Initial load
duke
parents:
diff changeset
2377
a61af66fc99e Initial load
duke
parents:
diff changeset
2378 if (ilen == 4) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2379 // Original instruction was wide; keep it wide for simplicity
a61af66fc99e Initial load
duke
parents:
diff changeset
2380 newIlen = 4;
a61af66fc99e Initial load
duke
parents:
diff changeset
2381 } else if (varNo < 4)
a61af66fc99e Initial load
duke
parents:
diff changeset
2382 newIlen = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
2383 else if (varNo >= 256)
a61af66fc99e Initial load
duke
parents:
diff changeset
2384 newIlen = 4;
a61af66fc99e Initial load
duke
parents:
diff changeset
2385 else
a61af66fc99e Initial load
duke
parents:
diff changeset
2386 newIlen = 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
2387
a61af66fc99e Initial load
duke
parents:
diff changeset
2388 // If we need to relocate in order to patch the byte, we
a61af66fc99e Initial load
duke
parents:
diff changeset
2389 // do the patching in a temp. buffer, that is passed to the reloc.
a61af66fc99e Initial load
duke
parents:
diff changeset
2390 // The patching of the bytecode stream is then done by the Relocator.
a61af66fc99e Initial load
duke
parents:
diff changeset
2391 // This is neccesary, since relocating the instruction at a certain bci, might
a61af66fc99e Initial load
duke
parents:
diff changeset
2392 // also relocate that instruction, e.g., if a _goto before it gets widen to a _goto_w.
a61af66fc99e Initial load
duke
parents:
diff changeset
2393 // Hence, we do not know which bci to patch after relocation.
a61af66fc99e Initial load
duke
parents:
diff changeset
2394
a61af66fc99e Initial load
duke
parents:
diff changeset
2395 assert(newIlen <= 4, "sanity check");
a61af66fc99e Initial load
duke
parents:
diff changeset
2396 u_char inst_buffer[4]; // Max. instruction size is 4.
a61af66fc99e Initial load
duke
parents:
diff changeset
2397 address bcp;
a61af66fc99e Initial load
duke
parents:
diff changeset
2398
a61af66fc99e Initial load
duke
parents:
diff changeset
2399 if (newIlen != ilen) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2400 // Relocation needed do patching in temp. buffer
a61af66fc99e Initial load
duke
parents:
diff changeset
2401 bcp = (address)inst_buffer;
a61af66fc99e Initial load
duke
parents:
diff changeset
2402 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
2403 bcp = _method->bcp_from(bcs->bci());
a61af66fc99e Initial load
duke
parents:
diff changeset
2404 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2405
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6266
diff changeset
2406 // Patch either directly in Method* or in temp. buffer
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2407 if (newIlen == 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2408 assert(varNo < 4, "varNo too large");
a61af66fc99e Initial load
duke
parents:
diff changeset
2409 *bcp = bc0 + varNo;
a61af66fc99e Initial load
duke
parents:
diff changeset
2410 } else if (newIlen == 2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2411 assert(varNo < 256, "2-byte index needed!");
a61af66fc99e Initial load
duke
parents:
diff changeset
2412 *(bcp + 0) = bcN;
a61af66fc99e Initial load
duke
parents:
diff changeset
2413 *(bcp + 1) = varNo;
a61af66fc99e Initial load
duke
parents:
diff changeset
2414 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
2415 assert(newIlen == 4, "Wrong instruction length");
a61af66fc99e Initial load
duke
parents:
diff changeset
2416 *(bcp + 0) = Bytecodes::_wide;
a61af66fc99e Initial load
duke
parents:
diff changeset
2417 *(bcp + 1) = bcN;
a61af66fc99e Initial load
duke
parents:
diff changeset
2418 Bytes::put_Java_u2(bcp+2, varNo);
a61af66fc99e Initial load
duke
parents:
diff changeset
2419 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2420
a61af66fc99e Initial load
duke
parents:
diff changeset
2421 if (newIlen != ilen) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2422 expand_current_instr(bcs->bci(), ilen, newIlen, inst_buffer);
a61af66fc99e Initial load
duke
parents:
diff changeset
2423 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2424
a61af66fc99e Initial load
duke
parents:
diff changeset
2425
a61af66fc99e Initial load
duke
parents:
diff changeset
2426 return (newIlen != ilen);
a61af66fc99e Initial load
duke
parents:
diff changeset
2427 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2428
a61af66fc99e Initial load
duke
parents:
diff changeset
2429 class RelocCallback : public RelocatorListener {
a61af66fc99e Initial load
duke
parents:
diff changeset
2430 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
2431 GenerateOopMap* _gom;
a61af66fc99e Initial load
duke
parents:
diff changeset
2432 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
2433 RelocCallback(GenerateOopMap* gom) { _gom = gom; };
a61af66fc99e Initial load
duke
parents:
diff changeset
2434
a61af66fc99e Initial load
duke
parents:
diff changeset
2435 // Callback method
a61af66fc99e Initial load
duke
parents:
diff changeset
2436 virtual void relocated(int bci, int delta, int new_code_length) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2437 _gom->update_basic_blocks (bci, delta, new_code_length);
a61af66fc99e Initial load
duke
parents:
diff changeset
2438 _gom->update_ret_adr_at_TOS(bci, delta);
a61af66fc99e Initial load
duke
parents:
diff changeset
2439 _gom->_rt.update_ret_table (bci, delta);
a61af66fc99e Initial load
duke
parents:
diff changeset
2440 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2441 };
a61af66fc99e Initial load
duke
parents:
diff changeset
2442
a61af66fc99e Initial load
duke
parents:
diff changeset
2443 // Returns true if expanding was succesful. Otherwise, reports an error and
a61af66fc99e Initial load
duke
parents:
diff changeset
2444 // returns false.
a61af66fc99e Initial load
duke
parents:
diff changeset
2445 void GenerateOopMap::expand_current_instr(int bci, int ilen, int newIlen, u_char inst_buffer[]) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2446 Thread *THREAD = Thread::current(); // Could really have TRAPS argument.
a61af66fc99e Initial load
duke
parents:
diff changeset
2447 RelocCallback rcb(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
2448 Relocator rc(_method, &rcb);
a61af66fc99e Initial load
duke
parents:
diff changeset
2449 methodHandle m= rc.insert_space_at(bci, newIlen, inst_buffer, THREAD);
a61af66fc99e Initial load
duke
parents:
diff changeset
2450 if (m.is_null() || HAS_PENDING_EXCEPTION) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2451 report_error("could not rewrite method - exception occurred or bytecode buffer overflow");
a61af66fc99e Initial load
duke
parents:
diff changeset
2452 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2453 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2454
a61af66fc99e Initial load
duke
parents:
diff changeset
2455 // Relocator returns a new method oop.
a61af66fc99e Initial load
duke
parents:
diff changeset
2456 _did_relocation = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
2457 _method = m;
a61af66fc99e Initial load
duke
parents:
diff changeset
2458 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2459
a61af66fc99e Initial load
duke
parents:
diff changeset
2460
a61af66fc99e Initial load
duke
parents:
diff changeset
2461 bool GenerateOopMap::is_astore(BytecodeStream *itr, int *index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2462 Bytecodes::Code bc = itr->code();
a61af66fc99e Initial load
duke
parents:
diff changeset
2463 switch(bc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2464 case Bytecodes::_astore_0:
a61af66fc99e Initial load
duke
parents:
diff changeset
2465 case Bytecodes::_astore_1:
a61af66fc99e Initial load
duke
parents:
diff changeset
2466 case Bytecodes::_astore_2:
a61af66fc99e Initial load
duke
parents:
diff changeset
2467 case Bytecodes::_astore_3:
a61af66fc99e Initial load
duke
parents:
diff changeset
2468 *index = bc - Bytecodes::_astore_0;
a61af66fc99e Initial load
duke
parents:
diff changeset
2469 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
2470 case Bytecodes::_astore:
a61af66fc99e Initial load
duke
parents:
diff changeset
2471 *index = itr->get_index();
a61af66fc99e Initial load
duke
parents:
diff changeset
2472 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
2473 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2474 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
2475 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2476
a61af66fc99e Initial load
duke
parents:
diff changeset
2477 bool GenerateOopMap::is_aload(BytecodeStream *itr, int *index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2478 Bytecodes::Code bc = itr->code();
a61af66fc99e Initial load
duke
parents:
diff changeset
2479 switch(bc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2480 case Bytecodes::_aload_0:
a61af66fc99e Initial load
duke
parents:
diff changeset
2481 case Bytecodes::_aload_1:
a61af66fc99e Initial load
duke
parents:
diff changeset
2482 case Bytecodes::_aload_2:
a61af66fc99e Initial load
duke
parents:
diff changeset
2483 case Bytecodes::_aload_3:
a61af66fc99e Initial load
duke
parents:
diff changeset
2484 *index = bc - Bytecodes::_aload_0;
a61af66fc99e Initial load
duke
parents:
diff changeset
2485 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
2486
a61af66fc99e Initial load
duke
parents:
diff changeset
2487 case Bytecodes::_aload:
a61af66fc99e Initial load
duke
parents:
diff changeset
2488 *index = itr->get_index();
a61af66fc99e Initial load
duke
parents:
diff changeset
2489 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
2490 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2491 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
2492 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2493
a61af66fc99e Initial load
duke
parents:
diff changeset
2494
a61af66fc99e Initial load
duke
parents:
diff changeset
2495 // Return true iff the top of the operand stack holds a return address at
a61af66fc99e Initial load
duke
parents:
diff changeset
2496 // the current instruction
a61af66fc99e Initial load
duke
parents:
diff changeset
2497 bool GenerateOopMap::stack_top_holds_ret_addr(int bci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2498 for(int i = 0; i < _ret_adr_tos->length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2499 if (_ret_adr_tos->at(i) == bci)
a61af66fc99e Initial load
duke
parents:
diff changeset
2500 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
2501 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2502
a61af66fc99e Initial load
duke
parents:
diff changeset
2503 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
2504 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2505
a61af66fc99e Initial load
duke
parents:
diff changeset
2506 void GenerateOopMap::compute_ret_adr_at_TOS() {
a61af66fc99e Initial load
duke
parents:
diff changeset
2507 assert(_ret_adr_tos != NULL, "must be initialized");
a61af66fc99e Initial load
duke
parents:
diff changeset
2508 _ret_adr_tos->clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
2509
a61af66fc99e Initial load
duke
parents:
diff changeset
2510 for (int i = 0; i < bb_count(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2511 BasicBlock* bb = &_basic_blocks[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
2512
a61af66fc99e Initial load
duke
parents:
diff changeset
2513 // Make sure to only check basicblocks that are reachable
a61af66fc99e Initial load
duke
parents:
diff changeset
2514 if (bb->is_reachable()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2515
a61af66fc99e Initial load
duke
parents:
diff changeset
2516 // For each Basic block we check all instructions
a61af66fc99e Initial load
duke
parents:
diff changeset
2517 BytecodeStream bcs(_method);
a61af66fc99e Initial load
duke
parents:
diff changeset
2518 bcs.set_interval(bb->_bci, next_bb_start_pc(bb));
a61af66fc99e Initial load
duke
parents:
diff changeset
2519
a61af66fc99e Initial load
duke
parents:
diff changeset
2520 restore_state(bb);
a61af66fc99e Initial load
duke
parents:
diff changeset
2521
a61af66fc99e Initial load
duke
parents:
diff changeset
2522 while (bcs.next()>=0 && !_got_error) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2523 // TDT: should this be is_good_address() ?
a61af66fc99e Initial load
duke
parents:
diff changeset
2524 if (_stack_top > 0 && stack()[_stack_top-1].is_address()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2525 _ret_adr_tos->append(bcs.bci());
a61af66fc99e Initial load
duke
parents:
diff changeset
2526 if (TraceNewOopMapGeneration) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2527 tty->print_cr("Ret_adr TOS at bci: %d", bcs.bci());
a61af66fc99e Initial load
duke
parents:
diff changeset
2528 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2529 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2530 interp1(&bcs);
a61af66fc99e Initial load
duke
parents:
diff changeset
2531 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2532 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2533 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2534 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2535
a61af66fc99e Initial load
duke
parents:
diff changeset
2536 void GenerateOopMap::update_ret_adr_at_TOS(int bci, int delta) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2537 for(int i = 0; i < _ret_adr_tos->length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2538 int v = _ret_adr_tos->at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
2539 if (v > bci) _ret_adr_tos->at_put(i, v + delta);
a61af66fc99e Initial load
duke
parents:
diff changeset
2540 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2541 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2542
a61af66fc99e Initial load
duke
parents:
diff changeset
2543 // ===================================================================
a61af66fc99e Initial load
duke
parents:
diff changeset
2544
a61af66fc99e Initial load
duke
parents:
diff changeset
2545 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
2546 int ResolveOopMapConflicts::_nof_invocations = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
2547 int ResolveOopMapConflicts::_nof_rewrites = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
2548 int ResolveOopMapConflicts::_nof_relocations = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
2549 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
2550
a61af66fc99e Initial load
duke
parents:
diff changeset
2551 methodHandle ResolveOopMapConflicts::do_potential_rewrite(TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2552 compute_map(CHECK_(methodHandle()));
a61af66fc99e Initial load
duke
parents:
diff changeset
2553
a61af66fc99e Initial load
duke
parents:
diff changeset
2554 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
2555 // Tracking and statistics
a61af66fc99e Initial load
duke
parents:
diff changeset
2556 if (PrintRewrites) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2557 _nof_invocations++;
a61af66fc99e Initial load
duke
parents:
diff changeset
2558 if (did_rewriting()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2559 _nof_rewrites++;
a61af66fc99e Initial load
duke
parents:
diff changeset
2560 if (did_relocation()) _nof_relocations++;
a61af66fc99e Initial load
duke
parents:
diff changeset
2561 tty->print("Method was rewritten %s: ", (did_relocation()) ? "and relocated" : "");
a61af66fc99e Initial load
duke
parents:
diff changeset
2562 method()->print_value(); tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
2563 tty->print_cr("Cand.: %d rewrts: %d (%d%%) reloc.: %d (%d%%)",
a61af66fc99e Initial load
duke
parents:
diff changeset
2564 _nof_invocations,
a61af66fc99e Initial load
duke
parents:
diff changeset
2565 _nof_rewrites, (_nof_rewrites * 100) / _nof_invocations,
a61af66fc99e Initial load
duke
parents:
diff changeset
2566 _nof_relocations, (_nof_relocations * 100) / _nof_invocations);
a61af66fc99e Initial load
duke
parents:
diff changeset
2567 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2568 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2569 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
2570 return methodHandle(THREAD, method());
a61af66fc99e Initial load
duke
parents:
diff changeset
2571 }