summaryrefslogtreecommitdiff
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/Ice/_ObjectDelM.java101
-rw-r--r--java/src/IceInternal/BasicStream.java177
-rw-r--r--java/src/IceInternal/Outgoing.java8
-rw-r--r--java/src/IceInternal/ThreadPool.java39
4 files changed, 207 insertions, 118 deletions
diff --git a/java/src/Ice/_ObjectDelM.java b/java/src/Ice/_ObjectDelM.java
index e4dcb4284c9..5347c233134 100644
--- a/java/src/Ice/_ObjectDelM.java
+++ b/java/src/Ice/_ObjectDelM.java
@@ -18,14 +18,21 @@ public class _ObjectDelM implements _ObjectDel
{
IceInternal.Outgoing __out =
new IceInternal.Outgoing(__connection, __reference, "ice_isA", true, __context);
- IceInternal.BasicStream __is = __out.is();
- IceInternal.BasicStream __os = __out.os();
- __os.writeString(__id);
- if (!__out.invoke())
+ try
{
- throw new UnknownUserException();
+ IceInternal.BasicStream __is = __out.is();
+ IceInternal.BasicStream __os = __out.os();
+ __os.writeString(__id);
+ if (!__out.invoke())
+ {
+ throw new UnknownUserException();
+ }
+ return __is.readBool();
+ }
+ finally
+ {
+ __out.destroy();
}
- return __is.readBool();
}
public void
@@ -34,9 +41,16 @@ public class _ObjectDelM implements _ObjectDel
{
IceInternal.Outgoing __out =
new IceInternal.Outgoing(__connection, __reference, "ice_ping", true, __context);
- if (!__out.invoke())
+ try
{
- throw new UnknownUserException();
+ if (!__out.invoke())
+ {
+ throw new UnknownUserException();
+ }
+ }
+ finally
+ {
+ __out.destroy();
}
}
@@ -46,13 +60,19 @@ public class _ObjectDelM implements _ObjectDel
{
IceInternal.Outgoing __out =
new IceInternal.Outgoing(__connection, __reference, "ice_ids", true, __context);
- IceInternal.BasicStream __is = __out.is();
- IceInternal.BasicStream __os = __out.os();
- if (!__out.invoke())
+ try
{
- throw new UnknownUserException();
+ IceInternal.BasicStream __is = __out.is();
+ if (!__out.invoke())
+ {
+ throw new UnknownUserException();
+ }
+ return __is.readStringSeq();
+ }
+ finally
+ {
+ __out.destroy();
}
- return __is.readStringSeq();
}
public String
@@ -61,13 +81,19 @@ public class _ObjectDelM implements _ObjectDel
{
IceInternal.Outgoing __out =
new IceInternal.Outgoing(__connection, __reference, "ice_id", true, __context);
- IceInternal.BasicStream __is = __out.is();
- IceInternal.BasicStream __os = __out.os();
- if (!__out.invoke())
+ try
{
- throw new UnknownUserException();
+ IceInternal.BasicStream __is = __out.is();
+ if (!__out.invoke())
+ {
+ throw new UnknownUserException();
+ }
+ return __is.readString();
+ }
+ finally
+ {
+ __out.destroy();
}
- return __is.readString();
}
public String[]
@@ -76,13 +102,19 @@ public class _ObjectDelM implements _ObjectDel
{
IceInternal.Outgoing __out =
new IceInternal.Outgoing(__connection, __reference, "ice_facets", true, __context);
- IceInternal.BasicStream __is = __out.is();
- IceInternal.BasicStream __os = __out.os();
- if (!__out.invoke())
+ try
+ {
+ IceInternal.BasicStream __is = __out.is();
+ if (!__out.invoke())
+ {
+ throw new UnknownUserException();
+ }
+ return __is.readStringSeq();
+ }
+ finally
{
- throw new UnknownUserException();
+ __out.destroy();
}
- return __is.readStringSeq();
}
public boolean
@@ -92,16 +124,23 @@ public class _ObjectDelM implements _ObjectDel
{
IceInternal.Outgoing __out =
new IceInternal.Outgoing(__connection, __reference, operation, nonmutating, __context);
- IceInternal.BasicStream __os = __out.os();
- __os.writeBlob(inParams);
- boolean ok = __out.invoke();
- if (__reference.mode == IceInternal.Reference.ModeTwoway)
+ try
{
- IceInternal.BasicStream __is = __out.is();
- int sz = __is.getReadEncapsSize();
- outParams.value = __is.readBlob(sz);
+ IceInternal.BasicStream __os = __out.os();
+ __os.writeBlob(inParams);
+ boolean ok = __out.invoke();
+ if (__reference.mode == IceInternal.Reference.ModeTwoway)
+ {
+ IceInternal.BasicStream __is = __out.is();
+ int sz = __is.getReadEncapsSize();
+ outParams.value = __is.readBlob(sz);
+ }
+ return ok;
+ }
+ finally
+ {
+ __out.destroy();
}
- return ok;
}
public void
diff --git a/java/src/IceInternal/BasicStream.java b/java/src/IceInternal/BasicStream.java
index b3713c73846..17ef3466c6b 100644
--- a/java/src/IceInternal/BasicStream.java
+++ b/java/src/IceInternal/BasicStream.java
@@ -22,19 +22,34 @@ public class BasicStream
_limit = 0;
assert(_buf.limit() == _capacity);
- _currentReadEncaps = null;
- _currentWriteEncaps = null;
+ _readEncapsStack = null;
+ _writeEncapsStack = null;
+ _readEncapsCache = null;
+ _writeEncapsCache = null;
}
protected void
finalize()
throws Throwable
{
- _bufferManager.reclaim(_buf);
+ if (_buf != null)
+ {
+ _bufferManager.reclaim(_buf);
+ }
super.finalize();
}
+ //
+ // Optional - deterministic destruction
+ //
+ public void
+ destroy()
+ {
+ _bufferManager.reclaim(_buf);
+ _buf = null;
+ }
+
public IceInternal.Instance
instance()
{
@@ -58,12 +73,18 @@ public class BasicStream
other._limit = _limit;
_limit = tmpLimit;
- java.util.LinkedList tmpStack = other._readEncapsStack;
+ ReadEncaps tmpRead = other._readEncapsStack;
other._readEncapsStack = _readEncapsStack;
- _readEncapsStack = tmpStack;
- tmpStack = other._writeEncapsStack;
+ _readEncapsStack = tmpRead;
+ tmpRead = other._readEncapsCache;
+ other._readEncapsCache = _readEncapsCache;
+ _readEncapsCache = tmpRead;
+ WriteEncaps tmpWrite = other._writeEncapsStack;
other._writeEncapsStack = _writeEncapsStack;
- _writeEncapsStack = tmpStack;
+ _writeEncapsStack = tmpWrite;
+ tmpWrite = other._writeEncapsCache;
+ other._writeEncapsCache = _writeEncapsCache;
+ _writeEncapsCache = tmpWrite;
}
private static final int MAX = 1024 * 1024; // TODO: Configurable
@@ -119,26 +140,30 @@ public class BasicStream
{
writeInt(0); // Encoding
writeInt(0); // Placeholder for the encapsulation length
- _currentWriteEncaps = new WriteEncaps();
- _currentWriteEncaps.encoding = 0;
- _currentWriteEncaps.start = _buf.position();
- _writeEncapsStack.add(_currentWriteEncaps);
- }
-
- public void
- endWriteEncaps()
- {
- assert(_currentWriteEncaps != null);
- final int start = _currentWriteEncaps.start;
- _writeEncapsStack.removeLast();
- if (_writeEncapsStack.isEmpty())
+ WriteEncaps curr = _writeEncapsCache;
+ if (curr != null)
{
- _currentWriteEncaps = null;
+ _writeEncapsCache = _writeEncapsCache.next;
}
else
{
- _currentWriteEncaps = (WriteEncaps)_writeEncapsStack.getLast();
+ curr = new WriteEncaps();
}
+ curr.encoding = 0;
+ curr.start = _buf.position();
+ curr.next = _writeEncapsStack;
+ _writeEncapsStack = curr;
+ }
+
+ public void
+ endWriteEncaps()
+ {
+ final WriteEncaps curr = _writeEncapsStack;
+ assert(curr != null);
+ final int start = curr.start;
+ _writeEncapsStack = curr.next;
+ curr.next = _writeEncapsCache;
+ _writeEncapsCache = curr;
final int sz = _buf.position() - start;
_buf.putInt(start - 4, sz);
}
@@ -152,26 +177,30 @@ public class BasicStream
throw new Ice.UnsupportedEncodingException();
}
int sz = readInt();
- _currentReadEncaps = new ReadEncaps();
- _currentReadEncaps.encoding = (byte)encoding;
- _currentReadEncaps.start = _buf.position();
- _readEncapsStack.add(_currentReadEncaps);
- }
-
- public void
- endReadEncaps()
- {
- assert(_currentReadEncaps != null);
- final int start = _currentReadEncaps.start;
- _readEncapsStack.removeLast();
- if (_readEncapsStack.isEmpty())
+ ReadEncaps curr = _readEncapsCache;
+ if (curr != null)
{
- _currentReadEncaps = null;
+ _readEncapsCache = _readEncapsCache.next;
}
else
{
- _currentReadEncaps = (ReadEncaps)_readEncapsStack.getLast();
+ curr = new ReadEncaps();
}
+ curr.encoding = (byte)encoding;
+ curr.start = _buf.position();
+ curr.next = _readEncapsStack;
+ _readEncapsStack = curr;
+ }
+
+ public void
+ endReadEncaps()
+ {
+ final ReadEncaps curr = _readEncapsStack;
+ assert(curr != null);
+ final int start = curr.start;
+ _readEncapsStack = curr.next;
+ curr.next = _readEncapsCache;
+ _readEncapsCache = curr;
final int sz = _buf.getInt(start - 4);
try
{
@@ -186,9 +215,9 @@ public class BasicStream
public void
checkReadEncaps()
{
- assert(_currentReadEncaps != null);
- final int sz = _buf.getInt(_currentReadEncaps.start - 4);
- if (sz != _buf.position() - _currentReadEncaps.start)
+ assert(_readEncapsStack != null);
+ final int sz = _buf.getInt(_readEncapsStack.start - 4);
+ if (sz != _buf.position() - _readEncapsStack.start)
{
throw new Ice.EncapsulationException();
}
@@ -197,8 +226,8 @@ public class BasicStream
public int
getReadEncapsSize()
{
- assert(_currentReadEncaps != null);
- return _buf.getInt(_currentReadEncaps.start - 4);
+ assert(_readEncapsStack != null);
+ return _buf.getInt(_readEncapsStack.start - 4);
}
public void
@@ -588,11 +617,10 @@ public class BasicStream
writeInt(len);
if (len > 0)
{
- final char[] arr = v.toCharArray();
expand(len);
for (int i = 0; i < len; i++)
{
- _buf.put((byte)arr[i]);
+ _buf.put((byte)v.charAt(i));
}
}
}
@@ -674,16 +702,23 @@ public class BasicStream
public void
writeObject(Ice.Object v)
{
- if (_currentWriteEncaps == null) // Lazy initialization
+ if (_writeEncapsStack == null) // Lazy initialization
{
- _currentWriteEncaps = new WriteEncaps();
- _writeEncapsStack.add(_currentWriteEncaps);
+ _writeEncapsStack = _writeEncapsCache;
+ if (_writeEncapsStack != null)
+ {
+ _writeEncapsCache = _writeEncapsCache.next;
+ }
+ else
+ {
+ _writeEncapsStack = new WriteEncaps();
+ }
}
Integer pos = null;
- if (_currentWriteEncaps.objectsWritten != null) // Lazy creation
+ if (_writeEncapsStack.objectsWritten != null) // Lazy creation
{
- pos = (Integer)_currentWriteEncaps.objectsWritten.get(v);
+ pos = (Integer)_writeEncapsStack.objectsWritten.get(v);
}
if (pos != null)
{
@@ -695,13 +730,12 @@ public class BasicStream
if (v != null)
{
- if (_currentWriteEncaps.objectsWritten == null)
+ if (_writeEncapsStack.objectsWritten == null)
{
- _currentWriteEncaps.objectsWritten =
- new java.util.IdentityHashMap();
+ _writeEncapsStack.objectsWritten = new java.util.IdentityHashMap();
}
- int num = _currentWriteEncaps.objectsWritten.size();
- _currentWriteEncaps.objectsWritten.put(v, new Integer(num));
+ int num = _writeEncapsStack.objectsWritten.size();
+ _writeEncapsStack.objectsWritten.put(v, new Integer(num));
writeString(v.__getClassIds()[0]);
v.__write(this);
}
@@ -717,22 +751,29 @@ public class BasicStream
{
Ice.Object v = null;
- if (_currentReadEncaps == null) // Lazy initialization
+ if (_readEncapsStack == null) // Lazy initialization
{
- _currentReadEncaps = new ReadEncaps();
- _readEncapsStack.add(_currentReadEncaps);
+ _readEncapsStack = _readEncapsCache;
+ if (_readEncapsStack != null)
+ {
+ _readEncapsCache = _readEncapsCache.next;
+ }
+ else
+ {
+ _readEncapsStack = new ReadEncaps();
+ }
}
final int pos = readInt();
if (pos >= 0)
{
- if (_currentReadEncaps.objectsRead == null || // Lazy creation
- pos >= _currentReadEncaps.objectsRead.size())
+ if (_readEncapsStack.objectsRead == null || // Lazy creation
+ pos >= _readEncapsStack.objectsRead.size())
{
throw new Ice.IllegalIndirectionException();
}
- v = (Ice.Object)_currentReadEncaps.objectsRead.get(pos);
+ v = (Ice.Object)_readEncapsStack.objectsRead.get(pos);
}
else
{
@@ -766,11 +807,11 @@ public class BasicStream
throw new Ice.NoObjectFactoryException();
}
}
- if (_currentReadEncaps.objectsRead == null) // Lazy creation
+ if (_readEncapsStack.objectsRead == null) // Lazy creation
{
- _currentReadEncaps.objectsRead = new java.util.ArrayList(10);
+ _readEncapsStack.objectsRead = new java.util.ArrayList(10);
}
- _currentReadEncaps.objectsRead.add(v);
+ _readEncapsStack.objectsRead.add(v);
v.__read(this);
}
@@ -868,6 +909,7 @@ public class BasicStream
int start;
byte encoding;
java.util.ArrayList objectsRead;
+ ReadEncaps next;
}
private static class WriteEncaps
@@ -875,10 +917,11 @@ public class BasicStream
int start;
byte encoding;
java.util.IdentityHashMap objectsWritten;
+ WriteEncaps next;
}
- private java.util.LinkedList _readEncapsStack = new java.util.LinkedList();
- private java.util.LinkedList _writeEncapsStack = new java.util.LinkedList();
- private ReadEncaps _currentReadEncaps;
- private WriteEncaps _currentWriteEncaps;
+ private ReadEncaps _readEncapsStack;
+ private WriteEncaps _writeEncapsStack;
+ private ReadEncaps _readEncapsCache;
+ private WriteEncaps _writeEncapsCache;
}
diff --git a/java/src/IceInternal/Outgoing.java b/java/src/IceInternal/Outgoing.java
index 0bb6f7de39c..0cd06592a63 100644
--- a/java/src/IceInternal/Outgoing.java
+++ b/java/src/IceInternal/Outgoing.java
@@ -72,9 +72,8 @@ public final class Outgoing
_os.startWriteEncaps();
}
- protected void
- finalize()
- throws Throwable
+ public void
+ destroy()
{
if (_state == StateUnsent &&
(_reference.mode == Reference.ModeBatchOneway ||
@@ -83,7 +82,8 @@ public final class Outgoing
_connection.abortBatchRequest();
}
- super.finalize();
+ _os.destroy();
+ _is.destroy();
}
// Returns true if ok, false if user exception.
diff --git a/java/src/IceInternal/ThreadPool.java b/java/src/IceInternal/ThreadPool.java
index 724c261e23f..de46b6764cc 100644
--- a/java/src/IceInternal/ThreadPool.java
+++ b/java/src/IceInternal/ThreadPool.java
@@ -592,31 +592,38 @@ catch (RuntimeException ex)
// ignore the event in this case.
//
BasicStream stream = new BasicStream(_instance);
- if (handler.readable())
+ try
{
- try
+ if (handler.readable())
{
- if (!read(handler)) // No data available.
+ try
{
+ if (!read(handler)) // No data available.
+ {
//System.out.println("ThreadPool - no input");
+ continue repeatSelect;
+ }
+ }
+ catch (Ice.TimeoutException ex) // Expected
+ {
continue repeatSelect;
}
- }
- catch (Ice.TimeoutException ex) // Expected
- {
- continue repeatSelect;
- }
- catch (Ice.LocalException ex)
- {
- handler.exception(ex);
- continue repeatSelect;
+ catch (Ice.LocalException ex)
+ {
+ handler.exception(ex);
+ continue repeatSelect;
+ }
+
+ stream.swap(handler._stream);
+ assert(stream.pos() == stream.size());
}
- stream.swap(handler._stream);
- assert(stream.pos() == stream.size());
+ handler.message(stream);
+ }
+ finally
+ {
+ stream.destroy();
}
-
- handler.message(stream);
break;
}