src/share/vm/oops/instanceKlass.cpp

Tue, 17 Dec 2019 05:07:06 +0000

author
zgu
date
Tue, 17 Dec 2019 05:07:06 +0000
changeset 9792
9a7135d0a309
parent 9721
78c11f573795
child 9799
2c1e9fab6964
permissions
-rw-r--r--

8225141: Better handling of classes in error state in fast class initialization checks
Reviewed-by: andrew

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

mercurial