comparison src/share/vm/oops/instanceKlass.cpp @ 2491:0654ee04b214

Merge with OpenJDK.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Fri, 22 Apr 2011 15:30:53 +0200
parents 2ab52cda08e5 2cd0180da6e1
children be4ca325525a
comparison
equal deleted inserted replaced
2490:29246b1d2d3c 2491:0654ee04b214
35 #include "jvmtifiles/jvmti.h" 35 #include "jvmtifiles/jvmti.h"
36 #include "memory/genOopClosures.inline.hpp" 36 #include "memory/genOopClosures.inline.hpp"
37 #include "memory/oopFactory.hpp" 37 #include "memory/oopFactory.hpp"
38 #include "memory/permGen.hpp" 38 #include "memory/permGen.hpp"
39 #include "oops/instanceKlass.hpp" 39 #include "oops/instanceKlass.hpp"
40 #include "oops/instanceMirrorKlass.hpp"
40 #include "oops/instanceOop.hpp" 41 #include "oops/instanceOop.hpp"
41 #include "oops/methodOop.hpp" 42 #include "oops/methodOop.hpp"
42 #include "oops/objArrayKlassKlass.hpp" 43 #include "oops/objArrayKlassKlass.hpp"
43 #include "oops/oop.inline.hpp" 44 #include "oops/oop.inline.hpp"
44 #include "oops/symbol.hpp" 45 #include "oops/symbol.hpp"
647 JavaCalls::call(&result, mh, &args, CHECK_NULL); 648 JavaCalls::call(&result, mh, &args, CHECK_NULL);
648 return h_i(); 649 return h_i();
649 } 650 }
650 651
651 instanceOop instanceKlass::allocate_instance(TRAPS) { 652 instanceOop instanceKlass::allocate_instance(TRAPS) {
653 assert(!oop_is_instanceMirror(), "wrong allocation path");
652 bool has_finalizer_flag = has_finalizer(); // Query before possible GC 654 bool has_finalizer_flag = has_finalizer(); // Query before possible GC
653 int size = size_helper(); // Query before forming handle. 655 int size = size_helper(); // Query before forming handle.
654 656
655 KlassHandle h_k(THREAD, as_klassOop()); 657 KlassHandle h_k(THREAD, as_klassOop());
656 658
667 // Finalizer registration occurs in the Object.<init> constructor 669 // Finalizer registration occurs in the Object.<init> constructor
668 // and constructors normally aren't run when allocating perm 670 // and constructors normally aren't run when allocating perm
669 // instances so simply disallow finalizable perm objects. This can 671 // instances so simply disallow finalizable perm objects. This can
670 // be relaxed if a need for it is found. 672 // be relaxed if a need for it is found.
671 assert(!has_finalizer(), "perm objects not allowed to have finalizers"); 673 assert(!has_finalizer(), "perm objects not allowed to have finalizers");
674 assert(!oop_is_instanceMirror(), "wrong allocation path");
672 int size = size_helper(); // Query before forming handle. 675 int size = size_helper(); // Query before forming handle.
673 KlassHandle h_k(THREAD, as_klassOop()); 676 KlassHandle h_k(THREAD, as_klassOop());
674 instanceOop i = (instanceOop) 677 instanceOop i = (instanceOop)
675 CollectedHeap::permanent_obj_allocate(h_k, size, CHECK_NULL); 678 CollectedHeap::permanent_obj_allocate(h_k, size, CHECK_NULL);
676 return i; 679 return i;
733 } 736 }
734 737
735 static int call_class_initializer_impl_counter = 0; // for debugging 738 static int call_class_initializer_impl_counter = 0; // for debugging
736 739
737 methodOop instanceKlass::class_initializer() { 740 methodOop instanceKlass::class_initializer() {
738 return find_method(vmSymbols::class_initializer_name(), vmSymbols::void_method_signature()); 741 methodOop clinit = find_method(
742 vmSymbols::class_initializer_name(), vmSymbols::void_method_signature());
743 if (clinit != NULL && clinit->has_valid_initializer_flags()) {
744 return clinit;
745 }
746 return NULL;
739 } 747 }
740 748
741 void instanceKlass::call_class_initializer_impl(instanceKlassHandle this_oop, TRAPS) { 749 void instanceKlass::call_class_initializer_impl(instanceKlassHandle this_oop, TRAPS) {
742 methodHandle h_method(THREAD, this_oop->class_initializer()); 750 methodHandle h_method(THREAD, this_oop->class_initializer());
743 assert(!this_oop->is_initialized(), "we cannot initialize twice"); 751 assert(!this_oop->is_initialized(), "we cannot initialize twice");
890 methodOop m = methodOop(methods()->obj_at(index)); 898 methodOop m = methodOop(methods()->obj_at(index));
891 assert(m->is_method(), "must be method"); 899 assert(m->is_method(), "must be method");
892 f(m); 900 f(m);
893 } 901 }
894 } 902 }
903
895 904
896 void instanceKlass::do_local_static_fields(FieldClosure* cl) { 905 void instanceKlass::do_local_static_fields(FieldClosure* cl) {
897 fieldDescriptor fd; 906 fieldDescriptor fd;
898 int length = fields()->length(); 907 int length = fields()->length();
899 for (int i = 0; i < length; i += next_offset) { 908 for (int i = 0; i < length; i += next_offset) {
1602 1611
1603 1612
1604 // The following macros call specialized macros, passing either oop or 1613 // The following macros call specialized macros, passing either oop or
1605 // narrowOop as the specialization type. These test the UseCompressedOops 1614 // narrowOop as the specialization type. These test the UseCompressedOops
1606 // flag. 1615 // flag.
1607 #define InstanceKlass_OOP_ITERATE(start_p, count, \
1608 do_oop, assert_fn) \
1609 { \
1610 if (UseCompressedOops) { \
1611 InstanceKlass_SPECIALIZED_OOP_ITERATE(narrowOop, \
1612 start_p, count, \
1613 do_oop, assert_fn) \
1614 } else { \
1615 InstanceKlass_SPECIALIZED_OOP_ITERATE(oop, \
1616 start_p, count, \
1617 do_oop, assert_fn) \
1618 } \
1619 }
1620
1621 #define InstanceKlass_BOUNDED_OOP_ITERATE(start_p, count, low, high, \
1622 do_oop, assert_fn) \
1623 { \
1624 if (UseCompressedOops) { \
1625 InstanceKlass_SPECIALIZED_BOUNDED_OOP_ITERATE(narrowOop, \
1626 start_p, count, \
1627 low, high, \
1628 do_oop, assert_fn) \
1629 } else { \
1630 InstanceKlass_SPECIALIZED_BOUNDED_OOP_ITERATE(oop, \
1631 start_p, count, \
1632 low, high, \
1633 do_oop, assert_fn) \
1634 } \
1635 }
1636
1637 #define InstanceKlass_OOP_MAP_ITERATE(obj, do_oop, assert_fn) \ 1616 #define InstanceKlass_OOP_MAP_ITERATE(obj, do_oop, assert_fn) \
1638 { \ 1617 { \
1639 /* Compute oopmap block range. The common case \ 1618 /* Compute oopmap block range. The common case \
1640 is nonstatic_oop_map_size == 1. */ \ 1619 is nonstatic_oop_map_size == 1. */ \
1641 OopMapBlock* map = start_of_nonstatic_oop_maps(); \ 1620 OopMapBlock* map = start_of_nonstatic_oop_maps(); \
1704 ++map; \ 1683 ++map; \
1705 } \ 1684 } \
1706 } \ 1685 } \
1707 } 1686 }
1708 1687
1709 void instanceKlass::follow_static_fields() {
1710 InstanceKlass_OOP_ITERATE( \
1711 start_of_static_fields(), static_oop_field_size(), \
1712 MarkSweep::mark_and_push(p), \
1713 assert_is_in_closed_subset)
1714 }
1715
1716 #ifndef SERIALGC
1717 void instanceKlass::follow_static_fields(ParCompactionManager* cm) {
1718 InstanceKlass_OOP_ITERATE( \
1719 start_of_static_fields(), static_oop_field_size(), \
1720 PSParallelCompact::mark_and_push(cm, p), \
1721 assert_is_in)
1722 }
1723 #endif // SERIALGC
1724
1725 void instanceKlass::adjust_static_fields() {
1726 InstanceKlass_OOP_ITERATE( \
1727 start_of_static_fields(), static_oop_field_size(), \
1728 MarkSweep::adjust_pointer(p), \
1729 assert_nothing)
1730 }
1731
1732 #ifndef SERIALGC
1733 void instanceKlass::update_static_fields() {
1734 InstanceKlass_OOP_ITERATE( \
1735 start_of_static_fields(), static_oop_field_size(), \
1736 PSParallelCompact::adjust_pointer(p), \
1737 assert_nothing)
1738 }
1739 #endif // SERIALGC
1740
1741 void instanceKlass::oop_follow_contents(oop obj) { 1688 void instanceKlass::oop_follow_contents(oop obj) {
1742 assert(obj != NULL, "can't follow the content of NULL object"); 1689 assert(obj != NULL, "can't follow the content of NULL object");
1743 obj->follow_header(); 1690 obj->follow_header();
1744 InstanceKlass_OOP_MAP_ITERATE( \ 1691 InstanceKlass_OOP_MAP_ITERATE( \
1745 obj, \ 1692 obj, \
1822 #ifndef SERIALGC 1769 #ifndef SERIALGC
1823 ALL_OOP_OOP_ITERATE_CLOSURES_1(InstanceKlass_OOP_OOP_ITERATE_BACKWARDS_DEFN) 1770 ALL_OOP_OOP_ITERATE_CLOSURES_1(InstanceKlass_OOP_OOP_ITERATE_BACKWARDS_DEFN)
1824 ALL_OOP_OOP_ITERATE_CLOSURES_2(InstanceKlass_OOP_OOP_ITERATE_BACKWARDS_DEFN) 1771 ALL_OOP_OOP_ITERATE_CLOSURES_2(InstanceKlass_OOP_OOP_ITERATE_BACKWARDS_DEFN)
1825 #endif // !SERIALGC 1772 #endif // !SERIALGC
1826 1773
1827 void instanceKlass::iterate_static_fields(OopClosure* closure) {
1828 InstanceKlass_OOP_ITERATE( \
1829 start_of_static_fields(), static_oop_field_size(), \
1830 closure->do_oop(p), \
1831 assert_is_in_reserved)
1832 }
1833
1834 void instanceKlass::iterate_static_fields(OopClosure* closure,
1835 MemRegion mr) {
1836 InstanceKlass_BOUNDED_OOP_ITERATE( \
1837 start_of_static_fields(), static_oop_field_size(), \
1838 mr.start(), mr.end(), \
1839 (closure)->do_oop_v(p), \
1840 assert_is_in_closed_subset)
1841 }
1842
1843 int instanceKlass::oop_adjust_pointers(oop obj) { 1774 int instanceKlass::oop_adjust_pointers(oop obj) {
1844 int size = size_helper(); 1775 int size = size_helper();
1845 InstanceKlass_OOP_MAP_ITERATE( \ 1776 InstanceKlass_OOP_MAP_ITERATE( \
1846 obj, \ 1777 obj, \
1847 MarkSweep::adjust_pointer(p), \ 1778 MarkSweep::adjust_pointer(p), \
1866 PSParallelCompact::adjust_pointer(p), \ 1797 PSParallelCompact::adjust_pointer(p), \
1867 assert_nothing) 1798 assert_nothing)
1868 return size_helper(); 1799 return size_helper();
1869 } 1800 }
1870 1801
1871 void instanceKlass::push_static_fields(PSPromotionManager* pm) {
1872 InstanceKlass_OOP_ITERATE( \
1873 start_of_static_fields(), static_oop_field_size(), \
1874 if (PSScavenge::should_scavenge(p)) { \
1875 pm->claim_or_forward_depth(p); \
1876 }, \
1877 assert_nothing )
1878 }
1879
1880 void instanceKlass::copy_static_fields(ParCompactionManager* cm) {
1881 InstanceKlass_OOP_ITERATE( \
1882 start_of_static_fields(), static_oop_field_size(), \
1883 PSParallelCompact::adjust_pointer(p), \
1884 assert_is_in)
1885 }
1886 #endif // SERIALGC 1802 #endif // SERIALGC
1887 1803
1888 // This klass is alive but the implementor link is not followed/updated. 1804 // This klass is alive but the implementor link is not followed/updated.
1889 // Subklass and sibling links are handled by Klass::follow_weak_klass_links 1805 // Subklass and sibling links are handled by Klass::follow_weak_klass_links
1890 1806
1994 1910
1995 void instanceKlass::set_source_debug_extension(Symbol* n) { 1911 void instanceKlass::set_source_debug_extension(Symbol* n) {
1996 _source_debug_extension = n; 1912 _source_debug_extension = n;
1997 if (_source_debug_extension != NULL) _source_debug_extension->increment_refcount(); 1913 if (_source_debug_extension != NULL) _source_debug_extension->increment_refcount();
1998 } 1914 }
1915
1916 address instanceKlass::static_field_addr(int offset) {
1917 return (address)(offset + instanceMirrorKlass::offset_of_static_fields() + (intptr_t)java_mirror());
1918 }
1919
1999 1920
2000 const char* instanceKlass::signature_name() const { 1921 const char* instanceKlass::signature_name() const {
2001 const char* src = (const char*) (name()->as_C_string()); 1922 const char* src = (const char*) (name()->as_C_string());
2002 const int src_length = (int)strlen(src); 1923 const int src_length = (int)strlen(src);
2003 char* dest = NEW_RESOURCE_ARRAY(char, src_length + 3); 1924 char* dest = NEW_RESOURCE_ARRAY(char, src_length + 3);
2362 2283
2363 #define BULLET " - " 2284 #define BULLET " - "
2364 2285
2365 void FieldPrinter::do_field(fieldDescriptor* fd) { 2286 void FieldPrinter::do_field(fieldDescriptor* fd) {
2366 _st->print(BULLET); 2287 _st->print(BULLET);
2367 if (fd->is_static() || (_obj == NULL)) { 2288 if (_obj == NULL) {
2368 fd->print_on(_st); 2289 fd->print_on(_st);
2369 _st->cr(); 2290 _st->cr();
2370 } else { 2291 } else {
2371 fd->print_on_for(_st, _obj); 2292 fd->print_on_for(_st, _obj);
2372 _st->cr(); 2293 _st->cr();
2392 if (!WizardMode) return; // that is enough 2313 if (!WizardMode) return; // that is enough
2393 } 2314 }
2394 } 2315 }
2395 2316
2396 st->print_cr(BULLET"---- fields (total size %d words):", oop_size(obj)); 2317 st->print_cr(BULLET"---- fields (total size %d words):", oop_size(obj));
2397 FieldPrinter print_nonstatic_field(st, obj); 2318 FieldPrinter print_field(st, obj);
2398 do_nonstatic_fields(&print_nonstatic_field); 2319 do_nonstatic_fields(&print_field);
2399 2320
2400 if (as_klassOop() == SystemDictionary::Class_klass()) { 2321 if (as_klassOop() == SystemDictionary::Class_klass()) {
2401 st->print(BULLET"signature: "); 2322 st->print(BULLET"signature: ");
2402 java_lang_Class::print_signature(obj, st); 2323 java_lang_Class::print_signature(obj, st);
2403 st->cr(); 2324 st->cr();
2411 klassOop array_klass = java_lang_Class::array_klass(obj); 2332 klassOop array_klass = java_lang_Class::array_klass(obj);
2412 st->cr(); 2333 st->cr();
2413 st->print(BULLET"fake entry for array: "); 2334 st->print(BULLET"fake entry for array: ");
2414 array_klass->print_value_on(st); 2335 array_klass->print_value_on(st);
2415 st->cr(); 2336 st->cr();
2337 st->print_cr(BULLET"fake entry for oop_size: %d", java_lang_Class::oop_size(obj));
2338 st->print_cr(BULLET"fake entry for static_oop_field_count: %d", java_lang_Class::static_oop_field_count(obj));
2339 klassOop real_klass = java_lang_Class::as_klassOop(obj);
2340 if (real_klass != NULL && real_klass->klass_part()->oop_is_instance()) {
2341 instanceKlass::cast(real_klass)->do_local_static_fields(&print_field);
2342 }
2416 } else if (as_klassOop() == SystemDictionary::MethodType_klass()) { 2343 } else if (as_klassOop() == SystemDictionary::MethodType_klass()) {
2417 st->print(BULLET"signature: "); 2344 st->print(BULLET"signature: ");
2418 java_dyn_MethodType::print_signature(obj, st); 2345 java_lang_invoke_MethodType::print_signature(obj, st);
2419 st->cr(); 2346 st->cr();
2420 } 2347 }
2421 } 2348 }
2422 2349
2423 #endif //PRODUCT 2350 #endif //PRODUCT
2444 const char* tname = type2name(java_lang_Class::primitive_type(obj)); 2371 const char* tname = type2name(java_lang_Class::primitive_type(obj));
2445 st->print("%s", tname ? tname : "type?"); 2372 st->print("%s", tname ? tname : "type?");
2446 } 2373 }
2447 } else if (as_klassOop() == SystemDictionary::MethodType_klass()) { 2374 } else if (as_klassOop() == SystemDictionary::MethodType_klass()) {
2448 st->print(" = "); 2375 st->print(" = ");
2449 java_dyn_MethodType::print_signature(obj, st); 2376 java_lang_invoke_MethodType::print_signature(obj, st);
2450 } else if (java_lang_boxing_object::is_instance(obj)) { 2377 } else if (java_lang_boxing_object::is_instance(obj)) {
2451 st->print(" = "); 2378 st->print(" = ");
2452 java_lang_boxing_object::print(obj, st); 2379 java_lang_boxing_object::print(obj, st);
2453 } 2380 }
2454 } 2381 }
2553 } 2480 }
2554 } 2481 }
2555 2482
2556 2483
2557 void JNIid::verify(klassOop holder) { 2484 void JNIid::verify(klassOop holder) {
2558 int first_field_offset = instanceKlass::cast(holder)->offset_of_static_fields(); 2485 int first_field_offset = instanceMirrorKlass::offset_of_static_fields();
2559 int end_field_offset; 2486 int end_field_offset;
2560 end_field_offset = first_field_offset + (instanceKlass::cast(holder)->static_field_size() * wordSize); 2487 end_field_offset = first_field_offset + (instanceKlass::cast(holder)->static_field_size() * wordSize);
2561 2488
2562 JNIid* current = this; 2489 JNIid* current = this;
2563 while (current != NULL) { 2490 while (current != NULL) {