1107 |
1107 |
1108 |
1108 |
1109 void InstanceKlass::mask_for(const methodHandle& method, int bci, |
1109 void InstanceKlass::mask_for(const methodHandle& method, int bci, |
1110 InterpreterOopMap* entry_for) { |
1110 InterpreterOopMap* entry_for) { |
1111 // Lazily create the _oop_map_cache at first request |
1111 // Lazily create the _oop_map_cache at first request |
1112 // Lock-free access requires load_ptr_acquire. |
1112 // Lock-free access requires load_acquire. |
1113 OopMapCache* oop_map_cache = |
1113 OopMapCache* oop_map_cache = OrderAccess::load_acquire(&_oop_map_cache); |
1114 static_cast<OopMapCache*>(OrderAccess::load_ptr_acquire(&_oop_map_cache)); |
|
1115 if (oop_map_cache == NULL) { |
1114 if (oop_map_cache == NULL) { |
1116 MutexLocker x(OopMapCacheAlloc_lock); |
1115 MutexLocker x(OopMapCacheAlloc_lock); |
1117 // Check if _oop_map_cache was allocated while we were waiting for this lock |
1116 // Check if _oop_map_cache was allocated while we were waiting for this lock |
1118 if ((oop_map_cache = _oop_map_cache) == NULL) { |
1117 if ((oop_map_cache = _oop_map_cache) == NULL) { |
1119 oop_map_cache = new OopMapCache(); |
1118 oop_map_cache = new OopMapCache(); |
1120 // Ensure _oop_map_cache is stable, since it is examined without a lock |
1119 // Ensure _oop_map_cache is stable, since it is examined without a lock |
1121 OrderAccess::release_store_ptr(&_oop_map_cache, oop_map_cache); |
1120 OrderAccess::release_store(&_oop_map_cache, oop_map_cache); |
1122 } |
1121 } |
1123 } |
1122 } |
1124 // _oop_map_cache is constant after init; lookup below does its own locking. |
1123 // _oop_map_cache is constant after init; lookup below does its own locking. |
1125 oop_map_cache->lookup(method, bci, entry_for); |
1124 oop_map_cache->lookup(method, bci, entry_for); |
1126 } |
1125 } |
1670 // We use a double-check locking idiom here because this cache is |
1669 // We use a double-check locking idiom here because this cache is |
1671 // performance sensitive. In the normal system, this cache only |
1670 // performance sensitive. In the normal system, this cache only |
1672 // transitions from NULL to non-NULL which is safe because we use |
1671 // transitions from NULL to non-NULL which is safe because we use |
1673 // release_set_methods_jmethod_ids() to advertise the new cache. |
1672 // release_set_methods_jmethod_ids() to advertise the new cache. |
1674 // A partially constructed cache should never be seen by a racing |
1673 // A partially constructed cache should never be seen by a racing |
1675 // thread. We also use release_store_ptr() to save a new jmethodID |
1674 // thread. We also use release_store() to save a new jmethodID |
1676 // in the cache so a partially constructed jmethodID should never be |
1675 // in the cache so a partially constructed jmethodID should never be |
1677 // seen either. Cache reads of existing jmethodIDs proceed without a |
1676 // seen either. Cache reads of existing jmethodIDs proceed without a |
1678 // lock, but cache writes of a new jmethodID requires uniqueness and |
1677 // lock, but cache writes of a new jmethodID requires uniqueness and |
1679 // creation of the cache itself requires no leaks so a lock is |
1678 // creation of the cache itself requires no leaks so a lock is |
1680 // generally acquired in those two cases. |
1679 // generally acquired in those two cases. |
1829 id = new_id; |
1828 id = new_id; |
1830 |
1829 |
1831 // The jmethodID cache can be read while unlocked so we have to |
1830 // The jmethodID cache can be read while unlocked so we have to |
1832 // make sure the new jmethodID is complete before installing it |
1831 // make sure the new jmethodID is complete before installing it |
1833 // in the cache. |
1832 // in the cache. |
1834 OrderAccess::release_store_ptr(&jmeths[idnum+1], id); |
1833 OrderAccess::release_store(&jmeths[idnum+1], id); |
1835 } else { |
1834 } else { |
1836 *to_dealloc_id_p = new_id; // save new id for later delete |
1835 *to_dealloc_id_p = new_id; // save new id for later delete |
1837 } |
1836 } |
1838 return id; |
1837 return id; |
1839 } |
1838 } |