comparison src/share/vm/interpreter/rewriter.cpp @ 7482:989155e2d07a

Merge with hs25-b15.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Wed, 16 Jan 2013 01:34:24 +0100
parents 5d0bb7d52783 cc6a617fffd2
children 5fc51c1ecdeb
comparison
equal deleted inserted replaced
7381:6761a8f854a4 7482:989155e2d07a
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).
402 Rewriter rw(klass, klass->constants(), klass->methods(), CHECK); 397 Rewriter rw(klass, klass->constants(), klass->methods(), CHECK);
403 // (That's all, folks.) 398 // (That's all, folks.)
404 } 399 }
405 400
406 401
407 void Rewriter::rewrite(instanceKlassHandle klass, constantPoolHandle cpool, Array<Method*>* methods, TRAPS) {
408 ResourceMark rm(THREAD);
409 Rewriter rw(klass, cpool, methods, CHECK);
410 // (That's all, folks.)
411 }
412
413
414 Rewriter::Rewriter(instanceKlassHandle klass, constantPoolHandle cpool, Array<Method*>* methods, TRAPS) 402 Rewriter::Rewriter(instanceKlassHandle klass, constantPoolHandle cpool, Array<Method*>* methods, TRAPS)
415 : _klass(klass), 403 : _klass(klass),
416 _pool(cpool), 404 _pool(cpool),
417 _methods(methods) 405 _methods(methods)
418 { 406 {
453 // rewriting bytecodes or allocating the cpCache 441 // rewriting bytecodes or allocating the cpCache
454 if (HAS_PENDING_EXCEPTION) { 442 if (HAS_PENDING_EXCEPTION) {
455 restore_bytecodes(); 443 restore_bytecodes();
456 return; 444 return;
457 } 445 }
458 } 446
459 447 // Relocate after everything, but still do this under the is_rewritten flag,
460 // Relocate jsr/rets in a method. This can't be done with the rewriter 448 // so methods with jsrs in custom class lists in aren't attempted to be
461 // stage because it can throw other exceptions, leaving the bytecodes 449 // rewritten in the RO section of the shared archive.
462 // pointing at constant pool cache entries. 450 // Relocated bytecodes don't have to be restored, only the cp cache entries
463 // Link and check jvmti dependencies while we're iterating over the methods.
464 // JSR292 code calls with a different set of methods, so two entry points.
465 void Rewriter::relocate_and_link(instanceKlassHandle this_oop, TRAPS) {
466 relocate_and_link(this_oop, this_oop->methods(), THREAD);
467 }
468
469 void Rewriter::relocate_and_link(instanceKlassHandle this_oop,
470 Array<Method*>* methods, TRAPS) {
471 int len = methods->length();
472 for (int i = len-1; i >= 0; i--) { 451 for (int i = len-1; i >= 0; i--) {
473 methodHandle m(THREAD, methods->at(i)); 452 methodHandle m(THREAD, _methods->at(i));
474 453
475 if (m->has_jsrs()) { 454 if (m->has_jsrs()) {
476 m = rewrite_jsrs(m, CHECK); 455 m = rewrite_jsrs(m, THREAD);
456 // Restore bytecodes to their unrewritten state if there are exceptions
457 // relocating bytecodes. If some are relocated, that is ok because that
458 // doesn't affect constant pool to cpCache rewriting.
459 if (HAS_PENDING_EXCEPTION) {
460 restore_bytecodes();
461 return;
462 }
477 // Method might have gotten rewritten. 463 // Method might have gotten rewritten.
478 methods->at_put(i, m()); 464 methods->at_put(i, m());
479 } 465 }
480 466 }
481 // Set up method entry points for compiler and interpreter . 467 }
482 m->link_method(m, CHECK);
483
484 // This is for JVMTI and unrelated to relocator but the last thing we do
485 #ifdef ASSERT
486 if (StressMethodComparator) {
487 static int nmc = 0;
488 for (int j = i; j >= 0 && j >= i-4; j--) {
489 if ((++nmc % 1000) == 0) tty->print_cr("Have run MethodComparator %d times...", nmc);
490 bool z = MethodComparator::methods_EMCP(m(),
491 methods->at(j));
492 if (j == i && !z) {
493 tty->print("MethodComparator FAIL: "); m->print(); m->print_codes();
494 assert(z, "method must compare equal to itself");
495 }
496 }
497 }
498 #endif //ASSERT
499 }
500 }