< prev index next >

src/share/vm/oops/method.cpp

Print this page




  93   set_method_data(NULL);
  94   clear_method_counters();
  95   set_vtable_index(Method::garbage_vtable_index);
  96 
  97   // Fix and bury in Method*
  98   set_interpreter_entry(NULL); // sets i2i entry and from_int
  99   set_adapter_entry(NULL);
 100   clear_code(); // from_c/from_i get set to c2i/i2i
 101 
 102   if (access_flags.is_native()) {
 103     clear_native_function();
 104     set_signature_handler(NULL);
 105   }
 106 
 107   NOT_PRODUCT(set_compiled_invocation_count(0);)
 108 }
 109 
 110 // Release Method*.  The nmethod will be gone when we get here because
 111 // we've walked the code cache.
 112 void Method::deallocate_contents(ClassLoaderData* loader_data) {

 113   MetadataFactory::free_metadata(loader_data, constMethod());
 114   set_constMethod(NULL);
 115   MetadataFactory::free_metadata(loader_data, method_data());
 116   set_method_data(NULL);
 117   MetadataFactory::free_metadata(loader_data, method_counters());
 118   clear_method_counters();
 119   // The nmethod will be gone when we get here.
 120   if (code() != NULL) _code = NULL;
 121 }
 122 
 123 address Method::get_i2c_entry() {
 124   assert(_adapter != NULL, "must have");
 125   return _adapter->get_i2c_entry();
 126 }
 127 
 128 address Method::get_c2i_entry() {
 129   assert(_adapter != NULL, "must have");
 130   return _adapter->get_c2i_entry();
 131 }
 132 


1755   }
1756 
1757   bool contains(Method** m) {
1758     for (JNIMethodBlock* b = this; b != NULL; b = b->_next) {
1759       for (int i = 0; i< number_of_methods; i++) {
1760         if (&(b->_methods[i]) == m) {
1761           return true;
1762         }
1763       }
1764     }
1765     return false;  // not found
1766   }
1767 
1768   // Doesn't really destroy it, just marks it as free so it can be reused.
1769   void destroy_method(Method** m) {
1770 #ifdef ASSERT
1771     assert(contains(m), "should be a methodID");
1772 #endif // ASSERT
1773     *m = _free_method;
1774   }










1775 
1776   // During class unloading the methods are cleared, which is different
1777   // than freed.
1778   void clear_all_methods() {
1779     for (JNIMethodBlock* b = this; b != NULL; b = b->_next) {
1780       for (int i = 0; i< number_of_methods; i++) {
1781         b->_methods[i] = NULL;
1782       }
1783     }
1784   }
1785 #ifndef PRODUCT
1786   int count_methods() {
1787     // count all allocated methods
1788     int count = 0;
1789     for (JNIMethodBlock* b = this; b != NULL; b = b->_next) {
1790       for (int i = 0; i< number_of_methods; i++) {
1791         if (b->_methods[i] != _free_method) count++;
1792       }
1793     }
1794     return count;


1827 // InstanceKlass while creating the jmethodID cache.
1828 void Method::destroy_jmethod_id(ClassLoaderData* loader_data, jmethodID m) {
1829   ClassLoaderData* cld = loader_data;
1830   Method** ptr = (Method**)m;
1831   assert(cld->jmethod_ids() != NULL, "should have method handles");
1832   cld->jmethod_ids()->destroy_method(ptr);
1833 }
1834 
1835 void Method::change_method_associated_with_jmethod_id(jmethodID jmid, Method* new_method) {
1836   // Can't assert the method_holder is the same because the new method has the
1837   // scratch method holder.
1838   assert(resolve_jmethod_id(jmid)->method_holder()->class_loader()
1839            == new_method->method_holder()->class_loader(),
1840          "changing to a different class loader");
1841   // Just change the method in place, jmethodID pointer doesn't change.
1842   *((Method**)jmid) = new_method;
1843 }
1844 
1845 bool Method::is_method_id(jmethodID mid) {
1846   Method* m = resolve_jmethod_id(mid);
1847   assert(m != NULL, "should be called with non-null method");


1848   InstanceKlass* ik = m->method_holder();
1849   if (ik == NULL) {
1850     return false;
1851   }
1852   ClassLoaderData* cld = ik->class_loader_data();
1853   if (cld->jmethod_ids() == NULL) return false;
1854   return (cld->jmethod_ids()->contains((Method**)mid));
1855 }
1856 
1857 Method* Method::checked_resolve_jmethod_id(jmethodID mid) {
1858   if (mid == NULL) return NULL;
1859   if (!Method::is_method_id(mid)) {
1860     return NULL;
1861   }
1862   Method* o = resolve_jmethod_id(mid);
1863   if (o == NULL || o == JNIMethodBlock::_free_method || !((Metadata*)o)->is_method()) {
1864     return NULL;
1865   }
1866   return o;
1867 };




1868 
1869 void Method::set_on_stack(const bool value) {
1870   // Set both the method itself and its constant pool.  The constant pool
1871   // on stack means some method referring to it is also on the stack.
1872   constants()->set_on_stack(value);
1873 
1874   bool succeeded = _access_flags.set_on_stack(value);
1875   if (value && succeeded) {
1876     MetadataOnStackMark::record(this, Thread::current());
1877   }
1878 }
1879 
1880 // Called when the class loader is unloaded to make all methods weak.
1881 void Method::clear_jmethod_ids(ClassLoaderData* loader_data) {
1882   loader_data->jmethod_ids()->clear_all_methods();
1883 }
1884 
1885 bool Method::has_method_vptr(const void* ptr) {
1886   Method m;
1887   // This assumes that the vtbl pointer is the first word of a C++ object.




  93   set_method_data(NULL);
  94   clear_method_counters();
  95   set_vtable_index(Method::garbage_vtable_index);
  96 
  97   // Fix and bury in Method*
  98   set_interpreter_entry(NULL); // sets i2i entry and from_int
  99   set_adapter_entry(NULL);
 100   clear_code(); // from_c/from_i get set to c2i/i2i
 101 
 102   if (access_flags.is_native()) {
 103     clear_native_function();
 104     set_signature_handler(NULL);
 105   }
 106 
 107   NOT_PRODUCT(set_compiled_invocation_count(0);)
 108 }
 109 
 110 // Release Method*.  The nmethod will be gone when we get here because
 111 // we've walked the code cache.
 112 void Method::deallocate_contents(ClassLoaderData* loader_data) {
 113   clear_jmethod_id(loader_data);
 114   MetadataFactory::free_metadata(loader_data, constMethod());
 115   set_constMethod(NULL);
 116   MetadataFactory::free_metadata(loader_data, method_data());
 117   set_method_data(NULL);
 118   MetadataFactory::free_metadata(loader_data, method_counters());
 119   clear_method_counters();
 120   // The nmethod will be gone when we get here.
 121   if (code() != NULL) _code = NULL;
 122 }
 123 
 124 address Method::get_i2c_entry() {
 125   assert(_adapter != NULL, "must have");
 126   return _adapter->get_i2c_entry();
 127 }
 128 
 129 address Method::get_c2i_entry() {
 130   assert(_adapter != NULL, "must have");
 131   return _adapter->get_c2i_entry();
 132 }
 133 


1756   }
1757 
1758   bool contains(Method** m) {
1759     for (JNIMethodBlock* b = this; b != NULL; b = b->_next) {
1760       for (int i = 0; i< number_of_methods; i++) {
1761         if (&(b->_methods[i]) == m) {
1762           return true;
1763         }
1764       }
1765     }
1766     return false;  // not found
1767   }
1768 
1769   // Doesn't really destroy it, just marks it as free so it can be reused.
1770   void destroy_method(Method** m) {
1771 #ifdef ASSERT
1772     assert(contains(m), "should be a methodID");
1773 #endif // ASSERT
1774     *m = _free_method;
1775   }
1776   void clear_method(Method* m) {
1777     for (JNIMethodBlock* b = this; b != NULL; b = b->_next) {
1778       for (int i = 0; i< number_of_methods; i++) {
1779         if (b->_methods[i] == m) {
1780           b->_methods[i] = NULL;
1781         }
1782       }
1783     }
1784     // not found
1785   }
1786 
1787   // During class unloading the methods are cleared, which is different
1788   // than freed.
1789   void clear_all_methods() {
1790     for (JNIMethodBlock* b = this; b != NULL; b = b->_next) {
1791       for (int i = 0; i< number_of_methods; i++) {
1792         b->_methods[i] = NULL;
1793       }
1794     }
1795   }
1796 #ifndef PRODUCT
1797   int count_methods() {
1798     // count all allocated methods
1799     int count = 0;
1800     for (JNIMethodBlock* b = this; b != NULL; b = b->_next) {
1801       for (int i = 0; i< number_of_methods; i++) {
1802         if (b->_methods[i] != _free_method) count++;
1803       }
1804     }
1805     return count;


1838 // InstanceKlass while creating the jmethodID cache.
1839 void Method::destroy_jmethod_id(ClassLoaderData* loader_data, jmethodID m) {
1840   ClassLoaderData* cld = loader_data;
1841   Method** ptr = (Method**)m;
1842   assert(cld->jmethod_ids() != NULL, "should have method handles");
1843   cld->jmethod_ids()->destroy_method(ptr);
1844 }
1845 
1846 void Method::change_method_associated_with_jmethod_id(jmethodID jmid, Method* new_method) {
1847   // Can't assert the method_holder is the same because the new method has the
1848   // scratch method holder.
1849   assert(resolve_jmethod_id(jmid)->method_holder()->class_loader()
1850            == new_method->method_holder()->class_loader(),
1851          "changing to a different class loader");
1852   // Just change the method in place, jmethodID pointer doesn't change.
1853   *((Method**)jmid) = new_method;
1854 }
1855 
1856 bool Method::is_method_id(jmethodID mid) {
1857   Method* m = resolve_jmethod_id(mid);
1858   if (m == NULL) {
1859     return false;
1860   }
1861   InstanceKlass* ik = m->method_holder();
1862   if (ik == NULL) {
1863     return false;
1864   }
1865   ClassLoaderData* cld = ik->class_loader_data();
1866   if (cld->jmethod_ids() == NULL) return false;
1867   return (cld->jmethod_ids()->contains((Method**)mid));
1868 }
1869 
1870 Method* Method::checked_resolve_jmethod_id(jmethodID mid) {
1871   if (mid == NULL) return NULL;
1872   if (!Method::is_method_id(mid)) {
1873     return NULL;
1874   }
1875   Method* o = resolve_jmethod_id(mid);
1876   if (o == NULL || o == JNIMethodBlock::_free_method || !((Metadata*)o)->is_method()) {
1877     return NULL;
1878   }
1879   return o;
1880 };
1881 
1882 void Method::clear_jmethod_id(ClassLoaderData* loader_data) {
1883   loader_data->jmethod_ids()->clear_method(this);
1884 }
1885 
1886 void Method::set_on_stack(const bool value) {
1887   // Set both the method itself and its constant pool.  The constant pool
1888   // on stack means some method referring to it is also on the stack.
1889   constants()->set_on_stack(value);
1890 
1891   bool succeeded = _access_flags.set_on_stack(value);
1892   if (value && succeeded) {
1893     MetadataOnStackMark::record(this, Thread::current());
1894   }
1895 }
1896 
1897 // Called when the class loader is unloaded to make all methods weak.
1898 void Method::clear_jmethod_ids(ClassLoaderData* loader_data) {
1899   loader_data->jmethod_ids()->clear_all_methods();
1900 }
1901 
1902 bool Method::has_method_vptr(const void* ptr) {
1903   Method m;
1904   // This assumes that the vtbl pointer is the first word of a C++ object.


< prev index next >