From: Marek P. <ma...@us...> - 2002-03-06 17:59:39
|
Update of /cvsroot/javaprofiler/jpiimpl/net/sourceforge/javaprofiler/jpiimpl/commun In directory usw-pr-cvs1:/tmp/cvs-serv6696/net/sourceforge/javaprofiler/jpiimpl/commun Modified Files: Buffer.java CommunSocket.java IProf.java Log Message: communication improvements Index: Buffer.java =================================================================== RCS file: /cvsroot/javaprofiler/jpiimpl/net/sourceforge/javaprofiler/jpiimpl/commun/Buffer.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -r1.2 -r1.3 *** Buffer.java 21 Nov 2001 22:05:55 -0000 1.2 --- Buffer.java 6 Mar 2002 17:59:34 -0000 1.3 *************** *** 50,61 **** private byte[] _buf; ! /// size of buffer private int _size; /// Default constructor. public Buffer() { ! _size = 0; ! _buf = null; } --- 50,68 ---- private byte[] _buf; ! /// size of data in buffer private int _size; + /// size of whole buffer + private int _bufSize; + + /// number of bytes to allocate in one + private static final int RESERVED = 50; + /// Default constructor. public Buffer() { ! _size = 0; ! _bufSize = 0; ! _buf = null; } *************** *** 69,74 **** public Buffer( byte[] buf, int size) { ! _size = size; ! _buf = new byte[_size]; copyBuffer( _buf, buf, _size); --- 76,82 ---- public Buffer( byte[] buf, int size) { ! _size = size; ! _bufSize = size; ! _buf = new byte[_size]; copyBuffer( _buf, buf, _size); *************** *** 84,89 **** public Buffer useBuffer( byte[] buf, int size) { _size = size; - _buf = buf; return this; --- 92,102 ---- public Buffer useBuffer( byte[] buf, int size) { + if( _buf != buf) { + + _buf = buf; + _bufSize = size; + } + _size = size; return this; *************** *** 104,115 **** public int getSize() { return _size;} /** Clear buffer. It truncates buffer to zero length, ** everything stored in the buffer will be lost. */ ! public void clear() { ! ! _size = 0; ! _buf = null; ! } /** Put integer into buffer. By this method you can insert Java --- 117,132 ---- public int getSize() { return _size;} + /** Get size of buffer. This method returns + ** size of whole buffer, so a number which can be + ** greater or equal to size of data stored in buffer. + ** + ** @return size of whole buffer */ + + public int getBufSize() { return _bufSize;} + /** Clear buffer. It truncates buffer to zero length, ** everything stored in the buffer will be lost. */ ! public void clear() { _size = 0;} /** Put integer into buffer. By this method you can insert Java *************** *** 124,129 **** public Buffer putInt( int c) { ! _buf = copyBuffer( new byte[_size+4], _buf, _size); ! _size = _size+4; for( int i = 0; i < 4; i++) { --- 141,151 ---- public Buffer putInt( int c) { ! if( _size+4 > _bufSize) { ! ! _buf = copyBuffer( new byte[_bufSize+RESERVED], _buf, _size); ! _bufSize += RESERVED; ! } ! ! _size += 4; for( int i = 0; i < 4; i++) { Index: CommunSocket.java =================================================================== RCS file: /cvsroot/javaprofiler/jpiimpl/net/sourceforge/javaprofiler/jpiimpl/commun/CommunSocket.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -r1.3 -r1.4 *** CommunSocket.java 27 Jan 2002 22:56:11 -0000 1.3 --- CommunSocket.java 6 Mar 2002 17:59:34 -0000 1.4 *************** *** 153,157 **** } ! byte[] nbuf = new byte[size]; int pos = 0; --- 153,161 ---- } ! byte[] nbuf; ! ! if( size <= b.getBufSize()) nbuf = b.getBuffer(); ! else nbuf = new byte[size]; ! int pos = 0; Index: IProf.java =================================================================== RCS file: /cvsroot/javaprofiler/jpiimpl/net/sourceforge/javaprofiler/jpiimpl/commun/IProf.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -r1.12 -r1.13 *** IProf.java 4 Mar 2002 23:58:04 -0000 1.12 --- IProf.java 6 Mar 2002 17:59:34 -0000 1.13 *************** *** 244,248 **** throws COMMUN_Exception, ! UNAVAILABLE_Exception { if( _threadsSuspended) --- 244,248 ---- throws COMMUN_Exception, ! UNAVAILABLE_Exception { if( _threadsSuspended) *************** *** 272,276 **** throws COMMUN_Exception, ! UNAVAILABLE_Exception { if( !_threadsSuspended) --- 272,276 ---- throws COMMUN_Exception, ! UNAVAILABLE_Exception { if( !_threadsSuspended) *************** *** 301,305 **** throws COMMUN_Exception, ! UNAVAILABLE_Exception { if( _threadsSuspended || _gcDisabled == 0) --- 301,305 ---- throws COMMUN_Exception, ! UNAVAILABLE_Exception { if( _threadsSuspended || _gcDisabled == 0) *************** *** 327,331 **** throws COMMUN_Exception, ! UNAVAILABLE_Exception { if( _threadsSuspended) --- 327,331 ---- throws COMMUN_Exception, ! UNAVAILABLE_Exception { if( _threadsSuspended) *************** *** 353,357 **** throws COMMUN_Exception, ! UNAVAILABLE_Exception { if( _threadsSuspended || _gcDisabled > 0) --- 353,357 ---- throws COMMUN_Exception, ! UNAVAILABLE_Exception { if( _threadsSuspended || _gcDisabled > 0) *************** *** 1412,1416 **** /// constant for no optional argument in call to getAll()/getChanged() public static final int NO_OPTIONAL_ARG = 0; ! /** Iterator thru statistic data. This class implements ** an iterator which can be used to iterate thru --- 1412,1416 ---- /// constant for no optional argument in call to getAll()/getChanged() public static final int NO_OPTIONAL_ARG = 0; ! /** Iterator thru statistic data. This class implements ** an iterator which can be used to iterate thru *************** *** 1463,1466 **** --- 1463,1468 ---- _pos = 4; _numItems = _dataBuf.getInt( 0); + + if( !hasNext()) releaseBuffer(); } *************** *** 1550,1553 **** --- 1552,1557 ---- } + if( !hasNext()) releaseBuffer(); + return _stat; } *************** *** 1574,1577 **** --- 1578,1594 ---- throw new UnsupportedOperationException(); } + + /** Release internal iterator's buffer. It releases buffer. */ + + private void releaseBuffer() { + + if( _dataBuf.getBufSize() > _buf.getBufSize()) { + + _buf = _dataBuf; + _buf.clear(); + } + + _dataBuf = null; + } }; *************** *** 1672,1679 **** LinkedList list = new LinkedList(); ! while( iterator.hasNext()) { ! ! list.addLast( iterator.next()); ! } return list; --- 1689,1693 ---- LinkedList list = new LinkedList(); ! while( iterator.hasNext()) list.addLast( iterator.next()); return list; *************** *** 2134,2138 **** _buf.putInt( F_GET_CALLTREE); _buf.putInt( threadObjId); ! _commun.write( _buf); if( _commun.hasFailed()) throw new COMMUN_Exception(); --- 2148,2152 ---- _buf.putInt( F_GET_CALLTREE); _buf.putInt( threadObjId); ! _commun.write( _buf); if( _commun.hasFailed()) throw new COMMUN_Exception(); *************** *** 2216,2220 **** if( parent == null) break; - } --- 2230,2233 ---- *************** *** 2234,2238 **** /// internal buffer with binary data ! private Buffer _dataBuf; /** indication whether still use same object --- 2247,2251 ---- /// internal buffer with binary data ! private Buffer _dataBuf = null; /** indication whether still use same object *************** *** 2245,2249 **** /// output item (one item of the calltree) ! private sCallTree _item; /// internal buffer size --- 2258,2262 ---- /// output item (one item of the calltree) ! private sCallTree _item = null; /// internal buffer size *************** *** 2261,2264 **** --- 2274,2279 ---- _bufSize = _dataBuf.getSize(); + + if( !hasNext()) releaseBuffer(); } *************** *** 2290,2293 **** --- 2305,2310 ---- _pos = getCallTreeItem( _dataBuf, _pos, _item); + if( !hasNext()) releaseBuffer(); + return _item; } *************** *** 2300,2303 **** --- 2317,2333 ---- throw new UnsupportedOperationException(); } + + /** Release internal iterator's buffer. It releases buffer. */ + + private void releaseBuffer() { + + if( _dataBuf.getBufSize() > _buf.getBufSize()) { + + _buf = _dataBuf; + _buf.clear(); + } + + _dataBuf = null; + } }; *************** *** 2330,2334 **** catch( COMMUN_Exception e) { throw e;} catch( BAD_OBJ_ID_Exception e) { throw e;} ! catch( UNKNOWN_Exception e) { throw e;} Iterator iterator = --- 2360,2364 ---- catch( COMMUN_Exception e) { throw e;} catch( BAD_OBJ_ID_Exception e) { throw e;} ! catch( UNKNOWN_Exception e) { throw e;} Iterator iterator = |