diff options
author | Mark Spruiell <mes@zeroc.com> | 2005-05-05 20:59:13 +0000 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2005-05-05 20:59:13 +0000 |
commit | 5be7b412439b4cf74de06051a4e64cbaed0f41e0 (patch) | |
tree | f9c224aae371cf4ea1218344c9b898290aa54d38 /java/src | |
parent | http://bugzilla.zeroc.com/bugzilla/show_bug.cgi?id=276 (diff) | |
download | ice-5be7b412439b4cf74de06051a4e64cbaed0f41e0.tar.bz2 ice-5be7b412439b4cf74de06051a4e64cbaed0f41e0.tar.xz ice-5be7b412439b4cf74de06051a4e64cbaed0f41e0.zip |
release references to Ice objects ASAP
Diffstat (limited to 'java/src')
-rw-r--r-- | java/src/Ice/ConnectionI.java | 327 | ||||
-rw-r--r-- | java/src/Ice/_ObjectDelM.java | 4 | ||||
-rw-r--r-- | java/src/IceInternal/BasicStream.java | 65 | ||||
-rw-r--r-- | java/src/IceInternal/Incoming.java | 14 | ||||
-rw-r--r-- | java/src/IceInternal/IncomingBase.java | 31 | ||||
-rw-r--r-- | java/src/IceInternal/Outgoing.java | 15 |
6 files changed, 246 insertions, 210 deletions
diff --git a/java/src/Ice/ConnectionI.java b/java/src/Ice/ConnectionI.java index e40a03af2b3..a88a31002fa 100644 --- a/java/src/Ice/ConnectionI.java +++ b/java/src/Ice/ConnectionI.java @@ -2039,6 +2039,8 @@ public final class ConnectionI extends IceInternal.EventHandler implements Conne boolean closed = false; + IceInternal.BasicStream stream = new IceInternal.BasicStream(_instance); + while(!closed) { // @@ -2046,202 +2048,207 @@ public final class ConnectionI extends IceInternal.EventHandler implements Conne // synchronization, because we use blocking accept. // - IceInternal.BasicStream stream = new IceInternal.BasicStream(_instance); - try { - stream.resize(IceInternal.Protocol.headerSize, true); - stream.pos(0); - _transceiver.read(stream, -1); - - int pos = stream.pos(); - assert(pos >= IceInternal.Protocol.headerSize); - stream.pos(0); - byte[] m = stream.readBlob(4); - if(m[0] != IceInternal.Protocol.magic[0] || m[1] != IceInternal.Protocol.magic[1] || - m[2] != IceInternal.Protocol.magic[2] || m[3] != IceInternal.Protocol.magic[3]) - { - BadMagicException ex = new BadMagicException(); - ex.badMagic = m; - throw ex; - } - byte pMajor = stream.readByte(); - byte pMinor = stream.readByte(); - if(pMajor != IceInternal.Protocol.protocolMajor) - { - UnsupportedProtocolException e = new UnsupportedProtocolException(); - e.badMajor = pMajor < 0 ? pMajor + 255 : pMajor; - e.badMinor = pMinor < 0 ? pMinor + 255 : pMinor; - e.major = IceInternal.Protocol.protocolMajor; - e.minor = IceInternal.Protocol.protocolMinor; - throw e; - } - byte eMajor = stream.readByte(); - byte eMinor = stream.readByte(); - if(eMajor != IceInternal.Protocol.encodingMajor) - { - UnsupportedEncodingException e = new UnsupportedEncodingException(); - e.badMajor = eMajor < 0 ? eMajor + 255 : eMajor; - e.badMinor = eMinor < 0 ? eMinor + 255 : eMinor; - e.major = IceInternal.Protocol.encodingMajor; - e.minor = IceInternal.Protocol.encodingMinor; - throw e; - } - byte messageType = stream.readByte(); - byte compress = stream.readByte(); - int size = stream.readInt(); - if(size < IceInternal.Protocol.headerSize) - { - throw new IllegalMessageSizeException(); - } - if(size > _instance.messageSizeMax()) - { - throw new MemoryLimitException(); - } - if(size > stream.size()) + try { - stream.resize(size, true); - } - stream.pos(pos); + stream.resize(IceInternal.Protocol.headerSize, true); + stream.pos(0); + _transceiver.read(stream, -1); - if(pos != stream.size()) - { - if(_endpoint.datagram()) + int pos = stream.pos(); + assert(pos >= IceInternal.Protocol.headerSize); + stream.pos(0); + byte[] m = stream.readBlob(4); + if(m[0] != IceInternal.Protocol.magic[0] || m[1] != IceInternal.Protocol.magic[1] || + m[2] != IceInternal.Protocol.magic[2] || m[3] != IceInternal.Protocol.magic[3]) { - if(warnUdp) - { - _logger.warning("DatagramLimitException: maximum size of " + pos + " exceeded"); - } - throw new DatagramLimitException(); + BadMagicException ex = new BadMagicException(); + ex.badMagic = m; + throw ex; } - else + byte pMajor = stream.readByte(); + byte pMinor = stream.readByte(); + if(pMajor != IceInternal.Protocol.protocolMajor) { - _transceiver.read(stream, -1); - assert(stream.pos() == stream.size()); + UnsupportedProtocolException e = new UnsupportedProtocolException(); + e.badMajor = pMajor < 0 ? pMajor + 255 : pMajor; + e.badMinor = pMinor < 0 ? pMinor + 255 : pMinor; + e.major = IceInternal.Protocol.protocolMajor; + e.minor = IceInternal.Protocol.protocolMinor; + throw e; } - } - } - catch(DatagramLimitException ex) // Expected. - { - continue; - } - catch(LocalException ex) - { - exception(ex); - } - - MessageInfo info = new MessageInfo(stream); - - LocalException exception = null; - - IceInternal.IntMap requests = null; - IceInternal.IntMap asyncRequests = null; - - synchronized(this) - { - while(_state == StateHolding) - { - try + byte eMajor = stream.readByte(); + byte eMinor = stream.readByte(); + if(eMajor != IceInternal.Protocol.encodingMajor) { - wait(); + UnsupportedEncodingException e = new UnsupportedEncodingException(); + e.badMajor = eMajor < 0 ? eMajor + 255 : eMajor; + e.badMinor = eMinor < 0 ? eMinor + 255 : eMinor; + e.major = IceInternal.Protocol.encodingMajor; + e.minor = IceInternal.Protocol.encodingMinor; + throw e; + } + byte messageType = stream.readByte(); + byte compress = stream.readByte(); + int size = stream.readInt(); + if(size < IceInternal.Protocol.headerSize) + { + throw new IllegalMessageSizeException(); } - catch(InterruptedException ex) + if(size > _instance.messageSizeMax()) { + throw new MemoryLimitException(); + } + if(size > stream.size()) + { + stream.resize(size, true); + } + stream.pos(pos); + + if(pos != stream.size()) + { + if(_endpoint.datagram()) + { + if(warnUdp) + { + _logger.warning("DatagramLimitException: maximum size of " + pos + " exceeded"); + } + throw new DatagramLimitException(); + } + else + { + _transceiver.read(stream, -1); + assert(stream.pos() == stream.size()); + } } } - - if(_state != StateClosed) + catch(DatagramLimitException ex) // Expected. + { + continue; + } + catch(LocalException ex) { - parseMessage(info); + exception(ex); } - // - // parseMessage() can close the connection, so we must - // check for closed state again. - // - if(_state == StateClosed) + MessageInfo info = new MessageInfo(stream); + + LocalException exception = null; + + IceInternal.IntMap requests = null; + IceInternal.IntMap asyncRequests = null; + + synchronized(this) { - // - // We must make sure that nobody is sending when we close - // the transceiver. - // - synchronized(_sendMutex) + while(_state == StateHolding) { try { - _transceiver.close(); + wait(); } - catch(LocalException ex) + catch(InterruptedException ex) { - exception = ex; } - - _transceiver = null; - notifyAll(); + } + + if(_state != StateClosed) + { + parseMessage(info); } // - // We cannot simply return here. We have to make sure - // that all requests (regular and async) are notified - // about the closed connection below. + // parseMessage() can close the connection, so we must + // check for closed state again. // - closed = true; - } + if(_state == StateClosed) + { + // + // We must make sure that nobody is sending when we close + // the transceiver. + // + synchronized(_sendMutex) + { + try + { + _transceiver.close(); + } + catch(LocalException ex) + { + exception = ex; + } + + _transceiver = null; + notifyAll(); + } - if(_state == StateClosed || _state == StateClosing) - { - requests = _requests; - _requests = 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; + } - asyncRequests = _asyncRequests; - _asyncRequests = new IceInternal.IntMap(); + if(_state == StateClosed || _state == StateClosing) + { + requests = _requests; + _requests = new IceInternal.IntMap(); + + asyncRequests = _asyncRequests; + _asyncRequests = new IceInternal.IntMap(); + } } - } - // - // 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); + // + // 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(requests != null) - { - java.util.Iterator i = requests.entryIterator(); - while(i.hasNext()) + if(requests != null) { - 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. + 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. + } } - } - if(asyncRequests != null) - { - java.util.Iterator i = asyncRequests.entryIterator(); - while(i.hasNext()) + if(asyncRequests != null) { - 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. + 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. + } } - } - if(exception != null) + if(exception != null) + { + assert(closed); + throw exception; + } + } + finally { - assert(closed); - throw exception; - } + stream.reset(); + } } } @@ -2282,7 +2289,7 @@ public final class ConnectionI extends IceInternal.EventHandler implements Conne { in = _incomingCache; _incomingCache = _incomingCache.next; - in.reset(_instance, this, adapter, response, compress); + in.reset(_instance, this, adapter, response, compress); in.next = null; } } @@ -2297,6 +2304,10 @@ public final class ConnectionI extends IceInternal.EventHandler implements Conne { in.next = _incomingCache; _incomingCache = in; + // + // Clear references to Ice objects as soon as possible. + // + _incomingCache.reclaim(); } } diff --git a/java/src/Ice/_ObjectDelM.java b/java/src/Ice/_ObjectDelM.java index 82695e5d7b5..e725a3af04b 100644 --- a/java/src/Ice/_ObjectDelM.java +++ b/java/src/Ice/_ObjectDelM.java @@ -231,6 +231,10 @@ public class _ObjectDelM implements _ObjectDel { out.next = __outgoingCache; __outgoingCache = out; + // + // Clear references to Ice objects as soon as possible. + // + __outgoingCache.reclaim(); } } diff --git a/java/src/IceInternal/BasicStream.java b/java/src/IceInternal/BasicStream.java index 5f73daf1611..e4555a5ac85 100644 --- a/java/src/IceInternal/BasicStream.java +++ b/java/src/IceInternal/BasicStream.java @@ -52,6 +52,7 @@ public class BasicStream _readEncapsStack.next = _readEncapsCache; _readEncapsCache = _readEncapsStack; _readEncapsStack = null; + _readEncapsCache.reset(); } if(_objectList != null) @@ -321,14 +322,7 @@ public class BasicStream WriteEncaps curr = _writeEncapsCache; if(curr != null) { - if(curr.toBeMarshaledMap != null) - { - curr.writeIndex = 0; - curr.toBeMarshaledMap.clear(); - curr.marshaledMap.clear(); - curr.typeIdIndex = 0; - curr.typeIdMap.clear(); - } + curr.reset(); _writeEncapsCache = _writeEncapsCache.next; } else @@ -353,12 +347,11 @@ public class BasicStream int sz = _buf.position() - start; // Size includes size and version. _buf.putInt(start, sz); - { - WriteEncaps curr = _writeEncapsStack; - _writeEncapsStack = curr.next; - curr.next = _writeEncapsCache; - _writeEncapsCache = curr; - } + WriteEncaps curr = _writeEncapsStack; + _writeEncapsStack = curr.next; + curr.next = _writeEncapsCache; + _writeEncapsCache = curr; + _writeEncapsCache.reset(); } public void @@ -368,13 +361,7 @@ public class BasicStream ReadEncaps curr = _readEncapsCache; if(curr != null) { - if(curr.patchMap != null) - { - curr.patchMap.clear(); - curr.unmarshaledMap.clear(); - curr.typeIdIndex = 0; - curr.typeIdMap.clear(); - } + curr.reset(); _readEncapsCache = _readEncapsCache.next; } else @@ -436,12 +423,11 @@ public class BasicStream throw new Ice.UnmarshalOutOfBoundsException(); } - { - ReadEncaps curr = _readEncapsStack; - _readEncapsStack = curr.next; - curr.next = _readEncapsCache; - _readEncapsCache = curr; - } + ReadEncaps curr = _readEncapsStack; + _readEncapsStack = curr.next; + curr.next = _readEncapsCache; + _readEncapsCache = curr; + _readEncapsCache.reset(); } public void @@ -2257,6 +2243,18 @@ public class BasicStream int typeIdIndex; java.util.TreeMap typeIdMap; ReadEncaps next; + + void + reset() + { + if(patchMap != null) + { + patchMap.clear(); + unmarshaledMap.clear(); + typeIdIndex = 0; + typeIdMap.clear(); + } + } } private static final class WriteEncaps @@ -2269,6 +2267,19 @@ public class BasicStream int typeIdIndex; java.util.TreeMap typeIdMap; WriteEncaps next; + + void + reset() + { + if(toBeMarshaledMap != null) + { + writeIndex = 0; + toBeMarshaledMap.clear(); + marshaledMap.clear(); + typeIdIndex = 0; + typeIdMap.clear(); + } + } } private ReadEncaps _readEncapsStack; diff --git a/java/src/IceInternal/Incoming.java b/java/src/IceInternal/Incoming.java index 6f48fd124a5..6a61a8063c4 100644 --- a/java/src/IceInternal/Incoming.java +++ b/java/src/IceInternal/Incoming.java @@ -20,8 +20,7 @@ final public class Incoming extends IncomingBase } // - // This function allows this object to be reused, rather than - // reallocated. + // These functions allow this object to be reused, rather than reallocated. // public void reset(Instance instance, Ice.ConnectionI connection, Ice.ObjectAdapter adapter, boolean response, byte compress) @@ -30,12 +29,19 @@ final public class Incoming extends IncomingBase { _is = new BasicStream(instance); } - else + + super.reset(instance, connection, adapter, response, compress); + } + + public void + reclaim() + { + if(_is != null) { _is.reset(); } - super.reset(instance, connection, adapter, response, compress); + super.reclaim(); } public void diff --git a/java/src/IceInternal/IncomingBase.java b/java/src/IceInternal/IncomingBase.java index 69d4393e410..1600b44fcc8 100644 --- a/java/src/IceInternal/IncomingBase.java +++ b/java/src/IceInternal/IncomingBase.java @@ -58,7 +58,7 @@ public class IncomingBase } // - // This function allows this object to be reused, rather than reallocated. + // These functions allow this object to be reused, rather than reallocated. // public void reset(Instance instance, Ice.ConnectionI connection, Ice.ObjectAdapter adapter, boolean response, byte compress) @@ -79,30 +79,33 @@ public class IncomingBase { _cookie = new Ice.LocalObjectHolder(); } - else - { - _cookie.value = null; - } _response = response; _compress = compress; - synchronized(this) + if(_os == null) { - if(_os == null) - { - _os = new BasicStream(instance); - } - else - { - _os.reset(); - } + _os = new BasicStream(instance); } _connection = connection; } + public void + reclaim() + { + if(_cookie != null) + { + _cookie.value = null; + } + + if(_os != null) + { + _os.reset(); + } + } + final protected void __warning(java.lang.Exception ex) { diff --git a/java/src/IceInternal/Outgoing.java b/java/src/IceInternal/Outgoing.java index 914944dc420..1371fc76e5b 100644 --- a/java/src/IceInternal/Outgoing.java +++ b/java/src/IceInternal/Outgoing.java @@ -27,7 +27,7 @@ public final class Outgoing } // - // This function allows this object to be reused, rather than + // These functions allow this object to be reused, rather than // reallocated. // public void @@ -37,15 +37,16 @@ public final class Outgoing _state = StateUnsent; _exception = null; - assert(_is != null); - _is.reset(); - - assert(_os != null); - _os.reset(); - writeHeader(operation, mode, context); } + public void + reclaim() + { + _is.reset(); + _os.reset(); + } + // Returns true if ok, false if user exception. public boolean invoke() |