src/share/vm/oops/constantPool.cpp

Print this page




  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/classLoaderData.hpp"
  27 #include "classfile/javaClasses.hpp"
  28 #include "classfile/symbolTable.hpp"
  29 #include "classfile/systemDictionary.hpp"
  30 #include "classfile/vmSymbols.hpp"
  31 #include "interpreter/linkResolver.hpp"

  32 #include "memory/metadataFactory.hpp"
  33 #include "memory/oopFactory.hpp"
  34 #include "oops/constantPool.hpp"
  35 #include "oops/instanceKlass.hpp"
  36 #include "oops/objArrayKlass.hpp"
  37 #include "prims/jvmtiRedefineClasses.hpp"
  38 #include "runtime/fieldType.hpp"
  39 #include "runtime/init.hpp"
  40 #include "runtime/javaCalls.hpp"
  41 #include "runtime/signature.hpp"
  42 #include "runtime/vframe.hpp"
  43 
  44 ConstantPool* ConstantPool::allocate(ClassLoaderData* loader_data, int length, TRAPS) {
  45   // Tags are RW but comment below applies to tags also.
  46   Array<u1>* tags = MetadataFactory::new_writeable_array<u1>(loader_data, length, 0, CHECK_NULL);
  47 
  48   int size = ConstantPool::size(length);
  49 
  50   // CDS considerations:
  51   // Allocate read-write but may be able to move to read-only at dumping time


1937 
1938 void ConstantPool::print_value_on(outputStream* st) const {
1939   assert(is_constantPool(), "must be constantPool");
1940   st->print("constant pool [%d]", length());
1941   if (has_pseudo_string()) st->print("/pseudo_string");
1942   if (has_invokedynamic()) st->print("/invokedynamic");
1943   if (has_preresolution()) st->print("/preresolution");
1944   if (operands() != NULL)  st->print("/operands[%d]", operands()->length());
1945   print_address_on(st);
1946   st->print(" for ");
1947   pool_holder()->print_value_on(st);
1948   if (pool_holder() != NULL) {
1949     bool extra = (pool_holder()->constants() != this);
1950     if (extra)  st->print(" (extra)");
1951   }
1952   if (cache() != NULL) {
1953     st->print(" cache=" PTR_FORMAT, cache());
1954   }
1955 }
1956 














1957 
1958 // Verification
1959 
1960 void ConstantPool::verify_on(outputStream* st) {
1961   guarantee(is_constantPool(), "object must be constant pool");
1962   for (int i = 0; i< length();  i++) {
1963     constantTag tag = tag_at(i);
1964     CPSlot entry = slot_at(i);
1965     if (tag.is_klass()) {
1966       if (entry.is_resolved()) {
1967         guarantee(entry.get_klass()->is_metadata(), "should be metadata");
1968         guarantee(entry.get_klass()->is_klass(),    "should be klass");
1969       }
1970     } else if (tag.is_unresolved_klass()) {
1971       if (entry.is_resolved()) {
1972         guarantee(entry.get_klass()->is_metadata(), "should be metadata");
1973         guarantee(entry.get_klass()->is_klass(),    "should be klass");
1974       }
1975     } else if (tag.is_symbol()) {
1976       guarantee(entry.get_symbol()->refcount() != 0, "should have nonzero reference count");




  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/classLoaderData.hpp"
  27 #include "classfile/javaClasses.hpp"
  28 #include "classfile/symbolTable.hpp"
  29 #include "classfile/systemDictionary.hpp"
  30 #include "classfile/vmSymbols.hpp"
  31 #include "interpreter/linkResolver.hpp"
  32 #include "memory/heapInspection.hpp"
  33 #include "memory/metadataFactory.hpp"
  34 #include "memory/oopFactory.hpp"
  35 #include "oops/constantPool.hpp"
  36 #include "oops/instanceKlass.hpp"
  37 #include "oops/objArrayKlass.hpp"
  38 #include "prims/jvmtiRedefineClasses.hpp"
  39 #include "runtime/fieldType.hpp"
  40 #include "runtime/init.hpp"
  41 #include "runtime/javaCalls.hpp"
  42 #include "runtime/signature.hpp"
  43 #include "runtime/vframe.hpp"
  44 
  45 ConstantPool* ConstantPool::allocate(ClassLoaderData* loader_data, int length, TRAPS) {
  46   // Tags are RW but comment below applies to tags also.
  47   Array<u1>* tags = MetadataFactory::new_writeable_array<u1>(loader_data, length, 0, CHECK_NULL);
  48 
  49   int size = ConstantPool::size(length);
  50 
  51   // CDS considerations:
  52   // Allocate read-write but may be able to move to read-only at dumping time


1938 
1939 void ConstantPool::print_value_on(outputStream* st) const {
1940   assert(is_constantPool(), "must be constantPool");
1941   st->print("constant pool [%d]", length());
1942   if (has_pseudo_string()) st->print("/pseudo_string");
1943   if (has_invokedynamic()) st->print("/invokedynamic");
1944   if (has_preresolution()) st->print("/preresolution");
1945   if (operands() != NULL)  st->print("/operands[%d]", operands()->length());
1946   print_address_on(st);
1947   st->print(" for ");
1948   pool_holder()->print_value_on(st);
1949   if (pool_holder() != NULL) {
1950     bool extra = (pool_holder()->constants() != this);
1951     if (extra)  st->print(" (extra)");
1952   }
1953   if (cache() != NULL) {
1954     st->print(" cache=" PTR_FORMAT, cache());
1955   }
1956 }
1957 
1958 #if INCLUDE_SERVICES
1959 // Size Statistics
1960 void ConstantPool::collect_statistics(KlassSizeStats *sz) const {
1961   sz->_cp_all_bytes += (sz->_cp_bytes          = sz->count(this));
1962   sz->_cp_all_bytes += (sz->_cp_tags_bytes     = sz->count_array(tags()));
1963   sz->_cp_all_bytes += (sz->_cp_cache_bytes    = sz->count(cache()));
1964   sz->_cp_all_bytes += (sz->_cp_operands_bytes = sz->count_array(operands()));
1965   sz->_cp_all_bytes += (sz->_cp_refmap_bytes   = sz->count_array(reference_map()));
1966 
1967   sz->_ro_bytes += sz->_cp_operands_bytes + sz->_cp_tags_bytes +
1968                    sz->_cp_refmap_bytes;
1969   sz->_rw_bytes += sz->_cp_bytes + sz->_cp_cache_bytes;
1970 }
1971 #endif // INCLUDE_SERVICES
1972 
1973 // Verification
1974 
1975 void ConstantPool::verify_on(outputStream* st) {
1976   guarantee(is_constantPool(), "object must be constant pool");
1977   for (int i = 0; i< length();  i++) {
1978     constantTag tag = tag_at(i);
1979     CPSlot entry = slot_at(i);
1980     if (tag.is_klass()) {
1981       if (entry.is_resolved()) {
1982         guarantee(entry.get_klass()->is_metadata(), "should be metadata");
1983         guarantee(entry.get_klass()->is_klass(),    "should be klass");
1984       }
1985     } else if (tag.is_unresolved_klass()) {
1986       if (entry.is_resolved()) {
1987         guarantee(entry.get_klass()->is_metadata(), "should be metadata");
1988         guarantee(entry.get_klass()->is_klass(),    "should be klass");
1989       }
1990     } else if (tag.is_symbol()) {
1991       guarantee(entry.get_symbol()->refcount() != 0, "should have nonzero reference count");