comparison src/share/vm/interpreter/rewriter.cpp @ 14333:26c3b944dc35

8033528: assert(0 <= i && i < length()) failed: index out of bounds Summary: Restoring bytecodes for invokedynamic had wrong index calculation added testing stress option. Reviewed-by: twisti, hseigel
author coleenp
date Fri, 07 Feb 2014 18:30:27 -0500
parents d61a1a166f44
children d8041d695d19
comparison
equal deleted inserted replaced
14332:c2626e4f0c80 14333:26c3b944dc35
1 /* 1 /*
2 * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 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 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
248 int cache_index = ConstantPool::decode_invokedynamic_index( 248 int cache_index = ConstantPool::decode_invokedynamic_index(
249 Bytes::get_native_u4(p)); 249 Bytes::get_native_u4(p));
250 // We will reverse the bytecode rewriting _after_ adjusting them. 250 // We will reverse the bytecode rewriting _after_ adjusting them.
251 // Adjust the cache index by offset to the invokedynamic entries in the 251 // Adjust the cache index by offset to the invokedynamic entries in the
252 // cpCache plus the delta if the invokedynamic bytecodes were adjusted. 252 // cpCache plus the delta if the invokedynamic bytecodes were adjusted.
253 cache_index = cp_cache_delta() + _first_iteration_cp_cache_limit; 253 int adjustment = cp_cache_delta() + _first_iteration_cp_cache_limit;
254 int cp_index = invokedynamic_cp_cache_entry_pool_index(cache_index); 254 int cp_index = invokedynamic_cp_cache_entry_pool_index(cache_index - adjustment);
255 assert(_pool->tag_at(cp_index).is_invoke_dynamic(), "wrong index"); 255 assert(_pool->tag_at(cp_index).is_invoke_dynamic(), "wrong index");
256 // zero out 4 bytes 256 // zero out 4 bytes
257 Bytes::put_Java_u4(p, 0); 257 Bytes::put_Java_u4(p, 0);
258 Bytes::put_Java_u2(p, cp_index); 258 Bytes::put_Java_u2(p, cp_index);
259 } 259 }
451 } 451 }
452 452
453 return method; 453 return method;
454 } 454 }
455 455
456 void Rewriter::rewrite(instanceKlassHandle klass, TRAPS) { 456 void Rewriter::rewrite_bytecodes(TRAPS) {
457 ResourceMark rm(THREAD);
458 Rewriter rw(klass, klass->constants(), klass->methods(), CHECK);
459 // (That's all, folks.)
460 }
461
462
463 Rewriter::Rewriter(instanceKlassHandle klass, constantPoolHandle cpool, Array<Method*>* methods, TRAPS)
464 : _klass(klass),
465 _pool(cpool),
466 _methods(methods)
467 {
468 assert(_pool->cache() == NULL, "constant pool cache must not be set yet"); 457 assert(_pool->cache() == NULL, "constant pool cache must not be set yet");
469 458
470 // determine index maps for Method* rewriting 459 // determine index maps for Method* rewriting
471 compute_index_maps(); 460 compute_index_maps();
472 461
506 } 495 }
507 496
508 // May have to fix invokedynamic bytecodes if invokestatic/InterfaceMethodref 497 // May have to fix invokedynamic bytecodes if invokestatic/InterfaceMethodref
509 // entries had to be added. 498 // entries had to be added.
510 patch_invokedynamic_bytecodes(); 499 patch_invokedynamic_bytecodes();
500 }
501
502 void Rewriter::rewrite(instanceKlassHandle klass, TRAPS) {
503 ResourceMark rm(THREAD);
504 Rewriter rw(klass, klass->constants(), klass->methods(), CHECK);
505 // (That's all, folks.)
506 }
507
508
509 Rewriter::Rewriter(instanceKlassHandle klass, constantPoolHandle cpool, Array<Method*>* methods, TRAPS)
510 : _klass(klass),
511 _pool(cpool),
512 _methods(methods)
513 {
514
515 // Rewrite bytecodes - exception here exits.
516 rewrite_bytecodes(CHECK);
517
518 // Stress restoring bytecodes
519 if (StressRewriter) {
520 restore_bytecodes();
521 rewrite_bytecodes(CHECK);
522 }
511 523
512 // allocate constant pool cache, now that we've seen all the bytecodes 524 // allocate constant pool cache, now that we've seen all the bytecodes
513 make_constant_pool_cache(THREAD); 525 make_constant_pool_cache(THREAD);
514 526
515 // Restore bytecodes to their unrewritten state if there are exceptions 527 // Restore bytecodes to their unrewritten state if there are exceptions
521 533
522 // Relocate after everything, but still do this under the is_rewritten flag, 534 // Relocate after everything, but still do this under the is_rewritten flag,
523 // so methods with jsrs in custom class lists in aren't attempted to be 535 // so methods with jsrs in custom class lists in aren't attempted to be
524 // rewritten in the RO section of the shared archive. 536 // rewritten in the RO section of the shared archive.
525 // Relocated bytecodes don't have to be restored, only the cp cache entries 537 // Relocated bytecodes don't have to be restored, only the cp cache entries
538 int len = _methods->length();
526 for (int i = len-1; i >= 0; i--) { 539 for (int i = len-1; i >= 0; i--) {
527 methodHandle m(THREAD, _methods->at(i)); 540 methodHandle m(THREAD, _methods->at(i));
528 541
529 if (m->has_jsrs()) { 542 if (m->has_jsrs()) {
530 m = rewrite_jsrs(m, THREAD); 543 m = rewrite_jsrs(m, THREAD);