use of java.lang.ref.Reference in project ACS by ACS-Community.
the class GarbageCollectionTestHelper method waitForGC.
public boolean waitForGC() {
waitingThread = Thread.currentThread();
Reference retRef = null;
System.gc();
while (true) {
try {
//@
System.err.println("refQ:waiting to remove()");
retRef = refQ.remove();
//@
System.err.println("refQ:removed()");
break;
} catch (InterruptedException ex) {
if (cancelFlag) {
break;
}
// ignore and continue
continue;
}
}
waitingThread = null;
return (retRef != null);
}
use of java.lang.ref.Reference in project jdk8u_jdk by JetBrains.
the class LFGarbageCollectedTest method collectLambdaForm.
private void collectLambdaForm() throws IllegalAccessException {
// Usually, 2 System.GCs are necessary to enqueue a SoftReference.
System.gc();
System.gc();
Reference ref = null;
for (int i = 0; i < 10; i++) {
try {
ref = rq.remove(1000);
} catch (InterruptedException e) {
/* ignore */
}
if (ref != null) {
break;
}
// If the reference hasn't been queued yet, trigger one more GC.
System.gc();
}
if (ref == null) {
dumpTestData();
System.err.println("Method type: " + mtype);
System.err.println("LambdaForm: " + REF_FIELD.get(ph));
if (HEAP_DUMP) {
// Trigger OOM to force heap dump for post-mortem analysis.
val = new long[1_000_000_000];
}
throw new AssertionError("Error: LambdaForm is not garbage collected");
}
;
}
use of java.lang.ref.Reference in project jdk8u_jdk by JetBrains.
the class ConnectionAcceptor method checkConnectPermission.
/**
* Checks if the current caller has sufficient privilege to make
* a connection to the remote endpoint.
* @exception SecurityException if caller is not allowed to use this
* Channel.
*/
private void checkConnectPermission() throws SecurityException {
SecurityManager security = System.getSecurityManager();
if (security == null)
return;
if (security != cacheSecurityManager) {
// The security manager changed: flush the cache
okContext = null;
authcache = new WeakHashMap<AccessControlContext, Reference<AccessControlContext>>();
cacheSecurityManager = security;
}
AccessControlContext ctx = AccessController.getContext();
// appears in the cache, bypass the checkConnect.
if (okContext == null || !(okContext.equals(ctx) || authcache.containsKey(ctx))) {
security.checkConnect(ep.getHost(), ep.getPort());
authcache.put(ctx, new SoftReference<AccessControlContext>(ctx));
// A WeakHashMap is transformed into a SoftHashSet by making
// each value softly refer to its own key (Peter's idea).
}
okContext = ctx;
}
use of java.lang.ref.Reference in project geode by apache.
the class ConnectionTable method getThreadOwnedConnection.
/**
* Must be looking for an ordered connection that this thread owns
*
* @param id stub on which to create the connection
* @param startTime the ms clock start time for the operation
* @param ackTimeout the ms ack-wait-threshold, or zero
* @param ackSATimeout the ms ack-severe-alert-threshold, or zero
* @return the connection, or null if an error
* @throws IOException if the connection could not be created
* @throws DistributedSystemDisconnectedException
*/
Connection getThreadOwnedConnection(DistributedMember id, long startTime, long ackTimeout, long ackSATimeout) throws IOException, DistributedSystemDisconnectedException {
Connection result = null;
// Look for result in the thread local
Map m = (Map) this.threadOrderedConnMap.get();
if (m == null) {
// First time for this thread. Create thread local
m = new HashMap();
synchronized (this.threadConnMaps) {
if (this.closed) {
owner.getCancelCriterion().checkCancelInProgress(null);
throw new DistributedSystemDisconnectedException(LocalizedStrings.ConnectionTable_CONNECTION_TABLE_IS_CLOSED.toLocalizedString());
}
// check for stale references and remove them.
for (Iterator it = this.threadConnMaps.iterator(); it.hasNext(); ) {
Reference r = (Reference) it.next();
if (r.get() == null) {
it.remove();
}
}
// for
// ref added for bug 38011
this.threadConnMaps.add(new WeakReference(m));
}
// synchronized
this.threadOrderedConnMap.set(m);
} else {
// Consult thread local.
synchronized (m) {
result = (Connection) m.get(id);
}
if (result != null && result.timedOut) {
result = null;
}
}
if (result != null)
return result;
// OK, we have to create a new connection.
result = Connection.createSender(owner.getMembershipManager(), this, true, /* preserveOrder */
id, false, /* shared */
startTime, ackTimeout, ackSATimeout);
if (logger.isDebugEnabled()) {
logger.debug("ConnectionTable: created an ordered connection: {}", result);
}
this.owner.stats.incSenders(false, /* shared */
true);
if (this.threadConnectionMap == null) {
// This instance is being destroyed; fail the operation
closeCon(LocalizedStrings.ConnectionTable_CONNECTION_TABLE_BEING_DESTROYED.toLocalizedString(), result);
return null;
}
ArrayList al = (ArrayList) this.threadConnectionMap.get(id);
if (al == null) {
// First connection for this DistributedMember. Make sure list for this
// stub is created if it isn't already there.
al = new ArrayList();
// Since it's a concurrent map, we just try to put it and then
// return whichever we got.
Object o = this.threadConnectionMap.putIfAbsent(id, al);
if (o != null) {
al = (ArrayList) o;
}
}
// Add our Connection to the list
synchronized (al) {
al.add(result);
}
// Finally, add the connection to our thread local map.
synchronized (m) {
m.put(id, result);
}
scheduleIdleTimeout(result);
return result;
}
use of java.lang.ref.Reference in project geode by apache.
the class ConnectionTable method close.
protected void close() {
/*
* NOMUX if (inputMuxManager != null) { inputMuxManager.stop(); }
*/
if (this.closed) {
return;
}
this.closed = true;
synchronized (this) {
if (this.idleConnTimer != null) {
this.idleConnTimer.cancel();
}
}
synchronized (this.orderedConnectionMap) {
for (Iterator it = this.orderedConnectionMap.values().iterator(); it.hasNext(); ) {
closeCon(LocalizedStrings.ConnectionTable_CONNECTION_TABLE_BEING_DESTROYED.toLocalizedString(), it.next());
}
this.orderedConnectionMap.clear();
}
synchronized (this.unorderedConnectionMap) {
for (Iterator it = this.unorderedConnectionMap.values().iterator(); it.hasNext(); ) {
closeCon(LocalizedStrings.ConnectionTable_CONNECTION_TABLE_BEING_DESTROYED.toLocalizedString(), it.next());
}
this.unorderedConnectionMap.clear();
}
if (this.threadConnectionMap != null) {
this.threadConnectionMap = null;
}
if (this.threadConnMaps != null) {
synchronized (this.threadConnMaps) {
for (Iterator it = this.threadConnMaps.iterator(); it.hasNext(); ) {
Reference r = (Reference) it.next();
Map m = (Map) r.get();
if (m != null) {
synchronized (m) {
for (Iterator mit = m.values().iterator(); mit.hasNext(); ) {
closeCon(LocalizedStrings.ConnectionTable_CONNECTION_TABLE_BEING_DESTROYED.toLocalizedString(), mit.next());
}
}
}
}
this.threadConnMaps.clear();
}
}
{
Executor localExec = this.p2pReaderThreadPool;
if (localExec != null) {
if (localExec instanceof ExecutorService) {
((ExecutorService) localExec).shutdown();
}
}
}
closeReceivers(false);
Map m = (Map) this.threadOrderedConnMap.get();
if (m != null) {
synchronized (m) {
m.clear();
}
}
this.socketCloser.close();
}
Aggregations