< prev index next >

src/share/vm/oops/method.cpp

Print this page




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


1783   }
1784 
1785   bool contains(Method** m) {
1786     for (JNIMethodBlock* b = this; b != NULL; b = b->_next) {
1787       for (int i = 0; i< number_of_methods; i++) {
1788         if (&(b->_methods[i]) == m) {
1789           return true;
1790         }
1791       }
1792     }
1793     return false;  // not found
1794   }
1795 
1796   // Doesn't really destroy it, just marks it as free so it can be reused.
1797   void destroy_method(Method** m) {
1798 #ifdef ASSERT
1799     assert(contains(m), "should be a methodID");
1800 #endif // ASSERT
1801     *m = _free_method;
1802   }











1803 
1804   // During class unloading the methods are cleared, which is different
1805   // than freed.
1806   void clear_all_methods() {
1807     for (JNIMethodBlock* b = this; b != NULL; b = b->_next) {
1808       for (int i = 0; i< number_of_methods; i++) {
1809         b->_methods[i] = NULL;
1810       }
1811     }
1812   }
1813 #ifndef PRODUCT
1814   int count_methods() {
1815     // count all allocated methods
1816     int count = 0;
1817     for (JNIMethodBlock* b = this; b != NULL; b = b->_next) {
1818       for (int i = 0; i< number_of_methods; i++) {
1819         if (b->_methods[i] != _free_method) count++;
1820       }
1821     }
1822     return count;


1855 // InstanceKlass while creating the jmethodID cache.
1856 void Method::destroy_jmethod_id(ClassLoaderData* loader_data, jmethodID m) {
1857   ClassLoaderData* cld = loader_data;
1858   Method** ptr = (Method**)m;
1859   assert(cld->jmethod_ids() != NULL, "should have method handles");
1860   cld->jmethod_ids()->destroy_method(ptr);
1861 }
1862 
1863 void Method::change_method_associated_with_jmethod_id(jmethodID jmid, Method* new_method) {
1864   // Can't assert the method_holder is the same because the new method has the
1865   // scratch method holder.
1866   assert(resolve_jmethod_id(jmid)->method_holder()->class_loader()
1867            == new_method->method_holder()->class_loader(),
1868          "changing to a different class loader");
1869   // Just change the method in place, jmethodID pointer doesn't change.
1870   *((Method**)jmid) = new_method;
1871 }
1872 
1873 bool Method::is_method_id(jmethodID mid) {
1874   Method* m = resolve_jmethod_id(mid);
1875   assert(m != NULL, "should be called with non-null method");


1876   InstanceKlass* ik = m->method_holder();
1877   if (ik == NULL) {
1878     return false;
1879   }
1880   ClassLoaderData* cld = ik->class_loader_data();
1881   if (cld->jmethod_ids() == NULL) return false;
1882   return (cld->jmethod_ids()->contains((Method**)mid));
1883 }
1884 
1885 Method* Method::checked_resolve_jmethod_id(jmethodID mid) {
1886   if (mid == NULL) return NULL;
1887   if (!Method::is_method_id(mid)) {
1888     return NULL;
1889   }
1890   Method* o = resolve_jmethod_id(mid);
1891   if (o == NULL || o == JNIMethodBlock::_free_method || !((Metadata*)o)->is_method()) {
1892     return NULL;
1893   }
1894   return o;
1895 };




1896 
1897 void Method::set_on_stack(const bool value) {
1898   // Set both the method itself and its constant pool.  The constant pool
1899   // on stack means some method referring to it is also on the stack.
1900   constants()->set_on_stack(value);
1901 
1902   bool succeeded = _access_flags.set_on_stack(value);
1903   if (value && succeeded) {
1904     MetadataOnStackMark::record(this, Thread::current());
1905   }
1906 }
1907 
1908 // Called when the class loader is unloaded to make all methods weak.
1909 void Method::clear_jmethod_ids(ClassLoaderData* loader_data) {
1910   loader_data->jmethod_ids()->clear_all_methods();
1911 }
1912 
1913 bool Method::has_method_vptr(const void* ptr) {
1914   Method m;
1915   // This assumes that the vtbl pointer is the first word of a C++ object.




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


1784   }
1785 
1786   bool contains(Method** m) {
1787     for (JNIMethodBlock* b = this; b != NULL; b = b->_next) {
1788       for (int i = 0; i< number_of_methods; i++) {
1789         if (&(b->_methods[i]) == m) {
1790           return true;
1791         }
1792       }
1793     }
1794     return false;  // not found
1795   }
1796 
1797   // Doesn't really destroy it, just marks it as free so it can be reused.
1798   void destroy_method(Method** m) {
1799 #ifdef ASSERT
1800     assert(contains(m), "should be a methodID");
1801 #endif // ASSERT
1802     *m = _free_method;
1803   }
1804   void clear_method(Method* m) {
1805     for (JNIMethodBlock* b = this; b != NULL; b = b->_next) {
1806       for (int i = 0; i < number_of_methods; i++) {
1807         if (b->_methods[i] == m) {
1808           b->_methods[i] = NULL;
1809           return;
1810         }
1811       }
1812     }
1813     // not found
1814   }
1815 
1816   // During class unloading the methods are cleared, which is different
1817   // than freed.
1818   void clear_all_methods() {
1819     for (JNIMethodBlock* b = this; b != NULL; b = b->_next) {
1820       for (int i = 0; i< number_of_methods; i++) {
1821         b->_methods[i] = NULL;
1822       }
1823     }
1824   }
1825 #ifndef PRODUCT
1826   int count_methods() {
1827     // count all allocated methods
1828     int count = 0;
1829     for (JNIMethodBlock* b = this; b != NULL; b = b->_next) {
1830       for (int i = 0; i< number_of_methods; i++) {
1831         if (b->_methods[i] != _free_method) count++;
1832       }
1833     }
1834     return count;


1867 // InstanceKlass while creating the jmethodID cache.
1868 void Method::destroy_jmethod_id(ClassLoaderData* loader_data, jmethodID m) {
1869   ClassLoaderData* cld = loader_data;
1870   Method** ptr = (Method**)m;
1871   assert(cld->jmethod_ids() != NULL, "should have method handles");
1872   cld->jmethod_ids()->destroy_method(ptr);
1873 }
1874 
1875 void Method::change_method_associated_with_jmethod_id(jmethodID jmid, Method* new_method) {
1876   // Can't assert the method_holder is the same because the new method has the
1877   // scratch method holder.
1878   assert(resolve_jmethod_id(jmid)->method_holder()->class_loader()
1879            == new_method->method_holder()->class_loader(),
1880          "changing to a different class loader");
1881   // Just change the method in place, jmethodID pointer doesn't change.
1882   *((Method**)jmid) = new_method;
1883 }
1884 
1885 bool Method::is_method_id(jmethodID mid) {
1886   Method* m = resolve_jmethod_id(mid);
1887   if (m == NULL) {
1888     return false;
1889   }
1890   InstanceKlass* ik = m->method_holder();
1891   if (ik == NULL) {
1892     return false;
1893   }
1894   ClassLoaderData* cld = ik->class_loader_data();
1895   if (cld->jmethod_ids() == NULL) return false;
1896   return (cld->jmethod_ids()->contains((Method**)mid));
1897 }
1898 
1899 Method* Method::checked_resolve_jmethod_id(jmethodID mid) {
1900   if (mid == NULL) return NULL;
1901   if (!Method::is_method_id(mid)) {
1902     return NULL;
1903   }
1904   Method* o = resolve_jmethod_id(mid);
1905   if (o == NULL || o == JNIMethodBlock::_free_method || !((Metadata*)o)->is_method()) {
1906     return NULL;
1907   }
1908   return o;
1909 };
1910 
1911 void Method::clear_jmethod_id(ClassLoaderData* loader_data) {
1912   loader_data->jmethod_ids()->clear_method(this);
1913 }
1914 
1915 void Method::set_on_stack(const bool value) {
1916   // Set both the method itself and its constant pool.  The constant pool
1917   // on stack means some method referring to it is also on the stack.
1918   constants()->set_on_stack(value);
1919 
1920   bool succeeded = _access_flags.set_on_stack(value);
1921   if (value && succeeded) {
1922     MetadataOnStackMark::record(this, Thread::current());
1923   }
1924 }
1925 
1926 // Called when the class loader is unloaded to make all methods weak.
1927 void Method::clear_jmethod_ids(ClassLoaderData* loader_data) {
1928   loader_data->jmethod_ids()->clear_all_methods();
1929 }
1930 
1931 bool Method::has_method_vptr(const void* ptr) {
1932   Method m;
1933   // This assumes that the vtbl pointer is the first word of a C++ object.


< prev index next >