1.1 --- a/src/share/vm/oops/cpCacheOop.hpp Fri Oct 30 10:12:52 2009 -0700 1.2 +++ b/src/share/vm/oops/cpCacheOop.hpp Fri Oct 30 16:22:59 2009 -0700 1.3 @@ -154,7 +154,8 @@ 1.4 }; 1.5 1.6 // Initialization 1.7 - void set_initial_state(int index); // sets entry to initial state 1.8 + void initialize_entry(int original_index); // initialize primary entry 1.9 + void initialize_secondary_entry(int main_index); // initialize secondary entry 1.10 1.11 void set_field( // sets entry to resolved field state 1.12 Bytecodes::Code get_code, // the bytecode used for reading the field 1.13 @@ -251,6 +252,7 @@ 1.14 1.15 // Code generation support 1.16 static WordSize size() { return in_WordSize(sizeof(ConstantPoolCacheEntry) / HeapWordSize); } 1.17 + static ByteSize size_in_bytes() { return in_ByteSize(sizeof(ConstantPoolCacheEntry)); } 1.18 static ByteSize indices_offset() { return byte_offset_of(ConstantPoolCacheEntry, _indices); } 1.19 static ByteSize f1_offset() { return byte_offset_of(ConstantPoolCacheEntry, _f1); } 1.20 static ByteSize f2_offset() { return byte_offset_of(ConstantPoolCacheEntry, _f2); } 1.21 @@ -321,6 +323,7 @@ 1.22 ConstantPoolCacheEntry* base() const { return (ConstantPoolCacheEntry*)((address)this + in_bytes(base_offset())); } 1.23 1.24 friend class constantPoolCacheKlass; 1.25 + friend class ConstantPoolCacheEntry; 1.26 1.27 public: 1.28 // Initialization 1.29 @@ -329,7 +332,8 @@ 1.30 // Secondary indexes. 1.31 // They must look completely different from normal indexes. 1.32 // The main reason is that byte swapping is sometimes done on normal indexes. 1.33 - // Also, it is helpful for debugging to tell the two apart. 1.34 + // Also, some of the CP accessors do different things for secondary indexes. 1.35 + // Finally, it is helpful for debugging to tell the two apart. 1.36 static bool is_secondary_index(int i) { return (i < 0); } 1.37 static int decode_secondary_index(int i) { assert(is_secondary_index(i), ""); return ~i; } 1.38 static int encode_secondary_index(int i) { assert(!is_secondary_index(i), ""); return ~i; } 1.39 @@ -337,18 +341,35 @@ 1.40 // Accessors 1.41 void set_constant_pool(constantPoolOop pool) { oop_store_without_check((oop*)&_constant_pool, (oop)pool); } 1.42 constantPoolOop constant_pool() const { return _constant_pool; } 1.43 - ConstantPoolCacheEntry* entry_at(int i) const { assert(0 <= i && i < length(), "index out of bounds"); return base() + i; } 1.44 + // Fetches the entry at the given index. 1.45 + // The entry may be either primary or secondary. 1.46 + // In either case the index must not be encoded or byte-swapped in any way. 1.47 + ConstantPoolCacheEntry* entry_at(int i) const { 1.48 + assert(0 <= i && i < length(), "index out of bounds"); 1.49 + return base() + i; 1.50 + } 1.51 + // Fetches the secondary entry referred to by index. 1.52 + // The index may be a secondary index, and must not be byte-swapped. 1.53 + ConstantPoolCacheEntry* secondary_entry_at(int i) const { 1.54 + int raw_index = i; 1.55 + if (is_secondary_index(i)) { // correct these on the fly 1.56 + raw_index = decode_secondary_index(i); 1.57 + } 1.58 + assert(entry_at(raw_index)->is_secondary_entry(), "not a secondary entry"); 1.59 + return entry_at(raw_index); 1.60 + } 1.61 + // Given a primary or secondary index, fetch the corresponding primary entry. 1.62 + // Indirect through the secondary entry, if the index is encoded as a secondary index. 1.63 + // The index must not be byte-swapped. 1.64 ConstantPoolCacheEntry* main_entry_at(int i) const { 1.65 - ConstantPoolCacheEntry* e; 1.66 + int primary_index = i; 1.67 if (is_secondary_index(i)) { 1.68 // run through an extra level of indirection: 1.69 - i = decode_secondary_index(i); 1.70 - e = entry_at(i); 1.71 - i = e->main_entry_index(); 1.72 + int raw_index = decode_secondary_index(i); 1.73 + primary_index = entry_at(raw_index)->main_entry_index(); 1.74 } 1.75 - e = entry_at(i); 1.76 - assert(!e->is_secondary_entry(), "only one level of indirection"); 1.77 - return e; 1.78 + assert(!entry_at(primary_index)->is_secondary_entry(), "only one level of indirection"); 1.79 + return entry_at(primary_index); 1.80 } 1.81 1.82 // GC support 1.83 @@ -359,6 +380,12 @@ 1.84 1.85 // Code generation 1.86 static ByteSize base_offset() { return in_ByteSize(sizeof(constantPoolCacheOopDesc)); } 1.87 + static ByteSize entry_offset(int raw_index) { 1.88 + int index = raw_index; 1.89 + if (is_secondary_index(raw_index)) 1.90 + index = decode_secondary_index(raw_index); 1.91 + return (base_offset() + ConstantPoolCacheEntry::size_in_bytes() * index); 1.92 + } 1.93 1.94 // RedefineClasses() API support: 1.95 // If any entry of this constantPoolCache points to any of