< prev index next >

src/hotspot/share/prims/jvmtiTagMap.cpp

Print this page




  87   JvmtiTagHashmapEntry(oop object, jlong tag) { init(object, tag); }
  88 
  89  public:
  90 
  91   // accessor methods
  92   inline oop* object_addr() { return &_object; }
  93   inline oop object()       { return NativeAccess<ON_PHANTOM_OOP_REF>::oop_load(object_addr()); }
  94   // Peek at the object without keeping it alive. The returned object must be
  95   // kept alive using a normal access if it leaks out of a thread transition from VM.
  96   inline oop object_peek()  {
  97     return NativeAccess<ON_PHANTOM_OOP_REF | AS_NO_KEEPALIVE>::oop_load(object_addr());
  98   }
  99   inline jlong tag() const  { return _tag; }
 100 
 101   inline void set_tag(jlong tag) {
 102     assert(tag != 0, "can't be zero");
 103     _tag = tag;
 104   }
 105 
 106   inline bool equals(oop object) {
 107     return object == object_peek();
 108   }
 109 
 110   inline JvmtiTagHashmapEntry* next() const        { return _next; }
 111   inline void set_next(JvmtiTagHashmapEntry* next) { _next = next; }
 112 };
 113 
 114 
 115 // JvmtiTagHashmap
 116 //
 117 // A hashmap is essentially a table of pointers to entries. Entries
 118 // are hashed to a location, or position in the table, and then
 119 // chained from that location. The "key" for hashing is address of
 120 // the object, or oop. The "value" is the tag value.
 121 //
 122 // A hashmap maintains a count of the number entries in the hashmap
 123 // and resizes if the number of entries exceeds a given threshold.
 124 // The threshold is specified as a percentage of the size - for
 125 // example a threshold of 0.75 will trigger the hashmap to resize
 126 // if the number of entries is >75% of table size.
 127 //


 168     _load_factor = load_factor;
 169     _resize_threshold = (int)(_load_factor * _size);
 170     _resizing_enabled = true;
 171     size_t s = initial_size * sizeof(JvmtiTagHashmapEntry*);
 172     _table = (JvmtiTagHashmapEntry**)os::malloc(s, mtInternal);
 173     if (_table == NULL) {
 174       vm_exit_out_of_memory(s, OOM_MALLOC_ERROR,
 175         "unable to allocate initial hashtable for jvmti object tags");
 176     }
 177     for (int i=0; i<initial_size; i++) {
 178       _table[i] = NULL;
 179     }
 180   }
 181 
 182   // hash a given key (oop) with the specified size
 183   static unsigned int hash(oop key, int size) {
 184     ZGC_ONLY(assert(ZAddressMetadataShift >= sizeof(unsigned int) * BitsPerByte, "cast removes the metadata bits");)
 185 
 186     // shift right to get better distribution (as these bits will be zero
 187     // with aligned addresses)

 188     unsigned int addr = (unsigned int)(cast_from_oop<intptr_t>(key));
 189 #ifdef _LP64
 190     return (addr >> 3) % size;
 191 #else
 192     return (addr >> 2) % size;
 193 #endif
 194   }
 195 
 196   // hash a given key (oop)
 197   unsigned int hash(oop key) {
 198     return hash(key, _size);
 199   }
 200 
 201   // resize the hashmap - allocates a large table and re-hashes
 202   // all entries into the new table.
 203   void resize() {
 204     int new_size_index = _size_index+1;
 205     int new_size = _sizes[new_size_index];
 206     if (new_size < 0) {
 207       // hashmap already at maximum capacity




  87   JvmtiTagHashmapEntry(oop object, jlong tag) { init(object, tag); }
  88 
  89  public:
  90 
  91   // accessor methods
  92   inline oop* object_addr() { return &_object; }
  93   inline oop object()       { return NativeAccess<ON_PHANTOM_OOP_REF>::oop_load(object_addr()); }
  94   // Peek at the object without keeping it alive. The returned object must be
  95   // kept alive using a normal access if it leaks out of a thread transition from VM.
  96   inline oop object_peek()  {
  97     return NativeAccess<ON_PHANTOM_OOP_REF | AS_NO_KEEPALIVE>::oop_load(object_addr());
  98   }
  99   inline jlong tag() const  { return _tag; }
 100 
 101   inline void set_tag(jlong tag) {
 102     assert(tag != 0, "can't be zero");
 103     _tag = tag;
 104   }
 105 
 106   inline bool equals(oop object) {
 107     return oopDesc::equals(object, object_peek());
 108   }
 109 
 110   inline JvmtiTagHashmapEntry* next() const        { return _next; }
 111   inline void set_next(JvmtiTagHashmapEntry* next) { _next = next; }
 112 };
 113 
 114 
 115 // JvmtiTagHashmap
 116 //
 117 // A hashmap is essentially a table of pointers to entries. Entries
 118 // are hashed to a location, or position in the table, and then
 119 // chained from that location. The "key" for hashing is address of
 120 // the object, or oop. The "value" is the tag value.
 121 //
 122 // A hashmap maintains a count of the number entries in the hashmap
 123 // and resizes if the number of entries exceeds a given threshold.
 124 // The threshold is specified as a percentage of the size - for
 125 // example a threshold of 0.75 will trigger the hashmap to resize
 126 // if the number of entries is >75% of table size.
 127 //


 168     _load_factor = load_factor;
 169     _resize_threshold = (int)(_load_factor * _size);
 170     _resizing_enabled = true;
 171     size_t s = initial_size * sizeof(JvmtiTagHashmapEntry*);
 172     _table = (JvmtiTagHashmapEntry**)os::malloc(s, mtInternal);
 173     if (_table == NULL) {
 174       vm_exit_out_of_memory(s, OOM_MALLOC_ERROR,
 175         "unable to allocate initial hashtable for jvmti object tags");
 176     }
 177     for (int i=0; i<initial_size; i++) {
 178       _table[i] = NULL;
 179     }
 180   }
 181 
 182   // hash a given key (oop) with the specified size
 183   static unsigned int hash(oop key, int size) {
 184     ZGC_ONLY(assert(ZAddressMetadataShift >= sizeof(unsigned int) * BitsPerByte, "cast removes the metadata bits");)
 185 
 186     // shift right to get better distribution (as these bits will be zero
 187     // with aligned addresses)
 188     key = Access<>::resolve(key);
 189     unsigned int addr = (unsigned int)(cast_from_oop<intptr_t>(key));
 190 #ifdef _LP64
 191     return (addr >> 3) % size;
 192 #else
 193     return (addr >> 2) % size;
 194 #endif
 195   }
 196 
 197   // hash a given key (oop)
 198   unsigned int hash(oop key) {
 199     return hash(key, _size);
 200   }
 201 
 202   // resize the hashmap - allocates a large table and re-hashes
 203   // all entries into the new table.
 204   void resize() {
 205     int new_size_index = _size_index+1;
 206     int new_size = _sizes[new_size_index];
 207     if (new_size < 0) {
 208       // hashmap already at maximum capacity


< prev index next >