< prev index next >

src/hotspot/share/prims/jvmtiTagMap.cpp

Print this page




  42 #include "oops/typeArrayOop.inline.hpp"
  43 #include "prims/jvmtiEventController.hpp"
  44 #include "prims/jvmtiEventController.inline.hpp"
  45 #include "prims/jvmtiExport.hpp"
  46 #include "prims/jvmtiImpl.hpp"
  47 #include "prims/jvmtiTagMap.hpp"
  48 #include "runtime/biasedLocking.hpp"
  49 #include "runtime/frame.inline.hpp"
  50 #include "runtime/handles.inline.hpp"
  51 #include "runtime/javaCalls.hpp"
  52 #include "runtime/jniHandles.inline.hpp"
  53 #include "runtime/mutex.hpp"
  54 #include "runtime/mutexLocker.hpp"
  55 #include "runtime/reflectionUtils.hpp"
  56 #include "runtime/thread.inline.hpp"
  57 #include "runtime/threadSMR.hpp"
  58 #include "runtime/vframe.hpp"
  59 #include "runtime/vmThread.hpp"
  60 #include "runtime/vm_operations.hpp"
  61 #include "utilities/macros.hpp"



  62 
  63 // JvmtiTagHashmapEntry
  64 //
  65 // Each entry encapsulates a reference to the tagged object
  66 // and the tag value. In addition an entry includes a next pointer which
  67 // is used to chain entries together.
  68 
  69 class JvmtiTagHashmapEntry : public CHeapObj<mtInternal> {
  70  private:
  71   friend class JvmtiTagMap;
  72 
  73   oop _object;                          // tagged object
  74   jlong _tag;                           // the tag
  75   JvmtiTagHashmapEntry* _next;          // next on the list
  76 
  77   inline void init(oop object, jlong tag) {
  78     _object = object;
  79     _tag = tag;
  80     _next = NULL;
  81   }


 161     _size_index = size_index;
 162     _size = initial_size;
 163     _entry_count = 0;
 164     _trace_threshold = initial_trace_threshold;
 165     _load_factor = load_factor;
 166     _resize_threshold = (int)(_load_factor * _size);
 167     _resizing_enabled = true;
 168     size_t s = initial_size * sizeof(JvmtiTagHashmapEntry*);
 169     _table = (JvmtiTagHashmapEntry**)os::malloc(s, mtInternal);
 170     if (_table == NULL) {
 171       vm_exit_out_of_memory(s, OOM_MALLOC_ERROR,
 172         "unable to allocate initial hashtable for jvmti object tags");
 173     }
 174     for (int i=0; i<initial_size; i++) {
 175       _table[i] = NULL;
 176     }
 177   }
 178 
 179   // hash a given key (oop) with the specified size
 180   static unsigned int hash(oop key, int size) {


 181     // shift right to get better distribution (as these bits will be zero
 182     // with aligned addresses)
 183     unsigned int addr = (unsigned int)(cast_from_oop<intptr_t>(key));
 184 #ifdef _LP64
 185     return (addr >> 3) % size;
 186 #else
 187     return (addr >> 2) % size;
 188 #endif
 189   }
 190 
 191   // hash a given key (oop)
 192   unsigned int hash(oop key) {
 193     return hash(key, _size);
 194   }
 195 
 196   // resize the hashmap - allocates a large table and re-hashes
 197   // all entries into the new table.
 198   void resize() {
 199     int new_size_index = _size_index+1;
 200     int new_size = _sizes[new_size_index];




  42 #include "oops/typeArrayOop.inline.hpp"
  43 #include "prims/jvmtiEventController.hpp"
  44 #include "prims/jvmtiEventController.inline.hpp"
  45 #include "prims/jvmtiExport.hpp"
  46 #include "prims/jvmtiImpl.hpp"
  47 #include "prims/jvmtiTagMap.hpp"
  48 #include "runtime/biasedLocking.hpp"
  49 #include "runtime/frame.inline.hpp"
  50 #include "runtime/handles.inline.hpp"
  51 #include "runtime/javaCalls.hpp"
  52 #include "runtime/jniHandles.inline.hpp"
  53 #include "runtime/mutex.hpp"
  54 #include "runtime/mutexLocker.hpp"
  55 #include "runtime/reflectionUtils.hpp"
  56 #include "runtime/thread.inline.hpp"
  57 #include "runtime/threadSMR.hpp"
  58 #include "runtime/vframe.hpp"
  59 #include "runtime/vmThread.hpp"
  60 #include "runtime/vm_operations.hpp"
  61 #include "utilities/macros.hpp"
  62 #if INCLUDE_ZGC
  63 #include "gc/z/zGlobals.hpp"
  64 #endif
  65 
  66 // JvmtiTagHashmapEntry
  67 //
  68 // Each entry encapsulates a reference to the tagged object
  69 // and the tag value. In addition an entry includes a next pointer which
  70 // is used to chain entries together.
  71 
  72 class JvmtiTagHashmapEntry : public CHeapObj<mtInternal> {
  73  private:
  74   friend class JvmtiTagMap;
  75 
  76   oop _object;                          // tagged object
  77   jlong _tag;                           // the tag
  78   JvmtiTagHashmapEntry* _next;          // next on the list
  79 
  80   inline void init(oop object, jlong tag) {
  81     _object = object;
  82     _tag = tag;
  83     _next = NULL;
  84   }


 164     _size_index = size_index;
 165     _size = initial_size;
 166     _entry_count = 0;
 167     _trace_threshold = initial_trace_threshold;
 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];


< prev index next >