summaryrefslogtreecommitdiff
path: root/java/src
diff options
context:
space:
mode:
authorMark Spruiell <mes@zeroc.com>2005-04-29 18:17:14 +0000
committerMark Spruiell <mes@zeroc.com>2005-04-29 18:17:14 +0000
commit19b5869472e679fb244709a53a1bb8b79ec5186f (patch)
treef65bbf8032a89f96a3c55c468d00e04a7e43edf5 /java/src
parentAdded call to srand48() (diff)
downloadice-19b5869472e679fb244709a53a1bb8b79ec5186f.tar.bz2
ice-19b5869472e679fb244709a53a1bb8b79ec5186f.tar.xz
ice-19b5869472e679fb244709a53a1bb8b79ec5186f.zip
- Removing BufferManager class and BasicStream.destroy(), which reduces the
complexity of many existing finalizers. - Removed code that cleans up cached objects. - For compatibility with C#, finalizers no longer call methods on other objects.
Diffstat (limited to 'java/src')
-rw-r--r--java/src/Freeze/ObjectStore.java92
-rw-r--r--java/src/Ice/CommunicatorI.java12
-rw-r--r--java/src/Ice/ConnectionI.java301
-rw-r--r--java/src/Ice/InputStreamI.java1
-rw-r--r--java/src/Ice/ObjectAdapterI.java32
-rw-r--r--java/src/Ice/OutputStreamI.java1
-rw-r--r--java/src/Ice/_ObjectDelM.java27
-rw-r--r--java/src/IceInternal/BasicStream.java66
-rw-r--r--java/src/IceInternal/BufferManager.java129
-rw-r--r--java/src/IceInternal/EventHandler.java17
-rw-r--r--java/src/IceInternal/Incoming.java17
-rw-r--r--java/src/IceInternal/IncomingAsync.java14
-rw-r--r--java/src/IceInternal/IncomingBase.java15
-rw-r--r--java/src/IceInternal/IncomingConnectionFactory.java11
-rw-r--r--java/src/IceInternal/Instance.java10
-rw-r--r--java/src/IceInternal/ObjectAdapterFactory.java31
-rw-r--r--java/src/IceInternal/Outgoing.java17
-rw-r--r--java/src/IceInternal/OutgoingAsync.java12
-rw-r--r--java/src/IceInternal/OutgoingConnectionFactory.java12
-rw-r--r--java/src/IceInternal/ThreadPool.java7
20 files changed, 239 insertions, 585 deletions
diff --git a/java/src/Freeze/ObjectStore.java b/java/src/Freeze/ObjectStore.java
index cba5a64bc37..887e6d76cbf 100644
--- a/java/src/Freeze/ObjectStore.java
+++ b/java/src/Freeze/ObjectStore.java
@@ -245,60 +245,39 @@ class ObjectStore implements IceUtil.Store
marshalKey(Ice.Identity v, Ice.Communicator communicator)
{
IceInternal.BasicStream os = new IceInternal.BasicStream(Ice.Util.getInstance(communicator));
- try
- {
- v.__write(os);
- java.nio.ByteBuffer buf = os.prepareWrite();
- byte[] r = new byte[buf.limit()];
- buf.get(r);
- return r;
- }
- finally
- {
- os.destroy();
- }
+ v.__write(os);
+ java.nio.ByteBuffer buf = os.prepareWrite();
+ byte[] r = new byte[buf.limit()];
+ buf.get(r);
+ return r;
}
static Ice.Identity
unmarshalKey(byte[] b, Ice.Communicator communicator)
{
IceInternal.BasicStream is = new IceInternal.BasicStream(Ice.Util.getInstance(communicator));
- try
- {
- is.resize(b.length, true);
- java.nio.ByteBuffer buf = is.prepareRead();
- buf.position(0);
- buf.put(b);
- buf.position(0);
- Ice.Identity key = new Ice.Identity();
- key.__read(is);
- return key;
- }
- finally
- {
- is.destroy();
- }
+ is.resize(b.length, true);
+ java.nio.ByteBuffer buf = is.prepareRead();
+ buf.position(0);
+ buf.put(b);
+ buf.position(0);
+ Ice.Identity key = new Ice.Identity();
+ key.__read(is);
+ return key;
}
static byte[]
marshalValue(ObjectRecord v, Ice.Communicator communicator)
{
IceInternal.BasicStream os = new IceInternal.BasicStream(Ice.Util.getInstance(communicator));
- try
- {
- os.startWriteEncaps();
- v.__write(os);
- os.writePendingObjects();
- os.endWriteEncaps();
- java.nio.ByteBuffer buf = os.prepareWrite();
- byte[] r = new byte[buf.limit()];
- buf.get(r);
- return r;
- }
- finally
- {
- os.destroy();
- }
+ os.startWriteEncaps();
+ v.__write(os);
+ os.writePendingObjects();
+ os.endWriteEncaps();
+ java.nio.ByteBuffer buf = os.prepareWrite();
+ byte[] r = new byte[buf.limit()];
+ buf.get(r);
+ return r;
}
static ObjectRecord
@@ -306,24 +285,17 @@ class ObjectStore implements IceUtil.Store
{
IceInternal.BasicStream is = new IceInternal.BasicStream(Ice.Util.getInstance(communicator));
is.sliceObjects(false);
- try
- {
- is.resize(b.length, true);
- java.nio.ByteBuffer buf = is.prepareRead();
- buf.position(0);
- buf.put(b);
- buf.position(0);
- ObjectRecord rec= new ObjectRecord();
- is.startReadEncaps();
- rec.__read(is);
- is.readPendingObjects();
- is.endReadEncaps();
- return rec;
- }
- finally
- {
- is.destroy();
- }
+ is.resize(b.length, true);
+ java.nio.ByteBuffer buf = is.prepareRead();
+ buf.position(0);
+ buf.put(b);
+ buf.position(0);
+ ObjectRecord rec= new ObjectRecord();
+ is.startReadEncaps();
+ rec.__read(is);
+ is.readPendingObjects();
+ is.endReadEncaps();
+ return rec;
}
diff --git a/java/src/Ice/CommunicatorI.java b/java/src/Ice/CommunicatorI.java
index 0e027e6844b..3dd2149789e 100644
--- a/java/src/Ice/CommunicatorI.java
+++ b/java/src/Ice/CommunicatorI.java
@@ -272,20 +272,22 @@ public final class CommunicatorI extends LocalObjectImpl implements Communicator
_instance = new IceInternal.Instance(this, properties);
}
+ /**
+ * For compatibility with C#, we do not invoke methods on other objects
+ * from within a finalizer.
+ *
protected synchronized void
finalize()
throws Throwable
{
- synchronized(this)
+ if(!_destroyed)
{
- if(!_destroyed)
- {
- _instance.logger().warning("Ice::Communicator::destroy() has not been called");
- }
+ _instance.logger().warning("Ice::Communicator::destroy() has not been called");
}
super.finalize();
}
+ */
//
// Certain initialization tasks need to be completed after the
diff --git a/java/src/Ice/ConnectionI.java b/java/src/Ice/ConnectionI.java
index 1a214f5cfff..e40a03af2b3 100644
--- a/java/src/Ice/ConnectionI.java
+++ b/java/src/Ice/ConnectionI.java
@@ -263,20 +263,7 @@ public final class ConnectionI extends IceInternal.EventHandler implements Conne
threadPerConnection = _threadPerConnection;
_threadPerConnection = null;
- //
- // We must destroy the incoming cache. It is now not
- // needed anymore.
- //
- synchronized(_incomingCacheMutex)
- {
- while(_incomingCache != null)
- {
- _incomingCache.__destroy();
- _incomingCache = _incomingCache.next;
- }
- }
-
- cleanup();
+ _incomingCache = null;
}
if(threadPerConnection != null)
@@ -391,20 +378,7 @@ public final class ConnectionI extends IceInternal.EventHandler implements Conne
threadPerConnection = _threadPerConnection;
_threadPerConnection = null;
- //
- // We must destroy the incoming cache. It is now not
- // needed anymore.
- //
- synchronized(_incomingCacheMutex)
- {
- while(_incomingCache != null)
- {
- _incomingCache.__destroy();
- _incomingCache = _incomingCache.next;
- }
- }
-
- cleanup();
+ _incomingCache = null;
}
if(threadPerConnection != null)
@@ -595,13 +569,6 @@ public final class ConnectionI extends IceInternal.EventHandler implements Conne
}
}
}
- finally
- {
- if(stream != null && stream != os)
- {
- stream.destroy();
- }
- }
}
public void
@@ -698,13 +665,6 @@ public final class ConnectionI extends IceInternal.EventHandler implements Conne
}
}
}
- finally
- {
- if(stream != null && stream != os)
- {
- stream.destroy();
- }
- }
}
private final static byte[] _requestBatchHdr =
@@ -799,10 +759,9 @@ public final class ConnectionI extends IceInternal.EventHandler implements Conne
{
//
// Destroy and reset the batch stream and batch count. We
- // cannot safe old requests in the batch stream, as they might
+ // cannot save old requests in the batch stream, as they might
// be corrupted due to incomplete marshaling.
//
- _batchStream.destroy();
_batchStream = new IceInternal.BasicStream(_instance);
_batchRequestNum = 0;
_batchRequestCompress = false;
@@ -902,20 +861,12 @@ public final class ConnectionI extends IceInternal.EventHandler implements Conne
throw _exception;
}
}
- finally
- {
- if(stream != null && stream != _batchStream)
- {
- stream.destroy();
- }
- }
synchronized(this)
{
//
// Reset the batch stream, and notify that flushing is over.
//
- _batchStream.destroy();
_batchStream = new IceInternal.BasicStream(_instance);
_batchRequestNum = 0;
_batchRequestCompress = false;
@@ -954,13 +905,6 @@ public final class ConnectionI extends IceInternal.EventHandler implements Conne
setState(StateClosed, ex);
}
}
- finally
- {
- if(stream != os)
- {
- stream.destroy();
- }
- }
synchronized(this)
{
@@ -1173,31 +1117,21 @@ public final class ConnectionI extends IceInternal.EventHandler implements Conne
}
}
- try
- {
- //
- // Asynchronous replies must be handled outside the thread
- // synchronization, so that nested calls are possible.
- //
- if(info.outAsync != null)
- {
- info.outAsync.__finished(info.stream);
- }
-
- //
- // Method invocation (or multiple invocations for batch messages)
- // must be done outside the thread synchronization, so that nested
- // calls are possible.
- //
- invokeAll(info.stream, info.invokeNum, info.requestId, info.compress, info.servantManager, info.adapter);
- }
- finally
+ //
+ // Asynchronous replies must be handled outside the thread
+ // synchronization, so that nested calls are possible.
+ //
+ if(info.outAsync != null)
{
- if(info.destroyStream)
- {
- info.stream.destroy();
- }
+ info.outAsync.__finished(info.stream);
}
+
+ //
+ // Method invocation (or multiple invocations for batch messages)
+ // must be done outside the thread synchronization, so that nested
+ // calls are possible.
+ //
+ invokeAll(info.stream, info.invokeNum, info.requestId, info.compress, info.servantManager, info.adapter);
}
public void
@@ -1211,7 +1145,6 @@ public final class ConnectionI extends IceInternal.EventHandler implements Conne
IceInternal.IntMap requests = null;
IceInternal.IntMap asyncRequests = null;
- IceInternal.Incoming in = null;
synchronized(this)
{
@@ -1251,12 +1184,6 @@ public final class ConnectionI extends IceInternal.EventHandler implements Conne
}
}
- while(in != null)
- {
- in.__destroy();
- in = in.next;
- }
-
if(requests != null)
{
java.util.Iterator i = requests.entryIterator();
@@ -1795,7 +1722,6 @@ public final class ConnectionI extends IceInternal.EventHandler implements Conne
}
IceInternal.BasicStream stream;
- boolean destroyStream;
int invokeNum;
int requestId;
byte compress;
@@ -1832,7 +1758,6 @@ public final class ConnectionI extends IceInternal.EventHandler implements Conne
IceInternal.BasicStream ustream = info.stream.uncompress(IceInternal.Protocol.headerSize);
if(ustream != info.stream)
{
- info.destroyStream = true;
info.stream = ustream;
}
}
@@ -1947,12 +1872,6 @@ public final class ConnectionI extends IceInternal.EventHandler implements Conne
catch(LocalException ex)
{
setState(StateClosed, ex);
-
- if(info.destroyStream)
- {
- info.stream.destroy();
- info.destroyStream = false;
- }
}
}
@@ -2218,121 +2137,111 @@ public final class ConnectionI extends IceInternal.EventHandler implements Conne
IceInternal.IntMap requests = null;
IceInternal.IntMap asyncRequests = null;
- try
+ synchronized(this)
{
- synchronized(this)
+ while(_state == StateHolding)
{
- while(_state == StateHolding)
+ try
{
- try
- {
- wait();
- }
- catch(InterruptedException ex)
- {
- }
+ wait();
}
-
- if(_state != StateClosed)
+ catch(InterruptedException ex)
{
- parseMessage(info);
}
+ }
+
+ if(_state != StateClosed)
+ {
+ parseMessage(info);
+ }
+ //
+ // parseMessage() can close the connection, so we must
+ // check for closed state again.
+ //
+ if(_state == StateClosed)
+ {
//
- // parseMessage() can close the connection, so we must
- // check for closed state again.
+ // We must make sure that nobody is sending when we close
+ // the transceiver.
//
- if(_state == StateClosed)
+ synchronized(_sendMutex)
{
- //
- // We must make sure that nobody is sending when we close
- // the transceiver.
- //
- synchronized(_sendMutex)
+ try
{
- try
- {
- _transceiver.close();
- }
- catch(LocalException ex)
- {
- exception = ex;
- }
-
- _transceiver = null;
- notifyAll();
+ _transceiver.close();
}
-
- //
- // We cannot simply return here. We have to make sure
- // that all requests (regular and async) are notified
- // about the closed connection below.
- //
- closed = true;
+ catch(LocalException ex)
+ {
+ exception = ex;
+ }
+
+ _transceiver = null;
+ notifyAll();
}
- if(_state == StateClosed || _state == StateClosing)
- {
- requests = _requests;
- _requests = new IceInternal.IntMap();
-
- asyncRequests = _asyncRequests;
- _asyncRequests = new IceInternal.IntMap();
- }
+ //
+ // We cannot simply return here. We have to make sure
+ // that all requests (regular and async) are notified
+ // about the closed connection below.
+ //
+ closed = true;
}
- //
- // Asynchronous replies must be handled outside the thread
- // synchronization, so that nested calls are possible.
- //
- if(info.outAsync != null)
+ if(_state == StateClosed || _state == StateClosing)
{
- info.outAsync.__finished(info.stream);
- }
-
- //
- // Method invocation (or multiple invocations for batch messages)
- // must be done outside the thread synchronization, so that nested
- // calls are possible.
- //
- invokeAll(info.stream, info.invokeNum, info.requestId, info.compress, info.servantManager,
- info.adapter);
+ requests = _requests;
+ _requests = new IceInternal.IntMap();
- if(requests != null)
- {
- java.util.Iterator i = requests.entryIterator();
- while(i.hasNext())
- {
- IceInternal.IntMap.Entry e = (IceInternal.IntMap.Entry)i.next();
- IceInternal.Outgoing out = (IceInternal.Outgoing)e.getValue();
- out.finished(_exception); // The exception is immutable at this point.
- }
+ asyncRequests = _asyncRequests;
+ _asyncRequests = new IceInternal.IntMap();
}
+ }
- if(asyncRequests != null)
- {
- java.util.Iterator i = asyncRequests.entryIterator();
- while(i.hasNext())
- {
- IceInternal.IntMap.Entry e = (IceInternal.IntMap.Entry)i.next();
- IceInternal.OutgoingAsync out = (IceInternal.OutgoingAsync)e.getValue();
- out.__finished(_exception); // The exception is immutable at this point.
- }
- }
+ //
+ // Asynchronous replies must be handled outside the thread
+ // synchronization, so that nested calls are possible.
+ //
+ if(info.outAsync != null)
+ {
+ info.outAsync.__finished(info.stream);
+ }
+
+ //
+ // Method invocation (or multiple invocations for batch messages)
+ // must be done outside the thread synchronization, so that nested
+ // calls are possible.
+ //
+ invokeAll(info.stream, info.invokeNum, info.requestId, info.compress, info.servantManager,
+ info.adapter);
- if(exception != null)
+ if(requests != null)
+ {
+ java.util.Iterator i = requests.entryIterator();
+ while(i.hasNext())
{
- assert(closed);
- throw exception;
- }
+ IceInternal.IntMap.Entry e = (IceInternal.IntMap.Entry)i.next();
+ IceInternal.Outgoing out = (IceInternal.Outgoing)e.getValue();
+ out.finished(_exception); // The exception is immutable at this point.
+ }
}
- finally
+
+ if(asyncRequests != null)
{
- if(info.destroyStream)
+ java.util.Iterator i = asyncRequests.entryIterator();
+ while(i.hasNext())
{
- info.stream.destroy();
+ IceInternal.IntMap.Entry e = (IceInternal.IntMap.Entry)i.next();
+ IceInternal.OutgoingAsync out = (IceInternal.OutgoingAsync)e.getValue();
+ out.__finished(_exception); // The exception is immutable at this point.
}
}
+
+ if(exception != null)
+ {
+ assert(closed);
+ throw exception;
+ }
}
}
@@ -2373,8 +2282,8 @@ public final class ConnectionI extends IceInternal.EventHandler implements Conne
{
in = _incomingCache;
_incomingCache = _incomingCache.next;
- in.next = null;
in.reset(_instance, this, adapter, response, compress);
+ in.next = null;
}
}
@@ -2386,27 +2295,11 @@ public final class ConnectionI extends IceInternal.EventHandler implements Conne
{
synchronized(_incomingCacheMutex)
{
- in.next = _incomingCache;
- _incomingCache = in;
+ in.next = _incomingCache;
+ _incomingCache = in;
}
}
- private void
- cleanup()
- {
- //
- // This should be called when we know that this object is no longer used,
- // so it is safe to reclaim resources.
- //
- // We do this here instead of in a finalizer because a C# finalizer
- // cannot invoke methods on other types of objects.
- //
- _batchStream.destroy();
- _batchStream = null;
-
- super.destroy();
- }
-
private class ThreadPerConnection extends Thread
{
public void
diff --git a/java/src/Ice/InputStreamI.java b/java/src/Ice/InputStreamI.java
index e8f26728c6f..1a4c1f23690 100644
--- a/java/src/Ice/InputStreamI.java
+++ b/java/src/Ice/InputStreamI.java
@@ -226,7 +226,6 @@ public class InputStreamI implements InputStream
{
if(_is != null)
{
- _is.destroy();
_is = null;
}
}
diff --git a/java/src/Ice/ObjectAdapterI.java b/java/src/Ice/ObjectAdapterI.java
index 7d9e4b4e57b..2064b0c1337 100644
--- a/java/src/Ice/ObjectAdapterI.java
+++ b/java/src/Ice/ObjectAdapterI.java
@@ -241,12 +241,15 @@ public final class ObjectAdapterI extends LocalObjectImpl implements ObjectAdapt
// Now we wait for until all incoming connection factories are
// finished.
//
- final int sz = _incomingConnectionFactories.size();
- for(int i = 0; i < sz; ++i)
+ if(_incomingConnectionFactories != null)
{
- IceInternal.IncomingConnectionFactory factory =
- (IceInternal.IncomingConnectionFactory)_incomingConnectionFactories.get(i);
- factory.waitUntilFinished();
+ final int sz = _incomingConnectionFactories.size();
+ for(int i = 0; i < sz; ++i)
+ {
+ IceInternal.IncomingConnectionFactory factory =
+ (IceInternal.IncomingConnectionFactory)_incomingConnectionFactories.get(i);
+ factory.waitUntilFinished();
+ }
}
//
@@ -279,7 +282,10 @@ public final class ObjectAdapterI extends LocalObjectImpl implements ObjectAdapt
// We're done, now we can throw away all incoming connection
// factories.
//
- _incomingConnectionFactories.clear();
+ // For compatibility with C#, we set _incomingConnectionFactories
+ // to null so that the finalizer does not invoke methods on objects.
+ //
+ _incomingConnectionFactories = null;
//
// Remove object references (some of them cyclic).
@@ -735,18 +741,26 @@ public final class ObjectAdapterI extends LocalObjectImpl implements ObjectAdapt
{
if(!_deactivated)
{
- _instance.logger().warning("object adapter `" + _name + "' has not been deactivated");
+ //
+ // For compatibility with C#, we do not invoke methods on other objects
+ // in a finalizer.
+ //
+ //_instance.logger().warning("object adapter `" + _name + "' has not been deactivated");
}
else if(_instance != null)
{
- _instance.logger().warning("object adapter `" + _name + "' deactivation had not been waited for");
+ //
+ // For compatibility with C#, we do not invoke methods on other objects
+ // in a finalizer.
+ //
+ //_instance.logger().warning("object adapter `" + _name + "' deactivation had not been waited for");
}
else
{
assert(_threadPool == null);
assert(_servantManager == null);
assert(_communicator == null);
- assert(_incomingConnectionFactories.isEmpty());
+ assert(_incomingConnectionFactories == null);
assert(_directCount == 0);
assert(!_waitForDeactivate);
}
diff --git a/java/src/Ice/OutputStreamI.java b/java/src/Ice/OutputStreamI.java
index 6c34371688f..4502a25ec4e 100644
--- a/java/src/Ice/OutputStreamI.java
+++ b/java/src/Ice/OutputStreamI.java
@@ -195,7 +195,6 @@ public class OutputStreamI implements OutputStream
{
if(_os != null)
{
- _os.destroy();
_os = null;
}
}
diff --git a/java/src/Ice/_ObjectDelM.java b/java/src/Ice/_ObjectDelM.java
index 718183e7c79..82695e5d7b5 100644
--- a/java/src/Ice/_ObjectDelM.java
+++ b/java/src/Ice/_ObjectDelM.java
@@ -204,7 +204,7 @@ public class _ObjectDelM implements _ObjectDel
getOutgoing(String operation, OperationMode mode, java.util.Map context)
throws IceInternal.NonRepeatable
{
- IceInternal.Outgoing out;
+ IceInternal.Outgoing out = null;
synchronized(__outgoingMutex)
{
@@ -216,8 +216,9 @@ public class _ObjectDelM implements _ObjectDel
{
out = __outgoingCache;
__outgoingCache = __outgoingCache.next;
- out.reset(operation, mode, context);
- }
+ out.reset(operation, mode, context);
+ out.next = null;
+ }
}
return out;
@@ -226,26 +227,10 @@ public class _ObjectDelM implements _ObjectDel
protected void
reclaimOutgoing(IceInternal.Outgoing out)
{
- synchronized(__outgoingMutex)
- {
- out.next = __outgoingCache;
- __outgoingCache = out;
- }
- }
-
- protected void
- finalize()
- throws Throwable
- {
synchronized(__outgoingMutex)
{
- while(__outgoingCache != null)
- {
- IceInternal.Outgoing next = __outgoingCache.next;
- __outgoingCache.destroy();
- __outgoingCache.next = null;
- __outgoingCache = next;
- }
+ out.next = __outgoingCache;
+ __outgoingCache = out;
}
}
diff --git a/java/src/IceInternal/BasicStream.java b/java/src/IceInternal/BasicStream.java
index a7db64fd848..5f73daf1611 100644
--- a/java/src/IceInternal/BasicStream.java
+++ b/java/src/IceInternal/BasicStream.java
@@ -15,9 +15,7 @@ public class BasicStream
BasicStream(IceInternal.Instance instance)
{
_instance = instance;
- _bufferManager = instance.bufferManager();
- _buf = _bufferManager.allocate(1500);
- assert(_buf != null);
+ allocate(1500);
_capacity = _buf.capacity();
_limit = 0;
assert(_buf.limit() == _capacity);
@@ -38,18 +36,6 @@ public class BasicStream
}
//
- // Do NOT use a finalizer, this would cause a severe performance
- // penalty! We must make sure that destroy() is called instead, to
- // reclaim resources.
- //
- public void
- destroy()
- {
- _bufferManager.reclaim(_buf);
- _buf = null;
- }
-
- //
// This function allows this object to be reused, rather than
// reallocated.
//
@@ -142,9 +128,7 @@ public class BasicStream
final int cap2 = _capacity << 1;
int newCapacity = cap2 > total ? cap2 : total;
_buf.limit(_limit);
- _buf.position(0);
- _buf = _bufferManager.reallocate(_buf, newCapacity);
- assert(_buf != null);
+ reallocate(newCapacity);
_capacity = _buf.capacity();
}
//
@@ -1928,9 +1912,7 @@ public class BasicStream
int newCapacity = cap2 > _limit ? cap2 : _limit;
_buf.limit(oldLimit);
int pos = _buf.position();
- _buf.position(0);
- _buf = _bufferManager.reallocate(_buf, newCapacity);
- assert(_buf != null);
+ reallocate(newCapacity);
_capacity = _buf.capacity();
_buf.limit(_capacity);
_buf.position(pos);
@@ -2222,13 +2204,45 @@ public class BasicStream
return buf.toString();
}
+ private void
+ allocate(int size)
+ {
+ java.nio.ByteBuffer buf = null;
+ try
+ {
+ //buf = java.nio.ByteBuffer.allocateDirect(size);
+ buf = java.nio.ByteBuffer.allocate(size);
+ }
+ catch(OutOfMemoryError ex)
+ {
+ Ice.MarshalException e = new Ice.MarshalException();
+ e.reason = "OutOfMemoryError occurred while allocating a ByteBuffer";
+ e.initCause(ex);
+ throw e;
+ }
+ buf.order(java.nio.ByteOrder.LITTLE_ENDIAN);
+ _buf = buf;
+ }
+
+ private void
+ reallocate(int size)
+ {
+ java.nio.ByteBuffer old = _buf;
+ assert(old != null);
+
+ allocate(size);
+ assert(_buf != null);
+
+ old.position(0);
+ _buf.put(old);
+ }
+
private IceInternal.Instance _instance;
- private BufferManager _bufferManager;
private java.nio.ByteBuffer _buf;
- private int _capacity; // Cache capacity to avoid excessive method calls
- private int _limit; // Cache limit to avoid excessive method calls
- private byte[] _stringBytes; // Reusable array for reading strings
- private char[] _stringChars; // Reusable array for reading strings
+ private int _capacity; // Cache capacity to avoid excessive method calls.
+ private int _limit; // Cache limit to avoid excessive method calls.
+ private byte[] _stringBytes; // Reusable array for reading strings.
+ private char[] _stringChars; // Reusable array for reading strings.
private static final class ReadEncaps
{
diff --git a/java/src/IceInternal/BufferManager.java b/java/src/IceInternal/BufferManager.java
deleted file mode 100644
index 325e1d5cdc6..00000000000
--- a/java/src/IceInternal/BufferManager.java
+++ /dev/null
@@ -1,129 +0,0 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-
-package IceInternal;
-
-final class BufferManager
-{
- BufferManager()
- {
- _head = null;
- }
-
- java.nio.ByteBuffer
- allocate(int size)
- {
- java.nio.ByteBuffer buf = getBuffer(size);
- if(buf == null)
- {
- try
- {
- //buf = java.nio.ByteBuffer.allocateDirect(size);
- buf = java.nio.ByteBuffer.allocate(size);
- }
- catch(OutOfMemoryError ex)
- {
- Ice.MemoryLimitException e = new Ice.MemoryLimitException();
- e.initCause(ex);
- throw e;
- }
- buf.order(java.nio.ByteOrder.LITTLE_ENDIAN);
- }
- return buf;
- }
-
- java.nio.ByteBuffer
- reallocate(java.nio.ByteBuffer old, int size)
- {
- java.nio.ByteBuffer buf = getBuffer(size);
- if(buf == null)
- {
- try
- {
- //buf = java.nio.ByteBuffer.allocateDirect(size);
- buf = java.nio.ByteBuffer.allocate(size);
- }
- catch(OutOfMemoryError ex)
- {
- Ice.MemoryLimitException e = new Ice.MemoryLimitException();
- e.initCause(ex);
- throw e;
- }
- buf.order(java.nio.ByteOrder.LITTLE_ENDIAN);
- }
- old.position(0);
- buf.put(old);
- reclaim(old);
- return buf;
- }
-
- synchronized void
- reclaim(java.nio.ByteBuffer buf)
- {
- BufferNode node;
- if(_nodeCache == null)
- {
- node = new BufferNode();
- }
- else
- {
- node = _nodeCache;
- _nodeCache = _nodeCache.next;
- }
- node.buf = buf;
- node.capacity = buf.capacity();
- node.next = _head;
- _head = node;
- }
-
- private synchronized java.nio.ByteBuffer
- getBuffer(int size)
- {
- BufferNode node = _head;
- BufferNode prev = null;
- while(node != null)
- {
- if(size <= node.capacity)
- {
- break;
- }
- prev = node;
- node = node.next;
- }
- if(node != null)
- {
- if(prev != null)
- {
- prev.next = node.next;
- }
- else
- {
- _head = node.next;
- }
- node.next = _nodeCache;
- _nodeCache = node;
- node.buf.clear();
- return node.buf;
- }
- else
- {
- return null;
- }
- }
-
- private static final class BufferNode
- {
- java.nio.ByteBuffer buf;
- int capacity;
- BufferNode next;
- }
-
- private BufferNode _head;
- private BufferNode _nodeCache;
-}
diff --git a/java/src/IceInternal/EventHandler.java b/java/src/IceInternal/EventHandler.java
index 66699da36dd..9fcfdffcec7 100644
--- a/java/src/IceInternal/EventHandler.java
+++ b/java/src/IceInternal/EventHandler.java
@@ -55,16 +55,6 @@ public abstract class EventHandler
return _instance;
}
- public void
- destroy()
- {
- synchronized(this)
- {
- _stream.destroy();
- _stream = null;
- }
- }
-
protected
EventHandler(Instance instance)
{
@@ -72,13 +62,6 @@ public abstract class EventHandler
_stream = new BasicStream(instance);
}
- protected synchronized void
- finalize()
- throws Throwable
- {
- IceUtil.Assert.FinalizerAssert(_stream == null);
- }
-
protected Instance _instance;
//
diff --git a/java/src/IceInternal/Incoming.java b/java/src/IceInternal/Incoming.java
index 0cebf970904..6f48fd124a5 100644
--- a/java/src/IceInternal/Incoming.java
+++ b/java/src/IceInternal/Incoming.java
@@ -20,23 +20,6 @@ final public class Incoming extends IncomingBase
}
//
- // Do NOT use a finalizer, this would cause a severe performance
- // penalty! We must make sure that __destroy() is called instead,
- // to reclaim resources.
- //
- public void
- __destroy()
- {
- if(_is != null)
- {
- _is.destroy();
- _is = null;
- }
-
- super.__destroy();
- }
-
- //
// This function allows this object to be reused, rather than
// reallocated.
//
diff --git a/java/src/IceInternal/IncomingAsync.java b/java/src/IceInternal/IncomingAsync.java
index 1bdcbc974ce..9ecfd31e97c 100644
--- a/java/src/IceInternal/IncomingAsync.java
+++ b/java/src/IceInternal/IncomingAsync.java
@@ -17,20 +17,6 @@ public class IncomingAsync extends IncomingBase
super(in);
}
- protected void
- finalize()
- {
- //
- // I must call __destroy() in the finalizer and not in
- // __response() or __exception(), because an exception may be
- // raised after the creation of an IncomingAsync but before
- // calling __response() or __exception(). This can happen if
- // an AMD operation raises an exception instead of calling
- // ice_response() or ice_exception().
- //
- __destroy();
- }
-
final protected void
__response(boolean ok)
{
diff --git a/java/src/IceInternal/IncomingBase.java b/java/src/IceInternal/IncomingBase.java
index 40a6ca1968e..69d4393e410 100644
--- a/java/src/IceInternal/IncomingBase.java
+++ b/java/src/IceInternal/IncomingBase.java
@@ -58,21 +58,6 @@ public class IncomingBase
}
//
- // Do NOT use a finalizer, this would cause a severe performance
- // penalty! We must make sure that __destroy() is called instead,
- // to reclaim resources.
- //
- public synchronized void
- __destroy()
- {
- if(_os != null)
- {
- _os.destroy();
- _os = null;
- }
- }
-
- //
// This function allows this object to be reused, rather than reallocated.
//
public void
diff --git a/java/src/IceInternal/IncomingConnectionFactory.java b/java/src/IceInternal/IncomingConnectionFactory.java
index 34e0d2bc487..86ff0182bcb 100644
--- a/java/src/IceInternal/IncomingConnectionFactory.java
+++ b/java/src/IceInternal/IncomingConnectionFactory.java
@@ -128,16 +128,6 @@ public final class IncomingConnectionFactory extends EventHandler
Ice.ConnectionI connection = (Ice.ConnectionI)p.next();
connection.waitUntilFinished();
}
-
- //
- // At this point we know that this factory is no longer used, so it is
- // safe to invoke destroy() on the EventHandler base class to reclaim
- // resources.
- //
- // We call this here instead of in the finalizer because a C# finalizer
- // cannot invoke methods on other types of objects.
- //
- super.destroy();
}
public Endpoint
@@ -454,7 +444,6 @@ public final class IncomingConnectionFactory extends EventHandler
_acceptor = null;
_connections = null;
_threadPerIncomingConnectionFactory = null;
- super.destroy();
}
Ice.SyscallException e = new Ice.SyscallException();
diff --git a/java/src/IceInternal/Instance.java b/java/src/IceInternal/Instance.java
index fb2e17747ba..815eabe7ab3 100644
--- a/java/src/IceInternal/Instance.java
+++ b/java/src/IceInternal/Instance.java
@@ -292,13 +292,6 @@ public final class Instance
adapterFactory.flushBatchRequests();
}
- public BufferManager
- bufferManager()
- {
- // No mutex lock, immutable.
- return _bufferManager;
- }
-
//
// Only for use by Ice.CommunicatorI
//
@@ -447,8 +440,6 @@ public final class Instance
_servantFactoryManager = new ObjectFactoryManager();
_objectAdapterFactory = new ObjectAdapterFactory(this, communicator);
-
- _bufferManager = new BufferManager(); // Must be created before the ThreadPool
}
catch(Ice.LocalException ex)
{
@@ -706,7 +697,6 @@ public final class Instance
private Ice.PluginManager _pluginManager;
private java.util.Map _defaultContext;
private static java.util.Map _emptyContext = new java.util.HashMap();
- private final BufferManager _bufferManager; // Immutable, not reset by destroy().
private static boolean _oneOffDone = false;
}
diff --git a/java/src/IceInternal/ObjectAdapterFactory.java b/java/src/IceInternal/ObjectAdapterFactory.java
index 7caa17ef2b7..f570684cbd0 100644
--- a/java/src/IceInternal/ObjectAdapterFactory.java
+++ b/java/src/IceInternal/ObjectAdapterFactory.java
@@ -75,17 +75,24 @@ public final class ObjectAdapterFactory
//
// Now we wait for deactivation of each object adapter.
//
- java.util.Iterator i = _adapters.values().iterator();
- while(i.hasNext())
- {
- Ice.ObjectAdapter adapter = (Ice.ObjectAdapter)i.next();
- adapter.waitForDeactivate();
- }
-
- //
- // We're done, now we can throw away the object adapters.
- //
- _adapters.clear();
+ if(_adapters != null)
+ {
+ java.util.Iterator i = _adapters.values().iterator();
+ while(i.hasNext())
+ {
+ Ice.ObjectAdapter adapter = (Ice.ObjectAdapter)i.next();
+ adapter.waitForDeactivate();
+ }
+
+ //
+ // We're done, now we can throw away the object adapters.
+ //
+ // For consistency with C#, we set _adapters to null
+ // so that our finalizer does not try to invoke any
+ // methods on member objects.
+ //
+ _adapters = null;
+ }
synchronized(this)
{
@@ -179,7 +186,7 @@ public final class ObjectAdapterFactory
{
assert(_instance == null);
assert(_communicator == null);
- assert(_adapters.size() == 0);
+ assert(_adapters == null);
assert(!_waitForShutdown);
super.finalize();
diff --git a/java/src/IceInternal/Outgoing.java b/java/src/IceInternal/Outgoing.java
index 81e945334e4..914944dc420 100644
--- a/java/src/IceInternal/Outgoing.java
+++ b/java/src/IceInternal/Outgoing.java
@@ -27,23 +27,6 @@ public final class Outgoing
}
//
- // Do NOT use a finalizer, this would cause a severe performance
- // penalty! We must make sure that destroy() is called instead, to
- // reclaim resources.
- //
- public void
- destroy()
- {
- assert(_is != null);
- _is.destroy();
- _is = null;
-
- assert(_os != null);
- _os.destroy();
- _os = null;
- }
-
- //
// This function allows this object to be reused, rather than
// reallocated.
//
diff --git a/java/src/IceInternal/OutgoingAsync.java b/java/src/IceInternal/OutgoingAsync.java
index 3c04ba877d1..7336b138929 100644
--- a/java/src/IceInternal/OutgoingAsync.java
+++ b/java/src/IceInternal/OutgoingAsync.java
@@ -438,16 +438,8 @@ public abstract class OutgoingAsync
{
_reference = null;
_connection = null;
- if(__is != null)
- {
- __is.destroy();
- __is = null;
- }
- if(__os != null)
- {
- __os.destroy();
- __os = null;
- }
+ __is = null;
+ __os = null;
_monitor.notify();
}
diff --git a/java/src/IceInternal/OutgoingConnectionFactory.java b/java/src/IceInternal/OutgoingConnectionFactory.java
index c6e060258db..5d8d13a0277 100644
--- a/java/src/IceInternal/OutgoingConnectionFactory.java
+++ b/java/src/IceInternal/OutgoingConnectionFactory.java
@@ -61,11 +61,15 @@ public final class OutgoingConnectionFactory
}
//
- // We want to wait until all connections are finished
- // outside the thread synchronization.
+ // We want to wait until all connections are finished outside the
+ // thread synchronization.
+ //
+ // For consistency with C#, we set _connections to null rather than to a
+ // new empty list so that our finalizer does not try to invoke any
+ // methods on member objects.
//
connections = _connections;
- _connections = new java.util.HashMap();
+ _connections = null;
}
//
@@ -543,7 +547,7 @@ public final class OutgoingConnectionFactory
throws Throwable
{
assert(_destroyed);
- assert(_connections.isEmpty());
+ assert(_connections == null);
super.finalize();
}
diff --git a/java/src/IceInternal/ThreadPool.java b/java/src/IceInternal/ThreadPool.java
index 67256e507ad..ac14d9fd97a 100644
--- a/java/src/IceInternal/ThreadPool.java
+++ b/java/src/IceInternal/ThreadPool.java
@@ -128,6 +128,10 @@ public final class ThreadPool
{
assert(_destroyed);
+ /**
+ * For compatibility with C#, we do not invoke methods on other objects
+ * in a finalizer.
+ *
try
{
if(_selector != null)
@@ -154,6 +158,7 @@ public final class ThreadPool
String s = "exception in `" + _prefix + "' while calling close():\n" + sw.toString();
_instance.logger().error(s);
}
+ */
super.finalize();
}
@@ -1150,8 +1155,6 @@ public final class ThreadPool
}
}
- stream.destroy();
-
if(TRACE_THREAD)
{
trace("run() terminated");