author | jrose |
Tue, 21 Apr 2009 23:21:04 -0700 | |
changeset 2570 | ecc7862946d4 |
parent 2105 | 347008ce7984 |
child 3273 | 6acf7084b1d3 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
2105 | 2 |
* Copyright 1998-2009 Sun Microsystems, Inc. All Rights Reserved. |
1 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
21 |
* have any questions. |
|
22 |
* |
|
23 |
*/ |
|
24 |
||
25 |
# include "incls/_precompiled.incl" |
|
26 |
# include "incls/_rewriter.cpp.incl" |
|
27 |
||
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
28 |
// Computes a CPC map (new_index -> original_index) for constant pool entries |
1 | 29 |
// that are referred to by the interpreter at runtime via the constant pool cache. |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
30 |
// Also computes a CP map (original_index -> new_index). |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
31 |
// Marks entries in CP which require additional processing. |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
32 |
void Rewriter::compute_index_maps() { |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
33 |
const int length = _pool->length(); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
34 |
init_cp_map(length); |
1 | 35 |
for (int i = 0; i < length; i++) { |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
36 |
int tag = _pool->tag_at(i).value(); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
37 |
switch (tag) { |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
38 |
case JVM_CONSTANT_InterfaceMethodref: |
1 | 39 |
case JVM_CONSTANT_Fieldref : // fall through |
40 |
case JVM_CONSTANT_Methodref : // fall through |
|
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
41 |
add_cp_cache_entry(i); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
42 |
break; |
1 | 43 |
} |
44 |
} |
|
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
45 |
|
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
46 |
guarantee((int)_cp_cache_map.length()-1 <= (int)((u2)-1), |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
47 |
"all cp cache indexes fit in a u2"); |
1 | 48 |
} |
49 |
||
50 |
||
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
51 |
int Rewriter::add_extra_cp_cache_entry(int main_entry) { |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
52 |
// Hack: We put it on the map as an encoded value. |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
53 |
// The only place that consumes this is ConstantPoolCacheEntry::set_initial_state |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
54 |
int encoded = constantPoolCacheOopDesc::encode_secondary_index(main_entry); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
55 |
int plain_secondary_index = _cp_cache_map.append(encoded); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
56 |
return constantPoolCacheOopDesc::encode_secondary_index(plain_secondary_index); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
57 |
} |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
58 |
|
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
59 |
|
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
60 |
|
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
61 |
// Creates a constant pool cache given a CPC map |
2006
f2d2f0f20063
6792421: assert(_bitMap->isMarked(addr+size-1),inconsistent Printezis mark)
jmasa
parents:
1
diff
changeset
|
62 |
// This creates the constant pool cache initially in a state |
f2d2f0f20063
6792421: assert(_bitMap->isMarked(addr+size-1),inconsistent Printezis mark)
jmasa
parents:
1
diff
changeset
|
63 |
// that is unsafe for concurrent GC processing but sets it to |
f2d2f0f20063
6792421: assert(_bitMap->isMarked(addr+size-1),inconsistent Printezis mark)
jmasa
parents:
1
diff
changeset
|
64 |
// a safe mode before the constant pool cache is returned. |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
65 |
void Rewriter::make_constant_pool_cache(TRAPS) { |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
66 |
const int length = _cp_cache_map.length(); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
67 |
constantPoolCacheOop cache = |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
68 |
oopFactory::new_constantPoolCache(length, methodOopDesc::IsUnsafeConc, CHECK); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
69 |
cache->initialize(_cp_cache_map); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
70 |
_pool->set_cache(cache); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
71 |
cache->set_constant_pool(_pool()); |
1 | 72 |
} |
73 |
||
74 |
||
75 |
||
76 |
// The new finalization semantics says that registration of |
|
77 |
// finalizable objects must be performed on successful return from the |
|
78 |
// Object.<init> constructor. We could implement this trivially if |
|
79 |
// <init> were never rewritten but since JVMTI allows this to occur, a |
|
80 |
// more complicated solution is required. A special return bytecode |
|
81 |
// is used only by Object.<init> to signal the finalization |
|
82 |
// registration point. Additionally local 0 must be preserved so it's |
|
83 |
// available to pass to the registration function. For simplicty we |
|
84 |
// require that local 0 is never overwritten so it's available as an |
|
85 |
// argument for registration. |
|
86 |
||
87 |
void Rewriter::rewrite_Object_init(methodHandle method, TRAPS) { |
|
88 |
RawBytecodeStream bcs(method); |
|
89 |
while (!bcs.is_last_bytecode()) { |
|
90 |
Bytecodes::Code opcode = bcs.raw_next(); |
|
91 |
switch (opcode) { |
|
92 |
case Bytecodes::_return: *bcs.bcp() = Bytecodes::_return_register_finalizer; break; |
|
93 |
||
94 |
case Bytecodes::_istore: |
|
95 |
case Bytecodes::_lstore: |
|
96 |
case Bytecodes::_fstore: |
|
97 |
case Bytecodes::_dstore: |
|
98 |
case Bytecodes::_astore: |
|
99 |
if (bcs.get_index() != 0) continue; |
|
100 |
||
101 |
// fall through |
|
102 |
case Bytecodes::_istore_0: |
|
103 |
case Bytecodes::_lstore_0: |
|
104 |
case Bytecodes::_fstore_0: |
|
105 |
case Bytecodes::_dstore_0: |
|
106 |
case Bytecodes::_astore_0: |
|
107 |
THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), |
|
108 |
"can't overwrite local 0 in Object.<init>"); |
|
109 |
break; |
|
110 |
} |
|
111 |
} |
|
112 |
} |
|
113 |
||
114 |
||
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
115 |
// Rewrite a classfile-order CP index into a native-order CPC index. |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
116 |
int Rewriter::rewrite_member_reference(address bcp, int offset) { |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
117 |
address p = bcp + offset; |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
118 |
int cp_index = Bytes::get_Java_u2(p); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
119 |
int cache_index = cp_entry_to_cp_cache(cp_index); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
120 |
Bytes::put_native_u2(p, cache_index); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
121 |
return cp_index; |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
122 |
} |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
123 |
|
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
124 |
|
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
125 |
void Rewriter::rewrite_invokedynamic(address bcp, int offset, int delete_me) { |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
126 |
address p = bcp + offset; |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
127 |
assert(p[-1] == Bytecodes::_invokedynamic, ""); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
128 |
int cp_index = Bytes::get_Java_u2(p); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
129 |
int cpc = maybe_add_cp_cache_entry(cp_index); // add lazily |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
130 |
int cpc2 = add_extra_cp_cache_entry(cpc); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
131 |
|
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
132 |
// Replace the trailing four bytes with a CPC index for the dynamic |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
133 |
// call site. Unlike other CPC entries, there is one per bytecode, |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
134 |
// not just one per distinct CP entry. In other words, the |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
135 |
// CPC-to-CP relation is many-to-one for invokedynamic entries. |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
136 |
// This means we must use a larger index size than u2 to address |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
137 |
// all these entries. That is the main reason invokedynamic |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
138 |
// must have a five-byte instruction format. (Of course, other JVM |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
139 |
// implementations can use the bytes for other purposes.) |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
140 |
Bytes::put_native_u4(p, cpc2); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
141 |
// Note: We use native_u4 format exclusively for 4-byte indexes. |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
142 |
} |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
143 |
|
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
144 |
|
1 | 145 |
// Rewrites a method given the index_map information |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
146 |
void Rewriter::scan_method(methodOop method) { |
1 | 147 |
|
148 |
int nof_jsrs = 0; |
|
149 |
bool has_monitor_bytecodes = false; |
|
150 |
||
151 |
{ |
|
152 |
// We cannot tolerate a GC in this block, because we've |
|
153 |
// cached the bytecodes in 'code_base'. If the methodOop |
|
154 |
// moves, the bytecodes will also move. |
|
155 |
No_Safepoint_Verifier nsv; |
|
156 |
Bytecodes::Code c; |
|
157 |
||
158 |
// Bytecodes and their length |
|
159 |
const address code_base = method->code_base(); |
|
160 |
const int code_length = method->code_size(); |
|
161 |
||
162 |
int bc_length; |
|
163 |
for (int bci = 0; bci < code_length; bci += bc_length) { |
|
164 |
address bcp = code_base + bci; |
|
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
165 |
int prefix_length = 0; |
1 | 166 |
c = (Bytecodes::Code)(*bcp); |
167 |
||
168 |
// Since we have the code, see if we can get the length |
|
169 |
// directly. Some more complicated bytecodes will report |
|
170 |
// a length of zero, meaning we need to make another method |
|
171 |
// call to calculate the length. |
|
172 |
bc_length = Bytecodes::length_for(c); |
|
173 |
if (bc_length == 0) { |
|
174 |
bc_length = Bytecodes::length_at(bcp); |
|
175 |
||
176 |
// length_at will put us at the bytecode after the one modified |
|
177 |
// by 'wide'. We don't currently examine any of the bytecodes |
|
178 |
// modified by wide, but in case we do in the future... |
|
179 |
if (c == Bytecodes::_wide) { |
|
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
180 |
prefix_length = 1; |
1 | 181 |
c = (Bytecodes::Code)bcp[1]; |
182 |
} |
|
183 |
} |
|
184 |
||
185 |
assert(bc_length != 0, "impossible bytecode length"); |
|
186 |
||
187 |
switch (c) { |
|
188 |
case Bytecodes::_lookupswitch : { |
|
189 |
#ifndef CC_INTERP |
|
190 |
Bytecode_lookupswitch* bc = Bytecode_lookupswitch_at(bcp); |
|
191 |
bc->set_code( |
|
192 |
bc->number_of_pairs() < BinarySwitchThreshold |
|
193 |
? Bytecodes::_fast_linearswitch |
|
194 |
: Bytecodes::_fast_binaryswitch |
|
195 |
); |
|
196 |
#endif |
|
197 |
break; |
|
198 |
} |
|
199 |
case Bytecodes::_getstatic : // fall through |
|
200 |
case Bytecodes::_putstatic : // fall through |
|
201 |
case Bytecodes::_getfield : // fall through |
|
202 |
case Bytecodes::_putfield : // fall through |
|
203 |
case Bytecodes::_invokevirtual : // fall through |
|
204 |
case Bytecodes::_invokespecial : // fall through |
|
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
205 |
case Bytecodes::_invokestatic : |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
206 |
case Bytecodes::_invokeinterface: |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
207 |
rewrite_member_reference(bcp, prefix_length+1); |
1 | 208 |
break; |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
209 |
case Bytecodes::_invokedynamic: |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
210 |
rewrite_invokedynamic(bcp, prefix_length+1, int(sizeof"@@@@DELETE ME")); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
211 |
break; |
1 | 212 |
case Bytecodes::_jsr : // fall through |
213 |
case Bytecodes::_jsr_w : nof_jsrs++; break; |
|
214 |
case Bytecodes::_monitorenter : // fall through |
|
215 |
case Bytecodes::_monitorexit : has_monitor_bytecodes = true; break; |
|
216 |
} |
|
217 |
} |
|
218 |
} |
|
219 |
||
220 |
// Update access flags |
|
221 |
if (has_monitor_bytecodes) { |
|
222 |
method->set_has_monitor_bytecodes(); |
|
223 |
} |
|
224 |
||
225 |
// The present of a jsr bytecode implies that the method might potentially |
|
226 |
// have to be rewritten, so we run the oopMapGenerator on the method |
|
227 |
if (nof_jsrs > 0) { |
|
228 |
method->set_has_jsrs(); |
|
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
229 |
// Second pass will revisit this method. |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
230 |
assert(method->has_jsrs(), ""); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
231 |
} |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
232 |
} |
1 | 233 |
|
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
234 |
// After constant pool is created, revisit methods containing jsrs. |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
235 |
methodHandle Rewriter::rewrite_jsrs(methodHandle method, TRAPS) { |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
236 |
ResolveOopMapConflicts romc(method); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
237 |
methodHandle original_method = method; |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
238 |
method = romc.do_potential_rewrite(CHECK_(methodHandle())); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
239 |
if (method() != original_method()) { |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
240 |
// Insert invalid bytecode into original methodOop and set |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
241 |
// interpreter entrypoint, so that a executing this method |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
242 |
// will manifest itself in an easy recognizable form. |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
243 |
address bcp = original_method->bcp_from(0); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
244 |
*bcp = (u1)Bytecodes::_shouldnotreachhere; |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
245 |
int kind = Interpreter::method_kind(original_method); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
246 |
original_method->set_interpreter_kind(kind); |
1 | 247 |
} |
248 |
||
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
249 |
// Update monitor matching info. |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
250 |
if (romc.monitor_safe()) { |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
251 |
method->set_guaranteed_monitor_matching(); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
252 |
} |
1 | 253 |
|
254 |
return method; |
|
255 |
} |
|
256 |
||
257 |
||
258 |
void Rewriter::rewrite(instanceKlassHandle klass, TRAPS) { |
|
259 |
ResourceMark rm(THREAD); |
|
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
260 |
Rewriter rw(klass, CHECK); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
261 |
// (That's all, folks.) |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
262 |
} |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
263 |
|
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
264 |
Rewriter::Rewriter(instanceKlassHandle klass, TRAPS) |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
265 |
: _klass(klass), |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
266 |
// gather starting points |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
267 |
_pool( THREAD, klass->constants()), |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
268 |
_methods(THREAD, klass->methods()) |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
269 |
{ |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
270 |
assert(_pool->cache() == NULL, "constant pool cache must not be set yet"); |
1 | 271 |
|
272 |
// determine index maps for methodOop rewriting |
|
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
273 |
compute_index_maps(); |
1 | 274 |
|
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
275 |
if (RegisterFinalizersAtInit && _klass->name() == vmSymbols::java_lang_Object()) { |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
276 |
int i = _methods->length(); |
1 | 277 |
while (i-- > 0) { |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
278 |
methodOop method = (methodOop)_methods->obj_at(i); |
1 | 279 |
if (method->intrinsic_id() == vmIntrinsics::_Object_init) { |
280 |
// rewrite the return bytecodes of Object.<init> to register the |
|
281 |
// object for finalization if needed. |
|
282 |
methodHandle m(THREAD, method); |
|
283 |
rewrite_Object_init(m, CHECK); |
|
284 |
break; |
|
285 |
} |
|
286 |
} |
|
287 |
} |
|
288 |
||
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
289 |
// rewrite methods, in two passes |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
290 |
int i, len = _methods->length(); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
291 |
|
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
292 |
for (i = len; --i >= 0; ) { |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
293 |
methodOop method = (methodOop)_methods->obj_at(i); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
294 |
scan_method(method); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
295 |
} |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
296 |
|
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
297 |
// allocate constant pool cache, now that we've seen all the bytecodes |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
298 |
make_constant_pool_cache(CHECK); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
299 |
|
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
300 |
for (i = len; --i >= 0; ) { |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
301 |
methodHandle m(THREAD, (methodOop)_methods->obj_at(i)); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
302 |
|
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
303 |
if (m->has_jsrs()) { |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
304 |
m = rewrite_jsrs(m, CHECK); |
1 | 305 |
// Method might have gotten rewritten. |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
306 |
_methods->obj_at_put(i, m()); |
1 | 307 |
} |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
308 |
|
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
309 |
// Set up method entry points for compiler and interpreter. |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
310 |
m->link_method(m, CHECK); |
1 | 311 |
} |
312 |
} |