/*
* Copyright 2012 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
/*
* Written by Doug Lea with assistance from members of JCP JSR-166
* Expert Group and released to the public domain, as explained at
* http://creativecommons.org/licenses/publicdomain
*/
package com.taobao.arthas.common.concurrent;
import java.lang.ref.Reference;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;
import java.util.AbstractCollection;
import java.util.AbstractMap;
import java.util.AbstractSet;
import java.util.Arrays;
import java.util.Collection;
import java.util.ConcurrentModificationException;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.locks.ReentrantLock;
/**
* An alternative weak-key {@link ConcurrentMap} which is similar to
* {@link ConcurrentHashMap}.
* @param <K> the type of keys maintained by this map
* @param <V> the type of mapped values
*/
public final class ConcurrentWeakKeyHashMap<K, V> extends AbstractMap<K, V> implements ConcurrentMap<K, V> {
/*
* The basic strategy is to subdivide the table among Segments,
* each of which itself is a concurrently readable hash table.
*/
/**
* The default initial capacity for this table, used when not otherwise
* specified in a constructor.
*/
static final int DEFAULT_INITIAL_CAPACITY = 16;
/**
* The default load factor for this table, used when not otherwise specified
* in a constructor.
*/
static final float DEFAULT_LOAD_FACTOR = 0.75f;
/**
* The default concurrency level for this table, used when not otherwise
* specified in a constructor.
*/
static final int DEFAULT_CONCURRENCY_LEVEL = 16;
/**
* The maximum capacity, used if a higher value is implicitly specified by
* either of the constructors with arguments. MUST be a power of two
* <= 1<<30 to ensure that entries are indexable using integers.
*/
static final int MAXIMUM_CAPACITY = 1 << 30;
/**
* The maximum number of segments to allow; used to bound constructor
* arguments.
*/
static final int MAX_SEGMENTS = 1 << 16; // slightly conservative
/**
* Number of unsynchronized retries in size and containsValue methods before
* resorting to locking. This is used to avoid unbounded retries if tables
* undergo continuous modification which would make it impossible to obtain
* an accurate result.
*/
static final int RETRIES_BEFORE_LOCK = 2;
/* ---------------- Fields -------------- */
/**
* Mask value for indexing into segments. The upper bits of a key's hash
* code are used to choose the segment.
*/
final int segmentMask;
/**
* Shift value for indexing within segments.
*/
final int segmentShift;
/**
* The segments, each of which is a specialized hash table
*/
final Segment<K, V>[] segments;
Set<K> keySet;
Set<Map.Entry<K, V>> entrySet;
Collection<V> values;
/* ---------------- Small Utilities -------------- */
/**
* Applies a supplemental hash function to a given hashCode, which defends
* against poor quality hash functions. This is critical because
* ConcurrentReferenceHashMap uses power-of-two length hash tables, that
* otherwise encounter collisions for hashCodes that do not differ in lower
* or upper bits.
*/
private static int hash(int h) {
// Spread bits to regularize both segment and index locations,
// using variant of single-word Wang/Jenkins hash.
h += h << 15 ^ 0xffffcd7d;
h ^= h >>> 10;
h += h << 3;
h ^= h >>> 6;
h += (h << 2) + (h << 14);
return h ^ h >>> 16;
}
/**
* Returns the segment that should be used for key with given hash.
*
* @param hash the hash code for the key
* @return the segment
*/
Segment<K, V> segmentFor(int hash) {
return segments[hash >>> segmentShift & segmentMask];
}
private static int hashOf(Object key) {
return hash(key.hashCode());
}
/* ---------------- Inner Classes -------------- */
/**
* A weak-key reference which stores the key hash needed for reclamation.
*/
static final class WeakKeyReference<K> extends WeakReference<K> {
final int hash;
WeakKeyReference(K key, int hash, ReferenceQueue<Object> refQueue) {
super(key, refQueue);
this.hash = hash;
}
public int keyHash() {
return hash;
}
public Object keyRef() {
return this;
}
}
/**
* ConcurrentReferenceHashMap list entry. Note that this is never exported
* out as a user-visible Map.Entry.
*
* Because the value field is volatile, not final, it is legal wrt
* the Java Memory Model for an unsynchronized reader to see null
* instead of initial value when read via a data race. Although a
* reordering leading to this is not likely to ever actually
* occur, the Segment.readValueUnderLock method is used as a
* backup in case a null (pre-initialized) value is ever seen in
* an unsynchronized access method.
*/
static final class HashEntry<K, V> {
final Object keyRef;
final int hash;
volatile Object valueRef;
final HashEntry<K, V> next;
HashEntry(
K key, int hash, HashEntry<K, V> next, V value,
ReferenceQueue<Object> refQueue) {
this.hash = hash;
this.next = next;
keyRef = new WeakKeyReference<K>(key, hash, refQueue);
valueRef = value;
}
@SuppressWarnings("unchecked")
K key() {
return ((Reference<K>) keyRef).get();
}
V value() {
return dereferenceValue(valueRef);
}
@SuppressWarnings("unchecked")
V dereferenceValue(Object value) {
if (value instanceof WeakKeyReference) {
return ((Reference<V>) value).get();
}
return (V) value;
}
void setValue(V value) {
valueRef = value;
}
@SuppressWarnings("unchecked")
static <K, V> HashEntry<K, V>[] newArray(int i) {
return new HashEntry[i];
}
}
/**
* Segments are specialized versions of hash tables. This subclasses from
* ReentrantLock opportunistically, just to simplify some locking and avoid
* separate construction.
*/
static final class Segment<K, V> extends ReentrantLock {
/*
* Segments maintain a table of entry lists that are ALWAYS kept in a
* consistent state, so can be read without locking. Next fields of
* nodes are immutable (final). All list additions are performed at the
* front of each bin. This makes it easy to check changes, and also fast
* to traverse. When nodes would otherwise be changed, new nodes are
* created to replace them. This works well for hash tables since the
* bin lists tend to be short. (The average length is less than two fo
没有合适的资源?快使用搜索试试~ 我知道了~
arthas-master.zip
共1993个文件
md:889个
java:592个
png:146个
0 下载量 12 浏览量
2023-03-12
12:56:29
上传
评论
收藏 5.69MB ZIP 举报
温馨提示
Arthas 是Alibaba开源的Java诊断工具,当你遇到以下类似问题而束手无策时,Arthas可以帮助你解决:这个类从哪个 jar 包加载的?为什么会报各种类相关的 Exception?我改的代码为什么没有执行到?难道是我没 commit?分支搞错了?遇到问题无法在线上 debug,难道只能通过加日志再重新发布吗?线上遇到某个用户的数据处理有问题,但线上同样无法 debug,线下无法重现!是否有一个全局视角来查看系统的运行状况?有什么办法可以监控到JVM的实时运行状态?怎么快速定位应用的热点,生成火焰图?怎样直接从JVM内查找某个类的实例?Arthas支持JDK 6+,支持Linux/Mac/Windows,采用命令行交互模式,同时提供丰富的 Tab 自动补全功能,进一步方便进行问题的定位和诊断。
资源推荐
资源详情
资源评论
收起资源包目录
arthas-master.zip (1993个子文件)
arthas.1 3KB
copyright.1 484B
batch.as 130B
as-service.bat 8KB
as.bat 3KB
AccessBridgeCalls.c 45KB
mvnw.cmd 6KB
control 291B
jni-library.cpp 6KB
main.css 60B
main.css 58B
main.css 58B
libArthasJniLibrary-x64.dll 2.29MB
Dockerfile 930B
Dockerfile-No-Jdk 545B
libArthasJniLibrary.dylib 132KB
.env 58B
spring.factories 184B
.gitignore 452B
.gitignore 261B
.gitignore 47B
verify.groovy 100B
jvmti.h 80KB
AccessBridgePackages.h 76KB
jni.h 74KB
AccessBridgeCalls.h 35KB
classfile_constants.h 22KB
jawt.h 12KB
jdwpTransport.h 8KB
AccessBridgeCallbacks.h 5KB
jvmticmlr.h 5KB
jawt_md.h 3KB
jni_md.h 2KB
jawt_md.h 2KB
jawt_md.h 2KB
jni_md.h 2KB
jni_md.h 2KB
arthas-tutorials.html 32KB
index.html 373B
index.html 373B
index.html 364B
agents.html 316B
apps.html 313B
favicon.ico 17KB
favicon.ico 17KB
inputrc 1KB
maven-wrapper.jar 50KB
ConcurrentWeakKeyHashMap.java 50KB
Telnet.java 33KB
StringUtils.java 31KB
Bootstrap.java 31KB
SocketClient.java 29KB
HttpApiHandler.java 28KB
ClassLoaderCommand.java 27KB
ObjectView.java 26KB
ArthasBootstrap.java 25KB
Enhancer.java 23KB
TelnetInputStream.java 22KB
ProcessImpl.java 21KB
TimeTunnelCommand.java 21KB
ProfilerCommand.java 20KB
ThreadUtil.java 19KB
ReflectUtils.java 19KB
MBeanCommand.java 19KB
ObjectUtils.java 19KB
RetransformCommand.java 18KB
FieldUtils.java 18KB
StringUtilsTest.java 18KB
ProcessUtils.java 16KB
Ansi.java 16KB
JFRCommand.java 15KB
LoggerCommand.java 15KB
TelnetConsole.java 15KB
CompletionUtils.java 14KB
TunnelSocketFrameHandler.java 14KB
ArthasReflectUtils.java 13KB
TelnetClient.java 13KB
VmToolCommand.java 12KB
DirectoryBrowser.java 12KB
ClassUtils.java 12KB
PropertySource.java 11KB
DashboardCommand.java 11KB
JulyCommand.java 11KB
MutablePropertySources.java 11KB
AdviceListenerManager.java 11KB
PropertyPlaceholderHelper.java 10KB
ObjectViewTest.java 10KB
DatagramSocketClient.java 10KB
JadCommand.java 10KB
ShellImpl.java 10KB
JobControllerImpl.java 10KB
ThreadLocalRandom.java 10KB
ShellServerImpl.java 10KB
TableView.java 10KB
MBeanView.java 9KB
OptionsCommand.java 9KB
ThreadCommand.java 9KB
GetStaticCommand.java 9KB
EnhancerCommand.java 9KB
JvmCommand.java 9KB
共 1993 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
m0_72731342
- 粉丝: 2
- 资源: 1832
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功