src/share/vm/oops/cpCacheOop.cpp

Sat, 25 Feb 2012 01:49:34 -0500

author
dholmes
date
Sat, 25 Feb 2012 01:49:34 -0500
changeset 3601
f096e1b74d85
parent 3137
e6b1331a51d2
child 3969
1d7922586cf6
permissions
-rw-r--r--

7148126: ConstantPoolCacheEntry::print prints to wrong stream
Summary: Should print to passed in stream not tty
Reviewed-by: dholmes, never
Contributed-by: Krystal Mok <sajia@taobao.com>

duke@435 1 /*
dholmes@3601 2 * Copyright (c) 1998, 2012, 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 "gc_implementation/shared/markSweep.inline.hpp"
stefank@2314 27 #include "interpreter/interpreter.hpp"
stefank@2314 28 #include "interpreter/rewriter.hpp"
stefank@2314 29 #include "memory/universe.inline.hpp"
stefank@2314 30 #include "oops/cpCacheOop.hpp"
stefank@2314 31 #include "oops/objArrayOop.hpp"
stefank@2314 32 #include "oops/oop.inline.hpp"
stefank@2314 33 #include "prims/jvmtiRedefineClassesTrace.hpp"
stefank@2314 34 #include "runtime/handles.inline.hpp"
duke@435 35
duke@435 36
duke@435 37 // Implememtation of ConstantPoolCacheEntry
duke@435 38
jrose@1494 39 void ConstantPoolCacheEntry::initialize_entry(int index) {
jrose@1161 40 assert(0 < index && index < 0x10000, "sanity check");
duke@435 41 _indices = index;
jrose@1161 42 assert(constant_pool_index() == index, "");
duke@435 43 }
duke@435 44
jrose@1494 45 void ConstantPoolCacheEntry::initialize_secondary_entry(int main_index) {
jrose@1494 46 assert(0 <= main_index && main_index < 0x10000, "sanity check");
jrose@1494 47 _indices = (main_index << 16);
jrose@1494 48 assert(main_entry_index() == main_index, "");
jrose@1494 49 }
duke@435 50
duke@435 51 int ConstantPoolCacheEntry::as_flags(TosState state, bool is_final,
duke@435 52 bool is_vfinal, bool is_volatile,
duke@435 53 bool is_method_interface, bool is_method) {
duke@435 54 int f = state;
duke@435 55
duke@435 56 assert( state < number_of_states, "Invalid state in as_flags");
duke@435 57
duke@435 58 f <<= 1;
duke@435 59 if (is_final) f |= 1;
duke@435 60 f <<= 1;
duke@435 61 if (is_vfinal) f |= 1;
duke@435 62 f <<= 1;
duke@435 63 if (is_volatile) f |= 1;
duke@435 64 f <<= 1;
duke@435 65 if (is_method_interface) f |= 1;
duke@435 66 f <<= 1;
duke@435 67 if (is_method) f |= 1;
duke@435 68 f <<= ConstantPoolCacheEntry::hotSwapBit;
duke@435 69 // Preserve existing flag bit values
duke@435 70 #ifdef ASSERT
duke@435 71 int old_state = ((_flags >> tosBits) & 0x0F);
duke@435 72 assert(old_state == 0 || old_state == state,
duke@435 73 "inconsistent cpCache flags state");
duke@435 74 #endif
duke@435 75 return (_flags | f) ;
duke@435 76 }
duke@435 77
duke@435 78 void ConstantPoolCacheEntry::set_bytecode_1(Bytecodes::Code code) {
duke@435 79 #ifdef ASSERT
duke@435 80 // Read once.
duke@435 81 volatile Bytecodes::Code c = bytecode_1();
duke@435 82 assert(c == 0 || c == code || code == 0, "update must be consistent");
duke@435 83 #endif
duke@435 84 // Need to flush pending stores here before bytecode is written.
duke@435 85 OrderAccess::release_store_ptr(&_indices, _indices | ((u_char)code << 16));
duke@435 86 }
duke@435 87
duke@435 88 void ConstantPoolCacheEntry::set_bytecode_2(Bytecodes::Code code) {
duke@435 89 #ifdef ASSERT
duke@435 90 // Read once.
duke@435 91 volatile Bytecodes::Code c = bytecode_2();
duke@435 92 assert(c == 0 || c == code || code == 0, "update must be consistent");
duke@435 93 #endif
duke@435 94 // Need to flush pending stores here before bytecode is written.
duke@435 95 OrderAccess::release_store_ptr(&_indices, _indices | ((u_char)code << 24));
duke@435 96 }
duke@435 97
twisti@2258 98 // Atomically sets f1 if it is still NULL, otherwise it keeps the
twisti@2258 99 // current value.
twisti@2258 100 void ConstantPoolCacheEntry::set_f1_if_null_atomic(oop f1) {
twisti@2553 101 // Use barriers as in oop_store
twisti@2553 102 oop* f1_addr = (oop*) &_f1;
twisti@2553 103 update_barrier_set_pre(f1_addr, f1);
twisti@2553 104 void* result = Atomic::cmpxchg_ptr(f1, f1_addr, NULL);
twisti@2553 105 bool success = (result == NULL);
twisti@2553 106 if (success) {
twisti@2811 107 update_barrier_set((void*) f1_addr, f1);
twisti@2258 108 }
twisti@2553 109 }
twisti@2258 110
duke@435 111 #ifdef ASSERT
duke@435 112 // It is possible to have two different dummy methodOops created
duke@435 113 // when the resolve code for invoke interface executes concurrently
duke@435 114 // Hence the assertion below is weakened a bit for the invokeinterface
duke@435 115 // case.
duke@435 116 bool ConstantPoolCacheEntry::same_methodOop(oop cur_f1, oop f1) {
duke@435 117 return (cur_f1 == f1 || ((methodOop)cur_f1)->name() ==
duke@435 118 ((methodOop)f1)->name() || ((methodOop)cur_f1)->signature() ==
duke@435 119 ((methodOop)f1)->signature());
duke@435 120 }
duke@435 121 #endif
duke@435 122
duke@435 123 // Note that concurrent update of both bytecodes can leave one of them
duke@435 124 // reset to zero. This is harmless; the interpreter will simply re-resolve
duke@435 125 // the damaged entry. More seriously, the memory synchronization is needed
duke@435 126 // to flush other fields (f1, f2) completely to memory before the bytecodes
duke@435 127 // are updated, lest other processors see a non-zero bytecode but zero f1/f2.
duke@435 128 void ConstantPoolCacheEntry::set_field(Bytecodes::Code get_code,
duke@435 129 Bytecodes::Code put_code,
duke@435 130 KlassHandle field_holder,
never@3137 131 int field_index,
duke@435 132 int field_offset,
duke@435 133 TosState field_type,
duke@435 134 bool is_final,
duke@435 135 bool is_volatile) {
never@2658 136 set_f1(field_holder()->java_mirror());
duke@435 137 set_f2(field_offset);
duke@435 138 assert(field_index <= field_index_mask,
duke@435 139 "field index does not fit in low flag bits");
duke@435 140 set_flags(as_flags(field_type, is_final, false, is_volatile, false, false) |
duke@435 141 (field_index & field_index_mask));
duke@435 142 set_bytecode_1(get_code);
duke@435 143 set_bytecode_2(put_code);
duke@435 144 NOT_PRODUCT(verify(tty));
duke@435 145 }
duke@435 146
duke@435 147 int ConstantPoolCacheEntry::field_index() const {
never@3137 148 return (_flags & field_index_mask);
duke@435 149 }
duke@435 150
duke@435 151 void ConstantPoolCacheEntry::set_method(Bytecodes::Code invoke_code,
duke@435 152 methodHandle method,
duke@435 153 int vtable_index) {
jrose@2015 154 assert(!is_secondary_entry(), "");
duke@435 155 assert(method->interpreter_entry() != NULL, "should have been set at this point");
duke@435 156 assert(!method->is_obsolete(), "attempt to write obsolete method to cpCache");
duke@435 157 bool change_to_virtual = (invoke_code == Bytecodes::_invokeinterface);
duke@435 158
duke@435 159 int byte_no = -1;
duke@435 160 bool needs_vfinal_flag = false;
duke@435 161 switch (invoke_code) {
duke@435 162 case Bytecodes::_invokevirtual:
duke@435 163 case Bytecodes::_invokeinterface: {
duke@435 164 if (method->can_be_statically_bound()) {
duke@435 165 set_f2((intptr_t)method());
duke@435 166 needs_vfinal_flag = true;
duke@435 167 } else {
duke@435 168 assert(vtable_index >= 0, "valid index");
duke@435 169 set_f2(vtable_index);
duke@435 170 }
duke@435 171 byte_no = 2;
duke@435 172 break;
duke@435 173 }
jrose@2015 174
jrose@2015 175 case Bytecodes::_invokedynamic: // similar to _invokevirtual
jrose@2015 176 if (TraceInvokeDynamic) {
jrose@2015 177 tty->print_cr("InvokeDynamic set_method%s method="PTR_FORMAT" index=%d",
jrose@2015 178 (is_secondary_entry() ? " secondary" : ""),
jrose@2015 179 (intptr_t)method(), vtable_index);
jrose@2015 180 method->print();
jrose@2015 181 this->print(tty, 0);
jrose@2015 182 }
jrose@2015 183 assert(method->can_be_statically_bound(), "must be a MH invoker method");
jrose@2742 184 assert(_f2 >= constantPoolOopDesc::CPCACHE_INDEX_TAG, "BSM index initialized");
twisti@2258 185 // SystemDictionary::find_method_handle_invoke only caches
twisti@2258 186 // methods which signature classes are on the boot classpath,
twisti@2258 187 // otherwise the newly created method is returned. To avoid
twisti@2258 188 // races in that case we store the first one coming in into the
twisti@2258 189 // cp-cache atomically if it's still unset.
twisti@2258 190 set_f1_if_null_atomic(method());
jrose@2015 191 needs_vfinal_flag = false; // _f2 is not an oop
jrose@2015 192 assert(!is_vfinal(), "f2 not an oop");
jrose@2017 193 byte_no = 1; // coordinate this with bytecode_number & is_resolved
jrose@2015 194 break;
jrose@2015 195
duke@435 196 case Bytecodes::_invokespecial:
duke@435 197 // Preserve the value of the vfinal flag on invokevirtual bytecode
duke@435 198 // which may be shared with this constant pool cache entry.
duke@435 199 needs_vfinal_flag = is_resolved(Bytecodes::_invokevirtual) && is_vfinal();
duke@435 200 // fall through
duke@435 201 case Bytecodes::_invokestatic:
duke@435 202 set_f1(method());
duke@435 203 byte_no = 1;
duke@435 204 break;
duke@435 205 default:
duke@435 206 ShouldNotReachHere();
duke@435 207 break;
duke@435 208 }
duke@435 209
duke@435 210 set_flags(as_flags(as_TosState(method->result_type()),
duke@435 211 method->is_final_method(),
duke@435 212 needs_vfinal_flag,
duke@435 213 false,
duke@435 214 change_to_virtual,
duke@435 215 true)|
duke@435 216 method()->size_of_parameters());
duke@435 217
duke@435 218 // Note: byte_no also appears in TemplateTable::resolve.
duke@435 219 if (byte_no == 1) {
duke@435 220 set_bytecode_1(invoke_code);
duke@435 221 } else if (byte_no == 2) {
duke@435 222 if (change_to_virtual) {
duke@435 223 // NOTE: THIS IS A HACK - BE VERY CAREFUL!!!
duke@435 224 //
duke@435 225 // Workaround for the case where we encounter an invokeinterface, but we
duke@435 226 // should really have an _invokevirtual since the resolved method is a
duke@435 227 // virtual method in java.lang.Object. This is a corner case in the spec
duke@435 228 // but is presumably legal. javac does not generate this code.
duke@435 229 //
duke@435 230 // We set bytecode_1() to _invokeinterface, because that is the
duke@435 231 // bytecode # used by the interpreter to see if it is resolved.
duke@435 232 // We set bytecode_2() to _invokevirtual.
duke@435 233 // See also interpreterRuntime.cpp. (8/25/2000)
duke@435 234 // Only set resolved for the invokeinterface case if method is public.
duke@435 235 // Otherwise, the method needs to be reresolved with caller for each
duke@435 236 // interface call.
duke@435 237 if (method->is_public()) set_bytecode_1(invoke_code);
duke@435 238 set_bytecode_2(Bytecodes::_invokevirtual);
duke@435 239 } else {
duke@435 240 set_bytecode_2(invoke_code);
duke@435 241 }
duke@435 242 } else {
duke@435 243 ShouldNotReachHere();
duke@435 244 }
duke@435 245 NOT_PRODUCT(verify(tty));
duke@435 246 }
duke@435 247
duke@435 248
duke@435 249 void ConstantPoolCacheEntry::set_interface_call(methodHandle method, int index) {
jrose@2015 250 assert(!is_secondary_entry(), "");
duke@435 251 klassOop interf = method->method_holder();
duke@435 252 assert(instanceKlass::cast(interf)->is_interface(), "must be an interface");
duke@435 253 set_f1(interf);
duke@435 254 set_f2(index);
duke@435 255 set_flags(as_flags(as_TosState(method->result_type()), method->is_final_method(), false, false, false, true) | method()->size_of_parameters());
duke@435 256 set_bytecode_1(Bytecodes::_invokeinterface);
duke@435 257 }
duke@435 258
duke@435 259
jrose@2015 260 void ConstantPoolCacheEntry::initialize_bootstrap_method_index_in_cache(int bsm_cache_index) {
jrose@2015 261 assert(!is_secondary_entry(), "only for JVM_CONSTANT_InvokeDynamic main entry");
jrose@2015 262 assert(_f2 == 0, "initialize once");
jrose@2015 263 assert(bsm_cache_index == (int)(u2)bsm_cache_index, "oob");
jrose@2015 264 set_f2(bsm_cache_index + constantPoolOopDesc::CPCACHE_INDEX_TAG);
jrose@2015 265 }
jrose@2015 266
jrose@2015 267 int ConstantPoolCacheEntry::bootstrap_method_index_in_cache() {
jrose@2015 268 assert(!is_secondary_entry(), "only for JVM_CONSTANT_InvokeDynamic main entry");
jrose@2015 269 intptr_t bsm_cache_index = (intptr_t) _f2 - constantPoolOopDesc::CPCACHE_INDEX_TAG;
jrose@2015 270 assert(bsm_cache_index == (intptr_t)(u2)bsm_cache_index, "oob");
jrose@2015 271 return (int) bsm_cache_index;
jrose@2015 272 }
jrose@2015 273
twisti@2811 274 void ConstantPoolCacheEntry::set_dynamic_call(Handle call_site, methodHandle signature_invoker) {
jrose@2015 275 assert(is_secondary_entry(), "");
twisti@2811 276 // NOTE: it's important that all other values are set before f1 is
twisti@2811 277 // set since some users short circuit on f1 being set
twisti@2811 278 // (i.e. non-null) and that may result in uninitialized values for
twisti@2811 279 // other racing threads (e.g. flags).
jrose@1862 280 int param_size = signature_invoker->size_of_parameters();
jrose@1494 281 assert(param_size >= 1, "method argument size must include MH.this");
twisti@2811 282 param_size -= 1; // do not count MH.this; it is not stacked for invokedynamic
jrose@1862 283 bool is_final = true;
jrose@1862 284 assert(signature_invoker->is_final_method(), "is_final");
twisti@2811 285 int flags = as_flags(as_TosState(signature_invoker->result_type()), is_final, false, false, false, true) | param_size;
twisti@2811 286 assert(_flags == 0 || _flags == flags, "flags should be the same");
twisti@2811 287 set_flags(flags);
jrose@1161 288 // do not do set_bytecode on a secondary CP cache entry
jrose@1161 289 //set_bytecode_1(Bytecodes::_invokedynamic);
twisti@2811 290 set_f1_if_null_atomic(call_site()); // This must be the last one to set (see NOTE above)!
jrose@1161 291 }
jrose@1161 292
jrose@1161 293
jrose@2982 294 methodOop ConstantPoolCacheEntry::get_method_if_resolved(Bytecodes::Code invoke_code, constantPoolHandle cpool) {
jrose@2982 295 assert(invoke_code > (Bytecodes::Code)0, "bad query");
jrose@2982 296 if (is_secondary_entry()) {
jrose@2982 297 return cpool->cache()->entry_at(main_entry_index())->get_method_if_resolved(invoke_code, cpool);
jrose@2982 298 }
jrose@2982 299 // Decode the action of set_method and set_interface_call
jrose@2982 300 if (bytecode_1() == invoke_code) {
jrose@2982 301 oop f1 = _f1;
jrose@2982 302 if (f1 != NULL) {
jrose@2982 303 switch (invoke_code) {
jrose@2982 304 case Bytecodes::_invokeinterface:
jrose@2982 305 assert(f1->is_klass(), "");
jrose@2982 306 return klassItable::method_for_itable_index(klassOop(f1), (int) f2());
jrose@2982 307 case Bytecodes::_invokestatic:
jrose@2982 308 case Bytecodes::_invokespecial:
jrose@2982 309 assert(f1->is_method(), "");
jrose@2982 310 return methodOop(f1);
jrose@2982 311 }
jrose@2982 312 }
jrose@2982 313 }
jrose@2982 314 if (bytecode_2() == invoke_code) {
jrose@2982 315 switch (invoke_code) {
jrose@2982 316 case Bytecodes::_invokevirtual:
jrose@2982 317 if (is_vfinal()) {
jrose@2982 318 // invokevirtual
jrose@2982 319 methodOop m = methodOop((intptr_t) f2());
jrose@2982 320 assert(m->is_method(), "");
jrose@2982 321 return m;
jrose@2982 322 } else {
jrose@2982 323 int holder_index = cpool->uncached_klass_ref_index_at(constant_pool_index());
jrose@2982 324 if (cpool->tag_at(holder_index).is_klass()) {
jrose@2982 325 klassOop klass = cpool->resolved_klass_at(holder_index);
jrose@2982 326 if (!Klass::cast(klass)->oop_is_instance())
jrose@2982 327 klass = SystemDictionary::Object_klass();
jrose@2982 328 return instanceKlass::cast(klass)->method_at_vtable((int) f2());
jrose@2982 329 }
jrose@2982 330 }
jrose@2982 331 }
jrose@2982 332 }
jrose@2982 333 return NULL;
jrose@2982 334 }
jrose@2982 335
jrose@2982 336
jrose@2982 337
duke@435 338 class LocalOopClosure: public OopClosure {
duke@435 339 private:
duke@435 340 void (*_f)(oop*);
duke@435 341
duke@435 342 public:
duke@435 343 LocalOopClosure(void f(oop*)) { _f = f; }
duke@435 344 virtual void do_oop(oop* o) { _f(o); }
coleenp@548 345 virtual void do_oop(narrowOop *o) { ShouldNotReachHere(); }
duke@435 346 };
duke@435 347
duke@435 348
duke@435 349 void ConstantPoolCacheEntry::oops_do(void f(oop*)) {
duke@435 350 LocalOopClosure blk(f);
duke@435 351 oop_iterate(&blk);
duke@435 352 }
duke@435 353
duke@435 354
duke@435 355 void ConstantPoolCacheEntry::oop_iterate(OopClosure* blk) {
duke@435 356 assert(in_words(size()) == 4, "check code below - may need adjustment");
duke@435 357 // field[1] is always oop or NULL
duke@435 358 blk->do_oop((oop*)&_f1);
duke@435 359 if (is_vfinal()) {
duke@435 360 blk->do_oop((oop*)&_f2);
duke@435 361 }
duke@435 362 }
duke@435 363
duke@435 364
duke@435 365 void ConstantPoolCacheEntry::oop_iterate_m(OopClosure* blk, MemRegion mr) {
duke@435 366 assert(in_words(size()) == 4, "check code below - may need adjustment");
duke@435 367 // field[1] is always oop or NULL
duke@435 368 if (mr.contains((oop *)&_f1)) blk->do_oop((oop*)&_f1);
duke@435 369 if (is_vfinal()) {
duke@435 370 if (mr.contains((oop *)&_f2)) blk->do_oop((oop*)&_f2);
duke@435 371 }
duke@435 372 }
duke@435 373
duke@435 374
duke@435 375 void ConstantPoolCacheEntry::follow_contents() {
duke@435 376 assert(in_words(size()) == 4, "check code below - may need adjustment");
duke@435 377 // field[1] is always oop or NULL
duke@435 378 MarkSweep::mark_and_push((oop*)&_f1);
duke@435 379 if (is_vfinal()) {
duke@435 380 MarkSweep::mark_and_push((oop*)&_f2);
duke@435 381 }
duke@435 382 }
duke@435 383
duke@435 384 #ifndef SERIALGC
duke@435 385 void ConstantPoolCacheEntry::follow_contents(ParCompactionManager* cm) {
duke@435 386 assert(in_words(size()) == 4, "check code below - may need adjustment");
duke@435 387 // field[1] is always oop or NULL
duke@435 388 PSParallelCompact::mark_and_push(cm, (oop*)&_f1);
duke@435 389 if (is_vfinal()) {
duke@435 390 PSParallelCompact::mark_and_push(cm, (oop*)&_f2);
duke@435 391 }
duke@435 392 }
duke@435 393 #endif // SERIALGC
duke@435 394
duke@435 395 void ConstantPoolCacheEntry::adjust_pointers() {
duke@435 396 assert(in_words(size()) == 4, "check code below - may need adjustment");
duke@435 397 // field[1] is always oop or NULL
duke@435 398 MarkSweep::adjust_pointer((oop*)&_f1);
duke@435 399 if (is_vfinal()) {
duke@435 400 MarkSweep::adjust_pointer((oop*)&_f2);
duke@435 401 }
duke@435 402 }
duke@435 403
duke@435 404 #ifndef SERIALGC
duke@435 405 void ConstantPoolCacheEntry::update_pointers() {
duke@435 406 assert(in_words(size()) == 4, "check code below - may need adjustment");
duke@435 407 // field[1] is always oop or NULL
duke@435 408 PSParallelCompact::adjust_pointer((oop*)&_f1);
duke@435 409 if (is_vfinal()) {
duke@435 410 PSParallelCompact::adjust_pointer((oop*)&_f2);
duke@435 411 }
duke@435 412 }
duke@435 413 #endif // SERIALGC
duke@435 414
duke@435 415 // RedefineClasses() API support:
duke@435 416 // If this constantPoolCacheEntry refers to old_method then update it
duke@435 417 // to refer to new_method.
duke@435 418 bool ConstantPoolCacheEntry::adjust_method_entry(methodOop old_method,
duke@435 419 methodOop new_method, bool * trace_name_printed) {
duke@435 420
duke@435 421 if (is_vfinal()) {
duke@435 422 // virtual and final so f2() contains method ptr instead of vtable index
duke@435 423 if (f2() == (intptr_t)old_method) {
duke@435 424 // match old_method so need an update
duke@435 425 _f2 = (intptr_t)new_method;
duke@435 426 if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
duke@435 427 if (!(*trace_name_printed)) {
duke@435 428 // RC_TRACE_MESG macro has an embedded ResourceMark
duke@435 429 RC_TRACE_MESG(("adjust: name=%s",
duke@435 430 Klass::cast(old_method->method_holder())->external_name()));
duke@435 431 *trace_name_printed = true;
duke@435 432 }
duke@435 433 // RC_TRACE macro has an embedded ResourceMark
duke@435 434 RC_TRACE(0x00400000, ("cpc vf-entry update: %s(%s)",
duke@435 435 new_method->name()->as_C_string(),
duke@435 436 new_method->signature()->as_C_string()));
duke@435 437 }
duke@435 438
duke@435 439 return true;
duke@435 440 }
duke@435 441
duke@435 442 // f1() is not used with virtual entries so bail out
duke@435 443 return false;
duke@435 444 }
duke@435 445
duke@435 446 if ((oop)_f1 == NULL) {
duke@435 447 // NULL f1() means this is a virtual entry so bail out
duke@435 448 // We are assuming that the vtable index does not need change.
duke@435 449 return false;
duke@435 450 }
duke@435 451
duke@435 452 if ((oop)_f1 == old_method) {
duke@435 453 _f1 = new_method;
duke@435 454 if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
duke@435 455 if (!(*trace_name_printed)) {
duke@435 456 // RC_TRACE_MESG macro has an embedded ResourceMark
duke@435 457 RC_TRACE_MESG(("adjust: name=%s",
duke@435 458 Klass::cast(old_method->method_holder())->external_name()));
duke@435 459 *trace_name_printed = true;
duke@435 460 }
duke@435 461 // RC_TRACE macro has an embedded ResourceMark
duke@435 462 RC_TRACE(0x00400000, ("cpc entry update: %s(%s)",
duke@435 463 new_method->name()->as_C_string(),
duke@435 464 new_method->signature()->as_C_string()));
duke@435 465 }
duke@435 466
duke@435 467 return true;
duke@435 468 }
duke@435 469
duke@435 470 return false;
duke@435 471 }
duke@435 472
duke@435 473 bool ConstantPoolCacheEntry::is_interesting_method_entry(klassOop k) {
duke@435 474 if (!is_method_entry()) {
duke@435 475 // not a method entry so not interesting by default
duke@435 476 return false;
duke@435 477 }
duke@435 478
duke@435 479 methodOop m = NULL;
duke@435 480 if (is_vfinal()) {
duke@435 481 // virtual and final so _f2 contains method ptr instead of vtable index
duke@435 482 m = (methodOop)_f2;
duke@435 483 } else if ((oop)_f1 == NULL) {
duke@435 484 // NULL _f1 means this is a virtual entry so also not interesting
duke@435 485 return false;
duke@435 486 } else {
duke@435 487 if (!((oop)_f1)->is_method()) {
duke@435 488 // _f1 can also contain a klassOop for an interface
duke@435 489 return false;
duke@435 490 }
duke@435 491 m = (methodOop)_f1;
duke@435 492 }
duke@435 493
duke@435 494 assert(m != NULL && m->is_method(), "sanity check");
duke@435 495 if (m == NULL || !m->is_method() || m->method_holder() != k) {
duke@435 496 // robustness for above sanity checks or method is not in
duke@435 497 // the interesting class
duke@435 498 return false;
duke@435 499 }
duke@435 500
duke@435 501 // the method is in the interesting class so the entry is interesting
duke@435 502 return true;
duke@435 503 }
duke@435 504
duke@435 505 void ConstantPoolCacheEntry::print(outputStream* st, int index) const {
duke@435 506 // print separator
dholmes@3601 507 if (index == 0) st->print_cr(" -------------");
duke@435 508 // print entry
dholmes@3601 509 st->print("%3d ("PTR_FORMAT") ", index, (intptr_t)this);
jrose@1161 510 if (is_secondary_entry())
dholmes@3601 511 st->print_cr("[%5d|secondary]", main_entry_index());
jrose@1161 512 else
dholmes@3601 513 st->print_cr("[%02x|%02x|%5d]", bytecode_2(), bytecode_1(), constant_pool_index());
dholmes@3601 514 st->print_cr(" [ "PTR_FORMAT"]", (intptr_t)(oop)_f1);
dholmes@3601 515 st->print_cr(" [ "PTR_FORMAT"]", (intptr_t)_f2);
dholmes@3601 516 st->print_cr(" [ "PTR_FORMAT"]", (intptr_t)_flags);
dholmes@3601 517 st->print_cr(" -------------");
duke@435 518 }
duke@435 519
duke@435 520 void ConstantPoolCacheEntry::verify(outputStream* st) const {
duke@435 521 // not implemented yet
duke@435 522 }
duke@435 523
duke@435 524 // Implementation of ConstantPoolCache
duke@435 525
duke@435 526 void constantPoolCacheOopDesc::initialize(intArray& inverse_index_map) {
duke@435 527 assert(inverse_index_map.length() == length(), "inverse index map must have same length as cache");
jrose@1494 528 for (int i = 0; i < length(); i++) {
jrose@1494 529 ConstantPoolCacheEntry* e = entry_at(i);
jrose@1494 530 int original_index = inverse_index_map[i];
jrose@1494 531 if ((original_index & Rewriter::_secondary_entry_tag) != 0) {
jrose@1494 532 int main_index = (original_index - Rewriter::_secondary_entry_tag);
jrose@1494 533 assert(!entry_at(main_index)->is_secondary_entry(), "valid main index");
jrose@1494 534 e->initialize_secondary_entry(main_index);
jrose@1494 535 } else {
jrose@1494 536 e->initialize_entry(original_index);
jrose@1494 537 }
jrose@1494 538 assert(entry_at(i) == e, "sanity");
jrose@1494 539 }
duke@435 540 }
duke@435 541
duke@435 542 // RedefineClasses() API support:
duke@435 543 // If any entry of this constantPoolCache points to any of
duke@435 544 // old_methods, replace it with the corresponding new_method.
duke@435 545 void constantPoolCacheOopDesc::adjust_method_entries(methodOop* old_methods, methodOop* new_methods,
duke@435 546 int methods_length, bool * trace_name_printed) {
duke@435 547
duke@435 548 if (methods_length == 0) {
duke@435 549 // nothing to do if there are no methods
duke@435 550 return;
duke@435 551 }
duke@435 552
duke@435 553 // get shorthand for the interesting class
duke@435 554 klassOop old_holder = old_methods[0]->method_holder();
duke@435 555
duke@435 556 for (int i = 0; i < length(); i++) {
duke@435 557 if (!entry_at(i)->is_interesting_method_entry(old_holder)) {
duke@435 558 // skip uninteresting methods
duke@435 559 continue;
duke@435 560 }
duke@435 561
duke@435 562 // The constantPoolCache contains entries for several different
duke@435 563 // things, but we only care about methods. In fact, we only care
duke@435 564 // about methods in the same class as the one that contains the
duke@435 565 // old_methods. At this point, we have an interesting entry.
duke@435 566
duke@435 567 for (int j = 0; j < methods_length; j++) {
duke@435 568 methodOop old_method = old_methods[j];
duke@435 569 methodOop new_method = new_methods[j];
duke@435 570
duke@435 571 if (entry_at(i)->adjust_method_entry(old_method, new_method,
duke@435 572 trace_name_printed)) {
duke@435 573 // current old_method matched this entry and we updated it so
duke@435 574 // break out and get to the next interesting entry if there one
duke@435 575 break;
duke@435 576 }
duke@435 577 }
duke@435 578 }
duke@435 579 }

mercurial