src/share/vm/interpreter/rewriter.cpp

Tue, 01 Oct 2013 08:10:42 -0400

author
acorn
date
Tue, 01 Oct 2013 08:10:42 -0400
changeset 5786
36b97be47bde
parent 4712
3efdfd6ddbf2
child 6081
41cb10cbfb3c
permissions
-rw-r--r--

8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
Reviewed-by: coleenp, bharadwaj, minqi

duke@435 1 /*
coleenp@4643 2 * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #include "precompiled.hpp"
stefank@2314 26 #include "interpreter/bytecodes.hpp"
stefank@2314 27 #include "interpreter/interpreter.hpp"
stefank@2314 28 #include "interpreter/rewriter.hpp"
stefank@2314 29 #include "memory/gcLocker.hpp"
stefank@2314 30 #include "memory/resourceArea.hpp"
stefank@2314 31 #include "oops/generateOopMap.hpp"
twisti@3969 32 #include "prims/methodHandles.hpp"
duke@435 33
jrose@1161 34 // Computes a CPC map (new_index -> original_index) for constant pool entries
duke@435 35 // that are referred to by the interpreter at runtime via the constant pool cache.
jrose@1161 36 // Also computes a CP map (original_index -> new_index).
jrose@1161 37 // Marks entries in CP which require additional processing.
jrose@1161 38 void Rewriter::compute_index_maps() {
jrose@1161 39 const int length = _pool->length();
coleenp@4037 40 init_maps(length);
twisti@3969 41 bool saw_mh_symbol = false;
duke@435 42 for (int i = 0; i < length; i++) {
jrose@1161 43 int tag = _pool->tag_at(i).value();
jrose@1161 44 switch (tag) {
jrose@1161 45 case JVM_CONSTANT_InterfaceMethodref:
duke@435 46 case JVM_CONSTANT_Fieldref : // fall through
duke@435 47 case JVM_CONSTANT_Methodref : // fall through
coleenp@4037 48 add_cp_cache_entry(i);
coleenp@4037 49 break;
coleenp@4037 50 case JVM_CONSTANT_String:
jrose@1957 51 case JVM_CONSTANT_MethodHandle : // fall through
jrose@1957 52 case JVM_CONSTANT_MethodType : // fall through
coleenp@4037 53 add_resolved_references_entry(i);
jrose@1161 54 break;
twisti@3969 55 case JVM_CONSTANT_Utf8:
twisti@3969 56 if (_pool->symbol_at(i) == vmSymbols::java_lang_invoke_MethodHandle())
twisti@3969 57 saw_mh_symbol = true;
twisti@3969 58 break;
duke@435 59 }
duke@435 60 }
jrose@1161 61
coleenp@4037 62 // Record limits of resolved reference map for constant pool cache indices
coleenp@4037 63 record_map_limits();
coleenp@4037 64
jrose@1161 65 guarantee((int)_cp_cache_map.length()-1 <= (int)((u2)-1),
jrose@1161 66 "all cp cache indexes fit in a u2");
jrose@2015 67
twisti@3969 68 if (saw_mh_symbol)
twisti@3969 69 _method_handle_invokers.initialize(length, (int)0);
duke@435 70 }
duke@435 71
coleenp@2945 72 // Unrewrite the bytecodes if an error occurs.
coleenp@2945 73 void Rewriter::restore_bytecodes() {
coleenp@2945 74 int len = _methods->length();
coleenp@2945 75
coleenp@2945 76 for (int i = len-1; i >= 0; i--) {
coleenp@4037 77 Method* method = _methods->at(i);
coleenp@2945 78 scan_method(method, true);
coleenp@2945 79 }
coleenp@2945 80 }
duke@435 81
jrose@1161 82 // Creates a constant pool cache given a CPC map
jrose@1161 83 void Rewriter::make_constant_pool_cache(TRAPS) {
jrose@1161 84 const int length = _cp_cache_map.length();
coleenp@4037 85 ClassLoaderData* loader_data = _pool->pool_holder()->class_loader_data();
coleenp@4037 86 ConstantPoolCache* cache =
coleenp@4712 87 ConstantPoolCache::allocate(loader_data, length, _cp_cache_map,
coleenp@4712 88 _invokedynamic_references_map, CHECK);
coleenp@4037 89
coleenp@4037 90 // initialize object cache in constant pool
coleenp@4037 91 _pool->initialize_resolved_references(loader_data, _resolved_references_map,
coleenp@4037 92 _resolved_reference_limit,
coleenp@4037 93 CHECK);
jrose@1161 94 _pool->set_cache(cache);
jrose@1161 95 cache->set_constant_pool(_pool());
duke@435 96 }
duke@435 97
duke@435 98
duke@435 99
duke@435 100 // The new finalization semantics says that registration of
duke@435 101 // finalizable objects must be performed on successful return from the
duke@435 102 // Object.<init> constructor. We could implement this trivially if
duke@435 103 // <init> were never rewritten but since JVMTI allows this to occur, a
duke@435 104 // more complicated solution is required. A special return bytecode
duke@435 105 // is used only by Object.<init> to signal the finalization
duke@435 106 // registration point. Additionally local 0 must be preserved so it's
duke@435 107 // available to pass to the registration function. For simplicty we
duke@435 108 // require that local 0 is never overwritten so it's available as an
duke@435 109 // argument for registration.
duke@435 110
duke@435 111 void Rewriter::rewrite_Object_init(methodHandle method, TRAPS) {
duke@435 112 RawBytecodeStream bcs(method);
duke@435 113 while (!bcs.is_last_bytecode()) {
duke@435 114 Bytecodes::Code opcode = bcs.raw_next();
duke@435 115 switch (opcode) {
duke@435 116 case Bytecodes::_return: *bcs.bcp() = Bytecodes::_return_register_finalizer; break;
duke@435 117
duke@435 118 case Bytecodes::_istore:
duke@435 119 case Bytecodes::_lstore:
duke@435 120 case Bytecodes::_fstore:
duke@435 121 case Bytecodes::_dstore:
duke@435 122 case Bytecodes::_astore:
duke@435 123 if (bcs.get_index() != 0) continue;
duke@435 124
duke@435 125 // fall through
duke@435 126 case Bytecodes::_istore_0:
duke@435 127 case Bytecodes::_lstore_0:
duke@435 128 case Bytecodes::_fstore_0:
duke@435 129 case Bytecodes::_dstore_0:
duke@435 130 case Bytecodes::_astore_0:
duke@435 131 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(),
duke@435 132 "can't overwrite local 0 in Object.<init>");
duke@435 133 break;
duke@435 134 }
duke@435 135 }
duke@435 136 }
duke@435 137
duke@435 138
jrose@1161 139 // Rewrite a classfile-order CP index into a native-order CPC index.
coleenp@2945 140 void Rewriter::rewrite_member_reference(address bcp, int offset, bool reverse) {
jrose@1161 141 address p = bcp + offset;
coleenp@2945 142 if (!reverse) {
coleenp@2945 143 int cp_index = Bytes::get_Java_u2(p);
coleenp@2945 144 int cache_index = cp_entry_to_cp_cache(cp_index);
coleenp@2945 145 Bytes::put_native_u2(p, cache_index);
twisti@3969 146 if (!_method_handle_invokers.is_empty())
coleenp@4037 147 maybe_rewrite_invokehandle(p - 1, cp_index, cache_index, reverse);
coleenp@2945 148 } else {
coleenp@2945 149 int cache_index = Bytes::get_native_u2(p);
coleenp@2945 150 int pool_index = cp_cache_entry_pool_index(cache_index);
coleenp@2945 151 Bytes::put_Java_u2(p, pool_index);
twisti@3969 152 if (!_method_handle_invokers.is_empty())
coleenp@4037 153 maybe_rewrite_invokehandle(p - 1, pool_index, cache_index, reverse);
twisti@3969 154 }
twisti@3969 155 }
twisti@3969 156
twisti@3969 157
twisti@3969 158 // Adjust the invocation bytecode for a signature-polymorphic method (MethodHandle.invoke, etc.)
coleenp@4037 159 void Rewriter::maybe_rewrite_invokehandle(address opc, int cp_index, int cache_index, bool reverse) {
twisti@3969 160 if (!reverse) {
twisti@3969 161 if ((*opc) == (u1)Bytecodes::_invokevirtual ||
twisti@3969 162 // allow invokespecial as an alias, although it would be very odd:
twisti@3969 163 (*opc) == (u1)Bytecodes::_invokespecial) {
twisti@3969 164 assert(_pool->tag_at(cp_index).is_method(), "wrong index");
twisti@3969 165 // Determine whether this is a signature-polymorphic method.
twisti@3969 166 if (cp_index >= _method_handle_invokers.length()) return;
twisti@3969 167 int status = _method_handle_invokers[cp_index];
twisti@3969 168 assert(status >= -1 && status <= 1, "oob tri-state");
twisti@3969 169 if (status == 0) {
twisti@3969 170 if (_pool->klass_ref_at_noresolve(cp_index) == vmSymbols::java_lang_invoke_MethodHandle() &&
twisti@3969 171 MethodHandles::is_signature_polymorphic_name(SystemDictionary::MethodHandle_klass(),
coleenp@4037 172 _pool->name_ref_at(cp_index))) {
coleenp@4037 173 // we may need a resolved_refs entry for the appendix
twisti@4133 174 add_invokedynamic_resolved_references_entries(cp_index, cache_index);
twisti@3969 175 status = +1;
coleenp@4037 176 } else {
twisti@3969 177 status = -1;
coleenp@4037 178 }
twisti@3969 179 _method_handle_invokers[cp_index] = status;
twisti@3969 180 }
twisti@3969 181 // We use a special internal bytecode for such methods (if non-static).
twisti@3969 182 // The basic reason for this is that such methods need an extra "appendix" argument
twisti@3969 183 // to transmit the call site's intended call type.
twisti@3969 184 if (status > 0) {
twisti@3969 185 (*opc) = (u1)Bytecodes::_invokehandle;
twisti@3969 186 }
twisti@3969 187 }
twisti@3969 188 } else {
twisti@3969 189 // Do not need to look at cp_index.
twisti@3969 190 if ((*opc) == (u1)Bytecodes::_invokehandle) {
twisti@3969 191 (*opc) = (u1)Bytecodes::_invokevirtual;
twisti@3969 192 // Ignore corner case of original _invokespecial instruction.
twisti@3969 193 // This is safe because (a) the signature polymorphic method was final, and
twisti@3969 194 // (b) the implementation of MethodHandle will not call invokespecial on it.
twisti@3969 195 }
coleenp@2945 196 }
jrose@1161 197 }
jrose@1161 198
jrose@1161 199
coleenp@2945 200 void Rewriter::rewrite_invokedynamic(address bcp, int offset, bool reverse) {
jrose@1161 201 address p = bcp + offset;
coleenp@2945 202 assert(p[-1] == Bytecodes::_invokedynamic, "not invokedynamic bytecode");
coleenp@2945 203 if (!reverse) {
coleenp@2945 204 int cp_index = Bytes::get_Java_u2(p);
coleenp@4037 205 int cache_index = add_invokedynamic_cp_cache_entry(cp_index);
twisti@4133 206 add_invokedynamic_resolved_references_entries(cp_index, cache_index);
coleenp@2945 207 // Replace the trailing four bytes with a CPC index for the dynamic
coleenp@2945 208 // call site. Unlike other CPC entries, there is one per bytecode,
coleenp@2945 209 // not just one per distinct CP entry. In other words, the
coleenp@2945 210 // CPC-to-CP relation is many-to-one for invokedynamic entries.
coleenp@2945 211 // This means we must use a larger index size than u2 to address
coleenp@2945 212 // all these entries. That is the main reason invokedynamic
coleenp@2945 213 // must have a five-byte instruction format. (Of course, other JVM
coleenp@2945 214 // implementations can use the bytes for other purposes.)
coleenp@4037 215 Bytes::put_native_u4(p, ConstantPool::encode_invokedynamic_index(cache_index));
coleenp@2945 216 // Note: We use native_u4 format exclusively for 4-byte indexes.
coleenp@2945 217 } else {
coleenp@4037 218 // callsite index
coleenp@4037 219 int cache_index = ConstantPool::decode_invokedynamic_index(
coleenp@2945 220 Bytes::get_native_u4(p));
coleenp@4037 221 int cp_index = cp_cache_entry_pool_index(cache_index);
coleenp@4037 222 assert(_pool->tag_at(cp_index).is_invoke_dynamic(), "wrong index");
coleenp@2945 223 // zero out 4 bytes
coleenp@2945 224 Bytes::put_Java_u4(p, 0);
coleenp@4037 225 Bytes::put_Java_u2(p, cp_index);
coleenp@2945 226 }
jrose@1161 227 }
jrose@1161 228
jrose@1161 229
jrose@1957 230 // Rewrite some ldc bytecodes to _fast_aldc
coleenp@2945 231 void Rewriter::maybe_rewrite_ldc(address bcp, int offset, bool is_wide,
coleenp@2945 232 bool reverse) {
coleenp@2945 233 if (!reverse) {
coleenp@2945 234 assert((*bcp) == (is_wide ? Bytecodes::_ldc_w : Bytecodes::_ldc), "not ldc bytecode");
coleenp@2945 235 address p = bcp + offset;
coleenp@2945 236 int cp_index = is_wide ? Bytes::get_Java_u2(p) : (u1)(*p);
coleenp@2945 237 constantTag tag = _pool->tag_at(cp_index).value();
coleenp@4643 238 if (tag.is_method_handle() || tag.is_method_type() || tag.is_string()) {
coleenp@4037 239 int ref_index = cp_entry_to_resolved_references(cp_index);
coleenp@2945 240 if (is_wide) {
coleenp@2945 241 (*bcp) = Bytecodes::_fast_aldc_w;
coleenp@4037 242 assert(ref_index == (u2)ref_index, "index overflow");
coleenp@4037 243 Bytes::put_native_u2(p, ref_index);
coleenp@2945 244 } else {
coleenp@2945 245 (*bcp) = Bytecodes::_fast_aldc;
coleenp@4037 246 assert(ref_index == (u1)ref_index, "index overflow");
coleenp@4037 247 (*p) = (u1)ref_index;
coleenp@2945 248 }
coleenp@2945 249 }
coleenp@2945 250 } else {
coleenp@2945 251 Bytecodes::Code rewritten_bc =
coleenp@2945 252 (is_wide ? Bytecodes::_fast_aldc_w : Bytecodes::_fast_aldc);
coleenp@2945 253 if ((*bcp) == rewritten_bc) {
coleenp@2945 254 address p = bcp + offset;
coleenp@4037 255 int ref_index = is_wide ? Bytes::get_native_u2(p) : (u1)(*p);
coleenp@4037 256 int pool_index = resolved_references_entry_to_pool_index(ref_index);
coleenp@2945 257 if (is_wide) {
coleenp@2945 258 (*bcp) = Bytecodes::_ldc_w;
coleenp@2945 259 assert(pool_index == (u2)pool_index, "index overflow");
coleenp@2945 260 Bytes::put_Java_u2(p, pool_index);
coleenp@2945 261 } else {
coleenp@2945 262 (*bcp) = Bytecodes::_ldc;
coleenp@2945 263 assert(pool_index == (u1)pool_index, "index overflow");
coleenp@2945 264 (*p) = (u1)pool_index;
coleenp@2945 265 }
jrose@1957 266 }
jrose@1957 267 }
jrose@1957 268 }
jrose@1957 269
jrose@1957 270
duke@435 271 // Rewrites a method given the index_map information
coleenp@4037 272 void Rewriter::scan_method(Method* method, bool reverse) {
duke@435 273
duke@435 274 int nof_jsrs = 0;
duke@435 275 bool has_monitor_bytecodes = false;
duke@435 276
duke@435 277 {
duke@435 278 // We cannot tolerate a GC in this block, because we've
coleenp@4037 279 // cached the bytecodes in 'code_base'. If the Method*
duke@435 280 // moves, the bytecodes will also move.
duke@435 281 No_Safepoint_Verifier nsv;
duke@435 282 Bytecodes::Code c;
duke@435 283
duke@435 284 // Bytecodes and their length
duke@435 285 const address code_base = method->code_base();
duke@435 286 const int code_length = method->code_size();
duke@435 287
duke@435 288 int bc_length;
duke@435 289 for (int bci = 0; bci < code_length; bci += bc_length) {
duke@435 290 address bcp = code_base + bci;
jrose@1161 291 int prefix_length = 0;
duke@435 292 c = (Bytecodes::Code)(*bcp);
duke@435 293
duke@435 294 // Since we have the code, see if we can get the length
duke@435 295 // directly. Some more complicated bytecodes will report
duke@435 296 // a length of zero, meaning we need to make another method
duke@435 297 // call to calculate the length.
duke@435 298 bc_length = Bytecodes::length_for(c);
duke@435 299 if (bc_length == 0) {
never@2462 300 bc_length = Bytecodes::length_at(method, bcp);
duke@435 301
duke@435 302 // length_at will put us at the bytecode after the one modified
duke@435 303 // by 'wide'. We don't currently examine any of the bytecodes
duke@435 304 // modified by wide, but in case we do in the future...
duke@435 305 if (c == Bytecodes::_wide) {
jrose@1161 306 prefix_length = 1;
duke@435 307 c = (Bytecodes::Code)bcp[1];
duke@435 308 }
duke@435 309 }
duke@435 310
duke@435 311 assert(bc_length != 0, "impossible bytecode length");
duke@435 312
duke@435 313 switch (c) {
duke@435 314 case Bytecodes::_lookupswitch : {
duke@435 315 #ifndef CC_INTERP
never@2462 316 Bytecode_lookupswitch bc(method, bcp);
jrose@1920 317 (*bcp) = (
never@2462 318 bc.number_of_pairs() < BinarySwitchThreshold
duke@435 319 ? Bytecodes::_fast_linearswitch
duke@435 320 : Bytecodes::_fast_binaryswitch
duke@435 321 );
duke@435 322 #endif
duke@435 323 break;
duke@435 324 }
coleenp@2945 325 case Bytecodes::_fast_linearswitch:
coleenp@2945 326 case Bytecodes::_fast_binaryswitch: {
coleenp@2945 327 #ifndef CC_INTERP
coleenp@2945 328 (*bcp) = Bytecodes::_lookupswitch;
coleenp@2945 329 #endif
coleenp@2945 330 break;
coleenp@2945 331 }
duke@435 332 case Bytecodes::_getstatic : // fall through
duke@435 333 case Bytecodes::_putstatic : // fall through
duke@435 334 case Bytecodes::_getfield : // fall through
duke@435 335 case Bytecodes::_putfield : // fall through
duke@435 336 case Bytecodes::_invokevirtual : // fall through
duke@435 337 case Bytecodes::_invokespecial : // fall through
jrose@1161 338 case Bytecodes::_invokestatic :
jrose@1161 339 case Bytecodes::_invokeinterface:
twisti@3969 340 case Bytecodes::_invokehandle : // if reverse=true
coleenp@2945 341 rewrite_member_reference(bcp, prefix_length+1, reverse);
duke@435 342 break;
jrose@1161 343 case Bytecodes::_invokedynamic:
coleenp@2945 344 rewrite_invokedynamic(bcp, prefix_length+1, reverse);
jrose@1161 345 break;
jrose@1957 346 case Bytecodes::_ldc:
twisti@3969 347 case Bytecodes::_fast_aldc: // if reverse=true
coleenp@2945 348 maybe_rewrite_ldc(bcp, prefix_length+1, false, reverse);
jrose@1957 349 break;
jrose@1957 350 case Bytecodes::_ldc_w:
twisti@3969 351 case Bytecodes::_fast_aldc_w: // if reverse=true
coleenp@2945 352 maybe_rewrite_ldc(bcp, prefix_length+1, true, reverse);
jrose@1957 353 break;
duke@435 354 case Bytecodes::_jsr : // fall through
duke@435 355 case Bytecodes::_jsr_w : nof_jsrs++; break;
duke@435 356 case Bytecodes::_monitorenter : // fall through
duke@435 357 case Bytecodes::_monitorexit : has_monitor_bytecodes = true; break;
duke@435 358 }
duke@435 359 }
duke@435 360 }
duke@435 361
duke@435 362 // Update access flags
duke@435 363 if (has_monitor_bytecodes) {
duke@435 364 method->set_has_monitor_bytecodes();
duke@435 365 }
duke@435 366
duke@435 367 // The present of a jsr bytecode implies that the method might potentially
duke@435 368 // have to be rewritten, so we run the oopMapGenerator on the method
duke@435 369 if (nof_jsrs > 0) {
duke@435 370 method->set_has_jsrs();
jrose@1161 371 // Second pass will revisit this method.
coleenp@2945 372 assert(method->has_jsrs(), "didn't we just set this?");
jrose@1161 373 }
jrose@1161 374 }
duke@435 375
jrose@1161 376 // After constant pool is created, revisit methods containing jsrs.
jrose@1161 377 methodHandle Rewriter::rewrite_jsrs(methodHandle method, TRAPS) {
coleenp@2945 378 ResourceMark rm(THREAD);
jrose@1161 379 ResolveOopMapConflicts romc(method);
jrose@1161 380 methodHandle original_method = method;
jrose@1161 381 method = romc.do_potential_rewrite(CHECK_(methodHandle()));
jrose@1161 382 // Update monitor matching info.
jrose@1161 383 if (romc.monitor_safe()) {
jrose@1161 384 method->set_guaranteed_monitor_matching();
jrose@1161 385 }
duke@435 386
duke@435 387 return method;
duke@435 388 }
duke@435 389
duke@435 390 void Rewriter::rewrite(instanceKlassHandle klass, TRAPS) {
duke@435 391 ResourceMark rm(THREAD);
twisti@1573 392 Rewriter rw(klass, klass->constants(), klass->methods(), CHECK);
jrose@1161 393 // (That's all, folks.)
jrose@1161 394 }
jrose@1161 395
twisti@1573 396
coleenp@4037 397 Rewriter::Rewriter(instanceKlassHandle klass, constantPoolHandle cpool, Array<Method*>* methods, TRAPS)
jrose@1161 398 : _klass(klass),
twisti@1573 399 _pool(cpool),
twisti@1573 400 _methods(methods)
jrose@1161 401 {
jrose@1161 402 assert(_pool->cache() == NULL, "constant pool cache must not be set yet");
duke@435 403
coleenp@4037 404 // determine index maps for Method* rewriting
jrose@1161 405 compute_index_maps();
duke@435 406
jrose@1161 407 if (RegisterFinalizersAtInit && _klass->name() == vmSymbols::java_lang_Object()) {
jrose@1291 408 bool did_rewrite = false;
jrose@1161 409 int i = _methods->length();
duke@435 410 while (i-- > 0) {
coleenp@4037 411 Method* method = _methods->at(i);
duke@435 412 if (method->intrinsic_id() == vmIntrinsics::_Object_init) {
duke@435 413 // rewrite the return bytecodes of Object.<init> to register the
duke@435 414 // object for finalization if needed.
duke@435 415 methodHandle m(THREAD, method);
duke@435 416 rewrite_Object_init(m, CHECK);
jrose@1291 417 did_rewrite = true;
duke@435 418 break;
duke@435 419 }
duke@435 420 }
jrose@1291 421 assert(did_rewrite, "must find Object::<init> to rewrite it");
duke@435 422 }
duke@435 423
jrose@1161 424 // rewrite methods, in two passes
coleenp@2945 425 int len = _methods->length();
jrose@1161 426
coleenp@2945 427 for (int i = len-1; i >= 0; i--) {
coleenp@4037 428 Method* method = _methods->at(i);
jrose@1161 429 scan_method(method);
jrose@1161 430 }
jrose@1161 431
jrose@1161 432 // allocate constant pool cache, now that we've seen all the bytecodes
coleenp@2945 433 make_constant_pool_cache(THREAD);
jrose@1161 434
coleenp@2945 435 // Restore bytecodes to their unrewritten state if there are exceptions
coleenp@2945 436 // rewriting bytecodes or allocating the cpCache
coleenp@2945 437 if (HAS_PENDING_EXCEPTION) {
coleenp@2945 438 restore_bytecodes();
coleenp@2945 439 return;
coleenp@2945 440 }
coleenp@2945 441
coleenp@4395 442 // Relocate after everything, but still do this under the is_rewritten flag,
coleenp@4395 443 // so methods with jsrs in custom class lists in aren't attempted to be
coleenp@4395 444 // rewritten in the RO section of the shared archive.
coleenp@4395 445 // Relocated bytecodes don't have to be restored, only the cp cache entries
coleenp@2945 446 for (int i = len-1; i >= 0; i--) {
coleenp@4395 447 methodHandle m(THREAD, _methods->at(i));
jrose@1161 448
jrose@1161 449 if (m->has_jsrs()) {
coleenp@4395 450 m = rewrite_jsrs(m, THREAD);
coleenp@4395 451 // Restore bytecodes to their unrewritten state if there are exceptions
coleenp@4395 452 // relocating bytecodes. If some are relocated, that is ok because that
coleenp@4395 453 // doesn't affect constant pool to cpCache rewriting.
coleenp@4395 454 if (HAS_PENDING_EXCEPTION) {
coleenp@4395 455 restore_bytecodes();
coleenp@4395 456 return;
coleenp@4395 457 }
duke@435 458 // Method might have gotten rewritten.
coleenp@4037 459 methods->at_put(i, m());
duke@435 460 }
duke@435 461 }
duke@435 462 }

mercurial