114 115 enum { 116 _has_preresolution = 1, // Flags 117 _on_stack = 2, 118 _is_shared = 4, 119 _has_dynamic_constant = 8 120 }; 121 122 int _flags; // old fashioned bit twiddling 123 int _length; // number of elements in the array 124 125 union { 126 // set for CDS to restore resolved references 127 int _resolved_reference_length; 128 // keeps version number for redefined classes (used in backtrace) 129 int _version; 130 } _saved; 131 132 void set_tags(Array<u1>* tags) { _tags = tags; } 133 void tag_at_put(int which, jbyte t) { tags()->at_put(which, t); } 134 void release_tag_at_put(int which, jbyte t) { tags()->release_at_put(which, t); } 135 136 u1* tag_addr_at(int which) const { return tags()->adr_at(which); } 137 138 void set_operands(Array<u2>* operands) { _operands = operands; } 139 140 int flags() const { return _flags; } 141 void set_flags(int f) { _flags = f; } 142 143 private: 144 intptr_t* base() const { return (intptr_t*) (((char*) this) + sizeof(ConstantPool)); } 145 146 CPSlot slot_at(int which) const { 147 assert(is_within_bounds(which), "index out of bounds"); 148 assert(!tag_at(which).is_unresolved_klass() && !tag_at(which).is_unresolved_klass_in_error(), "Corrupted constant pool"); 149 // Uses volatile because the klass slot changes without a lock. 150 intptr_t adr = OrderAccess::load_acquire(obj_at_addr(which)); 151 assert(adr != 0 || which == 0, "cp entry for klass should not be zero"); 152 return CPSlot(adr); 153 } 154 155 void slot_at_put(int which, CPSlot s) const { 156 assert(is_within_bounds(which), "index out of bounds"); 157 assert(s.value() != 0, "Caught something"); 158 *(intptr_t*)&base()[which] = s.value(); 159 } 160 intptr_t* obj_at_addr(int which) const { 161 assert(is_within_bounds(which), "index out of bounds"); 162 return (intptr_t*) &base()[which]; 163 } 164 165 jint* int_at_addr(int which) const { 166 assert(is_within_bounds(which), "index out of bounds"); 167 return (jint*) &base()[which]; 168 } 169 170 jlong* long_at_addr(int which) const { 171 assert(is_within_bounds(which), "index out of bounds"); 172 return (jlong*) &base()[which]; 173 } 363 *int_at_addr(which) = ((jint) name_and_type_index<<16) | class_index; 364 } 365 366 void method_at_put(int which, int class_index, int name_and_type_index) { 367 tag_at_put(which, JVM_CONSTANT_Methodref); 368 *int_at_addr(which) = ((jint) name_and_type_index<<16) | class_index; 369 } 370 371 void interface_method_at_put(int which, int class_index, int name_and_type_index) { 372 tag_at_put(which, JVM_CONSTANT_InterfaceMethodref); 373 *int_at_addr(which) = ((jint) name_and_type_index<<16) | class_index; // Not so nice 374 } 375 376 void name_and_type_at_put(int which, int name_index, int signature_index) { 377 tag_at_put(which, JVM_CONSTANT_NameAndType); 378 *int_at_addr(which) = ((jint) signature_index<<16) | name_index; // Not so nice 379 } 380 381 // Tag query 382 383 constantTag tag_at(int which) const { return (constantTag)tags()->at_acquire(which); } 384 385 // Fetching constants 386 387 Klass* klass_at(int which, TRAPS) { 388 constantPoolHandle h_this(THREAD, this); 389 return klass_at_impl(h_this, which, true, THREAD); 390 } 391 392 // Version of klass_at that doesn't save the resolution error, called during deopt 393 Klass* klass_at_ignore_error(int which, TRAPS) { 394 constantPoolHandle h_this(THREAD, this); 395 return klass_at_impl(h_this, which, false, THREAD); 396 } 397 398 CPKlassSlot klass_slot_at(int which) const { 399 assert(tag_at(which).is_unresolved_klass() || tag_at(which).is_klass(), 400 "Corrupted constant pool"); 401 int value = *int_at_addr(which); 402 int name_index = extract_high_short_from_int(value); 403 int resolved_klass_index = extract_low_short_from_int(value); 404 return CPKlassSlot(name_index, resolved_klass_index); 405 } 406 407 Symbol* klass_name_at(int which) const; // Returns the name, w/o resolving. 408 int klass_name_index_at(int which) const { 409 return klass_slot_at(which).name_index(); 410 } 411 412 Klass* resolved_klass_at(int which) const { // Used by Compiler 413 guarantee(tag_at(which).is_klass(), "Corrupted constant pool"); 414 // Must do an acquire here in case another thread resolved the klass 415 // behind our back, lest we later load stale values thru the oop. 416 CPKlassSlot kslot = klass_slot_at(which); 417 assert(tag_at(kslot.name_index()).is_symbol(), "sanity"); 418 419 Klass** adr = resolved_klasses()->adr_at(kslot.resolved_klass_index()); 420 return OrderAccess::load_acquire(adr); 421 } 422 423 // RedefineClasses() API support: 424 Symbol* klass_at_noresolve(int which) { return klass_name_at(which); } 425 void temp_unresolved_klass_at_put(int which, int name_index) { 426 // Used only during constant pool merging for class redefinition. The resolved klass index 427 // will be initialized later by a call to initialize_unresolved_klasses(). 428 unresolved_klass_at_put(which, name_index, CPKlassSlot::_temp_resolved_klass_index); 429 } 430 431 jint int_at(int which) { 432 assert(tag_at(which).is_int(), "Corrupted constant pool"); 433 return *int_at_addr(which); 434 } 435 436 jlong long_at(int which) { 437 assert(tag_at(which).is_long(), "Corrupted constant pool"); 438 // return *long_at_addr(which); 439 u8 tmp = Bytes::get_native_u8((address)&base()[which]); 440 return *((jlong*)&tmp); 441 } 458 459 oop string_at(int which, int obj_index, TRAPS) { 460 constantPoolHandle h_this(THREAD, this); 461 return string_at_impl(h_this, which, obj_index, THREAD); 462 } 463 oop string_at(int which, TRAPS) { 464 int obj_index = cp_to_object_index(which); 465 return string_at(which, obj_index, THREAD); 466 } 467 468 // Version that can be used before string oop array is created. 469 oop uncached_string_at(int which, TRAPS); 470 471 // A "pseudo-string" is an non-string oop that has found its way into 472 // a String entry. 473 // This can happen if the user patches a live 474 // object into a CONSTANT_String entry of an anonymous class. 475 // Method oops internally created for method handles may also 476 // use pseudo-strings to link themselves to related metaobjects. 477 478 bool is_pseudo_string_at(int which) { 479 assert(tag_at(which).is_string(), "Corrupted constant pool"); 480 return slot_at(which).is_pseudo_string(); 481 } 482 483 oop pseudo_string_at(int which, int obj_index) { 484 assert(is_pseudo_string_at(which), "must be a pseudo-string"); 485 oop s = resolved_references()->obj_at(obj_index); 486 return s; 487 } 488 489 oop pseudo_string_at(int which) { 490 assert(is_pseudo_string_at(which), "must be a pseudo-string"); 491 int obj_index = cp_to_object_index(which); 492 oop s = resolved_references()->obj_at(obj_index); 493 return s; 494 } 495 496 void pseudo_string_at_put(int which, int obj_index, oop x) { 497 assert(tag_at(which).is_string(), "Corrupted constant pool"); 498 Symbol* sym = unresolved_string_at(which); 499 slot_at_put(which, CPSlot(sym, CPSlot::_pseudo_bit)); 500 string_at_put(which, obj_index, x); // this works just fine 501 } 502 503 // only called when we are sure a string entry is already resolved (via an 504 // earlier string_at call. 505 oop resolved_string_at(int which) { 506 assert(tag_at(which).is_string(), "Corrupted constant pool"); 507 // Must do an acquire here in case another thread resolved the klass 508 // behind our back, lest we later load stale values thru the oop. 509 // we might want a volatile_obj_at in ObjArrayKlass. 510 int obj_index = cp_to_object_index(which); 511 return resolved_references()->obj_at(obj_index); 512 } 513 514 Symbol* unresolved_string_at(int which) { | 114 115 enum { 116 _has_preresolution = 1, // Flags 117 _on_stack = 2, 118 _is_shared = 4, 119 _has_dynamic_constant = 8 120 }; 121 122 int _flags; // old fashioned bit twiddling 123 int _length; // number of elements in the array 124 125 union { 126 // set for CDS to restore resolved references 127 int _resolved_reference_length; 128 // keeps version number for redefined classes (used in backtrace) 129 int _version; 130 } _saved; 131 132 void set_tags(Array<u1>* tags) { _tags = tags; } 133 void tag_at_put(int which, jbyte t) { tags()->at_put(which, t); } 134 void release_tag_at_put(int which, jbyte t); 135 136 u1* tag_addr_at(int which) const { return tags()->adr_at(which); } 137 138 void set_operands(Array<u2>* operands) { _operands = operands; } 139 140 int flags() const { return _flags; } 141 void set_flags(int f) { _flags = f; } 142 143 private: 144 intptr_t* base() const { return (intptr_t*) (((char*) this) + sizeof(ConstantPool)); } 145 146 CPSlot slot_at(int which) const; 147 148 void slot_at_put(int which, CPSlot s) const { 149 assert(is_within_bounds(which), "index out of bounds"); 150 assert(s.value() != 0, "Caught something"); 151 *(intptr_t*)&base()[which] = s.value(); 152 } 153 intptr_t* obj_at_addr(int which) const { 154 assert(is_within_bounds(which), "index out of bounds"); 155 return (intptr_t*) &base()[which]; 156 } 157 158 jint* int_at_addr(int which) const { 159 assert(is_within_bounds(which), "index out of bounds"); 160 return (jint*) &base()[which]; 161 } 162 163 jlong* long_at_addr(int which) const { 164 assert(is_within_bounds(which), "index out of bounds"); 165 return (jlong*) &base()[which]; 166 } 356 *int_at_addr(which) = ((jint) name_and_type_index<<16) | class_index; 357 } 358 359 void method_at_put(int which, int class_index, int name_and_type_index) { 360 tag_at_put(which, JVM_CONSTANT_Methodref); 361 *int_at_addr(which) = ((jint) name_and_type_index<<16) | class_index; 362 } 363 364 void interface_method_at_put(int which, int class_index, int name_and_type_index) { 365 tag_at_put(which, JVM_CONSTANT_InterfaceMethodref); 366 *int_at_addr(which) = ((jint) name_and_type_index<<16) | class_index; // Not so nice 367 } 368 369 void name_and_type_at_put(int which, int name_index, int signature_index) { 370 tag_at_put(which, JVM_CONSTANT_NameAndType); 371 *int_at_addr(which) = ((jint) signature_index<<16) | name_index; // Not so nice 372 } 373 374 // Tag query 375 376 constantTag tag_at(int which) const; 377 378 // Fetching constants 379 380 Klass* klass_at(int which, TRAPS) { 381 constantPoolHandle h_this(THREAD, this); 382 return klass_at_impl(h_this, which, true, THREAD); 383 } 384 385 // Version of klass_at that doesn't save the resolution error, called during deopt 386 Klass* klass_at_ignore_error(int which, TRAPS) { 387 constantPoolHandle h_this(THREAD, this); 388 return klass_at_impl(h_this, which, false, THREAD); 389 } 390 391 CPKlassSlot klass_slot_at(int which) const { 392 assert(tag_at(which).is_unresolved_klass() || tag_at(which).is_klass(), 393 "Corrupted constant pool"); 394 int value = *int_at_addr(which); 395 int name_index = extract_high_short_from_int(value); 396 int resolved_klass_index = extract_low_short_from_int(value); 397 return CPKlassSlot(name_index, resolved_klass_index); 398 } 399 400 Symbol* klass_name_at(int which) const; // Returns the name, w/o resolving. 401 int klass_name_index_at(int which) const { 402 return klass_slot_at(which).name_index(); 403 } 404 405 Klass* resolved_klass_at(int which) const; // Used by Compiler 406 407 // RedefineClasses() API support: 408 Symbol* klass_at_noresolve(int which) { return klass_name_at(which); } 409 void temp_unresolved_klass_at_put(int which, int name_index) { 410 // Used only during constant pool merging for class redefinition. The resolved klass index 411 // will be initialized later by a call to initialize_unresolved_klasses(). 412 unresolved_klass_at_put(which, name_index, CPKlassSlot::_temp_resolved_klass_index); 413 } 414 415 jint int_at(int which) { 416 assert(tag_at(which).is_int(), "Corrupted constant pool"); 417 return *int_at_addr(which); 418 } 419 420 jlong long_at(int which) { 421 assert(tag_at(which).is_long(), "Corrupted constant pool"); 422 // return *long_at_addr(which); 423 u8 tmp = Bytes::get_native_u8((address)&base()[which]); 424 return *((jlong*)&tmp); 425 } 442 443 oop string_at(int which, int obj_index, TRAPS) { 444 constantPoolHandle h_this(THREAD, this); 445 return string_at_impl(h_this, which, obj_index, THREAD); 446 } 447 oop string_at(int which, TRAPS) { 448 int obj_index = cp_to_object_index(which); 449 return string_at(which, obj_index, THREAD); 450 } 451 452 // Version that can be used before string oop array is created. 453 oop uncached_string_at(int which, TRAPS); 454 455 // A "pseudo-string" is an non-string oop that has found its way into 456 // a String entry. 457 // This can happen if the user patches a live 458 // object into a CONSTANT_String entry of an anonymous class. 459 // Method oops internally created for method handles may also 460 // use pseudo-strings to link themselves to related metaobjects. 461 462 bool is_pseudo_string_at(int which); 463 464 oop pseudo_string_at(int which, int obj_index); 465 466 oop pseudo_string_at(int which); 467 468 void pseudo_string_at_put(int which, int obj_index, oop x) { 469 assert(tag_at(which).is_string(), "Corrupted constant pool"); 470 Symbol* sym = unresolved_string_at(which); 471 slot_at_put(which, CPSlot(sym, CPSlot::_pseudo_bit)); 472 string_at_put(which, obj_index, x); // this works just fine 473 } 474 475 // only called when we are sure a string entry is already resolved (via an 476 // earlier string_at call. 477 oop resolved_string_at(int which) { 478 assert(tag_at(which).is_string(), "Corrupted constant pool"); 479 // Must do an acquire here in case another thread resolved the klass 480 // behind our back, lest we later load stale values thru the oop. 481 // we might want a volatile_obj_at in ObjArrayKlass. 482 int obj_index = cp_to_object_index(which); 483 return resolved_references()->obj_at(obj_index); 484 } 485 486 Symbol* unresolved_string_at(int which) { |