diff --git a/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/BufferManagerRead.java b/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/BufferManagerRead.java index d63f5382e..a00f543c5 100644 --- a/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/BufferManagerRead.java +++ b/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/BufferManagerRead.java @@ -41,7 +41,6 @@ package com.sun.corba.ee.impl.encoding; import java.nio.ByteBuffer; -import com.sun.corba.ee.impl.encoding.ByteBufferWithInfo; import com.sun.corba.ee.impl.protocol.giopmsgheaders.FragmentMessage; import com.sun.corba.ee.impl.protocol.giopmsgheaders.Message; @@ -55,18 +54,18 @@ public interface BufferManagerRead * in a fragment map (when collecting - GIOP 1.2 phase 1) or * in an active server requests map (when streaming - GIOP 1.2 phase 2). * - * As a model for implementation see IIOPInputStream's + * As a model for implementation see IIOPInputStream's * constructor of the same name. There are going to be some variations. * */ - public void processFragment ( ByteBuffer byteBuffer, + public void processFragment ( ByteBuffer byteBuffer, FragmentMessage header); /** * Case: called from CDRInputStream constructor before unmarshaling. - * + * * Does: * * this.bufQ.get() @@ -78,7 +77,7 @@ public void processFragment ( ByteBuffer byteBuffer, /** * Invoked when we run out of data to read. Obtains more data from the stream. */ - ByteBufferWithInfo underflow (ByteBufferWithInfo bbwi); + ByteBuffer underflow(ByteBuffer byteBuffer); /** * Returns true if this buffer manager reads fragments when it underflows. @@ -104,5 +103,5 @@ public void processFragment ( ByteBuffer byteBuffer, /* * Close BufferManagerRead and perform any oustanding cleanup. */ - public void close(ByteBufferWithInfo bbwi); + public void close(ByteBuffer byteBuffer); } diff --git a/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/BufferManagerReadGrow.java b/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/BufferManagerReadGrow.java index ab061aace..7fde1d5cf 100644 --- a/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/BufferManagerReadGrow.java +++ b/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/BufferManagerReadGrow.java @@ -41,7 +41,7 @@ package com.sun.corba.ee.impl.encoding; import java.nio.ByteBuffer; -import com.sun.corba.ee.spi.orb.ORB; + import com.sun.corba.ee.impl.protocol.giopmsgheaders.FragmentMessage; import com.sun.corba.ee.impl.protocol.giopmsgheaders.Message; import com.sun.corba.ee.spi.logging.ORBUtilSystemException; @@ -60,7 +60,7 @@ public void processFragment (ByteBuffer byteBuffer, FragmentMessage header) public void init(Message msg) {} - public ByteBufferWithInfo underflow (ByteBufferWithInfo bbwi) { + public ByteBuffer underflow(ByteBuffer byteBuffer) { throw wrapper.unexpectedEof() ; } @@ -88,7 +88,7 @@ public void mark(RestorableInputStream is) { } // This will never happen - public void fragmentationOccured(ByteBufferWithInfo newFragment) {} + public void fragmentationOccured(ByteBuffer byteBuffer) {} public void reset() { @@ -101,5 +101,5 @@ public void reset() { } // Nothing to close and cleanup. - public void close(ByteBufferWithInfo bbwi) {} + public void close(ByteBuffer byteBuffer) {} } diff --git a/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/BufferManagerReadStream.java b/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/BufferManagerReadStream.java index 73b72fd4d..539dbbc9e 100644 --- a/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/BufferManagerReadStream.java +++ b/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/BufferManagerReadStream.java @@ -88,14 +88,13 @@ private void bufferMessage(String msg, int bbAddr, String tail) {} @Transport public void processFragment(ByteBuffer byteBuffer, FragmentMessage msg) { - ByteBufferWithInfo bbwi = new ByteBufferWithInfo(byteBuffer); - bbwi.position(msg.getHeaderLength()); + byteBuffer.position(msg.getHeaderLength()); synchronized (fragmentQueue) { if (orb.transportDebugFlag) { logBufferMessage("processFragment() - queuing ByteByffer id (", byteBuffer, ") to fragment queue."); } - fragmentQueue.enqueue(bbwi); + fragmentQueue.enqueue(byteBuffer); endOfStream = !msg.moreFragmentsToFollow(); fragmentQueue.notify(); } @@ -106,9 +105,9 @@ private void underflowMessage(String msg, int rid) { } @Transport - public ByteBufferWithInfo underflow(ByteBufferWithInfo bbwi) { + public ByteBuffer underflow(ByteBuffer byteBuffer) { - ByteBufferWithInfo result; + ByteBuffer result; synchronized (fragmentQueue) { @@ -143,10 +142,10 @@ public ByteBufferWithInfo underflow(ByteBufferWithInfo bbwi) { result = fragmentQueue.dequeue(); // VERY IMPORTANT - // Release bbwi.byteBuffer to the ByteBufferPool only if + // Release byteBuffer to the ByteBufferPool only if // this BufferManagerStream is not marked for potential restore. - if (!markEngaged && bbwi != null) { - getByteBufferPool().releaseByteBuffer(bbwi.getByteBuffer()); + if (!markEngaged && byteBuffer != null) { + getByteBufferPool().releaseByteBuffer(byteBuffer); } } return result; @@ -163,14 +162,13 @@ public void init(Message msg) { } } - // Release any queued ByteBufferWithInfo's byteBuffers to the - // ByteBufferPoool + // Release any queued byteBuffers to the ByteBufferPoool @Transport - public void close(ByteBufferWithInfo bbwi) { + public void close(ByteBuffer byteBuffer) { int inputBbAddress = 0; - if (bbwi != null) { - inputBbAddress = System.identityHashCode(bbwi.getByteBuffer()); + if (byteBuffer != null) { + inputBbAddress = System.identityHashCode(byteBuffer); } ByteBufferPool byteBufferPool = getByteBufferPool(); @@ -184,11 +182,11 @@ public void close(ByteBufferWithInfo bbwi) { // on the stack. If one is found to equal, it will // not be released to the ByteBufferPool. - ByteBufferWithInfo abbwi; + ByteBuffer aBuffer; while (fragmentQueue.size() != 0) { - abbwi = fragmentQueue.dequeue(); - if (abbwi != null) { - byteBufferPool.releaseByteBuffer(abbwi.getByteBuffer()); + aBuffer = fragmentQueue.dequeue(); + if (aBuffer != null) { + byteBufferPool.releaseByteBuffer(aBuffer); } } } @@ -204,10 +202,10 @@ public void close(ByteBufferWithInfo bbwi) { // on the stack. If one is found to equal, it will // not be released to the ByteBufferPool. - for (ByteBufferWithInfo abbwi : fragmentStack) { - if (abbwi != null) { - if (inputBbAddress != System.identityHashCode(abbwi.getByteBuffer())) { - byteBufferPool.releaseByteBuffer(abbwi.getByteBuffer()); + for (ByteBuffer aBuffer : fragmentStack) { + if (aBuffer != null) { + if (inputBbAddress != System.identityHashCode(aBuffer)) { + byteBufferPool.releaseByteBuffer(aBuffer); } } } @@ -230,7 +228,7 @@ protected ByteBufferPool getByteBufferPool() { // List of fragment ByteBufferWithInfos received since // the mark was engaged. - private LinkedList fragmentStack = null; + private LinkedList fragmentStack = null; private RestorableInputStream inputStream = null; // Original state of the stream @@ -250,20 +248,16 @@ public void mark(RestorableInputStream inputStream) { } // Collects fragments received since the mark was engaged. - public void fragmentationOccured(ByteBufferWithInfo newFragment) { + public void fragmentationOccured(ByteBuffer newFrament) { if (!markEngaged) { return; } if (fragmentStack == null) { - fragmentStack = - new LinkedList(); + fragmentStack = new LinkedList(); } - ByteBufferWithInfo bbwi = newFragment.duplicate(); - bbwi.limit(newFragment.limit()); - bbwi.position(newFragment.position()); - fragmentStack.addFirst(bbwi); + fragmentStack.addFirst(newFrament.duplicate()); } public void reset() { @@ -280,8 +274,8 @@ public void reset() { if (fragmentStack != null && fragmentStack.size() != 0) { synchronized (fragmentQueue) { - for (ByteBufferWithInfo bbwi : fragmentStack) { - fragmentQueue.push(bbwi); + for (ByteBuffer aBuffer : fragmentStack) { + fragmentQueue.push(aBuffer); } } diff --git a/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/BufferManagerWrite.java b/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/BufferManagerWrite.java index 3d43bb77f..42b38499b 100644 --- a/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/BufferManagerWrite.java +++ b/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/BufferManagerWrite.java @@ -44,6 +44,8 @@ import com.sun.corba.ee.spi.logging.ORBUtilSystemException; +import java.nio.ByteBuffer; + /** * Defines the contract between the BufferManager and * CDR stream on the writing side. The CDR stream @@ -85,7 +87,7 @@ public boolean sentFullMessage() { /* * Invoked when we run out of room to write. Must either expand the buffer or send it as a fragment and clear it. */ - public abstract ByteBufferWithInfo overflow(ByteBufferWithInfo bbwi, int numBytesNeeded); + protected abstract ByteBuffer overflow(ByteBuffer byteBuffer, int numBytesNeeded); /** * Returns true if this buffer manager fragments when an overflow occurs. @@ -120,6 +122,7 @@ public boolean sentFullMessage() { public abstract void sendMessage (); + /** * A reference to the connection level stream will be required when * sending fragments. @@ -128,7 +131,6 @@ public void setOutputObject(Object outputObject) { this.outputObject = outputObject; } - /** * Close the BufferManagerWrite and do any outstanding cleanup. */ diff --git a/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/BufferManagerWriteGrow.java b/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/BufferManagerWriteGrow.java index c1d5f108a..0a3301334 100644 --- a/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/BufferManagerWriteGrow.java +++ b/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/BufferManagerWriteGrow.java @@ -65,21 +65,21 @@ public int getBufferSize() { return orb.getORBData().getGIOPBufferSize(); } - public ByteBufferWithInfo overflow(ByteBufferWithInfo bbwi, int numBytesNeeded) { - int newLength = bbwi.limit() * 2; + @Override + protected ByteBuffer overflow(ByteBuffer byteBuffer, int numBytesNeeded) { + int newLength = byteBuffer.limit() * 2; - while (bbwi.position() + numBytesNeeded >= newLength) + while (byteBuffer.position() + numBytesNeeded >= newLength) newLength = newLength * 2; ByteBufferPool byteBufferPool = orb.getByteBufferPool(); ByteBuffer newBB = byteBufferPool.getByteBuffer(newLength); - bbwi.flip(); - newBB.put(bbwi.toByteBuffer()); - - byteBufferPool.releaseByteBuffer(bbwi.getByteBuffer()); + byteBuffer.flip(); + newBB.put(byteBuffer); - return new ByteBufferWithInfo(newBB); + byteBufferPool.releaseByteBuffer(byteBuffer); + return newBB; } @Override diff --git a/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/BufferManagerWriteStream.java b/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/BufferManagerWriteStream.java index 66e93752a..f28f36963 100644 --- a/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/BufferManagerWriteStream.java +++ b/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/BufferManagerWriteStream.java @@ -39,6 +39,7 @@ */ package com.sun.corba.ee.impl.encoding; +import java.nio.ByteBuffer; import java.util.EmptyStackException; import sun.corba.Bridge; @@ -80,16 +81,15 @@ public int getBufferSize() { return orb.getORBData().getGIOPFragmentSize(); } - public ByteBufferWithInfo overflow(ByteBufferWithInfo bbwi, int numBytesNeeded) - { + protected ByteBuffer overflow(ByteBuffer byteBuffer, int numBytesNeeded) { // Set the fragment's moreFragments field to true - MessageBase.setFlag(bbwi, Message.MORE_FRAGMENTS_BIT); + MessageBase.setFlag(byteBuffer, Message.MORE_FRAGMENTS_BIT); try { sendFragment(false); } catch (SystemException se) { - // REVISIT: this part similar to - // CorbaClientRequestDispatchImpl.beginRequest() + // REVISIT: this part similar to + // CorbaClientRequestDispatchImpl.beginRequest() // and CorbaClientRequestDelegate.request() ContactInfoListIterator itr; try { @@ -98,7 +98,7 @@ public ByteBufferWithInfo overflow(ByteBufferWithInfo bbwi, int numBytesNeeded) // server side, don't reportException throw se; } - + // bug 6382377: must not lose exception in PI orb.getPIHandler().invokeClientPIEndingPoint( ReplyMessage.SYSTEM_EXCEPTION, se ) ; @@ -106,7 +106,7 @@ public ByteBufferWithInfo overflow(ByteBufferWithInfo bbwi, int numBytesNeeded) if (retry) { Bridge bridge = Bridge.get(); bridge.throwException(new RemarshalException()); - } else { + } else { // re-throw the SystemException throw se; } @@ -117,18 +117,18 @@ public ByteBufferWithInfo overflow(ByteBufferWithInfo bbwi, int numBytesNeeded) // REVISIT - need to account for case when needed > available // even after fragmenting. This is the large array case, so // the caller should retry when it runs out of space. - bbwi.position(0); - bbwi.limit(bbwi.capacity()); + byteBuffer.position(0); + byteBuffer.limit(byteBuffer.capacity()); // Now we must marshal in the fragment header/GIOP header // REVISIT - we can optimize this by not creating the fragment message - // each time. + // each time. FragmentMessage header = ((CDROutputObject)outputObject).getMessageHeader().createFragmentMessage(); header.write(((CDROutputObject)outputObject)); - return bbwi; + return byteBuffer; } @Override diff --git a/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/BufferQueue.java b/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/BufferQueue.java index d19c357f3..a93d23bce 100644 --- a/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/BufferQueue.java +++ b/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/BufferQueue.java @@ -39,24 +39,24 @@ */ package com.sun.corba.ee.impl.encoding; +import java.nio.ByteBuffer; import java.util.LinkedList; import java.util.NoSuchElementException; -import java.util.LinkedList; /** - * Simple unsynchronized queue implementation for ByteBufferWithInfos. + * Simple unsynchronized queue implementation for ByteBuffer. */ public class BufferQueue { - private LinkedList list = - new LinkedList(); + private LinkedList list = + new LinkedList(); - public void enqueue(ByteBufferWithInfo item) + public void enqueue(ByteBuffer item) { list.addLast(item); } - public ByteBufferWithInfo dequeue() throws NoSuchElementException + public ByteBuffer dequeue() throws NoSuchElementException { return list.removeFirst(); } @@ -66,9 +66,8 @@ public int size() return list.size(); } - // Adds the given ByteBufferWithInfo to the front - // of the queue. - public void push(ByteBufferWithInfo item) + // Adds the given ByteBuffer to the front of the queue. + public void push(ByteBuffer item) { list.addFirst(item); } diff --git a/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/ByteBufferWithInfo.java b/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/ByteBufferWithInfo.java deleted file mode 100644 index 40e295a16..000000000 --- a/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/ByteBufferWithInfo.java +++ /dev/null @@ -1,178 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common Development - * and Distribution License("CDDL") (collectively, the "License"). You - * may not use this file except in compliance with the License. You can - * obtain a copy of the License at - * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html - * or packager/legal/LICENSE.txt. See the License for the specific - * language governing permissions and limitations under the License. - * - * When distributing the software, include this License Header Notice in each - * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt. - * - * GPL Classpath Exception: - * Oracle designates this particular file as subject to the "Classpath" - * exception as provided by Oracle in the GPL Version 2 section of the License - * file that accompanied this code. - * - * Modifications: - * If applicable, add the following below the License Header, with the fields - * enclosed by brackets [] replaced by your own identifying information: - * "Portions Copyright [year] [name of copyright owner]" - * - * Contributor(s): - * If you wish your version of this file to be governed by only the CDDL or - * only the GPL Version 2, indicate your decision by adding "[Contributor] - * elects to include this software in this distribution under the [CDDL or GPL - * Version 2] license." If you don't indicate a single choice of license, a - * recipient has the option to distribute your version of this file under - * either the CDDL, the GPL Version 2 or to extend the choice of license to - * its licensees as provided above. However, if you add GPL Version 2 code - * and therefore, elected the GPL Version 2 license, then the option applies - * only if the new code is made subject to such option by the copyright - * holder. - */ - -package com.sun.corba.ee.impl.encoding; - -import com.sun.corba.ee.spi.trace.Transport; - -import java.nio.ByteBuffer; -import java.nio.ByteOrder; - - -@Transport -public class ByteBufferWithInfo -{ - private ByteBuffer byteBuffer; - - ByteBufferWithInfo(ByteBuffer byteBuffer) { - this.byteBuffer = byteBuffer; - } - - public byte get(int index) { - return byteBuffer.get(index); - } - - public ByteBufferWithInfo put(int index, byte b) { - byteBuffer.put(index, b); - return this; - } - - public ByteBuffer toByteBuffer() { - return byteBuffer; - } - - public ByteBufferWithInfo get(byte[] byteArray) { - byteBuffer.get(byteArray); - return this; - } - - public ByteBufferWithInfo get(byte[] buffer, int offset, int length) { - byteBuffer.get(buffer, offset, length); - return this; - } - - public ByteBufferWithInfo put(byte x) { - byteBuffer.put(x); - return this; - } - - public ByteBufferWithInfo put(byte[] buffer, int offset, int length) { - byteBuffer.put(buffer, offset, length); - return this; - } - - public ByteBuffer getByteBuffer() { - return byteBuffer; - } - - public ByteOrder order() { - return byteBuffer.order(); - } - - public ByteBufferWithInfo order(ByteOrder byteOrder) { - byteBuffer.order(byteOrder); - return this; - } - - public byte get() { - return byteBuffer.get(); - } - - public boolean hasRemaining() { - return byteBuffer.hasRemaining(); - } - - public int remaining() { - return byteBuffer.remaining(); - } - - public short getShort() { - return byteBuffer.getShort(); - } - - public long getLong() { - return byteBuffer.getLong(); - } - - public int getInt() { - return byteBuffer.getInt(); - } - - public ByteBufferWithInfo putLong(long x) { - byteBuffer.putLong(x); - return this; - } - - public ByteBufferWithInfo putInt(int x) { - byteBuffer.putInt(x); - return this; - } - - public ByteBufferWithInfo putShort(short x) { - byteBuffer.putShort(x); - return this; - } - - public int capacity() { - return byteBuffer.capacity(); - } - - public int limit() { - return byteBuffer.limit(); - } - - public int position() { - return byteBuffer.position(); - } - - public ByteBufferWithInfo position(int newPosition) { - byteBuffer.position(newPosition); - return this; - } - - public ByteBufferWithInfo flip() { - byteBuffer.flip(); - return this; - } - - public ByteBufferWithInfo limit(int theLength) { - byteBuffer.limit(theLength); - return this; - } - - public ByteBufferWithInfo slice() { - return new ByteBufferWithInfo(byteBuffer.slice()); - } - - ByteBufferWithInfo duplicate() { - return new ByteBufferWithInfo(byteBuffer.duplicate()); - } - -} diff --git a/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/CDRInputStream_1_0.java b/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/CDRInputStream_1_0.java index b7d95e080..0321b4b43 100644 --- a/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/CDRInputStream_1_0.java +++ b/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/CDRInputStream_1_0.java @@ -146,7 +146,7 @@ public class CDRInputStream_1_0 extends CDRInputStreamBase private static final int MAX_BLOCK_LENGTH = 0x7fffff00; protected BufferManagerRead bufferManagerRead; - protected ByteBufferWithInfo bbwi; + protected ByteBuffer byteBuffer; protected ORB orb; protected ValueHandler valueHandler = null; @@ -224,9 +224,9 @@ public CDRInputStreamBase dup() throw wrapper.couldNotDuplicateCdrInputStream( e ) ; } result.init(this.orb, - this.bbwi.getByteBuffer(), - this.bbwi.limit(), - this.bbwi.order(), + byteBuffer, + byteBuffer.limit(), + byteBuffer.order(), this.bufferManagerRead); return result; @@ -236,10 +236,10 @@ public CDRInputStreamBase dup() void init(org.omg.CORBA.ORB orb, ByteBuffer byteBuffer, int bufferSize, ByteOrder byteOrder, BufferManagerRead bufferManager) { this.orb = (ORB)orb; this.bufferManagerRead = bufferManager; - this.bbwi = new ByteBufferWithInfo(byteBuffer); - this.bbwi.position(0); - this.bbwi.order(byteOrder); - this.bbwi.limit(bufferSize); + this.byteBuffer = byteBuffer; + this.byteBuffer.position(0); + this.byteBuffer.order(byteOrder); + this.byteBuffer.limit(bufferSize); this.markAndResetHandler = bufferManagerRead.getMarkAndResetHandler(); } @@ -336,7 +336,7 @@ protected void checkBlockLength(int align, int dataSize) { // This probably means that we're in an RMI-IIOP // Serializable's readObject method or a custom marshaled // IDL type is reading too much/in an incorrect order - int requiredNumBytes = computeAlignment(bbwi.position(), align) + dataSize; + int requiredNumBytes = computeAlignment(byteBuffer.position(), align) + dataSize; if (blockLength != MAX_BLOCK_LENGTH && blockLength < get_offset() + requiredNumBytes) { @@ -348,7 +348,7 @@ blockLength < get_offset() + requiredNumBytes) { // back to its original location. if (checkForEndTag) { int nextLong = read_long(); - bbwi.position(bbwi.position() - 4); + byteBuffer.position(byteBuffer.position() - 4); // It was an end tag, so there wasn't enough data // left in the valuetype's encoding on the wire @@ -365,10 +365,10 @@ protected void alignAndCheck(int align, int n) { // WARNING: Must compute real alignment after calling // checkBlockLength since it may move the position - int alignResult = computeAlignment(bbwi.position(), align); - bbwi.position(bbwi.position() + alignResult); + int alignResult = computeAlignment(byteBuffer.position(), align); + byteBuffer.position(byteBuffer.position() + alignResult); - if (bbwi.position() + n > bbwi.limit()) { + if (byteBuffer.position() + n > byteBuffer.limit()) { grow(align, n); } } @@ -377,7 +377,7 @@ protected void alignAndCheck(int align, int n) { // This can be overridden.... @CdrRead protected void grow(int align, int n) { - bbwi = bufferManagerRead.underflow(bbwi); + byteBuffer = bufferManagerRead.underflow(byteBuffer); } @@ -386,7 +386,8 @@ protected void grow(int align, int n) { // public final void consumeEndian() { - bbwi.order(read_boolean() ? ByteOrder.LITTLE_ENDIAN : ByteOrder.BIG_ENDIAN ); + ByteOrder byteOrder = read_boolean() ? ByteOrder.LITTLE_ENDIAN : ByteOrder.BIG_ENDIAN; + byteBuffer.order(byteOrder); } public final boolean read_boolean() { @@ -407,19 +408,19 @@ public char read_wchar() { } // If we're talking to one of our legacy ORBs, do what they did: - return (char) bbwi.getShort(); + return (char) byteBuffer.getShort(); } @CdrRead public final byte read_octet() { alignAndCheck(1, 1); - return bbwi.get(); + return byteBuffer.get(); } @CdrRead public final short read_short() { alignAndCheck(2, 2); - return bbwi.getShort(); + return byteBuffer.getShort(); } public final short read_ushort() { @@ -429,7 +430,7 @@ public final short read_ushort() { @CdrRead public final int read_long() { alignAndCheck(4, 4); - return bbwi.getInt(); + return byteBuffer.getInt(); } public final int read_ulong() { @@ -439,7 +440,7 @@ public final int read_ulong() { @CdrRead public final long read_longlong() { alignAndCheck(8, 8); - return bbwi.getLong(); + return byteBuffer.getLong(); } public final long read_ulonglong() { @@ -530,14 +531,14 @@ private String legacyReadString(int len) { int numRead = 0; while (numRead < len) { - if (!bbwi.hasRemaining()) grow(1, 1); - int avail = bbwi.remaining(); + if (!byteBuffer.hasRemaining()) grow(1, 1); + int avail = byteBuffer.remaining(); int wanted = len - numRead; int bytes = (wanted < avail) ? wanted : avail; // Microbenchmarks are showing a loop of ByteBuffer.get(int) being // faster than ByteBuffer.get(byte[], int, int). for (int i=0; i bbwi.limit()) { + if (byteBuffer.position() + 1 > byteBuffer.limit()) { alignAndCheck(1, 1); } - bbwi.get(); + byteBuffer.get(); return new String(c); } @@ -608,10 +609,10 @@ public final void read_octet_array(byte[] buffer, int offset, int length) { int numWritten = 0; while (numWritten < length) { - if (!bbwi.hasRemaining()) grow(1, 1); + if (!byteBuffer.hasRemaining()) grow(1, 1); - int count = Math.min(length - numWritten, bbwi.remaining()); - bbwi.get(buffer, numWritten + offset, count); + int count = Math.min(length - numWritten, byteBuffer.remaining()); + byteBuffer.get(buffer, numWritten + offset, count); numWritten += count; } } @@ -1535,7 +1536,7 @@ private void readEndTag() { // again. Even with fragmentation, we'll always be able // to do this. if (anEndTag != chunkedValueNestingLevel) { - bbwi.position(bbwi.position() - 4); + byteBuffer.position(byteBuffer.position() - 4); } } else { // When talking to Kestrel (JDK 1.3) or Ladybird (JDK 1.3.1), we use our old @@ -1543,7 +1544,7 @@ private void readEndTag() { // isn't what we expected, we back up, assuming // compaction. if (anEndTag != end_flag) { - bbwi.position(bbwi.position() - 4); + byteBuffer.position(byteBuffer.position() - 4); } } @@ -1559,7 +1560,7 @@ private void readEndTag() { } protected int get_offset() { - return bbwi.position(); + return byteBuffer.position(); } @InfoMethod @@ -1585,7 +1586,7 @@ private void start_block() { blockLength += get_offset(); // _REVISIT_ unsafe, should use a Java long } else { blockLength = MAX_BLOCK_LENGTH; - bbwi.position(bbwi.position() - 4); + byteBuffer.position(byteBuffer.position() - 4); } } @@ -1621,7 +1622,7 @@ private void handleEndOfValue() { // Peek next long int nextLong = read_long(); peekNextLong( nextLong ) ; - bbwi.position(bbwi.position() - 4); + byteBuffer.position(byteBuffer.position() - 4); // We did find an end tag, so we're done. readEndTag // should take care of making sure it's the correct @@ -1809,7 +1810,7 @@ private String read_repositoryId() { return result; } - throw wrapper.badRepIdIndirection( bbwi.position() ) ; // todo test this case + throw wrapper.badRepIdIndirection(byteBuffer.position()) ; // todo test this case } @CdrRead @@ -1832,7 +1833,7 @@ private String read_codebase_URL() { return result; } - throw wrapper.badCodebaseIndirection( bbwi.position() ) ; // todo test this case + throw wrapper.badCodebaseIndirection(byteBuffer.position()) ; // todo test this case } /* DataInputStream methods */ @@ -1968,20 +1969,20 @@ public String[] _truncatable_ids() { } public int getBufferLength() { - return bbwi.limit(); // todo test this + return byteBuffer.limit(); } public void setBufferLength(int value) { - bbwi.limit(value); + byteBuffer.limit(value); } public void setIndex(int value) { - bbwi.position(value); + byteBuffer.position(value); } @Override public ByteOrder getByteOrder() { - return bbwi.order(); + return byteBuffer.order(); } public void orb(org.omg.CORBA.ORB orb) { @@ -2003,12 +2004,12 @@ private void skipToOffset(int offset) { int wanted; int bytes; - if (!bbwi.hasRemaining()) grow(1, 1); - int avail = bbwi.remaining(); + if (!byteBuffer.hasRemaining()) grow(1, 1); + int avail = byteBuffer.remaining(); wanted = len - n; bytes = (wanted < avail) ? wanted : avail; - bbwi.position(bbwi.position() + bytes); + byteBuffer.position(byteBuffer.position() + bytes); n += bytes; } } @@ -2018,8 +2019,7 @@ private void skipToOffset(int offset) { protected MarkAndResetHandler markAndResetHandler = null; - protected class StreamMemento - { + protected class StreamMemento { // These are the fields that may change after marking // the stream position, so we need to save them. private int blockLength_; @@ -2029,11 +2029,10 @@ protected class StreamMemento private int stringIndirection_; private boolean isChunked_; private ValueHandler valueHandler_; - private ByteBufferWithInfo bbwi_; + private ByteBuffer byteBuffer_; private boolean specialNoOptionalDataState_; - public StreamMemento() - { + public StreamMemento() { blockLength_ = blockLength; end_flag_ = end_flag; chunkedValueNestingLevel_ = chunkedValueNestingLevel; @@ -2042,9 +2041,7 @@ public StreamMemento() isChunked_ = isChunked; valueHandler_ = valueHandler; specialNoOptionalDataState_ = specialNoOptionalDataState; - bbwi_ = bbwi.duplicate(); - bbwi_.limit(bbwi.limit()); - bbwi_.position(bbwi.position()); + byteBuffer_ = byteBuffer.duplicate(); } } @@ -2064,7 +2061,7 @@ public void restoreInternalState(java.lang.Object streamMemento) { isChunked = mem.isChunked_; valueHandler = mem.valueHandler_; specialNoOptionalDataState = mem.specialNoOptionalDataState_; - bbwi = mem.bbwi_; + byteBuffer = mem.byteBuffer_; } public int getPosition() { @@ -2155,13 +2152,13 @@ char[] getConvertedChars(int numBytes, CodeSetConversion.BTCConverter converter) { - if (bbwi.remaining() >= numBytes) { + if (byteBuffer.remaining() >= numBytes) { // If the entire string is in this buffer, - // just convert directly from the bbwi rather than + // just convert directly from the buffer rather than // allocating and copying. - int pos = bbwi.position(); - char[] result = converter.getChars(bbwi.slice(), bbwi.position(), numBytes); - bbwi.position(pos + numBytes); + int pos = byteBuffer.position(); + char[] result = converter.getChars(byteBuffer.slice(), 0, numBytes); + byteBuffer.position(pos + numBytes); return result; } else { // Stretches across buffers. Unless we provide an @@ -2205,11 +2202,11 @@ protected CodeSetConversion.BTCConverter getWCharConverter() { */ void alignOnBoundary(int octetBoundary) { - int needed = computeAlignment(bbwi.position(), octetBoundary); + int needed = computeAlignment(byteBuffer.position(), octetBoundary); - if (bbwi.position() + needed <= bbwi.limit()) + if (byteBuffer.position() + needed <= byteBuffer.limit()) { - bbwi.position(bbwi.position() + needed); + byteBuffer.position(byteBuffer.position() + needed); } } @@ -2288,22 +2285,19 @@ public void end_value() { start_block(); } - @InfoMethod - private void bufferMessage( String head, int bbAddr, String tail ) { } - @Override @CdrRead public void close() throws IOException { // tell BufferManagerRead to release any ByteBuffers - getBufferManager().close(bbwi); + getBufferManager().close(byteBuffer); - if (bbwi != null && bbwi.getByteBuffer() != null) { + if (byteBuffer != null) { // release this stream's ByteBuffer to the pool ByteBufferPool byteBufferPool = orb.getByteBufferPool(); - byteBufferPool.releaseByteBuffer(bbwi.getByteBuffer()); - bbwi = null; + byteBufferPool.releaseByteBuffer(byteBuffer); + byteBuffer = null; } } } diff --git a/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/CDRInputStream_1_1.java b/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/CDRInputStream_1_1.java index b58ec09bc..f8fb06460 100644 --- a/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/CDRInputStream_1_1.java +++ b/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/CDRInputStream_1_1.java @@ -63,7 +63,7 @@ public CDRInputStreamBase dup() { @Override protected int get_offset() { - return bbwi.position() + fragmentOffset; + return byteBuffer.position() + fragmentOffset; } @Override @@ -74,16 +74,16 @@ protected void alignAndCheck(int align, int n) { // WARNING: Must compute real alignment after calling // checkBlockLength since it may move the position - int alignment = computeAlignment(bbwi.position(), align); + int alignment = computeAlignment(byteBuffer.position(), align); - if (bbwi.position() + n + alignment > bbwi.limit()) { + if (byteBuffer.position() + n + alignment > byteBuffer.limit()) { // Some other ORBs may have found a way to send 1.1 // fragments which put alignment bytes at the end // of a fragment - if (bbwi.position() + alignment == bbwi.limit()) + if (byteBuffer.position() + alignment == byteBuffer.limit()) { - bbwi.position(bbwi.position() + alignment); + byteBuffer.position(byteBuffer.position() + alignment); } grow(align, n); @@ -92,10 +92,10 @@ protected void alignAndCheck(int align, int n) { // fragmentation since the new bbwi.position() (after the header) // may require a different alignment. - alignment = computeAlignment(bbwi.position(), align); + alignment = computeAlignment(byteBuffer.position(), align); } - bbwi.position(bbwi.position() + alignment); + byteBuffer.position(byteBuffer.position() + alignment); } // @@ -106,9 +106,9 @@ protected void grow(int align, int n) { // Save the size of the current buffer for // possible fragmentOffset calculation - int oldSize = bbwi.position(); + int oldSize = byteBuffer.position(); - bbwi = bufferManagerRead.underflow(bbwi); + byteBuffer = bufferManagerRead.underflow(byteBuffer); if (bufferManagerRead.isFragmentOnUnderflow()) { @@ -116,9 +116,9 @@ protected void grow(int align, int n) { // a new fragment whose header has already been // unmarshalled. bbwi.position() should point to the // end of the header. - fragmentOffset += (oldSize - bbwi.position()); + fragmentOffset += (oldSize - byteBuffer.position()); - markAndResetHandler.fragmentationOccured(bbwi); + markAndResetHandler.fragmentationOccured(byteBuffer); } } diff --git a/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/CDRInputStream_1_2.java b/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/CDRInputStream_1_2.java index 69e74edd7..82f4f51c8 100644 --- a/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/CDRInputStream_1_2.java +++ b/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/CDRInputStream_1_2.java @@ -115,14 +115,14 @@ protected void alignAndCheck(int align, int n) { // NOTE: Change underlying ByteBuffer's position only if // alignIncr is less than or equal to underlying // ByteBuffer's limit. - int savedPosition = bbwi.position(); + int savedPosition = byteBuffer.position(); int alignIncr = computeAlignment(savedPosition,align); int bytesNeeded = alignIncr + n; - if (savedPosition + alignIncr <= bbwi.limit()) { - bbwi.position(savedPosition + alignIncr); + if (savedPosition + alignIncr <= byteBuffer.limit()) { + byteBuffer.position(savedPosition + alignIncr); } - if (savedPosition + bytesNeeded > bbwi.limit()) { + if (savedPosition + bytesNeeded > byteBuffer.limit()) { grow(1, n); } } diff --git a/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/CDROutputObject.java b/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/CDROutputObject.java index 6c6d6d156..48fa0872d 100644 --- a/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/CDROutputObject.java +++ b/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/CDROutputObject.java @@ -84,8 +84,8 @@ public class CDROutputObject extends org.omg.CORBA_2_3.portable.OutputStream // todo this is only used in a pair of legacy tests. Rewrite them as unit tests and remove this method. public void sendFirstFragment() { - ByteBufferWithInfo bbwi = getBufferManager().overflow(impl.getByteBufferWithInfo(), 0); - setPrivateFieldValue(impl, "bbwi", bbwi); + ByteBuffer buffer = getBufferManager().overflow(impl.getByteBuffer(), 0); + setPrivateFieldValue(impl, "byteBuffer", buffer); } protected void setPrivateFieldValue(Object obj, String fieldName, Object value) { @@ -209,20 +209,20 @@ public void writeTo(Connection connection) throws java.io.IOException { // Update the GIOP MessageHeader size field. // - ByteBufferWithInfo bbwi = impl.getByteBufferWithInfo(); + ByteBuffer byteBuffer = impl.getByteBuffer(); - getMessageHeader().setSize(bbwi.getByteBuffer(), bbwi.position()); + getMessageHeader().setSize(byteBuffer, byteBuffer.position()); ORB lorb = (ORB)orb() ; if (lorb != null) { TransportManager ctm = lorb.getTransportManager() ; MessageTraceManagerImpl mtm = (MessageTraceManagerImpl)ctm.getMessageTraceManager() ; if (mtm.isEnabled()) - mtm.recordDataSent( bbwi.getByteBuffer()) ; + mtm.recordDataSent(byteBuffer) ; } - bbwi.flip(); - connection.write(bbwi.getByteBuffer()); + byteBuffer.flip(); + connection.write(byteBuffer); } /** overrides create_input_stream from CDROutputStream */ @@ -241,7 +241,7 @@ public Connection getConnection() { // todo this is only used in a legacy test - rewrite the test as a unit test and remove this method public final int getBufferPosition() { - return impl.getByteBufferWithInfo().position(); + return impl.getByteBuffer().position(); } /* diff --git a/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/CDROutputStreamBase.java b/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/CDROutputStreamBase.java index 322c982dd..477fa243c 100644 --- a/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/CDROutputStreamBase.java +++ b/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/CDROutputStreamBase.java @@ -156,8 +156,6 @@ public abstract void writeTo(java.io.OutputStream s) abstract void dereferenceBuffer(); public abstract ByteBuffer getByteBuffer(); - public abstract ByteBufferWithInfo getByteBufferWithInfo(); - public abstract BufferManagerWrite getBufferManager(); public abstract void write_fixed(java.math.BigDecimal bigDecimal, short digits, short scale); diff --git a/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/CDROutputStream_1_0.java b/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/CDROutputStream_1_0.java index 7b088c74d..bc21260af 100644 --- a/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/CDROutputStream_1_0.java +++ b/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/CDROutputStream_1_0.java @@ -114,7 +114,7 @@ public class CDROutputStream_1_0 extends CDROutputStreamBase { private static final boolean BIG_ENDIAN = false; protected BufferManagerWrite bufferManagerWrite; - ByteBufferWithInfo bbwi; + ByteBuffer byteBuffer; protected ORB orb; protected static final ORBUtilSystemException wrapper = ORBUtilSystemException.self; @@ -184,8 +184,8 @@ public void init(org.omg.CORBA.ORB orb, this.orb = (ORB) orb; this.bufferManagerWrite = bufferManager; - this.bbwi = new ByteBufferWithInfo(allocateBuffer(orb, bufferManager, usePooledByteBuffers)); - this.bbwi.position(0); + byteBuffer = allocateBuffer(orb, bufferManager, usePooledByteBuffers); + byteBuffer.position(0); this.streamFormatVersion = streamFormatVersion; createRepositoryIdHandlers(); @@ -223,10 +223,10 @@ public byte[] toByteArray() { protected byte[] toByteArray(int start) { byte[] it; - it = new byte[bbwi.position() - start]; + it = new byte[byteBuffer.position() - start]; - bbwi.position(start); - bbwi.get(it); + byteBuffer.position(start); + byteBuffer.get(it); return it; } @@ -253,7 +253,7 @@ protected void handleSpecialChunkEnd() { protected final int computeAlignment(int align) { if (align > 1) { - int incr = bbwi.position() & (align - 1); + int incr = byteBuffer.position() & (align - 1); if (incr != 0) { return align - incr; } @@ -263,9 +263,9 @@ protected final int computeAlignment(int align) { } protected void alignAndReserve(int align, int n) { - bbwi.position(bbwi.position() + computeAlignment(align)); + byteBuffer.position(byteBuffer.position() + computeAlignment(align)); - if (bbwi.position() + n > bbwi.limit()) { + if (byteBuffer.position() + n > byteBuffer.limit()) { grow(align, n); } } @@ -276,7 +276,7 @@ protected void alignAndReserve(int align, int n) { // fragmentation policy for IIOP 1.1. // protected void grow(int align, int n) { - bbwi = bufferManagerWrite.overflow(bbwi, n); + byteBuffer = bufferManagerWrite.overflow(byteBuffer, n); } public final void putEndian() throws SystemException { @@ -300,7 +300,7 @@ void freeInternalCaches() { @PrimitiveWrite public void write_octet(byte x) { alignAndReserve(1, 1); - bbwi.put(x); + byteBuffer.put(x); } public final void write_boolean(boolean x) { @@ -323,8 +323,8 @@ public void write_char(char x) { } private void writeBigEndianWchar(char x) { - bbwi.put((byte) ((x >>> 8) & 0xFF)); - bbwi.put((byte) (x & 0xFF)); + byteBuffer.put((byte) ((x >>> 8) & 0xFF)); + byteBuffer.put((byte) (x & 0xFF)); } @PrimitiveWrite @@ -344,7 +344,7 @@ public void write_wchar(char x) { @PrimitiveWrite public void write_short(short x) { alignAndReserve(2, 2); - bbwi.putShort(x); + byteBuffer.putShort(x); } public final void write_ushort(short x) { @@ -354,7 +354,7 @@ public final void write_ushort(short x) { @PrimitiveWrite public void write_long(int x) { alignAndReserve(4, 4); - bbwi.putInt(x); + byteBuffer.putInt(x); } public final void write_ulong(int x) { @@ -365,7 +365,7 @@ public final void write_ulong(int x) { public void write_longlong(long x) { alignAndReserve(8, 8); - bbwi.putLong(x); + byteBuffer.putLong(x); } public final void write_ulonglong(long x) { @@ -451,10 +451,10 @@ void internalWriteOctetArray(byte[] value, int offset, int length) { int numWritten = 0; while (numWritten < length) { - if (!bbwi.hasRemaining()) alignAndReserve(1, 1); + if (!byteBuffer.hasRemaining()) alignAndReserve(1, 1); - int count = Math.min(length - numWritten, bbwi.remaining()); - bbwi.put(value, offset + numWritten, count); + int count = Math.min(length - numWritten, byteBuffer.remaining()); + byteBuffer.put(value, offset + numWritten, count); numWritten += count; } } @@ -918,7 +918,7 @@ private short getTypeModifier(ValueHelper factory) { * @return */ public int get_offset() { - return bbwi.position(); + return byteBuffer.position(); } @CdrWrite @@ -934,7 +934,7 @@ public void start_block() { // Note that get_offset is overridden in subclasses to handle fragmentation! // Thus blockSizePosition and blockSizeIndex are not always the same! blockSizePosition = get_offset(); - blockSizeIndex = bbwi.position(); + blockSizeIndex = byteBuffer.position(); } // Utility method which will hopefully decrease chunking complexity @@ -942,7 +942,7 @@ public void start_block() { // calling alignAndReserve. Otherwise, it's possible to get into // recursive scenarios which lose the chunking state. protected void writeLongWithoutAlign(int x) { - bbwi.putInt(x); + byteBuffer.putInt(x); } @InfoMethod @@ -978,18 +978,18 @@ public void end_block() { // Need to assert that blockSizeIndex == bbwi.position()? REVISIT - bbwi.position(bbwi.position() - 4); + byteBuffer.position(byteBuffer.position() - 4); blockSizeIndex = -1; blockSizePosition = -1; return; } - int oldSize = bbwi.position(); - bbwi.position(blockSizeIndex - 4); + int oldSize = byteBuffer.position(); + byteBuffer.position(blockSizeIndex - 4); writeLongWithoutAlign(oldSize - blockSizeIndex); - bbwi.position(oldSize); + byteBuffer.position(oldSize); blockSizeIndex = -1; blockSizePosition = -1; } @@ -1160,38 +1160,30 @@ public final void write_any_array(org.omg.CORBA.Any value[], int offset, int len // public void writeTo(java.io.OutputStream s) throws java.io.IOException { - byte[] tmpBuf = ORBUtility.getByteBufferArray(bbwi.toByteBuffer()); - s.write(tmpBuf, 0, bbwi.position()); + byte[] tmpBuf = ORBUtility.getByteBufferArray(byteBuffer); + s.write(tmpBuf, 0, byteBuffer.position()); } public void writeOctetSequenceTo(org.omg.CORBA.portable.OutputStream s) { - byte[] buf = ORBUtility.getByteBufferArray(bbwi.toByteBuffer()); - s.write_long(bbwi.position()); - s.write_octet_array(buf, 0, bbwi.position()); + byte[] buf = ORBUtility.getByteBufferArray(byteBuffer); + s.write_long(byteBuffer.position()); + s.write_octet_array(buf, 0, byteBuffer.position()); } public final int getSize() { - return bbwi.position(); + return byteBuffer.position(); } public int getIndex() { - return bbwi.position(); + return byteBuffer.position(); } public void setIndex(int value) { - bbwi.position(value); - } - - public ByteBufferWithInfo getByteBufferWithInfo() { - return bbwi; + byteBuffer.position(value); } public ByteBuffer getByteBuffer() { - ByteBuffer result = null; - if (bbwi != null) { - result = bbwi.getByteBuffer(); - } - return result; + return byteBuffer; } private void freeValueCache() { @@ -1350,11 +1342,11 @@ private void writeIDLValue(Serializable object, String repID) { private void writeEndTag(boolean chunked) { if (chunked) { if (get_offset() == end_flag_position) { - if (bbwi.position() == end_flag_index) { + if (byteBuffer.position() == end_flag_index) { // We are exactly at the same position and index as the // end of the last end tag. Thus, we can back up over it // and compact the tags. - bbwi.position(bbwi.position() - 4); + byteBuffer.position(byteBuffer.position() - 4); } else { // reg - is this even possible any more? // Special case in which we're at the beginning of a new // fragment, but the position is the same. We can't back up, @@ -1369,7 +1361,7 @@ private void writeEndTag(boolean chunked) { // Remember the last index and position. // These are only used when chunking. - end_flag_index = bbwi.position(); + end_flag_index = byteBuffer.position(); end_flag_position = get_offset(); chunkedValueNestingLevel++; @@ -1663,7 +1655,7 @@ private void startValueInfo(String repId, int offset, int position) { @CdrWrite public void start_value(String rep_id) { - startValueInfo(rep_id, get_offset(), bbwi.position()); + startValueInfo(rep_id, get_offset(), byteBuffer.position()); if (inBlock) { end_block(); @@ -1712,30 +1704,22 @@ public void end_value() { } } - @InfoMethod - private void releasingByteBuffer(int addr) { - } - @Override @CdrWrite public void close() throws IOException { // tell BufferManagerWrite to release any ByteBuffers getBufferManager().close(); - if (getByteBufferWithInfo() != null && getByteBuffer() != null) { + if (byteBuffer != null) { // release this stream's ByteBuffer to the pool ByteBufferPool byteBufferPool = orb.getByteBufferPool(); - byteBufferPool.releaseByteBuffer(getByteBuffer()); - bbwi = null; + byteBufferPool.releaseByteBuffer(byteBuffer); + byteBuffer = null; } } - @InfoMethod - private void releaseByteBuffer(int bbAddress) { - } - void dereferenceBuffer() { - bbwi = null; + byteBuffer = null; } } diff --git a/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/CDROutputStream_1_1.java b/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/CDROutputStream_1_1.java index cbded105d..4a97a0523 100644 --- a/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/CDROutputStream_1_1.java +++ b/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/CDROutputStream_1_1.java @@ -71,7 +71,7 @@ protected void alignAndReserve(int align, int n) { int alignment = computeAlignment(align); - if (bbwi.position() + n + alignment > bbwi.limit()) { + if (byteBuffer.position() + n + alignment > byteBuffer.limit()) { grow(align, n); // Must recompute the alignment after a grow. @@ -84,17 +84,17 @@ protected void alignAndReserve(int align, int n) { alignment = computeAlignment(align); } - bbwi.position(bbwi.position() + alignment); + byteBuffer.position(byteBuffer.position() + alignment); } @Override protected void grow(int align, int n) { // Save the current size for possible post-fragmentation calculation - int oldSize = bbwi.position(); + int oldSize = byteBuffer.position(); - bbwi = bufferManagerWrite.overflow(bbwi, n); + byteBuffer = bufferManagerWrite.overflow(byteBuffer, n); - // At this point, if we fragmented, we should have a ByteBufferWithInfo + // At this point, if we fragmented, we should have a ByteBuffer // with the fragment header already marshalled. The size and length fields // should be updated accordingly, and the fragmented flag should be set. if (bufferManagerWrite.isFragmentOnOverflow()) { @@ -103,13 +103,13 @@ protected void grow(int align, int n) { // At this point, oldSize is the entire length of the // previous buffer. bbwi.position() is the length of the // fragment header of this buffer. - fragmentOffset += (oldSize - bbwi.position()); + fragmentOffset += (oldSize - byteBuffer.position()); } } @Override public int get_offset() { - return bbwi.position() + fragmentOffset; + return byteBuffer.position() + fragmentOffset; } @Override diff --git a/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/CDROutputStream_1_2.java b/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/CDROutputStream_1_2.java index 5cb8d19d0..4c82b1fec 100644 --- a/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/CDROutputStream_1_2.java +++ b/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/CDROutputStream_1_2.java @@ -106,18 +106,18 @@ private void specialChunkCase() { } @Override protected void handleSpecialChunkBegin(int requiredSize) { // If we're chunking and the item won't fit in the buffer - if (inBlock && requiredSize + bbwi.position() > bbwi.limit()) { + if (inBlock && requiredSize + byteBuffer.position() > byteBuffer.limit()) { specialChunkCase() ; // Duplicating some code from end_block. Compute // and write the total chunk length. - int oldSize = bbwi.position(); - bbwi.position(blockSizeIndex - 4); + int oldSize = byteBuffer.position(); + byteBuffer.position(blockSizeIndex - 4); //write_long(oldSize - blockSizeIndex); writeLongWithoutAlign((oldSize - blockSizeIndex) + requiredSize); - bbwi.position(oldSize); + byteBuffer.position(oldSize); // Set the special flag so we don't end the chunk when // we fragment @@ -223,9 +223,9 @@ protected void alignAndReserve(int align, int n) { // is needed with respect to the next GIOP fragment // header since it ends on an 8 byte boundary. - bbwi.position(bbwi.position() + computeAlignment(align)); + byteBuffer.position(byteBuffer.position() + computeAlignment(align)); - if (bbwi.position() + n > bbwi.limit()) + if (byteBuffer.position() + n > byteBuffer.limit()) grow(align, n); } @@ -241,7 +241,7 @@ private void handlingFragmentCase() { } protected void grow(int align, int n) { // Save the current size for possible post-fragmentation calculation - int oldSize = bbwi.position(); + int oldSize = byteBuffer.position(); // See notes where specialChunk is defined, as well as the // above notes for primitiveAcrossFragmentedChunk. @@ -254,18 +254,18 @@ protected void grow(int align, int n) { // we don't actually close the chunk in that case. boolean handleChunk = (inBlock && !specialChunk); if (handleChunk) { - int oldIndex = bbwi.position(); + int oldIndex = byteBuffer.position(); - bbwi.position(blockSizeIndex - 4); + byteBuffer.position(blockSizeIndex - 4); writeLongWithoutAlign((oldIndex - blockSizeIndex) + n); - bbwi.position(oldIndex); + byteBuffer.position(oldIndex); } - bbwi = bufferManagerWrite.overflow(bbwi, n); + byteBuffer = bufferManagerWrite.overflow(byteBuffer, n); - // At this point, if we fragmented, we should have a ByteBufferWithInfo + // At this point, if we fragmented, we should have a ByteBuffer // with the fragment header already marshaled. The buflen and position // should be updated accordingly. if (bufferManagerWrite.isFragmentOnOverflow()) { @@ -274,7 +274,7 @@ protected void grow(int align, int n) { // At this point, oldSize is the entire length of the // previous buffer. bbwi.position() is the length of the // fragment header of this buffer. - fragmentOffset += (oldSize - bbwi.position()); + fragmentOffset += (oldSize - byteBuffer.position()); // We just fragmented, and need to signal that we should // start a new chunk after writing the primitive. diff --git a/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/CodeSetConversion.java b/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/CodeSetConversion.java index 725ffa771..a7b6a9f99 100644 --- a/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/CodeSetConversion.java +++ b/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/CodeSetConversion.java @@ -138,7 +138,7 @@ public abstract static class BTCConverter { // The same array may be used internally over multiple // calls. public abstract char[] getChars(byte[] bytes, int offset, int length); - public abstract char[] getChars(ByteBufferWithInfo buff, int offset, int length); + public abstract char[] getChars(ByteBuffer byteBuffer, int offset, int length); } @@ -338,10 +338,10 @@ public final int getNumChars() { return resultingNumChars; } - public char[] getChars(ByteBufferWithInfo buff, int offset, int numBytes) { + public char[] getChars(ByteBuffer byteBuffer, int offset, int numBytes) { try { - buff.limit(numBytes); // todo - the old implementation cached a clone of the buffer and results. How do we do that with a Grizzly Buffer? - CharBuffer charBuf = decoder.decode(buff.toByteBuffer()); + byteBuffer.limit(numBytes); + CharBuffer charBuf = decoder.decode(byteBuffer); resultingNumChars = charBuf.limit(); char[] buffer = new char[resultingNumChars]; charBuf.get(buffer, 0, resultingNumChars).position(0); @@ -466,17 +466,16 @@ private class UTF16BTCConverter extends JavaBTCConverter this.defaultByteOrder = defaultByteOrder; } - @Override - public char[] getChars(ByteBufferWithInfo bytes, int offset, int numBytes) { - byte [] marker = { bytes.get(), bytes.get() }; - bytes.position(0); + public char[] getChars(ByteBuffer byteBuffer, int offset, int numBytes) { + byte [] marker = {byteBuffer.get(), byteBuffer.get()}; + byteBuffer.position(0); if (hasUTF16ByteOrderMarker(marker, 0, numBytes)) { if (!converterUsesBOM) switchToConverter(OSFCodeSetRegistry.UTF_16); converterUsesBOM = true; - return super.getChars(bytes, offset, numBytes); + return super.getChars(byteBuffer, offset, numBytes); } else { if (converterUsesBOM) { if (defaultByteOrder == ByteOrder.LITTLE_ENDIAN) @@ -486,7 +485,7 @@ public char[] getChars(ByteBufferWithInfo bytes, int offset, int numBytes) { converterUsesBOM = false; } - return super.getChars(bytes, offset, numBytes); + return super.getChars(byteBuffer, offset, numBytes); } } diff --git a/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/MarkAndResetHandler.java b/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/MarkAndResetHandler.java index fdd544250..3d64c465a 100644 --- a/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/MarkAndResetHandler.java +++ b/orbmain/src/main/java/com/sun/corba/ee/impl/encoding/MarkAndResetHandler.java @@ -40,6 +40,8 @@ package com.sun.corba.ee.impl.encoding; +import java.nio.ByteBuffer; + /** * Defines an abstraction for a RestorableInputStream to * implement mark/reset. @@ -48,7 +50,7 @@ interface MarkAndResetHandler { void mark(RestorableInputStream inputStream); - void fragmentationOccured(ByteBufferWithInfo newFragment); + void fragmentationOccured(ByteBuffer byteBuffer); void reset(); } diff --git a/orbmain/src/main/java/com/sun/corba/ee/impl/protocol/giopmsgheaders/MessageBase.java b/orbmain/src/main/java/com/sun/corba/ee/impl/protocol/giopmsgheaders/MessageBase.java index 335b297e4..32bccc306 100644 --- a/orbmain/src/main/java/com/sun/corba/ee/impl/protocol/giopmsgheaders/MessageBase.java +++ b/orbmain/src/main/java/com/sun/corba/ee/impl/protocol/giopmsgheaders/MessageBase.java @@ -45,7 +45,6 @@ import java.nio.ByteBuffer; import java.util.Iterator; -import com.sun.corba.ee.impl.encoding.ByteBufferWithInfo; import org.omg.CORBA.CompletionStatus; import org.omg.CORBA.SystemException; import org.omg.IOP.TaggedProfile; @@ -753,10 +752,10 @@ public static Message createMessageError(GIOPVersion gv) { /** * Set a flag in the given buffer (fragment bit, byte order bit, etc) */ - public static void setFlag(ByteBufferWithInfo bbwi, byte flag) { - byte b = bbwi.get(6); - b |= (int) flag; - bbwi.put(6, b); + public static void setFlag(ByteBuffer byteBuffer, int flag) { + byte b = byteBuffer.get(6); + b |= flag; + byteBuffer.put(6, b); } private static void AreFragmentsAllowed(byte major, byte minor, byte flag, diff --git a/orbmain/src/main/java/com/sun/corba/ee/impl/transport/ByteBufferPoolImpl.java b/orbmain/src/main/java/com/sun/corba/ee/impl/transport/ByteBufferPoolImpl.java index d2444b48f..e7a54ed53 100644 --- a/orbmain/src/main/java/com/sun/corba/ee/impl/transport/ByteBufferPoolImpl.java +++ b/orbmain/src/main/java/com/sun/corba/ee/impl/transport/ByteBufferPoolImpl.java @@ -74,14 +74,6 @@ public ByteBufferPoolImpl(ORB orb) { } } - /** - * Locations where ByteBuffers are gotten from the pool: - * 1. ContactInfoBase.createMessageMediator() - * 2. ByteBufferWithInfo.growBuffer() - * 3. ByteBufferWithInfo(ORB, BufferManagerWrite) - constructor - * 4. SocketOrChannelConnectionImpl.doMinimalReadStrategy() - */ - /** Return a ByteBuffer of the requested size. */ public ByteBuffer getByteBuffer(int size) { if (useDirectBuffers) { @@ -108,16 +100,6 @@ public ByteBuffer getByteBuffer(int size) { } - /** - * Locations where ByteBuffers are released to the pool: - * 1. ByteBufferWithInfo.growBuffer() - * 2. CDROutputStream_1_0.close() - * 3. CDRInputStream_1_0.close() - * 4. BufferManagerReadStream.underflow() - * 5. BufferManagerWrite.close() - * 6. BufferManagerRead.close() - * 7. CorbaMessageMediatorImpl.releaseByteBufferToPool() - */ public void releaseByteBuffer(ByteBuffer buffer) { // nothing to do here other than help the garbage collector // Remove this, as it is not useful, and gets flagged by findbugs.