< prev index next >

src/share/vm/prims/jvmtiRedefineClasses.cpp

Print this page




1657       // Need to clear pending exception here as the super caller sets
1658       // the JVMTI_ERROR_INTERNAL if the returned value is false.
1659       CLEAR_PENDING_EXCEPTION;
1660       return false;
1661     }
1662   }
1663 
1664   return true;
1665 }
1666 
1667 
1668 // Rewrite constant pool references in the specific method. This code
1669 // was adapted from Rewriter::rewrite_method().
1670 void VM_RedefineClasses::rewrite_cp_refs_in_method(methodHandle method,
1671        methodHandle *new_method_p, TRAPS) {
1672 
1673   *new_method_p = methodHandle();  // default is no new method
1674 
1675   // We cache a pointer to the bytecodes here in code_base. If GC
1676   // moves the Method*, then the bytecodes will also move which
1677   // will likely cause a crash. We create a No_Safepoint_Verifier
1678   // object to detect whether we pass a possible safepoint in this
1679   // code block.
1680   No_Safepoint_Verifier nsv;
1681 
1682   // Bytecodes and their length
1683   address code_base = method->code_base();
1684   int code_length = method->code_size();
1685 
1686   int bc_length;
1687   for (int bci = 0; bci < code_length; bci += bc_length) {
1688     address bcp = code_base + bci;
1689     Bytecodes::Code c = (Bytecodes::Code)(*bcp);
1690 
1691     bc_length = Bytecodes::length_for(c);
1692     if (bc_length == 0) {
1693       // More complicated bytecodes report a length of zero so
1694       // we have to try again a slightly different way.
1695       bc_length = Bytecodes::length_at(method(), bcp);
1696     }
1697 
1698     assert(bc_length != 0, "impossible bytecode length");
1699 
1700     switch (c) {


1718               p2i(bcp), cp_index, new_index));
1719             *(bcp + 1) = new_index;
1720           } else {
1721             RC_TRACE_WITH_THREAD(0x00080000, THREAD,
1722               ("%s->ldc_w@" INTPTR_FORMAT " old=%d, new=%d",
1723               Bytecodes::name(c), p2i(bcp), cp_index, new_index));
1724             // the new value needs ldc_w instead of ldc
1725             u_char inst_buffer[4]; // max instruction size is 4 bytes
1726             bcp = (address)inst_buffer;
1727             // construct new instruction sequence
1728             *bcp = Bytecodes::_ldc_w;
1729             bcp++;
1730             // Rewriter::rewrite_method() does not rewrite ldc -> ldc_w.
1731             // See comment below for difference between put_Java_u2()
1732             // and put_native_u2().
1733             Bytes::put_Java_u2(bcp, new_index);
1734 
1735             Relocator rc(method, NULL /* no RelocatorListener needed */);
1736             methodHandle m;
1737             {
1738               Pause_No_Safepoint_Verifier pnsv(&nsv);
1739 
1740               // ldc is 2 bytes and ldc_w is 3 bytes
1741               m = rc.insert_space_at(bci, 3, inst_buffer, CHECK);
1742             }
1743 
1744             // return the new method so that the caller can update
1745             // the containing class
1746             *new_method_p = method = m;
1747             // switch our bytecode processing loop from the old method
1748             // to the new method
1749             code_base = method->code_base();
1750             code_length = method->code_size();
1751             bcp = code_base + bci;
1752             c = (Bytecodes::Code)(*bcp);
1753             bc_length = Bytecodes::length_for(c);
1754             assert(bc_length != 0, "sanity check");
1755           } // end we need ldc_w instead of ldc
1756         } // end if there is a mapped index
1757       } break;
1758 




1657       // Need to clear pending exception here as the super caller sets
1658       // the JVMTI_ERROR_INTERNAL if the returned value is false.
1659       CLEAR_PENDING_EXCEPTION;
1660       return false;
1661     }
1662   }
1663 
1664   return true;
1665 }
1666 
1667 
1668 // Rewrite constant pool references in the specific method. This code
1669 // was adapted from Rewriter::rewrite_method().
1670 void VM_RedefineClasses::rewrite_cp_refs_in_method(methodHandle method,
1671        methodHandle *new_method_p, TRAPS) {
1672 
1673   *new_method_p = methodHandle();  // default is no new method
1674 
1675   // We cache a pointer to the bytecodes here in code_base. If GC
1676   // moves the Method*, then the bytecodes will also move which
1677   // will likely cause a crash. We create a NoSafepointVerifier
1678   // object to detect whether we pass a possible safepoint in this
1679   // code block.
1680   NoSafepointVerifier nsv;
1681 
1682   // Bytecodes and their length
1683   address code_base = method->code_base();
1684   int code_length = method->code_size();
1685 
1686   int bc_length;
1687   for (int bci = 0; bci < code_length; bci += bc_length) {
1688     address bcp = code_base + bci;
1689     Bytecodes::Code c = (Bytecodes::Code)(*bcp);
1690 
1691     bc_length = Bytecodes::length_for(c);
1692     if (bc_length == 0) {
1693       // More complicated bytecodes report a length of zero so
1694       // we have to try again a slightly different way.
1695       bc_length = Bytecodes::length_at(method(), bcp);
1696     }
1697 
1698     assert(bc_length != 0, "impossible bytecode length");
1699 
1700     switch (c) {


1718               p2i(bcp), cp_index, new_index));
1719             *(bcp + 1) = new_index;
1720           } else {
1721             RC_TRACE_WITH_THREAD(0x00080000, THREAD,
1722               ("%s->ldc_w@" INTPTR_FORMAT " old=%d, new=%d",
1723               Bytecodes::name(c), p2i(bcp), cp_index, new_index));
1724             // the new value needs ldc_w instead of ldc
1725             u_char inst_buffer[4]; // max instruction size is 4 bytes
1726             bcp = (address)inst_buffer;
1727             // construct new instruction sequence
1728             *bcp = Bytecodes::_ldc_w;
1729             bcp++;
1730             // Rewriter::rewrite_method() does not rewrite ldc -> ldc_w.
1731             // See comment below for difference between put_Java_u2()
1732             // and put_native_u2().
1733             Bytes::put_Java_u2(bcp, new_index);
1734 
1735             Relocator rc(method, NULL /* no RelocatorListener needed */);
1736             methodHandle m;
1737             {
1738               PauseNoSafepointVerifier pnsv(&nsv);
1739 
1740               // ldc is 2 bytes and ldc_w is 3 bytes
1741               m = rc.insert_space_at(bci, 3, inst_buffer, CHECK);
1742             }
1743 
1744             // return the new method so that the caller can update
1745             // the containing class
1746             *new_method_p = method = m;
1747             // switch our bytecode processing loop from the old method
1748             // to the new method
1749             code_base = method->code_base();
1750             code_length = method->code_size();
1751             bcp = code_base + bci;
1752             c = (Bytecodes::Code)(*bcp);
1753             bc_length = Bytecodes::length_for(c);
1754             assert(bc_length != 0, "sanity check");
1755           } // end we need ldc_w instead of ldc
1756         } // end if there is a mapped index
1757       } break;
1758 


< prev index next >