Tue, 06 Dec 2011 18:28:51 -0500
7117052: instanceKlass::_init_state can be u1 type
Summary: Change instanceKlass::_init_state field to u1 type.
Reviewed-by: bdelsart, coleenp, dholmes, phh, never
Contributed-by: Jiangli Zhou <jiangli.zhou@oracle.com>
duke@435 | 1 | /* |
stefank@2534 | 2 | * Copyright (c) 1997, 2011, 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" |
stefank@2314 | 28 | #include "classfile/verifier.hpp" |
stefank@2314 | 29 | #include "classfile/vmSymbols.hpp" |
stefank@2314 | 30 | #include "compiler/compileBroker.hpp" |
stefank@2314 | 31 | #include "gc_implementation/shared/markSweep.inline.hpp" |
stefank@2314 | 32 | #include "gc_interface/collectedHeap.inline.hpp" |
stefank@2314 | 33 | #include "interpreter/oopMapCache.hpp" |
stefank@2314 | 34 | #include "interpreter/rewriter.hpp" |
stefank@2314 | 35 | #include "jvmtifiles/jvmti.h" |
stefank@2314 | 36 | #include "memory/genOopClosures.inline.hpp" |
stefank@2314 | 37 | #include "memory/oopFactory.hpp" |
stefank@2314 | 38 | #include "memory/permGen.hpp" |
never@3137 | 39 | #include "oops/fieldStreams.hpp" |
stefank@2314 | 40 | #include "oops/instanceKlass.hpp" |
never@2658 | 41 | #include "oops/instanceMirrorKlass.hpp" |
stefank@2314 | 42 | #include "oops/instanceOop.hpp" |
stefank@2314 | 43 | #include "oops/methodOop.hpp" |
stefank@2314 | 44 | #include "oops/objArrayKlassKlass.hpp" |
stefank@2314 | 45 | #include "oops/oop.inline.hpp" |
coleenp@2497 | 46 | #include "oops/symbol.hpp" |
stefank@2314 | 47 | #include "prims/jvmtiExport.hpp" |
stefank@2314 | 48 | #include "prims/jvmtiRedefineClassesTrace.hpp" |
stefank@2314 | 49 | #include "runtime/fieldDescriptor.hpp" |
stefank@2314 | 50 | #include "runtime/handles.inline.hpp" |
stefank@2314 | 51 | #include "runtime/javaCalls.hpp" |
stefank@2314 | 52 | #include "runtime/mutexLocker.hpp" |
stefank@2314 | 53 | #include "services/threadService.hpp" |
stefank@2314 | 54 | #include "utilities/dtrace.hpp" |
stefank@2314 | 55 | #ifdef TARGET_OS_FAMILY_linux |
stefank@2314 | 56 | # include "thread_linux.inline.hpp" |
stefank@2314 | 57 | #endif |
stefank@2314 | 58 | #ifdef TARGET_OS_FAMILY_solaris |
stefank@2314 | 59 | # include "thread_solaris.inline.hpp" |
stefank@2314 | 60 | #endif |
stefank@2314 | 61 | #ifdef TARGET_OS_FAMILY_windows |
stefank@2314 | 62 | # include "thread_windows.inline.hpp" |
stefank@2314 | 63 | #endif |
never@3156 | 64 | #ifdef TARGET_OS_FAMILY_bsd |
never@3156 | 65 | # include "thread_bsd.inline.hpp" |
never@3156 | 66 | #endif |
stefank@2314 | 67 | #ifndef SERIALGC |
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" |
stefank@2314 | 71 | #include "gc_implementation/g1/heapRegionSeq.inline.hpp" |
stefank@2314 | 72 | #include "gc_implementation/parNew/parOopClosures.inline.hpp" |
stefank@2314 | 73 | #include "gc_implementation/parallelScavenge/psPromotionManager.inline.hpp" |
stefank@2314 | 74 | #include "gc_implementation/parallelScavenge/psScavenge.inline.hpp" |
stefank@2314 | 75 | #include "oops/oop.pcgc.inline.hpp" |
stefank@2314 | 76 | #endif |
stefank@2314 | 77 | #ifdef COMPILER1 |
stefank@2314 | 78 | #include "c1/c1_Compiler.hpp" |
stefank@2314 | 79 | #endif |
duke@435 | 80 | |
fparain@1759 | 81 | #ifdef DTRACE_ENABLED |
fparain@1759 | 82 | |
dcubed@3202 | 83 | #ifndef USDT2 |
dcubed@3202 | 84 | |
fparain@1759 | 85 | HS_DTRACE_PROBE_DECL4(hotspot, class__initialization__required, |
fparain@1759 | 86 | char*, intptr_t, oop, intptr_t); |
fparain@1759 | 87 | HS_DTRACE_PROBE_DECL5(hotspot, class__initialization__recursive, |
fparain@1759 | 88 | char*, intptr_t, oop, intptr_t, int); |
fparain@1759 | 89 | HS_DTRACE_PROBE_DECL5(hotspot, class__initialization__concurrent, |
fparain@1759 | 90 | char*, intptr_t, oop, intptr_t, int); |
fparain@1759 | 91 | HS_DTRACE_PROBE_DECL5(hotspot, class__initialization__erroneous, |
fparain@1759 | 92 | char*, intptr_t, oop, intptr_t, int); |
fparain@1759 | 93 | HS_DTRACE_PROBE_DECL5(hotspot, class__initialization__super__failed, |
fparain@1759 | 94 | char*, intptr_t, oop, intptr_t, int); |
fparain@1759 | 95 | HS_DTRACE_PROBE_DECL5(hotspot, class__initialization__clinit, |
fparain@1759 | 96 | char*, intptr_t, oop, intptr_t, int); |
fparain@1759 | 97 | HS_DTRACE_PROBE_DECL5(hotspot, class__initialization__error, |
fparain@1759 | 98 | char*, intptr_t, oop, intptr_t, int); |
fparain@1759 | 99 | HS_DTRACE_PROBE_DECL5(hotspot, class__initialization__end, |
fparain@1759 | 100 | char*, intptr_t, oop, intptr_t, int); |
fparain@1759 | 101 | |
fparain@1759 | 102 | #define DTRACE_CLASSINIT_PROBE(type, clss, thread_type) \ |
fparain@1759 | 103 | { \ |
fparain@1759 | 104 | char* data = NULL; \ |
fparain@1759 | 105 | int len = 0; \ |
coleenp@2497 | 106 | Symbol* name = (clss)->name(); \ |
fparain@1759 | 107 | if (name != NULL) { \ |
fparain@1759 | 108 | data = (char*)name->bytes(); \ |
fparain@1759 | 109 | len = name->utf8_length(); \ |
fparain@1759 | 110 | } \ |
fparain@1759 | 111 | HS_DTRACE_PROBE4(hotspot, class__initialization__##type, \ |
fparain@1759 | 112 | data, len, (clss)->class_loader(), thread_type); \ |
fparain@1759 | 113 | } |
fparain@1759 | 114 | |
fparain@1759 | 115 | #define DTRACE_CLASSINIT_PROBE_WAIT(type, clss, thread_type, wait) \ |
fparain@1759 | 116 | { \ |
fparain@1759 | 117 | char* data = NULL; \ |
fparain@1759 | 118 | int len = 0; \ |
coleenp@2497 | 119 | Symbol* name = (clss)->name(); \ |
fparain@1759 | 120 | if (name != NULL) { \ |
fparain@1759 | 121 | data = (char*)name->bytes(); \ |
fparain@1759 | 122 | len = name->utf8_length(); \ |
fparain@1759 | 123 | } \ |
fparain@1759 | 124 | HS_DTRACE_PROBE5(hotspot, class__initialization__##type, \ |
fparain@1759 | 125 | data, len, (clss)->class_loader(), thread_type, wait); \ |
fparain@1759 | 126 | } |
dcubed@3202 | 127 | #else /* USDT2 */ |
dcubed@3202 | 128 | |
dcubed@3202 | 129 | #define HOTSPOT_CLASS_INITIALIZATION_required HOTSPOT_CLASS_INITIALIZATION_REQUIRED |
dcubed@3202 | 130 | #define HOTSPOT_CLASS_INITIALIZATION_recursive HOTSPOT_CLASS_INITIALIZATION_RECURSIVE |
dcubed@3202 | 131 | #define HOTSPOT_CLASS_INITIALIZATION_concurrent HOTSPOT_CLASS_INITIALIZATION_CONCURRENT |
dcubed@3202 | 132 | #define HOTSPOT_CLASS_INITIALIZATION_erroneous HOTSPOT_CLASS_INITIALIZATION_ERRONEOUS |
dcubed@3202 | 133 | #define HOTSPOT_CLASS_INITIALIZATION_super__failed HOTSPOT_CLASS_INITIALIZATION_SUPER_FAILED |
dcubed@3202 | 134 | #define HOTSPOT_CLASS_INITIALIZATION_clinit HOTSPOT_CLASS_INITIALIZATION_CLINIT |
dcubed@3202 | 135 | #define HOTSPOT_CLASS_INITIALIZATION_error HOTSPOT_CLASS_INITIALIZATION_ERROR |
dcubed@3202 | 136 | #define HOTSPOT_CLASS_INITIALIZATION_end HOTSPOT_CLASS_INITIALIZATION_END |
dcubed@3202 | 137 | #define DTRACE_CLASSINIT_PROBE(type, clss, thread_type) \ |
dcubed@3202 | 138 | { \ |
dcubed@3202 | 139 | char* data = NULL; \ |
dcubed@3202 | 140 | int len = 0; \ |
dcubed@3202 | 141 | Symbol* name = (clss)->name(); \ |
dcubed@3202 | 142 | if (name != NULL) { \ |
dcubed@3202 | 143 | data = (char*)name->bytes(); \ |
dcubed@3202 | 144 | len = name->utf8_length(); \ |
dcubed@3202 | 145 | } \ |
dcubed@3202 | 146 | HOTSPOT_CLASS_INITIALIZATION_##type( \ |
dcubed@3202 | 147 | data, len, (clss)->class_loader(), thread_type); \ |
dcubed@3202 | 148 | } |
dcubed@3202 | 149 | |
dcubed@3202 | 150 | #define DTRACE_CLASSINIT_PROBE_WAIT(type, clss, thread_type, wait) \ |
dcubed@3202 | 151 | { \ |
dcubed@3202 | 152 | char* data = NULL; \ |
dcubed@3202 | 153 | int len = 0; \ |
dcubed@3202 | 154 | Symbol* name = (clss)->name(); \ |
dcubed@3202 | 155 | if (name != NULL) { \ |
dcubed@3202 | 156 | data = (char*)name->bytes(); \ |
dcubed@3202 | 157 | len = name->utf8_length(); \ |
dcubed@3202 | 158 | } \ |
dcubed@3202 | 159 | HOTSPOT_CLASS_INITIALIZATION_##type( \ |
dcubed@3202 | 160 | data, len, (clss)->class_loader(), thread_type, wait); \ |
dcubed@3202 | 161 | } |
dcubed@3202 | 162 | #endif /* USDT2 */ |
fparain@1759 | 163 | |
fparain@1759 | 164 | #else // ndef DTRACE_ENABLED |
fparain@1759 | 165 | |
fparain@1759 | 166 | #define DTRACE_CLASSINIT_PROBE(type, clss, thread_type) |
fparain@1759 | 167 | #define DTRACE_CLASSINIT_PROBE_WAIT(type, clss, thread_type, wait) |
fparain@1759 | 168 | |
fparain@1759 | 169 | #endif // ndef DTRACE_ENABLED |
fparain@1759 | 170 | |
duke@435 | 171 | bool instanceKlass::should_be_initialized() const { |
duke@435 | 172 | return !is_initialized(); |
duke@435 | 173 | } |
duke@435 | 174 | |
duke@435 | 175 | klassVtable* instanceKlass::vtable() const { |
duke@435 | 176 | return new klassVtable(as_klassOop(), start_of_vtable(), vtable_length() / vtableEntry::size()); |
duke@435 | 177 | } |
duke@435 | 178 | |
duke@435 | 179 | klassItable* instanceKlass::itable() const { |
duke@435 | 180 | return new klassItable(as_klassOop()); |
duke@435 | 181 | } |
duke@435 | 182 | |
duke@435 | 183 | void instanceKlass::eager_initialize(Thread *thread) { |
duke@435 | 184 | if (!EagerInitialization) return; |
duke@435 | 185 | |
duke@435 | 186 | if (this->is_not_initialized()) { |
duke@435 | 187 | // abort if the the class has a class initializer |
duke@435 | 188 | if (this->class_initializer() != NULL) return; |
duke@435 | 189 | |
duke@435 | 190 | // abort if it is java.lang.Object (initialization is handled in genesis) |
duke@435 | 191 | klassOop super = this->super(); |
duke@435 | 192 | if (super == NULL) return; |
duke@435 | 193 | |
duke@435 | 194 | // abort if the super class should be initialized |
duke@435 | 195 | if (!instanceKlass::cast(super)->is_initialized()) return; |
duke@435 | 196 | |
duke@435 | 197 | // call body to expose the this pointer |
duke@435 | 198 | instanceKlassHandle this_oop(thread, this->as_klassOop()); |
duke@435 | 199 | eager_initialize_impl(this_oop); |
duke@435 | 200 | } |
duke@435 | 201 | } |
duke@435 | 202 | |
duke@435 | 203 | |
duke@435 | 204 | void instanceKlass::eager_initialize_impl(instanceKlassHandle this_oop) { |
duke@435 | 205 | EXCEPTION_MARK; |
duke@435 | 206 | ObjectLocker ol(this_oop, THREAD); |
duke@435 | 207 | |
duke@435 | 208 | // abort if someone beat us to the initialization |
duke@435 | 209 | if (!this_oop->is_not_initialized()) return; // note: not equivalent to is_initialized() |
duke@435 | 210 | |
coleenp@3368 | 211 | ClassState old_state = this_oop->init_state(); |
duke@435 | 212 | link_class_impl(this_oop, true, THREAD); |
duke@435 | 213 | if (HAS_PENDING_EXCEPTION) { |
duke@435 | 214 | CLEAR_PENDING_EXCEPTION; |
duke@435 | 215 | // Abort if linking the class throws an exception. |
duke@435 | 216 | |
duke@435 | 217 | // Use a test to avoid redundantly resetting the state if there's |
duke@435 | 218 | // no change. Set_init_state() asserts that state changes make |
duke@435 | 219 | // progress, whereas here we might just be spinning in place. |
duke@435 | 220 | if( old_state != this_oop->_init_state ) |
duke@435 | 221 | this_oop->set_init_state (old_state); |
duke@435 | 222 | } else { |
duke@435 | 223 | // linking successfull, mark class as initialized |
duke@435 | 224 | this_oop->set_init_state (fully_initialized); |
duke@435 | 225 | // trace |
duke@435 | 226 | if (TraceClassInitialization) { |
duke@435 | 227 | ResourceMark rm(THREAD); |
duke@435 | 228 | tty->print_cr("[Initialized %s without side effects]", this_oop->external_name()); |
duke@435 | 229 | } |
duke@435 | 230 | } |
duke@435 | 231 | } |
duke@435 | 232 | |
duke@435 | 233 | |
duke@435 | 234 | // See "The Virtual Machine Specification" section 2.16.5 for a detailed explanation of the class initialization |
duke@435 | 235 | // process. The step comments refers to the procedure described in that section. |
duke@435 | 236 | // Note: implementation moved to static method to expose the this pointer. |
duke@435 | 237 | void instanceKlass::initialize(TRAPS) { |
duke@435 | 238 | if (this->should_be_initialized()) { |
duke@435 | 239 | HandleMark hm(THREAD); |
duke@435 | 240 | instanceKlassHandle this_oop(THREAD, this->as_klassOop()); |
duke@435 | 241 | initialize_impl(this_oop, CHECK); |
duke@435 | 242 | // Note: at this point the class may be initialized |
duke@435 | 243 | // OR it may be in the state of being initialized |
duke@435 | 244 | // in case of recursive initialization! |
duke@435 | 245 | } else { |
duke@435 | 246 | assert(is_initialized(), "sanity check"); |
duke@435 | 247 | } |
duke@435 | 248 | } |
duke@435 | 249 | |
duke@435 | 250 | |
duke@435 | 251 | bool instanceKlass::verify_code( |
duke@435 | 252 | instanceKlassHandle this_oop, bool throw_verifyerror, TRAPS) { |
duke@435 | 253 | // 1) Verify the bytecodes |
duke@435 | 254 | Verifier::Mode mode = |
duke@435 | 255 | throw_verifyerror ? Verifier::ThrowException : Verifier::NoException; |
acorn@1408 | 256 | return Verifier::verify(this_oop, mode, this_oop->should_verify_class(), CHECK_false); |
duke@435 | 257 | } |
duke@435 | 258 | |
duke@435 | 259 | |
duke@435 | 260 | // Used exclusively by the shared spaces dump mechanism to prevent |
duke@435 | 261 | // classes mapped into the shared regions in new VMs from appearing linked. |
duke@435 | 262 | |
duke@435 | 263 | void instanceKlass::unlink_class() { |
duke@435 | 264 | assert(is_linked(), "must be linked"); |
duke@435 | 265 | _init_state = loaded; |
duke@435 | 266 | } |
duke@435 | 267 | |
duke@435 | 268 | void instanceKlass::link_class(TRAPS) { |
duke@435 | 269 | assert(is_loaded(), "must be loaded"); |
duke@435 | 270 | if (!is_linked()) { |
duke@435 | 271 | instanceKlassHandle this_oop(THREAD, this->as_klassOop()); |
duke@435 | 272 | link_class_impl(this_oop, true, CHECK); |
duke@435 | 273 | } |
duke@435 | 274 | } |
duke@435 | 275 | |
duke@435 | 276 | // Called to verify that a class can link during initialization, without |
duke@435 | 277 | // throwing a VerifyError. |
duke@435 | 278 | bool instanceKlass::link_class_or_fail(TRAPS) { |
duke@435 | 279 | assert(is_loaded(), "must be loaded"); |
duke@435 | 280 | if (!is_linked()) { |
duke@435 | 281 | instanceKlassHandle this_oop(THREAD, this->as_klassOop()); |
duke@435 | 282 | link_class_impl(this_oop, false, CHECK_false); |
duke@435 | 283 | } |
duke@435 | 284 | return is_linked(); |
duke@435 | 285 | } |
duke@435 | 286 | |
duke@435 | 287 | bool instanceKlass::link_class_impl( |
duke@435 | 288 | instanceKlassHandle this_oop, bool throw_verifyerror, TRAPS) { |
duke@435 | 289 | // check for error state |
duke@435 | 290 | if (this_oop->is_in_error_state()) { |
duke@435 | 291 | ResourceMark rm(THREAD); |
duke@435 | 292 | THROW_MSG_(vmSymbols::java_lang_NoClassDefFoundError(), |
duke@435 | 293 | this_oop->external_name(), false); |
duke@435 | 294 | } |
duke@435 | 295 | // return if already verified |
duke@435 | 296 | if (this_oop->is_linked()) { |
duke@435 | 297 | return true; |
duke@435 | 298 | } |
duke@435 | 299 | |
duke@435 | 300 | // Timing |
duke@435 | 301 | // timer handles recursion |
duke@435 | 302 | assert(THREAD->is_Java_thread(), "non-JavaThread in link_class_impl"); |
duke@435 | 303 | JavaThread* jt = (JavaThread*)THREAD; |
duke@435 | 304 | |
duke@435 | 305 | // link super class before linking this class |
duke@435 | 306 | instanceKlassHandle super(THREAD, this_oop->super()); |
duke@435 | 307 | if (super.not_null()) { |
duke@435 | 308 | if (super->is_interface()) { // check if super class is an interface |
duke@435 | 309 | ResourceMark rm(THREAD); |
duke@435 | 310 | Exceptions::fthrow( |
duke@435 | 311 | THREAD_AND_LOCATION, |
coleenp@2497 | 312 | vmSymbols::java_lang_IncompatibleClassChangeError(), |
duke@435 | 313 | "class %s has interface %s as super class", |
duke@435 | 314 | this_oop->external_name(), |
duke@435 | 315 | super->external_name() |
duke@435 | 316 | ); |
duke@435 | 317 | return false; |
duke@435 | 318 | } |
duke@435 | 319 | |
duke@435 | 320 | link_class_impl(super, throw_verifyerror, CHECK_false); |
duke@435 | 321 | } |
duke@435 | 322 | |
duke@435 | 323 | // link all interfaces implemented by this class before linking this class |
duke@435 | 324 | objArrayHandle interfaces (THREAD, this_oop->local_interfaces()); |
duke@435 | 325 | int num_interfaces = interfaces->length(); |
duke@435 | 326 | for (int index = 0; index < num_interfaces; index++) { |
duke@435 | 327 | HandleMark hm(THREAD); |
duke@435 | 328 | instanceKlassHandle ih(THREAD, klassOop(interfaces->obj_at(index))); |
duke@435 | 329 | link_class_impl(ih, throw_verifyerror, CHECK_false); |
duke@435 | 330 | } |
duke@435 | 331 | |
duke@435 | 332 | // in case the class is linked in the process of linking its superclasses |
duke@435 | 333 | if (this_oop->is_linked()) { |
duke@435 | 334 | return true; |
duke@435 | 335 | } |
duke@435 | 336 | |
mchung@1310 | 337 | // trace only the link time for this klass that includes |
mchung@1310 | 338 | // the verification time |
mchung@1310 | 339 | PerfClassTraceTime vmtimer(ClassLoader::perf_class_link_time(), |
mchung@1310 | 340 | ClassLoader::perf_class_link_selftime(), |
mchung@1310 | 341 | ClassLoader::perf_classes_linked(), |
mchung@1310 | 342 | jt->get_thread_stat()->perf_recursion_counts_addr(), |
mchung@1310 | 343 | jt->get_thread_stat()->perf_timers_addr(), |
mchung@1310 | 344 | PerfClassTraceTime::CLASS_LINK); |
mchung@1310 | 345 | |
duke@435 | 346 | // verification & rewriting |
duke@435 | 347 | { |
duke@435 | 348 | ObjectLocker ol(this_oop, THREAD); |
duke@435 | 349 | // rewritten will have been set if loader constraint error found |
duke@435 | 350 | // on an earlier link attempt |
duke@435 | 351 | // don't verify or rewrite if already rewritten |
duke@435 | 352 | if (!this_oop->is_linked()) { |
duke@435 | 353 | if (!this_oop->is_rewritten()) { |
duke@435 | 354 | { |
duke@435 | 355 | // Timer includes any side effects of class verification (resolution, |
duke@435 | 356 | // etc), but not recursive entry into verify_code(). |
mchung@1310 | 357 | PerfClassTraceTime timer(ClassLoader::perf_class_verify_time(), |
mchung@1310 | 358 | ClassLoader::perf_class_verify_selftime(), |
mchung@1310 | 359 | ClassLoader::perf_classes_verified(), |
mchung@1310 | 360 | jt->get_thread_stat()->perf_recursion_counts_addr(), |
mchung@1310 | 361 | jt->get_thread_stat()->perf_timers_addr(), |
mchung@1310 | 362 | PerfClassTraceTime::CLASS_VERIFY); |
duke@435 | 363 | bool verify_ok = verify_code(this_oop, throw_verifyerror, THREAD); |
duke@435 | 364 | if (!verify_ok) { |
duke@435 | 365 | return false; |
duke@435 | 366 | } |
duke@435 | 367 | } |
duke@435 | 368 | |
duke@435 | 369 | // Just in case a side-effect of verify linked this class already |
duke@435 | 370 | // (which can sometimes happen since the verifier loads classes |
duke@435 | 371 | // using custom class loaders, which are free to initialize things) |
duke@435 | 372 | if (this_oop->is_linked()) { |
duke@435 | 373 | return true; |
duke@435 | 374 | } |
duke@435 | 375 | |
duke@435 | 376 | // also sets rewritten |
duke@435 | 377 | this_oop->rewrite_class(CHECK_false); |
duke@435 | 378 | } |
duke@435 | 379 | |
coleenp@2945 | 380 | // relocate jsrs and link methods after they are all rewritten |
coleenp@2945 | 381 | this_oop->relocate_and_link_methods(CHECK_false); |
coleenp@2945 | 382 | |
duke@435 | 383 | // Initialize the vtable and interface table after |
duke@435 | 384 | // methods have been rewritten since rewrite may |
duke@435 | 385 | // fabricate new methodOops. |
duke@435 | 386 | // also does loader constraint checking |
duke@435 | 387 | if (!this_oop()->is_shared()) { |
duke@435 | 388 | ResourceMark rm(THREAD); |
duke@435 | 389 | this_oop->vtable()->initialize_vtable(true, CHECK_false); |
duke@435 | 390 | this_oop->itable()->initialize_itable(true, CHECK_false); |
duke@435 | 391 | } |
duke@435 | 392 | #ifdef ASSERT |
duke@435 | 393 | else { |
duke@435 | 394 | ResourceMark rm(THREAD); |
duke@435 | 395 | this_oop->vtable()->verify(tty, true); |
duke@435 | 396 | // In case itable verification is ever added. |
duke@435 | 397 | // this_oop->itable()->verify(tty, true); |
duke@435 | 398 | } |
duke@435 | 399 | #endif |
duke@435 | 400 | this_oop->set_init_state(linked); |
duke@435 | 401 | if (JvmtiExport::should_post_class_prepare()) { |
duke@435 | 402 | Thread *thread = THREAD; |
duke@435 | 403 | assert(thread->is_Java_thread(), "thread->is_Java_thread()"); |
duke@435 | 404 | JvmtiExport::post_class_prepare((JavaThread *) thread, this_oop()); |
duke@435 | 405 | } |
duke@435 | 406 | } |
duke@435 | 407 | } |
duke@435 | 408 | return true; |
duke@435 | 409 | } |
duke@435 | 410 | |
duke@435 | 411 | |
duke@435 | 412 | // Rewrite the byte codes of all of the methods of a class. |
duke@435 | 413 | // The rewriter must be called exactly once. Rewriting must happen after |
duke@435 | 414 | // verification but before the first method of the class is executed. |
duke@435 | 415 | void instanceKlass::rewrite_class(TRAPS) { |
duke@435 | 416 | assert(is_loaded(), "must be loaded"); |
duke@435 | 417 | instanceKlassHandle this_oop(THREAD, this->as_klassOop()); |
duke@435 | 418 | if (this_oop->is_rewritten()) { |
duke@435 | 419 | assert(this_oop()->is_shared(), "rewriting an unshared class?"); |
duke@435 | 420 | return; |
duke@435 | 421 | } |
coleenp@2945 | 422 | Rewriter::rewrite(this_oop, CHECK); |
duke@435 | 423 | this_oop->set_rewritten(); |
duke@435 | 424 | } |
duke@435 | 425 | |
coleenp@2945 | 426 | // Now relocate and link method entry points after class is rewritten. |
coleenp@2945 | 427 | // This is outside is_rewritten flag. In case of an exception, it can be |
coleenp@2945 | 428 | // executed more than once. |
coleenp@2945 | 429 | void instanceKlass::relocate_and_link_methods(TRAPS) { |
coleenp@2945 | 430 | assert(is_loaded(), "must be loaded"); |
coleenp@2945 | 431 | instanceKlassHandle this_oop(THREAD, this->as_klassOop()); |
coleenp@2945 | 432 | Rewriter::relocate_and_link(this_oop, CHECK); |
coleenp@2945 | 433 | } |
coleenp@2945 | 434 | |
duke@435 | 435 | |
duke@435 | 436 | void instanceKlass::initialize_impl(instanceKlassHandle this_oop, TRAPS) { |
duke@435 | 437 | // Make sure klass is linked (verified) before initialization |
duke@435 | 438 | // A class could already be verified, since it has been reflected upon. |
duke@435 | 439 | this_oop->link_class(CHECK); |
duke@435 | 440 | |
fparain@1759 | 441 | DTRACE_CLASSINIT_PROBE(required, instanceKlass::cast(this_oop()), -1); |
fparain@1759 | 442 | |
fparain@1759 | 443 | bool wait = false; |
fparain@1759 | 444 | |
duke@435 | 445 | // refer to the JVM book page 47 for description of steps |
duke@435 | 446 | // Step 1 |
duke@435 | 447 | { ObjectLocker ol(this_oop, THREAD); |
duke@435 | 448 | |
duke@435 | 449 | Thread *self = THREAD; // it's passed the current thread |
duke@435 | 450 | |
duke@435 | 451 | // Step 2 |
duke@435 | 452 | // If we were to use wait() instead of waitInterruptibly() then |
duke@435 | 453 | // we might end up throwing IE from link/symbol resolution sites |
duke@435 | 454 | // that aren't expected to throw. This would wreak havoc. See 6320309. |
duke@435 | 455 | while(this_oop->is_being_initialized() && !this_oop->is_reentrant_initialization(self)) { |
fparain@1759 | 456 | wait = true; |
duke@435 | 457 | ol.waitUninterruptibly(CHECK); |
duke@435 | 458 | } |
duke@435 | 459 | |
duke@435 | 460 | // Step 3 |
fparain@1759 | 461 | if (this_oop->is_being_initialized() && this_oop->is_reentrant_initialization(self)) { |
fparain@1759 | 462 | DTRACE_CLASSINIT_PROBE_WAIT(recursive, instanceKlass::cast(this_oop()), -1,wait); |
duke@435 | 463 | return; |
fparain@1759 | 464 | } |
duke@435 | 465 | |
duke@435 | 466 | // Step 4 |
fparain@1759 | 467 | if (this_oop->is_initialized()) { |
fparain@1759 | 468 | DTRACE_CLASSINIT_PROBE_WAIT(concurrent, instanceKlass::cast(this_oop()), -1,wait); |
duke@435 | 469 | return; |
fparain@1759 | 470 | } |
duke@435 | 471 | |
duke@435 | 472 | // Step 5 |
duke@435 | 473 | if (this_oop->is_in_error_state()) { |
fparain@1759 | 474 | DTRACE_CLASSINIT_PROBE_WAIT(erroneous, instanceKlass::cast(this_oop()), -1,wait); |
duke@435 | 475 | ResourceMark rm(THREAD); |
duke@435 | 476 | const char* desc = "Could not initialize class "; |
duke@435 | 477 | const char* className = this_oop->external_name(); |
duke@435 | 478 | size_t msglen = strlen(desc) + strlen(className) + 1; |
kamg@2106 | 479 | char* message = NEW_RESOURCE_ARRAY(char, msglen); |
duke@435 | 480 | if (NULL == message) { |
duke@435 | 481 | // Out of memory: can't create detailed error message |
duke@435 | 482 | THROW_MSG(vmSymbols::java_lang_NoClassDefFoundError(), className); |
duke@435 | 483 | } else { |
duke@435 | 484 | jio_snprintf(message, msglen, "%s%s", desc, className); |
duke@435 | 485 | THROW_MSG(vmSymbols::java_lang_NoClassDefFoundError(), message); |
duke@435 | 486 | } |
duke@435 | 487 | } |
duke@435 | 488 | |
duke@435 | 489 | // Step 6 |
duke@435 | 490 | this_oop->set_init_state(being_initialized); |
duke@435 | 491 | this_oop->set_init_thread(self); |
duke@435 | 492 | } |
duke@435 | 493 | |
duke@435 | 494 | // Step 7 |
duke@435 | 495 | klassOop super_klass = this_oop->super(); |
duke@435 | 496 | if (super_klass != NULL && !this_oop->is_interface() && Klass::cast(super_klass)->should_be_initialized()) { |
duke@435 | 497 | Klass::cast(super_klass)->initialize(THREAD); |
duke@435 | 498 | |
duke@435 | 499 | if (HAS_PENDING_EXCEPTION) { |
duke@435 | 500 | Handle e(THREAD, PENDING_EXCEPTION); |
duke@435 | 501 | CLEAR_PENDING_EXCEPTION; |
duke@435 | 502 | { |
duke@435 | 503 | EXCEPTION_MARK; |
duke@435 | 504 | this_oop->set_initialization_state_and_notify(initialization_error, THREAD); // Locks object, set state, and notify all waiting threads |
duke@435 | 505 | CLEAR_PENDING_EXCEPTION; // ignore any exception thrown, superclass initialization error is thrown below |
duke@435 | 506 | } |
fparain@1759 | 507 | DTRACE_CLASSINIT_PROBE_WAIT(super__failed, instanceKlass::cast(this_oop()), -1,wait); |
duke@435 | 508 | THROW_OOP(e()); |
duke@435 | 509 | } |
duke@435 | 510 | } |
duke@435 | 511 | |
duke@435 | 512 | // Step 8 |
duke@435 | 513 | { |
duke@435 | 514 | assert(THREAD->is_Java_thread(), "non-JavaThread in initialize_impl"); |
duke@435 | 515 | JavaThread* jt = (JavaThread*)THREAD; |
fparain@1759 | 516 | DTRACE_CLASSINIT_PROBE_WAIT(clinit, instanceKlass::cast(this_oop()), -1,wait); |
duke@435 | 517 | // Timer includes any side effects of class initialization (resolution, |
duke@435 | 518 | // etc), but not recursive entry into call_class_initializer(). |
mchung@1310 | 519 | PerfClassTraceTime timer(ClassLoader::perf_class_init_time(), |
mchung@1310 | 520 | ClassLoader::perf_class_init_selftime(), |
mchung@1310 | 521 | ClassLoader::perf_classes_inited(), |
mchung@1310 | 522 | jt->get_thread_stat()->perf_recursion_counts_addr(), |
mchung@1310 | 523 | jt->get_thread_stat()->perf_timers_addr(), |
mchung@1310 | 524 | PerfClassTraceTime::CLASS_CLINIT); |
duke@435 | 525 | this_oop->call_class_initializer(THREAD); |
duke@435 | 526 | } |
duke@435 | 527 | |
duke@435 | 528 | // Step 9 |
duke@435 | 529 | if (!HAS_PENDING_EXCEPTION) { |
duke@435 | 530 | this_oop->set_initialization_state_and_notify(fully_initialized, CHECK); |
duke@435 | 531 | { ResourceMark rm(THREAD); |
duke@435 | 532 | debug_only(this_oop->vtable()->verify(tty, true);) |
duke@435 | 533 | } |
duke@435 | 534 | } |
duke@435 | 535 | else { |
duke@435 | 536 | // Step 10 and 11 |
duke@435 | 537 | Handle e(THREAD, PENDING_EXCEPTION); |
duke@435 | 538 | CLEAR_PENDING_EXCEPTION; |
duke@435 | 539 | { |
duke@435 | 540 | EXCEPTION_MARK; |
duke@435 | 541 | this_oop->set_initialization_state_and_notify(initialization_error, THREAD); |
duke@435 | 542 | CLEAR_PENDING_EXCEPTION; // ignore any exception thrown, class initialization error is thrown below |
duke@435 | 543 | } |
fparain@1759 | 544 | DTRACE_CLASSINIT_PROBE_WAIT(error, instanceKlass::cast(this_oop()), -1,wait); |
never@1577 | 545 | if (e->is_a(SystemDictionary::Error_klass())) { |
duke@435 | 546 | THROW_OOP(e()); |
duke@435 | 547 | } else { |
duke@435 | 548 | JavaCallArguments args(e); |
coleenp@2497 | 549 | THROW_ARG(vmSymbols::java_lang_ExceptionInInitializerError(), |
coleenp@2497 | 550 | vmSymbols::throwable_void_signature(), |
duke@435 | 551 | &args); |
duke@435 | 552 | } |
duke@435 | 553 | } |
fparain@1759 | 554 | DTRACE_CLASSINIT_PROBE_WAIT(end, instanceKlass::cast(this_oop()), -1,wait); |
duke@435 | 555 | } |
duke@435 | 556 | |
duke@435 | 557 | |
duke@435 | 558 | // Note: implementation moved to static method to expose the this pointer. |
duke@435 | 559 | void instanceKlass::set_initialization_state_and_notify(ClassState state, TRAPS) { |
duke@435 | 560 | instanceKlassHandle kh(THREAD, this->as_klassOop()); |
duke@435 | 561 | set_initialization_state_and_notify_impl(kh, state, CHECK); |
duke@435 | 562 | } |
duke@435 | 563 | |
duke@435 | 564 | void instanceKlass::set_initialization_state_and_notify_impl(instanceKlassHandle this_oop, ClassState state, TRAPS) { |
duke@435 | 565 | ObjectLocker ol(this_oop, THREAD); |
duke@435 | 566 | this_oop->set_init_state(state); |
duke@435 | 567 | ol.notify_all(CHECK); |
duke@435 | 568 | } |
duke@435 | 569 | |
duke@435 | 570 | void instanceKlass::add_implementor(klassOop k) { |
duke@435 | 571 | assert(Compile_lock->owned_by_self(), ""); |
duke@435 | 572 | // Filter out my subinterfaces. |
duke@435 | 573 | // (Note: Interfaces are never on the subklass list.) |
duke@435 | 574 | if (instanceKlass::cast(k)->is_interface()) return; |
duke@435 | 575 | |
duke@435 | 576 | // Filter out subclasses whose supers already implement me. |
duke@435 | 577 | // (Note: CHA must walk subclasses of direct implementors |
duke@435 | 578 | // in order to locate indirect implementors.) |
duke@435 | 579 | klassOop sk = instanceKlass::cast(k)->super(); |
duke@435 | 580 | if (sk != NULL && instanceKlass::cast(sk)->implements_interface(as_klassOop())) |
duke@435 | 581 | // We only need to check one immediate superclass, since the |
duke@435 | 582 | // implements_interface query looks at transitive_interfaces. |
duke@435 | 583 | // Any supers of the super have the same (or fewer) transitive_interfaces. |
duke@435 | 584 | return; |
duke@435 | 585 | |
duke@435 | 586 | // Update number of implementors |
duke@435 | 587 | int i = _nof_implementors++; |
duke@435 | 588 | |
duke@435 | 589 | // Record this implementor, if there are not too many already |
duke@435 | 590 | if (i < implementors_limit) { |
duke@435 | 591 | assert(_implementors[i] == NULL, "should be exactly one implementor"); |
duke@435 | 592 | oop_store_without_check((oop*)&_implementors[i], k); |
duke@435 | 593 | } else if (i == implementors_limit) { |
duke@435 | 594 | // clear out the list on first overflow |
duke@435 | 595 | for (int i2 = 0; i2 < implementors_limit; i2++) |
duke@435 | 596 | oop_store_without_check((oop*)&_implementors[i2], NULL); |
duke@435 | 597 | } |
duke@435 | 598 | |
duke@435 | 599 | // The implementor also implements the transitive_interfaces |
duke@435 | 600 | for (int index = 0; index < local_interfaces()->length(); index++) { |
duke@435 | 601 | instanceKlass::cast(klassOop(local_interfaces()->obj_at(index)))->add_implementor(k); |
duke@435 | 602 | } |
duke@435 | 603 | } |
duke@435 | 604 | |
duke@435 | 605 | void instanceKlass::init_implementor() { |
duke@435 | 606 | for (int i = 0; i < implementors_limit; i++) |
duke@435 | 607 | oop_store_without_check((oop*)&_implementors[i], NULL); |
duke@435 | 608 | _nof_implementors = 0; |
duke@435 | 609 | } |
duke@435 | 610 | |
duke@435 | 611 | |
duke@435 | 612 | void instanceKlass::process_interfaces(Thread *thread) { |
duke@435 | 613 | // link this class into the implementors list of every interface it implements |
duke@435 | 614 | KlassHandle this_as_oop (thread, this->as_klassOop()); |
duke@435 | 615 | for (int i = local_interfaces()->length() - 1; i >= 0; i--) { |
duke@435 | 616 | assert(local_interfaces()->obj_at(i)->is_klass(), "must be a klass"); |
duke@435 | 617 | instanceKlass* interf = instanceKlass::cast(klassOop(local_interfaces()->obj_at(i))); |
duke@435 | 618 | assert(interf->is_interface(), "expected interface"); |
duke@435 | 619 | interf->add_implementor(this_as_oop()); |
duke@435 | 620 | } |
duke@435 | 621 | } |
duke@435 | 622 | |
duke@435 | 623 | bool instanceKlass::can_be_primary_super_slow() const { |
duke@435 | 624 | if (is_interface()) |
duke@435 | 625 | return false; |
duke@435 | 626 | else |
duke@435 | 627 | return Klass::can_be_primary_super_slow(); |
duke@435 | 628 | } |
duke@435 | 629 | |
duke@435 | 630 | objArrayOop instanceKlass::compute_secondary_supers(int num_extra_slots, TRAPS) { |
duke@435 | 631 | // The secondaries are the implemented interfaces. |
duke@435 | 632 | instanceKlass* ik = instanceKlass::cast(as_klassOop()); |
duke@435 | 633 | objArrayHandle interfaces (THREAD, ik->transitive_interfaces()); |
duke@435 | 634 | int num_secondaries = num_extra_slots + interfaces->length(); |
duke@435 | 635 | if (num_secondaries == 0) { |
duke@435 | 636 | return Universe::the_empty_system_obj_array(); |
duke@435 | 637 | } else if (num_extra_slots == 0) { |
duke@435 | 638 | return interfaces(); |
duke@435 | 639 | } else { |
duke@435 | 640 | // a mix of both |
duke@435 | 641 | objArrayOop secondaries = oopFactory::new_system_objArray(num_secondaries, CHECK_NULL); |
duke@435 | 642 | for (int i = 0; i < interfaces->length(); i++) { |
duke@435 | 643 | secondaries->obj_at_put(num_extra_slots+i, interfaces->obj_at(i)); |
duke@435 | 644 | } |
duke@435 | 645 | return secondaries; |
duke@435 | 646 | } |
duke@435 | 647 | } |
duke@435 | 648 | |
duke@435 | 649 | bool instanceKlass::compute_is_subtype_of(klassOop k) { |
duke@435 | 650 | if (Klass::cast(k)->is_interface()) { |
duke@435 | 651 | return implements_interface(k); |
duke@435 | 652 | } else { |
duke@435 | 653 | return Klass::compute_is_subtype_of(k); |
duke@435 | 654 | } |
duke@435 | 655 | } |
duke@435 | 656 | |
duke@435 | 657 | bool instanceKlass::implements_interface(klassOop k) const { |
duke@435 | 658 | if (as_klassOop() == k) return true; |
duke@435 | 659 | assert(Klass::cast(k)->is_interface(), "should be an interface class"); |
duke@435 | 660 | for (int i = 0; i < transitive_interfaces()->length(); i++) { |
duke@435 | 661 | if (transitive_interfaces()->obj_at(i) == k) { |
duke@435 | 662 | return true; |
duke@435 | 663 | } |
duke@435 | 664 | } |
duke@435 | 665 | return false; |
duke@435 | 666 | } |
duke@435 | 667 | |
duke@435 | 668 | objArrayOop instanceKlass::allocate_objArray(int n, int length, TRAPS) { |
duke@435 | 669 | if (length < 0) THROW_0(vmSymbols::java_lang_NegativeArraySizeException()); |
duke@435 | 670 | if (length > arrayOopDesc::max_array_length(T_OBJECT)) { |
martin@1311 | 671 | report_java_out_of_memory("Requested array size exceeds VM limit"); |
duke@435 | 672 | THROW_OOP_0(Universe::out_of_memory_error_array_size()); |
duke@435 | 673 | } |
duke@435 | 674 | int size = objArrayOopDesc::object_size(length); |
duke@435 | 675 | klassOop ak = array_klass(n, CHECK_NULL); |
duke@435 | 676 | KlassHandle h_ak (THREAD, ak); |
duke@435 | 677 | objArrayOop o = |
duke@435 | 678 | (objArrayOop)CollectedHeap::array_allocate(h_ak, size, length, CHECK_NULL); |
duke@435 | 679 | return o; |
duke@435 | 680 | } |
duke@435 | 681 | |
duke@435 | 682 | instanceOop instanceKlass::register_finalizer(instanceOop i, TRAPS) { |
duke@435 | 683 | if (TraceFinalizerRegistration) { |
duke@435 | 684 | tty->print("Registered "); |
duke@435 | 685 | i->print_value_on(tty); |
duke@435 | 686 | tty->print_cr(" (" INTPTR_FORMAT ") as finalizable", (address)i); |
duke@435 | 687 | } |
duke@435 | 688 | instanceHandle h_i(THREAD, i); |
duke@435 | 689 | // Pass the handle as argument, JavaCalls::call expects oop as jobjects |
duke@435 | 690 | JavaValue result(T_VOID); |
duke@435 | 691 | JavaCallArguments args(h_i); |
duke@435 | 692 | methodHandle mh (THREAD, Universe::finalizer_register_method()); |
duke@435 | 693 | JavaCalls::call(&result, mh, &args, CHECK_NULL); |
duke@435 | 694 | return h_i(); |
duke@435 | 695 | } |
duke@435 | 696 | |
duke@435 | 697 | instanceOop instanceKlass::allocate_instance(TRAPS) { |
never@2658 | 698 | assert(!oop_is_instanceMirror(), "wrong allocation path"); |
duke@435 | 699 | bool has_finalizer_flag = has_finalizer(); // Query before possible GC |
duke@435 | 700 | int size = size_helper(); // Query before forming handle. |
duke@435 | 701 | |
duke@435 | 702 | KlassHandle h_k(THREAD, as_klassOop()); |
duke@435 | 703 | |
duke@435 | 704 | instanceOop i; |
duke@435 | 705 | |
duke@435 | 706 | i = (instanceOop)CollectedHeap::obj_allocate(h_k, size, CHECK_NULL); |
duke@435 | 707 | if (has_finalizer_flag && !RegisterFinalizersAtInit) { |
duke@435 | 708 | i = register_finalizer(i, CHECK_NULL); |
duke@435 | 709 | } |
duke@435 | 710 | return i; |
duke@435 | 711 | } |
duke@435 | 712 | |
duke@435 | 713 | instanceOop instanceKlass::allocate_permanent_instance(TRAPS) { |
duke@435 | 714 | // Finalizer registration occurs in the Object.<init> constructor |
duke@435 | 715 | // and constructors normally aren't run when allocating perm |
duke@435 | 716 | // instances so simply disallow finalizable perm objects. This can |
duke@435 | 717 | // be relaxed if a need for it is found. |
duke@435 | 718 | assert(!has_finalizer(), "perm objects not allowed to have finalizers"); |
never@2658 | 719 | assert(!oop_is_instanceMirror(), "wrong allocation path"); |
duke@435 | 720 | int size = size_helper(); // Query before forming handle. |
duke@435 | 721 | KlassHandle h_k(THREAD, as_klassOop()); |
duke@435 | 722 | instanceOop i = (instanceOop) |
duke@435 | 723 | CollectedHeap::permanent_obj_allocate(h_k, size, CHECK_NULL); |
duke@435 | 724 | return i; |
duke@435 | 725 | } |
duke@435 | 726 | |
duke@435 | 727 | void instanceKlass::check_valid_for_instantiation(bool throwError, TRAPS) { |
duke@435 | 728 | if (is_interface() || is_abstract()) { |
duke@435 | 729 | ResourceMark rm(THREAD); |
duke@435 | 730 | THROW_MSG(throwError ? vmSymbols::java_lang_InstantiationError() |
duke@435 | 731 | : vmSymbols::java_lang_InstantiationException(), external_name()); |
duke@435 | 732 | } |
never@1577 | 733 | if (as_klassOop() == SystemDictionary::Class_klass()) { |
duke@435 | 734 | ResourceMark rm(THREAD); |
duke@435 | 735 | THROW_MSG(throwError ? vmSymbols::java_lang_IllegalAccessError() |
duke@435 | 736 | : vmSymbols::java_lang_IllegalAccessException(), external_name()); |
duke@435 | 737 | } |
duke@435 | 738 | } |
duke@435 | 739 | |
duke@435 | 740 | klassOop instanceKlass::array_klass_impl(bool or_null, int n, TRAPS) { |
duke@435 | 741 | instanceKlassHandle this_oop(THREAD, as_klassOop()); |
duke@435 | 742 | return array_klass_impl(this_oop, or_null, n, THREAD); |
duke@435 | 743 | } |
duke@435 | 744 | |
duke@435 | 745 | klassOop instanceKlass::array_klass_impl(instanceKlassHandle this_oop, bool or_null, int n, TRAPS) { |
duke@435 | 746 | if (this_oop->array_klasses() == NULL) { |
duke@435 | 747 | if (or_null) return NULL; |
duke@435 | 748 | |
duke@435 | 749 | ResourceMark rm; |
duke@435 | 750 | JavaThread *jt = (JavaThread *)THREAD; |
duke@435 | 751 | { |
duke@435 | 752 | // Atomic creation of array_klasses |
duke@435 | 753 | MutexLocker mc(Compile_lock, THREAD); // for vtables |
duke@435 | 754 | MutexLocker ma(MultiArray_lock, THREAD); |
duke@435 | 755 | |
duke@435 | 756 | // Check if update has already taken place |
duke@435 | 757 | if (this_oop->array_klasses() == NULL) { |
duke@435 | 758 | objArrayKlassKlass* oakk = |
duke@435 | 759 | (objArrayKlassKlass*)Universe::objArrayKlassKlassObj()->klass_part(); |
duke@435 | 760 | |
duke@435 | 761 | klassOop k = oakk->allocate_objArray_klass(1, this_oop, CHECK_NULL); |
duke@435 | 762 | this_oop->set_array_klasses(k); |
duke@435 | 763 | } |
duke@435 | 764 | } |
duke@435 | 765 | } |
duke@435 | 766 | // _this will always be set at this point |
duke@435 | 767 | objArrayKlass* oak = (objArrayKlass*)this_oop->array_klasses()->klass_part(); |
duke@435 | 768 | if (or_null) { |
duke@435 | 769 | return oak->array_klass_or_null(n); |
duke@435 | 770 | } |
duke@435 | 771 | return oak->array_klass(n, CHECK_NULL); |
duke@435 | 772 | } |
duke@435 | 773 | |
duke@435 | 774 | klassOop instanceKlass::array_klass_impl(bool or_null, TRAPS) { |
duke@435 | 775 | return array_klass_impl(or_null, 1, THREAD); |
duke@435 | 776 | } |
duke@435 | 777 | |
duke@435 | 778 | void instanceKlass::call_class_initializer(TRAPS) { |
duke@435 | 779 | instanceKlassHandle ik (THREAD, as_klassOop()); |
duke@435 | 780 | call_class_initializer_impl(ik, THREAD); |
duke@435 | 781 | } |
duke@435 | 782 | |
duke@435 | 783 | static int call_class_initializer_impl_counter = 0; // for debugging |
duke@435 | 784 | |
duke@435 | 785 | methodOop instanceKlass::class_initializer() { |
kamg@2616 | 786 | methodOop clinit = find_method( |
kamg@2616 | 787 | vmSymbols::class_initializer_name(), vmSymbols::void_method_signature()); |
kamg@2616 | 788 | if (clinit != NULL && clinit->has_valid_initializer_flags()) { |
kamg@2616 | 789 | return clinit; |
kamg@2616 | 790 | } |
kamg@2616 | 791 | return NULL; |
duke@435 | 792 | } |
duke@435 | 793 | |
duke@435 | 794 | void instanceKlass::call_class_initializer_impl(instanceKlassHandle this_oop, TRAPS) { |
duke@435 | 795 | methodHandle h_method(THREAD, this_oop->class_initializer()); |
duke@435 | 796 | assert(!this_oop->is_initialized(), "we cannot initialize twice"); |
duke@435 | 797 | if (TraceClassInitialization) { |
duke@435 | 798 | tty->print("%d Initializing ", call_class_initializer_impl_counter++); |
duke@435 | 799 | this_oop->name()->print_value(); |
duke@435 | 800 | tty->print_cr("%s (" INTPTR_FORMAT ")", h_method() == NULL ? "(no method)" : "", (address)this_oop()); |
duke@435 | 801 | } |
duke@435 | 802 | if (h_method() != NULL) { |
duke@435 | 803 | JavaCallArguments args; // No arguments |
duke@435 | 804 | JavaValue result(T_VOID); |
duke@435 | 805 | JavaCalls::call(&result, h_method, &args, CHECK); // Static call (no args) |
duke@435 | 806 | } |
duke@435 | 807 | } |
duke@435 | 808 | |
duke@435 | 809 | |
duke@435 | 810 | void instanceKlass::mask_for(methodHandle method, int bci, |
duke@435 | 811 | InterpreterOopMap* entry_for) { |
duke@435 | 812 | // Dirty read, then double-check under a lock. |
duke@435 | 813 | if (_oop_map_cache == NULL) { |
duke@435 | 814 | // Otherwise, allocate a new one. |
duke@435 | 815 | MutexLocker x(OopMapCacheAlloc_lock); |
duke@435 | 816 | // First time use. Allocate a cache in C heap |
duke@435 | 817 | if (_oop_map_cache == NULL) { |
duke@435 | 818 | _oop_map_cache = new OopMapCache(); |
duke@435 | 819 | } |
duke@435 | 820 | } |
duke@435 | 821 | // _oop_map_cache is constant after init; lookup below does is own locking. |
duke@435 | 822 | _oop_map_cache->lookup(method, bci, entry_for); |
duke@435 | 823 | } |
duke@435 | 824 | |
duke@435 | 825 | |
coleenp@2497 | 826 | bool instanceKlass::find_local_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const { |
never@3137 | 827 | for (JavaFieldStream fs(as_klassOop()); !fs.done(); fs.next()) { |
never@3137 | 828 | Symbol* f_name = fs.name(); |
never@3137 | 829 | Symbol* f_sig = fs.signature(); |
duke@435 | 830 | if (f_name == name && f_sig == sig) { |
never@3137 | 831 | fd->initialize(as_klassOop(), fs.index()); |
duke@435 | 832 | return true; |
duke@435 | 833 | } |
duke@435 | 834 | } |
duke@435 | 835 | return false; |
duke@435 | 836 | } |
duke@435 | 837 | |
duke@435 | 838 | |
coleenp@2497 | 839 | void instanceKlass::shared_symbols_iterate(SymbolClosure* closure) { |
coleenp@2497 | 840 | Klass::shared_symbols_iterate(closure); |
coleenp@2497 | 841 | closure->do_symbol(&_generic_signature); |
coleenp@2497 | 842 | closure->do_symbol(&_source_file_name); |
coleenp@2497 | 843 | closure->do_symbol(&_source_debug_extension); |
coleenp@2497 | 844 | |
never@3137 | 845 | for (JavaFieldStream fs(this); !fs.done(); fs.next()) { |
never@3137 | 846 | int name_index = fs.name_index(); |
coleenp@2497 | 847 | closure->do_symbol(constants()->symbol_at_addr(name_index)); |
never@3137 | 848 | int sig_index = fs.signature_index(); |
coleenp@2497 | 849 | closure->do_symbol(constants()->symbol_at_addr(sig_index)); |
duke@435 | 850 | } |
duke@435 | 851 | } |
duke@435 | 852 | |
duke@435 | 853 | |
coleenp@2497 | 854 | klassOop instanceKlass::find_interface_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const { |
duke@435 | 855 | const int n = local_interfaces()->length(); |
duke@435 | 856 | for (int i = 0; i < n; i++) { |
duke@435 | 857 | klassOop intf1 = klassOop(local_interfaces()->obj_at(i)); |
duke@435 | 858 | assert(Klass::cast(intf1)->is_interface(), "just checking type"); |
duke@435 | 859 | // search for field in current interface |
duke@435 | 860 | if (instanceKlass::cast(intf1)->find_local_field(name, sig, fd)) { |
duke@435 | 861 | assert(fd->is_static(), "interface field must be static"); |
duke@435 | 862 | return intf1; |
duke@435 | 863 | } |
duke@435 | 864 | // search for field in direct superinterfaces |
duke@435 | 865 | klassOop intf2 = instanceKlass::cast(intf1)->find_interface_field(name, sig, fd); |
duke@435 | 866 | if (intf2 != NULL) return intf2; |
duke@435 | 867 | } |
duke@435 | 868 | // otherwise field lookup fails |
duke@435 | 869 | return NULL; |
duke@435 | 870 | } |
duke@435 | 871 | |
duke@435 | 872 | |
coleenp@2497 | 873 | klassOop instanceKlass::find_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const { |
duke@435 | 874 | // search order according to newest JVM spec (5.4.3.2, p.167). |
duke@435 | 875 | // 1) search for field in current klass |
duke@435 | 876 | if (find_local_field(name, sig, fd)) { |
duke@435 | 877 | return as_klassOop(); |
duke@435 | 878 | } |
duke@435 | 879 | // 2) search for field recursively in direct superinterfaces |
duke@435 | 880 | { klassOop intf = find_interface_field(name, sig, fd); |
duke@435 | 881 | if (intf != NULL) return intf; |
duke@435 | 882 | } |
duke@435 | 883 | // 3) apply field lookup recursively if superclass exists |
duke@435 | 884 | { klassOop supr = super(); |
duke@435 | 885 | if (supr != NULL) return instanceKlass::cast(supr)->find_field(name, sig, fd); |
duke@435 | 886 | } |
duke@435 | 887 | // 4) otherwise field lookup fails |
duke@435 | 888 | return NULL; |
duke@435 | 889 | } |
duke@435 | 890 | |
duke@435 | 891 | |
coleenp@2497 | 892 | klassOop instanceKlass::find_field(Symbol* name, Symbol* sig, bool is_static, fieldDescriptor* fd) const { |
duke@435 | 893 | // search order according to newest JVM spec (5.4.3.2, p.167). |
duke@435 | 894 | // 1) search for field in current klass |
duke@435 | 895 | if (find_local_field(name, sig, fd)) { |
duke@435 | 896 | if (fd->is_static() == is_static) return as_klassOop(); |
duke@435 | 897 | } |
duke@435 | 898 | // 2) search for field recursively in direct superinterfaces |
duke@435 | 899 | if (is_static) { |
duke@435 | 900 | klassOop intf = find_interface_field(name, sig, fd); |
duke@435 | 901 | if (intf != NULL) return intf; |
duke@435 | 902 | } |
duke@435 | 903 | // 3) apply field lookup recursively if superclass exists |
duke@435 | 904 | { klassOop supr = super(); |
duke@435 | 905 | if (supr != NULL) return instanceKlass::cast(supr)->find_field(name, sig, is_static, fd); |
duke@435 | 906 | } |
duke@435 | 907 | // 4) otherwise field lookup fails |
duke@435 | 908 | return NULL; |
duke@435 | 909 | } |
duke@435 | 910 | |
duke@435 | 911 | |
duke@435 | 912 | bool instanceKlass::find_local_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const { |
never@3137 | 913 | for (JavaFieldStream fs(as_klassOop()); !fs.done(); fs.next()) { |
never@3137 | 914 | if (fs.offset() == offset) { |
never@3137 | 915 | fd->initialize(as_klassOop(), fs.index()); |
duke@435 | 916 | if (fd->is_static() == is_static) return true; |
duke@435 | 917 | } |
duke@435 | 918 | } |
duke@435 | 919 | return false; |
duke@435 | 920 | } |
duke@435 | 921 | |
duke@435 | 922 | |
duke@435 | 923 | bool instanceKlass::find_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const { |
duke@435 | 924 | klassOop klass = as_klassOop(); |
duke@435 | 925 | while (klass != NULL) { |
duke@435 | 926 | if (instanceKlass::cast(klass)->find_local_field_from_offset(offset, is_static, fd)) { |
duke@435 | 927 | return true; |
duke@435 | 928 | } |
duke@435 | 929 | klass = Klass::cast(klass)->super(); |
duke@435 | 930 | } |
duke@435 | 931 | return false; |
duke@435 | 932 | } |
duke@435 | 933 | |
duke@435 | 934 | |
duke@435 | 935 | void instanceKlass::methods_do(void f(methodOop method)) { |
duke@435 | 936 | int len = methods()->length(); |
duke@435 | 937 | for (int index = 0; index < len; index++) { |
duke@435 | 938 | methodOop m = methodOop(methods()->obj_at(index)); |
duke@435 | 939 | assert(m->is_method(), "must be method"); |
duke@435 | 940 | f(m); |
duke@435 | 941 | } |
duke@435 | 942 | } |
duke@435 | 943 | |
never@2658 | 944 | |
duke@435 | 945 | void instanceKlass::do_local_static_fields(FieldClosure* cl) { |
never@3137 | 946 | for (JavaFieldStream fs(this); !fs.done(); fs.next()) { |
never@3137 | 947 | if (fs.access_flags().is_static()) { |
never@3137 | 948 | fieldDescriptor fd; |
never@3137 | 949 | fd.initialize(as_klassOop(), fs.index()); |
never@3137 | 950 | cl->do_field(&fd); |
never@3137 | 951 | } |
duke@435 | 952 | } |
duke@435 | 953 | } |
duke@435 | 954 | |
duke@435 | 955 | |
duke@435 | 956 | void instanceKlass::do_local_static_fields(void f(fieldDescriptor*, TRAPS), TRAPS) { |
duke@435 | 957 | instanceKlassHandle h_this(THREAD, as_klassOop()); |
duke@435 | 958 | do_local_static_fields_impl(h_this, f, CHECK); |
duke@435 | 959 | } |
duke@435 | 960 | |
duke@435 | 961 | |
duke@435 | 962 | void instanceKlass::do_local_static_fields_impl(instanceKlassHandle this_oop, void f(fieldDescriptor* fd, TRAPS), TRAPS) { |
never@3137 | 963 | for (JavaFieldStream fs(this_oop()); !fs.done(); fs.next()) { |
never@3137 | 964 | if (fs.access_flags().is_static()) { |
never@3137 | 965 | fieldDescriptor fd; |
never@3137 | 966 | fd.initialize(this_oop(), fs.index()); |
never@3137 | 967 | f(&fd, CHECK); |
never@3137 | 968 | } |
duke@435 | 969 | } |
duke@435 | 970 | } |
duke@435 | 971 | |
duke@435 | 972 | |
kvn@479 | 973 | static int compare_fields_by_offset(int* a, int* b) { |
kvn@479 | 974 | return a[0] - b[0]; |
kvn@479 | 975 | } |
kvn@479 | 976 | |
duke@435 | 977 | void instanceKlass::do_nonstatic_fields(FieldClosure* cl) { |
duke@435 | 978 | instanceKlass* super = superklass(); |
duke@435 | 979 | if (super != NULL) { |
duke@435 | 980 | super->do_nonstatic_fields(cl); |
duke@435 | 981 | } |
kvn@479 | 982 | fieldDescriptor fd; |
never@3137 | 983 | int length = java_fields_count(); |
kvn@479 | 984 | // In DebugInfo nonstatic fields are sorted by offset. |
kvn@479 | 985 | int* fields_sorted = NEW_C_HEAP_ARRAY(int, 2*(length+1)); |
kvn@479 | 986 | int j = 0; |
never@3137 | 987 | for (int i = 0; i < length; i += 1) { |
duke@435 | 988 | fd.initialize(as_klassOop(), i); |
kvn@479 | 989 | if (!fd.is_static()) { |
kvn@479 | 990 | fields_sorted[j + 0] = fd.offset(); |
kvn@479 | 991 | fields_sorted[j + 1] = i; |
kvn@479 | 992 | j += 2; |
kvn@479 | 993 | } |
duke@435 | 994 | } |
kvn@479 | 995 | if (j > 0) { |
kvn@479 | 996 | length = j; |
kvn@479 | 997 | // _sort_Fn is defined in growableArray.hpp. |
kvn@479 | 998 | qsort(fields_sorted, length/2, 2*sizeof(int), (_sort_Fn)compare_fields_by_offset); |
kvn@479 | 999 | for (int i = 0; i < length; i += 2) { |
kvn@479 | 1000 | fd.initialize(as_klassOop(), fields_sorted[i + 1]); |
kvn@479 | 1001 | assert(!fd.is_static() && fd.offset() == fields_sorted[i], "only nonstatic fields"); |
kvn@479 | 1002 | cl->do_field(&fd); |
kvn@479 | 1003 | } |
kvn@479 | 1004 | } |
kvn@479 | 1005 | FREE_C_HEAP_ARRAY(int, fields_sorted); |
duke@435 | 1006 | } |
duke@435 | 1007 | |
duke@435 | 1008 | |
duke@435 | 1009 | void instanceKlass::array_klasses_do(void f(klassOop k)) { |
duke@435 | 1010 | if (array_klasses() != NULL) |
duke@435 | 1011 | arrayKlass::cast(array_klasses())->array_klasses_do(f); |
duke@435 | 1012 | } |
duke@435 | 1013 | |
duke@435 | 1014 | |
duke@435 | 1015 | void instanceKlass::with_array_klasses_do(void f(klassOop k)) { |
duke@435 | 1016 | f(as_klassOop()); |
duke@435 | 1017 | array_klasses_do(f); |
duke@435 | 1018 | } |
duke@435 | 1019 | |
duke@435 | 1020 | #ifdef ASSERT |
coleenp@2497 | 1021 | static int linear_search(objArrayOop methods, Symbol* name, Symbol* signature) { |
duke@435 | 1022 | int len = methods->length(); |
duke@435 | 1023 | for (int index = 0; index < len; index++) { |
duke@435 | 1024 | methodOop m = (methodOop)(methods->obj_at(index)); |
duke@435 | 1025 | assert(m->is_method(), "must be method"); |
duke@435 | 1026 | if (m->signature() == signature && m->name() == name) { |
duke@435 | 1027 | return index; |
duke@435 | 1028 | } |
duke@435 | 1029 | } |
duke@435 | 1030 | return -1; |
duke@435 | 1031 | } |
duke@435 | 1032 | #endif |
duke@435 | 1033 | |
coleenp@2497 | 1034 | methodOop instanceKlass::find_method(Symbol* name, Symbol* signature) const { |
duke@435 | 1035 | return instanceKlass::find_method(methods(), name, signature); |
duke@435 | 1036 | } |
duke@435 | 1037 | |
coleenp@2497 | 1038 | methodOop instanceKlass::find_method(objArrayOop methods, Symbol* name, Symbol* signature) { |
duke@435 | 1039 | int len = methods->length(); |
duke@435 | 1040 | // methods are sorted, so do binary search |
duke@435 | 1041 | int l = 0; |
duke@435 | 1042 | int h = len - 1; |
duke@435 | 1043 | while (l <= h) { |
duke@435 | 1044 | int mid = (l + h) >> 1; |
duke@435 | 1045 | methodOop m = (methodOop)methods->obj_at(mid); |
duke@435 | 1046 | assert(m->is_method(), "must be method"); |
duke@435 | 1047 | int res = m->name()->fast_compare(name); |
duke@435 | 1048 | if (res == 0) { |
duke@435 | 1049 | // found matching name; do linear search to find matching signature |
duke@435 | 1050 | // first, quick check for common case |
duke@435 | 1051 | if (m->signature() == signature) return m; |
duke@435 | 1052 | // search downwards through overloaded methods |
duke@435 | 1053 | int i; |
duke@435 | 1054 | for (i = mid - 1; i >= l; i--) { |
duke@435 | 1055 | methodOop m = (methodOop)methods->obj_at(i); |
duke@435 | 1056 | assert(m->is_method(), "must be method"); |
duke@435 | 1057 | if (m->name() != name) break; |
duke@435 | 1058 | if (m->signature() == signature) return m; |
duke@435 | 1059 | } |
duke@435 | 1060 | // search upwards |
duke@435 | 1061 | for (i = mid + 1; i <= h; i++) { |
duke@435 | 1062 | methodOop m = (methodOop)methods->obj_at(i); |
duke@435 | 1063 | assert(m->is_method(), "must be method"); |
duke@435 | 1064 | if (m->name() != name) break; |
duke@435 | 1065 | if (m->signature() == signature) return m; |
duke@435 | 1066 | } |
duke@435 | 1067 | // not found |
duke@435 | 1068 | #ifdef ASSERT |
duke@435 | 1069 | int index = linear_search(methods, name, signature); |
jcoomes@1845 | 1070 | assert(index == -1, err_msg("binary search should have found entry %d", index)); |
duke@435 | 1071 | #endif |
duke@435 | 1072 | return NULL; |
duke@435 | 1073 | } else if (res < 0) { |
duke@435 | 1074 | l = mid + 1; |
duke@435 | 1075 | } else { |
duke@435 | 1076 | h = mid - 1; |
duke@435 | 1077 | } |
duke@435 | 1078 | } |
duke@435 | 1079 | #ifdef ASSERT |
duke@435 | 1080 | int index = linear_search(methods, name, signature); |
jcoomes@1845 | 1081 | assert(index == -1, err_msg("binary search should have found entry %d", index)); |
duke@435 | 1082 | #endif |
duke@435 | 1083 | return NULL; |
duke@435 | 1084 | } |
duke@435 | 1085 | |
coleenp@2497 | 1086 | methodOop instanceKlass::uncached_lookup_method(Symbol* name, Symbol* signature) const { |
duke@435 | 1087 | klassOop klass = as_klassOop(); |
duke@435 | 1088 | while (klass != NULL) { |
duke@435 | 1089 | methodOop method = instanceKlass::cast(klass)->find_method(name, signature); |
duke@435 | 1090 | if (method != NULL) return method; |
duke@435 | 1091 | klass = instanceKlass::cast(klass)->super(); |
duke@435 | 1092 | } |
duke@435 | 1093 | return NULL; |
duke@435 | 1094 | } |
duke@435 | 1095 | |
duke@435 | 1096 | // lookup a method in all the interfaces that this class implements |
coleenp@2497 | 1097 | methodOop instanceKlass::lookup_method_in_all_interfaces(Symbol* name, |
coleenp@2497 | 1098 | Symbol* signature) const { |
duke@435 | 1099 | objArrayOop all_ifs = instanceKlass::cast(as_klassOop())->transitive_interfaces(); |
duke@435 | 1100 | int num_ifs = all_ifs->length(); |
duke@435 | 1101 | instanceKlass *ik = NULL; |
duke@435 | 1102 | for (int i = 0; i < num_ifs; i++) { |
duke@435 | 1103 | ik = instanceKlass::cast(klassOop(all_ifs->obj_at(i))); |
duke@435 | 1104 | methodOop m = ik->lookup_method(name, signature); |
duke@435 | 1105 | if (m != NULL) { |
duke@435 | 1106 | return m; |
duke@435 | 1107 | } |
duke@435 | 1108 | } |
duke@435 | 1109 | return NULL; |
duke@435 | 1110 | } |
duke@435 | 1111 | |
duke@435 | 1112 | /* jni_id_for_impl for jfieldIds only */ |
duke@435 | 1113 | JNIid* instanceKlass::jni_id_for_impl(instanceKlassHandle this_oop, int offset) { |
duke@435 | 1114 | MutexLocker ml(JfieldIdCreation_lock); |
duke@435 | 1115 | // Retry lookup after we got the lock |
duke@435 | 1116 | JNIid* probe = this_oop->jni_ids() == NULL ? NULL : this_oop->jni_ids()->find(offset); |
duke@435 | 1117 | if (probe == NULL) { |
duke@435 | 1118 | // Slow case, allocate new static field identifier |
duke@435 | 1119 | probe = new JNIid(this_oop->as_klassOop(), offset, this_oop->jni_ids()); |
duke@435 | 1120 | this_oop->set_jni_ids(probe); |
duke@435 | 1121 | } |
duke@435 | 1122 | return probe; |
duke@435 | 1123 | } |
duke@435 | 1124 | |
duke@435 | 1125 | |
duke@435 | 1126 | /* jni_id_for for jfieldIds only */ |
duke@435 | 1127 | JNIid* instanceKlass::jni_id_for(int offset) { |
duke@435 | 1128 | JNIid* probe = jni_ids() == NULL ? NULL : jni_ids()->find(offset); |
duke@435 | 1129 | if (probe == NULL) { |
duke@435 | 1130 | probe = jni_id_for_impl(this->as_klassOop(), offset); |
duke@435 | 1131 | } |
duke@435 | 1132 | return probe; |
duke@435 | 1133 | } |
duke@435 | 1134 | |
duke@435 | 1135 | |
duke@435 | 1136 | // Lookup or create a jmethodID. |
dcubed@1412 | 1137 | // This code is called by the VMThread and JavaThreads so the |
dcubed@1412 | 1138 | // locking has to be done very carefully to avoid deadlocks |
dcubed@1412 | 1139 | // and/or other cache consistency problems. |
dcubed@1412 | 1140 | // |
dcubed@1412 | 1141 | jmethodID instanceKlass::get_jmethod_id(instanceKlassHandle ik_h, methodHandle method_h) { |
duke@435 | 1142 | size_t idnum = (size_t)method_h->method_idnum(); |
duke@435 | 1143 | jmethodID* jmeths = ik_h->methods_jmethod_ids_acquire(); |
duke@435 | 1144 | size_t length = 0; |
duke@435 | 1145 | jmethodID id = NULL; |
duke@435 | 1146 | |
dcubed@1412 | 1147 | // We use a double-check locking idiom here because this cache is |
dcubed@1412 | 1148 | // performance sensitive. In the normal system, this cache only |
dcubed@1412 | 1149 | // transitions from NULL to non-NULL which is safe because we use |
dcubed@1412 | 1150 | // release_set_methods_jmethod_ids() to advertise the new cache. |
dcubed@1412 | 1151 | // A partially constructed cache should never be seen by a racing |
dcubed@1412 | 1152 | // thread. We also use release_store_ptr() to save a new jmethodID |
dcubed@1412 | 1153 | // in the cache so a partially constructed jmethodID should never be |
dcubed@1412 | 1154 | // seen either. Cache reads of existing jmethodIDs proceed without a |
dcubed@1412 | 1155 | // lock, but cache writes of a new jmethodID requires uniqueness and |
dcubed@1412 | 1156 | // creation of the cache itself requires no leaks so a lock is |
dcubed@1412 | 1157 | // generally acquired in those two cases. |
dcubed@1412 | 1158 | // |
dcubed@1412 | 1159 | // If the RedefineClasses() API has been used, then this cache can |
dcubed@1412 | 1160 | // grow and we'll have transitions from non-NULL to bigger non-NULL. |
dcubed@1412 | 1161 | // Cache creation requires no leaks and we require safety between all |
dcubed@1412 | 1162 | // cache accesses and freeing of the old cache so a lock is generally |
dcubed@1412 | 1163 | // acquired when the RedefineClasses() API has been used. |
duke@435 | 1164 | |
dcubed@1412 | 1165 | if (jmeths != NULL) { |
dcubed@1412 | 1166 | // the cache already exists |
dcubed@1412 | 1167 | if (!ik_h->idnum_can_increment()) { |
dcubed@1412 | 1168 | // the cache can't grow so we can just get the current values |
dcubed@1412 | 1169 | get_jmethod_id_length_value(jmeths, idnum, &length, &id); |
dcubed@1412 | 1170 | } else { |
dcubed@1412 | 1171 | // cache can grow so we have to be more careful |
dcubed@1412 | 1172 | if (Threads::number_of_threads() == 0 || |
dcubed@1412 | 1173 | SafepointSynchronize::is_at_safepoint()) { |
dcubed@1412 | 1174 | // we're single threaded or at a safepoint - no locking needed |
dcubed@1412 | 1175 | get_jmethod_id_length_value(jmeths, idnum, &length, &id); |
dcubed@1412 | 1176 | } else { |
dcubed@1412 | 1177 | MutexLocker ml(JmethodIdCreation_lock); |
dcubed@1412 | 1178 | get_jmethod_id_length_value(jmeths, idnum, &length, &id); |
dcubed@1412 | 1179 | } |
dcubed@1412 | 1180 | } |
dcubed@1412 | 1181 | } |
dcubed@1412 | 1182 | // implied else: |
dcubed@1412 | 1183 | // we need to allocate a cache so default length and id values are good |
dcubed@1412 | 1184 | |
dcubed@1412 | 1185 | if (jmeths == NULL || // no cache yet |
dcubed@1412 | 1186 | length <= idnum || // cache is too short |
dcubed@1412 | 1187 | id == NULL) { // cache doesn't contain entry |
dcubed@1412 | 1188 | |
dcubed@1412 | 1189 | // This function can be called by the VMThread so we have to do all |
dcubed@1412 | 1190 | // things that might block on a safepoint before grabbing the lock. |
dcubed@1412 | 1191 | // Otherwise, we can deadlock with the VMThread or have a cache |
dcubed@1412 | 1192 | // consistency issue. These vars keep track of what we might have |
dcubed@1412 | 1193 | // to free after the lock is dropped. |
dcubed@1412 | 1194 | jmethodID to_dealloc_id = NULL; |
dcubed@1412 | 1195 | jmethodID* to_dealloc_jmeths = NULL; |
dcubed@1412 | 1196 | |
dcubed@1412 | 1197 | // may not allocate new_jmeths or use it if we allocate it |
duke@435 | 1198 | jmethodID* new_jmeths = NULL; |
duke@435 | 1199 | if (length <= idnum) { |
dcubed@1412 | 1200 | // allocate a new cache that might be used |
duke@435 | 1201 | size_t size = MAX2(idnum+1, (size_t)ik_h->idnum_allocated_count()); |
duke@435 | 1202 | new_jmeths = NEW_C_HEAP_ARRAY(jmethodID, size+1); |
duke@435 | 1203 | memset(new_jmeths, 0, (size+1)*sizeof(jmethodID)); |
dcubed@1412 | 1204 | // cache size is stored in element[0], other elements offset by one |
dcubed@1412 | 1205 | new_jmeths[0] = (jmethodID)size; |
duke@435 | 1206 | } |
duke@435 | 1207 | |
dcubed@1412 | 1208 | // allocate a new jmethodID that might be used |
duke@435 | 1209 | jmethodID new_id = NULL; |
duke@435 | 1210 | if (method_h->is_old() && !method_h->is_obsolete()) { |
duke@435 | 1211 | // The method passed in is old (but not obsolete), we need to use the current version |
duke@435 | 1212 | methodOop current_method = ik_h->method_with_idnum((int)idnum); |
duke@435 | 1213 | assert(current_method != NULL, "old and but not obsolete, so should exist"); |
duke@435 | 1214 | methodHandle current_method_h(current_method == NULL? method_h() : current_method); |
duke@435 | 1215 | new_id = JNIHandles::make_jmethod_id(current_method_h); |
duke@435 | 1216 | } else { |
duke@435 | 1217 | // It is the current version of the method or an obsolete method, |
duke@435 | 1218 | // use the version passed in |
duke@435 | 1219 | new_id = JNIHandles::make_jmethod_id(method_h); |
duke@435 | 1220 | } |
duke@435 | 1221 | |
dcubed@1412 | 1222 | if (Threads::number_of_threads() == 0 || |
dcubed@1412 | 1223 | SafepointSynchronize::is_at_safepoint()) { |
dcubed@1412 | 1224 | // we're single threaded or at a safepoint - no locking needed |
dcubed@1412 | 1225 | id = get_jmethod_id_fetch_or_update(ik_h, idnum, new_id, new_jmeths, |
dcubed@1412 | 1226 | &to_dealloc_id, &to_dealloc_jmeths); |
dcubed@484 | 1227 | } else { |
duke@435 | 1228 | MutexLocker ml(JmethodIdCreation_lock); |
dcubed@1412 | 1229 | id = get_jmethod_id_fetch_or_update(ik_h, idnum, new_id, new_jmeths, |
dcubed@1412 | 1230 | &to_dealloc_id, &to_dealloc_jmeths); |
dcubed@1412 | 1231 | } |
dcubed@1412 | 1232 | |
dcubed@1412 | 1233 | // The lock has been dropped so we can free resources. |
dcubed@1412 | 1234 | // Free up either the old cache or the new cache if we allocated one. |
dcubed@1412 | 1235 | if (to_dealloc_jmeths != NULL) { |
dcubed@1412 | 1236 | FreeHeap(to_dealloc_jmeths); |
dcubed@1412 | 1237 | } |
dcubed@1412 | 1238 | // free up the new ID since it wasn't needed |
dcubed@1412 | 1239 | if (to_dealloc_id != NULL) { |
dcubed@1412 | 1240 | JNIHandles::destroy_jmethod_id(to_dealloc_id); |
dcubed@484 | 1241 | } |
dcubed@484 | 1242 | } |
dcubed@484 | 1243 | return id; |
dcubed@484 | 1244 | } |
duke@435 | 1245 | |
duke@435 | 1246 | |
dcubed@1412 | 1247 | // Common code to fetch the jmethodID from the cache or update the |
dcubed@1412 | 1248 | // cache with the new jmethodID. This function should never do anything |
dcubed@1412 | 1249 | // that causes the caller to go to a safepoint or we can deadlock with |
dcubed@1412 | 1250 | // the VMThread or have cache consistency issues. |
dcubed@1412 | 1251 | // |
dcubed@1412 | 1252 | jmethodID instanceKlass::get_jmethod_id_fetch_or_update( |
dcubed@1412 | 1253 | instanceKlassHandle ik_h, size_t idnum, jmethodID new_id, |
dcubed@1412 | 1254 | jmethodID* new_jmeths, jmethodID* to_dealloc_id_p, |
dcubed@1412 | 1255 | jmethodID** to_dealloc_jmeths_p) { |
dcubed@1412 | 1256 | assert(new_id != NULL, "sanity check"); |
dcubed@1412 | 1257 | assert(to_dealloc_id_p != NULL, "sanity check"); |
dcubed@1412 | 1258 | assert(to_dealloc_jmeths_p != NULL, "sanity check"); |
dcubed@1412 | 1259 | assert(Threads::number_of_threads() == 0 || |
dcubed@1412 | 1260 | SafepointSynchronize::is_at_safepoint() || |
dcubed@1412 | 1261 | JmethodIdCreation_lock->owned_by_self(), "sanity check"); |
dcubed@1412 | 1262 | |
dcubed@1412 | 1263 | // reacquire the cache - we are locked, single threaded or at a safepoint |
dcubed@484 | 1264 | jmethodID* jmeths = ik_h->methods_jmethod_ids_acquire(); |
dcubed@1412 | 1265 | jmethodID id = NULL; |
dcubed@1412 | 1266 | size_t length = 0; |
dcubed@484 | 1267 | |
dcubed@1412 | 1268 | if (jmeths == NULL || // no cache yet |
dcubed@1412 | 1269 | (length = (size_t)jmeths[0]) <= idnum) { // cache is too short |
dcubed@484 | 1270 | if (jmeths != NULL) { |
dcubed@1412 | 1271 | // copy any existing entries from the old cache |
dcubed@484 | 1272 | for (size_t index = 0; index < length; index++) { |
dcubed@484 | 1273 | new_jmeths[index+1] = jmeths[index+1]; |
duke@435 | 1274 | } |
dcubed@1412 | 1275 | *to_dealloc_jmeths_p = jmeths; // save old cache for later delete |
duke@435 | 1276 | } |
dcubed@484 | 1277 | ik_h->release_set_methods_jmethod_ids(jmeths = new_jmeths); |
dcubed@484 | 1278 | } else { |
dcubed@1412 | 1279 | // fetch jmethodID (if any) from the existing cache |
dcubed@484 | 1280 | id = jmeths[idnum+1]; |
dcubed@1412 | 1281 | *to_dealloc_jmeths_p = new_jmeths; // save new cache for later delete |
dcubed@484 | 1282 | } |
dcubed@484 | 1283 | if (id == NULL) { |
dcubed@1412 | 1284 | // No matching jmethodID in the existing cache or we have a new |
dcubed@1412 | 1285 | // cache or we just grew the cache. This cache write is done here |
dcubed@1412 | 1286 | // by the first thread to win the foot race because a jmethodID |
dcubed@1412 | 1287 | // needs to be unique once it is generally available. |
dcubed@484 | 1288 | id = new_id; |
dcubed@1412 | 1289 | |
dcubed@1412 | 1290 | // The jmethodID cache can be read while unlocked so we have to |
dcubed@1412 | 1291 | // make sure the new jmethodID is complete before installing it |
dcubed@1412 | 1292 | // in the cache. |
dcubed@1412 | 1293 | OrderAccess::release_store_ptr(&jmeths[idnum+1], id); |
dcubed@484 | 1294 | } else { |
dcubed@1412 | 1295 | *to_dealloc_id_p = new_id; // save new id for later delete |
duke@435 | 1296 | } |
duke@435 | 1297 | return id; |
duke@435 | 1298 | } |
duke@435 | 1299 | |
duke@435 | 1300 | |
dcubed@1412 | 1301 | // Common code to get the jmethodID cache length and the jmethodID |
dcubed@1412 | 1302 | // value at index idnum if there is one. |
dcubed@1412 | 1303 | // |
dcubed@1412 | 1304 | void instanceKlass::get_jmethod_id_length_value(jmethodID* cache, |
dcubed@1412 | 1305 | size_t idnum, size_t *length_p, jmethodID* id_p) { |
dcubed@1412 | 1306 | assert(cache != NULL, "sanity check"); |
dcubed@1412 | 1307 | assert(length_p != NULL, "sanity check"); |
dcubed@1412 | 1308 | assert(id_p != NULL, "sanity check"); |
dcubed@1412 | 1309 | |
dcubed@1412 | 1310 | // cache size is stored in element[0], other elements offset by one |
dcubed@1412 | 1311 | *length_p = (size_t)cache[0]; |
dcubed@1412 | 1312 | if (*length_p <= idnum) { // cache is too short |
dcubed@1412 | 1313 | *id_p = NULL; |
dcubed@1412 | 1314 | } else { |
dcubed@1412 | 1315 | *id_p = cache[idnum+1]; // fetch jmethodID (if any) |
dcubed@1412 | 1316 | } |
dcubed@1412 | 1317 | } |
dcubed@1412 | 1318 | |
dcubed@1412 | 1319 | |
duke@435 | 1320 | // Lookup a jmethodID, NULL if not found. Do no blocking, no allocations, no handles |
duke@435 | 1321 | jmethodID instanceKlass::jmethod_id_or_null(methodOop method) { |
duke@435 | 1322 | size_t idnum = (size_t)method->method_idnum(); |
duke@435 | 1323 | jmethodID* jmeths = methods_jmethod_ids_acquire(); |
duke@435 | 1324 | size_t length; // length assigned as debugging crumb |
duke@435 | 1325 | jmethodID id = NULL; |
dcubed@1412 | 1326 | if (jmeths != NULL && // If there is a cache |
duke@435 | 1327 | (length = (size_t)jmeths[0]) > idnum) { // and if it is long enough, |
duke@435 | 1328 | id = jmeths[idnum+1]; // Look up the id (may be NULL) |
duke@435 | 1329 | } |
duke@435 | 1330 | return id; |
duke@435 | 1331 | } |
duke@435 | 1332 | |
duke@435 | 1333 | |
duke@435 | 1334 | // Cache an itable index |
duke@435 | 1335 | void instanceKlass::set_cached_itable_index(size_t idnum, int index) { |
duke@435 | 1336 | int* indices = methods_cached_itable_indices_acquire(); |
dcubed@1412 | 1337 | int* to_dealloc_indices = NULL; |
dcubed@1412 | 1338 | |
dcubed@1412 | 1339 | // We use a double-check locking idiom here because this cache is |
dcubed@1412 | 1340 | // performance sensitive. In the normal system, this cache only |
dcubed@1412 | 1341 | // transitions from NULL to non-NULL which is safe because we use |
dcubed@1412 | 1342 | // release_set_methods_cached_itable_indices() to advertise the |
dcubed@1412 | 1343 | // new cache. A partially constructed cache should never be seen |
dcubed@1412 | 1344 | // by a racing thread. Cache reads and writes proceed without a |
dcubed@1412 | 1345 | // lock, but creation of the cache itself requires no leaks so a |
dcubed@1412 | 1346 | // lock is generally acquired in that case. |
dcubed@1412 | 1347 | // |
dcubed@1412 | 1348 | // If the RedefineClasses() API has been used, then this cache can |
dcubed@1412 | 1349 | // grow and we'll have transitions from non-NULL to bigger non-NULL. |
dcubed@1412 | 1350 | // Cache creation requires no leaks and we require safety between all |
dcubed@1412 | 1351 | // cache accesses and freeing of the old cache so a lock is generally |
dcubed@1412 | 1352 | // acquired when the RedefineClasses() API has been used. |
dcubed@1412 | 1353 | |
dcubed@1412 | 1354 | if (indices == NULL || idnum_can_increment()) { |
dcubed@1412 | 1355 | // we need a cache or the cache can grow |
duke@435 | 1356 | MutexLocker ml(JNICachedItableIndex_lock); |
dcubed@1412 | 1357 | // reacquire the cache to see if another thread already did the work |
duke@435 | 1358 | indices = methods_cached_itable_indices_acquire(); |
duke@435 | 1359 | size_t length = 0; |
dcubed@1412 | 1360 | // cache size is stored in element[0], other elements offset by one |
duke@435 | 1361 | if (indices == NULL || (length = (size_t)indices[0]) <= idnum) { |
duke@435 | 1362 | size_t size = MAX2(idnum+1, (size_t)idnum_allocated_count()); |
duke@435 | 1363 | int* new_indices = NEW_C_HEAP_ARRAY(int, size+1); |
dcubed@1412 | 1364 | new_indices[0] = (int)size; |
dcubed@1412 | 1365 | // copy any existing entries |
duke@435 | 1366 | size_t i; |
duke@435 | 1367 | for (i = 0; i < length; i++) { |
duke@435 | 1368 | new_indices[i+1] = indices[i+1]; |
duke@435 | 1369 | } |
duke@435 | 1370 | // Set all the rest to -1 |
duke@435 | 1371 | for (i = length; i < size; i++) { |
duke@435 | 1372 | new_indices[i+1] = -1; |
duke@435 | 1373 | } |
duke@435 | 1374 | if (indices != NULL) { |
dcubed@1412 | 1375 | // We have an old cache to delete so save it for after we |
dcubed@1412 | 1376 | // drop the lock. |
dcubed@1412 | 1377 | to_dealloc_indices = indices; |
duke@435 | 1378 | } |
duke@435 | 1379 | release_set_methods_cached_itable_indices(indices = new_indices); |
duke@435 | 1380 | } |
dcubed@1412 | 1381 | |
dcubed@1412 | 1382 | if (idnum_can_increment()) { |
dcubed@1412 | 1383 | // this cache can grow so we have to write to it safely |
dcubed@1412 | 1384 | indices[idnum+1] = index; |
dcubed@1412 | 1385 | } |
duke@435 | 1386 | } else { |
duke@435 | 1387 | CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops()); |
duke@435 | 1388 | } |
dcubed@1412 | 1389 | |
dcubed@1412 | 1390 | if (!idnum_can_increment()) { |
dcubed@1412 | 1391 | // The cache cannot grow and this JNI itable index value does not |
dcubed@1412 | 1392 | // have to be unique like a jmethodID. If there is a race to set it, |
dcubed@1412 | 1393 | // it doesn't matter. |
dcubed@1412 | 1394 | indices[idnum+1] = index; |
dcubed@1412 | 1395 | } |
dcubed@1412 | 1396 | |
dcubed@1412 | 1397 | if (to_dealloc_indices != NULL) { |
dcubed@1412 | 1398 | // we allocated a new cache so free the old one |
dcubed@1412 | 1399 | FreeHeap(to_dealloc_indices); |
dcubed@1412 | 1400 | } |
duke@435 | 1401 | } |
duke@435 | 1402 | |
duke@435 | 1403 | |
duke@435 | 1404 | // Retrieve a cached itable index |
duke@435 | 1405 | int instanceKlass::cached_itable_index(size_t idnum) { |
duke@435 | 1406 | int* indices = methods_cached_itable_indices_acquire(); |
duke@435 | 1407 | if (indices != NULL && ((size_t)indices[0]) > idnum) { |
duke@435 | 1408 | // indices exist and are long enough, retrieve possible cached |
duke@435 | 1409 | return indices[idnum+1]; |
duke@435 | 1410 | } |
duke@435 | 1411 | return -1; |
duke@435 | 1412 | } |
duke@435 | 1413 | |
duke@435 | 1414 | |
duke@435 | 1415 | // |
duke@435 | 1416 | // Walk the list of dependent nmethods searching for nmethods which |
twisti@3050 | 1417 | // are dependent on the changes that were passed in and mark them for |
duke@435 | 1418 | // deoptimization. Returns the number of nmethods found. |
duke@435 | 1419 | // |
duke@435 | 1420 | int instanceKlass::mark_dependent_nmethods(DepChange& changes) { |
duke@435 | 1421 | assert_locked_or_safepoint(CodeCache_lock); |
duke@435 | 1422 | int found = 0; |
duke@435 | 1423 | nmethodBucket* b = _dependencies; |
duke@435 | 1424 | while (b != NULL) { |
duke@435 | 1425 | nmethod* nm = b->get_nmethod(); |
duke@435 | 1426 | // since dependencies aren't removed until an nmethod becomes a zombie, |
duke@435 | 1427 | // the dependency list may contain nmethods which aren't alive. |
duke@435 | 1428 | if (nm->is_alive() && !nm->is_marked_for_deoptimization() && nm->check_dependency_on(changes)) { |
duke@435 | 1429 | if (TraceDependencies) { |
duke@435 | 1430 | ResourceMark rm; |
duke@435 | 1431 | tty->print_cr("Marked for deoptimization"); |
duke@435 | 1432 | tty->print_cr(" context = %s", this->external_name()); |
duke@435 | 1433 | changes.print(); |
duke@435 | 1434 | nm->print(); |
duke@435 | 1435 | nm->print_dependencies(); |
duke@435 | 1436 | } |
duke@435 | 1437 | nm->mark_for_deoptimization(); |
duke@435 | 1438 | found++; |
duke@435 | 1439 | } |
duke@435 | 1440 | b = b->next(); |
duke@435 | 1441 | } |
duke@435 | 1442 | return found; |
duke@435 | 1443 | } |
duke@435 | 1444 | |
duke@435 | 1445 | |
duke@435 | 1446 | // |
duke@435 | 1447 | // Add an nmethodBucket to the list of dependencies for this nmethod. |
duke@435 | 1448 | // It's possible that an nmethod has multiple dependencies on this klass |
duke@435 | 1449 | // so a count is kept for each bucket to guarantee that creation and |
duke@435 | 1450 | // deletion of dependencies is consistent. |
duke@435 | 1451 | // |
duke@435 | 1452 | void instanceKlass::add_dependent_nmethod(nmethod* nm) { |
duke@435 | 1453 | assert_locked_or_safepoint(CodeCache_lock); |
duke@435 | 1454 | nmethodBucket* b = _dependencies; |
duke@435 | 1455 | nmethodBucket* last = NULL; |
duke@435 | 1456 | while (b != NULL) { |
duke@435 | 1457 | if (nm == b->get_nmethod()) { |
duke@435 | 1458 | b->increment(); |
duke@435 | 1459 | return; |
duke@435 | 1460 | } |
duke@435 | 1461 | b = b->next(); |
duke@435 | 1462 | } |
duke@435 | 1463 | _dependencies = new nmethodBucket(nm, _dependencies); |
duke@435 | 1464 | } |
duke@435 | 1465 | |
duke@435 | 1466 | |
duke@435 | 1467 | // |
duke@435 | 1468 | // Decrement count of the nmethod in the dependency list and remove |
duke@435 | 1469 | // the bucket competely when the count goes to 0. This method must |
duke@435 | 1470 | // find a corresponding bucket otherwise there's a bug in the |
duke@435 | 1471 | // recording of dependecies. |
duke@435 | 1472 | // |
duke@435 | 1473 | void instanceKlass::remove_dependent_nmethod(nmethod* nm) { |
duke@435 | 1474 | assert_locked_or_safepoint(CodeCache_lock); |
duke@435 | 1475 | nmethodBucket* b = _dependencies; |
duke@435 | 1476 | nmethodBucket* last = NULL; |
duke@435 | 1477 | while (b != NULL) { |
duke@435 | 1478 | if (nm == b->get_nmethod()) { |
duke@435 | 1479 | if (b->decrement() == 0) { |
duke@435 | 1480 | if (last == NULL) { |
duke@435 | 1481 | _dependencies = b->next(); |
duke@435 | 1482 | } else { |
duke@435 | 1483 | last->set_next(b->next()); |
duke@435 | 1484 | } |
duke@435 | 1485 | delete b; |
duke@435 | 1486 | } |
duke@435 | 1487 | return; |
duke@435 | 1488 | } |
duke@435 | 1489 | last = b; |
duke@435 | 1490 | b = b->next(); |
duke@435 | 1491 | } |
duke@435 | 1492 | #ifdef ASSERT |
duke@435 | 1493 | tty->print_cr("### %s can't find dependent nmethod:", this->external_name()); |
duke@435 | 1494 | nm->print(); |
duke@435 | 1495 | #endif // ASSERT |
duke@435 | 1496 | ShouldNotReachHere(); |
duke@435 | 1497 | } |
duke@435 | 1498 | |
duke@435 | 1499 | |
duke@435 | 1500 | #ifndef PRODUCT |
duke@435 | 1501 | void instanceKlass::print_dependent_nmethods(bool verbose) { |
duke@435 | 1502 | nmethodBucket* b = _dependencies; |
duke@435 | 1503 | int idx = 0; |
duke@435 | 1504 | while (b != NULL) { |
duke@435 | 1505 | nmethod* nm = b->get_nmethod(); |
duke@435 | 1506 | tty->print("[%d] count=%d { ", idx++, b->count()); |
duke@435 | 1507 | if (!verbose) { |
duke@435 | 1508 | nm->print_on(tty, "nmethod"); |
duke@435 | 1509 | tty->print_cr(" } "); |
duke@435 | 1510 | } else { |
duke@435 | 1511 | nm->print(); |
duke@435 | 1512 | nm->print_dependencies(); |
duke@435 | 1513 | tty->print_cr("--- } "); |
duke@435 | 1514 | } |
duke@435 | 1515 | b = b->next(); |
duke@435 | 1516 | } |
duke@435 | 1517 | } |
duke@435 | 1518 | |
duke@435 | 1519 | |
duke@435 | 1520 | bool instanceKlass::is_dependent_nmethod(nmethod* nm) { |
duke@435 | 1521 | nmethodBucket* b = _dependencies; |
duke@435 | 1522 | while (b != NULL) { |
duke@435 | 1523 | if (nm == b->get_nmethod()) { |
duke@435 | 1524 | return true; |
duke@435 | 1525 | } |
duke@435 | 1526 | b = b->next(); |
duke@435 | 1527 | } |
duke@435 | 1528 | return false; |
duke@435 | 1529 | } |
duke@435 | 1530 | #endif //PRODUCT |
duke@435 | 1531 | |
duke@435 | 1532 | |
coleenp@548 | 1533 | #ifdef ASSERT |
coleenp@548 | 1534 | template <class T> void assert_is_in(T *p) { |
coleenp@548 | 1535 | T heap_oop = oopDesc::load_heap_oop(p); |
coleenp@548 | 1536 | if (!oopDesc::is_null(heap_oop)) { |
coleenp@548 | 1537 | oop o = oopDesc::decode_heap_oop_not_null(heap_oop); |
coleenp@548 | 1538 | assert(Universe::heap()->is_in(o), "should be in heap"); |
coleenp@548 | 1539 | } |
coleenp@548 | 1540 | } |
coleenp@548 | 1541 | template <class T> void assert_is_in_closed_subset(T *p) { |
coleenp@548 | 1542 | T heap_oop = oopDesc::load_heap_oop(p); |
coleenp@548 | 1543 | if (!oopDesc::is_null(heap_oop)) { |
coleenp@548 | 1544 | oop o = oopDesc::decode_heap_oop_not_null(heap_oop); |
coleenp@548 | 1545 | assert(Universe::heap()->is_in_closed_subset(o), "should be in closed"); |
coleenp@548 | 1546 | } |
coleenp@548 | 1547 | } |
coleenp@548 | 1548 | template <class T> void assert_is_in_reserved(T *p) { |
coleenp@548 | 1549 | T heap_oop = oopDesc::load_heap_oop(p); |
coleenp@548 | 1550 | if (!oopDesc::is_null(heap_oop)) { |
coleenp@548 | 1551 | oop o = oopDesc::decode_heap_oop_not_null(heap_oop); |
coleenp@548 | 1552 | assert(Universe::heap()->is_in_reserved(o), "should be in reserved"); |
coleenp@548 | 1553 | } |
coleenp@548 | 1554 | } |
coleenp@548 | 1555 | template <class T> void assert_nothing(T *p) {} |
coleenp@548 | 1556 | |
coleenp@548 | 1557 | #else |
coleenp@548 | 1558 | template <class T> void assert_is_in(T *p) {} |
coleenp@548 | 1559 | template <class T> void assert_is_in_closed_subset(T *p) {} |
coleenp@548 | 1560 | template <class T> void assert_is_in_reserved(T *p) {} |
coleenp@548 | 1561 | template <class T> void assert_nothing(T *p) {} |
coleenp@548 | 1562 | #endif // ASSERT |
coleenp@548 | 1563 | |
coleenp@548 | 1564 | // |
coleenp@548 | 1565 | // Macros that iterate over areas of oops which are specialized on type of |
coleenp@548 | 1566 | // oop pointer either narrow or wide, depending on UseCompressedOops |
coleenp@548 | 1567 | // |
coleenp@548 | 1568 | // Parameters are: |
coleenp@548 | 1569 | // T - type of oop to point to (either oop or narrowOop) |
coleenp@548 | 1570 | // start_p - starting pointer for region to iterate over |
coleenp@548 | 1571 | // count - number of oops or narrowOops to iterate over |
coleenp@548 | 1572 | // do_oop - action to perform on each oop (it's arbitrary C code which |
coleenp@548 | 1573 | // makes it more efficient to put in a macro rather than making |
coleenp@548 | 1574 | // it a template function) |
coleenp@548 | 1575 | // assert_fn - assert function which is template function because performance |
coleenp@548 | 1576 | // doesn't matter when enabled. |
coleenp@548 | 1577 | #define InstanceKlass_SPECIALIZED_OOP_ITERATE( \ |
coleenp@548 | 1578 | T, start_p, count, do_oop, \ |
coleenp@548 | 1579 | assert_fn) \ |
coleenp@548 | 1580 | { \ |
coleenp@548 | 1581 | T* p = (T*)(start_p); \ |
coleenp@548 | 1582 | T* const end = p + (count); \ |
coleenp@548 | 1583 | while (p < end) { \ |
coleenp@548 | 1584 | (assert_fn)(p); \ |
coleenp@548 | 1585 | do_oop; \ |
coleenp@548 | 1586 | ++p; \ |
coleenp@548 | 1587 | } \ |
coleenp@548 | 1588 | } |
coleenp@548 | 1589 | |
coleenp@548 | 1590 | #define InstanceKlass_SPECIALIZED_OOP_REVERSE_ITERATE( \ |
coleenp@548 | 1591 | T, start_p, count, do_oop, \ |
coleenp@548 | 1592 | assert_fn) \ |
coleenp@548 | 1593 | { \ |
coleenp@548 | 1594 | T* const start = (T*)(start_p); \ |
coleenp@548 | 1595 | T* p = start + (count); \ |
coleenp@548 | 1596 | while (start < p) { \ |
coleenp@548 | 1597 | --p; \ |
coleenp@548 | 1598 | (assert_fn)(p); \ |
coleenp@548 | 1599 | do_oop; \ |
coleenp@548 | 1600 | } \ |
coleenp@548 | 1601 | } |
coleenp@548 | 1602 | |
coleenp@548 | 1603 | #define InstanceKlass_SPECIALIZED_BOUNDED_OOP_ITERATE( \ |
coleenp@548 | 1604 | T, start_p, count, low, high, \ |
coleenp@548 | 1605 | do_oop, assert_fn) \ |
coleenp@548 | 1606 | { \ |
coleenp@548 | 1607 | T* const l = (T*)(low); \ |
coleenp@548 | 1608 | T* const h = (T*)(high); \ |
coleenp@548 | 1609 | assert(mask_bits((intptr_t)l, sizeof(T)-1) == 0 && \ |
coleenp@548 | 1610 | mask_bits((intptr_t)h, sizeof(T)-1) == 0, \ |
coleenp@548 | 1611 | "bounded region must be properly aligned"); \ |
coleenp@548 | 1612 | T* p = (T*)(start_p); \ |
coleenp@548 | 1613 | T* end = p + (count); \ |
coleenp@548 | 1614 | if (p < l) p = l; \ |
coleenp@548 | 1615 | if (end > h) end = h; \ |
coleenp@548 | 1616 | while (p < end) { \ |
coleenp@548 | 1617 | (assert_fn)(p); \ |
coleenp@548 | 1618 | do_oop; \ |
coleenp@548 | 1619 | ++p; \ |
coleenp@548 | 1620 | } \ |
coleenp@548 | 1621 | } |
coleenp@548 | 1622 | |
coleenp@548 | 1623 | |
coleenp@548 | 1624 | // The following macros call specialized macros, passing either oop or |
coleenp@548 | 1625 | // narrowOop as the specialization type. These test the UseCompressedOops |
coleenp@548 | 1626 | // flag. |
coleenp@548 | 1627 | #define InstanceKlass_OOP_MAP_ITERATE(obj, do_oop, assert_fn) \ |
coleenp@548 | 1628 | { \ |
coleenp@548 | 1629 | /* Compute oopmap block range. The common case \ |
coleenp@548 | 1630 | is nonstatic_oop_map_size == 1. */ \ |
coleenp@548 | 1631 | OopMapBlock* map = start_of_nonstatic_oop_maps(); \ |
jcoomes@1373 | 1632 | OopMapBlock* const end_map = map + nonstatic_oop_map_count(); \ |
coleenp@548 | 1633 | if (UseCompressedOops) { \ |
coleenp@548 | 1634 | while (map < end_map) { \ |
coleenp@548 | 1635 | InstanceKlass_SPECIALIZED_OOP_ITERATE(narrowOop, \ |
jcoomes@1373 | 1636 | obj->obj_field_addr<narrowOop>(map->offset()), map->count(), \ |
coleenp@548 | 1637 | do_oop, assert_fn) \ |
coleenp@548 | 1638 | ++map; \ |
coleenp@548 | 1639 | } \ |
coleenp@548 | 1640 | } else { \ |
coleenp@548 | 1641 | while (map < end_map) { \ |
coleenp@548 | 1642 | InstanceKlass_SPECIALIZED_OOP_ITERATE(oop, \ |
jcoomes@1373 | 1643 | obj->obj_field_addr<oop>(map->offset()), map->count(), \ |
coleenp@548 | 1644 | do_oop, assert_fn) \ |
coleenp@548 | 1645 | ++map; \ |
coleenp@548 | 1646 | } \ |
coleenp@548 | 1647 | } \ |
coleenp@548 | 1648 | } |
coleenp@548 | 1649 | |
coleenp@548 | 1650 | #define InstanceKlass_OOP_MAP_REVERSE_ITERATE(obj, do_oop, assert_fn) \ |
coleenp@548 | 1651 | { \ |
coleenp@548 | 1652 | OopMapBlock* const start_map = start_of_nonstatic_oop_maps(); \ |
jcoomes@1373 | 1653 | OopMapBlock* map = start_map + nonstatic_oop_map_count(); \ |
coleenp@548 | 1654 | if (UseCompressedOops) { \ |
coleenp@548 | 1655 | while (start_map < map) { \ |
coleenp@548 | 1656 | --map; \ |
coleenp@548 | 1657 | InstanceKlass_SPECIALIZED_OOP_REVERSE_ITERATE(narrowOop, \ |
jcoomes@1373 | 1658 | obj->obj_field_addr<narrowOop>(map->offset()), map->count(), \ |
coleenp@548 | 1659 | do_oop, assert_fn) \ |
coleenp@548 | 1660 | } \ |
coleenp@548 | 1661 | } else { \ |
coleenp@548 | 1662 | while (start_map < map) { \ |
coleenp@548 | 1663 | --map; \ |
coleenp@548 | 1664 | InstanceKlass_SPECIALIZED_OOP_REVERSE_ITERATE(oop, \ |
jcoomes@1373 | 1665 | obj->obj_field_addr<oop>(map->offset()), map->count(), \ |
coleenp@548 | 1666 | do_oop, assert_fn) \ |
coleenp@548 | 1667 | } \ |
coleenp@548 | 1668 | } \ |
coleenp@548 | 1669 | } |
coleenp@548 | 1670 | |
coleenp@548 | 1671 | #define InstanceKlass_BOUNDED_OOP_MAP_ITERATE(obj, low, high, do_oop, \ |
coleenp@548 | 1672 | assert_fn) \ |
coleenp@548 | 1673 | { \ |
coleenp@548 | 1674 | /* Compute oopmap block range. The common case is \ |
coleenp@548 | 1675 | nonstatic_oop_map_size == 1, so we accept the \ |
coleenp@548 | 1676 | usually non-existent extra overhead of examining \ |
coleenp@548 | 1677 | all the maps. */ \ |
coleenp@548 | 1678 | OopMapBlock* map = start_of_nonstatic_oop_maps(); \ |
jcoomes@1373 | 1679 | OopMapBlock* const end_map = map + nonstatic_oop_map_count(); \ |
coleenp@548 | 1680 | if (UseCompressedOops) { \ |
coleenp@548 | 1681 | while (map < end_map) { \ |
coleenp@548 | 1682 | InstanceKlass_SPECIALIZED_BOUNDED_OOP_ITERATE(narrowOop, \ |
jcoomes@1373 | 1683 | obj->obj_field_addr<narrowOop>(map->offset()), map->count(), \ |
coleenp@548 | 1684 | low, high, \ |
coleenp@548 | 1685 | do_oop, assert_fn) \ |
coleenp@548 | 1686 | ++map; \ |
coleenp@548 | 1687 | } \ |
coleenp@548 | 1688 | } else { \ |
coleenp@548 | 1689 | while (map < end_map) { \ |
coleenp@548 | 1690 | InstanceKlass_SPECIALIZED_BOUNDED_OOP_ITERATE(oop, \ |
jcoomes@1373 | 1691 | obj->obj_field_addr<oop>(map->offset()), map->count(), \ |
coleenp@548 | 1692 | low, high, \ |
coleenp@548 | 1693 | do_oop, assert_fn) \ |
coleenp@548 | 1694 | ++map; \ |
coleenp@548 | 1695 | } \ |
coleenp@548 | 1696 | } \ |
coleenp@548 | 1697 | } |
coleenp@548 | 1698 | |
duke@435 | 1699 | void instanceKlass::oop_follow_contents(oop obj) { |
coleenp@548 | 1700 | assert(obj != NULL, "can't follow the content of NULL object"); |
duke@435 | 1701 | obj->follow_header(); |
coleenp@548 | 1702 | InstanceKlass_OOP_MAP_ITERATE( \ |
coleenp@548 | 1703 | obj, \ |
coleenp@548 | 1704 | MarkSweep::mark_and_push(p), \ |
coleenp@548 | 1705 | assert_is_in_closed_subset) |
duke@435 | 1706 | } |
duke@435 | 1707 | |
duke@435 | 1708 | #ifndef SERIALGC |
duke@435 | 1709 | void instanceKlass::oop_follow_contents(ParCompactionManager* cm, |
duke@435 | 1710 | oop obj) { |
coleenp@548 | 1711 | assert(obj != NULL, "can't follow the content of NULL object"); |
duke@435 | 1712 | obj->follow_header(cm); |
coleenp@548 | 1713 | InstanceKlass_OOP_MAP_ITERATE( \ |
coleenp@548 | 1714 | obj, \ |
coleenp@548 | 1715 | PSParallelCompact::mark_and_push(cm, p), \ |
coleenp@548 | 1716 | assert_is_in) |
duke@435 | 1717 | } |
duke@435 | 1718 | #endif // SERIALGC |
duke@435 | 1719 | |
duke@435 | 1720 | // closure's do_header() method dicates whether the given closure should be |
duke@435 | 1721 | // applied to the klass ptr in the object header. |
duke@435 | 1722 | |
ysr@777 | 1723 | #define InstanceKlass_OOP_OOP_ITERATE_DEFN(OopClosureType, nv_suffix) \ |
ysr@777 | 1724 | \ |
ysr@777 | 1725 | int instanceKlass::oop_oop_iterate##nv_suffix(oop obj, OopClosureType* closure) { \ |
coleenp@548 | 1726 | SpecializationStats::record_iterate_call##nv_suffix(SpecializationStats::ik);\ |
coleenp@548 | 1727 | /* header */ \ |
coleenp@548 | 1728 | if (closure->do_header()) { \ |
coleenp@548 | 1729 | obj->oop_iterate_header(closure); \ |
coleenp@548 | 1730 | } \ |
coleenp@548 | 1731 | InstanceKlass_OOP_MAP_ITERATE( \ |
coleenp@548 | 1732 | obj, \ |
coleenp@548 | 1733 | SpecializationStats:: \ |
coleenp@548 | 1734 | record_do_oop_call##nv_suffix(SpecializationStats::ik); \ |
coleenp@548 | 1735 | (closure)->do_oop##nv_suffix(p), \ |
coleenp@548 | 1736 | assert_is_in_closed_subset) \ |
coleenp@548 | 1737 | return size_helper(); \ |
duke@435 | 1738 | } |
duke@435 | 1739 | |
ysr@777 | 1740 | #ifndef SERIALGC |
ysr@777 | 1741 | #define InstanceKlass_OOP_OOP_ITERATE_BACKWARDS_DEFN(OopClosureType, nv_suffix) \ |
ysr@777 | 1742 | \ |
ysr@777 | 1743 | int instanceKlass::oop_oop_iterate_backwards##nv_suffix(oop obj, \ |
ysr@777 | 1744 | OopClosureType* closure) { \ |
ysr@777 | 1745 | SpecializationStats::record_iterate_call##nv_suffix(SpecializationStats::ik); \ |
ysr@777 | 1746 | /* header */ \ |
ysr@777 | 1747 | if (closure->do_header()) { \ |
ysr@777 | 1748 | obj->oop_iterate_header(closure); \ |
ysr@777 | 1749 | } \ |
ysr@777 | 1750 | /* instance variables */ \ |
ysr@777 | 1751 | InstanceKlass_OOP_MAP_REVERSE_ITERATE( \ |
ysr@777 | 1752 | obj, \ |
ysr@777 | 1753 | SpecializationStats::record_do_oop_call##nv_suffix(SpecializationStats::ik);\ |
ysr@777 | 1754 | (closure)->do_oop##nv_suffix(p), \ |
ysr@777 | 1755 | assert_is_in_closed_subset) \ |
ysr@777 | 1756 | return size_helper(); \ |
ysr@777 | 1757 | } |
ysr@777 | 1758 | #endif // !SERIALGC |
ysr@777 | 1759 | |
coleenp@548 | 1760 | #define InstanceKlass_OOP_OOP_ITERATE_DEFN_m(OopClosureType, nv_suffix) \ |
coleenp@548 | 1761 | \ |
coleenp@548 | 1762 | int instanceKlass::oop_oop_iterate##nv_suffix##_m(oop obj, \ |
coleenp@548 | 1763 | OopClosureType* closure, \ |
coleenp@548 | 1764 | MemRegion mr) { \ |
coleenp@548 | 1765 | SpecializationStats::record_iterate_call##nv_suffix(SpecializationStats::ik);\ |
coleenp@548 | 1766 | if (closure->do_header()) { \ |
coleenp@548 | 1767 | obj->oop_iterate_header(closure, mr); \ |
coleenp@548 | 1768 | } \ |
coleenp@548 | 1769 | InstanceKlass_BOUNDED_OOP_MAP_ITERATE( \ |
coleenp@548 | 1770 | obj, mr.start(), mr.end(), \ |
coleenp@548 | 1771 | (closure)->do_oop##nv_suffix(p), \ |
coleenp@548 | 1772 | assert_is_in_closed_subset) \ |
coleenp@548 | 1773 | return size_helper(); \ |
duke@435 | 1774 | } |
duke@435 | 1775 | |
duke@435 | 1776 | ALL_OOP_OOP_ITERATE_CLOSURES_1(InstanceKlass_OOP_OOP_ITERATE_DEFN) |
ysr@777 | 1777 | ALL_OOP_OOP_ITERATE_CLOSURES_2(InstanceKlass_OOP_OOP_ITERATE_DEFN) |
duke@435 | 1778 | ALL_OOP_OOP_ITERATE_CLOSURES_1(InstanceKlass_OOP_OOP_ITERATE_DEFN_m) |
ysr@777 | 1779 | ALL_OOP_OOP_ITERATE_CLOSURES_2(InstanceKlass_OOP_OOP_ITERATE_DEFN_m) |
ysr@777 | 1780 | #ifndef SERIALGC |
ysr@777 | 1781 | ALL_OOP_OOP_ITERATE_CLOSURES_1(InstanceKlass_OOP_OOP_ITERATE_BACKWARDS_DEFN) |
ysr@777 | 1782 | ALL_OOP_OOP_ITERATE_CLOSURES_2(InstanceKlass_OOP_OOP_ITERATE_BACKWARDS_DEFN) |
ysr@777 | 1783 | #endif // !SERIALGC |
duke@435 | 1784 | |
duke@435 | 1785 | int instanceKlass::oop_adjust_pointers(oop obj) { |
duke@435 | 1786 | int size = size_helper(); |
coleenp@548 | 1787 | InstanceKlass_OOP_MAP_ITERATE( \ |
coleenp@548 | 1788 | obj, \ |
coleenp@548 | 1789 | MarkSweep::adjust_pointer(p), \ |
coleenp@548 | 1790 | assert_is_in) |
duke@435 | 1791 | obj->adjust_header(); |
duke@435 | 1792 | return size; |
duke@435 | 1793 | } |
duke@435 | 1794 | |
duke@435 | 1795 | #ifndef SERIALGC |
duke@435 | 1796 | void instanceKlass::oop_push_contents(PSPromotionManager* pm, oop obj) { |
coleenp@548 | 1797 | InstanceKlass_OOP_MAP_REVERSE_ITERATE( \ |
coleenp@548 | 1798 | obj, \ |
coleenp@548 | 1799 | if (PSScavenge::should_scavenge(p)) { \ |
coleenp@548 | 1800 | pm->claim_or_forward_depth(p); \ |
coleenp@548 | 1801 | }, \ |
coleenp@548 | 1802 | assert_nothing ) |
duke@435 | 1803 | } |
duke@435 | 1804 | |
duke@435 | 1805 | int instanceKlass::oop_update_pointers(ParCompactionManager* cm, oop obj) { |
coleenp@548 | 1806 | InstanceKlass_OOP_MAP_ITERATE( \ |
coleenp@548 | 1807 | obj, \ |
coleenp@548 | 1808 | PSParallelCompact::adjust_pointer(p), \ |
coleenp@548 | 1809 | assert_nothing) |
duke@435 | 1810 | return size_helper(); |
duke@435 | 1811 | } |
duke@435 | 1812 | |
duke@435 | 1813 | #endif // SERIALGC |
duke@435 | 1814 | |
duke@435 | 1815 | // This klass is alive but the implementor link is not followed/updated. |
duke@435 | 1816 | // Subklass and sibling links are handled by Klass::follow_weak_klass_links |
duke@435 | 1817 | |
duke@435 | 1818 | void instanceKlass::follow_weak_klass_links( |
duke@435 | 1819 | BoolObjectClosure* is_alive, OopClosure* keep_alive) { |
duke@435 | 1820 | assert(is_alive->do_object_b(as_klassOop()), "this oop should be live"); |
duke@435 | 1821 | if (ClassUnloading) { |
duke@435 | 1822 | for (int i = 0; i < implementors_limit; i++) { |
duke@435 | 1823 | klassOop impl = _implementors[i]; |
duke@435 | 1824 | if (impl == NULL) break; // no more in the list |
duke@435 | 1825 | if (!is_alive->do_object_b(impl)) { |
duke@435 | 1826 | // remove this guy from the list by overwriting him with the tail |
duke@435 | 1827 | int lasti = --_nof_implementors; |
duke@435 | 1828 | assert(lasti >= i && lasti < implementors_limit, "just checking"); |
duke@435 | 1829 | _implementors[i] = _implementors[lasti]; |
duke@435 | 1830 | _implementors[lasti] = NULL; |
duke@435 | 1831 | --i; // rerun the loop at this index |
duke@435 | 1832 | } |
duke@435 | 1833 | } |
duke@435 | 1834 | } else { |
duke@435 | 1835 | for (int i = 0; i < implementors_limit; i++) { |
duke@435 | 1836 | keep_alive->do_oop(&adr_implementors()[i]); |
duke@435 | 1837 | } |
duke@435 | 1838 | } |
duke@435 | 1839 | Klass::follow_weak_klass_links(is_alive, keep_alive); |
duke@435 | 1840 | } |
duke@435 | 1841 | |
duke@435 | 1842 | void instanceKlass::remove_unshareable_info() { |
duke@435 | 1843 | Klass::remove_unshareable_info(); |
duke@435 | 1844 | init_implementor(); |
duke@435 | 1845 | } |
duke@435 | 1846 | |
duke@435 | 1847 | static void clear_all_breakpoints(methodOop m) { |
duke@435 | 1848 | m->clear_all_breakpoints(); |
duke@435 | 1849 | } |
duke@435 | 1850 | |
duke@435 | 1851 | void instanceKlass::release_C_heap_structures() { |
duke@435 | 1852 | // Deallocate oop map cache |
duke@435 | 1853 | if (_oop_map_cache != NULL) { |
duke@435 | 1854 | delete _oop_map_cache; |
duke@435 | 1855 | _oop_map_cache = NULL; |
duke@435 | 1856 | } |
duke@435 | 1857 | |
duke@435 | 1858 | // Deallocate JNI identifiers for jfieldIDs |
duke@435 | 1859 | JNIid::deallocate(jni_ids()); |
duke@435 | 1860 | set_jni_ids(NULL); |
duke@435 | 1861 | |
duke@435 | 1862 | jmethodID* jmeths = methods_jmethod_ids_acquire(); |
duke@435 | 1863 | if (jmeths != (jmethodID*)NULL) { |
duke@435 | 1864 | release_set_methods_jmethod_ids(NULL); |
duke@435 | 1865 | FreeHeap(jmeths); |
duke@435 | 1866 | } |
duke@435 | 1867 | |
duke@435 | 1868 | int* indices = methods_cached_itable_indices_acquire(); |
duke@435 | 1869 | if (indices != (int*)NULL) { |
duke@435 | 1870 | release_set_methods_cached_itable_indices(NULL); |
duke@435 | 1871 | FreeHeap(indices); |
duke@435 | 1872 | } |
duke@435 | 1873 | |
duke@435 | 1874 | // release dependencies |
duke@435 | 1875 | nmethodBucket* b = _dependencies; |
duke@435 | 1876 | _dependencies = NULL; |
duke@435 | 1877 | while (b != NULL) { |
duke@435 | 1878 | nmethodBucket* next = b->next(); |
duke@435 | 1879 | delete b; |
duke@435 | 1880 | b = next; |
duke@435 | 1881 | } |
duke@435 | 1882 | |
duke@435 | 1883 | // Deallocate breakpoint records |
duke@435 | 1884 | if (breakpoints() != 0x0) { |
duke@435 | 1885 | methods_do(clear_all_breakpoints); |
duke@435 | 1886 | assert(breakpoints() == 0x0, "should have cleared breakpoints"); |
duke@435 | 1887 | } |
duke@435 | 1888 | |
duke@435 | 1889 | // deallocate information about previous versions |
duke@435 | 1890 | if (_previous_versions != NULL) { |
duke@435 | 1891 | for (int i = _previous_versions->length() - 1; i >= 0; i--) { |
duke@435 | 1892 | PreviousVersionNode * pv_node = _previous_versions->at(i); |
duke@435 | 1893 | delete pv_node; |
duke@435 | 1894 | } |
duke@435 | 1895 | delete _previous_versions; |
duke@435 | 1896 | _previous_versions = NULL; |
duke@435 | 1897 | } |
duke@435 | 1898 | |
duke@435 | 1899 | // deallocate the cached class file |
duke@435 | 1900 | if (_cached_class_file_bytes != NULL) { |
duke@435 | 1901 | os::free(_cached_class_file_bytes); |
duke@435 | 1902 | _cached_class_file_bytes = NULL; |
duke@435 | 1903 | _cached_class_file_len = 0; |
duke@435 | 1904 | } |
coleenp@2497 | 1905 | |
coleenp@2497 | 1906 | // Decrement symbol reference counts associated with the unloaded class. |
coleenp@2497 | 1907 | if (_name != NULL) _name->decrement_refcount(); |
coleenp@2497 | 1908 | // unreference array name derived from this class name (arrays of an unloaded |
coleenp@2497 | 1909 | // class can't be referenced anymore). |
coleenp@2497 | 1910 | if (_array_name != NULL) _array_name->decrement_refcount(); |
coleenp@2497 | 1911 | if (_source_file_name != NULL) _source_file_name->decrement_refcount(); |
coleenp@2497 | 1912 | if (_source_debug_extension != NULL) _source_debug_extension->decrement_refcount(); |
coleenp@2497 | 1913 | // walk constant pool and decrement symbol reference counts |
coleenp@2497 | 1914 | _constants->unreference_symbols(); |
coleenp@2497 | 1915 | } |
coleenp@2497 | 1916 | |
coleenp@2497 | 1917 | void instanceKlass::set_source_file_name(Symbol* n) { |
coleenp@2497 | 1918 | _source_file_name = n; |
coleenp@2497 | 1919 | if (_source_file_name != NULL) _source_file_name->increment_refcount(); |
coleenp@2497 | 1920 | } |
coleenp@2497 | 1921 | |
coleenp@2497 | 1922 | void instanceKlass::set_source_debug_extension(Symbol* n) { |
coleenp@2497 | 1923 | _source_debug_extension = n; |
coleenp@2497 | 1924 | if (_source_debug_extension != NULL) _source_debug_extension->increment_refcount(); |
duke@435 | 1925 | } |
duke@435 | 1926 | |
never@2658 | 1927 | address instanceKlass::static_field_addr(int offset) { |
never@2658 | 1928 | return (address)(offset + instanceMirrorKlass::offset_of_static_fields() + (intptr_t)java_mirror()); |
never@2658 | 1929 | } |
never@2658 | 1930 | |
never@2658 | 1931 | |
jrose@1474 | 1932 | const char* instanceKlass::signature_name() const { |
duke@435 | 1933 | const char* src = (const char*) (name()->as_C_string()); |
duke@435 | 1934 | const int src_length = (int)strlen(src); |
duke@435 | 1935 | char* dest = NEW_RESOURCE_ARRAY(char, src_length + 3); |
duke@435 | 1936 | int src_index = 0; |
duke@435 | 1937 | int dest_index = 0; |
duke@435 | 1938 | dest[dest_index++] = 'L'; |
duke@435 | 1939 | while (src_index < src_length) { |
duke@435 | 1940 | dest[dest_index++] = src[src_index++]; |
duke@435 | 1941 | } |
duke@435 | 1942 | dest[dest_index++] = ';'; |
duke@435 | 1943 | dest[dest_index] = '\0'; |
duke@435 | 1944 | return dest; |
duke@435 | 1945 | } |
duke@435 | 1946 | |
duke@435 | 1947 | // different verisons of is_same_class_package |
duke@435 | 1948 | bool instanceKlass::is_same_class_package(klassOop class2) { |
duke@435 | 1949 | klassOop class1 = as_klassOop(); |
duke@435 | 1950 | oop classloader1 = instanceKlass::cast(class1)->class_loader(); |
coleenp@2497 | 1951 | Symbol* classname1 = Klass::cast(class1)->name(); |
duke@435 | 1952 | |
duke@435 | 1953 | if (Klass::cast(class2)->oop_is_objArray()) { |
duke@435 | 1954 | class2 = objArrayKlass::cast(class2)->bottom_klass(); |
duke@435 | 1955 | } |
duke@435 | 1956 | oop classloader2; |
duke@435 | 1957 | if (Klass::cast(class2)->oop_is_instance()) { |
duke@435 | 1958 | classloader2 = instanceKlass::cast(class2)->class_loader(); |
duke@435 | 1959 | } else { |
duke@435 | 1960 | assert(Klass::cast(class2)->oop_is_typeArray(), "should be type array"); |
duke@435 | 1961 | classloader2 = NULL; |
duke@435 | 1962 | } |
coleenp@2497 | 1963 | Symbol* classname2 = Klass::cast(class2)->name(); |
duke@435 | 1964 | |
duke@435 | 1965 | return instanceKlass::is_same_class_package(classloader1, classname1, |
duke@435 | 1966 | classloader2, classname2); |
duke@435 | 1967 | } |
duke@435 | 1968 | |
coleenp@2497 | 1969 | bool instanceKlass::is_same_class_package(oop classloader2, Symbol* classname2) { |
duke@435 | 1970 | klassOop class1 = as_klassOop(); |
duke@435 | 1971 | oop classloader1 = instanceKlass::cast(class1)->class_loader(); |
coleenp@2497 | 1972 | Symbol* classname1 = Klass::cast(class1)->name(); |
duke@435 | 1973 | |
duke@435 | 1974 | return instanceKlass::is_same_class_package(classloader1, classname1, |
duke@435 | 1975 | classloader2, classname2); |
duke@435 | 1976 | } |
duke@435 | 1977 | |
duke@435 | 1978 | // return true if two classes are in the same package, classloader |
duke@435 | 1979 | // and classname information is enough to determine a class's package |
coleenp@2497 | 1980 | bool instanceKlass::is_same_class_package(oop class_loader1, Symbol* class_name1, |
coleenp@2497 | 1981 | oop class_loader2, Symbol* class_name2) { |
duke@435 | 1982 | if (class_loader1 != class_loader2) { |
duke@435 | 1983 | return false; |
jrose@1100 | 1984 | } else if (class_name1 == class_name2) { |
jrose@1100 | 1985 | return true; // skip painful bytewise comparison |
duke@435 | 1986 | } else { |
duke@435 | 1987 | ResourceMark rm; |
duke@435 | 1988 | |
coleenp@2497 | 1989 | // The Symbol*'s are in UTF8 encoding. Since we only need to check explicitly |
duke@435 | 1990 | // for ASCII characters ('/', 'L', '['), we can keep them in UTF8 encoding. |
duke@435 | 1991 | // Otherwise, we just compare jbyte values between the strings. |
coleenp@2497 | 1992 | const jbyte *name1 = class_name1->base(); |
coleenp@2497 | 1993 | const jbyte *name2 = class_name2->base(); |
coleenp@2497 | 1994 | |
coleenp@2497 | 1995 | const jbyte *last_slash1 = UTF8::strrchr(name1, class_name1->utf8_length(), '/'); |
coleenp@2497 | 1996 | const jbyte *last_slash2 = UTF8::strrchr(name2, class_name2->utf8_length(), '/'); |
duke@435 | 1997 | |
duke@435 | 1998 | if ((last_slash1 == NULL) || (last_slash2 == NULL)) { |
duke@435 | 1999 | // One of the two doesn't have a package. Only return true |
duke@435 | 2000 | // if the other one also doesn't have a package. |
duke@435 | 2001 | return last_slash1 == last_slash2; |
duke@435 | 2002 | } else { |
duke@435 | 2003 | // Skip over '['s |
duke@435 | 2004 | if (*name1 == '[') { |
duke@435 | 2005 | do { |
duke@435 | 2006 | name1++; |
duke@435 | 2007 | } while (*name1 == '['); |
duke@435 | 2008 | if (*name1 != 'L') { |
duke@435 | 2009 | // Something is terribly wrong. Shouldn't be here. |
duke@435 | 2010 | return false; |
duke@435 | 2011 | } |
duke@435 | 2012 | } |
duke@435 | 2013 | if (*name2 == '[') { |
duke@435 | 2014 | do { |
duke@435 | 2015 | name2++; |
duke@435 | 2016 | } while (*name2 == '['); |
duke@435 | 2017 | if (*name2 != 'L') { |
duke@435 | 2018 | // Something is terribly wrong. Shouldn't be here. |
duke@435 | 2019 | return false; |
duke@435 | 2020 | } |
duke@435 | 2021 | } |
duke@435 | 2022 | |
duke@435 | 2023 | // Check that package part is identical |
duke@435 | 2024 | int length1 = last_slash1 - name1; |
duke@435 | 2025 | int length2 = last_slash2 - name2; |
duke@435 | 2026 | |
duke@435 | 2027 | return UTF8::equal(name1, length1, name2, length2); |
duke@435 | 2028 | } |
duke@435 | 2029 | } |
duke@435 | 2030 | } |
duke@435 | 2031 | |
acorn@1087 | 2032 | // Returns true iff super_method can be overridden by a method in targetclassname |
acorn@1087 | 2033 | // See JSL 3rd edition 8.4.6.1 |
acorn@1087 | 2034 | // Assumes name-signature match |
acorn@1087 | 2035 | // "this" is instanceKlass of super_method which must exist |
acorn@1087 | 2036 | // note that the instanceKlass of the method in the targetclassname has not always been created yet |
coleenp@2497 | 2037 | bool instanceKlass::is_override(methodHandle super_method, Handle targetclassloader, Symbol* targetclassname, TRAPS) { |
acorn@1087 | 2038 | // Private methods can not be overridden |
acorn@1087 | 2039 | if (super_method->is_private()) { |
acorn@1087 | 2040 | return false; |
acorn@1087 | 2041 | } |
acorn@1087 | 2042 | // If super method is accessible, then override |
acorn@1087 | 2043 | if ((super_method->is_protected()) || |
acorn@1087 | 2044 | (super_method->is_public())) { |
acorn@1087 | 2045 | return true; |
acorn@1087 | 2046 | } |
acorn@1087 | 2047 | // Package-private methods are not inherited outside of package |
acorn@1087 | 2048 | assert(super_method->is_package_private(), "must be package private"); |
coleenp@2497 | 2049 | return(is_same_class_package(targetclassloader(), targetclassname)); |
acorn@1087 | 2050 | } |
twisti@1040 | 2051 | |
jrose@1100 | 2052 | /* defined for now in jvm.cpp, for historical reasons *-- |
jrose@1100 | 2053 | klassOop instanceKlass::compute_enclosing_class_impl(instanceKlassHandle self, |
coleenp@2497 | 2054 | Symbol*& simple_name_result, TRAPS) { |
jrose@1100 | 2055 | ... |
jrose@1100 | 2056 | } |
jrose@1100 | 2057 | */ |
jrose@1100 | 2058 | |
jrose@1100 | 2059 | // tell if two classes have the same enclosing class (at package level) |
jrose@1100 | 2060 | bool instanceKlass::is_same_package_member_impl(instanceKlassHandle class1, |
jrose@1100 | 2061 | klassOop class2_oop, TRAPS) { |
jrose@1100 | 2062 | if (class2_oop == class1->as_klassOop()) return true; |
jrose@1100 | 2063 | if (!Klass::cast(class2_oop)->oop_is_instance()) return false; |
jrose@1100 | 2064 | instanceKlassHandle class2(THREAD, class2_oop); |
jrose@1100 | 2065 | |
jrose@1100 | 2066 | // must be in same package before we try anything else |
jrose@1100 | 2067 | if (!class1->is_same_class_package(class2->class_loader(), class2->name())) |
jrose@1100 | 2068 | return false; |
jrose@1100 | 2069 | |
jrose@1100 | 2070 | // As long as there is an outer1.getEnclosingClass, |
jrose@1100 | 2071 | // shift the search outward. |
jrose@1100 | 2072 | instanceKlassHandle outer1 = class1; |
jrose@1100 | 2073 | for (;;) { |
jrose@1100 | 2074 | // As we walk along, look for equalities between outer1 and class2. |
jrose@1100 | 2075 | // Eventually, the walks will terminate as outer1 stops |
jrose@1100 | 2076 | // at the top-level class around the original class. |
xlu@1561 | 2077 | bool ignore_inner_is_member; |
xlu@1561 | 2078 | klassOop next = outer1->compute_enclosing_class(&ignore_inner_is_member, |
xlu@1561 | 2079 | CHECK_false); |
jrose@1100 | 2080 | if (next == NULL) break; |
jrose@1100 | 2081 | if (next == class2()) return true; |
jrose@1100 | 2082 | outer1 = instanceKlassHandle(THREAD, next); |
jrose@1100 | 2083 | } |
jrose@1100 | 2084 | |
jrose@1100 | 2085 | // Now do the same for class2. |
jrose@1100 | 2086 | instanceKlassHandle outer2 = class2; |
jrose@1100 | 2087 | for (;;) { |
xlu@1561 | 2088 | bool ignore_inner_is_member; |
xlu@1561 | 2089 | klassOop next = outer2->compute_enclosing_class(&ignore_inner_is_member, |
xlu@1561 | 2090 | CHECK_false); |
jrose@1100 | 2091 | if (next == NULL) break; |
jrose@1100 | 2092 | // Might as well check the new outer against all available values. |
jrose@1100 | 2093 | if (next == class1()) return true; |
jrose@1100 | 2094 | if (next == outer1()) return true; |
jrose@1100 | 2095 | outer2 = instanceKlassHandle(THREAD, next); |
jrose@1100 | 2096 | } |
jrose@1100 | 2097 | |
jrose@1100 | 2098 | // If by this point we have not found an equality between the |
jrose@1100 | 2099 | // two classes, we know they are in separate package members. |
jrose@1100 | 2100 | return false; |
jrose@1100 | 2101 | } |
jrose@1100 | 2102 | |
duke@435 | 2103 | |
duke@435 | 2104 | jint instanceKlass::compute_modifier_flags(TRAPS) const { |
duke@435 | 2105 | klassOop k = as_klassOop(); |
duke@435 | 2106 | jint access = access_flags().as_int(); |
duke@435 | 2107 | |
duke@435 | 2108 | // But check if it happens to be member class. |
duke@435 | 2109 | typeArrayOop inner_class_list = inner_classes(); |
duke@435 | 2110 | int length = (inner_class_list == NULL) ? 0 : inner_class_list->length(); |
duke@435 | 2111 | assert (length % instanceKlass::inner_class_next_offset == 0, "just checking"); |
duke@435 | 2112 | if (length > 0) { |
duke@435 | 2113 | typeArrayHandle inner_class_list_h(THREAD, inner_class_list); |
duke@435 | 2114 | instanceKlassHandle ik(THREAD, k); |
duke@435 | 2115 | for (int i = 0; i < length; i += instanceKlass::inner_class_next_offset) { |
duke@435 | 2116 | int ioff = inner_class_list_h->ushort_at( |
duke@435 | 2117 | i + instanceKlass::inner_class_inner_class_info_offset); |
duke@435 | 2118 | |
duke@435 | 2119 | // Inner class attribute can be zero, skip it. |
duke@435 | 2120 | // Strange but true: JVM spec. allows null inner class refs. |
duke@435 | 2121 | if (ioff == 0) continue; |
duke@435 | 2122 | |
duke@435 | 2123 | // only look at classes that are already loaded |
duke@435 | 2124 | // since we are looking for the flags for our self. |
coleenp@2497 | 2125 | Symbol* inner_name = ik->constants()->klass_name_at(ioff); |
duke@435 | 2126 | if ((ik->name() == inner_name)) { |
duke@435 | 2127 | // This is really a member class. |
duke@435 | 2128 | access = inner_class_list_h->ushort_at(i + instanceKlass::inner_class_access_flags_offset); |
duke@435 | 2129 | break; |
duke@435 | 2130 | } |
duke@435 | 2131 | } |
duke@435 | 2132 | } |
duke@435 | 2133 | // Remember to strip ACC_SUPER bit |
duke@435 | 2134 | return (access & (~JVM_ACC_SUPER)) & JVM_ACC_WRITTEN_FLAGS; |
duke@435 | 2135 | } |
duke@435 | 2136 | |
duke@435 | 2137 | jint instanceKlass::jvmti_class_status() const { |
duke@435 | 2138 | jint result = 0; |
duke@435 | 2139 | |
duke@435 | 2140 | if (is_linked()) { |
duke@435 | 2141 | result |= JVMTI_CLASS_STATUS_VERIFIED | JVMTI_CLASS_STATUS_PREPARED; |
duke@435 | 2142 | } |
duke@435 | 2143 | |
duke@435 | 2144 | if (is_initialized()) { |
duke@435 | 2145 | assert(is_linked(), "Class status is not consistent"); |
duke@435 | 2146 | result |= JVMTI_CLASS_STATUS_INITIALIZED; |
duke@435 | 2147 | } |
duke@435 | 2148 | if (is_in_error_state()) { |
duke@435 | 2149 | result |= JVMTI_CLASS_STATUS_ERROR; |
duke@435 | 2150 | } |
duke@435 | 2151 | return result; |
duke@435 | 2152 | } |
duke@435 | 2153 | |
duke@435 | 2154 | methodOop instanceKlass::method_at_itable(klassOop holder, int index, TRAPS) { |
duke@435 | 2155 | itableOffsetEntry* ioe = (itableOffsetEntry*)start_of_itable(); |
duke@435 | 2156 | int method_table_offset_in_words = ioe->offset()/wordSize; |
duke@435 | 2157 | int nof_interfaces = (method_table_offset_in_words - itable_offset_in_words()) |
duke@435 | 2158 | / itableOffsetEntry::size(); |
duke@435 | 2159 | |
duke@435 | 2160 | for (int cnt = 0 ; ; cnt ++, ioe ++) { |
twisti@1040 | 2161 | // If the interface isn't implemented by the receiver class, |
duke@435 | 2162 | // the VM should throw IncompatibleClassChangeError. |
duke@435 | 2163 | if (cnt >= nof_interfaces) { |
coleenp@2497 | 2164 | THROW_0(vmSymbols::java_lang_IncompatibleClassChangeError()); |
duke@435 | 2165 | } |
duke@435 | 2166 | |
duke@435 | 2167 | klassOop ik = ioe->interface_klass(); |
duke@435 | 2168 | if (ik == holder) break; |
duke@435 | 2169 | } |
duke@435 | 2170 | |
duke@435 | 2171 | itableMethodEntry* ime = ioe->first_method_entry(as_klassOop()); |
duke@435 | 2172 | methodOop m = ime[index].method(); |
duke@435 | 2173 | if (m == NULL) { |
coleenp@2497 | 2174 | THROW_0(vmSymbols::java_lang_AbstractMethodError()); |
duke@435 | 2175 | } |
duke@435 | 2176 | return m; |
duke@435 | 2177 | } |
duke@435 | 2178 | |
duke@435 | 2179 | // On-stack replacement stuff |
duke@435 | 2180 | void instanceKlass::add_osr_nmethod(nmethod* n) { |
duke@435 | 2181 | // only one compilation can be active |
duke@435 | 2182 | NEEDS_CLEANUP |
duke@435 | 2183 | // This is a short non-blocking critical region, so the no safepoint check is ok. |
duke@435 | 2184 | OsrList_lock->lock_without_safepoint_check(); |
duke@435 | 2185 | assert(n->is_osr_method(), "wrong kind of nmethod"); |
jrose@1424 | 2186 | n->set_osr_link(osr_nmethods_head()); |
duke@435 | 2187 | set_osr_nmethods_head(n); |
iveresov@2138 | 2188 | // Raise the highest osr level if necessary |
iveresov@2138 | 2189 | if (TieredCompilation) { |
iveresov@2138 | 2190 | methodOop m = n->method(); |
iveresov@2138 | 2191 | m->set_highest_osr_comp_level(MAX2(m->highest_osr_comp_level(), n->comp_level())); |
iveresov@2138 | 2192 | } |
duke@435 | 2193 | // Remember to unlock again |
duke@435 | 2194 | OsrList_lock->unlock(); |
iveresov@2138 | 2195 | |
iveresov@2138 | 2196 | // Get rid of the osr methods for the same bci that have lower levels. |
iveresov@2138 | 2197 | if (TieredCompilation) { |
iveresov@2138 | 2198 | for (int l = CompLevel_limited_profile; l < n->comp_level(); l++) { |
iveresov@2138 | 2199 | nmethod *inv = lookup_osr_nmethod(n->method(), n->osr_entry_bci(), l, true); |
iveresov@2138 | 2200 | if (inv != NULL && inv->is_in_use()) { |
iveresov@2138 | 2201 | inv->make_not_entrant(); |
iveresov@2138 | 2202 | } |
iveresov@2138 | 2203 | } |
iveresov@2138 | 2204 | } |
duke@435 | 2205 | } |
duke@435 | 2206 | |
duke@435 | 2207 | |
duke@435 | 2208 | void instanceKlass::remove_osr_nmethod(nmethod* n) { |
duke@435 | 2209 | // This is a short non-blocking critical region, so the no safepoint check is ok. |
duke@435 | 2210 | OsrList_lock->lock_without_safepoint_check(); |
duke@435 | 2211 | assert(n->is_osr_method(), "wrong kind of nmethod"); |
duke@435 | 2212 | nmethod* last = NULL; |
duke@435 | 2213 | nmethod* cur = osr_nmethods_head(); |
iveresov@2138 | 2214 | int max_level = CompLevel_none; // Find the max comp level excluding n |
iveresov@2138 | 2215 | methodOop m = n->method(); |
duke@435 | 2216 | // Search for match |
duke@435 | 2217 | while(cur != NULL && cur != n) { |
iveresov@2138 | 2218 | if (TieredCompilation) { |
iveresov@2138 | 2219 | // Find max level before n |
iveresov@2138 | 2220 | max_level = MAX2(max_level, cur->comp_level()); |
iveresov@2138 | 2221 | } |
duke@435 | 2222 | last = cur; |
jrose@1424 | 2223 | cur = cur->osr_link(); |
duke@435 | 2224 | } |
iveresov@2138 | 2225 | nmethod* next = NULL; |
duke@435 | 2226 | if (cur == n) { |
iveresov@2138 | 2227 | next = cur->osr_link(); |
duke@435 | 2228 | if (last == NULL) { |
duke@435 | 2229 | // Remove first element |
iveresov@2138 | 2230 | set_osr_nmethods_head(next); |
duke@435 | 2231 | } else { |
iveresov@2138 | 2232 | last->set_osr_link(next); |
duke@435 | 2233 | } |
duke@435 | 2234 | } |
jrose@1424 | 2235 | n->set_osr_link(NULL); |
iveresov@2138 | 2236 | if (TieredCompilation) { |
iveresov@2138 | 2237 | cur = next; |
iveresov@2138 | 2238 | while (cur != NULL) { |
iveresov@2138 | 2239 | // Find max level after n |
iveresov@2138 | 2240 | max_level = MAX2(max_level, cur->comp_level()); |
iveresov@2138 | 2241 | cur = cur->osr_link(); |
iveresov@2138 | 2242 | } |
iveresov@2138 | 2243 | m->set_highest_osr_comp_level(max_level); |
iveresov@2138 | 2244 | } |
duke@435 | 2245 | // Remember to unlock again |
duke@435 | 2246 | OsrList_lock->unlock(); |
duke@435 | 2247 | } |
duke@435 | 2248 | |
iveresov@2138 | 2249 | nmethod* instanceKlass::lookup_osr_nmethod(const methodOop m, int bci, int comp_level, bool match_level) const { |
duke@435 | 2250 | // This is a short non-blocking critical region, so the no safepoint check is ok. |
duke@435 | 2251 | OsrList_lock->lock_without_safepoint_check(); |
duke@435 | 2252 | nmethod* osr = osr_nmethods_head(); |
iveresov@2138 | 2253 | nmethod* best = NULL; |
duke@435 | 2254 | while (osr != NULL) { |
duke@435 | 2255 | assert(osr->is_osr_method(), "wrong kind of nmethod found in chain"); |
iveresov@2138 | 2256 | // There can be a time when a c1 osr method exists but we are waiting |
iveresov@2138 | 2257 | // for a c2 version. When c2 completes its osr nmethod we will trash |
iveresov@2138 | 2258 | // the c1 version and only be able to find the c2 version. However |
iveresov@2138 | 2259 | // while we overflow in the c1 code at back branches we don't want to |
iveresov@2138 | 2260 | // try and switch to the same code as we are already running |
iveresov@2138 | 2261 | |
duke@435 | 2262 | if (osr->method() == m && |
duke@435 | 2263 | (bci == InvocationEntryBci || osr->osr_entry_bci() == bci)) { |
iveresov@2138 | 2264 | if (match_level) { |
iveresov@2138 | 2265 | if (osr->comp_level() == comp_level) { |
iveresov@2138 | 2266 | // Found a match - return it. |
iveresov@2138 | 2267 | OsrList_lock->unlock(); |
iveresov@2138 | 2268 | return osr; |
iveresov@2138 | 2269 | } |
iveresov@2138 | 2270 | } else { |
iveresov@2138 | 2271 | if (best == NULL || (osr->comp_level() > best->comp_level())) { |
iveresov@2138 | 2272 | if (osr->comp_level() == CompLevel_highest_tier) { |
iveresov@2138 | 2273 | // Found the best possible - return it. |
iveresov@2138 | 2274 | OsrList_lock->unlock(); |
iveresov@2138 | 2275 | return osr; |
iveresov@2138 | 2276 | } |
iveresov@2138 | 2277 | best = osr; |
iveresov@2138 | 2278 | } |
iveresov@2138 | 2279 | } |
duke@435 | 2280 | } |
jrose@1424 | 2281 | osr = osr->osr_link(); |
duke@435 | 2282 | } |
duke@435 | 2283 | OsrList_lock->unlock(); |
iveresov@2138 | 2284 | if (best != NULL && best->comp_level() >= comp_level && match_level == false) { |
iveresov@2138 | 2285 | return best; |
iveresov@2138 | 2286 | } |
duke@435 | 2287 | return NULL; |
duke@435 | 2288 | } |
duke@435 | 2289 | |
duke@435 | 2290 | // ----------------------------------------------------------------------------------------------------- |
duke@435 | 2291 | #ifndef PRODUCT |
duke@435 | 2292 | |
duke@435 | 2293 | // Printing |
duke@435 | 2294 | |
jrose@1100 | 2295 | #define BULLET " - " |
jrose@1100 | 2296 | |
duke@435 | 2297 | void FieldPrinter::do_field(fieldDescriptor* fd) { |
jrose@1100 | 2298 | _st->print(BULLET); |
never@2658 | 2299 | if (_obj == NULL) { |
duke@435 | 2300 | fd->print_on(_st); |
duke@435 | 2301 | _st->cr(); |
duke@435 | 2302 | } else { |
duke@435 | 2303 | fd->print_on_for(_st, _obj); |
duke@435 | 2304 | _st->cr(); |
duke@435 | 2305 | } |
duke@435 | 2306 | } |
duke@435 | 2307 | |
duke@435 | 2308 | |
duke@435 | 2309 | void instanceKlass::oop_print_on(oop obj, outputStream* st) { |
duke@435 | 2310 | Klass::oop_print_on(obj, st); |
duke@435 | 2311 | |
never@1577 | 2312 | if (as_klassOop() == SystemDictionary::String_klass()) { |
duke@435 | 2313 | typeArrayOop value = java_lang_String::value(obj); |
duke@435 | 2314 | juint offset = java_lang_String::offset(obj); |
duke@435 | 2315 | juint length = java_lang_String::length(obj); |
duke@435 | 2316 | if (value != NULL && |
duke@435 | 2317 | value->is_typeArray() && |
duke@435 | 2318 | offset <= (juint) value->length() && |
duke@435 | 2319 | offset + length <= (juint) value->length()) { |
jrose@1100 | 2320 | st->print(BULLET"string: "); |
duke@435 | 2321 | Handle h_obj(obj); |
duke@435 | 2322 | java_lang_String::print(h_obj, st); |
duke@435 | 2323 | st->cr(); |
duke@435 | 2324 | if (!WizardMode) return; // that is enough |
duke@435 | 2325 | } |
duke@435 | 2326 | } |
duke@435 | 2327 | |
jrose@1100 | 2328 | st->print_cr(BULLET"---- fields (total size %d words):", oop_size(obj)); |
never@2658 | 2329 | FieldPrinter print_field(st, obj); |
never@2658 | 2330 | do_nonstatic_fields(&print_field); |
duke@435 | 2331 | |
never@1577 | 2332 | if (as_klassOop() == SystemDictionary::Class_klass()) { |
jrose@1100 | 2333 | st->print(BULLET"signature: "); |
jrose@1100 | 2334 | java_lang_Class::print_signature(obj, st); |
jrose@1100 | 2335 | st->cr(); |
duke@435 | 2336 | klassOop mirrored_klass = java_lang_Class::as_klassOop(obj); |
jrose@1100 | 2337 | st->print(BULLET"fake entry for mirror: "); |
duke@435 | 2338 | mirrored_klass->print_value_on(st); |
duke@435 | 2339 | st->cr(); |
jrose@1100 | 2340 | st->print(BULLET"fake entry resolved_constructor: "); |
duke@435 | 2341 | methodOop ctor = java_lang_Class::resolved_constructor(obj); |
duke@435 | 2342 | ctor->print_value_on(st); |
duke@435 | 2343 | klassOop array_klass = java_lang_Class::array_klass(obj); |
jrose@1100 | 2344 | st->cr(); |
jrose@1100 | 2345 | st->print(BULLET"fake entry for array: "); |
duke@435 | 2346 | array_klass->print_value_on(st); |
duke@435 | 2347 | st->cr(); |
never@2658 | 2348 | st->print_cr(BULLET"fake entry for oop_size: %d", java_lang_Class::oop_size(obj)); |
never@2658 | 2349 | st->print_cr(BULLET"fake entry for static_oop_field_count: %d", java_lang_Class::static_oop_field_count(obj)); |
never@2658 | 2350 | klassOop real_klass = java_lang_Class::as_klassOop(obj); |
never@2690 | 2351 | if (real_klass != NULL && real_klass->klass_part()->oop_is_instance()) { |
never@2658 | 2352 | instanceKlass::cast(real_klass)->do_local_static_fields(&print_field); |
never@2658 | 2353 | } |
jrose@1474 | 2354 | } else if (as_klassOop() == SystemDictionary::MethodType_klass()) { |
jrose@1474 | 2355 | st->print(BULLET"signature: "); |
jrose@2639 | 2356 | java_lang_invoke_MethodType::print_signature(obj, st); |
jrose@1474 | 2357 | st->cr(); |
duke@435 | 2358 | } |
duke@435 | 2359 | } |
duke@435 | 2360 | |
jrose@1590 | 2361 | #endif //PRODUCT |
jrose@1590 | 2362 | |
duke@435 | 2363 | void instanceKlass::oop_print_value_on(oop obj, outputStream* st) { |
duke@435 | 2364 | st->print("a "); |
duke@435 | 2365 | name()->print_value_on(st); |
duke@435 | 2366 | obj->print_address_on(st); |
never@1577 | 2367 | if (as_klassOop() == SystemDictionary::String_klass() |
jrose@1100 | 2368 | && java_lang_String::value(obj) != NULL) { |
jrose@1100 | 2369 | ResourceMark rm; |
jrose@1100 | 2370 | int len = java_lang_String::length(obj); |
jrose@1100 | 2371 | int plen = (len < 24 ? len : 12); |
jrose@1100 | 2372 | char* str = java_lang_String::as_utf8_string(obj, 0, plen); |
jrose@1100 | 2373 | st->print(" = \"%s\"", str); |
jrose@1100 | 2374 | if (len > plen) |
jrose@1100 | 2375 | st->print("...[%d]", len); |
never@1577 | 2376 | } else if (as_klassOop() == SystemDictionary::Class_klass()) { |
jrose@1100 | 2377 | klassOop k = java_lang_Class::as_klassOop(obj); |
jrose@1100 | 2378 | st->print(" = "); |
jrose@1100 | 2379 | if (k != NULL) { |
jrose@1100 | 2380 | k->print_value_on(st); |
jrose@1100 | 2381 | } else { |
jrose@1100 | 2382 | const char* tname = type2name(java_lang_Class::primitive_type(obj)); |
jrose@1100 | 2383 | st->print("%s", tname ? tname : "type?"); |
jrose@1100 | 2384 | } |
jrose@1474 | 2385 | } else if (as_klassOop() == SystemDictionary::MethodType_klass()) { |
jrose@1474 | 2386 | st->print(" = "); |
jrose@2639 | 2387 | java_lang_invoke_MethodType::print_signature(obj, st); |
jrose@1100 | 2388 | } else if (java_lang_boxing_object::is_instance(obj)) { |
jrose@1100 | 2389 | st->print(" = "); |
jrose@1100 | 2390 | java_lang_boxing_object::print(obj, st); |
jrose@1100 | 2391 | } |
duke@435 | 2392 | } |
duke@435 | 2393 | |
duke@435 | 2394 | const char* instanceKlass::internal_name() const { |
duke@435 | 2395 | return external_name(); |
duke@435 | 2396 | } |
duke@435 | 2397 | |
duke@435 | 2398 | // Verification |
duke@435 | 2399 | |
duke@435 | 2400 | class VerifyFieldClosure: public OopClosure { |
coleenp@548 | 2401 | protected: |
coleenp@548 | 2402 | template <class T> void do_oop_work(T* p) { |
duke@435 | 2403 | guarantee(Universe::heap()->is_in_closed_subset(p), "should be in heap"); |
coleenp@548 | 2404 | oop obj = oopDesc::load_decode_heap_oop(p); |
coleenp@548 | 2405 | if (!obj->is_oop_or_null()) { |
coleenp@548 | 2406 | tty->print_cr("Failed: " PTR_FORMAT " -> " PTR_FORMAT, p, (address)obj); |
duke@435 | 2407 | Universe::print(); |
duke@435 | 2408 | guarantee(false, "boom"); |
duke@435 | 2409 | } |
duke@435 | 2410 | } |
coleenp@548 | 2411 | public: |
coleenp@548 | 2412 | virtual void do_oop(oop* p) { VerifyFieldClosure::do_oop_work(p); } |
coleenp@548 | 2413 | virtual void do_oop(narrowOop* p) { VerifyFieldClosure::do_oop_work(p); } |
duke@435 | 2414 | }; |
duke@435 | 2415 | |
duke@435 | 2416 | void instanceKlass::oop_verify_on(oop obj, outputStream* st) { |
duke@435 | 2417 | Klass::oop_verify_on(obj, st); |
duke@435 | 2418 | VerifyFieldClosure blk; |
duke@435 | 2419 | oop_oop_iterate(obj, &blk); |
duke@435 | 2420 | } |
duke@435 | 2421 | |
coleenp@548 | 2422 | // JNIid class for jfieldIDs only |
coleenp@548 | 2423 | // Note to reviewers: |
coleenp@548 | 2424 | // These JNI functions are just moved over to column 1 and not changed |
coleenp@548 | 2425 | // in the compressed oops workspace. |
coleenp@548 | 2426 | JNIid::JNIid(klassOop holder, int offset, JNIid* next) { |
coleenp@548 | 2427 | _holder = holder; |
coleenp@548 | 2428 | _offset = offset; |
coleenp@548 | 2429 | _next = next; |
coleenp@548 | 2430 | debug_only(_is_static_field_id = false;) |
coleenp@548 | 2431 | } |
duke@435 | 2432 | |
duke@435 | 2433 | |
coleenp@548 | 2434 | JNIid* JNIid::find(int offset) { |
coleenp@548 | 2435 | JNIid* current = this; |
coleenp@548 | 2436 | while (current != NULL) { |
coleenp@548 | 2437 | if (current->offset() == offset) return current; |
coleenp@548 | 2438 | current = current->next(); |
coleenp@548 | 2439 | } |
coleenp@548 | 2440 | return NULL; |
coleenp@548 | 2441 | } |
duke@435 | 2442 | |
duke@435 | 2443 | void JNIid::oops_do(OopClosure* f) { |
duke@435 | 2444 | for (JNIid* cur = this; cur != NULL; cur = cur->next()) { |
duke@435 | 2445 | f->do_oop(cur->holder_addr()); |
duke@435 | 2446 | } |
duke@435 | 2447 | } |
duke@435 | 2448 | |
duke@435 | 2449 | void JNIid::deallocate(JNIid* current) { |
coleenp@548 | 2450 | while (current != NULL) { |
coleenp@548 | 2451 | JNIid* next = current->next(); |
coleenp@548 | 2452 | delete current; |
coleenp@548 | 2453 | current = next; |
coleenp@548 | 2454 | } |
coleenp@548 | 2455 | } |
duke@435 | 2456 | |
duke@435 | 2457 | |
coleenp@548 | 2458 | void JNIid::verify(klassOop holder) { |
never@2658 | 2459 | int first_field_offset = instanceMirrorKlass::offset_of_static_fields(); |
coleenp@548 | 2460 | int end_field_offset; |
coleenp@548 | 2461 | end_field_offset = first_field_offset + (instanceKlass::cast(holder)->static_field_size() * wordSize); |
duke@435 | 2462 | |
coleenp@548 | 2463 | JNIid* current = this; |
coleenp@548 | 2464 | while (current != NULL) { |
coleenp@548 | 2465 | guarantee(current->holder() == holder, "Invalid klass in JNIid"); |
coleenp@548 | 2466 | #ifdef ASSERT |
coleenp@548 | 2467 | int o = current->offset(); |
coleenp@548 | 2468 | if (current->is_static_field_id()) { |
coleenp@548 | 2469 | guarantee(o >= first_field_offset && o < end_field_offset, "Invalid static field offset in JNIid"); |
coleenp@548 | 2470 | } |
coleenp@548 | 2471 | #endif |
coleenp@548 | 2472 | current = current->next(); |
coleenp@548 | 2473 | } |
coleenp@548 | 2474 | } |
duke@435 | 2475 | |
duke@435 | 2476 | |
duke@435 | 2477 | #ifdef ASSERT |
coleenp@548 | 2478 | void instanceKlass::set_init_state(ClassState state) { |
coleenp@548 | 2479 | bool good_state = as_klassOop()->is_shared() ? (_init_state <= state) |
coleenp@548 | 2480 | : (_init_state < state); |
coleenp@548 | 2481 | assert(good_state || state == allocated, "illegal state transition"); |
coleenp@3368 | 2482 | _init_state = (u1)state; |
coleenp@548 | 2483 | } |
duke@435 | 2484 | #endif |
duke@435 | 2485 | |
duke@435 | 2486 | |
duke@435 | 2487 | // RedefineClasses() support for previous versions: |
duke@435 | 2488 | |
duke@435 | 2489 | // Add an information node that contains weak references to the |
duke@435 | 2490 | // interesting parts of the previous version of the_class. |
dcubed@1412 | 2491 | // This is also where we clean out any unused weak references. |
dcubed@1412 | 2492 | // Note that while we delete nodes from the _previous_versions |
dcubed@1412 | 2493 | // array, we never delete the array itself until the klass is |
dcubed@1412 | 2494 | // unloaded. The has_been_redefined() query depends on that fact. |
dcubed@1412 | 2495 | // |
duke@435 | 2496 | void instanceKlass::add_previous_version(instanceKlassHandle ikh, |
coleenp@548 | 2497 | BitMap* emcp_methods, int emcp_method_count) { |
duke@435 | 2498 | assert(Thread::current()->is_VM_thread(), |
coleenp@548 | 2499 | "only VMThread can add previous versions"); |
duke@435 | 2500 | |
duke@435 | 2501 | if (_previous_versions == NULL) { |
duke@435 | 2502 | // This is the first previous version so make some space. |
duke@435 | 2503 | // Start with 2 elements under the assumption that the class |
duke@435 | 2504 | // won't be redefined much. |
duke@435 | 2505 | _previous_versions = new (ResourceObj::C_HEAP) |
duke@435 | 2506 | GrowableArray<PreviousVersionNode *>(2, true); |
duke@435 | 2507 | } |
duke@435 | 2508 | |
duke@435 | 2509 | // RC_TRACE macro has an embedded ResourceMark |
duke@435 | 2510 | RC_TRACE(0x00000100, ("adding previous version ref for %s @%d, EMCP_cnt=%d", |
duke@435 | 2511 | ikh->external_name(), _previous_versions->length(), emcp_method_count)); |
duke@435 | 2512 | constantPoolHandle cp_h(ikh->constants()); |
dcubed@482 | 2513 | jobject cp_ref; |
dcubed@482 | 2514 | if (cp_h->is_shared()) { |
dcubed@482 | 2515 | // a shared ConstantPool requires a regular reference; a weak |
dcubed@482 | 2516 | // reference would be collectible |
dcubed@482 | 2517 | cp_ref = JNIHandles::make_global(cp_h); |
dcubed@482 | 2518 | } else { |
dcubed@482 | 2519 | cp_ref = JNIHandles::make_weak_global(cp_h); |
dcubed@482 | 2520 | } |
duke@435 | 2521 | PreviousVersionNode * pv_node = NULL; |
duke@435 | 2522 | objArrayOop old_methods = ikh->methods(); |
duke@435 | 2523 | |
duke@435 | 2524 | if (emcp_method_count == 0) { |
dcubed@482 | 2525 | // non-shared ConstantPool gets a weak reference |
dcubed@482 | 2526 | pv_node = new PreviousVersionNode(cp_ref, !cp_h->is_shared(), NULL); |
duke@435 | 2527 | RC_TRACE(0x00000400, |
duke@435 | 2528 | ("add: all methods are obsolete; flushing any EMCP weak refs")); |
duke@435 | 2529 | } else { |
duke@435 | 2530 | int local_count = 0; |
duke@435 | 2531 | GrowableArray<jweak>* method_refs = new (ResourceObj::C_HEAP) |
duke@435 | 2532 | GrowableArray<jweak>(emcp_method_count, true); |
duke@435 | 2533 | for (int i = 0; i < old_methods->length(); i++) { |
duke@435 | 2534 | if (emcp_methods->at(i)) { |
duke@435 | 2535 | // this old method is EMCP so save a weak ref |
duke@435 | 2536 | methodOop old_method = (methodOop) old_methods->obj_at(i); |
duke@435 | 2537 | methodHandle old_method_h(old_method); |
duke@435 | 2538 | jweak method_ref = JNIHandles::make_weak_global(old_method_h); |
duke@435 | 2539 | method_refs->append(method_ref); |
duke@435 | 2540 | if (++local_count >= emcp_method_count) { |
duke@435 | 2541 | // no more EMCP methods so bail out now |
duke@435 | 2542 | break; |
duke@435 | 2543 | } |
duke@435 | 2544 | } |
duke@435 | 2545 | } |
dcubed@482 | 2546 | // non-shared ConstantPool gets a weak reference |
dcubed@482 | 2547 | pv_node = new PreviousVersionNode(cp_ref, !cp_h->is_shared(), method_refs); |
duke@435 | 2548 | } |
duke@435 | 2549 | |
duke@435 | 2550 | _previous_versions->append(pv_node); |
duke@435 | 2551 | |
duke@435 | 2552 | // Using weak references allows the interesting parts of previous |
duke@435 | 2553 | // classes to be GC'ed when they are no longer needed. Since the |
duke@435 | 2554 | // caller is the VMThread and we are at a safepoint, this is a good |
duke@435 | 2555 | // time to clear out unused weak references. |
duke@435 | 2556 | |
duke@435 | 2557 | RC_TRACE(0x00000400, ("add: previous version length=%d", |
duke@435 | 2558 | _previous_versions->length())); |
duke@435 | 2559 | |
duke@435 | 2560 | // skip the last entry since we just added it |
duke@435 | 2561 | for (int i = _previous_versions->length() - 2; i >= 0; i--) { |
duke@435 | 2562 | // check the previous versions array for a GC'ed weak refs |
duke@435 | 2563 | pv_node = _previous_versions->at(i); |
duke@435 | 2564 | cp_ref = pv_node->prev_constant_pool(); |
dcubed@482 | 2565 | assert(cp_ref != NULL, "cp ref was unexpectedly cleared"); |
duke@435 | 2566 | if (cp_ref == NULL) { |
duke@435 | 2567 | delete pv_node; |
duke@435 | 2568 | _previous_versions->remove_at(i); |
duke@435 | 2569 | // Since we are traversing the array backwards, we don't have to |
duke@435 | 2570 | // do anything special with the index. |
duke@435 | 2571 | continue; // robustness |
duke@435 | 2572 | } |
duke@435 | 2573 | |
duke@435 | 2574 | constantPoolOop cp = (constantPoolOop)JNIHandles::resolve(cp_ref); |
duke@435 | 2575 | if (cp == NULL) { |
duke@435 | 2576 | // this entry has been GC'ed so remove it |
duke@435 | 2577 | delete pv_node; |
duke@435 | 2578 | _previous_versions->remove_at(i); |
duke@435 | 2579 | // Since we are traversing the array backwards, we don't have to |
duke@435 | 2580 | // do anything special with the index. |
duke@435 | 2581 | continue; |
duke@435 | 2582 | } else { |
duke@435 | 2583 | RC_TRACE(0x00000400, ("add: previous version @%d is alive", i)); |
duke@435 | 2584 | } |
duke@435 | 2585 | |
duke@435 | 2586 | GrowableArray<jweak>* method_refs = pv_node->prev_EMCP_methods(); |
duke@435 | 2587 | if (method_refs != NULL) { |
duke@435 | 2588 | RC_TRACE(0x00000400, ("add: previous methods length=%d", |
duke@435 | 2589 | method_refs->length())); |
duke@435 | 2590 | for (int j = method_refs->length() - 1; j >= 0; j--) { |
duke@435 | 2591 | jweak method_ref = method_refs->at(j); |
duke@435 | 2592 | assert(method_ref != NULL, "weak method ref was unexpectedly cleared"); |
duke@435 | 2593 | if (method_ref == NULL) { |
duke@435 | 2594 | method_refs->remove_at(j); |
duke@435 | 2595 | // Since we are traversing the array backwards, we don't have to |
duke@435 | 2596 | // do anything special with the index. |
duke@435 | 2597 | continue; // robustness |
duke@435 | 2598 | } |
duke@435 | 2599 | |
duke@435 | 2600 | methodOop method = (methodOop)JNIHandles::resolve(method_ref); |
duke@435 | 2601 | if (method == NULL || emcp_method_count == 0) { |
duke@435 | 2602 | // This method entry has been GC'ed or the current |
duke@435 | 2603 | // RedefineClasses() call has made all methods obsolete |
duke@435 | 2604 | // so remove it. |
duke@435 | 2605 | JNIHandles::destroy_weak_global(method_ref); |
duke@435 | 2606 | method_refs->remove_at(j); |
duke@435 | 2607 | } else { |
duke@435 | 2608 | // RC_TRACE macro has an embedded ResourceMark |
duke@435 | 2609 | RC_TRACE(0x00000400, |
duke@435 | 2610 | ("add: %s(%s): previous method @%d in version @%d is alive", |
duke@435 | 2611 | method->name()->as_C_string(), method->signature()->as_C_string(), |
duke@435 | 2612 | j, i)); |
duke@435 | 2613 | } |
duke@435 | 2614 | } |
duke@435 | 2615 | } |
duke@435 | 2616 | } |
duke@435 | 2617 | |
duke@435 | 2618 | int obsolete_method_count = old_methods->length() - emcp_method_count; |
duke@435 | 2619 | |
duke@435 | 2620 | if (emcp_method_count != 0 && obsolete_method_count != 0 && |
duke@435 | 2621 | _previous_versions->length() > 1) { |
duke@435 | 2622 | // We have a mix of obsolete and EMCP methods. If there is more |
duke@435 | 2623 | // than the previous version that we just added, then we have to |
duke@435 | 2624 | // clear out any matching EMCP method entries the hard way. |
duke@435 | 2625 | int local_count = 0; |
duke@435 | 2626 | for (int i = 0; i < old_methods->length(); i++) { |
duke@435 | 2627 | if (!emcp_methods->at(i)) { |
duke@435 | 2628 | // only obsolete methods are interesting |
duke@435 | 2629 | methodOop old_method = (methodOop) old_methods->obj_at(i); |
coleenp@2497 | 2630 | Symbol* m_name = old_method->name(); |
coleenp@2497 | 2631 | Symbol* m_signature = old_method->signature(); |
duke@435 | 2632 | |
duke@435 | 2633 | // skip the last entry since we just added it |
duke@435 | 2634 | for (int j = _previous_versions->length() - 2; j >= 0; j--) { |
duke@435 | 2635 | // check the previous versions array for a GC'ed weak refs |
duke@435 | 2636 | pv_node = _previous_versions->at(j); |
duke@435 | 2637 | cp_ref = pv_node->prev_constant_pool(); |
dcubed@482 | 2638 | assert(cp_ref != NULL, "cp ref was unexpectedly cleared"); |
duke@435 | 2639 | if (cp_ref == NULL) { |
duke@435 | 2640 | delete pv_node; |
duke@435 | 2641 | _previous_versions->remove_at(j); |
duke@435 | 2642 | // Since we are traversing the array backwards, we don't have to |
duke@435 | 2643 | // do anything special with the index. |
duke@435 | 2644 | continue; // robustness |
duke@435 | 2645 | } |
duke@435 | 2646 | |
duke@435 | 2647 | constantPoolOop cp = (constantPoolOop)JNIHandles::resolve(cp_ref); |
duke@435 | 2648 | if (cp == NULL) { |
duke@435 | 2649 | // this entry has been GC'ed so remove it |
duke@435 | 2650 | delete pv_node; |
duke@435 | 2651 | _previous_versions->remove_at(j); |
duke@435 | 2652 | // Since we are traversing the array backwards, we don't have to |
duke@435 | 2653 | // do anything special with the index. |
duke@435 | 2654 | continue; |
duke@435 | 2655 | } |
duke@435 | 2656 | |
duke@435 | 2657 | GrowableArray<jweak>* method_refs = pv_node->prev_EMCP_methods(); |
duke@435 | 2658 | if (method_refs == NULL) { |
duke@435 | 2659 | // We have run into a PreviousVersion generation where |
duke@435 | 2660 | // all methods were made obsolete during that generation's |
duke@435 | 2661 | // RedefineClasses() operation. At the time of that |
duke@435 | 2662 | // operation, all EMCP methods were flushed so we don't |
duke@435 | 2663 | // have to go back any further. |
duke@435 | 2664 | // |
duke@435 | 2665 | // A NULL method_refs is different than an empty method_refs. |
duke@435 | 2666 | // We cannot infer any optimizations about older generations |
duke@435 | 2667 | // from an empty method_refs for the current generation. |
duke@435 | 2668 | break; |
duke@435 | 2669 | } |
duke@435 | 2670 | |
duke@435 | 2671 | for (int k = method_refs->length() - 1; k >= 0; k--) { |
duke@435 | 2672 | jweak method_ref = method_refs->at(k); |
duke@435 | 2673 | assert(method_ref != NULL, |
duke@435 | 2674 | "weak method ref was unexpectedly cleared"); |
duke@435 | 2675 | if (method_ref == NULL) { |
duke@435 | 2676 | method_refs->remove_at(k); |
duke@435 | 2677 | // Since we are traversing the array backwards, we don't |
duke@435 | 2678 | // have to do anything special with the index. |
duke@435 | 2679 | continue; // robustness |
duke@435 | 2680 | } |
duke@435 | 2681 | |
duke@435 | 2682 | methodOop method = (methodOop)JNIHandles::resolve(method_ref); |
duke@435 | 2683 | if (method == NULL) { |
duke@435 | 2684 | // this method entry has been GC'ed so skip it |
duke@435 | 2685 | JNIHandles::destroy_weak_global(method_ref); |
duke@435 | 2686 | method_refs->remove_at(k); |
duke@435 | 2687 | continue; |
duke@435 | 2688 | } |
duke@435 | 2689 | |
duke@435 | 2690 | if (method->name() == m_name && |
duke@435 | 2691 | method->signature() == m_signature) { |
duke@435 | 2692 | // The current RedefineClasses() call has made all EMCP |
duke@435 | 2693 | // versions of this method obsolete so mark it as obsolete |
duke@435 | 2694 | // and remove the weak ref. |
duke@435 | 2695 | RC_TRACE(0x00000400, |
duke@435 | 2696 | ("add: %s(%s): flush obsolete method @%d in version @%d", |
duke@435 | 2697 | m_name->as_C_string(), m_signature->as_C_string(), k, j)); |
duke@435 | 2698 | |
duke@435 | 2699 | method->set_is_obsolete(); |
duke@435 | 2700 | JNIHandles::destroy_weak_global(method_ref); |
duke@435 | 2701 | method_refs->remove_at(k); |
duke@435 | 2702 | break; |
duke@435 | 2703 | } |
duke@435 | 2704 | } |
duke@435 | 2705 | |
duke@435 | 2706 | // The previous loop may not find a matching EMCP method, but |
duke@435 | 2707 | // that doesn't mean that we can optimize and not go any |
duke@435 | 2708 | // further back in the PreviousVersion generations. The EMCP |
duke@435 | 2709 | // method for this generation could have already been GC'ed, |
duke@435 | 2710 | // but there still may be an older EMCP method that has not |
duke@435 | 2711 | // been GC'ed. |
duke@435 | 2712 | } |
duke@435 | 2713 | |
duke@435 | 2714 | if (++local_count >= obsolete_method_count) { |
duke@435 | 2715 | // no more obsolete methods so bail out now |
duke@435 | 2716 | break; |
duke@435 | 2717 | } |
duke@435 | 2718 | } |
duke@435 | 2719 | } |
duke@435 | 2720 | } |
duke@435 | 2721 | } // end add_previous_version() |
duke@435 | 2722 | |
duke@435 | 2723 | |
duke@435 | 2724 | // Determine if instanceKlass has a previous version. |
duke@435 | 2725 | bool instanceKlass::has_previous_version() const { |
duke@435 | 2726 | if (_previous_versions == NULL) { |
duke@435 | 2727 | // no previous versions array so answer is easy |
duke@435 | 2728 | return false; |
duke@435 | 2729 | } |
duke@435 | 2730 | |
duke@435 | 2731 | for (int i = _previous_versions->length() - 1; i >= 0; i--) { |
duke@435 | 2732 | // Check the previous versions array for an info node that hasn't |
duke@435 | 2733 | // been GC'ed |
duke@435 | 2734 | PreviousVersionNode * pv_node = _previous_versions->at(i); |
duke@435 | 2735 | |
dcubed@482 | 2736 | jobject cp_ref = pv_node->prev_constant_pool(); |
dcubed@482 | 2737 | assert(cp_ref != NULL, "cp reference was unexpectedly cleared"); |
duke@435 | 2738 | if (cp_ref == NULL) { |
duke@435 | 2739 | continue; // robustness |
duke@435 | 2740 | } |
duke@435 | 2741 | |
duke@435 | 2742 | constantPoolOop cp = (constantPoolOop)JNIHandles::resolve(cp_ref); |
duke@435 | 2743 | if (cp != NULL) { |
duke@435 | 2744 | // we have at least one previous version |
duke@435 | 2745 | return true; |
duke@435 | 2746 | } |
duke@435 | 2747 | |
duke@435 | 2748 | // We don't have to check the method refs. If the constant pool has |
duke@435 | 2749 | // been GC'ed then so have the methods. |
duke@435 | 2750 | } |
duke@435 | 2751 | |
duke@435 | 2752 | // all of the underlying nodes' info has been GC'ed |
duke@435 | 2753 | return false; |
duke@435 | 2754 | } // end has_previous_version() |
duke@435 | 2755 | |
duke@435 | 2756 | methodOop instanceKlass::method_with_idnum(int idnum) { |
duke@435 | 2757 | methodOop m = NULL; |
duke@435 | 2758 | if (idnum < methods()->length()) { |
duke@435 | 2759 | m = (methodOop) methods()->obj_at(idnum); |
duke@435 | 2760 | } |
duke@435 | 2761 | if (m == NULL || m->method_idnum() != idnum) { |
duke@435 | 2762 | for (int index = 0; index < methods()->length(); ++index) { |
duke@435 | 2763 | m = (methodOop) methods()->obj_at(index); |
duke@435 | 2764 | if (m->method_idnum() == idnum) { |
duke@435 | 2765 | return m; |
duke@435 | 2766 | } |
duke@435 | 2767 | } |
duke@435 | 2768 | } |
duke@435 | 2769 | return m; |
duke@435 | 2770 | } |
duke@435 | 2771 | |
duke@435 | 2772 | |
duke@435 | 2773 | // Set the annotation at 'idnum' to 'anno'. |
duke@435 | 2774 | // We don't want to create or extend the array if 'anno' is NULL, since that is the |
duke@435 | 2775 | // default value. However, if the array exists and is long enough, we must set NULL values. |
duke@435 | 2776 | void instanceKlass::set_methods_annotations_of(int idnum, typeArrayOop anno, objArrayOop* md_p) { |
duke@435 | 2777 | objArrayOop md = *md_p; |
duke@435 | 2778 | if (md != NULL && md->length() > idnum) { |
duke@435 | 2779 | md->obj_at_put(idnum, anno); |
duke@435 | 2780 | } else if (anno != NULL) { |
duke@435 | 2781 | // create the array |
duke@435 | 2782 | int length = MAX2(idnum+1, (int)_idnum_allocated_count); |
duke@435 | 2783 | md = oopFactory::new_system_objArray(length, Thread::current()); |
duke@435 | 2784 | if (*md_p != NULL) { |
duke@435 | 2785 | // copy the existing entries |
duke@435 | 2786 | for (int index = 0; index < (*md_p)->length(); index++) { |
duke@435 | 2787 | md->obj_at_put(index, (*md_p)->obj_at(index)); |
duke@435 | 2788 | } |
duke@435 | 2789 | } |
duke@435 | 2790 | set_annotations(md, md_p); |
duke@435 | 2791 | md->obj_at_put(idnum, anno); |
duke@435 | 2792 | } // if no array and idnum isn't included there is nothing to do |
duke@435 | 2793 | } |
duke@435 | 2794 | |
duke@435 | 2795 | // Construct a PreviousVersionNode entry for the array hung off |
duke@435 | 2796 | // the instanceKlass. |
dcubed@482 | 2797 | PreviousVersionNode::PreviousVersionNode(jobject prev_constant_pool, |
dcubed@482 | 2798 | bool prev_cp_is_weak, GrowableArray<jweak>* prev_EMCP_methods) { |
duke@435 | 2799 | |
duke@435 | 2800 | _prev_constant_pool = prev_constant_pool; |
dcubed@482 | 2801 | _prev_cp_is_weak = prev_cp_is_weak; |
duke@435 | 2802 | _prev_EMCP_methods = prev_EMCP_methods; |
duke@435 | 2803 | } |
duke@435 | 2804 | |
duke@435 | 2805 | |
duke@435 | 2806 | // Destroy a PreviousVersionNode |
duke@435 | 2807 | PreviousVersionNode::~PreviousVersionNode() { |
duke@435 | 2808 | if (_prev_constant_pool != NULL) { |
dcubed@482 | 2809 | if (_prev_cp_is_weak) { |
dcubed@482 | 2810 | JNIHandles::destroy_weak_global(_prev_constant_pool); |
dcubed@482 | 2811 | } else { |
dcubed@482 | 2812 | JNIHandles::destroy_global(_prev_constant_pool); |
dcubed@482 | 2813 | } |
duke@435 | 2814 | } |
duke@435 | 2815 | |
duke@435 | 2816 | if (_prev_EMCP_methods != NULL) { |
duke@435 | 2817 | for (int i = _prev_EMCP_methods->length() - 1; i >= 0; i--) { |
duke@435 | 2818 | jweak method_ref = _prev_EMCP_methods->at(i); |
duke@435 | 2819 | if (method_ref != NULL) { |
duke@435 | 2820 | JNIHandles::destroy_weak_global(method_ref); |
duke@435 | 2821 | } |
duke@435 | 2822 | } |
duke@435 | 2823 | delete _prev_EMCP_methods; |
duke@435 | 2824 | } |
duke@435 | 2825 | } |
duke@435 | 2826 | |
duke@435 | 2827 | |
duke@435 | 2828 | // Construct a PreviousVersionInfo entry |
duke@435 | 2829 | PreviousVersionInfo::PreviousVersionInfo(PreviousVersionNode *pv_node) { |
duke@435 | 2830 | _prev_constant_pool_handle = constantPoolHandle(); // NULL handle |
duke@435 | 2831 | _prev_EMCP_method_handles = NULL; |
duke@435 | 2832 | |
dcubed@482 | 2833 | jobject cp_ref = pv_node->prev_constant_pool(); |
dcubed@482 | 2834 | assert(cp_ref != NULL, "constant pool ref was unexpectedly cleared"); |
duke@435 | 2835 | if (cp_ref == NULL) { |
duke@435 | 2836 | return; // robustness |
duke@435 | 2837 | } |
duke@435 | 2838 | |
duke@435 | 2839 | constantPoolOop cp = (constantPoolOop)JNIHandles::resolve(cp_ref); |
duke@435 | 2840 | if (cp == NULL) { |
duke@435 | 2841 | // Weak reference has been GC'ed. Since the constant pool has been |
duke@435 | 2842 | // GC'ed, the methods have also been GC'ed. |
duke@435 | 2843 | return; |
duke@435 | 2844 | } |
duke@435 | 2845 | |
duke@435 | 2846 | // make the constantPoolOop safe to return |
duke@435 | 2847 | _prev_constant_pool_handle = constantPoolHandle(cp); |
duke@435 | 2848 | |
duke@435 | 2849 | GrowableArray<jweak>* method_refs = pv_node->prev_EMCP_methods(); |
duke@435 | 2850 | if (method_refs == NULL) { |
duke@435 | 2851 | // the instanceKlass did not have any EMCP methods |
duke@435 | 2852 | return; |
duke@435 | 2853 | } |
duke@435 | 2854 | |
duke@435 | 2855 | _prev_EMCP_method_handles = new GrowableArray<methodHandle>(10); |
duke@435 | 2856 | |
duke@435 | 2857 | int n_methods = method_refs->length(); |
duke@435 | 2858 | for (int i = 0; i < n_methods; i++) { |
duke@435 | 2859 | jweak method_ref = method_refs->at(i); |
duke@435 | 2860 | assert(method_ref != NULL, "weak method ref was unexpectedly cleared"); |
duke@435 | 2861 | if (method_ref == NULL) { |
duke@435 | 2862 | continue; // robustness |
duke@435 | 2863 | } |
duke@435 | 2864 | |
duke@435 | 2865 | methodOop method = (methodOop)JNIHandles::resolve(method_ref); |
duke@435 | 2866 | if (method == NULL) { |
duke@435 | 2867 | // this entry has been GC'ed so skip it |
duke@435 | 2868 | continue; |
duke@435 | 2869 | } |
duke@435 | 2870 | |
duke@435 | 2871 | // make the methodOop safe to return |
duke@435 | 2872 | _prev_EMCP_method_handles->append(methodHandle(method)); |
duke@435 | 2873 | } |
duke@435 | 2874 | } |
duke@435 | 2875 | |
duke@435 | 2876 | |
duke@435 | 2877 | // Destroy a PreviousVersionInfo |
duke@435 | 2878 | PreviousVersionInfo::~PreviousVersionInfo() { |
duke@435 | 2879 | // Since _prev_EMCP_method_handles is not C-heap allocated, we |
duke@435 | 2880 | // don't have to delete it. |
duke@435 | 2881 | } |
duke@435 | 2882 | |
duke@435 | 2883 | |
duke@435 | 2884 | // Construct a helper for walking the previous versions array |
duke@435 | 2885 | PreviousVersionWalker::PreviousVersionWalker(instanceKlass *ik) { |
duke@435 | 2886 | _previous_versions = ik->previous_versions(); |
duke@435 | 2887 | _current_index = 0; |
duke@435 | 2888 | // _hm needs no initialization |
duke@435 | 2889 | _current_p = NULL; |
duke@435 | 2890 | } |
duke@435 | 2891 | |
duke@435 | 2892 | |
duke@435 | 2893 | // Destroy a PreviousVersionWalker |
duke@435 | 2894 | PreviousVersionWalker::~PreviousVersionWalker() { |
duke@435 | 2895 | // Delete the current info just in case the caller didn't walk to |
duke@435 | 2896 | // the end of the previous versions list. No harm if _current_p is |
duke@435 | 2897 | // already NULL. |
duke@435 | 2898 | delete _current_p; |
duke@435 | 2899 | |
duke@435 | 2900 | // When _hm is destroyed, all the Handles returned in |
duke@435 | 2901 | // PreviousVersionInfo objects will be destroyed. |
duke@435 | 2902 | // Also, after this destructor is finished it will be |
duke@435 | 2903 | // safe to delete the GrowableArray allocated in the |
duke@435 | 2904 | // PreviousVersionInfo objects. |
duke@435 | 2905 | } |
duke@435 | 2906 | |
duke@435 | 2907 | |
duke@435 | 2908 | // Return the interesting information for the next previous version |
duke@435 | 2909 | // of the klass. Returns NULL if there are no more previous versions. |
duke@435 | 2910 | PreviousVersionInfo* PreviousVersionWalker::next_previous_version() { |
duke@435 | 2911 | if (_previous_versions == NULL) { |
duke@435 | 2912 | // no previous versions so nothing to return |
duke@435 | 2913 | return NULL; |
duke@435 | 2914 | } |
duke@435 | 2915 | |
duke@435 | 2916 | delete _current_p; // cleanup the previous info for the caller |
duke@435 | 2917 | _current_p = NULL; // reset to NULL so we don't delete same object twice |
duke@435 | 2918 | |
duke@435 | 2919 | int length = _previous_versions->length(); |
duke@435 | 2920 | |
duke@435 | 2921 | while (_current_index < length) { |
duke@435 | 2922 | PreviousVersionNode * pv_node = _previous_versions->at(_current_index++); |
duke@435 | 2923 | PreviousVersionInfo * pv_info = new (ResourceObj::C_HEAP) |
duke@435 | 2924 | PreviousVersionInfo(pv_node); |
duke@435 | 2925 | |
duke@435 | 2926 | constantPoolHandle cp_h = pv_info->prev_constant_pool_handle(); |
duke@435 | 2927 | if (cp_h.is_null()) { |
duke@435 | 2928 | delete pv_info; |
duke@435 | 2929 | |
duke@435 | 2930 | // The underlying node's info has been GC'ed so try the next one. |
duke@435 | 2931 | // We don't have to check the methods. If the constant pool has |
duke@435 | 2932 | // GC'ed then so have the methods. |
duke@435 | 2933 | continue; |
duke@435 | 2934 | } |
duke@435 | 2935 | |
duke@435 | 2936 | // Found a node with non GC'ed info so return it. The caller will |
duke@435 | 2937 | // need to delete pv_info when they are done with it. |
duke@435 | 2938 | _current_p = pv_info; |
duke@435 | 2939 | return pv_info; |
duke@435 | 2940 | } |
duke@435 | 2941 | |
duke@435 | 2942 | // all of the underlying nodes' info has been GC'ed |
duke@435 | 2943 | return NULL; |
duke@435 | 2944 | } // end next_previous_version() |