src/share/vm/oops/instanceKlass.cpp

Mon, 07 Aug 2017 12:19:17 +0200

author
sgehwolf
date
Mon, 07 Aug 2017 12:19:17 +0200
changeset 9721
78c11f573795
parent 9690
61d955db2a5b
child 9756
2be326848943
child 9792
9a7135d0a309
child 9866
41515291559a
permissions
-rw-r--r--

8185900: hotspot build failed with gcc version Red Hat 4.4.7-3
Summary: Cast to void* within DTRACE_CLASS* macros.
Reviewed-by: coleenp, shade

duke@435 1 /*
xliu@9690 2 * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #include "precompiled.hpp"
stefank@2314 26 #include "classfile/javaClasses.hpp"
stefank@2314 27 #include "classfile/systemDictionary.hpp"
iklam@8497 28 #include "classfile/systemDictionaryShared.hpp"
stefank@2314 29 #include "classfile/verifier.hpp"
stefank@2314 30 #include "classfile/vmSymbols.hpp"
stefank@2314 31 #include "compiler/compileBroker.hpp"
stefank@2314 32 #include "gc_implementation/shared/markSweep.inline.hpp"
stefank@2314 33 #include "gc_interface/collectedHeap.inline.hpp"
stefank@2314 34 #include "interpreter/oopMapCache.hpp"
stefank@2314 35 #include "interpreter/rewriter.hpp"
stefank@2314 36 #include "jvmtifiles/jvmti.h"
stefank@2314 37 #include "memory/genOopClosures.inline.hpp"
acorn@4497 38 #include "memory/heapInspection.hpp"
stefank@6982 39 #include "memory/iterator.inline.hpp"
coleenp@4037 40 #include "memory/metadataFactory.hpp"
stefank@2314 41 #include "memory/oopFactory.hpp"
never@3137 42 #include "oops/fieldStreams.hpp"
coleenp@4037 43 #include "oops/instanceClassLoaderKlass.hpp"
stefank@2314 44 #include "oops/instanceKlass.hpp"
never@2658 45 #include "oops/instanceMirrorKlass.hpp"
stefank@2314 46 #include "oops/instanceOop.hpp"
coleenp@4037 47 #include "oops/klass.inline.hpp"
coleenp@4037 48 #include "oops/method.hpp"
stefank@2314 49 #include "oops/oop.inline.hpp"
coleenp@2497 50 #include "oops/symbol.hpp"
stefank@2314 51 #include "prims/jvmtiExport.hpp"
stefank@2314 52 #include "prims/jvmtiRedefineClassesTrace.hpp"
jiangli@5421 53 #include "prims/jvmtiRedefineClasses.hpp"
jbachorik@7812 54 #include "prims/jvmtiThreadState.hpp"
coleenp@4395 55 #include "prims/methodComparator.hpp"
stefank@2314 56 #include "runtime/fieldDescriptor.hpp"
stefank@2314 57 #include "runtime/handles.inline.hpp"
stefank@2314 58 #include "runtime/javaCalls.hpp"
stefank@2314 59 #include "runtime/mutexLocker.hpp"
goetz@6911 60 #include "runtime/orderAccess.inline.hpp"
stefank@4299 61 #include "runtime/thread.inline.hpp"
coleenp@4981 62 #include "services/classLoadingService.hpp"
stefank@2314 63 #include "services/threadService.hpp"
stefank@2314 64 #include "utilities/dtrace.hpp"
jprovino@4542 65 #include "utilities/macros.hpp"
jprovino@4542 66 #if INCLUDE_ALL_GCS
coleenp@4037 67 #include "gc_implementation/concurrentMarkSweep/cmsOopClosures.inline.hpp"
stefank@2314 68 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
stefank@2314 69 #include "gc_implementation/g1/g1OopClosures.inline.hpp"
stefank@2314 70 #include "gc_implementation/g1/g1RemSet.inline.hpp"
tschatzl@7091 71 #include "gc_implementation/g1/heapRegionManager.inline.hpp"
stefank@2314 72 #include "gc_implementation/parNew/parOopClosures.inline.hpp"
coleenp@4037 73 #include "gc_implementation/parallelScavenge/parallelScavengeHeap.inline.hpp"
stefank@2314 74 #include "gc_implementation/parallelScavenge/psPromotionManager.inline.hpp"
stefank@2314 75 #include "gc_implementation/parallelScavenge/psScavenge.inline.hpp"
stefank@2314 76 #include "oops/oop.pcgc.inline.hpp"
jprovino@4542 77 #endif // INCLUDE_ALL_GCS
stefank@2314 78 #ifdef COMPILER1
stefank@2314 79 #include "c1/c1_Compiler.hpp"
stefank@2314 80 #endif
duke@435 81
drchase@6680 82 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
drchase@6680 83
fparain@1759 84 #ifdef DTRACE_ENABLED
fparain@1759 85
dcubed@3202 86 #ifndef USDT2
dcubed@3202 87
fparain@1759 88 HS_DTRACE_PROBE_DECL4(hotspot, class__initialization__required,
fparain@1759 89 char*, intptr_t, oop, intptr_t);
fparain@1759 90 HS_DTRACE_PROBE_DECL5(hotspot, class__initialization__recursive,
fparain@1759 91 char*, intptr_t, oop, intptr_t, int);
fparain@1759 92 HS_DTRACE_PROBE_DECL5(hotspot, class__initialization__concurrent,
fparain@1759 93 char*, intptr_t, oop, intptr_t, int);
fparain@1759 94 HS_DTRACE_PROBE_DECL5(hotspot, class__initialization__erroneous,
fparain@1759 95 char*, intptr_t, oop, intptr_t, int);
fparain@1759 96 HS_DTRACE_PROBE_DECL5(hotspot, class__initialization__super__failed,
fparain@1759 97 char*, intptr_t, oop, intptr_t, int);
fparain@1759 98 HS_DTRACE_PROBE_DECL5(hotspot, class__initialization__clinit,
fparain@1759 99 char*, intptr_t, oop, intptr_t, int);
fparain@1759 100 HS_DTRACE_PROBE_DECL5(hotspot, class__initialization__error,
fparain@1759 101 char*, intptr_t, oop, intptr_t, int);
fparain@1759 102 HS_DTRACE_PROBE_DECL5(hotspot, class__initialization__end,
fparain@1759 103 char*, intptr_t, oop, intptr_t, int);
fparain@1759 104
fparain@1759 105 #define DTRACE_CLASSINIT_PROBE(type, clss, thread_type) \
fparain@1759 106 { \
fparain@1759 107 char* data = NULL; \
fparain@1759 108 int len = 0; \
coleenp@2497 109 Symbol* name = (clss)->name(); \
fparain@1759 110 if (name != NULL) { \
fparain@1759 111 data = (char*)name->bytes(); \
fparain@1759 112 len = name->utf8_length(); \
fparain@1759 113 } \
fparain@1759 114 HS_DTRACE_PROBE4(hotspot, class__initialization__##type, \
lfoltan@7770 115 data, len, (void *)(clss)->class_loader(), thread_type); \
fparain@1759 116 }
fparain@1759 117
fparain@1759 118 #define DTRACE_CLASSINIT_PROBE_WAIT(type, clss, thread_type, wait) \
fparain@1759 119 { \
fparain@1759 120 char* data = NULL; \
fparain@1759 121 int len = 0; \
coleenp@2497 122 Symbol* name = (clss)->name(); \
fparain@1759 123 if (name != NULL) { \
fparain@1759 124 data = (char*)name->bytes(); \
fparain@1759 125 len = name->utf8_length(); \
fparain@1759 126 } \
fparain@1759 127 HS_DTRACE_PROBE5(hotspot, class__initialization__##type, \
lfoltan@7770 128 data, len, (void *)(clss)->class_loader(), thread_type, wait); \
fparain@1759 129 }
dcubed@3202 130 #else /* USDT2 */
dcubed@3202 131
dcubed@3202 132 #define HOTSPOT_CLASS_INITIALIZATION_required HOTSPOT_CLASS_INITIALIZATION_REQUIRED
dcubed@3202 133 #define HOTSPOT_CLASS_INITIALIZATION_recursive HOTSPOT_CLASS_INITIALIZATION_RECURSIVE
dcubed@3202 134 #define HOTSPOT_CLASS_INITIALIZATION_concurrent HOTSPOT_CLASS_INITIALIZATION_CONCURRENT
dcubed@3202 135 #define HOTSPOT_CLASS_INITIALIZATION_erroneous HOTSPOT_CLASS_INITIALIZATION_ERRONEOUS
dcubed@3202 136 #define HOTSPOT_CLASS_INITIALIZATION_super__failed HOTSPOT_CLASS_INITIALIZATION_SUPER_FAILED
dcubed@3202 137 #define HOTSPOT_CLASS_INITIALIZATION_clinit HOTSPOT_CLASS_INITIALIZATION_CLINIT
dcubed@3202 138 #define HOTSPOT_CLASS_INITIALIZATION_error HOTSPOT_CLASS_INITIALIZATION_ERROR
dcubed@3202 139 #define HOTSPOT_CLASS_INITIALIZATION_end HOTSPOT_CLASS_INITIALIZATION_END
dcubed@3202 140 #define DTRACE_CLASSINIT_PROBE(type, clss, thread_type) \
dcubed@3202 141 { \
dcubed@3202 142 char* data = NULL; \
dcubed@3202 143 int len = 0; \
dcubed@3202 144 Symbol* name = (clss)->name(); \
dcubed@3202 145 if (name != NULL) { \
dcubed@3202 146 data = (char*)name->bytes(); \
dcubed@3202 147 len = name->utf8_length(); \
dcubed@3202 148 } \
dcubed@3202 149 HOTSPOT_CLASS_INITIALIZATION_##type( \
sgehwolf@9721 150 data, len, (void *)(clss)->class_loader(), thread_type); \
dcubed@3202 151 }
dcubed@3202 152
dcubed@3202 153 #define DTRACE_CLASSINIT_PROBE_WAIT(type, clss, thread_type, wait) \
dcubed@3202 154 { \
dcubed@3202 155 char* data = NULL; \
dcubed@3202 156 int len = 0; \
dcubed@3202 157 Symbol* name = (clss)->name(); \
dcubed@3202 158 if (name != NULL) { \
dcubed@3202 159 data = (char*)name->bytes(); \
dcubed@3202 160 len = name->utf8_length(); \
dcubed@3202 161 } \
dcubed@3202 162 HOTSPOT_CLASS_INITIALIZATION_##type( \
sgehwolf@9721 163 data, len, (void *)(clss)->class_loader(), thread_type, wait); \
dcubed@3202 164 }
dcubed@3202 165 #endif /* USDT2 */
fparain@1759 166
fparain@1759 167 #else // ndef DTRACE_ENABLED
fparain@1759 168
fparain@1759 169 #define DTRACE_CLASSINIT_PROBE(type, clss, thread_type)
fparain@1759 170 #define DTRACE_CLASSINIT_PROBE_WAIT(type, clss, thread_type, wait)
fparain@1759 171
fparain@1759 172 #endif // ndef DTRACE_ENABLED
fparain@1759 173
zgu@4400 174 volatile int InstanceKlass::_total_instanceKlass_count = 0;
zgu@4400 175
coleenp@4719 176 InstanceKlass* InstanceKlass::allocate_instance_klass(
coleenp@4719 177 ClassLoaderData* loader_data,
coleenp@4572 178 int vtable_len,
coleenp@4572 179 int itable_len,
coleenp@4572 180 int static_field_size,
coleenp@4572 181 int nonstatic_oop_map_size,
coleenp@4572 182 ReferenceType rt,
coleenp@4572 183 AccessFlags access_flags,
coleenp@4572 184 Symbol* name,
coleenp@4037 185 Klass* super_klass,
coleenp@4572 186 bool is_anonymous,
coleenp@4572 187 TRAPS) {
coleenp@4037 188
coleenp@4037 189 int size = InstanceKlass::size(vtable_len, itable_len, nonstatic_oop_map_size,
coleenp@4572 190 access_flags.is_interface(), is_anonymous);
coleenp@4037 191
coleenp@4037 192 // Allocation
coleenp@4037 193 InstanceKlass* ik;
coleenp@4037 194 if (rt == REF_NONE) {
coleenp@4037 195 if (name == vmSymbols::java_lang_Class()) {
coleenp@4047 196 ik = new (loader_data, size, THREAD) InstanceMirrorKlass(
coleenp@4037 197 vtable_len, itable_len, static_field_size, nonstatic_oop_map_size, rt,
coleenp@4572 198 access_flags, is_anonymous);
coleenp@4037 199 } else if (name == vmSymbols::java_lang_ClassLoader() ||
coleenp@4037 200 (SystemDictionary::ClassLoader_klass_loaded() &&
coleenp@4037 201 super_klass != NULL &&
coleenp@4037 202 super_klass->is_subtype_of(SystemDictionary::ClassLoader_klass()))) {
coleenp@4047 203 ik = new (loader_data, size, THREAD) InstanceClassLoaderKlass(
coleenp@4037 204 vtable_len, itable_len, static_field_size, nonstatic_oop_map_size, rt,
coleenp@4572 205 access_flags, is_anonymous);
coleenp@4037 206 } else {
coleenp@4037 207 // normal class
coleenp@4037 208 ik = new (loader_data, size, THREAD) InstanceKlass(
coleenp@4037 209 vtable_len, itable_len, static_field_size, nonstatic_oop_map_size, rt,
coleenp@4572 210 access_flags, is_anonymous);
coleenp@4037 211 }
coleenp@4037 212 } else {
coleenp@4037 213 // reference klass
coleenp@4047 214 ik = new (loader_data, size, THREAD) InstanceRefKlass(
coleenp@4037 215 vtable_len, itable_len, static_field_size, nonstatic_oop_map_size, rt,
coleenp@4572 216 access_flags, is_anonymous);
coleenp@4037 217 }
coleenp@4037 218
coleenp@4719 219 // Check for pending exception before adding to the loader data and incrementing
coleenp@4719 220 // class count. Can get OOM here.
coleenp@4719 221 if (HAS_PENDING_EXCEPTION) {
coleenp@4719 222 return NULL;
coleenp@4719 223 }
coleenp@4719 224
coleenp@4719 225 // Add all classes to our internal class loader list here,
coleenp@4719 226 // including classes in the bootstrap (NULL) class loader.
coleenp@4719 227 loader_data->add_class(ik);
coleenp@4719 228
zgu@4400 229 Atomic::inc(&_total_instanceKlass_count);
coleenp@4037 230 return ik;
coleenp@4037 231 }
coleenp@4037 232
coleenp@4719 233
coleenp@4719 234 // copy method ordering from resource area to Metaspace
coleenp@4719 235 void InstanceKlass::copy_method_ordering(intArray* m, TRAPS) {
coleenp@4719 236 if (m != NULL) {
coleenp@4719 237 // allocate a new array and copy contents (memcpy?)
coleenp@4719 238 _method_ordering = MetadataFactory::new_array<int>(class_loader_data(), m->length(), CHECK);
coleenp@4719 239 for (int i = 0; i < m->length(); i++) {
coleenp@4719 240 _method_ordering->at_put(i, m->at(i));
coleenp@4719 241 }
coleenp@4719 242 } else {
coleenp@4719 243 _method_ordering = Universe::the_empty_int_array();
coleenp@4719 244 }
coleenp@4719 245 }
coleenp@4719 246
acorn@5848 247 // create a new array of vtable_indices for default methods
acorn@5848 248 Array<int>* InstanceKlass::create_new_default_vtable_indices(int len, TRAPS) {
acorn@5848 249 Array<int>* vtable_indices = MetadataFactory::new_array<int>(class_loader_data(), len, CHECK_NULL);
acorn@5848 250 assert(default_vtable_indices() == NULL, "only create once");
acorn@5848 251 set_default_vtable_indices(vtable_indices);
acorn@5848 252 return vtable_indices;
acorn@5848 253 }
coleenp@4719 254
coleenp@4037 255 InstanceKlass::InstanceKlass(int vtable_len,
coleenp@4037 256 int itable_len,
coleenp@4037 257 int static_field_size,
coleenp@4037 258 int nonstatic_oop_map_size,
coleenp@4037 259 ReferenceType rt,
coleenp@4037 260 AccessFlags access_flags,
coleenp@4037 261 bool is_anonymous) {
coleenp@4037 262 No_Safepoint_Verifier no_safepoint; // until k becomes parsable
coleenp@4037 263
coleenp@4712 264 int iksize = InstanceKlass::size(vtable_len, itable_len, nonstatic_oop_map_size,
coleenp@4712 265 access_flags.is_interface(), is_anonymous);
coleenp@4037 266
coleenp@4712 267 set_vtable_length(vtable_len);
coleenp@4712 268 set_itable_length(itable_len);
coleenp@4712 269 set_static_field_size(static_field_size);
coleenp@4712 270 set_nonstatic_oop_map_size(nonstatic_oop_map_size);
coleenp@4712 271 set_access_flags(access_flags);
coleenp@4712 272 _misc_flags = 0; // initialize to zero
coleenp@4712 273 set_is_anonymous(is_anonymous);
coleenp@4712 274 assert(size() == iksize, "wrong size for object");
coleenp@4712 275
coleenp@4712 276 set_array_klasses(NULL);
coleenp@4712 277 set_methods(NULL);
coleenp@4712 278 set_method_ordering(NULL);
acorn@5848 279 set_default_methods(NULL);
acorn@5848 280 set_default_vtable_indices(NULL);
coleenp@4712 281 set_local_interfaces(NULL);
coleenp@4712 282 set_transitive_interfaces(NULL);
coleenp@4712 283 init_implementor();
coleenp@4712 284 set_fields(NULL, 0);
coleenp@4712 285 set_constants(NULL);
coleenp@4712 286 set_class_loader_data(NULL);
jiangli@5535 287 set_source_file_name_index(0);
coleenp@4712 288 set_source_debug_extension(NULL, 0);
coleenp@4712 289 set_array_name(NULL);
coleenp@4712 290 set_inner_classes(NULL);
coleenp@4712 291 set_static_oop_field_count(0);
coleenp@4712 292 set_nonstatic_field_size(0);
coleenp@4712 293 set_is_marked_dependent(false);
stefank@6992 294 set_has_unloaded_dependent(false);
coleenp@4712 295 set_init_state(InstanceKlass::allocated);
coleenp@4712 296 set_init_thread(NULL);
coleenp@4712 297 set_reference_type(rt);
coleenp@4712 298 set_oop_map_cache(NULL);
coleenp@4712 299 set_jni_ids(NULL);
coleenp@4712 300 set_osr_nmethods_head(NULL);
coleenp@4712 301 set_breakpoints(NULL);
coleenp@4712 302 init_previous_versions();
jiangli@5535 303 set_generic_signature_index(0);
coleenp@4712 304 release_set_methods_jmethod_ids(NULL);
coleenp@4712 305 set_annotations(NULL);
coleenp@4712 306 set_jvmti_cached_class_field_map(NULL);
coleenp@4712 307 set_initial_method_idnum(0);
coleenp@4712 308 _dependencies = NULL;
coleenp@4712 309 set_jvmti_cached_class_field_map(NULL);
jiangli@5421 310 set_cached_class_file(NULL);
coleenp@4712 311 set_initial_method_idnum(0);
coleenp@4712 312 set_minor_version(0);
coleenp@4712 313 set_major_version(0);
coleenp@4712 314 NOT_PRODUCT(_verify_count = 0;)
coleenp@4037 315
coleenp@4037 316 // initialize the non-header words to zero
coleenp@4037 317 intptr_t* p = (intptr_t*)this;
coleenp@4712 318 for (int index = InstanceKlass::header_size(); index < iksize; index++) {
coleenp@4037 319 p[index] = NULL_WORD;
coleenp@4037 320 }
coleenp@4037 321
coleenp@4037 322 // Set temporary value until parseClassFile updates it with the real instance
coleenp@4037 323 // size.
coleenp@4712 324 set_layout_helper(Klass::instance_layout_helper(0, true));
coleenp@4037 325 }
coleenp@4037 326
coleenp@4037 327
coleenp@4719 328 void InstanceKlass::deallocate_methods(ClassLoaderData* loader_data,
coleenp@4719 329 Array<Method*>* methods) {
hseigel@5896 330 if (methods != NULL && methods != Universe::the_empty_method_array() &&
hseigel@5896 331 !methods->is_shared()) {
coleenp@4719 332 for (int i = 0; i < methods->length(); i++) {
coleenp@4719 333 Method* method = methods->at(i);
coleenp@4719 334 if (method == NULL) continue; // maybe null if error processing
coleenp@4719 335 // Only want to delete methods that are not executing for RedefineClasses.
coleenp@4719 336 // The previous version will point to them so they're not totally dangling
coleenp@4719 337 assert (!method->on_stack(), "shouldn't be called with methods on stack");
coleenp@4719 338 MetadataFactory::free_metadata(loader_data, method);
coleenp@4719 339 }
coleenp@4719 340 MetadataFactory::free_array<Method*>(loader_data, methods);
coleenp@4719 341 }
coleenp@4719 342 }
coleenp@4719 343
coleenp@4719 344 void InstanceKlass::deallocate_interfaces(ClassLoaderData* loader_data,
coleenp@4719 345 Klass* super_klass,
coleenp@4719 346 Array<Klass*>* local_interfaces,
coleenp@4719 347 Array<Klass*>* transitive_interfaces) {
coleenp@4719 348 // Only deallocate transitive interfaces if not empty, same as super class
coleenp@4719 349 // or same as local interfaces. See code in parseClassFile.
coleenp@4719 350 Array<Klass*>* ti = transitive_interfaces;
coleenp@4719 351 if (ti != Universe::the_empty_klass_array() && ti != local_interfaces) {
coleenp@4719 352 // check that the interfaces don't come from super class
coleenp@4719 353 Array<Klass*>* sti = (super_klass == NULL) ? NULL :
coleenp@4719 354 InstanceKlass::cast(super_klass)->transitive_interfaces();
hseigel@5896 355 if (ti != sti && ti != NULL && !ti->is_shared()) {
coleenp@4719 356 MetadataFactory::free_array<Klass*>(loader_data, ti);
coleenp@4719 357 }
coleenp@4719 358 }
coleenp@4719 359
coleenp@4719 360 // local interfaces can be empty
hseigel@5896 361 if (local_interfaces != Universe::the_empty_klass_array() &&
hseigel@5896 362 local_interfaces != NULL && !local_interfaces->is_shared()) {
coleenp@4719 363 MetadataFactory::free_array<Klass*>(loader_data, local_interfaces);
coleenp@4719 364 }
coleenp@4719 365 }
coleenp@4719 366
coleenp@4037 367 // This function deallocates the metadata and C heap pointers that the
coleenp@4037 368 // InstanceKlass points to.
coleenp@4037 369 void InstanceKlass::deallocate_contents(ClassLoaderData* loader_data) {
coleenp@4037 370
coleenp@4037 371 // Orphan the mirror first, CMS thinks it's still live.
coleenp@4719 372 if (java_mirror() != NULL) {
coleenp@4719 373 java_lang_Class::set_klass(java_mirror(), NULL);
coleenp@4719 374 }
coleenp@4037 375
coleenp@4037 376 // Need to take this class off the class loader data list.
coleenp@4037 377 loader_data->remove_class(this);
coleenp@4037 378
coleenp@4037 379 // The array_klass for this class is created later, after error handling.
coleenp@4037 380 // For class redefinition, we keep the original class so this scratch class
coleenp@4037 381 // doesn't have an array class. Either way, assert that there is nothing
coleenp@4037 382 // to deallocate.
coleenp@4037 383 assert(array_klasses() == NULL, "array classes shouldn't be created for this class yet");
coleenp@4037 384
coleenp@4037 385 // Release C heap allocated data that this might point to, which includes
coleenp@4037 386 // reference counting symbol names.
coleenp@4037 387 release_C_heap_structures();
coleenp@4037 388
coleenp@4719 389 deallocate_methods(loader_data, methods());
coleenp@4037 390 set_methods(NULL);
coleenp@4037 391
hseigel@5896 392 if (method_ordering() != NULL &&
hseigel@5896 393 method_ordering() != Universe::the_empty_int_array() &&
hseigel@5896 394 !method_ordering()->is_shared()) {
coleenp@4037 395 MetadataFactory::free_array<int>(loader_data, method_ordering());
coleenp@4037 396 }
coleenp@4037 397 set_method_ordering(NULL);
coleenp@4037 398
acorn@5848 399 // default methods can be empty
acorn@5848 400 if (default_methods() != NULL &&
hseigel@5896 401 default_methods() != Universe::the_empty_method_array() &&
hseigel@5896 402 !default_methods()->is_shared()) {
acorn@5848 403 MetadataFactory::free_array<Method*>(loader_data, default_methods());
acorn@5848 404 }
acorn@5848 405 // Do NOT deallocate the default methods, they are owned by superinterfaces.
acorn@5848 406 set_default_methods(NULL);
acorn@5848 407
acorn@5848 408 // default methods vtable indices can be empty
hseigel@5896 409 if (default_vtable_indices() != NULL &&
hseigel@5896 410 !default_vtable_indices()->is_shared()) {
acorn@5848 411 MetadataFactory::free_array<int>(loader_data, default_vtable_indices());
acorn@5848 412 }
acorn@5848 413 set_default_vtable_indices(NULL);
acorn@5848 414
acorn@5848 415
coleenp@4037 416 // This array is in Klass, but remove it with the InstanceKlass since
coleenp@4037 417 // this place would be the only caller and it can share memory with transitive
coleenp@4037 418 // interfaces.
hseigel@5896 419 if (secondary_supers() != NULL &&
hseigel@5896 420 secondary_supers() != Universe::the_empty_klass_array() &&
hseigel@5896 421 secondary_supers() != transitive_interfaces() &&
hseigel@5896 422 !secondary_supers()->is_shared()) {
coleenp@4037 423 MetadataFactory::free_array<Klass*>(loader_data, secondary_supers());
coleenp@4037 424 }
coleenp@4037 425 set_secondary_supers(NULL);
coleenp@4037 426
coleenp@4719 427 deallocate_interfaces(loader_data, super(), local_interfaces(), transitive_interfaces());
coleenp@4037 428 set_transitive_interfaces(NULL);
coleenp@4037 429 set_local_interfaces(NULL);
coleenp@4037 430
hseigel@5896 431 if (fields() != NULL && !fields()->is_shared()) {
hseigel@5896 432 MetadataFactory::free_array<jushort>(loader_data, fields());
hseigel@5896 433 }
coleenp@4037 434 set_fields(NULL, 0);
coleenp@4037 435
coleenp@4037 436 // If a method from a redefined class is using this constant pool, don't
coleenp@4037 437 // delete it, yet. The new class's previous version will point to this.
coleenp@4719 438 if (constants() != NULL) {
coleenp@4719 439 assert (!constants()->on_stack(), "shouldn't be called if anything is onstack");
hseigel@5896 440 if (!constants()->is_shared()) {
hseigel@5896 441 MetadataFactory::free_metadata(loader_data, constants());
hseigel@5896 442 }
aeriksso@8042 443 // Delete any cached resolution errors for the constant pool
aeriksso@8042 444 SystemDictionary::delete_resolution_error(constants());
aeriksso@8042 445
coleenp@4719 446 set_constants(NULL);
coleenp@4719 447 }
coleenp@4037 448
hseigel@5896 449 if (inner_classes() != NULL &&
hseigel@5896 450 inner_classes() != Universe::the_empty_short_array() &&
hseigel@5896 451 !inner_classes()->is_shared()) {
coleenp@4037 452 MetadataFactory::free_array<jushort>(loader_data, inner_classes());
coleenp@4037 453 }
coleenp@4037 454 set_inner_classes(NULL);
coleenp@4037 455
hseigel@5896 456 // We should deallocate the Annotations instance if it's not in shared spaces.
hseigel@5896 457 if (annotations() != NULL && !annotations()->is_shared()) {
hseigel@5896 458 MetadataFactory::free_metadata(loader_data, annotations());
hseigel@5896 459 }
coleenp@4037 460 set_annotations(NULL);
coleenp@4037 461 }
coleenp@4037 462
coleenp@4037 463 bool InstanceKlass::should_be_initialized() const {
duke@435 464 return !is_initialized();
duke@435 465 }
duke@435 466
coleenp@4037 467 klassVtable* InstanceKlass::vtable() const {
coleenp@4037 468 return new klassVtable(this, start_of_vtable(), vtable_length() / vtableEntry::size());
duke@435 469 }
duke@435 470
coleenp@4037 471 klassItable* InstanceKlass::itable() const {
coleenp@4037 472 return new klassItable(instanceKlassHandle(this));
duke@435 473 }
duke@435 474
coleenp@4037 475 void InstanceKlass::eager_initialize(Thread *thread) {
duke@435 476 if (!EagerInitialization) return;
duke@435 477
duke@435 478 if (this->is_not_initialized()) {
duke@435 479 // abort if the the class has a class initializer
duke@435 480 if (this->class_initializer() != NULL) return;
duke@435 481
duke@435 482 // abort if it is java.lang.Object (initialization is handled in genesis)
coleenp@4037 483 Klass* super = this->super();
duke@435 484 if (super == NULL) return;
duke@435 485
duke@435 486 // abort if the super class should be initialized
coleenp@4037 487 if (!InstanceKlass::cast(super)->is_initialized()) return;
duke@435 488
duke@435 489 // call body to expose the this pointer
coleenp@4037 490 instanceKlassHandle this_oop(thread, this);
duke@435 491 eager_initialize_impl(this_oop);
duke@435 492 }
duke@435 493 }
duke@435 494
coleenp@5176 495 // JVMTI spec thinks there are signers and protection domain in the
coleenp@5176 496 // instanceKlass. These accessors pretend these fields are there.
coleenp@5176 497 // The hprof specification also thinks these fields are in InstanceKlass.
coleenp@5176 498 oop InstanceKlass::protection_domain() const {
coleenp@5176 499 // return the protection_domain from the mirror
coleenp@5176 500 return java_lang_Class::protection_domain(java_mirror());
coleenp@5176 501 }
coleenp@5176 502
coleenp@5176 503 // To remove these from requires an incompatible change and CCC request.
coleenp@5176 504 objArrayOop InstanceKlass::signers() const {
coleenp@5176 505 // return the signers from the mirror
coleenp@5176 506 return java_lang_Class::signers(java_mirror());
coleenp@5176 507 }
coleenp@5176 508
coleenp@5836 509 oop InstanceKlass::init_lock() const {
coleenp@5176 510 // return the init lock from the mirror
iklam@5971 511 oop lock = java_lang_Class::init_lock(java_mirror());
dholmes@7191 512 // Prevent reordering with any access of initialization state
dholmes@7191 513 OrderAccess::loadload();
iklam@5971 514 assert((oop)lock != NULL || !is_not_initialized(), // initialized or in_error state
iklam@5971 515 "only fully initialized state can have a null lock");
iklam@5971 516 return lock;
iklam@5971 517 }
iklam@5971 518
iklam@5971 519 // Set the initialization lock to null so the object can be GC'ed. Any racing
iklam@5971 520 // threads to get this lock will see a null lock and will not lock.
iklam@5971 521 // That's okay because they all check for initialized state after getting
iklam@5971 522 // the lock and return.
iklam@5971 523 void InstanceKlass::fence_and_clear_init_lock() {
iklam@5971 524 // make sure previous stores are all done, notably the init_state.
iklam@5971 525 OrderAccess::storestore();
iklam@5971 526 java_lang_Class::set_init_lock(java_mirror(), NULL);
iklam@5971 527 assert(!is_not_initialized(), "class must be initialized now");
coleenp@5176 528 }
duke@435 529
coleenp@4037 530 void InstanceKlass::eager_initialize_impl(instanceKlassHandle this_oop) {
duke@435 531 EXCEPTION_MARK;
coleenp@5836 532 oop init_lock = this_oop->init_lock();
iklam@5971 533 ObjectLocker ol(init_lock, THREAD, init_lock != NULL);
duke@435 534
duke@435 535 // abort if someone beat us to the initialization
duke@435 536 if (!this_oop->is_not_initialized()) return; // note: not equivalent to is_initialized()
duke@435 537
coleenp@3368 538 ClassState old_state = this_oop->init_state();
duke@435 539 link_class_impl(this_oop, true, THREAD);
duke@435 540 if (HAS_PENDING_EXCEPTION) {
duke@435 541 CLEAR_PENDING_EXCEPTION;
duke@435 542 // Abort if linking the class throws an exception.
duke@435 543
duke@435 544 // Use a test to avoid redundantly resetting the state if there's
duke@435 545 // no change. Set_init_state() asserts that state changes make
duke@435 546 // progress, whereas here we might just be spinning in place.
duke@435 547 if( old_state != this_oop->_init_state )
duke@435 548 this_oop->set_init_state (old_state);
duke@435 549 } else {
duke@435 550 // linking successfull, mark class as initialized
duke@435 551 this_oop->set_init_state (fully_initialized);
iklam@5971 552 this_oop->fence_and_clear_init_lock();
duke@435 553 // trace
duke@435 554 if (TraceClassInitialization) {
duke@435 555 ResourceMark rm(THREAD);
duke@435 556 tty->print_cr("[Initialized %s without side effects]", this_oop->external_name());
duke@435 557 }
duke@435 558 }
duke@435 559 }
duke@435 560
duke@435 561
duke@435 562 // See "The Virtual Machine Specification" section 2.16.5 for a detailed explanation of the class initialization
duke@435 563 // process. The step comments refers to the procedure described in that section.
duke@435 564 // Note: implementation moved to static method to expose the this pointer.
coleenp@4037 565 void InstanceKlass::initialize(TRAPS) {
duke@435 566 if (this->should_be_initialized()) {
duke@435 567 HandleMark hm(THREAD);
coleenp@4037 568 instanceKlassHandle this_oop(THREAD, this);
duke@435 569 initialize_impl(this_oop, CHECK);
duke@435 570 // Note: at this point the class may be initialized
duke@435 571 // OR it may be in the state of being initialized
duke@435 572 // in case of recursive initialization!
duke@435 573 } else {
duke@435 574 assert(is_initialized(), "sanity check");
duke@435 575 }
duke@435 576 }
duke@435 577
duke@435 578
coleenp@4037 579 bool InstanceKlass::verify_code(
duke@435 580 instanceKlassHandle this_oop, bool throw_verifyerror, TRAPS) {
duke@435 581 // 1) Verify the bytecodes
duke@435 582 Verifier::Mode mode =
duke@435 583 throw_verifyerror ? Verifier::ThrowException : Verifier::NoException;
phh@9507 584 return Verifier::verify(this_oop, mode, this_oop->should_verify_class(), THREAD);
duke@435 585 }
duke@435 586
duke@435 587
duke@435 588 // Used exclusively by the shared spaces dump mechanism to prevent
duke@435 589 // classes mapped into the shared regions in new VMs from appearing linked.
duke@435 590
coleenp@4037 591 void InstanceKlass::unlink_class() {
duke@435 592 assert(is_linked(), "must be linked");
duke@435 593 _init_state = loaded;
duke@435 594 }
duke@435 595
coleenp@4037 596 void InstanceKlass::link_class(TRAPS) {
duke@435 597 assert(is_loaded(), "must be loaded");
duke@435 598 if (!is_linked()) {
coleenp@4037 599 HandleMark hm(THREAD);
coleenp@4037 600 instanceKlassHandle this_oop(THREAD, this);
duke@435 601 link_class_impl(this_oop, true, CHECK);
duke@435 602 }
duke@435 603 }
duke@435 604
duke@435 605 // Called to verify that a class can link during initialization, without
duke@435 606 // throwing a VerifyError.
coleenp@4037 607 bool InstanceKlass::link_class_or_fail(TRAPS) {
duke@435 608 assert(is_loaded(), "must be loaded");
duke@435 609 if (!is_linked()) {
coleenp@4037 610 HandleMark hm(THREAD);
coleenp@4037 611 instanceKlassHandle this_oop(THREAD, this);
duke@435 612 link_class_impl(this_oop, false, CHECK_false);
duke@435 613 }
duke@435 614 return is_linked();
duke@435 615 }
duke@435 616
coleenp@4037 617 bool InstanceKlass::link_class_impl(
duke@435 618 instanceKlassHandle this_oop, bool throw_verifyerror, TRAPS) {
coleenp@8640 619 // check for error state.
coleenp@8640 620 // This is checking for the wrong state. If the state is initialization_error,
coleenp@8640 621 // then this class *was* linked. The CDS code does a try_link_class and uses
coleenp@8640 622 // initialization_error to mark classes to not include in the archive during
coleenp@8640 623 // DumpSharedSpaces. This should be removed when the CDS bug is fixed.
duke@435 624 if (this_oop->is_in_error_state()) {
duke@435 625 ResourceMark rm(THREAD);
duke@435 626 THROW_MSG_(vmSymbols::java_lang_NoClassDefFoundError(),
duke@435 627 this_oop->external_name(), false);
duke@435 628 }
duke@435 629 // return if already verified
duke@435 630 if (this_oop->is_linked()) {
duke@435 631 return true;
duke@435 632 }
duke@435 633
duke@435 634 // Timing
duke@435 635 // timer handles recursion
duke@435 636 assert(THREAD->is_Java_thread(), "non-JavaThread in link_class_impl");
duke@435 637 JavaThread* jt = (JavaThread*)THREAD;
duke@435 638
duke@435 639 // link super class before linking this class
duke@435 640 instanceKlassHandle super(THREAD, this_oop->super());
duke@435 641 if (super.not_null()) {
duke@435 642 if (super->is_interface()) { // check if super class is an interface
duke@435 643 ResourceMark rm(THREAD);
duke@435 644 Exceptions::fthrow(
duke@435 645 THREAD_AND_LOCATION,
coleenp@2497 646 vmSymbols::java_lang_IncompatibleClassChangeError(),
duke@435 647 "class %s has interface %s as super class",
duke@435 648 this_oop->external_name(),
duke@435 649 super->external_name()
duke@435 650 );
duke@435 651 return false;
duke@435 652 }
duke@435 653
duke@435 654 link_class_impl(super, throw_verifyerror, CHECK_false);
duke@435 655 }
duke@435 656
duke@435 657 // link all interfaces implemented by this class before linking this class
coleenp@4037 658 Array<Klass*>* interfaces = this_oop->local_interfaces();
duke@435 659 int num_interfaces = interfaces->length();
duke@435 660 for (int index = 0; index < num_interfaces; index++) {
duke@435 661 HandleMark hm(THREAD);
coleenp@4037 662 instanceKlassHandle ih(THREAD, interfaces->at(index));
duke@435 663 link_class_impl(ih, throw_verifyerror, CHECK_false);
duke@435 664 }
duke@435 665
duke@435 666 // in case the class is linked in the process of linking its superclasses
duke@435 667 if (this_oop->is_linked()) {
duke@435 668 return true;
duke@435 669 }
duke@435 670
mchung@1310 671 // trace only the link time for this klass that includes
mchung@1310 672 // the verification time
mchung@1310 673 PerfClassTraceTime vmtimer(ClassLoader::perf_class_link_time(),
mchung@1310 674 ClassLoader::perf_class_link_selftime(),
mchung@1310 675 ClassLoader::perf_classes_linked(),
mchung@1310 676 jt->get_thread_stat()->perf_recursion_counts_addr(),
mchung@1310 677 jt->get_thread_stat()->perf_timers_addr(),
mchung@1310 678 PerfClassTraceTime::CLASS_LINK);
mchung@1310 679
duke@435 680 // verification & rewriting
duke@435 681 {
coleenp@5836 682 oop init_lock = this_oop->init_lock();
iklam@5971 683 ObjectLocker ol(init_lock, THREAD, init_lock != NULL);
duke@435 684 // rewritten will have been set if loader constraint error found
duke@435 685 // on an earlier link attempt
duke@435 686 // don't verify or rewrite if already rewritten
coleenp@4037 687
duke@435 688 if (!this_oop->is_linked()) {
duke@435 689 if (!this_oop->is_rewritten()) {
duke@435 690 {
duke@435 691 // Timer includes any side effects of class verification (resolution,
duke@435 692 // etc), but not recursive entry into verify_code().
mchung@1310 693 PerfClassTraceTime timer(ClassLoader::perf_class_verify_time(),
mchung@1310 694 ClassLoader::perf_class_verify_selftime(),
mchung@1310 695 ClassLoader::perf_classes_verified(),
mchung@1310 696 jt->get_thread_stat()->perf_recursion_counts_addr(),
mchung@1310 697 jt->get_thread_stat()->perf_timers_addr(),
mchung@1310 698 PerfClassTraceTime::CLASS_VERIFY);
duke@435 699 bool verify_ok = verify_code(this_oop, throw_verifyerror, THREAD);
duke@435 700 if (!verify_ok) {
duke@435 701 return false;
duke@435 702 }
duke@435 703 }
duke@435 704
duke@435 705 // Just in case a side-effect of verify linked this class already
duke@435 706 // (which can sometimes happen since the verifier loads classes
duke@435 707 // using custom class loaders, which are free to initialize things)
duke@435 708 if (this_oop->is_linked()) {
duke@435 709 return true;
duke@435 710 }
duke@435 711
duke@435 712 // also sets rewritten
duke@435 713 this_oop->rewrite_class(CHECK_false);
iklam@8497 714 } else if (this_oop()->is_shared()) {
iklam@8497 715 ResourceMark rm(THREAD);
iklam@8497 716 char* message_buffer; // res-allocated by check_verification_dependencies
iklam@8497 717 Handle loader = this_oop()->class_loader();
iklam@8497 718 Handle pd = this_oop()->protection_domain();
iklam@8497 719 bool verified = SystemDictionaryShared::check_verification_dependencies(this_oop(),
iklam@8497 720 loader, pd, &message_buffer, THREAD);
iklam@8497 721 if (!verified) {
iklam@8497 722 THROW_MSG_(vmSymbols::java_lang_VerifyError(), message_buffer, false);
iklam@8497 723 }
duke@435 724 }
duke@435 725
coleenp@2945 726 // relocate jsrs and link methods after they are all rewritten
coleenp@4395 727 this_oop->link_methods(CHECK_false);
coleenp@2945 728
duke@435 729 // Initialize the vtable and interface table after
duke@435 730 // methods have been rewritten since rewrite may
coleenp@4037 731 // fabricate new Method*s.
duke@435 732 // also does loader constraint checking
jiangli@8509 733 //
jiangli@8509 734 // Initialize_vtable and initialize_itable need to be rerun for
jiangli@8509 735 // a shared class if the class is not loaded by the NULL classloader.
jiangli@8509 736 ClassLoaderData * loader_data = this_oop->class_loader_data();
jiangli@8509 737 if (!(this_oop()->is_shared() &&
jiangli@8509 738 loader_data->is_the_null_class_loader_data())) {
duke@435 739 ResourceMark rm(THREAD);
duke@435 740 this_oop->vtable()->initialize_vtable(true, CHECK_false);
duke@435 741 this_oop->itable()->initialize_itable(true, CHECK_false);
duke@435 742 }
duke@435 743 #ifdef ASSERT
duke@435 744 else {
duke@435 745 ResourceMark rm(THREAD);
duke@435 746 this_oop->vtable()->verify(tty, true);
duke@435 747 // In case itable verification is ever added.
duke@435 748 // this_oop->itable()->verify(tty, true);
duke@435 749 }
duke@435 750 #endif
duke@435 751 this_oop->set_init_state(linked);
duke@435 752 if (JvmtiExport::should_post_class_prepare()) {
duke@435 753 Thread *thread = THREAD;
duke@435 754 assert(thread->is_Java_thread(), "thread->is_Java_thread()");
duke@435 755 JvmtiExport::post_class_prepare((JavaThread *) thread, this_oop());
duke@435 756 }
duke@435 757 }
duke@435 758 }
duke@435 759 return true;
duke@435 760 }
duke@435 761
duke@435 762
duke@435 763 // Rewrite the byte codes of all of the methods of a class.
duke@435 764 // The rewriter must be called exactly once. Rewriting must happen after
duke@435 765 // verification but before the first method of the class is executed.
coleenp@4037 766 void InstanceKlass::rewrite_class(TRAPS) {
duke@435 767 assert(is_loaded(), "must be loaded");
coleenp@4037 768 instanceKlassHandle this_oop(THREAD, this);
duke@435 769 if (this_oop->is_rewritten()) {
duke@435 770 assert(this_oop()->is_shared(), "rewriting an unshared class?");
duke@435 771 return;
duke@435 772 }
coleenp@2945 773 Rewriter::rewrite(this_oop, CHECK);
duke@435 774 this_oop->set_rewritten();
duke@435 775 }
duke@435 776
coleenp@2945 777 // Now relocate and link method entry points after class is rewritten.
coleenp@2945 778 // This is outside is_rewritten flag. In case of an exception, it can be
coleenp@2945 779 // executed more than once.
coleenp@4395 780 void InstanceKlass::link_methods(TRAPS) {
coleenp@4395 781 int len = methods()->length();
coleenp@4395 782 for (int i = len-1; i >= 0; i--) {
coleenp@4395 783 methodHandle m(THREAD, methods()->at(i));
coleenp@4395 784
coleenp@4395 785 // Set up method entry points for compiler and interpreter .
coleenp@4395 786 m->link_method(m, CHECK);
coleenp@4395 787
coleenp@4395 788 // This is for JVMTI and unrelated to relocator but the last thing we do
coleenp@4395 789 #ifdef ASSERT
coleenp@4395 790 if (StressMethodComparator) {
coleenp@4395 791 ResourceMark rm(THREAD);
coleenp@4395 792 static int nmc = 0;
coleenp@4395 793 for (int j = i; j >= 0 && j >= i-4; j--) {
coleenp@4395 794 if ((++nmc % 1000) == 0) tty->print_cr("Have run MethodComparator %d times...", nmc);
coleenp@4395 795 bool z = MethodComparator::methods_EMCP(m(),
coleenp@4395 796 methods()->at(j));
coleenp@4395 797 if (j == i && !z) {
coleenp@4395 798 tty->print("MethodComparator FAIL: "); m->print(); m->print_codes();
coleenp@4395 799 assert(z, "method must compare equal to itself");
coleenp@4395 800 }
coleenp@4395 801 }
coleenp@4395 802 }
coleenp@4395 803 #endif //ASSERT
coleenp@4395 804 }
coleenp@2945 805 }
coleenp@2945 806
acorn@7290 807 // Eagerly initialize superinterfaces that declare default methods (concrete instance: any access)
coleenp@8640 808 void InstanceKlass::initialize_super_interfaces(instanceKlassHandle this_k, TRAPS) {
coleenp@8640 809 assert (this_k->has_default_methods(), "caller should have checked this");
coleenp@8640 810 for (int i = 0; i < this_k->local_interfaces()->length(); ++i) {
coleenp@8640 811 Klass* iface = this_k->local_interfaces()->at(i);
coleenp@8640 812 InstanceKlass* ik = InstanceKlass::cast(iface);
coleenp@8640 813
coleenp@8640 814 // Initialization is depth first search ie. we start with top of the inheritance tree
coleenp@8640 815 // has_default_methods drives searching superinterfaces since it
coleenp@8640 816 // means has_default_methods in its superinterface hierarchy
coleenp@8640 817 if (ik->has_default_methods()) {
coleenp@8640 818 ik->initialize_super_interfaces(ik, CHECK);
coleenp@8640 819 }
coleenp@8640 820
coleenp@8640 821 // Only initialize() interfaces that "declare" concrete methods.
coleenp@8640 822 if (ik->should_be_initialized() && ik->declares_default_methods()) {
coleenp@8640 823 ik->initialize(CHECK);
acorn@7290 824 }
acorn@7290 825 }
acorn@7290 826 }
duke@435 827
coleenp@4037 828 void InstanceKlass::initialize_impl(instanceKlassHandle this_oop, TRAPS) {
duke@435 829 // Make sure klass is linked (verified) before initialization
duke@435 830 // A class could already be verified, since it has been reflected upon.
duke@435 831 this_oop->link_class(CHECK);
duke@435 832
coleenp@4037 833 DTRACE_CLASSINIT_PROBE(required, InstanceKlass::cast(this_oop()), -1);
fparain@1759 834
fparain@1759 835 bool wait = false;
fparain@1759 836
duke@435 837 // refer to the JVM book page 47 for description of steps
duke@435 838 // Step 1
coleenp@4037 839 {
coleenp@5836 840 oop init_lock = this_oop->init_lock();
iklam@5971 841 ObjectLocker ol(init_lock, THREAD, init_lock != NULL);
duke@435 842
duke@435 843 Thread *self = THREAD; // it's passed the current thread
duke@435 844
duke@435 845 // Step 2
duke@435 846 // If we were to use wait() instead of waitInterruptibly() then
duke@435 847 // we might end up throwing IE from link/symbol resolution sites
duke@435 848 // that aren't expected to throw. This would wreak havoc. See 6320309.
duke@435 849 while(this_oop->is_being_initialized() && !this_oop->is_reentrant_initialization(self)) {
fparain@1759 850 wait = true;
duke@435 851 ol.waitUninterruptibly(CHECK);
duke@435 852 }
duke@435 853
duke@435 854 // Step 3
fparain@1759 855 if (this_oop->is_being_initialized() && this_oop->is_reentrant_initialization(self)) {
coleenp@4037 856 DTRACE_CLASSINIT_PROBE_WAIT(recursive, InstanceKlass::cast(this_oop()), -1,wait);
duke@435 857 return;
fparain@1759 858 }
duke@435 859
duke@435 860 // Step 4
fparain@1759 861 if (this_oop->is_initialized()) {
coleenp@4037 862 DTRACE_CLASSINIT_PROBE_WAIT(concurrent, InstanceKlass::cast(this_oop()), -1,wait);
duke@435 863 return;
fparain@1759 864 }
duke@435 865
duke@435 866 // Step 5
duke@435 867 if (this_oop->is_in_error_state()) {
coleenp@4037 868 DTRACE_CLASSINIT_PROBE_WAIT(erroneous, InstanceKlass::cast(this_oop()), -1,wait);
duke@435 869 ResourceMark rm(THREAD);
duke@435 870 const char* desc = "Could not initialize class ";
duke@435 871 const char* className = this_oop->external_name();
duke@435 872 size_t msglen = strlen(desc) + strlen(className) + 1;
kamg@2106 873 char* message = NEW_RESOURCE_ARRAY(char, msglen);
duke@435 874 if (NULL == message) {
duke@435 875 // Out of memory: can't create detailed error message
duke@435 876 THROW_MSG(vmSymbols::java_lang_NoClassDefFoundError(), className);
duke@435 877 } else {
duke@435 878 jio_snprintf(message, msglen, "%s%s", desc, className);
duke@435 879 THROW_MSG(vmSymbols::java_lang_NoClassDefFoundError(), message);
duke@435 880 }
duke@435 881 }
duke@435 882
duke@435 883 // Step 6
duke@435 884 this_oop->set_init_state(being_initialized);
duke@435 885 this_oop->set_init_thread(self);
duke@435 886 }
duke@435 887
duke@435 888 // Step 7
coleenp@8640 889 // Next, if C is a class rather than an interface, initialize its super class and super
coleenp@8640 890 // interfaces.
coleenp@8640 891 if (!this_oop->is_interface()) {
coleenp@8640 892 Klass* super_klass = this_oop->super();
coleenp@8640 893 if (super_klass != NULL && super_klass->should_be_initialized()) {
coleenp@8640 894 super_klass->initialize(THREAD);
coleenp@8640 895 }
coleenp@8640 896 // If C implements any interfaces that declares a non-abstract, non-static method,
coleenp@8640 897 // the initialization of C triggers initialization of its super interfaces.
coleenp@8640 898 // Only need to recurse if has_default_methods which includes declaring and
coleenp@8640 899 // inheriting default methods
coleenp@8640 900 if (!HAS_PENDING_EXCEPTION && this_oop->has_default_methods()) {
coleenp@8640 901 this_oop->initialize_super_interfaces(this_oop, THREAD);
coleenp@8640 902 }
coleenp@8640 903
coleenp@8640 904 // If any exceptions, complete abruptly, throwing the same exception as above.
duke@435 905 if (HAS_PENDING_EXCEPTION) {
duke@435 906 Handle e(THREAD, PENDING_EXCEPTION);
duke@435 907 CLEAR_PENDING_EXCEPTION;
duke@435 908 {
duke@435 909 EXCEPTION_MARK;
coleenp@8640 910 // Locks object, set state, and notify all waiting threads
coleenp@8640 911 this_oop->set_initialization_state_and_notify(initialization_error, THREAD);
coleenp@8640 912 CLEAR_PENDING_EXCEPTION;
duke@435 913 }
coleenp@4037 914 DTRACE_CLASSINIT_PROBE_WAIT(super__failed, InstanceKlass::cast(this_oop()), -1,wait);
duke@435 915 THROW_OOP(e());
duke@435 916 }
duke@435 917 }
duke@435 918
duke@435 919 // Step 8
duke@435 920 {
duke@435 921 assert(THREAD->is_Java_thread(), "non-JavaThread in initialize_impl");
duke@435 922 JavaThread* jt = (JavaThread*)THREAD;
coleenp@4037 923 DTRACE_CLASSINIT_PROBE_WAIT(clinit, InstanceKlass::cast(this_oop()), -1,wait);
duke@435 924 // Timer includes any side effects of class initialization (resolution,
duke@435 925 // etc), but not recursive entry into call_class_initializer().
mchung@1310 926 PerfClassTraceTime timer(ClassLoader::perf_class_init_time(),
mchung@1310 927 ClassLoader::perf_class_init_selftime(),
mchung@1310 928 ClassLoader::perf_classes_inited(),
mchung@1310 929 jt->get_thread_stat()->perf_recursion_counts_addr(),
mchung@1310 930 jt->get_thread_stat()->perf_timers_addr(),
mchung@1310 931 PerfClassTraceTime::CLASS_CLINIT);
duke@435 932 this_oop->call_class_initializer(THREAD);
duke@435 933 }
duke@435 934
duke@435 935 // Step 9
duke@435 936 if (!HAS_PENDING_EXCEPTION) {
duke@435 937 this_oop->set_initialization_state_and_notify(fully_initialized, CHECK);
duke@435 938 { ResourceMark rm(THREAD);
duke@435 939 debug_only(this_oop->vtable()->verify(tty, true);)
duke@435 940 }
duke@435 941 }
duke@435 942 else {
duke@435 943 // Step 10 and 11
duke@435 944 Handle e(THREAD, PENDING_EXCEPTION);
duke@435 945 CLEAR_PENDING_EXCEPTION;
jbachorik@7812 946 // JVMTI has already reported the pending exception
jbachorik@7812 947 // JVMTI internal flag reset is needed in order to report ExceptionInInitializerError
jbachorik@7812 948 JvmtiExport::clear_detected_exception((JavaThread*)THREAD);
duke@435 949 {
duke@435 950 EXCEPTION_MARK;
duke@435 951 this_oop->set_initialization_state_and_notify(initialization_error, THREAD);
duke@435 952 CLEAR_PENDING_EXCEPTION; // ignore any exception thrown, class initialization error is thrown below
jbachorik@7812 953 // JVMTI has already reported the pending exception
jbachorik@7812 954 // JVMTI internal flag reset is needed in order to report ExceptionInInitializerError
jbachorik@7812 955 JvmtiExport::clear_detected_exception((JavaThread*)THREAD);
duke@435 956 }
coleenp@4037 957 DTRACE_CLASSINIT_PROBE_WAIT(error, InstanceKlass::cast(this_oop()), -1,wait);
never@1577 958 if (e->is_a(SystemDictionary::Error_klass())) {
duke@435 959 THROW_OOP(e());
duke@435 960 } else {
duke@435 961 JavaCallArguments args(e);
coleenp@2497 962 THROW_ARG(vmSymbols::java_lang_ExceptionInInitializerError(),
coleenp@2497 963 vmSymbols::throwable_void_signature(),
duke@435 964 &args);
duke@435 965 }
duke@435 966 }
coleenp@4037 967 DTRACE_CLASSINIT_PROBE_WAIT(end, InstanceKlass::cast(this_oop()), -1,wait);
duke@435 968 }
duke@435 969
duke@435 970
duke@435 971 // Note: implementation moved to static method to expose the this pointer.
coleenp@4037 972 void InstanceKlass::set_initialization_state_and_notify(ClassState state, TRAPS) {
coleenp@4037 973 instanceKlassHandle kh(THREAD, this);
duke@435 974 set_initialization_state_and_notify_impl(kh, state, CHECK);
duke@435 975 }
duke@435 976
coleenp@4037 977 void InstanceKlass::set_initialization_state_and_notify_impl(instanceKlassHandle this_oop, ClassState state, TRAPS) {
coleenp@5836 978 oop init_lock = this_oop->init_lock();
coleenp@8640 979 if (init_lock != NULL) {
coleenp@8640 980 ObjectLocker ol(init_lock, THREAD);
coleenp@8640 981 this_oop->set_init_state(state);
coleenp@8640 982 this_oop->fence_and_clear_init_lock();
coleenp@8640 983 ol.notify_all(CHECK);
coleenp@8640 984 } else {
coleenp@8640 985 assert(init_lock != NULL, "The initialization state should never be set twice");
coleenp@8640 986 this_oop->set_init_state(state);
coleenp@8640 987 }
duke@435 988 }
duke@435 989
jiangli@3701 990 // The embedded _implementor field can only record one implementor.
jiangli@3701 991 // When there are more than one implementors, the _implementor field
coleenp@4037 992 // is set to the interface Klass* itself. Following are the possible
jiangli@3701 993 // values for the _implementor field:
jiangli@3701 994 // NULL - no implementor
coleenp@4037 995 // implementor Klass* - one implementor
jiangli@3701 996 // self - more than one implementor
jiangli@3701 997 //
jiangli@3701 998 // The _implementor field only exists for interfaces.
coleenp@4037 999 void InstanceKlass::add_implementor(Klass* k) {
duke@435 1000 assert(Compile_lock->owned_by_self(), "");
jiangli@3701 1001 assert(is_interface(), "not interface");
duke@435 1002 // Filter out my subinterfaces.
duke@435 1003 // (Note: Interfaces are never on the subklass list.)
coleenp@4037 1004 if (InstanceKlass::cast(k)->is_interface()) return;
duke@435 1005
duke@435 1006 // Filter out subclasses whose supers already implement me.
duke@435 1007 // (Note: CHA must walk subclasses of direct implementors
duke@435 1008 // in order to locate indirect implementors.)
coleenp@4037 1009 Klass* sk = InstanceKlass::cast(k)->super();
coleenp@4037 1010 if (sk != NULL && InstanceKlass::cast(sk)->implements_interface(this))
duke@435 1011 // We only need to check one immediate superclass, since the
duke@435 1012 // implements_interface query looks at transitive_interfaces.
duke@435 1013 // Any supers of the super have the same (or fewer) transitive_interfaces.
duke@435 1014 return;
duke@435 1015
coleenp@4037 1016 Klass* ik = implementor();
jiangli@3701 1017 if (ik == NULL) {
jiangli@3701 1018 set_implementor(k);
coleenp@4037 1019 } else if (ik != this) {
jiangli@3701 1020 // There is already an implementor. Use itself as an indicator of
jiangli@3701 1021 // more than one implementors.
coleenp@4037 1022 set_implementor(this);
duke@435 1023 }
duke@435 1024
duke@435 1025 // The implementor also implements the transitive_interfaces
duke@435 1026 for (int index = 0; index < local_interfaces()->length(); index++) {
coleenp@4037 1027 InstanceKlass::cast(local_interfaces()->at(index))->add_implementor(k);
duke@435 1028 }
duke@435 1029 }
duke@435 1030
coleenp@4037 1031 void InstanceKlass::init_implementor() {
jiangli@3701 1032 if (is_interface()) {
jiangli@3701 1033 set_implementor(NULL);
jiangli@3701 1034 }
duke@435 1035 }
duke@435 1036
duke@435 1037
coleenp@4037 1038 void InstanceKlass::process_interfaces(Thread *thread) {
duke@435 1039 // link this class into the implementors list of every interface it implements
coleenp@4037 1040 Klass* this_as_klass_oop = this;
duke@435 1041 for (int i = local_interfaces()->length() - 1; i >= 0; i--) {
coleenp@4037 1042 assert(local_interfaces()->at(i)->is_klass(), "must be a klass");
coleenp@4037 1043 InstanceKlass* interf = InstanceKlass::cast(local_interfaces()->at(i));
duke@435 1044 assert(interf->is_interface(), "expected interface");
coleenp@4037 1045 interf->add_implementor(this_as_klass_oop);
duke@435 1046 }
duke@435 1047 }
duke@435 1048
coleenp@4037 1049 bool InstanceKlass::can_be_primary_super_slow() const {
duke@435 1050 if (is_interface())
duke@435 1051 return false;
duke@435 1052 else
duke@435 1053 return Klass::can_be_primary_super_slow();
duke@435 1054 }
duke@435 1055
coleenp@4037 1056 GrowableArray<Klass*>* InstanceKlass::compute_secondary_supers(int num_extra_slots) {
duke@435 1057 // The secondaries are the implemented interfaces.
coleenp@4037 1058 InstanceKlass* ik = InstanceKlass::cast(this);
coleenp@4037 1059 Array<Klass*>* interfaces = ik->transitive_interfaces();
duke@435 1060 int num_secondaries = num_extra_slots + interfaces->length();
duke@435 1061 if (num_secondaries == 0) {
coleenp@4037 1062 // Must share this for correct bootstrapping!
coleenp@4037 1063 set_secondary_supers(Universe::the_empty_klass_array());
coleenp@4037 1064 return NULL;
duke@435 1065 } else if (num_extra_slots == 0) {
coleenp@4037 1066 // The secondary super list is exactly the same as the transitive interfaces.
coleenp@4037 1067 // Redefine classes has to be careful not to delete this!
coleenp@4037 1068 set_secondary_supers(interfaces);
coleenp@4037 1069 return NULL;
duke@435 1070 } else {
coleenp@4037 1071 // Copy transitive interfaces to a temporary growable array to be constructed
coleenp@4037 1072 // into the secondary super list with extra slots.
coleenp@4037 1073 GrowableArray<Klass*>* secondaries = new GrowableArray<Klass*>(interfaces->length());
duke@435 1074 for (int i = 0; i < interfaces->length(); i++) {
coleenp@4037 1075 secondaries->push(interfaces->at(i));
duke@435 1076 }
duke@435 1077 return secondaries;
duke@435 1078 }
duke@435 1079 }
duke@435 1080
coleenp@4037 1081 bool InstanceKlass::compute_is_subtype_of(Klass* k) {
hseigel@4278 1082 if (k->is_interface()) {
duke@435 1083 return implements_interface(k);
duke@435 1084 } else {
duke@435 1085 return Klass::compute_is_subtype_of(k);
duke@435 1086 }
duke@435 1087 }
duke@435 1088
coleenp@4037 1089 bool InstanceKlass::implements_interface(Klass* k) const {
coleenp@4037 1090 if (this == k) return true;
hseigel@4278 1091 assert(k->is_interface(), "should be an interface class");
duke@435 1092 for (int i = 0; i < transitive_interfaces()->length(); i++) {
coleenp@4037 1093 if (transitive_interfaces()->at(i) == k) {
duke@435 1094 return true;
duke@435 1095 }
duke@435 1096 }
duke@435 1097 return false;
duke@435 1098 }
duke@435 1099
hseigel@6132 1100 bool InstanceKlass::is_same_or_direct_interface(Klass *k) const {
hseigel@6132 1101 // Verify direct super interface
hseigel@6132 1102 if (this == k) return true;
hseigel@6132 1103 assert(k->is_interface(), "should be an interface class");
hseigel@6132 1104 for (int i = 0; i < local_interfaces()->length(); i++) {
hseigel@6132 1105 if (local_interfaces()->at(i) == k) {
hseigel@6132 1106 return true;
hseigel@6132 1107 }
hseigel@6132 1108 }
hseigel@6132 1109 return false;
hseigel@6132 1110 }
hseigel@6132 1111
coleenp@4037 1112 objArrayOop InstanceKlass::allocate_objArray(int n, int length, TRAPS) {
duke@435 1113 if (length < 0) THROW_0(vmSymbols::java_lang_NegativeArraySizeException());
duke@435 1114 if (length > arrayOopDesc::max_array_length(T_OBJECT)) {
martin@1311 1115 report_java_out_of_memory("Requested array size exceeds VM limit");
sspitsyn@3638 1116 JvmtiExport::post_array_size_exhausted();
duke@435 1117 THROW_OOP_0(Universe::out_of_memory_error_array_size());
duke@435 1118 }
duke@435 1119 int size = objArrayOopDesc::object_size(length);
coleenp@4037 1120 Klass* ak = array_klass(n, CHECK_NULL);
duke@435 1121 KlassHandle h_ak (THREAD, ak);
duke@435 1122 objArrayOop o =
duke@435 1123 (objArrayOop)CollectedHeap::array_allocate(h_ak, size, length, CHECK_NULL);
duke@435 1124 return o;
duke@435 1125 }
duke@435 1126
coleenp@4037 1127 instanceOop InstanceKlass::register_finalizer(instanceOop i, TRAPS) {
duke@435 1128 if (TraceFinalizerRegistration) {
duke@435 1129 tty->print("Registered ");
duke@435 1130 i->print_value_on(tty);
duke@435 1131 tty->print_cr(" (" INTPTR_FORMAT ") as finalizable", (address)i);
duke@435 1132 }
duke@435 1133 instanceHandle h_i(THREAD, i);
duke@435 1134 // Pass the handle as argument, JavaCalls::call expects oop as jobjects
duke@435 1135 JavaValue result(T_VOID);
duke@435 1136 JavaCallArguments args(h_i);
duke@435 1137 methodHandle mh (THREAD, Universe::finalizer_register_method());
duke@435 1138 JavaCalls::call(&result, mh, &args, CHECK_NULL);
duke@435 1139 return h_i();
duke@435 1140 }
duke@435 1141
coleenp@4037 1142 instanceOop InstanceKlass::allocate_instance(TRAPS) {
duke@435 1143 bool has_finalizer_flag = has_finalizer(); // Query before possible GC
duke@435 1144 int size = size_helper(); // Query before forming handle.
duke@435 1145
coleenp@4037 1146 KlassHandle h_k(THREAD, this);
duke@435 1147
duke@435 1148 instanceOop i;
duke@435 1149
duke@435 1150 i = (instanceOop)CollectedHeap::obj_allocate(h_k, size, CHECK_NULL);
duke@435 1151 if (has_finalizer_flag && !RegisterFinalizersAtInit) {
duke@435 1152 i = register_finalizer(i, CHECK_NULL);
duke@435 1153 }
duke@435 1154 return i;
duke@435 1155 }
duke@435 1156
coleenp@4037 1157 void InstanceKlass::check_valid_for_instantiation(bool throwError, TRAPS) {
duke@435 1158 if (is_interface() || is_abstract()) {
duke@435 1159 ResourceMark rm(THREAD);
duke@435 1160 THROW_MSG(throwError ? vmSymbols::java_lang_InstantiationError()
duke@435 1161 : vmSymbols::java_lang_InstantiationException(), external_name());
duke@435 1162 }
coleenp@4037 1163 if (this == SystemDictionary::Class_klass()) {
duke@435 1164 ResourceMark rm(THREAD);
duke@435 1165 THROW_MSG(throwError ? vmSymbols::java_lang_IllegalAccessError()
duke@435 1166 : vmSymbols::java_lang_IllegalAccessException(), external_name());
duke@435 1167 }
duke@435 1168 }
duke@435 1169
coleenp@4037 1170 Klass* InstanceKlass::array_klass_impl(bool or_null, int n, TRAPS) {
coleenp@4037 1171 instanceKlassHandle this_oop(THREAD, this);
duke@435 1172 return array_klass_impl(this_oop, or_null, n, THREAD);
duke@435 1173 }
duke@435 1174
coleenp@4037 1175 Klass* InstanceKlass::array_klass_impl(instanceKlassHandle this_oop, bool or_null, int n, TRAPS) {
duke@435 1176 if (this_oop->array_klasses() == NULL) {
duke@435 1177 if (or_null) return NULL;
duke@435 1178
duke@435 1179 ResourceMark rm;
duke@435 1180 JavaThread *jt = (JavaThread *)THREAD;
duke@435 1181 {
duke@435 1182 // Atomic creation of array_klasses
duke@435 1183 MutexLocker mc(Compile_lock, THREAD); // for vtables
duke@435 1184 MutexLocker ma(MultiArray_lock, THREAD);
duke@435 1185
duke@435 1186 // Check if update has already taken place
duke@435 1187 if (this_oop->array_klasses() == NULL) {
coleenp@4142 1188 Klass* k = ObjArrayKlass::allocate_objArray_klass(this_oop->class_loader_data(), 1, this_oop, CHECK_NULL);
duke@435 1189 this_oop->set_array_klasses(k);
duke@435 1190 }
duke@435 1191 }
duke@435 1192 }
duke@435 1193 // _this will always be set at this point
coleenp@4142 1194 ObjArrayKlass* oak = (ObjArrayKlass*)this_oop->array_klasses();
duke@435 1195 if (or_null) {
duke@435 1196 return oak->array_klass_or_null(n);
duke@435 1197 }
phh@9507 1198 return oak->array_klass(n, THREAD);
duke@435 1199 }
duke@435 1200
coleenp@4037 1201 Klass* InstanceKlass::array_klass_impl(bool or_null, TRAPS) {
duke@435 1202 return array_klass_impl(or_null, 1, THREAD);
duke@435 1203 }
duke@435 1204
coleenp@4037 1205 void InstanceKlass::call_class_initializer(TRAPS) {
coleenp@4037 1206 instanceKlassHandle ik (THREAD, this);
duke@435 1207 call_class_initializer_impl(ik, THREAD);
duke@435 1208 }
duke@435 1209
duke@435 1210 static int call_class_initializer_impl_counter = 0; // for debugging
duke@435 1211
coleenp@4037 1212 Method* InstanceKlass::class_initializer() {
coleenp@4037 1213 Method* clinit = find_method(
kamg@2616 1214 vmSymbols::class_initializer_name(), vmSymbols::void_method_signature());
kamg@2616 1215 if (clinit != NULL && clinit->has_valid_initializer_flags()) {
kamg@2616 1216 return clinit;
kamg@2616 1217 }
kamg@2616 1218 return NULL;
duke@435 1219 }
duke@435 1220
coleenp@4037 1221 void InstanceKlass::call_class_initializer_impl(instanceKlassHandle this_oop, TRAPS) {
minqi@4267 1222 if (ReplayCompiles &&
minqi@4267 1223 (ReplaySuppressInitializers == 1 ||
minqi@4267 1224 ReplaySuppressInitializers >= 2 && this_oop->class_loader() != NULL)) {
minqi@4267 1225 // Hide the existence of the initializer for the purpose of replaying the compile
minqi@4267 1226 return;
minqi@4267 1227 }
minqi@4267 1228
duke@435 1229 methodHandle h_method(THREAD, this_oop->class_initializer());
duke@435 1230 assert(!this_oop->is_initialized(), "we cannot initialize twice");
duke@435 1231 if (TraceClassInitialization) {
duke@435 1232 tty->print("%d Initializing ", call_class_initializer_impl_counter++);
duke@435 1233 this_oop->name()->print_value();
duke@435 1234 tty->print_cr("%s (" INTPTR_FORMAT ")", h_method() == NULL ? "(no method)" : "", (address)this_oop());
duke@435 1235 }
duke@435 1236 if (h_method() != NULL) {
duke@435 1237 JavaCallArguments args; // No arguments
duke@435 1238 JavaValue result(T_VOID);
duke@435 1239 JavaCalls::call(&result, h_method, &args, CHECK); // Static call (no args)
duke@435 1240 }
duke@435 1241 }
duke@435 1242
duke@435 1243
coleenp@4037 1244 void InstanceKlass::mask_for(methodHandle method, int bci,
duke@435 1245 InterpreterOopMap* entry_for) {
duke@435 1246 // Dirty read, then double-check under a lock.
duke@435 1247 if (_oop_map_cache == NULL) {
duke@435 1248 // Otherwise, allocate a new one.
duke@435 1249 MutexLocker x(OopMapCacheAlloc_lock);
duke@435 1250 // First time use. Allocate a cache in C heap
duke@435 1251 if (_oop_map_cache == NULL) {
goetz@6493 1252 // Release stores from OopMapCache constructor before assignment
goetz@6493 1253 // to _oop_map_cache. C++ compilers on ppc do not emit the
goetz@6493 1254 // required memory barrier only because of the volatile
goetz@6493 1255 // qualifier of _oop_map_cache.
goetz@6493 1256 OrderAccess::release_store_ptr(&_oop_map_cache, new OopMapCache());
duke@435 1257 }
duke@435 1258 }
duke@435 1259 // _oop_map_cache is constant after init; lookup below does is own locking.
duke@435 1260 _oop_map_cache->lookup(method, bci, entry_for);
duke@435 1261 }
duke@435 1262
duke@435 1263
coleenp@4037 1264 bool InstanceKlass::find_local_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const {
coleenp@4037 1265 for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
never@3137 1266 Symbol* f_name = fs.name();
never@3137 1267 Symbol* f_sig = fs.signature();
duke@435 1268 if (f_name == name && f_sig == sig) {
drchase@5732 1269 fd->reinitialize(const_cast<InstanceKlass*>(this), fs.index());
duke@435 1270 return true;
duke@435 1271 }
duke@435 1272 }
duke@435 1273 return false;
duke@435 1274 }
duke@435 1275
duke@435 1276
coleenp@4037 1277 Klass* InstanceKlass::find_interface_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const {
duke@435 1278 const int n = local_interfaces()->length();
duke@435 1279 for (int i = 0; i < n; i++) {
coleenp@4037 1280 Klass* intf1 = local_interfaces()->at(i);
hseigel@4278 1281 assert(intf1->is_interface(), "just checking type");
duke@435 1282 // search for field in current interface
coleenp@4037 1283 if (InstanceKlass::cast(intf1)->find_local_field(name, sig, fd)) {
duke@435 1284 assert(fd->is_static(), "interface field must be static");
duke@435 1285 return intf1;
duke@435 1286 }
duke@435 1287 // search for field in direct superinterfaces
coleenp@4037 1288 Klass* intf2 = InstanceKlass::cast(intf1)->find_interface_field(name, sig, fd);
duke@435 1289 if (intf2 != NULL) return intf2;
duke@435 1290 }
duke@435 1291 // otherwise field lookup fails
duke@435 1292 return NULL;
duke@435 1293 }
duke@435 1294
duke@435 1295
coleenp@4037 1296 Klass* InstanceKlass::find_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const {
duke@435 1297 // search order according to newest JVM spec (5.4.3.2, p.167).
duke@435 1298 // 1) search for field in current klass
duke@435 1299 if (find_local_field(name, sig, fd)) {
coleenp@4037 1300 return const_cast<InstanceKlass*>(this);
duke@435 1301 }
duke@435 1302 // 2) search for field recursively in direct superinterfaces
coleenp@4037 1303 { Klass* intf = find_interface_field(name, sig, fd);
duke@435 1304 if (intf != NULL) return intf;
duke@435 1305 }
duke@435 1306 // 3) apply field lookup recursively if superclass exists
coleenp@4037 1307 { Klass* supr = super();
coleenp@4037 1308 if (supr != NULL) return InstanceKlass::cast(supr)->find_field(name, sig, fd);
duke@435 1309 }
duke@435 1310 // 4) otherwise field lookup fails
duke@435 1311 return NULL;
duke@435 1312 }
duke@435 1313
duke@435 1314
coleenp@4037 1315 Klass* InstanceKlass::find_field(Symbol* name, Symbol* sig, bool is_static, fieldDescriptor* fd) const {
duke@435 1316 // search order according to newest JVM spec (5.4.3.2, p.167).
duke@435 1317 // 1) search for field in current klass
duke@435 1318 if (find_local_field(name, sig, fd)) {
coleenp@4037 1319 if (fd->is_static() == is_static) return const_cast<InstanceKlass*>(this);
duke@435 1320 }
duke@435 1321 // 2) search for field recursively in direct superinterfaces
duke@435 1322 if (is_static) {
coleenp@4037 1323 Klass* intf = find_interface_field(name, sig, fd);
duke@435 1324 if (intf != NULL) return intf;
duke@435 1325 }
duke@435 1326 // 3) apply field lookup recursively if superclass exists
coleenp@4037 1327 { Klass* supr = super();
coleenp@4037 1328 if (supr != NULL) return InstanceKlass::cast(supr)->find_field(name, sig, is_static, fd);
duke@435 1329 }
duke@435 1330 // 4) otherwise field lookup fails
duke@435 1331 return NULL;
duke@435 1332 }
duke@435 1333
duke@435 1334
coleenp@4037 1335 bool InstanceKlass::find_local_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const {
coleenp@4037 1336 for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
never@3137 1337 if (fs.offset() == offset) {
drchase@5732 1338 fd->reinitialize(const_cast<InstanceKlass*>(this), fs.index());
duke@435 1339 if (fd->is_static() == is_static) return true;
duke@435 1340 }
duke@435 1341 }
duke@435 1342 return false;
duke@435 1343 }
duke@435 1344
duke@435 1345
coleenp@4037 1346 bool InstanceKlass::find_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const {
coleenp@4037 1347 Klass* klass = const_cast<InstanceKlass*>(this);
duke@435 1348 while (klass != NULL) {
coleenp@4037 1349 if (InstanceKlass::cast(klass)->find_local_field_from_offset(offset, is_static, fd)) {
duke@435 1350 return true;
duke@435 1351 }
hseigel@4278 1352 klass = klass->super();
duke@435 1353 }
duke@435 1354 return false;
duke@435 1355 }
duke@435 1356
duke@435 1357
coleenp@4037 1358 void InstanceKlass::methods_do(void f(Method* method)) {
duke@435 1359 int len = methods()->length();
duke@435 1360 for (int index = 0; index < len; index++) {
coleenp@4037 1361 Method* m = methods()->at(index);
duke@435 1362 assert(m->is_method(), "must be method");
duke@435 1363 f(m);
duke@435 1364 }
duke@435 1365 }
duke@435 1366
never@2658 1367
coleenp@4037 1368 void InstanceKlass::do_local_static_fields(FieldClosure* cl) {
never@3137 1369 for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
never@3137 1370 if (fs.access_flags().is_static()) {
drchase@5732 1371 fieldDescriptor& fd = fs.field_descriptor();
never@3137 1372 cl->do_field(&fd);
never@3137 1373 }
duke@435 1374 }
duke@435 1375 }
duke@435 1376
duke@435 1377
coleenp@6626 1378 void InstanceKlass::do_local_static_fields(void f(fieldDescriptor*, Handle, TRAPS), Handle mirror, TRAPS) {
coleenp@4037 1379 instanceKlassHandle h_this(THREAD, this);
coleenp@6626 1380 do_local_static_fields_impl(h_this, f, mirror, CHECK);
duke@435 1381 }
duke@435 1382
duke@435 1383
coleenp@6626 1384 void InstanceKlass::do_local_static_fields_impl(instanceKlassHandle this_k,
coleenp@6626 1385 void f(fieldDescriptor* fd, Handle mirror, TRAPS), Handle mirror, TRAPS) {
coleenp@6626 1386 for (JavaFieldStream fs(this_k()); !fs.done(); fs.next()) {
never@3137 1387 if (fs.access_flags().is_static()) {
drchase@5732 1388 fieldDescriptor& fd = fs.field_descriptor();
coleenp@6626 1389 f(&fd, mirror, CHECK);
never@3137 1390 }
duke@435 1391 }
duke@435 1392 }
duke@435 1393
duke@435 1394
kvn@479 1395 static int compare_fields_by_offset(int* a, int* b) {
kvn@479 1396 return a[0] - b[0];
kvn@479 1397 }
kvn@479 1398
coleenp@4037 1399 void InstanceKlass::do_nonstatic_fields(FieldClosure* cl) {
coleenp@4037 1400 InstanceKlass* super = superklass();
duke@435 1401 if (super != NULL) {
duke@435 1402 super->do_nonstatic_fields(cl);
duke@435 1403 }
kvn@479 1404 fieldDescriptor fd;
never@3137 1405 int length = java_fields_count();
kvn@479 1406 // In DebugInfo nonstatic fields are sorted by offset.
zgu@3900 1407 int* fields_sorted = NEW_C_HEAP_ARRAY(int, 2*(length+1), mtClass);
kvn@479 1408 int j = 0;
never@3137 1409 for (int i = 0; i < length; i += 1) {
drchase@5732 1410 fd.reinitialize(this, i);
kvn@479 1411 if (!fd.is_static()) {
kvn@479 1412 fields_sorted[j + 0] = fd.offset();
kvn@479 1413 fields_sorted[j + 1] = i;
kvn@479 1414 j += 2;
kvn@479 1415 }
duke@435 1416 }
kvn@479 1417 if (j > 0) {
kvn@479 1418 length = j;
kvn@479 1419 // _sort_Fn is defined in growableArray.hpp.
kvn@479 1420 qsort(fields_sorted, length/2, 2*sizeof(int), (_sort_Fn)compare_fields_by_offset);
kvn@479 1421 for (int i = 0; i < length; i += 2) {
drchase@5732 1422 fd.reinitialize(this, fields_sorted[i + 1]);
kvn@479 1423 assert(!fd.is_static() && fd.offset() == fields_sorted[i], "only nonstatic fields");
kvn@479 1424 cl->do_field(&fd);
kvn@479 1425 }
kvn@479 1426 }
zgu@3900 1427 FREE_C_HEAP_ARRAY(int, fields_sorted, mtClass);
duke@435 1428 }
duke@435 1429
duke@435 1430
coleenp@4037 1431 void InstanceKlass::array_klasses_do(void f(Klass* k, TRAPS), TRAPS) {
coleenp@4037 1432 if (array_klasses() != NULL)
coleenp@4142 1433 ArrayKlass::cast(array_klasses())->array_klasses_do(f, THREAD);
coleenp@4037 1434 }
coleenp@4037 1435
coleenp@4037 1436 void InstanceKlass::array_klasses_do(void f(Klass* k)) {
duke@435 1437 if (array_klasses() != NULL)
coleenp@4142 1438 ArrayKlass::cast(array_klasses())->array_klasses_do(f);
duke@435 1439 }
duke@435 1440
duke@435 1441 #ifdef ASSERT
coleenp@4037 1442 static int linear_search(Array<Method*>* methods, Symbol* name, Symbol* signature) {
duke@435 1443 int len = methods->length();
duke@435 1444 for (int index = 0; index < len; index++) {
coleenp@4037 1445 Method* m = methods->at(index);
duke@435 1446 assert(m->is_method(), "must be method");
duke@435 1447 if (m->signature() == signature && m->name() == name) {
duke@435 1448 return index;
duke@435 1449 }
duke@435 1450 }
duke@435 1451 return -1;
duke@435 1452 }
duke@435 1453 #endif
duke@435 1454
kamg@4245 1455 static int binary_search(Array<Method*>* methods, Symbol* name) {
duke@435 1456 int len = methods->length();
duke@435 1457 // methods are sorted, so do binary search
duke@435 1458 int l = 0;
duke@435 1459 int h = len - 1;
duke@435 1460 while (l <= h) {
duke@435 1461 int mid = (l + h) >> 1;
coleenp@4037 1462 Method* m = methods->at(mid);
duke@435 1463 assert(m->is_method(), "must be method");
duke@435 1464 int res = m->name()->fast_compare(name);
duke@435 1465 if (res == 0) {
kamg@4245 1466 return mid;
duke@435 1467 } else if (res < 0) {
duke@435 1468 l = mid + 1;
duke@435 1469 } else {
duke@435 1470 h = mid - 1;
duke@435 1471 }
duke@435 1472 }
kamg@4245 1473 return -1;
kamg@4245 1474 }
kamg@4245 1475
acorn@5848 1476 // find_method looks up the name/signature in the local methods array
kamg@4245 1477 Method* InstanceKlass::find_method(Symbol* name, Symbol* signature) const {
dbuck@8716 1478 return find_method_impl(name, signature, find_overpass, find_static, find_private);
lfoltan@6632 1479 }
lfoltan@6632 1480
dbuck@8716 1481 Method* InstanceKlass::find_method_impl(Symbol* name, Symbol* signature,
dbuck@8716 1482 OverpassLookupMode overpass_mode,
dbuck@8716 1483 StaticLookupMode static_mode,
dbuck@8716 1484 PrivateLookupMode private_mode) const {
dbuck@8716 1485 return InstanceKlass::find_method_impl(methods(), name, signature, overpass_mode, static_mode, private_mode);
kamg@4245 1486 }
kamg@4245 1487
acorn@6145 1488 // find_instance_method looks up the name/signature in the local methods array
acorn@6145 1489 // and skips over static methods
acorn@6145 1490 Method* InstanceKlass::find_instance_method(
acorn@6145 1491 Array<Method*>* methods, Symbol* name, Symbol* signature) {
dbuck@8716 1492 Method* meth = InstanceKlass::find_method_impl(methods, name, signature,
dbuck@8716 1493 find_overpass, skip_static, find_private);
dbuck@8716 1494 assert(((meth == NULL) || !meth->is_static()), "find_instance_method should have skipped statics");
acorn@6145 1495 return meth;
acorn@6145 1496 }
acorn@6145 1497
drchase@7499 1498 // find_instance_method looks up the name/signature in the local methods array
drchase@7499 1499 // and skips over static methods
drchase@7499 1500 Method* InstanceKlass::find_instance_method(Symbol* name, Symbol* signature) {
drchase@7499 1501 return InstanceKlass::find_instance_method(methods(), name, signature);
drchase@7499 1502 }
drchase@7499 1503
dbuck@8716 1504 // Find looks up the name/signature in the local methods array
dbuck@8716 1505 // and filters on the overpass, static and private flags
dbuck@8716 1506 // This returns the first one found
dbuck@8716 1507 // note that the local methods array can have up to one overpass, one static
dbuck@8716 1508 // and one instance (private or not) with the same name/signature
dbuck@8716 1509 Method* InstanceKlass::find_local_method(Symbol* name, Symbol* signature,
dbuck@8716 1510 OverpassLookupMode overpass_mode,
dbuck@8716 1511 StaticLookupMode static_mode,
dbuck@8716 1512 PrivateLookupMode private_mode) const {
dbuck@8716 1513 return InstanceKlass::find_method_impl(methods(), name, signature, overpass_mode, static_mode, private_mode);
dbuck@8716 1514 }
dbuck@8716 1515
dbuck@8716 1516 // Find looks up the name/signature in the local methods array
dbuck@8716 1517 // and filters on the overpass, static and private flags
dbuck@8716 1518 // This returns the first one found
dbuck@8716 1519 // note that the local methods array can have up to one overpass, one static
dbuck@8716 1520 // and one instance (private or not) with the same name/signature
dbuck@8716 1521 Method* InstanceKlass::find_local_method(Array<Method*>* methods,
dbuck@8716 1522 Symbol* name, Symbol* signature,
dbuck@8716 1523 OverpassLookupMode overpass_mode,
dbuck@8716 1524 StaticLookupMode static_mode,
dbuck@8716 1525 PrivateLookupMode private_mode) {
dbuck@8716 1526 return InstanceKlass::find_method_impl(methods, name, signature, overpass_mode, static_mode, private_mode);
dbuck@8716 1527 }
dbuck@8716 1528
dbuck@8716 1529
acorn@5848 1530 // find_method looks up the name/signature in the local methods array
kamg@4245 1531 Method* InstanceKlass::find_method(
kamg@4245 1532 Array<Method*>* methods, Symbol* name, Symbol* signature) {
dbuck@8716 1533 return InstanceKlass::find_method_impl(methods, name, signature, find_overpass, find_static, find_private);
lfoltan@6632 1534 }
lfoltan@6632 1535
lfoltan@6632 1536 Method* InstanceKlass::find_method_impl(
dbuck@8716 1537 Array<Method*>* methods, Symbol* name, Symbol* signature,
dbuck@8716 1538 OverpassLookupMode overpass_mode, StaticLookupMode static_mode,
dbuck@8716 1539 PrivateLookupMode private_mode) {
dbuck@8716 1540 int hit = find_method_index(methods, name, signature, overpass_mode, static_mode, private_mode);
acorn@5848 1541 return hit >= 0 ? methods->at(hit): NULL;
acorn@5848 1542 }
acorn@5848 1543
dbuck@8716 1544 bool InstanceKlass::method_matches(Method* m, Symbol* signature, bool skipping_overpass, bool skipping_static, bool skipping_private) {
dbuck@8716 1545 return ((m->signature() == signature) &&
drchase@7499 1546 (!skipping_overpass || !m->is_overpass()) &&
dbuck@8716 1547 (!skipping_static || !m->is_static()) &&
dbuck@8716 1548 (!skipping_private || !m->is_private()));
drchase@7499 1549 }
drchase@7499 1550
acorn@5848 1551 // Used directly for default_methods to find the index into the
acorn@5848 1552 // default_vtable_indices, and indirectly by find_method
acorn@5848 1553 // find_method_index looks in the local methods array to return the index
lfoltan@6632 1554 // of the matching name/signature. If, overpass methods are being ignored,
lfoltan@6632 1555 // the search continues to find a potential non-overpass match. This capability
lfoltan@6632 1556 // is important during method resolution to prefer a static method, for example,
lfoltan@6632 1557 // over an overpass method.
dbuck@8716 1558 // There is the possibility in any _method's array to have the same name/signature
dbuck@8716 1559 // for a static method, an overpass method and a local instance method
dbuck@8716 1560 // To correctly catch a given method, the search criteria may need
dbuck@8716 1561 // to explicitly skip the other two. For local instance methods, it
dbuck@8716 1562 // is often necessary to skip private methods
acorn@5848 1563 int InstanceKlass::find_method_index(
dbuck@8716 1564 Array<Method*>* methods, Symbol* name, Symbol* signature,
dbuck@8716 1565 OverpassLookupMode overpass_mode, StaticLookupMode static_mode,
dbuck@8716 1566 PrivateLookupMode private_mode) {
dbuck@8716 1567 bool skipping_overpass = (overpass_mode == skip_overpass);
dbuck@8716 1568 bool skipping_static = (static_mode == skip_static);
dbuck@8716 1569 bool skipping_private = (private_mode == skip_private);
kamg@4245 1570 int hit = binary_search(methods, name);
kamg@4245 1571 if (hit != -1) {
kamg@4245 1572 Method* m = methods->at(hit);
drchase@7499 1573
kamg@4245 1574 // Do linear search to find matching signature. First, quick check
lfoltan@6632 1575 // for common case, ignoring overpasses if requested.
dbuck@8716 1576 if (method_matches(m, signature, skipping_overpass, skipping_static, skipping_private)) return hit;
lfoltan@6632 1577
kamg@4245 1578 // search downwards through overloaded methods
kamg@4245 1579 int i;
kamg@4245 1580 for (i = hit - 1; i >= 0; --i) {
kamg@4245 1581 Method* m = methods->at(i);
kamg@4245 1582 assert(m->is_method(), "must be method");
kamg@4245 1583 if (m->name() != name) break;
dbuck@8716 1584 if (method_matches(m, signature, skipping_overpass, skipping_static, skipping_private)) return i;
kamg@4245 1585 }
kamg@4245 1586 // search upwards
kamg@4245 1587 for (i = hit + 1; i < methods->length(); ++i) {
kamg@4245 1588 Method* m = methods->at(i);
kamg@4245 1589 assert(m->is_method(), "must be method");
kamg@4245 1590 if (m->name() != name) break;
dbuck@8716 1591 if (method_matches(m, signature, skipping_overpass, skipping_static, skipping_private)) return i;
kamg@4245 1592 }
kamg@4245 1593 // not found
duke@435 1594 #ifdef ASSERT
dbuck@8716 1595 int index = (skipping_overpass || skipping_static || skipping_private) ? -1 : linear_search(methods, name, signature);
kamg@4245 1596 assert(index == -1, err_msg("binary search should have found entry %d", index));
duke@435 1597 #endif
kamg@4245 1598 }
acorn@5848 1599 return -1;
duke@435 1600 }
kamg@4245 1601 int InstanceKlass::find_method_by_name(Symbol* name, int* end) {
kamg@4245 1602 return find_method_by_name(methods(), name, end);
kamg@4245 1603 }
kamg@4245 1604
kamg@4245 1605 int InstanceKlass::find_method_by_name(
kamg@4245 1606 Array<Method*>* methods, Symbol* name, int* end_ptr) {
kamg@4245 1607 assert(end_ptr != NULL, "just checking");
kamg@4245 1608 int start = binary_search(methods, name);
kamg@4245 1609 int end = start + 1;
kamg@4245 1610 if (start != -1) {
kamg@4245 1611 while (start - 1 >= 0 && (methods->at(start - 1))->name() == name) --start;
kamg@4245 1612 while (end < methods->length() && (methods->at(end))->name() == name) ++end;
kamg@4245 1613 *end_ptr = end;
kamg@4245 1614 return start;
kamg@4245 1615 }
kamg@4245 1616 return -1;
kamg@4245 1617 }
kamg@4245 1618
hseigel@6195 1619 // uncached_lookup_method searches both the local class methods array and all
hseigel@6195 1620 // superclasses methods arrays, skipping any overpass methods in superclasses.
dbuck@8716 1621 Method* InstanceKlass::uncached_lookup_method(Symbol* name, Symbol* signature, OverpassLookupMode overpass_mode) const {
dbuck@8716 1622 OverpassLookupMode overpass_local_mode = overpass_mode;
coleenp@4037 1623 Klass* klass = const_cast<InstanceKlass*>(this);
duke@435 1624 while (klass != NULL) {
dbuck@8716 1625 Method* method = InstanceKlass::cast(klass)->find_method_impl(name, signature, overpass_local_mode, find_static, find_private);
lfoltan@6632 1626 if (method != NULL) {
hseigel@6195 1627 return method;
hseigel@6195 1628 }
coleenp@4037 1629 klass = InstanceKlass::cast(klass)->super();
dbuck@8716 1630 overpass_local_mode = skip_overpass; // Always ignore overpass methods in superclasses
duke@435 1631 }
duke@435 1632 return NULL;
duke@435 1633 }
duke@435 1634
dsamersoff@8049 1635 #ifdef ASSERT
dsamersoff@8049 1636 // search through class hierarchy and return true if this class or
dsamersoff@8049 1637 // one of the superclasses was redefined
dsamersoff@8049 1638 bool InstanceKlass::has_redefined_this_or_super() const {
dsamersoff@8049 1639 const InstanceKlass* klass = this;
dsamersoff@8049 1640 while (klass != NULL) {
dsamersoff@8049 1641 if (klass->has_been_redefined()) {
dsamersoff@8049 1642 return true;
dsamersoff@8049 1643 }
dsamersoff@8049 1644 klass = InstanceKlass::cast(klass->super());
dsamersoff@8049 1645 }
dsamersoff@8049 1646 return false;
dsamersoff@8049 1647 }
dsamersoff@8049 1648 #endif
dsamersoff@8049 1649
acorn@5848 1650 // lookup a method in the default methods list then in all transitive interfaces
acorn@5848 1651 // Do NOT return private or static methods
acorn@5848 1652 Method* InstanceKlass::lookup_method_in_ordered_interfaces(Symbol* name,
acorn@5848 1653 Symbol* signature) const {
acorn@5853 1654 Method* m = NULL;
acorn@5848 1655 if (default_methods() != NULL) {
acorn@5848 1656 m = find_method(default_methods(), name, signature);
acorn@5848 1657 }
acorn@5848 1658 // Look up interfaces
acorn@5848 1659 if (m == NULL) {
dbuck@8716 1660 m = lookup_method_in_all_interfaces(name, signature, find_defaults);
acorn@5848 1661 }
acorn@5848 1662 return m;
acorn@5848 1663 }
acorn@5848 1664
duke@435 1665 // lookup a method in all the interfaces that this class implements
acorn@5786 1666 // Do NOT return private or static methods, new in JDK8 which are not externally visible
acorn@5786 1667 // They should only be found in the initial InterfaceMethodRef
coleenp@4037 1668 Method* InstanceKlass::lookup_method_in_all_interfaces(Symbol* name,
hseigel@6195 1669 Symbol* signature,
dbuck@8716 1670 DefaultsLookupMode defaults_mode) const {
coleenp@4037 1671 Array<Klass*>* all_ifs = transitive_interfaces();
duke@435 1672 int num_ifs = all_ifs->length();
coleenp@4037 1673 InstanceKlass *ik = NULL;
duke@435 1674 for (int i = 0; i < num_ifs; i++) {
coleenp@4037 1675 ik = InstanceKlass::cast(all_ifs->at(i));
coleenp@4037 1676 Method* m = ik->lookup_method(name, signature);
hseigel@6195 1677 if (m != NULL && m->is_public() && !m->is_static() &&
dbuck@8716 1678 ((defaults_mode != skip_defaults) || !m->is_default_method())) {
duke@435 1679 return m;
duke@435 1680 }
duke@435 1681 }
duke@435 1682 return NULL;
duke@435 1683 }
duke@435 1684
duke@435 1685 /* jni_id_for_impl for jfieldIds only */
coleenp@4037 1686 JNIid* InstanceKlass::jni_id_for_impl(instanceKlassHandle this_oop, int offset) {
duke@435 1687 MutexLocker ml(JfieldIdCreation_lock);
duke@435 1688 // Retry lookup after we got the lock
duke@435 1689 JNIid* probe = this_oop->jni_ids() == NULL ? NULL : this_oop->jni_ids()->find(offset);
duke@435 1690 if (probe == NULL) {
duke@435 1691 // Slow case, allocate new static field identifier
coleenp@4037 1692 probe = new JNIid(this_oop(), offset, this_oop->jni_ids());
duke@435 1693 this_oop->set_jni_ids(probe);
duke@435 1694 }
duke@435 1695 return probe;
duke@435 1696 }
duke@435 1697
duke@435 1698
duke@435 1699 /* jni_id_for for jfieldIds only */
coleenp@4037 1700 JNIid* InstanceKlass::jni_id_for(int offset) {
duke@435 1701 JNIid* probe = jni_ids() == NULL ? NULL : jni_ids()->find(offset);
duke@435 1702 if (probe == NULL) {
coleenp@4037 1703 probe = jni_id_for_impl(this, offset);
duke@435 1704 }
duke@435 1705 return probe;
duke@435 1706 }
duke@435 1707
coleenp@4037 1708 u2 InstanceKlass::enclosing_method_data(int offset) {
coleenp@4037 1709 Array<jushort>* inner_class_list = inner_classes();
jiangli@3670 1710 if (inner_class_list == NULL) {
jiangli@3670 1711 return 0;
jiangli@3670 1712 }
jiangli@3670 1713 int length = inner_class_list->length();
jiangli@3670 1714 if (length % inner_class_next_offset == 0) {
jiangli@3670 1715 return 0;
jiangli@3670 1716 } else {
jiangli@3670 1717 int index = length - enclosing_method_attribute_size;
jiangli@3670 1718 assert(offset < enclosing_method_attribute_size, "invalid offset");
coleenp@4037 1719 return inner_class_list->at(index + offset);
jiangli@3670 1720 }
jiangli@3670 1721 }
jiangli@3670 1722
coleenp@4037 1723 void InstanceKlass::set_enclosing_method_indices(u2 class_index,
jiangli@3670 1724 u2 method_index) {
coleenp@4037 1725 Array<jushort>* inner_class_list = inner_classes();
jiangli@3670 1726 assert (inner_class_list != NULL, "_inner_classes list is not set up");
jiangli@3670 1727 int length = inner_class_list->length();
jiangli@3670 1728 if (length % inner_class_next_offset == enclosing_method_attribute_size) {
jiangli@3670 1729 int index = length - enclosing_method_attribute_size;
coleenp@4037 1730 inner_class_list->at_put(
jiangli@3670 1731 index + enclosing_method_class_index_offset, class_index);
coleenp@4037 1732 inner_class_list->at_put(
jiangli@3670 1733 index + enclosing_method_method_index_offset, method_index);
jiangli@3670 1734 }
jiangli@3670 1735 }
duke@435 1736
duke@435 1737 // Lookup or create a jmethodID.
dcubed@1412 1738 // This code is called by the VMThread and JavaThreads so the
dcubed@1412 1739 // locking has to be done very carefully to avoid deadlocks
dcubed@1412 1740 // and/or other cache consistency problems.
dcubed@1412 1741 //
coleenp@4037 1742 jmethodID InstanceKlass::get_jmethod_id(instanceKlassHandle ik_h, methodHandle method_h) {
duke@435 1743 size_t idnum = (size_t)method_h->method_idnum();
duke@435 1744 jmethodID* jmeths = ik_h->methods_jmethod_ids_acquire();
duke@435 1745 size_t length = 0;
duke@435 1746 jmethodID id = NULL;
duke@435 1747
dcubed@1412 1748 // We use a double-check locking idiom here because this cache is
dcubed@1412 1749 // performance sensitive. In the normal system, this cache only
dcubed@1412 1750 // transitions from NULL to non-NULL which is safe because we use
dcubed@1412 1751 // release_set_methods_jmethod_ids() to advertise the new cache.
dcubed@1412 1752 // A partially constructed cache should never be seen by a racing
dcubed@1412 1753 // thread. We also use release_store_ptr() to save a new jmethodID
dcubed@1412 1754 // in the cache so a partially constructed jmethodID should never be
dcubed@1412 1755 // seen either. Cache reads of existing jmethodIDs proceed without a
dcubed@1412 1756 // lock, but cache writes of a new jmethodID requires uniqueness and
dcubed@1412 1757 // creation of the cache itself requires no leaks so a lock is
dcubed@1412 1758 // generally acquired in those two cases.
dcubed@1412 1759 //
dcubed@1412 1760 // If the RedefineClasses() API has been used, then this cache can
dcubed@1412 1761 // grow and we'll have transitions from non-NULL to bigger non-NULL.
dcubed@1412 1762 // Cache creation requires no leaks and we require safety between all
dcubed@1412 1763 // cache accesses and freeing of the old cache so a lock is generally
dcubed@1412 1764 // acquired when the RedefineClasses() API has been used.
duke@435 1765
dcubed@1412 1766 if (jmeths != NULL) {
dcubed@1412 1767 // the cache already exists
dcubed@1412 1768 if (!ik_h->idnum_can_increment()) {
dcubed@1412 1769 // the cache can't grow so we can just get the current values
dcubed@1412 1770 get_jmethod_id_length_value(jmeths, idnum, &length, &id);
dcubed@1412 1771 } else {
dcubed@1412 1772 // cache can grow so we have to be more careful
dcubed@1412 1773 if (Threads::number_of_threads() == 0 ||
dcubed@1412 1774 SafepointSynchronize::is_at_safepoint()) {
dcubed@1412 1775 // we're single threaded or at a safepoint - no locking needed
dcubed@1412 1776 get_jmethod_id_length_value(jmeths, idnum, &length, &id);
dcubed@1412 1777 } else {
dcubed@1412 1778 MutexLocker ml(JmethodIdCreation_lock);
dcubed@1412 1779 get_jmethod_id_length_value(jmeths, idnum, &length, &id);
dcubed@1412 1780 }
dcubed@1412 1781 }
dcubed@1412 1782 }
dcubed@1412 1783 // implied else:
dcubed@1412 1784 // we need to allocate a cache so default length and id values are good
dcubed@1412 1785
dcubed@1412 1786 if (jmeths == NULL || // no cache yet
dcubed@1412 1787 length <= idnum || // cache is too short
dcubed@1412 1788 id == NULL) { // cache doesn't contain entry
dcubed@1412 1789
dcubed@1412 1790 // This function can be called by the VMThread so we have to do all
dcubed@1412 1791 // things that might block on a safepoint before grabbing the lock.
dcubed@1412 1792 // Otherwise, we can deadlock with the VMThread or have a cache
dcubed@1412 1793 // consistency issue. These vars keep track of what we might have
dcubed@1412 1794 // to free after the lock is dropped.
dcubed@1412 1795 jmethodID to_dealloc_id = NULL;
dcubed@1412 1796 jmethodID* to_dealloc_jmeths = NULL;
dcubed@1412 1797
dcubed@1412 1798 // may not allocate new_jmeths or use it if we allocate it
duke@435 1799 jmethodID* new_jmeths = NULL;
duke@435 1800 if (length <= idnum) {
dcubed@1412 1801 // allocate a new cache that might be used
duke@435 1802 size_t size = MAX2(idnum+1, (size_t)ik_h->idnum_allocated_count());
zgu@3900 1803 new_jmeths = NEW_C_HEAP_ARRAY(jmethodID, size+1, mtClass);
duke@435 1804 memset(new_jmeths, 0, (size+1)*sizeof(jmethodID));
dcubed@1412 1805 // cache size is stored in element[0], other elements offset by one
dcubed@1412 1806 new_jmeths[0] = (jmethodID)size;
duke@435 1807 }
duke@435 1808
dcubed@1412 1809 // allocate a new jmethodID that might be used
duke@435 1810 jmethodID new_id = NULL;
duke@435 1811 if (method_h->is_old() && !method_h->is_obsolete()) {
duke@435 1812 // The method passed in is old (but not obsolete), we need to use the current version
coleenp@4037 1813 Method* current_method = ik_h->method_with_idnum((int)idnum);
duke@435 1814 assert(current_method != NULL, "old and but not obsolete, so should exist");
coleenp@4037 1815 new_id = Method::make_jmethod_id(ik_h->class_loader_data(), current_method);
duke@435 1816 } else {
duke@435 1817 // It is the current version of the method or an obsolete method,
duke@435 1818 // use the version passed in
coleenp@4037 1819 new_id = Method::make_jmethod_id(ik_h->class_loader_data(), method_h());
duke@435 1820 }
duke@435 1821
dcubed@1412 1822 if (Threads::number_of_threads() == 0 ||
dcubed@1412 1823 SafepointSynchronize::is_at_safepoint()) {
dcubed@1412 1824 // we're single threaded or at a safepoint - no locking needed
dcubed@1412 1825 id = get_jmethod_id_fetch_or_update(ik_h, idnum, new_id, new_jmeths,
dcubed@1412 1826 &to_dealloc_id, &to_dealloc_jmeths);
dcubed@484 1827 } else {
duke@435 1828 MutexLocker ml(JmethodIdCreation_lock);
dcubed@1412 1829 id = get_jmethod_id_fetch_or_update(ik_h, idnum, new_id, new_jmeths,
dcubed@1412 1830 &to_dealloc_id, &to_dealloc_jmeths);
dcubed@1412 1831 }
dcubed@1412 1832
dcubed@1412 1833 // The lock has been dropped so we can free resources.
dcubed@1412 1834 // Free up either the old cache or the new cache if we allocated one.
dcubed@1412 1835 if (to_dealloc_jmeths != NULL) {
dcubed@1412 1836 FreeHeap(to_dealloc_jmeths);
dcubed@1412 1837 }
dcubed@1412 1838 // free up the new ID since it wasn't needed
dcubed@1412 1839 if (to_dealloc_id != NULL) {
coleenp@4037 1840 Method::destroy_jmethod_id(ik_h->class_loader_data(), to_dealloc_id);
dcubed@484 1841 }
dcubed@484 1842 }
dcubed@484 1843 return id;
dcubed@484 1844 }
duke@435 1845
duke@435 1846
dcubed@1412 1847 // Common code to fetch the jmethodID from the cache or update the
dcubed@1412 1848 // cache with the new jmethodID. This function should never do anything
dcubed@1412 1849 // that causes the caller to go to a safepoint or we can deadlock with
dcubed@1412 1850 // the VMThread or have cache consistency issues.
dcubed@1412 1851 //
coleenp@4037 1852 jmethodID InstanceKlass::get_jmethod_id_fetch_or_update(
dcubed@1412 1853 instanceKlassHandle ik_h, size_t idnum, jmethodID new_id,
dcubed@1412 1854 jmethodID* new_jmeths, jmethodID* to_dealloc_id_p,
dcubed@1412 1855 jmethodID** to_dealloc_jmeths_p) {
dcubed@1412 1856 assert(new_id != NULL, "sanity check");
dcubed@1412 1857 assert(to_dealloc_id_p != NULL, "sanity check");
dcubed@1412 1858 assert(to_dealloc_jmeths_p != NULL, "sanity check");
dcubed@1412 1859 assert(Threads::number_of_threads() == 0 ||
dcubed@1412 1860 SafepointSynchronize::is_at_safepoint() ||
dcubed@1412 1861 JmethodIdCreation_lock->owned_by_self(), "sanity check");
dcubed@1412 1862
dcubed@1412 1863 // reacquire the cache - we are locked, single threaded or at a safepoint
dcubed@484 1864 jmethodID* jmeths = ik_h->methods_jmethod_ids_acquire();
dcubed@1412 1865 jmethodID id = NULL;
dcubed@1412 1866 size_t length = 0;
dcubed@484 1867
dcubed@1412 1868 if (jmeths == NULL || // no cache yet
dcubed@1412 1869 (length = (size_t)jmeths[0]) <= idnum) { // cache is too short
dcubed@484 1870 if (jmeths != NULL) {
dcubed@1412 1871 // copy any existing entries from the old cache
dcubed@484 1872 for (size_t index = 0; index < length; index++) {
dcubed@484 1873 new_jmeths[index+1] = jmeths[index+1];
duke@435 1874 }
dcubed@1412 1875 *to_dealloc_jmeths_p = jmeths; // save old cache for later delete
duke@435 1876 }
dcubed@484 1877 ik_h->release_set_methods_jmethod_ids(jmeths = new_jmeths);
dcubed@484 1878 } else {
dcubed@1412 1879 // fetch jmethodID (if any) from the existing cache
dcubed@484 1880 id = jmeths[idnum+1];
dcubed@1412 1881 *to_dealloc_jmeths_p = new_jmeths; // save new cache for later delete
dcubed@484 1882 }
dcubed@484 1883 if (id == NULL) {
dcubed@1412 1884 // No matching jmethodID in the existing cache or we have a new
dcubed@1412 1885 // cache or we just grew the cache. This cache write is done here
dcubed@1412 1886 // by the first thread to win the foot race because a jmethodID
dcubed@1412 1887 // needs to be unique once it is generally available.
dcubed@484 1888 id = new_id;
dcubed@1412 1889
dcubed@1412 1890 // The jmethodID cache can be read while unlocked so we have to
dcubed@1412 1891 // make sure the new jmethodID is complete before installing it
dcubed@1412 1892 // in the cache.
dcubed@1412 1893 OrderAccess::release_store_ptr(&jmeths[idnum+1], id);
dcubed@484 1894 } else {
dcubed@1412 1895 *to_dealloc_id_p = new_id; // save new id for later delete
duke@435 1896 }
duke@435 1897 return id;
duke@435 1898 }
duke@435 1899
duke@435 1900
dcubed@1412 1901 // Common code to get the jmethodID cache length and the jmethodID
dcubed@1412 1902 // value at index idnum if there is one.
dcubed@1412 1903 //
coleenp@4037 1904 void InstanceKlass::get_jmethod_id_length_value(jmethodID* cache,
dcubed@1412 1905 size_t idnum, size_t *length_p, jmethodID* id_p) {
dcubed@1412 1906 assert(cache != NULL, "sanity check");
dcubed@1412 1907 assert(length_p != NULL, "sanity check");
dcubed@1412 1908 assert(id_p != NULL, "sanity check");
dcubed@1412 1909
dcubed@1412 1910 // cache size is stored in element[0], other elements offset by one
dcubed@1412 1911 *length_p = (size_t)cache[0];
dcubed@1412 1912 if (*length_p <= idnum) { // cache is too short
dcubed@1412 1913 *id_p = NULL;
dcubed@1412 1914 } else {
dcubed@1412 1915 *id_p = cache[idnum+1]; // fetch jmethodID (if any)
dcubed@1412 1916 }
dcubed@1412 1917 }
dcubed@1412 1918
dcubed@1412 1919
duke@435 1920 // Lookup a jmethodID, NULL if not found. Do no blocking, no allocations, no handles
coleenp@4037 1921 jmethodID InstanceKlass::jmethod_id_or_null(Method* method) {
duke@435 1922 size_t idnum = (size_t)method->method_idnum();
duke@435 1923 jmethodID* jmeths = methods_jmethod_ids_acquire();
duke@435 1924 size_t length; // length assigned as debugging crumb
duke@435 1925 jmethodID id = NULL;
dcubed@1412 1926 if (jmeths != NULL && // If there is a cache
duke@435 1927 (length = (size_t)jmeths[0]) > idnum) { // and if it is long enough,
duke@435 1928 id = jmeths[idnum+1]; // Look up the id (may be NULL)
duke@435 1929 }
duke@435 1930 return id;
duke@435 1931 }
duke@435 1932
stefank@6992 1933 int nmethodBucket::decrement() {
stefank@6992 1934 return Atomic::add(-1, (volatile int *)&_count);
stefank@6992 1935 }
duke@435 1936
duke@435 1937 //
duke@435 1938 // Walk the list of dependent nmethods searching for nmethods which
twisti@3050 1939 // are dependent on the changes that were passed in and mark them for
duke@435 1940 // deoptimization. Returns the number of nmethods found.
duke@435 1941 //
coleenp@4037 1942 int InstanceKlass::mark_dependent_nmethods(DepChange& changes) {
duke@435 1943 assert_locked_or_safepoint(CodeCache_lock);
duke@435 1944 int found = 0;
duke@435 1945 nmethodBucket* b = _dependencies;
duke@435 1946 while (b != NULL) {
duke@435 1947 nmethod* nm = b->get_nmethod();
duke@435 1948 // since dependencies aren't removed until an nmethod becomes a zombie,
duke@435 1949 // the dependency list may contain nmethods which aren't alive.
stefank@6992 1950 if (b->count() > 0 && nm->is_alive() && !nm->is_marked_for_deoptimization() && nm->check_dependency_on(changes)) {
duke@435 1951 if (TraceDependencies) {
duke@435 1952 ResourceMark rm;
duke@435 1953 tty->print_cr("Marked for deoptimization");
duke@435 1954 tty->print_cr(" context = %s", this->external_name());
duke@435 1955 changes.print();
duke@435 1956 nm->print();
duke@435 1957 nm->print_dependencies();
duke@435 1958 }
duke@435 1959 nm->mark_for_deoptimization();
duke@435 1960 found++;
duke@435 1961 }
duke@435 1962 b = b->next();
duke@435 1963 }
duke@435 1964 return found;
duke@435 1965 }
duke@435 1966
stefank@6992 1967 void InstanceKlass::clean_dependent_nmethods() {
stefank@6992 1968 assert_locked_or_safepoint(CodeCache_lock);
stefank@6992 1969
stefank@6992 1970 if (has_unloaded_dependent()) {
stefank@6992 1971 nmethodBucket* b = _dependencies;
stefank@6992 1972 nmethodBucket* last = NULL;
stefank@6992 1973 while (b != NULL) {
stefank@6992 1974 assert(b->count() >= 0, err_msg("bucket count: %d", b->count()));
stefank@6992 1975
stefank@6992 1976 nmethodBucket* next = b->next();
stefank@6992 1977
stefank@6992 1978 if (b->count() == 0) {
stefank@6992 1979 if (last == NULL) {
stefank@6992 1980 _dependencies = next;
stefank@6992 1981 } else {
stefank@6992 1982 last->set_next(next);
stefank@6992 1983 }
stefank@6992 1984 delete b;
stefank@6992 1985 // last stays the same.
stefank@6992 1986 } else {
stefank@6992 1987 last = b;
stefank@6992 1988 }
stefank@6992 1989
stefank@6992 1990 b = next;
stefank@6992 1991 }
stefank@6992 1992 set_has_unloaded_dependent(false);
stefank@6992 1993 }
stefank@6992 1994 #ifdef ASSERT
stefank@6992 1995 else {
stefank@6992 1996 // Verification
stefank@6992 1997 for (nmethodBucket* b = _dependencies; b != NULL; b = b->next()) {
stefank@6992 1998 assert(b->count() >= 0, err_msg("bucket count: %d", b->count()));
stefank@6992 1999 assert(b->count() != 0, "empty buckets need to be cleaned");
stefank@6992 2000 }
stefank@6992 2001 }
stefank@6992 2002 #endif
stefank@6992 2003 }
duke@435 2004
duke@435 2005 //
duke@435 2006 // Add an nmethodBucket to the list of dependencies for this nmethod.
duke@435 2007 // It's possible that an nmethod has multiple dependencies on this klass
duke@435 2008 // so a count is kept for each bucket to guarantee that creation and
duke@435 2009 // deletion of dependencies is consistent.
duke@435 2010 //
coleenp@4037 2011 void InstanceKlass::add_dependent_nmethod(nmethod* nm) {
duke@435 2012 assert_locked_or_safepoint(CodeCache_lock);
duke@435 2013 nmethodBucket* b = _dependencies;
duke@435 2014 nmethodBucket* last = NULL;
duke@435 2015 while (b != NULL) {
duke@435 2016 if (nm == b->get_nmethod()) {
duke@435 2017 b->increment();
duke@435 2018 return;
duke@435 2019 }
duke@435 2020 b = b->next();
duke@435 2021 }
duke@435 2022 _dependencies = new nmethodBucket(nm, _dependencies);
duke@435 2023 }
duke@435 2024
duke@435 2025
duke@435 2026 //
duke@435 2027 // Decrement count of the nmethod in the dependency list and remove
duke@435 2028 // the bucket competely when the count goes to 0. This method must
duke@435 2029 // find a corresponding bucket otherwise there's a bug in the
duke@435 2030 // recording of dependecies.
duke@435 2031 //
stefank@8185 2032 void InstanceKlass::remove_dependent_nmethod(nmethod* nm, bool delete_immediately) {
duke@435 2033 assert_locked_or_safepoint(CodeCache_lock);
duke@435 2034 nmethodBucket* b = _dependencies;
duke@435 2035 nmethodBucket* last = NULL;
duke@435 2036 while (b != NULL) {
duke@435 2037 if (nm == b->get_nmethod()) {
stefank@6992 2038 int val = b->decrement();
stefank@6992 2039 guarantee(val >= 0, err_msg("Underflow: %d", val));
stefank@6992 2040 if (val == 0) {
stefank@8185 2041 if (delete_immediately) {
stefank@8185 2042 if (last == NULL) {
stefank@8185 2043 _dependencies = b->next();
stefank@8185 2044 } else {
stefank@8185 2045 last->set_next(b->next());
stefank@8185 2046 }
stefank@8185 2047 delete b;
stefank@8185 2048 } else {
stefank@8185 2049 // The deletion of this entry is deferred until a later, potentially parallel GC phase.
stefank@8185 2050 set_has_unloaded_dependent(true);
stefank@8185 2051 }
duke@435 2052 }
duke@435 2053 return;
duke@435 2054 }
duke@435 2055 last = b;
duke@435 2056 b = b->next();
duke@435 2057 }
duke@435 2058 #ifdef ASSERT
duke@435 2059 tty->print_cr("### %s can't find dependent nmethod:", this->external_name());
duke@435 2060 nm->print();
duke@435 2061 #endif // ASSERT
duke@435 2062 ShouldNotReachHere();
duke@435 2063 }
duke@435 2064
duke@435 2065
duke@435 2066 #ifndef PRODUCT
coleenp@4037 2067 void InstanceKlass::print_dependent_nmethods(bool verbose) {
duke@435 2068 nmethodBucket* b = _dependencies;
duke@435 2069 int idx = 0;
duke@435 2070 while (b != NULL) {
duke@435 2071 nmethod* nm = b->get_nmethod();
duke@435 2072 tty->print("[%d] count=%d { ", idx++, b->count());
duke@435 2073 if (!verbose) {
duke@435 2074 nm->print_on(tty, "nmethod");
duke@435 2075 tty->print_cr(" } ");
duke@435 2076 } else {
duke@435 2077 nm->print();
duke@435 2078 nm->print_dependencies();
duke@435 2079 tty->print_cr("--- } ");
duke@435 2080 }
duke@435 2081 b = b->next();
duke@435 2082 }
duke@435 2083 }
duke@435 2084
duke@435 2085
coleenp@4037 2086 bool InstanceKlass::is_dependent_nmethod(nmethod* nm) {
duke@435 2087 nmethodBucket* b = _dependencies;
duke@435 2088 while (b != NULL) {
duke@435 2089 if (nm == b->get_nmethod()) {
stefank@6992 2090 #ifdef ASSERT
stefank@6992 2091 int count = b->count();
ehelin@6993 2092 assert(count >= 0, err_msg("count shouldn't be negative: %d", count));
stefank@6992 2093 #endif
duke@435 2094 return true;
duke@435 2095 }
duke@435 2096 b = b->next();
duke@435 2097 }
duke@435 2098 return false;
duke@435 2099 }
duke@435 2100 #endif //PRODUCT
duke@435 2101
duke@435 2102
coleenp@4037 2103 // Garbage collection
coleenp@4037 2104
coleenp@548 2105 #ifdef ASSERT
coleenp@548 2106 template <class T> void assert_is_in(T *p) {
coleenp@548 2107 T heap_oop = oopDesc::load_heap_oop(p);
coleenp@548 2108 if (!oopDesc::is_null(heap_oop)) {
coleenp@548 2109 oop o = oopDesc::decode_heap_oop_not_null(heap_oop);
coleenp@548 2110 assert(Universe::heap()->is_in(o), "should be in heap");
coleenp@548 2111 }
coleenp@548 2112 }
coleenp@548 2113 template <class T> void assert_is_in_closed_subset(T *p) {
coleenp@548 2114 T heap_oop = oopDesc::load_heap_oop(p);
coleenp@548 2115 if (!oopDesc::is_null(heap_oop)) {
coleenp@548 2116 oop o = oopDesc::decode_heap_oop_not_null(heap_oop);
coleenp@4037 2117 assert(Universe::heap()->is_in_closed_subset(o),
coleenp@4037 2118 err_msg("should be in closed *p " INTPTR_FORMAT " " INTPTR_FORMAT, (address)p, (address)o));
coleenp@548 2119 }
coleenp@548 2120 }
coleenp@548 2121 template <class T> void assert_is_in_reserved(T *p) {
coleenp@548 2122 T heap_oop = oopDesc::load_heap_oop(p);
coleenp@548 2123 if (!oopDesc::is_null(heap_oop)) {
coleenp@548 2124 oop o = oopDesc::decode_heap_oop_not_null(heap_oop);
coleenp@548 2125 assert(Universe::heap()->is_in_reserved(o), "should be in reserved");
coleenp@548 2126 }
coleenp@548 2127 }
coleenp@548 2128 template <class T> void assert_nothing(T *p) {}
coleenp@548 2129
coleenp@548 2130 #else
coleenp@548 2131 template <class T> void assert_is_in(T *p) {}
coleenp@548 2132 template <class T> void assert_is_in_closed_subset(T *p) {}
coleenp@548 2133 template <class T> void assert_is_in_reserved(T *p) {}
coleenp@548 2134 template <class T> void assert_nothing(T *p) {}
coleenp@548 2135 #endif // ASSERT
coleenp@548 2136
coleenp@548 2137 //
coleenp@548 2138 // Macros that iterate over areas of oops which are specialized on type of
coleenp@548 2139 // oop pointer either narrow or wide, depending on UseCompressedOops
coleenp@548 2140 //
coleenp@548 2141 // Parameters are:
coleenp@548 2142 // T - type of oop to point to (either oop or narrowOop)
coleenp@548 2143 // start_p - starting pointer for region to iterate over
coleenp@548 2144 // count - number of oops or narrowOops to iterate over
coleenp@548 2145 // do_oop - action to perform on each oop (it's arbitrary C code which
coleenp@548 2146 // makes it more efficient to put in a macro rather than making
coleenp@548 2147 // it a template function)
coleenp@548 2148 // assert_fn - assert function which is template function because performance
coleenp@548 2149 // doesn't matter when enabled.
coleenp@548 2150 #define InstanceKlass_SPECIALIZED_OOP_ITERATE( \
coleenp@548 2151 T, start_p, count, do_oop, \
coleenp@548 2152 assert_fn) \
coleenp@548 2153 { \
coleenp@548 2154 T* p = (T*)(start_p); \
coleenp@548 2155 T* const end = p + (count); \
coleenp@548 2156 while (p < end) { \
coleenp@548 2157 (assert_fn)(p); \
coleenp@548 2158 do_oop; \
coleenp@548 2159 ++p; \
coleenp@548 2160 } \
coleenp@548 2161 }
coleenp@548 2162
coleenp@548 2163 #define InstanceKlass_SPECIALIZED_OOP_REVERSE_ITERATE( \
coleenp@548 2164 T, start_p, count, do_oop, \
coleenp@548 2165 assert_fn) \
coleenp@548 2166 { \
coleenp@548 2167 T* const start = (T*)(start_p); \
coleenp@548 2168 T* p = start + (count); \
coleenp@548 2169 while (start < p) { \
coleenp@548 2170 --p; \
coleenp@548 2171 (assert_fn)(p); \
coleenp@548 2172 do_oop; \
coleenp@548 2173 } \
coleenp@548 2174 }
coleenp@548 2175
coleenp@548 2176 #define InstanceKlass_SPECIALIZED_BOUNDED_OOP_ITERATE( \
coleenp@548 2177 T, start_p, count, low, high, \
coleenp@548 2178 do_oop, assert_fn) \
coleenp@548 2179 { \
coleenp@548 2180 T* const l = (T*)(low); \
coleenp@548 2181 T* const h = (T*)(high); \
coleenp@548 2182 assert(mask_bits((intptr_t)l, sizeof(T)-1) == 0 && \
coleenp@548 2183 mask_bits((intptr_t)h, sizeof(T)-1) == 0, \
coleenp@548 2184 "bounded region must be properly aligned"); \
coleenp@548 2185 T* p = (T*)(start_p); \
coleenp@548 2186 T* end = p + (count); \
coleenp@548 2187 if (p < l) p = l; \
coleenp@548 2188 if (end > h) end = h; \
coleenp@548 2189 while (p < end) { \
coleenp@548 2190 (assert_fn)(p); \
coleenp@548 2191 do_oop; \
coleenp@548 2192 ++p; \
coleenp@548 2193 } \
coleenp@548 2194 }
coleenp@548 2195
coleenp@548 2196
coleenp@548 2197 // The following macros call specialized macros, passing either oop or
coleenp@548 2198 // narrowOop as the specialization type. These test the UseCompressedOops
coleenp@548 2199 // flag.
coleenp@548 2200 #define InstanceKlass_OOP_MAP_ITERATE(obj, do_oop, assert_fn) \
coleenp@548 2201 { \
coleenp@548 2202 /* Compute oopmap block range. The common case \
coleenp@548 2203 is nonstatic_oop_map_size == 1. */ \
coleenp@548 2204 OopMapBlock* map = start_of_nonstatic_oop_maps(); \
jcoomes@1373 2205 OopMapBlock* const end_map = map + nonstatic_oop_map_count(); \
coleenp@548 2206 if (UseCompressedOops) { \
coleenp@548 2207 while (map < end_map) { \
coleenp@548 2208 InstanceKlass_SPECIALIZED_OOP_ITERATE(narrowOop, \
jcoomes@1373 2209 obj->obj_field_addr<narrowOop>(map->offset()), map->count(), \
coleenp@548 2210 do_oop, assert_fn) \
coleenp@548 2211 ++map; \
coleenp@548 2212 } \
coleenp@548 2213 } else { \
coleenp@548 2214 while (map < end_map) { \
coleenp@548 2215 InstanceKlass_SPECIALIZED_OOP_ITERATE(oop, \
jcoomes@1373 2216 obj->obj_field_addr<oop>(map->offset()), map->count(), \
coleenp@548 2217 do_oop, assert_fn) \
coleenp@548 2218 ++map; \
coleenp@548 2219 } \
coleenp@548 2220 } \
coleenp@548 2221 }
coleenp@548 2222
coleenp@548 2223 #define InstanceKlass_OOP_MAP_REVERSE_ITERATE(obj, do_oop, assert_fn) \
coleenp@548 2224 { \
coleenp@548 2225 OopMapBlock* const start_map = start_of_nonstatic_oop_maps(); \
jcoomes@1373 2226 OopMapBlock* map = start_map + nonstatic_oop_map_count(); \
coleenp@548 2227 if (UseCompressedOops) { \
coleenp@548 2228 while (start_map < map) { \
coleenp@548 2229 --map; \
coleenp@548 2230 InstanceKlass_SPECIALIZED_OOP_REVERSE_ITERATE(narrowOop, \
jcoomes@1373 2231 obj->obj_field_addr<narrowOop>(map->offset()), map->count(), \
coleenp@548 2232 do_oop, assert_fn) \
coleenp@548 2233 } \
coleenp@548 2234 } else { \
coleenp@548 2235 while (start_map < map) { \
coleenp@548 2236 --map; \
coleenp@548 2237 InstanceKlass_SPECIALIZED_OOP_REVERSE_ITERATE(oop, \
jcoomes@1373 2238 obj->obj_field_addr<oop>(map->offset()), map->count(), \
coleenp@548 2239 do_oop, assert_fn) \
coleenp@548 2240 } \
coleenp@548 2241 } \
coleenp@548 2242 }
coleenp@548 2243
coleenp@548 2244 #define InstanceKlass_BOUNDED_OOP_MAP_ITERATE(obj, low, high, do_oop, \
coleenp@548 2245 assert_fn) \
coleenp@548 2246 { \
coleenp@548 2247 /* Compute oopmap block range. The common case is \
coleenp@548 2248 nonstatic_oop_map_size == 1, so we accept the \
coleenp@548 2249 usually non-existent extra overhead of examining \
coleenp@548 2250 all the maps. */ \
coleenp@548 2251 OopMapBlock* map = start_of_nonstatic_oop_maps(); \
jcoomes@1373 2252 OopMapBlock* const end_map = map + nonstatic_oop_map_count(); \
coleenp@548 2253 if (UseCompressedOops) { \
coleenp@548 2254 while (map < end_map) { \
coleenp@548 2255 InstanceKlass_SPECIALIZED_BOUNDED_OOP_ITERATE(narrowOop, \
jcoomes@1373 2256 obj->obj_field_addr<narrowOop>(map->offset()), map->count(), \
coleenp@548 2257 low, high, \
coleenp@548 2258 do_oop, assert_fn) \
coleenp@548 2259 ++map; \
coleenp@548 2260 } \
coleenp@548 2261 } else { \
coleenp@548 2262 while (map < end_map) { \
coleenp@548 2263 InstanceKlass_SPECIALIZED_BOUNDED_OOP_ITERATE(oop, \
jcoomes@1373 2264 obj->obj_field_addr<oop>(map->offset()), map->count(), \
coleenp@548 2265 low, high, \
coleenp@548 2266 do_oop, assert_fn) \
coleenp@548 2267 ++map; \
coleenp@548 2268 } \
coleenp@548 2269 } \
coleenp@548 2270 }
coleenp@548 2271
coleenp@4037 2272 void InstanceKlass::oop_follow_contents(oop obj) {
coleenp@548 2273 assert(obj != NULL, "can't follow the content of NULL object");
coleenp@4037 2274 MarkSweep::follow_klass(obj->klass());
coleenp@548 2275 InstanceKlass_OOP_MAP_ITERATE( \
coleenp@548 2276 obj, \
coleenp@548 2277 MarkSweep::mark_and_push(p), \
coleenp@548 2278 assert_is_in_closed_subset)
duke@435 2279 }
duke@435 2280
jprovino@4542 2281 #if INCLUDE_ALL_GCS
coleenp@4037 2282 void InstanceKlass::oop_follow_contents(ParCompactionManager* cm,
duke@435 2283 oop obj) {
coleenp@548 2284 assert(obj != NULL, "can't follow the content of NULL object");
coleenp@4037 2285 PSParallelCompact::follow_klass(cm, obj->klass());
coleenp@4037 2286 // Only mark the header and let the scan of the meta-data mark
coleenp@4037 2287 // everything else.
coleenp@548 2288 InstanceKlass_OOP_MAP_ITERATE( \
coleenp@548 2289 obj, \
coleenp@548 2290 PSParallelCompact::mark_and_push(cm, p), \
coleenp@548 2291 assert_is_in)
duke@435 2292 }
jprovino@4542 2293 #endif // INCLUDE_ALL_GCS
duke@435 2294
coleenp@4037 2295 // closure's do_metadata() method dictates whether the given closure should be
duke@435 2296 // applied to the klass ptr in the object header.
duke@435 2297
ysr@777 2298 #define InstanceKlass_OOP_OOP_ITERATE_DEFN(OopClosureType, nv_suffix) \
ysr@777 2299 \
coleenp@4037 2300 int InstanceKlass::oop_oop_iterate##nv_suffix(oop obj, OopClosureType* closure) { \
coleenp@548 2301 SpecializationStats::record_iterate_call##nv_suffix(SpecializationStats::ik);\
coleenp@548 2302 /* header */ \
coleenp@4037 2303 if_do_metadata_checked(closure, nv_suffix) { \
coleenp@4037 2304 closure->do_klass##nv_suffix(obj->klass()); \
coleenp@548 2305 } \
coleenp@548 2306 InstanceKlass_OOP_MAP_ITERATE( \
coleenp@548 2307 obj, \
coleenp@548 2308 SpecializationStats:: \
coleenp@548 2309 record_do_oop_call##nv_suffix(SpecializationStats::ik); \
coleenp@548 2310 (closure)->do_oop##nv_suffix(p), \
coleenp@548 2311 assert_is_in_closed_subset) \
coleenp@548 2312 return size_helper(); \
duke@435 2313 }
duke@435 2314
jprovino@4542 2315 #if INCLUDE_ALL_GCS
ysr@777 2316 #define InstanceKlass_OOP_OOP_ITERATE_BACKWARDS_DEFN(OopClosureType, nv_suffix) \
ysr@777 2317 \
coleenp@4037 2318 int InstanceKlass::oop_oop_iterate_backwards##nv_suffix(oop obj, \
ysr@777 2319 OopClosureType* closure) { \
ysr@777 2320 SpecializationStats::record_iterate_call##nv_suffix(SpecializationStats::ik); \
stefank@6982 2321 \
stefank@6982 2322 assert_should_ignore_metadata(closure, nv_suffix); \
stefank@6982 2323 \
ysr@777 2324 /* instance variables */ \
ysr@777 2325 InstanceKlass_OOP_MAP_REVERSE_ITERATE( \
ysr@777 2326 obj, \
ysr@777 2327 SpecializationStats::record_do_oop_call##nv_suffix(SpecializationStats::ik);\
ysr@777 2328 (closure)->do_oop##nv_suffix(p), \
ysr@777 2329 assert_is_in_closed_subset) \
ysr@777 2330 return size_helper(); \
ysr@777 2331 }
jprovino@4542 2332 #endif // INCLUDE_ALL_GCS
ysr@777 2333
coleenp@548 2334 #define InstanceKlass_OOP_OOP_ITERATE_DEFN_m(OopClosureType, nv_suffix) \
coleenp@548 2335 \
coleenp@4037 2336 int InstanceKlass::oop_oop_iterate##nv_suffix##_m(oop obj, \
coleenp@548 2337 OopClosureType* closure, \
coleenp@548 2338 MemRegion mr) { \
coleenp@548 2339 SpecializationStats::record_iterate_call##nv_suffix(SpecializationStats::ik);\
coleenp@4037 2340 if_do_metadata_checked(closure, nv_suffix) { \
coleenp@4037 2341 if (mr.contains(obj)) { \
coleenp@4037 2342 closure->do_klass##nv_suffix(obj->klass()); \
coleenp@4037 2343 } \
coleenp@548 2344 } \
coleenp@548 2345 InstanceKlass_BOUNDED_OOP_MAP_ITERATE( \
coleenp@548 2346 obj, mr.start(), mr.end(), \
coleenp@548 2347 (closure)->do_oop##nv_suffix(p), \
coleenp@548 2348 assert_is_in_closed_subset) \
coleenp@548 2349 return size_helper(); \
duke@435 2350 }
duke@435 2351
duke@435 2352 ALL_OOP_OOP_ITERATE_CLOSURES_1(InstanceKlass_OOP_OOP_ITERATE_DEFN)
ysr@777 2353 ALL_OOP_OOP_ITERATE_CLOSURES_2(InstanceKlass_OOP_OOP_ITERATE_DEFN)
duke@435 2354 ALL_OOP_OOP_ITERATE_CLOSURES_1(InstanceKlass_OOP_OOP_ITERATE_DEFN_m)
ysr@777 2355 ALL_OOP_OOP_ITERATE_CLOSURES_2(InstanceKlass_OOP_OOP_ITERATE_DEFN_m)
jprovino@4542 2356 #if INCLUDE_ALL_GCS
ysr@777 2357 ALL_OOP_OOP_ITERATE_CLOSURES_1(InstanceKlass_OOP_OOP_ITERATE_BACKWARDS_DEFN)
ysr@777 2358 ALL_OOP_OOP_ITERATE_CLOSURES_2(InstanceKlass_OOP_OOP_ITERATE_BACKWARDS_DEFN)
jprovino@4542 2359 #endif // INCLUDE_ALL_GCS
duke@435 2360
coleenp@4037 2361 int InstanceKlass::oop_adjust_pointers(oop obj) {
duke@435 2362 int size = size_helper();
coleenp@548 2363 InstanceKlass_OOP_MAP_ITERATE( \
coleenp@548 2364 obj, \
coleenp@548 2365 MarkSweep::adjust_pointer(p), \
coleenp@548 2366 assert_is_in)
duke@435 2367 return size;
duke@435 2368 }
duke@435 2369
jprovino@4542 2370 #if INCLUDE_ALL_GCS
coleenp@4037 2371 void InstanceKlass::oop_push_contents(PSPromotionManager* pm, oop obj) {
coleenp@548 2372 InstanceKlass_OOP_MAP_REVERSE_ITERATE( \
coleenp@548 2373 obj, \
coleenp@548 2374 if (PSScavenge::should_scavenge(p)) { \
coleenp@548 2375 pm->claim_or_forward_depth(p); \
coleenp@548 2376 }, \
coleenp@548 2377 assert_nothing )
duke@435 2378 }
duke@435 2379
coleenp@4037 2380 int InstanceKlass::oop_update_pointers(ParCompactionManager* cm, oop obj) {
coleenp@4037 2381 int size = size_helper();
coleenp@548 2382 InstanceKlass_OOP_MAP_ITERATE( \
coleenp@548 2383 obj, \
coleenp@548 2384 PSParallelCompact::adjust_pointer(p), \
coleenp@4037 2385 assert_is_in)
coleenp@4037 2386 return size;
duke@435 2387 }
duke@435 2388
jprovino@4542 2389 #endif // INCLUDE_ALL_GCS
duke@435 2390
stefank@8185 2391 void InstanceKlass::clean_weak_instanceklass_links(BoolObjectClosure* is_alive) {
stefank@8185 2392 clean_implementors_list(is_alive);
stefank@8185 2393 clean_method_data(is_alive);
stefank@8185 2394
stefank@8185 2395 clean_dependent_nmethods();
stefank@8185 2396 }
stefank@8185 2397
coleenp@4037 2398 void InstanceKlass::clean_implementors_list(BoolObjectClosure* is_alive) {
stefank@6992 2399 assert(class_loader_data()->is_alive(is_alive), "this klass should be live");
jiangli@3701 2400 if (is_interface()) {
jiangli@3701 2401 if (ClassUnloading) {
coleenp@4037 2402 Klass* impl = implementor();
jiangli@3701 2403 if (impl != NULL) {
coleenp@4037 2404 if (!impl->is_loader_alive(is_alive)) {
jiangli@3701 2405 // remove this guy
morris@4693 2406 Klass** klass = adr_implementor();
morris@4693 2407 assert(klass != NULL, "null klass");
morris@4693 2408 if (klass != NULL) {
morris@4693 2409 *klass = NULL;
morris@4693 2410 }
jiangli@3701 2411 }
duke@435 2412 }
duke@435 2413 }
duke@435 2414 }
duke@435 2415 }
duke@435 2416
coleenp@4037 2417 void InstanceKlass::clean_method_data(BoolObjectClosure* is_alive) {
coleenp@4037 2418 for (int m = 0; m < methods()->length(); m++) {
coleenp@4037 2419 MethodData* mdo = methods()->at(m)->method_data();
coleenp@4037 2420 if (mdo != NULL) {
roland@6377 2421 mdo->clean_method_data(is_alive);
coleenp@4037 2422 }
coleenp@4037 2423 }
coleenp@4037 2424 }
coleenp@4037 2425
coleenp@4037 2426
coleenp@4037 2427 static void remove_unshareable_in_class(Klass* k) {
coleenp@4037 2428 // remove klass's unshareable info
coleenp@4037 2429 k->remove_unshareable_info();
coleenp@4037 2430 }
coleenp@4037 2431
coleenp@4037 2432 void InstanceKlass::remove_unshareable_info() {
duke@435 2433 Klass::remove_unshareable_info();
coleenp@4037 2434 // Unlink the class
coleenp@4037 2435 if (is_linked()) {
coleenp@4037 2436 unlink_class();
coleenp@4037 2437 }
duke@435 2438 init_implementor();
coleenp@4037 2439
coleenp@4037 2440 constants()->remove_unshareable_info();
coleenp@4037 2441
coleenp@4037 2442 for (int i = 0; i < methods()->length(); i++) {
coleenp@4037 2443 Method* m = methods()->at(i);
coleenp@4037 2444 m->remove_unshareable_info();
coleenp@4037 2445 }
coleenp@4037 2446
coleenp@4037 2447 // do array classes also.
coleenp@4037 2448 array_klasses_do(remove_unshareable_in_class);
duke@435 2449 }
duke@435 2450
iklam@7089 2451 static void restore_unshareable_in_class(Klass* k, TRAPS) {
iklam@7089 2452 // Array classes have null protection domain.
iklam@7089 2453 // --> see ArrayKlass::complete_create_array_klass()
iklam@7089 2454 k->restore_unshareable_info(ClassLoaderData::the_null_class_loader_data(), Handle(), CHECK);
coleenp@4037 2455 }
coleenp@4037 2456
iklam@7089 2457 void InstanceKlass::restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, TRAPS) {
iklam@7089 2458 Klass::restore_unshareable_info(loader_data, protection_domain, CHECK);
coleenp@4037 2459 instanceKlassHandle ik(THREAD, this);
coleenp@4037 2460
coleenp@4037 2461 Array<Method*>* methods = ik->methods();
coleenp@4037 2462 int num_methods = methods->length();
coleenp@4037 2463 for (int index2 = 0; index2 < num_methods; ++index2) {
coleenp@4037 2464 methodHandle m(THREAD, methods->at(index2));
coleenp@6626 2465 m->restore_unshareable_info(CHECK);
coleenp@4037 2466 }
coleenp@4037 2467 if (JvmtiExport::has_redefined_a_class()) {
coleenp@4037 2468 // Reinitialize vtable because RedefineClasses may have changed some
coleenp@4037 2469 // entries in this vtable for super classes so the CDS vtable might
coleenp@4037 2470 // point to old or obsolete entries. RedefineClasses doesn't fix up
coleenp@4037 2471 // vtables in the shared system dictionary, only the main one.
coleenp@4037 2472 // It also redefines the itable too so fix that too.
coleenp@4037 2473 ResourceMark rm(THREAD);
coleenp@4037 2474 ik->vtable()->initialize_vtable(false, CHECK);
coleenp@4037 2475 ik->itable()->initialize_itable(false, CHECK);
coleenp@4037 2476 }
coleenp@4037 2477
coleenp@4037 2478 // restore constant pool resolved references
coleenp@4037 2479 ik->constants()->restore_unshareable_info(CHECK);
coleenp@4037 2480
coleenp@4037 2481 ik->array_klasses_do(restore_unshareable_in_class, CHECK);
coleenp@4037 2482 }
coleenp@4037 2483
iklam@7089 2484 // returns true IFF is_in_error_state() has been changed as a result of this call.
iklam@7089 2485 bool InstanceKlass::check_sharing_error_state() {
iklam@7089 2486 assert(DumpSharedSpaces, "should only be called during dumping");
iklam@7089 2487 bool old_state = is_in_error_state();
iklam@7089 2488
iklam@7089 2489 if (!is_in_error_state()) {
iklam@7089 2490 bool bad = false;
iklam@7089 2491 for (InstanceKlass* sup = java_super(); sup; sup = sup->java_super()) {
iklam@7089 2492 if (sup->is_in_error_state()) {
iklam@7089 2493 bad = true;
iklam@7089 2494 break;
iklam@7089 2495 }
iklam@7089 2496 }
iklam@7089 2497 if (!bad) {
iklam@7089 2498 Array<Klass*>* interfaces = transitive_interfaces();
iklam@7089 2499 for (int i = 0; i < interfaces->length(); i++) {
iklam@7089 2500 Klass* iface = interfaces->at(i);
iklam@7089 2501 if (InstanceKlass::cast(iface)->is_in_error_state()) {
iklam@7089 2502 bad = true;
iklam@7089 2503 break;
iklam@7089 2504 }
iklam@7089 2505 }
iklam@7089 2506 }
iklam@7089 2507
iklam@7089 2508 if (bad) {
iklam@7089 2509 set_in_error_state();
iklam@7089 2510 }
iklam@7089 2511 }
iklam@7089 2512
iklam@7089 2513 return (old_state != is_in_error_state());
iklam@7089 2514 }
iklam@7089 2515
coleenp@4037 2516 static void clear_all_breakpoints(Method* m) {
duke@435 2517 m->clear_all_breakpoints();
duke@435 2518 }
duke@435 2519
coleenp@4981 2520
coleenp@4981 2521 void InstanceKlass::notify_unload_class(InstanceKlass* ik) {
coleenp@4981 2522 // notify the debugger
coleenp@4981 2523 if (JvmtiExport::should_post_class_unload()) {
coleenp@4981 2524 JvmtiExport::post_class_unload(ik);
coleenp@4981 2525 }
coleenp@4981 2526
coleenp@4981 2527 // notify ClassLoadingService of class unload
coleenp@4981 2528 ClassLoadingService::notify_class_unloaded(ik);
coleenp@4981 2529 }
coleenp@4981 2530
coleenp@4981 2531 void InstanceKlass::release_C_heap_structures(InstanceKlass* ik) {
coleenp@4981 2532 // Clean up C heap
coleenp@4981 2533 ik->release_C_heap_structures();
coleenp@4981 2534 ik->constants()->release_C_heap_structures();
coleenp@4981 2535 }
coleenp@4981 2536
coleenp@4037 2537 void InstanceKlass::release_C_heap_structures() {
coleenp@4981 2538
coleenp@4981 2539 // Can't release the constant pool here because the constant pool can be
coleenp@4981 2540 // deallocated separately from the InstanceKlass for default methods and
coleenp@4981 2541 // redefine classes.
coleenp@4981 2542
duke@435 2543 // Deallocate oop map cache
duke@435 2544 if (_oop_map_cache != NULL) {
duke@435 2545 delete _oop_map_cache;
duke@435 2546 _oop_map_cache = NULL;
duke@435 2547 }
duke@435 2548
duke@435 2549 // Deallocate JNI identifiers for jfieldIDs
duke@435 2550 JNIid::deallocate(jni_ids());
duke@435 2551 set_jni_ids(NULL);
duke@435 2552
duke@435 2553 jmethodID* jmeths = methods_jmethod_ids_acquire();
duke@435 2554 if (jmeths != (jmethodID*)NULL) {
duke@435 2555 release_set_methods_jmethod_ids(NULL);
duke@435 2556 FreeHeap(jmeths);
duke@435 2557 }
duke@435 2558
sspitsyn@5180 2559 // Deallocate MemberNameTable
sspitsyn@5180 2560 {
sspitsyn@5180 2561 Mutex* lock_or_null = SafepointSynchronize::is_at_safepoint() ? NULL : MemberNameTable_lock;
sspitsyn@5180 2562 MutexLockerEx ml(lock_or_null, Mutex::_no_safepoint_check_flag);
sspitsyn@5180 2563 MemberNameTable* mnt = member_names();
sspitsyn@5180 2564 if (mnt != NULL) {
sspitsyn@5180 2565 delete mnt;
sspitsyn@5180 2566 set_member_names(NULL);
sspitsyn@5180 2567 }
sspitsyn@4965 2568 }
sspitsyn@4965 2569
duke@435 2570 // release dependencies
duke@435 2571 nmethodBucket* b = _dependencies;
duke@435 2572 _dependencies = NULL;
duke@435 2573 while (b != NULL) {
duke@435 2574 nmethodBucket* next = b->next();
duke@435 2575 delete b;
duke@435 2576 b = next;
duke@435 2577 }
duke@435 2578
duke@435 2579 // Deallocate breakpoint records
duke@435 2580 if (breakpoints() != 0x0) {
duke@435 2581 methods_do(clear_all_breakpoints);
duke@435 2582 assert(breakpoints() == 0x0, "should have cleared breakpoints");
duke@435 2583 }
duke@435 2584
duke@435 2585 // deallocate the cached class file
jiangli@5421 2586 if (_cached_class_file != NULL) {
jiangli@5421 2587 os::free(_cached_class_file, mtClass);
jiangli@5421 2588 _cached_class_file = NULL;
duke@435 2589 }
coleenp@2497 2590
coleenp@2497 2591 // Decrement symbol reference counts associated with the unloaded class.
coleenp@2497 2592 if (_name != NULL) _name->decrement_refcount();
coleenp@2497 2593 // unreference array name derived from this class name (arrays of an unloaded
coleenp@2497 2594 // class can't be referenced anymore).
coleenp@2497 2595 if (_array_name != NULL) _array_name->decrement_refcount();
fparain@3906 2596 if (_source_debug_extension != NULL) FREE_C_HEAP_ARRAY(char, _source_debug_extension, mtClass);
zgu@4400 2597
zgu@4400 2598 assert(_total_instanceKlass_count >= 1, "Sanity check");
zgu@4400 2599 Atomic::dec(&_total_instanceKlass_count);
coleenp@2497 2600 }
coleenp@2497 2601
coleenp@4037 2602 void InstanceKlass::set_source_debug_extension(char* array, int length) {
fparain@3906 2603 if (array == NULL) {
fparain@3906 2604 _source_debug_extension = NULL;
fparain@3906 2605 } else {
fparain@3906 2606 // Adding one to the attribute length in order to store a null terminator
fparain@3906 2607 // character could cause an overflow because the attribute length is
fparain@3906 2608 // already coded with an u4 in the classfile, but in practice, it's
fparain@3906 2609 // unlikely to happen.
fparain@3906 2610 assert((length+1) > length, "Overflow checking");
fparain@3906 2611 char* sde = NEW_C_HEAP_ARRAY(char, (length + 1), mtClass);
fparain@3906 2612 for (int i = 0; i < length; i++) {
fparain@3906 2613 sde[i] = array[i];
fparain@3906 2614 }
fparain@3906 2615 sde[length] = '\0';
fparain@3906 2616 _source_debug_extension = sde;
fparain@3906 2617 }
duke@435 2618 }
duke@435 2619
coleenp@4037 2620 address InstanceKlass::static_field_addr(int offset) {
hseigel@5784 2621 return (address)(offset + InstanceMirrorKlass::offset_of_static_fields() + cast_from_oop<intptr_t>(java_mirror()));
never@2658 2622 }
never@2658 2623
never@2658 2624
coleenp@4037 2625 const char* InstanceKlass::signature_name() const {
farvidsson@6024 2626 int hash_len = 0;
farvidsson@6024 2627 char hash_buf[40];
farvidsson@6024 2628
farvidsson@6024 2629 // If this is an anonymous class, append a hash to make the name unique
farvidsson@6024 2630 if (is_anonymous()) {
farvidsson@6024 2631 assert(EnableInvokeDynamic, "EnableInvokeDynamic was not set.");
farvidsson@6024 2632 intptr_t hash = (java_mirror() != NULL) ? java_mirror()->identity_hash() : 0;
farvidsson@6024 2633 sprintf(hash_buf, "/" UINTX_FORMAT, (uintx)hash);
farvidsson@6024 2634 hash_len = (int)strlen(hash_buf);
farvidsson@6024 2635 }
farvidsson@6024 2636
farvidsson@6024 2637 // Get the internal name as a c string
duke@435 2638 const char* src = (const char*) (name()->as_C_string());
duke@435 2639 const int src_length = (int)strlen(src);
farvidsson@6024 2640
farvidsson@6024 2641 char* dest = NEW_RESOURCE_ARRAY(char, src_length + hash_len + 3);
farvidsson@6024 2642
farvidsson@6024 2643 // Add L as type indicator
duke@435 2644 int dest_index = 0;
duke@435 2645 dest[dest_index++] = 'L';
farvidsson@6024 2646
farvidsson@6024 2647 // Add the actual class name
farvidsson@6024 2648 for (int src_index = 0; src_index < src_length; ) {
duke@435 2649 dest[dest_index++] = src[src_index++];
duke@435 2650 }
farvidsson@6024 2651
farvidsson@6024 2652 // If we have a hash, append it
farvidsson@6024 2653 for (int hash_index = 0; hash_index < hash_len; ) {
farvidsson@6024 2654 dest[dest_index++] = hash_buf[hash_index++];
farvidsson@6024 2655 }
farvidsson@6024 2656
farvidsson@6024 2657 // Add the semicolon and the NULL
duke@435 2658 dest[dest_index++] = ';';
duke@435 2659 dest[dest_index] = '\0';
duke@435 2660 return dest;
duke@435 2661 }
duke@435 2662
duke@435 2663 // different verisons of is_same_class_package
coleenp@4037 2664 bool InstanceKlass::is_same_class_package(Klass* class2) {
coleenp@4037 2665 Klass* class1 = this;
coleenp@4037 2666 oop classloader1 = InstanceKlass::cast(class1)->class_loader();
hseigel@4278 2667 Symbol* classname1 = class1->name();
hseigel@4278 2668
hseigel@4278 2669 if (class2->oop_is_objArray()) {
coleenp@4142 2670 class2 = ObjArrayKlass::cast(class2)->bottom_klass();
duke@435 2671 }
duke@435 2672 oop classloader2;
hseigel@4278 2673 if (class2->oop_is_instance()) {
coleenp@4037 2674 classloader2 = InstanceKlass::cast(class2)->class_loader();
duke@435 2675 } else {
hseigel@4278 2676 assert(class2->oop_is_typeArray(), "should be type array");
duke@435 2677 classloader2 = NULL;
duke@435 2678 }
hseigel@4278 2679 Symbol* classname2 = class2->name();
duke@435 2680
coleenp@4037 2681 return InstanceKlass::is_same_class_package(classloader1, classname1,
duke@435 2682 classloader2, classname2);
duke@435 2683 }
duke@435 2684
coleenp@4037 2685 bool InstanceKlass::is_same_class_package(oop classloader2, Symbol* classname2) {
coleenp@4037 2686 Klass* class1 = this;
coleenp@4037 2687 oop classloader1 = InstanceKlass::cast(class1)->class_loader();
hseigel@4278 2688 Symbol* classname1 = class1->name();
duke@435 2689
coleenp@4037 2690 return InstanceKlass::is_same_class_package(classloader1, classname1,
duke@435 2691 classloader2, classname2);
duke@435 2692 }
duke@435 2693
duke@435 2694 // return true if two classes are in the same package, classloader
duke@435 2695 // and classname information is enough to determine a class's package
coleenp@4037 2696 bool InstanceKlass::is_same_class_package(oop class_loader1, Symbol* class_name1,
coleenp@2497 2697 oop class_loader2, Symbol* class_name2) {
duke@435 2698 if (class_loader1 != class_loader2) {
duke@435 2699 return false;
jrose@1100 2700 } else if (class_name1 == class_name2) {
jrose@1100 2701 return true; // skip painful bytewise comparison
duke@435 2702 } else {
duke@435 2703 ResourceMark rm;
duke@435 2704
coleenp@2497 2705 // The Symbol*'s are in UTF8 encoding. Since we only need to check explicitly
duke@435 2706 // for ASCII characters ('/', 'L', '['), we can keep them in UTF8 encoding.
duke@435 2707 // Otherwise, we just compare jbyte values between the strings.
coleenp@2497 2708 const jbyte *name1 = class_name1->base();
coleenp@2497 2709 const jbyte *name2 = class_name2->base();
coleenp@2497 2710
coleenp@2497 2711 const jbyte *last_slash1 = UTF8::strrchr(name1, class_name1->utf8_length(), '/');
coleenp@2497 2712 const jbyte *last_slash2 = UTF8::strrchr(name2, class_name2->utf8_length(), '/');
duke@435 2713
duke@435 2714 if ((last_slash1 == NULL) || (last_slash2 == NULL)) {
duke@435 2715 // One of the two doesn't have a package. Only return true
duke@435 2716 // if the other one also doesn't have a package.
duke@435 2717 return last_slash1 == last_slash2;
duke@435 2718 } else {
duke@435 2719 // Skip over '['s
duke@435 2720 if (*name1 == '[') {
duke@435 2721 do {
duke@435 2722 name1++;
duke@435 2723 } while (*name1 == '[');
duke@435 2724 if (*name1 != 'L') {
duke@435 2725 // Something is terribly wrong. Shouldn't be here.
duke@435 2726 return false;
duke@435 2727 }
duke@435 2728 }
duke@435 2729 if (*name2 == '[') {
duke@435 2730 do {
duke@435 2731 name2++;
duke@435 2732 } while (*name2 == '[');
duke@435 2733 if (*name2 != 'L') {
duke@435 2734 // Something is terribly wrong. Shouldn't be here.
duke@435 2735 return false;
duke@435 2736 }
duke@435 2737 }
duke@435 2738
duke@435 2739 // Check that package part is identical
duke@435 2740 int length1 = last_slash1 - name1;
duke@435 2741 int length2 = last_slash2 - name2;
duke@435 2742
duke@435 2743 return UTF8::equal(name1, length1, name2, length2);
duke@435 2744 }
duke@435 2745 }
duke@435 2746 }
duke@435 2747
acorn@1087 2748 // Returns true iff super_method can be overridden by a method in targetclassname
acorn@1087 2749 // See JSL 3rd edition 8.4.6.1
acorn@1087 2750 // Assumes name-signature match
coleenp@4037 2751 // "this" is InstanceKlass of super_method which must exist
coleenp@4037 2752 // note that the InstanceKlass of the method in the targetclassname has not always been created yet
coleenp@4037 2753 bool InstanceKlass::is_override(methodHandle super_method, Handle targetclassloader, Symbol* targetclassname, TRAPS) {
acorn@1087 2754 // Private methods can not be overridden
acorn@1087 2755 if (super_method->is_private()) {
acorn@1087 2756 return false;
acorn@1087 2757 }
acorn@1087 2758 // If super method is accessible, then override
acorn@1087 2759 if ((super_method->is_protected()) ||
acorn@1087 2760 (super_method->is_public())) {
acorn@1087 2761 return true;
acorn@1087 2762 }
acorn@1087 2763 // Package-private methods are not inherited outside of package
acorn@1087 2764 assert(super_method->is_package_private(), "must be package private");
coleenp@2497 2765 return(is_same_class_package(targetclassloader(), targetclassname));
acorn@1087 2766 }
twisti@1040 2767
jrose@1100 2768 /* defined for now in jvm.cpp, for historical reasons *--
coleenp@4037 2769 Klass* InstanceKlass::compute_enclosing_class_impl(instanceKlassHandle self,
coleenp@2497 2770 Symbol*& simple_name_result, TRAPS) {
jrose@1100 2771 ...
jrose@1100 2772 }
jrose@1100 2773 */
jrose@1100 2774
jrose@1100 2775 // tell if two classes have the same enclosing class (at package level)
coleenp@4037 2776 bool InstanceKlass::is_same_package_member_impl(instanceKlassHandle class1,
coleenp@4037 2777 Klass* class2_oop, TRAPS) {
coleenp@4037 2778 if (class2_oop == class1()) return true;
hseigel@4278 2779 if (!class2_oop->oop_is_instance()) return false;
jrose@1100 2780 instanceKlassHandle class2(THREAD, class2_oop);
jrose@1100 2781
jrose@1100 2782 // must be in same package before we try anything else
jrose@1100 2783 if (!class1->is_same_class_package(class2->class_loader(), class2->name()))
jrose@1100 2784 return false;
jrose@1100 2785
jrose@1100 2786 // As long as there is an outer1.getEnclosingClass,
jrose@1100 2787 // shift the search outward.
jrose@1100 2788 instanceKlassHandle outer1 = class1;
jrose@1100 2789 for (;;) {
jrose@1100 2790 // As we walk along, look for equalities between outer1 and class2.
jrose@1100 2791 // Eventually, the walks will terminate as outer1 stops
jrose@1100 2792 // at the top-level class around the original class.
xlu@1561 2793 bool ignore_inner_is_member;
coleenp@4037 2794 Klass* next = outer1->compute_enclosing_class(&ignore_inner_is_member,
xlu@1561 2795 CHECK_false);
jrose@1100 2796 if (next == NULL) break;
jrose@1100 2797 if (next == class2()) return true;
jrose@1100 2798 outer1 = instanceKlassHandle(THREAD, next);
jrose@1100 2799 }
jrose@1100 2800
jrose@1100 2801 // Now do the same for class2.
jrose@1100 2802 instanceKlassHandle outer2 = class2;
jrose@1100 2803 for (;;) {
xlu@1561 2804 bool ignore_inner_is_member;
coleenp@4037 2805 Klass* next = outer2->compute_enclosing_class(&ignore_inner_is_member,
xlu@1561 2806 CHECK_false);
jrose@1100 2807 if (next == NULL) break;
jrose@1100 2808 // Might as well check the new outer against all available values.
jrose@1100 2809 if (next == class1()) return true;
jrose@1100 2810 if (next == outer1()) return true;
jrose@1100 2811 outer2 = instanceKlassHandle(THREAD, next);
jrose@1100 2812 }
jrose@1100 2813
jrose@1100 2814 // If by this point we have not found an equality between the
jrose@1100 2815 // two classes, we know they are in separate package members.
jrose@1100 2816 return false;
jrose@1100 2817 }
jrose@1100 2818
duke@435 2819
coleenp@4037 2820 jint InstanceKlass::compute_modifier_flags(TRAPS) const {
duke@435 2821 jint access = access_flags().as_int();
duke@435 2822
duke@435 2823 // But check if it happens to be member class.
coleenp@4037 2824 instanceKlassHandle ik(THREAD, this);
jiangli@3670 2825 InnerClassesIterator iter(ik);
jiangli@3670 2826 for (; !iter.done(); iter.next()) {
jiangli@3670 2827 int ioff = iter.inner_class_info_index();
jiangli@3670 2828 // Inner class attribute can be zero, skip it.
jiangli@3670 2829 // Strange but true: JVM spec. allows null inner class refs.
jiangli@3670 2830 if (ioff == 0) continue;
jiangli@3670 2831
jiangli@3670 2832 // only look at classes that are already loaded
jiangli@3670 2833 // since we are looking for the flags for our self.
jiangli@3670 2834 Symbol* inner_name = ik->constants()->klass_name_at(ioff);
jiangli@3670 2835 if ((ik->name() == inner_name)) {
jiangli@3670 2836 // This is really a member class.
jiangli@3670 2837 access = iter.inner_access_flags();
jiangli@3670 2838 break;
duke@435 2839 }
duke@435 2840 }
duke@435 2841 // Remember to strip ACC_SUPER bit
duke@435 2842 return (access & (~JVM_ACC_SUPER)) & JVM_ACC_WRITTEN_FLAGS;
duke@435 2843 }
duke@435 2844
coleenp@4037 2845 jint InstanceKlass::jvmti_class_status() const {
duke@435 2846 jint result = 0;
duke@435 2847
duke@435 2848 if (is_linked()) {
duke@435 2849 result |= JVMTI_CLASS_STATUS_VERIFIED | JVMTI_CLASS_STATUS_PREPARED;
duke@435 2850 }
duke@435 2851
duke@435 2852 if (is_initialized()) {
duke@435 2853 assert(is_linked(), "Class status is not consistent");
duke@435 2854 result |= JVMTI_CLASS_STATUS_INITIALIZED;
duke@435 2855 }
duke@435 2856 if (is_in_error_state()) {
duke@435 2857 result |= JVMTI_CLASS_STATUS_ERROR;
duke@435 2858 }
duke@435 2859 return result;
duke@435 2860 }
duke@435 2861
coleenp@4037 2862 Method* InstanceKlass::method_at_itable(Klass* holder, int index, TRAPS) {
duke@435 2863 itableOffsetEntry* ioe = (itableOffsetEntry*)start_of_itable();
duke@435 2864 int method_table_offset_in_words = ioe->offset()/wordSize;
duke@435 2865 int nof_interfaces = (method_table_offset_in_words - itable_offset_in_words())
duke@435 2866 / itableOffsetEntry::size();
duke@435 2867
duke@435 2868 for (int cnt = 0 ; ; cnt ++, ioe ++) {
twisti@1040 2869 // If the interface isn't implemented by the receiver class,
duke@435 2870 // the VM should throw IncompatibleClassChangeError.
duke@435 2871 if (cnt >= nof_interfaces) {
coleenp@4037 2872 THROW_NULL(vmSymbols::java_lang_IncompatibleClassChangeError());
duke@435 2873 }
duke@435 2874
coleenp@4037 2875 Klass* ik = ioe->interface_klass();
duke@435 2876 if (ik == holder) break;
duke@435 2877 }
duke@435 2878
coleenp@4037 2879 itableMethodEntry* ime = ioe->first_method_entry(this);
coleenp@4037 2880 Method* m = ime[index].method();
duke@435 2881 if (m == NULL) {
coleenp@4037 2882 THROW_NULL(vmSymbols::java_lang_AbstractMethodError());
duke@435 2883 }
duke@435 2884 return m;
duke@435 2885 }
duke@435 2886
acorn@5848 2887
acorn@5848 2888 #if INCLUDE_JVMTI
acorn@5848 2889 // update default_methods for redefineclasses for methods that are
acorn@5848 2890 // not yet in the vtable due to concurrent subclass define and superinterface
acorn@5848 2891 // redefinition
acorn@5848 2892 // Note: those in the vtable, should have been updated via adjust_method_entries
sspitsyn@7636 2893 void InstanceKlass::adjust_default_methods(InstanceKlass* holder, bool* trace_name_printed) {
acorn@5848 2894 // search the default_methods for uses of either obsolete or EMCP methods
acorn@5848 2895 if (default_methods() != NULL) {
sspitsyn@7636 2896 for (int index = 0; index < default_methods()->length(); index ++) {
sspitsyn@7636 2897 Method* old_method = default_methods()->at(index);
sspitsyn@7636 2898 if (old_method == NULL || old_method->method_holder() != holder || !old_method->is_old()) {
sspitsyn@7636 2899 continue; // skip uninteresting entries
sspitsyn@7636 2900 }
sspitsyn@7636 2901 assert(!old_method->is_deleted(), "default methods may not be deleted");
sspitsyn@7636 2902
sspitsyn@7636 2903 Method* new_method = holder->method_with_idnum(old_method->orig_method_idnum());
sspitsyn@7636 2904
sspitsyn@7636 2905 assert(new_method != NULL, "method_with_idnum() should not be NULL");
sspitsyn@7636 2906 assert(old_method != new_method, "sanity check");
sspitsyn@7636 2907
sspitsyn@7636 2908 default_methods()->at_put(index, new_method);
sspitsyn@7636 2909 if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
sspitsyn@7636 2910 if (!(*trace_name_printed)) {
sspitsyn@7636 2911 // RC_TRACE_MESG macro has an embedded ResourceMark
sspitsyn@7636 2912 RC_TRACE_MESG(("adjust: klassname=%s default methods from name=%s",
sspitsyn@7636 2913 external_name(),
sspitsyn@7636 2914 old_method->method_holder()->external_name()));
sspitsyn@7636 2915 *trace_name_printed = true;
acorn@5848 2916 }
sspitsyn@7636 2917 RC_TRACE(0x00100000, ("default method update: %s(%s) ",
sspitsyn@7636 2918 new_method->name()->as_C_string(),
sspitsyn@7636 2919 new_method->signature()->as_C_string()));
acorn@5848 2920 }
acorn@5848 2921 }
acorn@5848 2922 }
acorn@5848 2923 }
acorn@5848 2924 #endif // INCLUDE_JVMTI
acorn@5848 2925
duke@435 2926 // On-stack replacement stuff
coleenp@4037 2927 void InstanceKlass::add_osr_nmethod(nmethod* n) {
xliu@9690 2928 #ifndef PRODUCT
xliu@9690 2929 if (TieredCompilation) {
xliu@9690 2930 nmethod * prev = lookup_osr_nmethod(n->method(), n->osr_entry_bci(), n->comp_level(), true);
xliu@9690 2931 assert(prev == NULL || !prev->is_in_use(),
xliu@9690 2932 "redundunt OSR recompilation detected. memory leak in CodeCache!");
xliu@9690 2933 }
xliu@9690 2934 #endif
duke@435 2935 // only one compilation can be active
duke@435 2936 NEEDS_CLEANUP
duke@435 2937 // This is a short non-blocking critical region, so the no safepoint check is ok.
duke@435 2938 OsrList_lock->lock_without_safepoint_check();
duke@435 2939 assert(n->is_osr_method(), "wrong kind of nmethod");
jrose@1424 2940 n->set_osr_link(osr_nmethods_head());
duke@435 2941 set_osr_nmethods_head(n);
iveresov@2138 2942 // Raise the highest osr level if necessary
iveresov@2138 2943 if (TieredCompilation) {
coleenp@4037 2944 Method* m = n->method();
iveresov@2138 2945 m->set_highest_osr_comp_level(MAX2(m->highest_osr_comp_level(), n->comp_level()));
iveresov@2138 2946 }
duke@435 2947 // Remember to unlock again
duke@435 2948 OsrList_lock->unlock();
iveresov@2138 2949
iveresov@2138 2950 // Get rid of the osr methods for the same bci that have lower levels.
iveresov@2138 2951 if (TieredCompilation) {
iveresov@2138 2952 for (int l = CompLevel_limited_profile; l < n->comp_level(); l++) {
iveresov@2138 2953 nmethod *inv = lookup_osr_nmethod(n->method(), n->osr_entry_bci(), l, true);
iveresov@2138 2954 if (inv != NULL && inv->is_in_use()) {
iveresov@2138 2955 inv->make_not_entrant();
iveresov@2138 2956 }
iveresov@2138 2957 }
iveresov@2138 2958 }
duke@435 2959 }
duke@435 2960
duke@435 2961
coleenp@4037 2962 void InstanceKlass::remove_osr_nmethod(nmethod* n) {
duke@435 2963 // This is a short non-blocking critical region, so the no safepoint check is ok.
duke@435 2964 OsrList_lock->lock_without_safepoint_check();
duke@435 2965 assert(n->is_osr_method(), "wrong kind of nmethod");
duke@435 2966 nmethod* last = NULL;
duke@435 2967 nmethod* cur = osr_nmethods_head();
iveresov@2138 2968 int max_level = CompLevel_none; // Find the max comp level excluding n
coleenp@4037 2969 Method* m = n->method();
duke@435 2970 // Search for match
duke@435 2971 while(cur != NULL && cur != n) {
neliasso@6718 2972 if (TieredCompilation && m == cur->method()) {
iveresov@2138 2973 // Find max level before n
iveresov@2138 2974 max_level = MAX2(max_level, cur->comp_level());
iveresov@2138 2975 }
duke@435 2976 last = cur;
jrose@1424 2977 cur = cur->osr_link();
duke@435 2978 }
iveresov@2138 2979 nmethod* next = NULL;
duke@435 2980 if (cur == n) {
iveresov@2138 2981 next = cur->osr_link();
duke@435 2982 if (last == NULL) {
duke@435 2983 // Remove first element
iveresov@2138 2984 set_osr_nmethods_head(next);
duke@435 2985 } else {
iveresov@2138 2986 last->set_osr_link(next);
duke@435 2987 }
duke@435 2988 }
jrose@1424 2989 n->set_osr_link(NULL);
iveresov@2138 2990 if (TieredCompilation) {
iveresov@2138 2991 cur = next;
iveresov@2138 2992 while (cur != NULL) {
iveresov@2138 2993 // Find max level after n
neliasso@6718 2994 if (m == cur->method()) {
neliasso@6718 2995 max_level = MAX2(max_level, cur->comp_level());
neliasso@6718 2996 }
iveresov@2138 2997 cur = cur->osr_link();
iveresov@2138 2998 }
iveresov@2138 2999 m->set_highest_osr_comp_level(max_level);
iveresov@2138 3000 }
duke@435 3001 // Remember to unlock again
duke@435 3002 OsrList_lock->unlock();
duke@435 3003 }
duke@435 3004
thartmann@7325 3005 int InstanceKlass::mark_osr_nmethods(const Method* m) {
thartmann@7325 3006 // This is a short non-blocking critical region, so the no safepoint check is ok.
thartmann@7325 3007 MutexLockerEx ml(OsrList_lock, Mutex::_no_safepoint_check_flag);
thartmann@7325 3008 nmethod* osr = osr_nmethods_head();
thartmann@7325 3009 int found = 0;
thartmann@7325 3010 while (osr != NULL) {
thartmann@7325 3011 assert(osr->is_osr_method(), "wrong kind of nmethod found in chain");
thartmann@7325 3012 if (osr->method() == m) {
thartmann@7325 3013 osr->mark_for_deoptimization();
thartmann@7325 3014 found++;
thartmann@7325 3015 }
thartmann@7325 3016 osr = osr->osr_link();
thartmann@7325 3017 }
thartmann@7325 3018 return found;
thartmann@7325 3019 }
thartmann@7325 3020
minqi@5097 3021 nmethod* InstanceKlass::lookup_osr_nmethod(const Method* m, int bci, int comp_level, bool match_level) const {
duke@435 3022 // This is a short non-blocking critical region, so the no safepoint check is ok.
duke@435 3023 OsrList_lock->lock_without_safepoint_check();
duke@435 3024 nmethod* osr = osr_nmethods_head();
iveresov@2138 3025 nmethod* best = NULL;
duke@435 3026 while (osr != NULL) {
duke@435 3027 assert(osr->is_osr_method(), "wrong kind of nmethod found in chain");
iveresov@2138 3028 // There can be a time when a c1 osr method exists but we are waiting
iveresov@2138 3029 // for a c2 version. When c2 completes its osr nmethod we will trash
iveresov@2138 3030 // the c1 version and only be able to find the c2 version. However
iveresov@2138 3031 // while we overflow in the c1 code at back branches we don't want to
iveresov@2138 3032 // try and switch to the same code as we are already running
iveresov@2138 3033
duke@435 3034 if (osr->method() == m &&
duke@435 3035 (bci == InvocationEntryBci || osr->osr_entry_bci() == bci)) {
iveresov@2138 3036 if (match_level) {
iveresov@2138 3037 if (osr->comp_level() == comp_level) {
iveresov@2138 3038 // Found a match - return it.
iveresov@2138 3039 OsrList_lock->unlock();
iveresov@2138 3040 return osr;
iveresov@2138 3041 }
iveresov@2138 3042 } else {
iveresov@2138 3043 if (best == NULL || (osr->comp_level() > best->comp_level())) {
iveresov@2138 3044 if (osr->comp_level() == CompLevel_highest_tier) {
iveresov@2138 3045 // Found the best possible - return it.
iveresov@2138 3046 OsrList_lock->unlock();
iveresov@2138 3047 return osr;
iveresov@2138 3048 }
iveresov@2138 3049 best = osr;
iveresov@2138 3050 }
iveresov@2138 3051 }
duke@435 3052 }
jrose@1424 3053 osr = osr->osr_link();
duke@435 3054 }
duke@435 3055 OsrList_lock->unlock();
xliu@9690 3056
xliu@9690 3057 assert(match_level == false || best == NULL, "shouldn't pick up anything if match_level is set");
xliu@9690 3058 if (best != NULL && best->comp_level() >= comp_level) {
iveresov@2138 3059 return best;
iveresov@2138 3060 }
duke@435 3061 return NULL;
duke@435 3062 }
duke@435 3063
kevinw@8721 3064 oop InstanceKlass::add_member_name(Handle mem_name, bool intern) {
sspitsyn@4965 3065 jweak mem_name_wref = JNIHandles::make_weak_global(mem_name);
sspitsyn@4965 3066 MutexLocker ml(MemberNameTable_lock);
sspitsyn@4965 3067 DEBUG_ONLY(No_Safepoint_Verifier nsv);
sspitsyn@4965 3068
coleenp@7391 3069 // Check if method has been redefined while taking out MemberNameTable_lock, if so
coleenp@7391 3070 // return false. We cannot cache obsolete methods. They will crash when the function
coleenp@7391 3071 // is called!
coleenp@7391 3072 Method* method = (Method*)java_lang_invoke_MemberName::vmtarget(mem_name());
coleenp@7391 3073 if (method->is_obsolete()) {
kevinw@8721 3074 return NULL;
coleenp@7391 3075 } else if (method->is_old()) {
coleenp@7391 3076 // Replace method with redefined version
coleenp@7391 3077 java_lang_invoke_MemberName::set_vmtarget(mem_name(), method_with_idnum(method->method_idnum()));
coleenp@7391 3078 }
coleenp@7391 3079
sspitsyn@4965 3080 if (_member_names == NULL) {
sspitsyn@5178 3081 _member_names = new (ResourceObj::C_HEAP, mtClass) MemberNameTable(idnum_allocated_count());
sspitsyn@4965 3082 }
kevinw@8721 3083 if (intern) {
kevinw@8721 3084 return _member_names->find_or_add_member_name(mem_name_wref);
kevinw@8721 3085 } else {
kevinw@8721 3086 return _member_names->add_member_name(mem_name_wref);
kevinw@8721 3087 }
sspitsyn@4965 3088 }
sspitsyn@4965 3089
duke@435 3090 // -----------------------------------------------------------------------------------------------------
coleenp@4037 3091 // Printing
coleenp@4037 3092
duke@435 3093 #ifndef PRODUCT
duke@435 3094
jrose@1100 3095 #define BULLET " - "
jrose@1100 3096
coleenp@4037 3097 static const char* state_names[] = {
coleenp@4037 3098 "allocated", "loaded", "linked", "being_initialized", "fully_initialized", "initialization_error"
coleenp@4037 3099 };
coleenp@4037 3100
drchase@5732 3101 static void print_vtable(intptr_t* start, int len, outputStream* st) {
drchase@5732 3102 for (int i = 0; i < len; i++) {
drchase@5732 3103 intptr_t e = start[i];
drchase@5732 3104 st->print("%d : " INTPTR_FORMAT, i, e);
drchase@5732 3105 if (e != 0 && ((Metadata*)e)->is_metaspace_object()) {
drchase@5732 3106 st->print(" ");
drchase@5732 3107 ((Metadata*)e)->print_value_on(st);
drchase@5732 3108 }
drchase@5732 3109 st->cr();
drchase@5732 3110 }
drchase@5732 3111 }
drchase@5732 3112
coleenp@4037 3113 void InstanceKlass::print_on(outputStream* st) const {
coleenp@4037 3114 assert(is_klass(), "must be klass");
coleenp@4037 3115 Klass::print_on(st);
coleenp@4037 3116
coleenp@4037 3117 st->print(BULLET"instance size: %d", size_helper()); st->cr();
coleenp@4037 3118 st->print(BULLET"klass size: %d", size()); st->cr();
coleenp@4037 3119 st->print(BULLET"access: "); access_flags().print_on(st); st->cr();
drchase@6680 3120 st->print(BULLET"state: "); st->print_cr("%s", state_names[_init_state]);
coleenp@4037 3121 st->print(BULLET"name: "); name()->print_value_on(st); st->cr();
coleenp@4037 3122 st->print(BULLET"super: "); super()->print_value_on_maybe_null(st); st->cr();
coleenp@4037 3123 st->print(BULLET"sub: ");
coleenp@4037 3124 Klass* sub = subklass();
coleenp@4037 3125 int n;
coleenp@4037 3126 for (n = 0; sub != NULL; n++, sub = sub->next_sibling()) {
coleenp@4037 3127 if (n < MaxSubklassPrintSize) {
coleenp@4037 3128 sub->print_value_on(st);
coleenp@4037 3129 st->print(" ");
coleenp@4037 3130 }
coleenp@4037 3131 }
coleenp@4037 3132 if (n >= MaxSubklassPrintSize) st->print("(%d more klasses...)", n - MaxSubklassPrintSize);
coleenp@4037 3133 st->cr();
coleenp@4037 3134
coleenp@4037 3135 if (is_interface()) {
coleenp@4037 3136 st->print_cr(BULLET"nof implementors: %d", nof_implementors());
coleenp@4037 3137 if (nof_implementors() == 1) {
coleenp@4037 3138 st->print_cr(BULLET"implementor: ");
coleenp@4037 3139 st->print(" ");
coleenp@4037 3140 implementor()->print_value_on(st);
coleenp@4037 3141 st->cr();
coleenp@4037 3142 }
coleenp@4037 3143 }
coleenp@4037 3144
coleenp@4037 3145 st->print(BULLET"arrays: "); array_klasses()->print_value_on_maybe_null(st); st->cr();
coleenp@4037 3146 st->print(BULLET"methods: "); methods()->print_value_on(st); st->cr();
drchase@5732 3147 if (Verbose || WizardMode) {
coleenp@4037 3148 Array<Method*>* method_array = methods();
acorn@5848 3149 for (int i = 0; i < method_array->length(); i++) {
coleenp@4037 3150 st->print("%d : ", i); method_array->at(i)->print_value(); st->cr();
coleenp@4037 3151 }
coleenp@4037 3152 }
acorn@5848 3153 st->print(BULLET"method ordering: "); method_ordering()->print_value_on(st); st->cr();
acorn@5848 3154 st->print(BULLET"default_methods: "); default_methods()->print_value_on(st); st->cr();
acorn@5848 3155 if (Verbose && default_methods() != NULL) {
acorn@5848 3156 Array<Method*>* method_array = default_methods();
acorn@5848 3157 for (int i = 0; i < method_array->length(); i++) {
acorn@5848 3158 st->print("%d : ", i); method_array->at(i)->print_value(); st->cr();
acorn@5848 3159 }
acorn@5848 3160 }
acorn@5848 3161 if (default_vtable_indices() != NULL) {
acorn@5848 3162 st->print(BULLET"default vtable indices: "); default_vtable_indices()->print_value_on(st); st->cr();
acorn@5848 3163 }
coleenp@4037 3164 st->print(BULLET"local interfaces: "); local_interfaces()->print_value_on(st); st->cr();
coleenp@4037 3165 st->print(BULLET"trans. interfaces: "); transitive_interfaces()->print_value_on(st); st->cr();
coleenp@4037 3166 st->print(BULLET"constants: "); constants()->print_value_on(st); st->cr();
coleenp@4037 3167 if (class_loader_data() != NULL) {
coleenp@4037 3168 st->print(BULLET"class loader data: ");
coleenp@4037 3169 class_loader_data()->print_value_on(st);
coleenp@4037 3170 st->cr();
coleenp@4037 3171 }
coleenp@4037 3172 st->print(BULLET"host class: "); host_klass()->print_value_on_maybe_null(st); st->cr();
coleenp@4037 3173 if (source_file_name() != NULL) {
coleenp@4037 3174 st->print(BULLET"source file: ");
coleenp@4037 3175 source_file_name()->print_value_on(st);
coleenp@4037 3176 st->cr();
coleenp@4037 3177 }
coleenp@4037 3178 if (source_debug_extension() != NULL) {
coleenp@4037 3179 st->print(BULLET"source debug extension: ");
coleenp@4037 3180 st->print("%s", source_debug_extension());
coleenp@4037 3181 st->cr();
coleenp@4037 3182 }
coleenp@4572 3183 st->print(BULLET"class annotations: "); class_annotations()->print_value_on(st); st->cr();
coleenp@4572 3184 st->print(BULLET"class type annotations: "); class_type_annotations()->print_value_on(st); st->cr();
coleenp@4572 3185 st->print(BULLET"field annotations: "); fields_annotations()->print_value_on(st); st->cr();
coleenp@4572 3186 st->print(BULLET"field type annotations: "); fields_type_annotations()->print_value_on(st); st->cr();
coleenp@4037 3187 {
coleenp@5749 3188 bool have_pv = false;
kevinw@9184 3189 // previous versions are linked together through the InstanceKlass
kevinw@9184 3190 for (InstanceKlass* pv_node = _previous_versions;
kevinw@9184 3191 pv_node != NULL;
kevinw@9184 3192 pv_node = pv_node->previous_versions()) {
coleenp@5749 3193 if (!have_pv)
coleenp@5749 3194 st->print(BULLET"previous version: ");
coleenp@5749 3195 have_pv = true;
kevinw@9184 3196 pv_node->constants()->print_value_on(st);
coleenp@5749 3197 }
coleenp@5749 3198 if (have_pv) st->cr();
kevinw@9184 3199 }
coleenp@4037 3200
coleenp@4037 3201 if (generic_signature() != NULL) {
coleenp@4037 3202 st->print(BULLET"generic signature: ");
coleenp@4037 3203 generic_signature()->print_value_on(st);
coleenp@4037 3204 st->cr();
coleenp@4037 3205 }
coleenp@4037 3206 st->print(BULLET"inner classes: "); inner_classes()->print_value_on(st); st->cr();
coleenp@4037 3207 st->print(BULLET"java mirror: "); java_mirror()->print_value_on(st); st->cr();
coleenp@4037 3208 st->print(BULLET"vtable length %d (start addr: " INTPTR_FORMAT ")", vtable_length(), start_of_vtable()); st->cr();
drchase@5732 3209 if (vtable_length() > 0 && (Verbose || WizardMode)) print_vtable(start_of_vtable(), vtable_length(), st);
coleenp@4037 3210 st->print(BULLET"itable length %d (start addr: " INTPTR_FORMAT ")", itable_length(), start_of_itable()); st->cr();
drchase@5732 3211 if (itable_length() > 0 && (Verbose || WizardMode)) print_vtable(start_of_itable(), itable_length(), st);
coleenp@4037 3212 st->print_cr(BULLET"---- static fields (%d words):", static_field_size());
coleenp@4037 3213 FieldPrinter print_static_field(st);
coleenp@4037 3214 ((InstanceKlass*)this)->do_local_static_fields(&print_static_field);
coleenp@4037 3215 st->print_cr(BULLET"---- non-static fields (%d words):", nonstatic_field_size());
coleenp@4037 3216 FieldPrinter print_nonstatic_field(st);
coleenp@4037 3217 ((InstanceKlass*)this)->do_nonstatic_fields(&print_nonstatic_field);
coleenp@4037 3218
coleenp@4037 3219 st->print(BULLET"non-static oop maps: ");
coleenp@4037 3220 OopMapBlock* map = start_of_nonstatic_oop_maps();
coleenp@4037 3221 OopMapBlock* end_map = map + nonstatic_oop_map_count();
coleenp@4037 3222 while (map < end_map) {
coleenp@4037 3223 st->print("%d-%d ", map->offset(), map->offset() + heapOopSize*(map->count() - 1));
coleenp@4037 3224 map++;
coleenp@4037 3225 }
coleenp@4037 3226 st->cr();
coleenp@4037 3227 }
coleenp@4037 3228
coleenp@4037 3229 #endif //PRODUCT
coleenp@4037 3230
coleenp@4037 3231 void InstanceKlass::print_value_on(outputStream* st) const {
coleenp@4037 3232 assert(is_klass(), "must be klass");
drchase@5732 3233 if (Verbose || WizardMode) access_flags().print_on(st);
coleenp@4037 3234 name()->print_value_on(st);
coleenp@4037 3235 }
coleenp@4037 3236
coleenp@4037 3237 #ifndef PRODUCT
coleenp@4037 3238
duke@435 3239 void FieldPrinter::do_field(fieldDescriptor* fd) {
jrose@1100 3240 _st->print(BULLET);
never@2658 3241 if (_obj == NULL) {
duke@435 3242 fd->print_on(_st);
duke@435 3243 _st->cr();
duke@435 3244 } else {
duke@435 3245 fd->print_on_for(_st, _obj);
duke@435 3246 _st->cr();
duke@435 3247 }
duke@435 3248 }
duke@435 3249
duke@435 3250
coleenp@4037 3251 void InstanceKlass::oop_print_on(oop obj, outputStream* st) {
duke@435 3252 Klass::oop_print_on(obj, st);
duke@435 3253
coleenp@4037 3254 if (this == SystemDictionary::String_klass()) {
duke@435 3255 typeArrayOop value = java_lang_String::value(obj);
duke@435 3256 juint offset = java_lang_String::offset(obj);
duke@435 3257 juint length = java_lang_String::length(obj);
duke@435 3258 if (value != NULL &&
duke@435 3259 value->is_typeArray() &&
duke@435 3260 offset <= (juint) value->length() &&
duke@435 3261 offset + length <= (juint) value->length()) {
jrose@1100 3262 st->print(BULLET"string: ");
stefank@6975 3263 java_lang_String::print(obj, st);
duke@435 3264 st->cr();
duke@435 3265 if (!WizardMode) return; // that is enough
duke@435 3266 }
duke@435 3267 }
duke@435 3268
jrose@1100 3269 st->print_cr(BULLET"---- fields (total size %d words):", oop_size(obj));
never@2658 3270 FieldPrinter print_field(st, obj);
never@2658 3271 do_nonstatic_fields(&print_field);
duke@435 3272
coleenp@4037 3273 if (this == SystemDictionary::Class_klass()) {
jrose@1100 3274 st->print(BULLET"signature: ");
jrose@1100 3275 java_lang_Class::print_signature(obj, st);
jrose@1100 3276 st->cr();
coleenp@4037 3277 Klass* mirrored_klass = java_lang_Class::as_Klass(obj);
jrose@1100 3278 st->print(BULLET"fake entry for mirror: ");
coleenp@4037 3279 mirrored_klass->print_value_on_maybe_null(st);
duke@435 3280 st->cr();
coleenp@4037 3281 Klass* array_klass = java_lang_Class::array_klass(obj);
jrose@1100 3282 st->print(BULLET"fake entry for array: ");
coleenp@4037 3283 array_klass->print_value_on_maybe_null(st);
duke@435 3284 st->cr();
never@2658 3285 st->print_cr(BULLET"fake entry for oop_size: %d", java_lang_Class::oop_size(obj));
never@2658 3286 st->print_cr(BULLET"fake entry for static_oop_field_count: %d", java_lang_Class::static_oop_field_count(obj));
coleenp@4037 3287 Klass* real_klass = java_lang_Class::as_Klass(obj);
coleenp@4037 3288 if (real_klass != NULL && real_klass->oop_is_instance()) {
coleenp@4037 3289 InstanceKlass::cast(real_klass)->do_local_static_fields(&print_field);
never@2658 3290 }
coleenp@4037 3291 } else if (this == SystemDictionary::MethodType_klass()) {
jrose@1474 3292 st->print(BULLET"signature: ");
jrose@2639 3293 java_lang_invoke_MethodType::print_signature(obj, st);
jrose@1474 3294 st->cr();
duke@435 3295 }
duke@435 3296 }
duke@435 3297
jrose@1590 3298 #endif //PRODUCT
jrose@1590 3299
coleenp@4037 3300 void InstanceKlass::oop_print_value_on(oop obj, outputStream* st) {
duke@435 3301 st->print("a ");
duke@435 3302 name()->print_value_on(st);
duke@435 3303 obj->print_address_on(st);
coleenp@4037 3304 if (this == SystemDictionary::String_klass()
jrose@1100 3305 && java_lang_String::value(obj) != NULL) {
jrose@1100 3306 ResourceMark rm;
jrose@1100 3307 int len = java_lang_String::length(obj);
jrose@1100 3308 int plen = (len < 24 ? len : 12);
jrose@1100 3309 char* str = java_lang_String::as_utf8_string(obj, 0, plen);
jrose@1100 3310 st->print(" = \"%s\"", str);
jrose@1100 3311 if (len > plen)
jrose@1100 3312 st->print("...[%d]", len);
coleenp@4037 3313 } else if (this == SystemDictionary::Class_klass()) {
coleenp@4037 3314 Klass* k = java_lang_Class::as_Klass(obj);
jrose@1100 3315 st->print(" = ");
jrose@1100 3316 if (k != NULL) {
jrose@1100 3317 k->print_value_on(st);
jrose@1100 3318 } else {
jrose@1100 3319 const char* tname = type2name(java_lang_Class::primitive_type(obj));
jrose@1100 3320 st->print("%s", tname ? tname : "type?");
jrose@1100 3321 }
coleenp@4037 3322 } else if (this == SystemDictionary::MethodType_klass()) {
jrose@1474 3323 st->print(" = ");
jrose@2639 3324 java_lang_invoke_MethodType::print_signature(obj, st);
jrose@1100 3325 } else if (java_lang_boxing_object::is_instance(obj)) {
jrose@1100 3326 st->print(" = ");
jrose@1100 3327 java_lang_boxing_object::print(obj, st);
coleenp@4037 3328 } else if (this == SystemDictionary::LambdaForm_klass()) {
twisti@3969 3329 oop vmentry = java_lang_invoke_LambdaForm::vmentry(obj);
twisti@3969 3330 if (vmentry != NULL) {
twisti@3969 3331 st->print(" => ");
twisti@3969 3332 vmentry->print_value_on(st);
twisti@3969 3333 }
coleenp@4037 3334 } else if (this == SystemDictionary::MemberName_klass()) {
coleenp@4037 3335 Metadata* vmtarget = java_lang_invoke_MemberName::vmtarget(obj);
twisti@3969 3336 if (vmtarget != NULL) {
twisti@3969 3337 st->print(" = ");
twisti@3969 3338 vmtarget->print_value_on(st);
twisti@3969 3339 } else {
twisti@3969 3340 java_lang_invoke_MemberName::clazz(obj)->print_value_on(st);
twisti@3969 3341 st->print(".");
twisti@3969 3342 java_lang_invoke_MemberName::name(obj)->print_value_on(st);
twisti@3969 3343 }
jrose@1100 3344 }
duke@435 3345 }
duke@435 3346
coleenp@4037 3347 const char* InstanceKlass::internal_name() const {
duke@435 3348 return external_name();
duke@435 3349 }
duke@435 3350
acorn@4497 3351 #if INCLUDE_SERVICES
acorn@4497 3352 // Size Statistics
acorn@4497 3353 void InstanceKlass::collect_statistics(KlassSizeStats *sz) const {
acorn@4497 3354 Klass::collect_statistics(sz);
acorn@4497 3355
acorn@4497 3356 sz->_inst_size = HeapWordSize * size_helper();
acorn@4497 3357 sz->_vtab_bytes = HeapWordSize * align_object_offset(vtable_length());
acorn@4497 3358 sz->_itab_bytes = HeapWordSize * align_object_offset(itable_length());
acorn@4497 3359 sz->_nonstatic_oopmap_bytes = HeapWordSize *
acorn@4497 3360 ((is_interface() || is_anonymous()) ?
acorn@4497 3361 align_object_offset(nonstatic_oop_map_size()) :
acorn@4497 3362 nonstatic_oop_map_size());
acorn@4497 3363
acorn@4497 3364 int n = 0;
acorn@4497 3365 n += (sz->_methods_array_bytes = sz->count_array(methods()));
acorn@4497 3366 n += (sz->_method_ordering_bytes = sz->count_array(method_ordering()));
acorn@4497 3367 n += (sz->_local_interfaces_bytes = sz->count_array(local_interfaces()));
acorn@4497 3368 n += (sz->_transitive_interfaces_bytes = sz->count_array(transitive_interfaces()));
acorn@4497 3369 n += (sz->_fields_bytes = sz->count_array(fields()));
acorn@4497 3370 n += (sz->_inner_classes_bytes = sz->count_array(inner_classes()));
acorn@4497 3371 sz->_ro_bytes += n;
acorn@4497 3372
acorn@4497 3373 const ConstantPool* cp = constants();
acorn@4497 3374 if (cp) {
acorn@4497 3375 cp->collect_statistics(sz);
acorn@4497 3376 }
acorn@4497 3377
acorn@4497 3378 const Annotations* anno = annotations();
acorn@4497 3379 if (anno) {
acorn@4497 3380 anno->collect_statistics(sz);
acorn@4497 3381 }
acorn@4497 3382
acorn@4497 3383 const Array<Method*>* methods_array = methods();
acorn@4497 3384 if (methods()) {
acorn@4497 3385 for (int i = 0; i < methods_array->length(); i++) {
acorn@4497 3386 Method* method = methods_array->at(i);
acorn@4497 3387 if (method) {
acorn@4497 3388 sz->_method_count ++;
acorn@4497 3389 method->collect_statistics(sz);
acorn@4497 3390 }
acorn@4497 3391 }
acorn@4497 3392 }
acorn@4497 3393 }
acorn@4497 3394 #endif // INCLUDE_SERVICES
acorn@4497 3395
duke@435 3396 // Verification
duke@435 3397
duke@435 3398 class VerifyFieldClosure: public OopClosure {
coleenp@548 3399 protected:
coleenp@548 3400 template <class T> void do_oop_work(T* p) {
coleenp@548 3401 oop obj = oopDesc::load_decode_heap_oop(p);
coleenp@548 3402 if (!obj->is_oop_or_null()) {
coleenp@548 3403 tty->print_cr("Failed: " PTR_FORMAT " -> " PTR_FORMAT, p, (address)obj);
duke@435 3404 Universe::print();
duke@435 3405 guarantee(false, "boom");
duke@435 3406 }
duke@435 3407 }
coleenp@548 3408 public:
coleenp@548 3409 virtual void do_oop(oop* p) { VerifyFieldClosure::do_oop_work(p); }
coleenp@548 3410 virtual void do_oop(narrowOop* p) { VerifyFieldClosure::do_oop_work(p); }
duke@435 3411 };
duke@435 3412
coleenp@6316 3413 void InstanceKlass::verify_on(outputStream* st) {
coleenp@4037 3414 #ifndef PRODUCT
coleenp@5307 3415 // Avoid redundant verifies, this really should be in product.
coleenp@4037 3416 if (_verify_count == Universe::verify_count()) return;
coleenp@4037 3417 _verify_count = Universe::verify_count();
coleenp@4037 3418 #endif
coleenp@5307 3419
coleenp@5307 3420 // Verify Klass
coleenp@6316 3421 Klass::verify_on(st);
coleenp@6316 3422
coleenp@6316 3423 // Verify that klass is present in ClassLoaderData
coleenp@6316 3424 guarantee(class_loader_data()->contains_klass(this),
coleenp@6316 3425 "this class isn't found in class loader data");
coleenp@4037 3426
coleenp@4037 3427 // Verify vtables
coleenp@4037 3428 if (is_linked()) {
coleenp@5307 3429 ResourceMark rm;
coleenp@4037 3430 // $$$ This used to be done only for m/s collections. Doing it
coleenp@4037 3431 // always seemed a valid generalization. (DLD -- 6/00)
coleenp@4037 3432 vtable()->verify(st);
coleenp@4037 3433 }
coleenp@4037 3434
coleenp@4037 3435 // Verify first subklass
coleenp@4037 3436 if (subklass_oop() != NULL) {
coleenp@4037 3437 guarantee(subklass_oop()->is_klass(), "should be klass");
coleenp@4037 3438 }
coleenp@4037 3439
coleenp@4037 3440 // Verify siblings
coleenp@4037 3441 Klass* super = this->super();
coleenp@4037 3442 Klass* sib = next_sibling();
coleenp@4037 3443 if (sib != NULL) {
coleenp@4037 3444 if (sib == this) {
coleenp@4037 3445 fatal(err_msg("subclass points to itself " PTR_FORMAT, sib));
coleenp@4037 3446 }
coleenp@4037 3447
coleenp@4037 3448 guarantee(sib->is_klass(), "should be klass");
coleenp@4037 3449 guarantee(sib->super() == super, "siblings should have same superklass");
coleenp@4037 3450 }
coleenp@4037 3451
coleenp@4037 3452 // Verify implementor fields
coleenp@4037 3453 Klass* im = implementor();
coleenp@4037 3454 if (im != NULL) {
coleenp@4037 3455 guarantee(is_interface(), "only interfaces should have implementor set");
coleenp@4037 3456 guarantee(im->is_klass(), "should be klass");
hseigel@4278 3457 guarantee(!im->is_interface() || im == this,
coleenp@4037 3458 "implementors cannot be interfaces");
coleenp@4037 3459 }
coleenp@4037 3460
coleenp@4037 3461 // Verify local interfaces
coleenp@4037 3462 if (local_interfaces()) {
coleenp@4037 3463 Array<Klass*>* local_interfaces = this->local_interfaces();
coleenp@4037 3464 for (int j = 0; j < local_interfaces->length(); j++) {
coleenp@4037 3465 Klass* e = local_interfaces->at(j);
hseigel@4278 3466 guarantee(e->is_klass() && e->is_interface(), "invalid local interface");
coleenp@4037 3467 }
coleenp@4037 3468 }
coleenp@4037 3469
coleenp@4037 3470 // Verify transitive interfaces
coleenp@4037 3471 if (transitive_interfaces() != NULL) {
coleenp@4037 3472 Array<Klass*>* transitive_interfaces = this->transitive_interfaces();
coleenp@4037 3473 for (int j = 0; j < transitive_interfaces->length(); j++) {
coleenp@4037 3474 Klass* e = transitive_interfaces->at(j);
hseigel@4278 3475 guarantee(e->is_klass() && e->is_interface(), "invalid transitive interface");
coleenp@4037 3476 }
coleenp@4037 3477 }
coleenp@4037 3478
coleenp@4037 3479 // Verify methods
coleenp@4037 3480 if (methods() != NULL) {
coleenp@4037 3481 Array<Method*>* methods = this->methods();
coleenp@4037 3482 for (int j = 0; j < methods->length(); j++) {
coleenp@4037 3483 guarantee(methods->at(j)->is_method(), "non-method in methods array");
coleenp@4037 3484 }
coleenp@4037 3485 for (int j = 0; j < methods->length() - 1; j++) {
coleenp@4037 3486 Method* m1 = methods->at(j);
coleenp@4037 3487 Method* m2 = methods->at(j + 1);
coleenp@4037 3488 guarantee(m1->name()->fast_compare(m2->name()) <= 0, "methods not sorted correctly");
coleenp@4037 3489 }
coleenp@4037 3490 }
coleenp@4037 3491
coleenp@4037 3492 // Verify method ordering
coleenp@4037 3493 if (method_ordering() != NULL) {
coleenp@4037 3494 Array<int>* method_ordering = this->method_ordering();
coleenp@4037 3495 int length = method_ordering->length();
coleenp@4037 3496 if (JvmtiExport::can_maintain_original_method_order() ||
hseigel@4886 3497 ((UseSharedSpaces || DumpSharedSpaces) && length != 0)) {
coleenp@4037 3498 guarantee(length == methods()->length(), "invalid method ordering length");
coleenp@4037 3499 jlong sum = 0;
coleenp@4037 3500 for (int j = 0; j < length; j++) {
coleenp@4037 3501 int original_index = method_ordering->at(j);
coleenp@4037 3502 guarantee(original_index >= 0, "invalid method ordering index");
coleenp@4037 3503 guarantee(original_index < length, "invalid method ordering index");
coleenp@4037 3504 sum += original_index;
coleenp@4037 3505 }
coleenp@4037 3506 // Verify sum of indices 0,1,...,length-1
coleenp@4037 3507 guarantee(sum == ((jlong)length*(length-1))/2, "invalid method ordering sum");
coleenp@4037 3508 } else {
coleenp@4037 3509 guarantee(length == 0, "invalid method ordering length");
coleenp@4037 3510 }
coleenp@4037 3511 }
coleenp@4037 3512
acorn@5848 3513 // Verify default methods
acorn@5848 3514 if (default_methods() != NULL) {
acorn@5848 3515 Array<Method*>* methods = this->default_methods();
acorn@5848 3516 for (int j = 0; j < methods->length(); j++) {
acorn@5848 3517 guarantee(methods->at(j)->is_method(), "non-method in methods array");
acorn@5848 3518 }
acorn@5848 3519 for (int j = 0; j < methods->length() - 1; j++) {
acorn@5848 3520 Method* m1 = methods->at(j);
acorn@5848 3521 Method* m2 = methods->at(j + 1);
acorn@5848 3522 guarantee(m1->name()->fast_compare(m2->name()) <= 0, "methods not sorted correctly");
acorn@5848 3523 }
acorn@5848 3524 }
acorn@5848 3525
coleenp@4037 3526 // Verify JNI static field identifiers
coleenp@4037 3527 if (jni_ids() != NULL) {
coleenp@4037 3528 jni_ids()->verify(this);
coleenp@4037 3529 }
coleenp@4037 3530
coleenp@4037 3531 // Verify other fields
coleenp@4037 3532 if (array_klasses() != NULL) {
coleenp@4037 3533 guarantee(array_klasses()->is_klass(), "should be klass");
coleenp@4037 3534 }
coleenp@4037 3535 if (constants() != NULL) {
coleenp@4037 3536 guarantee(constants()->is_constantPool(), "should be constant pool");
coleenp@4037 3537 }
morris@4693 3538 const Klass* host = host_klass();
morris@4693 3539 if (host != NULL) {
morris@4693 3540 guarantee(host->is_klass(), "should be klass");
coleenp@4037 3541 }
coleenp@4037 3542 }
coleenp@4037 3543
coleenp@4037 3544 void InstanceKlass::oop_verify_on(oop obj, outputStream* st) {
duke@435 3545 Klass::oop_verify_on(obj, st);
duke@435 3546 VerifyFieldClosure blk;
coleenp@4037 3547 obj->oop_iterate_no_header(&blk);
duke@435 3548 }
duke@435 3549
coleenp@4037 3550
coleenp@548 3551 // JNIid class for jfieldIDs only
coleenp@548 3552 // Note to reviewers:
coleenp@548 3553 // These JNI functions are just moved over to column 1 and not changed
coleenp@548 3554 // in the compressed oops workspace.
coleenp@4037 3555 JNIid::JNIid(Klass* holder, int offset, JNIid* next) {
coleenp@548 3556 _holder = holder;
coleenp@548 3557 _offset = offset;
coleenp@548 3558 _next = next;
coleenp@548 3559 debug_only(_is_static_field_id = false;)
coleenp@548 3560 }
duke@435 3561
duke@435 3562
coleenp@548 3563 JNIid* JNIid::find(int offset) {
coleenp@548 3564 JNIid* current = this;
coleenp@548 3565 while (current != NULL) {
coleenp@548 3566 if (current->offset() == offset) return current;
coleenp@548 3567 current = current->next();
coleenp@548 3568 }
coleenp@548 3569 return NULL;
coleenp@548 3570 }
duke@435 3571
duke@435 3572 void JNIid::deallocate(JNIid* current) {
coleenp@548 3573 while (current != NULL) {
coleenp@548 3574 JNIid* next = current->next();
coleenp@548 3575 delete current;
coleenp@548 3576 current = next;
coleenp@548 3577 }
coleenp@548 3578 }
duke@435 3579
duke@435 3580
coleenp@4037 3581 void JNIid::verify(Klass* holder) {
coleenp@4047 3582 int first_field_offset = InstanceMirrorKlass::offset_of_static_fields();
coleenp@548 3583 int end_field_offset;
coleenp@4037 3584 end_field_offset = first_field_offset + (InstanceKlass::cast(holder)->static_field_size() * wordSize);
duke@435 3585
coleenp@548 3586 JNIid* current = this;
coleenp@548 3587 while (current != NULL) {
coleenp@548 3588 guarantee(current->holder() == holder, "Invalid klass in JNIid");
coleenp@548 3589 #ifdef ASSERT
coleenp@548 3590 int o = current->offset();
coleenp@548 3591 if (current->is_static_field_id()) {
coleenp@548 3592 guarantee(o >= first_field_offset && o < end_field_offset, "Invalid static field offset in JNIid");
coleenp@548 3593 }
coleenp@548 3594 #endif
coleenp@548 3595 current = current->next();
coleenp@548 3596 }
coleenp@548 3597 }
duke@435 3598
duke@435 3599
duke@435 3600 #ifdef ASSERT
coleenp@4037 3601 void InstanceKlass::set_init_state(ClassState state) {
coleenp@4037 3602 bool good_state = is_shared() ? (_init_state <= state)
coleenp@548 3603 : (_init_state < state);
coleenp@548 3604 assert(good_state || state == allocated, "illegal state transition");
coleenp@3368 3605 _init_state = (u1)state;
coleenp@548 3606 }
duke@435 3607 #endif
duke@435 3608
duke@435 3609
duke@435 3610 // RedefineClasses() support for previous versions:
duke@435 3611
coleenp@4037 3612 // Purge previous versions
kevinw@9184 3613 void InstanceKlass::purge_previous_versions(InstanceKlass* ik) {
coleenp@4037 3614 if (ik->previous_versions() != NULL) {
coleenp@4037 3615 // This klass has previous versions so see what we can cleanup
coleenp@4037 3616 // while it is safe to do so.
coleenp@4037 3617
coleenp@4037 3618 int deleted_count = 0; // leave debugging breadcrumbs
coleenp@4037 3619 int live_count = 0;
kevinw@9184 3620 ClassLoaderData* loader_data = ik->class_loader_data();
kevinw@9184 3621 assert(loader_data != NULL, "should never be null");
coleenp@4037 3622
coleenp@4037 3623 // RC_TRACE macro has an embedded ResourceMark
kevinw@9184 3624 RC_TRACE(0x00000200, ("purge: %s: previous versions", ik->external_name()));
kevinw@9184 3625
kevinw@9184 3626 // previous versions are linked together through the InstanceKlass
kevinw@9184 3627 InstanceKlass* pv_node = ik->previous_versions();
kevinw@9184 3628 InstanceKlass* last = ik;
kevinw@9184 3629 int version = 0;
kevinw@9184 3630
kevinw@9184 3631 // check the previous versions list
kevinw@9184 3632 for (; pv_node != NULL; ) {
kevinw@9184 3633
kevinw@9184 3634 ConstantPool* pvcp = pv_node->constants();
kevinw@9184 3635 assert(pvcp != NULL, "cp ref was unexpectedly cleared");
kevinw@9184 3636
kevinw@9184 3637
coleenp@4037 3638 if (!pvcp->on_stack()) {
coleenp@4037 3639 // If the constant pool isn't on stack, none of the methods
kevinw@9184 3640 // are executing. Unlink this previous_version.
kevinw@9184 3641 // The previous version InstanceKlass is on the ClassLoaderData deallocate list
kevinw@9184 3642 // so will be deallocated during the next phase of class unloading.
kevinw@9184 3643 pv_node = pv_node->previous_versions();
kevinw@9184 3644 last->link_previous_versions(pv_node);
coleenp@4037 3645 deleted_count++;
kevinw@9184 3646 version++;
coleenp@4037 3647 continue;
coleenp@4037 3648 } else {
kevinw@9184 3649 RC_TRACE(0x00000200, ("purge: previous version " INTPTR_FORMAT " is alive",
kevinw@9184 3650 pv_node));
coleenp@4037 3651 assert(pvcp->pool_holder() != NULL, "Constant pool with no holder");
coleenp@4037 3652 guarantee (!loader_data->is_unloading(), "unloaded classes can't be on the stack");
coleenp@4037 3653 live_count++;
coleenp@4037 3654 }
coleenp@4037 3655
kevinw@9184 3656 // At least one method is live in this previous version so clean its MethodData.
kevinw@9184 3657 // Reset dead EMCP methods not to get breakpoints.
kevinw@9184 3658 // All methods are deallocated when all of the methods for this class are no
kevinw@9184 3659 // longer running.
kevinw@9184 3660 Array<Method*>* method_refs = pv_node->methods();
coleenp@4037 3661 if (method_refs != NULL) {
coleenp@4037 3662 RC_TRACE(0x00000200, ("purge: previous methods length=%d",
coleenp@4037 3663 method_refs->length()));
kevinw@9184 3664 for (int j = 0; j < method_refs->length(); j++) {
coleenp@4037 3665 Method* method = method_refs->at(j);
kevinw@9184 3666
coleenp@4037 3667 if (!method->on_stack()) {
kevinw@9184 3668 // no breakpoints for non-running methods
kevinw@9184 3669 if (method->is_running_emcp()) {
kevinw@9184 3670 method->set_running_emcp(false);
kevinw@9184 3671 }
coleenp@4037 3672 } else {
kevinw@9184 3673 assert (method->is_obsolete() || method->is_running_emcp(),
kevinw@9184 3674 "emcp method cannot run after emcp bit is cleared");
coleenp@4037 3675 // RC_TRACE macro has an embedded ResourceMark
coleenp@4037 3676 RC_TRACE(0x00000200,
coleenp@4037 3677 ("purge: %s(%s): prev method @%d in version @%d is alive",
coleenp@4037 3678 method->name()->as_C_string(),
kevinw@9184 3679 method->signature()->as_C_string(), j, version));
roland@9183 3680 if (method->method_data() != NULL) {
kevinw@9184 3681 // Clean out any weak method links for running methods
kevinw@9184 3682 // (also should include not EMCP methods)
roland@9183 3683 method->method_data()->clean_weak_method_links();
roland@9183 3684 }
coleenp@4037 3685 }
coleenp@4037 3686 }
coleenp@4037 3687 }
kevinw@9184 3688 // next previous version
kevinw@9184 3689 last = pv_node;
kevinw@9184 3690 pv_node = pv_node->previous_versions();
kevinw@9184 3691 version++;
coleenp@4037 3692 }
coleenp@4037 3693 RC_TRACE(0x00000200,
coleenp@4037 3694 ("purge: previous version stats: live=%d, deleted=%d", live_count,
coleenp@4037 3695 deleted_count));
coleenp@4037 3696 }
roland@9183 3697
kevinw@9184 3698 // Clean MethodData of this class's methods so they don't refer to
kevinw@9184 3699 // old methods that are no longer running.
roland@9183 3700 Array<Method*>* methods = ik->methods();
roland@9183 3701 int num_methods = methods->length();
roland@9183 3702 for (int index2 = 0; index2 < num_methods; ++index2) {
roland@9183 3703 if (methods->at(index2)->method_data() != NULL) {
roland@9183 3704 methods->at(index2)->method_data()->clean_weak_method_links();
roland@9183 3705 }
roland@9183 3706 }
coleenp@4037 3707 }
coleenp@4037 3708
kevinw@9184 3709 void InstanceKlass::mark_newly_obsolete_methods(Array<Method*>* old_methods,
kevinw@9184 3710 int emcp_method_count) {
duke@435 3711 int obsolete_method_count = old_methods->length() - emcp_method_count;
duke@435 3712
duke@435 3713 if (emcp_method_count != 0 && obsolete_method_count != 0 &&
kevinw@9184 3714 _previous_versions != NULL) {
coleenp@4037 3715 // We have a mix of obsolete and EMCP methods so we have to
duke@435 3716 // clear out any matching EMCP method entries the hard way.
duke@435 3717 int local_count = 0;
duke@435 3718 for (int i = 0; i < old_methods->length(); i++) {
kevinw@9184 3719 Method* old_method = old_methods->at(i);
kevinw@9184 3720 if (old_method->is_obsolete()) {
duke@435 3721 // only obsolete methods are interesting
coleenp@2497 3722 Symbol* m_name = old_method->name();
coleenp@2497 3723 Symbol* m_signature = old_method->signature();
duke@435 3724
kevinw@9184 3725 // previous versions are linked together through the InstanceKlass
kevinw@9184 3726 int j = 0;
kevinw@9184 3727 for (InstanceKlass* prev_version = _previous_versions;
kevinw@9184 3728 prev_version != NULL;
kevinw@9184 3729 prev_version = prev_version->previous_versions(), j++) {
kevinw@9184 3730
kevinw@9184 3731 Array<Method*>* method_refs = prev_version->methods();
kevinw@9184 3732 for (int k = 0; k < method_refs->length(); k++) {
coleenp@4037 3733 Method* method = method_refs->at(k);
coleenp@4037 3734
coleenp@4037 3735 if (!method->is_obsolete() &&
coleenp@4037 3736 method->name() == m_name &&
duke@435 3737 method->signature() == m_signature) {
duke@435 3738 // The current RedefineClasses() call has made all EMCP
duke@435 3739 // versions of this method obsolete so mark it as obsolete
duke@435 3740 RC_TRACE(0x00000400,
duke@435 3741 ("add: %s(%s): flush obsolete method @%d in version @%d",
duke@435 3742 m_name->as_C_string(), m_signature->as_C_string(), k, j));
duke@435 3743
duke@435 3744 method->set_is_obsolete();
duke@435 3745 break;
duke@435 3746 }
duke@435 3747 }
duke@435 3748
duke@435 3749 // The previous loop may not find a matching EMCP method, but
duke@435 3750 // that doesn't mean that we can optimize and not go any
duke@435 3751 // further back in the PreviousVersion generations. The EMCP
kevinw@9184 3752 // method for this generation could have already been made obsolete,
duke@435 3753 // but there still may be an older EMCP method that has not
kevinw@9184 3754 // been made obsolete.
duke@435 3755 }
duke@435 3756
duke@435 3757 if (++local_count >= obsolete_method_count) {
duke@435 3758 // no more obsolete methods so bail out now
duke@435 3759 break;
duke@435 3760 }
duke@435 3761 }
duke@435 3762 }
duke@435 3763 }
kevinw@9184 3764 }
kevinw@9184 3765
kevinw@9184 3766 // Save the scratch_class as the previous version if any of the methods are running.
kevinw@9184 3767 // The previous_versions are used to set breakpoints in EMCP methods and they are
kevinw@9184 3768 // also used to clean MethodData links to redefined methods that are no longer running.
kevinw@9184 3769 void InstanceKlass::add_previous_version(instanceKlassHandle scratch_class,
kevinw@9184 3770 int emcp_method_count) {
kevinw@9184 3771 assert(Thread::current()->is_VM_thread(),
kevinw@9184 3772 "only VMThread can add previous versions");
kevinw@9184 3773
kevinw@9184 3774 // RC_TRACE macro has an embedded ResourceMark
kevinw@9184 3775 RC_TRACE(0x00000400, ("adding previous version ref for %s, EMCP_cnt=%d",
kevinw@9184 3776 scratch_class->external_name(), emcp_method_count));
kevinw@9184 3777
kevinw@9184 3778 // Clean out old previous versions
kevinw@9184 3779 purge_previous_versions(this);
kevinw@9184 3780
kevinw@9184 3781 // Mark newly obsolete methods in remaining previous versions. An EMCP method from
kevinw@9184 3782 // a previous redefinition may be made obsolete by this redefinition.
kevinw@9184 3783 Array<Method*>* old_methods = scratch_class->methods();
kevinw@9184 3784 mark_newly_obsolete_methods(old_methods, emcp_method_count);
kevinw@9184 3785
kevinw@9184 3786 // If the constant pool for this previous version of the class
kevinw@9184 3787 // is not marked as being on the stack, then none of the methods
kevinw@9184 3788 // in this previous version of the class are on the stack so
kevinw@9184 3789 // we don't need to add this as a previous version.
kevinw@9184 3790 ConstantPool* cp_ref = scratch_class->constants();
kevinw@9184 3791 if (!cp_ref->on_stack()) {
kevinw@9184 3792 RC_TRACE(0x00000400, ("add: scratch class not added; no methods are running"));
kevinw@9184 3793 return;
sspitsyn@7683 3794 }
kevinw@9184 3795
kevinw@9184 3796 if (emcp_method_count != 0) {
kevinw@9184 3797 // At least one method is still running, check for EMCP methods
kevinw@9184 3798 for (int i = 0; i < old_methods->length(); i++) {
kevinw@9184 3799 Method* old_method = old_methods->at(i);
kevinw@9184 3800 if (!old_method->is_obsolete() && old_method->on_stack()) {
kevinw@9184 3801 // if EMCP method (not obsolete) is on the stack, mark as EMCP so that
kevinw@9184 3802 // we can add breakpoints for it.
kevinw@9184 3803
kevinw@9184 3804 // We set the method->on_stack bit during safepoints for class redefinition and
kevinw@9184 3805 // class unloading and use this bit to set the is_running_emcp bit.
kevinw@9184 3806 // After the safepoint, the on_stack bit is cleared and the running emcp
kevinw@9184 3807 // method may exit. If so, we would set a breakpoint in a method that
kevinw@9184 3808 // is never reached, but this won't be noticeable to the programmer.
kevinw@9184 3809 old_method->set_running_emcp(true);
kevinw@9184 3810 RC_TRACE(0x00000400, ("add: EMCP method %s is on_stack " INTPTR_FORMAT,
kevinw@9184 3811 old_method->name_and_sig_as_C_string(), old_method));
kevinw@9184 3812 } else if (!old_method->is_obsolete()) {
kevinw@9184 3813 RC_TRACE(0x00000400, ("add: EMCP method %s is NOT on_stack " INTPTR_FORMAT,
kevinw@9184 3814 old_method->name_and_sig_as_C_string(), old_method));
kevinw@9184 3815 }
sspitsyn@7683 3816 }
sspitsyn@7683 3817 }
kevinw@9184 3818
kevinw@9184 3819 // Add previous version if any methods are still running.
kevinw@9184 3820 RC_TRACE(0x00000400, ("add: scratch class added; one of its methods is on_stack"));
kevinw@9184 3821 assert(scratch_class->previous_versions() == NULL, "shouldn't have a previous version");
kevinw@9184 3822 scratch_class->link_previous_versions(previous_versions());
kevinw@9184 3823 link_previous_versions(scratch_class());
kevinw@9184 3824 } // end add_previous_version()
sspitsyn@7683 3825
coleenp@4037 3826 Method* InstanceKlass::method_with_idnum(int idnum) {
coleenp@4037 3827 Method* m = NULL;
duke@435 3828 if (idnum < methods()->length()) {
coleenp@4037 3829 m = methods()->at(idnum);
duke@435 3830 }
duke@435 3831 if (m == NULL || m->method_idnum() != idnum) {
duke@435 3832 for (int index = 0; index < methods()->length(); ++index) {
coleenp@4037 3833 m = methods()->at(index);
duke@435 3834 if (m->method_idnum() == idnum) {
duke@435 3835 return m;
duke@435 3836 }
duke@435 3837 }
coleenp@5749 3838 // None found, return null for the caller to handle.
coleenp@5749 3839 return NULL;
duke@435 3840 }
duke@435 3841 return m;
duke@435 3842 }
duke@435 3843
sspitsyn@7683 3844
sspitsyn@7683 3845 Method* InstanceKlass::method_with_orig_idnum(int idnum) {
sspitsyn@7683 3846 if (idnum >= methods()->length()) {
sspitsyn@7683 3847 return NULL;
sspitsyn@7683 3848 }
sspitsyn@7683 3849 Method* m = methods()->at(idnum);
sspitsyn@7683 3850 if (m != NULL && m->orig_method_idnum() == idnum) {
sspitsyn@7683 3851 return m;
sspitsyn@7683 3852 }
sspitsyn@7683 3853 // Obsolete method idnum does not match the original idnum
sspitsyn@7683 3854 for (int index = 0; index < methods()->length(); ++index) {
sspitsyn@7683 3855 m = methods()->at(index);
sspitsyn@7683 3856 if (m->orig_method_idnum() == idnum) {
sspitsyn@7683 3857 return m;
sspitsyn@7683 3858 }
sspitsyn@7683 3859 }
sspitsyn@7683 3860 // None found, return null for the caller to handle.
sspitsyn@7683 3861 return NULL;
sspitsyn@7683 3862 }
sspitsyn@7683 3863
sspitsyn@7683 3864
sspitsyn@7683 3865 Method* InstanceKlass::method_with_orig_idnum(int idnum, int version) {
sspitsyn@7683 3866 InstanceKlass* holder = get_klass_version(version);
sspitsyn@7683 3867 if (holder == NULL) {
sspitsyn@7683 3868 return NULL; // The version of klass is gone, no method is found
sspitsyn@7683 3869 }
sspitsyn@7683 3870 Method* method = holder->method_with_orig_idnum(idnum);
sspitsyn@7683 3871 return method;
sspitsyn@7683 3872 }
sspitsyn@7683 3873
sspitsyn@7683 3874
jiangli@5421 3875 jint InstanceKlass::get_cached_class_file_len() {
jiangli@5421 3876 return VM_RedefineClasses::get_cached_class_file_len(_cached_class_file);
jiangli@5421 3877 }
jiangli@5421 3878
jiangli@5421 3879 unsigned char * InstanceKlass::get_cached_class_file_bytes() {
jiangli@5421 3880 return VM_RedefineClasses::get_cached_class_file_bytes(_cached_class_file);
jiangli@5421 3881 }

mercurial