comparison src/share/vm/oops/instanceKlass.cpp @ 8124:5fc51c1ecdeb

Merge.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Tue, 05 Mar 2013 23:44:54 +0100
parents 3ac7d10a6572 927a311d00f9
children b9a918201d47
comparison
equal deleted inserted replaced
7943:a413bcd552a4 8124:5fc51c1ecdeb
1 /* 1 /*
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
32 #include "gc_interface/collectedHeap.inline.hpp" 32 #include "gc_interface/collectedHeap.inline.hpp"
33 #include "interpreter/oopMapCache.hpp" 33 #include "interpreter/oopMapCache.hpp"
34 #include "interpreter/rewriter.hpp" 34 #include "interpreter/rewriter.hpp"
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/heapInspection.hpp"
37 #include "memory/metadataFactory.hpp" 38 #include "memory/metadataFactory.hpp"
38 #include "memory/oopFactory.hpp" 39 #include "memory/oopFactory.hpp"
39 #include "oops/fieldStreams.hpp" 40 #include "oops/fieldStreams.hpp"
40 #include "oops/instanceClassLoaderKlass.hpp" 41 #include "oops/instanceClassLoaderKlass.hpp"
41 #include "oops/instanceKlass.hpp" 42 #include "oops/instanceKlass.hpp"
53 #include "runtime/javaCalls.hpp" 54 #include "runtime/javaCalls.hpp"
54 #include "runtime/mutexLocker.hpp" 55 #include "runtime/mutexLocker.hpp"
55 #include "runtime/thread.inline.hpp" 56 #include "runtime/thread.inline.hpp"
56 #include "services/threadService.hpp" 57 #include "services/threadService.hpp"
57 #include "utilities/dtrace.hpp" 58 #include "utilities/dtrace.hpp"
58 #ifndef SERIALGC 59 #include "utilities/macros.hpp"
60 #if INCLUDE_ALL_GCS
59 #include "gc_implementation/concurrentMarkSweep/cmsOopClosures.inline.hpp" 61 #include "gc_implementation/concurrentMarkSweep/cmsOopClosures.inline.hpp"
60 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp" 62 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
61 #include "gc_implementation/g1/g1OopClosures.inline.hpp" 63 #include "gc_implementation/g1/g1OopClosures.inline.hpp"
62 #include "gc_implementation/g1/g1RemSet.inline.hpp" 64 #include "gc_implementation/g1/g1RemSet.inline.hpp"
63 #include "gc_implementation/g1/heapRegionSeq.inline.hpp" 65 #include "gc_implementation/g1/heapRegionSeq.inline.hpp"
64 #include "gc_implementation/parNew/parOopClosures.inline.hpp" 66 #include "gc_implementation/parNew/parOopClosures.inline.hpp"
65 #include "gc_implementation/parallelScavenge/parallelScavengeHeap.inline.hpp" 67 #include "gc_implementation/parallelScavenge/parallelScavengeHeap.inline.hpp"
66 #include "gc_implementation/parallelScavenge/psPromotionManager.inline.hpp" 68 #include "gc_implementation/parallelScavenge/psPromotionManager.inline.hpp"
67 #include "gc_implementation/parallelScavenge/psScavenge.inline.hpp" 69 #include "gc_implementation/parallelScavenge/psScavenge.inline.hpp"
68 #include "oops/oop.pcgc.inline.hpp" 70 #include "oops/oop.pcgc.inline.hpp"
69 #endif 71 #endif // INCLUDE_ALL_GCS
70 #ifdef COMPILER1 72 #ifdef COMPILER1
71 #include "c1/c1_Compiler.hpp" 73 #include "c1/c1_Compiler.hpp"
72 #endif 74 #endif
73 75
74 #ifdef DTRACE_ENABLED 76 #ifdef DTRACE_ENABLED
162 #endif // ndef DTRACE_ENABLED 164 #endif // ndef DTRACE_ENABLED
163 165
164 volatile int InstanceKlass::_total_instanceKlass_count = 0; 166 volatile int InstanceKlass::_total_instanceKlass_count = 0;
165 167
166 Klass* InstanceKlass::allocate_instance_klass(ClassLoaderData* loader_data, 168 Klass* InstanceKlass::allocate_instance_klass(ClassLoaderData* loader_data,
167 int vtable_len, 169 int vtable_len,
168 int itable_len, 170 int itable_len,
169 int static_field_size, 171 int static_field_size,
170 int nonstatic_oop_map_size, 172 int nonstatic_oop_map_size,
171 ReferenceType rt, 173 ReferenceType rt,
172 AccessFlags access_flags, 174 AccessFlags access_flags,
173 Symbol* name, 175 Symbol* name,
174 Klass* super_klass, 176 Klass* super_klass,
175 KlassHandle host_klass, 177 bool is_anonymous,
176 TRAPS) { 178 TRAPS) {
177 179
178 int size = InstanceKlass::size(vtable_len, itable_len, nonstatic_oop_map_size, 180 int size = InstanceKlass::size(vtable_len, itable_len, nonstatic_oop_map_size,
179 access_flags.is_interface(), 181 access_flags.is_interface(), is_anonymous);
180 !host_klass.is_null());
181 182
182 // Allocation 183 // Allocation
183 InstanceKlass* ik; 184 InstanceKlass* ik;
184 if (rt == REF_NONE) { 185 if (rt == REF_NONE) {
185 if (name == vmSymbols::java_lang_Class()) { 186 if (name == vmSymbols::java_lang_Class()) {
186 ik = new (loader_data, size, THREAD) InstanceMirrorKlass( 187 ik = new (loader_data, size, THREAD) InstanceMirrorKlass(
187 vtable_len, itable_len, static_field_size, nonstatic_oop_map_size, rt, 188 vtable_len, itable_len, static_field_size, nonstatic_oop_map_size, rt,
188 access_flags, !host_klass.is_null()); 189 access_flags, is_anonymous);
189 } else if (name == vmSymbols::java_lang_ClassLoader() || 190 } else if (name == vmSymbols::java_lang_ClassLoader() ||
190 (SystemDictionary::ClassLoader_klass_loaded() && 191 (SystemDictionary::ClassLoader_klass_loaded() &&
191 super_klass != NULL && 192 super_klass != NULL &&
192 super_klass->is_subtype_of(SystemDictionary::ClassLoader_klass()))) { 193 super_klass->is_subtype_of(SystemDictionary::ClassLoader_klass()))) {
193 ik = new (loader_data, size, THREAD) InstanceClassLoaderKlass( 194 ik = new (loader_data, size, THREAD) InstanceClassLoaderKlass(
194 vtable_len, itable_len, static_field_size, nonstatic_oop_map_size, rt, 195 vtable_len, itable_len, static_field_size, nonstatic_oop_map_size, rt,
195 access_flags, !host_klass.is_null()); 196 access_flags, is_anonymous);
196 } else { 197 } else {
197 // normal class 198 // normal class
198 ik = new (loader_data, size, THREAD) InstanceKlass( 199 ik = new (loader_data, size, THREAD) InstanceKlass(
199 vtable_len, itable_len, static_field_size, nonstatic_oop_map_size, rt, 200 vtable_len, itable_len, static_field_size, nonstatic_oop_map_size, rt,
200 access_flags, !host_klass.is_null()); 201 access_flags, is_anonymous);
201 } 202 }
202 } else { 203 } else {
203 // reference klass 204 // reference klass
204 ik = new (loader_data, size, THREAD) InstanceRefKlass( 205 ik = new (loader_data, size, THREAD) InstanceRefKlass(
205 vtable_len, itable_len, static_field_size, nonstatic_oop_map_size, rt, 206 vtable_len, itable_len, static_field_size, nonstatic_oop_map_size, rt,
206 access_flags, !host_klass.is_null()); 207 access_flags, is_anonymous);
207 } 208 }
208 209
209 Atomic::inc(&_total_instanceKlass_count); 210 Atomic::inc(&_total_instanceKlass_count);
210 return ik; 211 return ik;
211 } 212 }
2040 obj, \ 2041 obj, \
2041 MarkSweep::mark_and_push(p), \ 2042 MarkSweep::mark_and_push(p), \
2042 assert_is_in_closed_subset) 2043 assert_is_in_closed_subset)
2043 } 2044 }
2044 2045
2045 #ifndef SERIALGC 2046 #if INCLUDE_ALL_GCS
2046 void InstanceKlass::oop_follow_contents(ParCompactionManager* cm, 2047 void InstanceKlass::oop_follow_contents(ParCompactionManager* cm,
2047 oop obj) { 2048 oop obj) {
2048 assert(obj != NULL, "can't follow the content of NULL object"); 2049 assert(obj != NULL, "can't follow the content of NULL object");
2049 PSParallelCompact::follow_klass(cm, obj->klass()); 2050 PSParallelCompact::follow_klass(cm, obj->klass());
2050 // Only mark the header and let the scan of the meta-data mark 2051 // Only mark the header and let the scan of the meta-data mark
2052 InstanceKlass_OOP_MAP_ITERATE( \ 2053 InstanceKlass_OOP_MAP_ITERATE( \
2053 obj, \ 2054 obj, \
2054 PSParallelCompact::mark_and_push(cm, p), \ 2055 PSParallelCompact::mark_and_push(cm, p), \
2055 assert_is_in) 2056 assert_is_in)
2056 } 2057 }
2057 #endif // SERIALGC 2058 #endif // INCLUDE_ALL_GCS
2058 2059
2059 // closure's do_metadata() method dictates whether the given closure should be 2060 // closure's do_metadata() method dictates whether the given closure should be
2060 // applied to the klass ptr in the object header. 2061 // applied to the klass ptr in the object header.
2061 2062
2062 #define if_do_metadata_checked(closure, nv_suffix) \ 2063 #define if_do_metadata_checked(closure, nv_suffix) \
2080 (closure)->do_oop##nv_suffix(p), \ 2081 (closure)->do_oop##nv_suffix(p), \
2081 assert_is_in_closed_subset) \ 2082 assert_is_in_closed_subset) \
2082 return size_helper(); \ 2083 return size_helper(); \
2083 } 2084 }
2084 2085
2085 #ifndef SERIALGC 2086 #if INCLUDE_ALL_GCS
2086 #define InstanceKlass_OOP_OOP_ITERATE_BACKWARDS_DEFN(OopClosureType, nv_suffix) \ 2087 #define InstanceKlass_OOP_OOP_ITERATE_BACKWARDS_DEFN(OopClosureType, nv_suffix) \
2087 \ 2088 \
2088 int InstanceKlass::oop_oop_iterate_backwards##nv_suffix(oop obj, \ 2089 int InstanceKlass::oop_oop_iterate_backwards##nv_suffix(oop obj, \
2089 OopClosureType* closure) { \ 2090 OopClosureType* closure) { \
2090 SpecializationStats::record_iterate_call##nv_suffix(SpecializationStats::ik); \ 2091 SpecializationStats::record_iterate_call##nv_suffix(SpecializationStats::ik); \
2098 SpecializationStats::record_do_oop_call##nv_suffix(SpecializationStats::ik);\ 2099 SpecializationStats::record_do_oop_call##nv_suffix(SpecializationStats::ik);\
2099 (closure)->do_oop##nv_suffix(p), \ 2100 (closure)->do_oop##nv_suffix(p), \
2100 assert_is_in_closed_subset) \ 2101 assert_is_in_closed_subset) \
2101 return size_helper(); \ 2102 return size_helper(); \
2102 } 2103 }
2103 #endif // !SERIALGC 2104 #endif // INCLUDE_ALL_GCS
2104 2105
2105 #define InstanceKlass_OOP_OOP_ITERATE_DEFN_m(OopClosureType, nv_suffix) \ 2106 #define InstanceKlass_OOP_OOP_ITERATE_DEFN_m(OopClosureType, nv_suffix) \
2106 \ 2107 \
2107 int InstanceKlass::oop_oop_iterate##nv_suffix##_m(oop obj, \ 2108 int InstanceKlass::oop_oop_iterate##nv_suffix##_m(oop obj, \
2108 OopClosureType* closure, \ 2109 OopClosureType* closure, \
2122 2123
2123 ALL_OOP_OOP_ITERATE_CLOSURES_1(InstanceKlass_OOP_OOP_ITERATE_DEFN) 2124 ALL_OOP_OOP_ITERATE_CLOSURES_1(InstanceKlass_OOP_OOP_ITERATE_DEFN)
2124 ALL_OOP_OOP_ITERATE_CLOSURES_2(InstanceKlass_OOP_OOP_ITERATE_DEFN) 2125 ALL_OOP_OOP_ITERATE_CLOSURES_2(InstanceKlass_OOP_OOP_ITERATE_DEFN)
2125 ALL_OOP_OOP_ITERATE_CLOSURES_1(InstanceKlass_OOP_OOP_ITERATE_DEFN_m) 2126 ALL_OOP_OOP_ITERATE_CLOSURES_1(InstanceKlass_OOP_OOP_ITERATE_DEFN_m)
2126 ALL_OOP_OOP_ITERATE_CLOSURES_2(InstanceKlass_OOP_OOP_ITERATE_DEFN_m) 2127 ALL_OOP_OOP_ITERATE_CLOSURES_2(InstanceKlass_OOP_OOP_ITERATE_DEFN_m)
2127 #ifndef SERIALGC 2128 #if INCLUDE_ALL_GCS
2128 ALL_OOP_OOP_ITERATE_CLOSURES_1(InstanceKlass_OOP_OOP_ITERATE_BACKWARDS_DEFN) 2129 ALL_OOP_OOP_ITERATE_CLOSURES_1(InstanceKlass_OOP_OOP_ITERATE_BACKWARDS_DEFN)
2129 ALL_OOP_OOP_ITERATE_CLOSURES_2(InstanceKlass_OOP_OOP_ITERATE_BACKWARDS_DEFN) 2130 ALL_OOP_OOP_ITERATE_CLOSURES_2(InstanceKlass_OOP_OOP_ITERATE_BACKWARDS_DEFN)
2130 #endif // !SERIALGC 2131 #endif // INCLUDE_ALL_GCS
2131 2132
2132 int InstanceKlass::oop_adjust_pointers(oop obj) { 2133 int InstanceKlass::oop_adjust_pointers(oop obj) {
2133 int size = size_helper(); 2134 int size = size_helper();
2134 InstanceKlass_OOP_MAP_ITERATE( \ 2135 InstanceKlass_OOP_MAP_ITERATE( \
2135 obj, \ 2136 obj, \
2137 assert_is_in) 2138 assert_is_in)
2138 MarkSweep::adjust_klass(obj->klass()); 2139 MarkSweep::adjust_klass(obj->klass());
2139 return size; 2140 return size;
2140 } 2141 }
2141 2142
2142 #ifndef SERIALGC 2143 #if INCLUDE_ALL_GCS
2143 void InstanceKlass::oop_push_contents(PSPromotionManager* pm, oop obj) { 2144 void InstanceKlass::oop_push_contents(PSPromotionManager* pm, oop obj) {
2144 InstanceKlass_OOP_MAP_REVERSE_ITERATE( \ 2145 InstanceKlass_OOP_MAP_REVERSE_ITERATE( \
2145 obj, \ 2146 obj, \
2146 if (PSScavenge::should_scavenge(p)) { \ 2147 if (PSScavenge::should_scavenge(p)) { \
2147 pm->claim_or_forward_depth(p); \ 2148 pm->claim_or_forward_depth(p); \
2157 assert_is_in) 2158 assert_is_in)
2158 obj->update_header(cm); 2159 obj->update_header(cm);
2159 return size; 2160 return size;
2160 } 2161 }
2161 2162
2162 #endif // SERIALGC 2163 #endif // INCLUDE_ALL_GCS
2163 2164
2164 void InstanceKlass::clean_implementors_list(BoolObjectClosure* is_alive) { 2165 void InstanceKlass::clean_implementors_list(BoolObjectClosure* is_alive) {
2165 assert(is_loader_alive(is_alive), "this klass should be live"); 2166 assert(is_loader_alive(is_alive), "this klass should be live");
2166 if (is_interface()) { 2167 if (is_interface()) {
2167 if (ClassUnloading) { 2168 if (ClassUnloading) {
2789 if (source_debug_extension() != NULL) { 2790 if (source_debug_extension() != NULL) {
2790 st->print(BULLET"source debug extension: "); 2791 st->print(BULLET"source debug extension: ");
2791 st->print("%s", source_debug_extension()); 2792 st->print("%s", source_debug_extension());
2792 st->cr(); 2793 st->cr();
2793 } 2794 }
2794 st->print(BULLET"annotations: "); annotations()->print_value_on(st); st->cr(); 2795 st->print(BULLET"class annotations: "); class_annotations()->print_value_on(st); st->cr();
2796 st->print(BULLET"class type annotations: "); class_type_annotations()->print_value_on(st); st->cr();
2797 st->print(BULLET"field annotations: "); fields_annotations()->print_value_on(st); st->cr();
2798 st->print(BULLET"field type annotations: "); fields_type_annotations()->print_value_on(st); st->cr();
2795 { 2799 {
2796 ResourceMark rm; 2800 ResourceMark rm;
2797 // PreviousVersionInfo objects returned via PreviousVersionWalker 2801 // PreviousVersionInfo objects returned via PreviousVersionWalker
2798 // contain a GrowableArray of handles. We have to clean up the 2802 // contain a GrowableArray of handles. We have to clean up the
2799 // GrowableArray _after_ the PreviousVersionWalker destructor 2803 // GrowableArray _after_ the PreviousVersionWalker destructor
2957 } 2961 }
2958 2962
2959 const char* InstanceKlass::internal_name() const { 2963 const char* InstanceKlass::internal_name() const {
2960 return external_name(); 2964 return external_name();
2961 } 2965 }
2966
2967 #if INCLUDE_SERVICES
2968 // Size Statistics
2969 void InstanceKlass::collect_statistics(KlassSizeStats *sz) const {
2970 Klass::collect_statistics(sz);
2971
2972 sz->_inst_size = HeapWordSize * size_helper();
2973 sz->_vtab_bytes = HeapWordSize * align_object_offset(vtable_length());
2974 sz->_itab_bytes = HeapWordSize * align_object_offset(itable_length());
2975 sz->_nonstatic_oopmap_bytes = HeapWordSize *
2976 ((is_interface() || is_anonymous()) ?
2977 align_object_offset(nonstatic_oop_map_size()) :
2978 nonstatic_oop_map_size());
2979
2980 int n = 0;
2981 n += (sz->_methods_array_bytes = sz->count_array(methods()));
2982 n += (sz->_method_ordering_bytes = sz->count_array(method_ordering()));
2983 n += (sz->_local_interfaces_bytes = sz->count_array(local_interfaces()));
2984 n += (sz->_transitive_interfaces_bytes = sz->count_array(transitive_interfaces()));
2985 n += (sz->_signers_bytes = sz->count_array(signers()));
2986 n += (sz->_fields_bytes = sz->count_array(fields()));
2987 n += (sz->_inner_classes_bytes = sz->count_array(inner_classes()));
2988 sz->_ro_bytes += n;
2989
2990 const ConstantPool* cp = constants();
2991 if (cp) {
2992 cp->collect_statistics(sz);
2993 }
2994
2995 const Annotations* anno = annotations();
2996 if (anno) {
2997 anno->collect_statistics(sz);
2998 }
2999
3000 const Array<Method*>* methods_array = methods();
3001 if (methods()) {
3002 for (int i = 0; i < methods_array->length(); i++) {
3003 Method* method = methods_array->at(i);
3004 if (method) {
3005 sz->_method_count ++;
3006 method->collect_statistics(sz);
3007 }
3008 }
3009 }
3010 }
3011 #endif // INCLUDE_SERVICES
2962 3012
2963 // Verification 3013 // Verification
2964 3014
2965 class VerifyFieldClosure: public OopClosure { 3015 class VerifyFieldClosure: public OopClosure {
2966 protected: 3016 protected: