comparison src/share/vm/interpreter/rewriter.cpp @ 7459:cc6a617fffd2

8005494: SIGSEGV in Rewriter::relocate_and_link() when testing Weblogic with CompressedOops and KlassPtrs Summary: Relocate functions with jsr's when rewriting so not repeated after reading shared archive Reviewed-by: twisti, jrose
author coleenp
date Wed, 02 Jan 2013 20:28:09 -0500
parents f6b0eb4e44cf
children 989155e2d07a f16e75e0cf11
comparison
equal deleted inserted replaced
7458:4daebd4cc1dd 7459:cc6a617fffd2
25 #include "precompiled.hpp" 25 #include "precompiled.hpp"
26 #include "interpreter/bytecodes.hpp" 26 #include "interpreter/bytecodes.hpp"
27 #include "interpreter/interpreter.hpp" 27 #include "interpreter/interpreter.hpp"
28 #include "interpreter/rewriter.hpp" 28 #include "interpreter/rewriter.hpp"
29 #include "memory/gcLocker.hpp" 29 #include "memory/gcLocker.hpp"
30 #include "memory/metadataFactory.hpp"
31 #include "memory/oopFactory.hpp"
32 #include "memory/resourceArea.hpp" 30 #include "memory/resourceArea.hpp"
33 #include "oops/generateOopMap.hpp" 31 #include "oops/generateOopMap.hpp"
34 #include "oops/objArrayOop.hpp"
35 #include "oops/oop.inline.hpp"
36 #include "prims/methodComparator.hpp"
37 #include "prims/methodHandles.hpp" 32 #include "prims/methodHandles.hpp"
38 33
39 // Computes a CPC map (new_index -> original_index) for constant pool entries 34 // Computes a CPC map (new_index -> original_index) for constant pool entries
40 // that are referred to by the interpreter at runtime via the constant pool cache. 35 // that are referred to by the interpreter at runtime via the constant pool cache.
41 // Also computes a CP map (original_index -> new_index). 36 // Also computes a CP map (original_index -> new_index).
400 Rewriter rw(klass, klass->constants(), klass->methods(), CHECK); 395 Rewriter rw(klass, klass->constants(), klass->methods(), CHECK);
401 // (That's all, folks.) 396 // (That's all, folks.)
402 } 397 }
403 398
404 399
405 void Rewriter::rewrite(instanceKlassHandle klass, constantPoolHandle cpool, Array<Method*>* methods, TRAPS) {
406 ResourceMark rm(THREAD);
407 Rewriter rw(klass, cpool, methods, CHECK);
408 // (That's all, folks.)
409 }
410
411
412 Rewriter::Rewriter(instanceKlassHandle klass, constantPoolHandle cpool, Array<Method*>* methods, TRAPS) 400 Rewriter::Rewriter(instanceKlassHandle klass, constantPoolHandle cpool, Array<Method*>* methods, TRAPS)
413 : _klass(klass), 401 : _klass(klass),
414 _pool(cpool), 402 _pool(cpool),
415 _methods(methods) 403 _methods(methods)
416 { 404 {
451 // rewriting bytecodes or allocating the cpCache 439 // rewriting bytecodes or allocating the cpCache
452 if (HAS_PENDING_EXCEPTION) { 440 if (HAS_PENDING_EXCEPTION) {
453 restore_bytecodes(); 441 restore_bytecodes();
454 return; 442 return;
455 } 443 }
456 } 444
457 445 // Relocate after everything, but still do this under the is_rewritten flag,
458 // Relocate jsr/rets in a method. This can't be done with the rewriter 446 // so methods with jsrs in custom class lists in aren't attempted to be
459 // stage because it can throw other exceptions, leaving the bytecodes 447 // rewritten in the RO section of the shared archive.
460 // pointing at constant pool cache entries. 448 // Relocated bytecodes don't have to be restored, only the cp cache entries
461 // Link and check jvmti dependencies while we're iterating over the methods.
462 // JSR292 code calls with a different set of methods, so two entry points.
463 void Rewriter::relocate_and_link(instanceKlassHandle this_oop, TRAPS) {
464 relocate_and_link(this_oop, this_oop->methods(), THREAD);
465 }
466
467 void Rewriter::relocate_and_link(instanceKlassHandle this_oop,
468 Array<Method*>* methods, TRAPS) {
469 int len = methods->length();
470 for (int i = len-1; i >= 0; i--) { 449 for (int i = len-1; i >= 0; i--) {
471 methodHandle m(THREAD, methods->at(i)); 450 methodHandle m(THREAD, _methods->at(i));
472 451
473 if (m->has_jsrs()) { 452 if (m->has_jsrs()) {
474 m = rewrite_jsrs(m, CHECK); 453 m = rewrite_jsrs(m, THREAD);
454 // Restore bytecodes to their unrewritten state if there are exceptions
455 // relocating bytecodes. If some are relocated, that is ok because that
456 // doesn't affect constant pool to cpCache rewriting.
457 if (HAS_PENDING_EXCEPTION) {
458 restore_bytecodes();
459 return;
460 }
475 // Method might have gotten rewritten. 461 // Method might have gotten rewritten.
476 methods->at_put(i, m()); 462 methods->at_put(i, m());
477 } 463 }
478 464 }
479 // Set up method entry points for compiler and interpreter . 465 }
480 m->link_method(m, CHECK);
481
482 // This is for JVMTI and unrelated to relocator but the last thing we do
483 #ifdef ASSERT
484 if (StressMethodComparator) {
485 static int nmc = 0;
486 for (int j = i; j >= 0 && j >= i-4; j--) {
487 if ((++nmc % 1000) == 0) tty->print_cr("Have run MethodComparator %d times...", nmc);
488 bool z = MethodComparator::methods_EMCP(m(),
489 methods->at(j));
490 if (j == i && !z) {
491 tty->print("MethodComparator FAIL: "); m->print(); m->print_codes();
492 assert(z, "method must compare equal to itself");
493 }
494 }
495 }
496 #endif //ASSERT
497 }
498 }