harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From var...@apache.org
Subject svn commit: r527979 - in /harmony/enhanced: classlib/trunk/modules/nio/src/main/java/java/nio/ classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/ classlib/trunk/modules/nio/src/main/native/nio/shared/ drlvm/trunk/src/test/regress...
Date Thu, 12 Apr 2007 15:27:51 GMT
Author: varlax
Date: Thu Apr 12 08:27:49 2007
New Revision: 527979

URL: http://svn.apache.org/viewvc?view=rev&rev=527979
Log:
Fixed HARMONY-3591, HARMONY-3638 [classlib][nio] Flawed JNI support for direct buffer views
Regression test is added to DRLVM module.

Modified:
    harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/CharToByteBufferAdapter.java
    harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DirectByteBuffer.java
    harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DoubleToByteBufferAdapter.java
    harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/FloatToByteBufferAdapter.java
    harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/IntToByteBufferAdapter.java
    harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/LongToByteBufferAdapter.java
    harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/MappedByteBufferAdapter.java
    harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ShortToByteBufferAdapter.java
    harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/DirectBuffer.java
    harmony/enhanced/classlib/trunk/modules/nio/src/main/native/nio/shared/DirectBufferUtil.c
    harmony/enhanced/drlvm/trunk/src/test/regression/H0000/DirectByteBufferTest.c
    harmony/enhanced/drlvm/trunk/src/test/regression/H0000/DirectByteBufferTest.java

Modified: harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/CharToByteBufferAdapter.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/CharToByteBufferAdapter.java?view=diff&rev=527979&r1=527978&r2=527979
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/CharToByteBufferAdapter.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/CharToByteBufferAdapter.java
Thu Apr 12 08:27:49 2007
@@ -16,6 +16,8 @@
 
 package java.nio;
 
+import org.apache.harmony.nio.internal.DirectBuffer;
+import org.apache.harmony.luni.platform.PlatformAddress;
 
 
 /**
@@ -31,7 +33,7 @@
  * </p>
  * 
  */
-final class CharToByteBufferAdapter extends CharBuffer {
+final class CharToByteBufferAdapter extends CharBuffer implements DirectBuffer {
 
 	static CharBuffer wrap(ByteBuffer byteBuffer) {
 		return new CharToByteBufferAdapter(byteBuffer.slice());
@@ -44,6 +46,58 @@
 		this.byteBuffer = byteBuffer;
 		this.byteBuffer.clear();
 	}
+        
+        public int getByteCapacity() {
+            if (byteBuffer instanceof DirectBuffer) {
+                return ((DirectBuffer)byteBuffer).getByteCapacity();
+            } else {
+                assert false : byteBuffer;
+                return -1;
+            }            
+        }
+        
+        public PlatformAddress getEffectiveAddress() {
+            if (byteBuffer instanceof DirectBuffer) {
+                return ((DirectBuffer)byteBuffer).getEffectiveAddress();
+            } else {
+                assert false : byteBuffer;
+                return null;
+            }
+        }
+
+        public PlatformAddress getBaseAddress() {
+            if (byteBuffer instanceof DirectBuffer) {
+                return ((DirectBuffer)byteBuffer).getBaseAddress();
+            } else {
+                assert false : byteBuffer;
+                return null;
+            }
+        }
+            
+        public boolean isAddressValid() {
+            if (byteBuffer instanceof DirectBuffer) {
+                return ((DirectBuffer)byteBuffer).isAddressValid();
+            } else {
+                assert false : byteBuffer;
+                return false;
+            }
+        }
+
+        public void addressValidityCheck() {
+            if (byteBuffer instanceof DirectBuffer) {
+                ((DirectBuffer)byteBuffer).addressValidityCheck();
+            } else {
+                assert false : byteBuffer;
+            }
+        }
+            
+        public void free() {
+            if (byteBuffer instanceof DirectBuffer) {
+                ((DirectBuffer)byteBuffer).free();
+            } else {
+                assert false : byteBuffer;
+            }   
+        }
 
 	public CharBuffer asReadOnlyBuffer() {
 		CharToByteBufferAdapter buf = new CharToByteBufferAdapter(byteBuffer

Modified: harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DirectByteBuffer.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DirectByteBuffer.java?view=diff&rev=527979&r1=527978&r2=527979
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DirectByteBuffer.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DirectByteBuffer.java
Thu Apr 12 08:27:49 2007
@@ -269,4 +269,8 @@
     final protected boolean protectedHasArray() {
         return false;
     }
+    
+    public final int getByteCapacity() {
+        return capacity;
+    }
 }

Modified: harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DoubleToByteBufferAdapter.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DoubleToByteBufferAdapter.java?view=diff&rev=527979&r1=527978&r2=527979
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DoubleToByteBufferAdapter.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DoubleToByteBufferAdapter.java
Thu Apr 12 08:27:49 2007
@@ -16,6 +16,8 @@
 
 package java.nio;
 
+import org.apache.harmony.nio.internal.DirectBuffer;
+import org.apache.harmony.luni.platform.PlatformAddress;
 
 
 /**
@@ -31,7 +33,7 @@
  * </p>
  * 
  */
-final class DoubleToByteBufferAdapter extends DoubleBuffer {
+final class DoubleToByteBufferAdapter extends DoubleBuffer implements DirectBuffer {
 
 	static DoubleBuffer wrap(ByteBuffer byteBuffer) {
 		return new DoubleToByteBufferAdapter(byteBuffer.slice());
@@ -44,6 +46,58 @@
 		this.byteBuffer = byteBuffer;
 		this.byteBuffer.clear();
 	}
+
+        public int getByteCapacity() {
+            if (byteBuffer instanceof DirectBuffer) {
+                return ((DirectBuffer)byteBuffer).getByteCapacity();
+            } else {
+                assert false : byteBuffer;
+                return -1;
+            }            
+        }
+
+        public PlatformAddress getEffectiveAddress() {
+            if (byteBuffer instanceof DirectBuffer) {
+                return ((DirectBuffer)byteBuffer).getEffectiveAddress();
+            } else {
+                assert false : byteBuffer;
+                return null;
+            }
+        }
+
+        public PlatformAddress getBaseAddress() {
+            if (byteBuffer instanceof DirectBuffer) {
+                return ((DirectBuffer)byteBuffer).getBaseAddress();
+            } else {
+                assert false : byteBuffer;
+                return null;
+            }
+        }
+            
+        public boolean isAddressValid() {
+            if (byteBuffer instanceof DirectBuffer) {
+                return ((DirectBuffer)byteBuffer).isAddressValid();
+            } else {
+                assert false : byteBuffer;
+                return false;
+            }
+        }
+
+        public void addressValidityCheck() {
+            if (byteBuffer instanceof DirectBuffer) {
+                ((DirectBuffer)byteBuffer).addressValidityCheck();
+            } else {
+                assert false : byteBuffer;
+            }
+        }
+            
+        public void free() {
+            if (byteBuffer instanceof DirectBuffer) {
+                ((DirectBuffer)byteBuffer).free();
+            } else {
+                assert false : byteBuffer;
+            }   
+        }
 
 	public DoubleBuffer asReadOnlyBuffer() {
 		DoubleToByteBufferAdapter buf = new DoubleToByteBufferAdapter(

Modified: harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/FloatToByteBufferAdapter.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/FloatToByteBufferAdapter.java?view=diff&rev=527979&r1=527978&r2=527979
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/FloatToByteBufferAdapter.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/FloatToByteBufferAdapter.java
Thu Apr 12 08:27:49 2007
@@ -16,6 +16,8 @@
 
 package java.nio;
 
+import org.apache.harmony.nio.internal.DirectBuffer;
+import org.apache.harmony.luni.platform.PlatformAddress;
 
 
 /**
@@ -31,7 +33,7 @@
  * </p>
  * 
  */
-final class FloatToByteBufferAdapter extends FloatBuffer {
+final class FloatToByteBufferAdapter extends FloatBuffer implements DirectBuffer {
 
 	static FloatBuffer wrap(ByteBuffer byteBuffer) {
 		return new FloatToByteBufferAdapter(byteBuffer.slice());
@@ -44,6 +46,58 @@
 		this.byteBuffer = byteBuffer;
 		this.byteBuffer.clear();
 	}
+
+        public int getByteCapacity() {
+            if (byteBuffer instanceof DirectBuffer) {
+                return ((DirectBuffer)byteBuffer).getByteCapacity();
+            } else {
+                assert false : byteBuffer;
+                return -1;
+            }            
+        }
+
+        public PlatformAddress getEffectiveAddress() {
+            if (byteBuffer instanceof DirectBuffer) {
+                return ((DirectBuffer)byteBuffer).getEffectiveAddress();
+            } else {
+                assert false : byteBuffer;
+                return null;
+            }
+        }
+
+        public PlatformAddress getBaseAddress() {
+            if (byteBuffer instanceof DirectBuffer) {
+                return ((DirectBuffer)byteBuffer).getBaseAddress();
+            } else {
+                assert false : byteBuffer;
+                return null;
+            }
+        }
+            
+        public boolean isAddressValid() {
+            if (byteBuffer instanceof DirectBuffer) {
+                return ((DirectBuffer)byteBuffer).isAddressValid();
+            } else {
+                assert false : byteBuffer;
+                return false;
+            }
+        }
+
+        public void addressValidityCheck() {
+            if (byteBuffer instanceof DirectBuffer) {
+                ((DirectBuffer)byteBuffer).addressValidityCheck();
+            } else {
+                assert false : byteBuffer;
+            }
+        }
+            
+        public void free() {
+            if (byteBuffer instanceof DirectBuffer) {
+                ((DirectBuffer)byteBuffer).free();
+            } else {
+                assert false : byteBuffer;
+            }   
+        }
 
 	public FloatBuffer asReadOnlyBuffer() {
 		FloatToByteBufferAdapter buf = new FloatToByteBufferAdapter(byteBuffer

Modified: harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/IntToByteBufferAdapter.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/IntToByteBufferAdapter.java?view=diff&rev=527979&r1=527978&r2=527979
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/IntToByteBufferAdapter.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/IntToByteBufferAdapter.java
Thu Apr 12 08:27:49 2007
@@ -16,6 +16,8 @@
 
 package java.nio;
 
+import org.apache.harmony.nio.internal.DirectBuffer;
+import org.apache.harmony.luni.platform.PlatformAddress;
 
 
 /**
@@ -31,7 +33,7 @@
  * </p>
  * 
  */
-final class IntToByteBufferAdapter extends IntBuffer {
+final class IntToByteBufferAdapter extends IntBuffer implements DirectBuffer {
 
 	static IntBuffer wrap(ByteBuffer byteBuffer) {
 		return new IntToByteBufferAdapter(byteBuffer.slice());
@@ -44,6 +46,59 @@
 		this.byteBuffer = byteBuffer;
 		this.byteBuffer.clear();
 	}
+        
+        public int getByteCapacity() {
+            if (byteBuffer instanceof DirectBuffer) {
+                return ((DirectBuffer)byteBuffer).getByteCapacity();
+            } else {
+                assert false : byteBuffer;
+                return -1;
+            }            
+        }
+
+        public PlatformAddress getEffectiveAddress() {
+            if (byteBuffer instanceof DirectBuffer) {
+                return ((DirectBuffer)byteBuffer).getEffectiveAddress();
+            } else {
+                assert false : byteBuffer;
+                return null;
+            }
+        }
+            
+        public PlatformAddress getBaseAddress() {
+            if (byteBuffer instanceof DirectBuffer) {
+                return ((DirectBuffer)byteBuffer).getBaseAddress();
+            } else {
+                assert false : byteBuffer;
+                return null;
+            }
+        }
+            
+        public boolean isAddressValid() {
+            if (byteBuffer instanceof DirectBuffer) {
+                return ((DirectBuffer)byteBuffer).isAddressValid();
+            } else {
+                assert false : byteBuffer;
+                return false;
+            }
+        }
+
+        public void addressValidityCheck() {
+            if (byteBuffer instanceof DirectBuffer) {
+                ((DirectBuffer)byteBuffer).addressValidityCheck();
+            } else {
+                assert false : byteBuffer;
+            }
+        }
+            
+        public void free() {
+            if (byteBuffer instanceof DirectBuffer) {
+                ((DirectBuffer)byteBuffer).free();
+            } else {
+                assert false : byteBuffer;
+            }   
+        }
+
 
 	public IntBuffer asReadOnlyBuffer() {
 		IntToByteBufferAdapter buf = new IntToByteBufferAdapter(byteBuffer

Modified: harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/LongToByteBufferAdapter.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/LongToByteBufferAdapter.java?view=diff&rev=527979&r1=527978&r2=527979
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/LongToByteBufferAdapter.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/LongToByteBufferAdapter.java
Thu Apr 12 08:27:49 2007
@@ -16,6 +16,8 @@
 
 package java.nio;
 
+import org.apache.harmony.nio.internal.DirectBuffer;
+import org.apache.harmony.luni.platform.PlatformAddress;
 
 
 /**
@@ -31,7 +33,7 @@
  * </p>
  * 
  */
-final class LongToByteBufferAdapter extends LongBuffer {
+final class LongToByteBufferAdapter extends LongBuffer implements DirectBuffer {
 
 	static LongBuffer wrap(ByteBuffer byteBuffer) {
 		return new LongToByteBufferAdapter(byteBuffer.slice());
@@ -44,6 +46,58 @@
 		this.byteBuffer = byteBuffer;
 		this.byteBuffer.clear();
 	}
+        
+        public int getByteCapacity() {
+            if (byteBuffer instanceof DirectBuffer) {
+                return ((DirectBuffer)byteBuffer).getByteCapacity();
+            } else {
+                assert false : byteBuffer;
+                return -1;
+            }            
+        }
+
+        public PlatformAddress getEffectiveAddress() {
+            if (byteBuffer instanceof DirectBuffer) {
+                return ((DirectBuffer)byteBuffer).getEffectiveAddress();
+            } else {
+                assert false : byteBuffer;
+                return null;
+            }
+        }
+
+        public PlatformAddress getBaseAddress() {
+            if (byteBuffer instanceof DirectBuffer) {
+                return ((DirectBuffer)byteBuffer).getBaseAddress();
+            } else {
+                assert false : byteBuffer;
+                return null;
+            }
+        }
+            
+        public boolean isAddressValid() {
+            if (byteBuffer instanceof DirectBuffer) {
+                return ((DirectBuffer)byteBuffer).isAddressValid();
+            } else {
+                assert false : byteBuffer;
+                return false;
+            }
+        }
+
+        public void addressValidityCheck() {
+            if (byteBuffer instanceof DirectBuffer) {
+                ((DirectBuffer)byteBuffer).addressValidityCheck();
+            } else {
+                assert false : byteBuffer;
+            }
+        }
+            
+        public void free() {
+            if (byteBuffer instanceof DirectBuffer) {
+                ((DirectBuffer)byteBuffer).free();
+            } else {
+                assert false : byteBuffer;
+            }   
+        }
 
 	public LongBuffer asReadOnlyBuffer() {
 		LongToByteBufferAdapter buf = new LongToByteBufferAdapter(byteBuffer

Modified: harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/MappedByteBufferAdapter.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/MappedByteBufferAdapter.java?view=diff&rev=527979&r1=527978&r2=527979
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/MappedByteBufferAdapter.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/MappedByteBufferAdapter.java
Thu Apr 12 08:27:49 2007
@@ -360,4 +360,8 @@
 		((MappedPlatformAddress)this.wrapped.getBaseAddress()).free();
 		this.wrapped.free();
 	}
+        
+        public int getByteCapacity() {
+            return wrapped.getByteCapacity();
+        }
 }

Modified: harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ShortToByteBufferAdapter.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ShortToByteBufferAdapter.java?view=diff&rev=527979&r1=527978&r2=527979
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ShortToByteBufferAdapter.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ShortToByteBufferAdapter.java
Thu Apr 12 08:27:49 2007
@@ -16,6 +16,8 @@
 
 package java.nio;
 
+import org.apache.harmony.nio.internal.DirectBuffer;
+import org.apache.harmony.luni.platform.PlatformAddress;
 
 
 /**
@@ -31,7 +33,7 @@
  * </p>
  * 
  */
-final class ShortToByteBufferAdapter extends ShortBuffer {
+final class ShortToByteBufferAdapter extends ShortBuffer implements DirectBuffer {
 
 	static ShortBuffer wrap(ByteBuffer byteBuffer) {
 		return new ShortToByteBufferAdapter(byteBuffer.slice());
@@ -44,6 +46,58 @@
 		this.byteBuffer = byteBuffer;
 		this.byteBuffer.clear();
 	}
+
+        public int getByteCapacity() {
+            if (byteBuffer instanceof DirectBuffer) {
+                return ((DirectBuffer)byteBuffer).getByteCapacity();
+            } else {
+                assert false : byteBuffer;
+                return -1;
+            }            
+        }
+
+        public PlatformAddress getEffectiveAddress() {
+            if (byteBuffer instanceof DirectBuffer) {
+                return ((DirectBuffer)byteBuffer).getEffectiveAddress();
+            } else {
+                assert false : byteBuffer;
+                return null;
+            }
+        }
+
+        public PlatformAddress getBaseAddress() {
+            if (byteBuffer instanceof DirectBuffer) {
+                return ((DirectBuffer)byteBuffer).getBaseAddress();
+            } else {
+                assert false : byteBuffer;
+                return null;
+            }
+        }
+            
+        public boolean isAddressValid() {
+            if (byteBuffer instanceof DirectBuffer) {
+                return ((DirectBuffer)byteBuffer).isAddressValid();
+            } else {
+                assert false : byteBuffer;
+                return false;
+            }
+        }
+
+        public void addressValidityCheck() {
+            if (byteBuffer instanceof DirectBuffer) {
+                ((DirectBuffer)byteBuffer).addressValidityCheck();
+            } else {
+                assert false : byteBuffer;
+            }
+        }
+            
+        public void free() {
+            if (byteBuffer instanceof DirectBuffer) {
+                ((DirectBuffer)byteBuffer).free();
+            } else {
+                assert false : byteBuffer;
+            }   
+        }
 
 	public ShortBuffer asReadOnlyBuffer() {
 		ShortToByteBufferAdapter buf = new ShortToByteBufferAdapter(byteBuffer

Modified: harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/DirectBuffer.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/DirectBuffer.java?view=diff&rev=527979&r1=527978&r2=527979
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/DirectBuffer.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/DirectBuffer.java
Thu Apr 12 08:27:49 2007
@@ -18,13 +18,16 @@
 import org.apache.harmony.luni.platform.PlatformAddress;
 
 public interface DirectBuffer {
-	public PlatformAddress getEffectiveAddress();
     
-    public PlatformAddress getBaseAddress();
+    PlatformAddress getEffectiveAddress();
     
-    public boolean isAddressValid();
+    PlatformAddress getBaseAddress();
     
-    public void addressValidityCheck();
+    boolean isAddressValid();
     
-    public void free();
+    void addressValidityCheck();
+    
+    void free();
+    
+    int getByteCapacity();
 }

Modified: harmony/enhanced/classlib/trunk/modules/nio/src/main/native/nio/shared/DirectBufferUtil.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/src/main/native/nio/shared/DirectBufferUtil.c?view=diff&rev=527979&r1=527978&r2=527979
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/src/main/native/nio/shared/DirectBufferUtil.c
(original)
+++ harmony/enhanced/classlib/trunk/modules/nio/src/main/native/nio/shared/DirectBufferUtil.c
Thu Apr 12 08:27:49 2007
@@ -99,9 +99,8 @@
  */
 JNIEXPORT jlong JNICALL GetDirectBufferCapacity
   (JNIEnv * env, jobject buf){
-	  jfieldID fieldCapacity;
+	  jmethodID methodCapacity;
 	  jclass directBufferClass;
-	  jclass bufferClass;
           directBufferClass = (*env)->FindClass (env, "org/apache/harmony/nio/internal/DirectBuffer");
 	  if (!directBufferClass){
 	      	  return -1;
@@ -109,14 +108,10 @@
 	  if (JNI_FALSE == (*env)->IsInstanceOf(env, buf, directBufferClass)){
 		  return -1;
 	  }
-	  bufferClass = (*env)->FindClass (env, "java/nio/Buffer");
-	  if (!bufferClass){
+	  methodCapacity = (*env)->GetMethodID (env, directBufferClass, "getByteCapacity",
+             "()I");
+	  if (!methodCapacity){
 	      	  return -1;
 	  }
-	  fieldCapacity = (*env)->GetFieldID (env, bufferClass, "capacity",
-             "I");
-	  if (!fieldCapacity){
-	      	  return -1;
-	  }
-	  return (*env)->GetIntField(env, buf, fieldCapacity);
+	  return (jlong)(*env)->CallIntMethod(env, buf, methodCapacity);
   }

Modified: harmony/enhanced/drlvm/trunk/src/test/regression/H0000/DirectByteBufferTest.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/src/test/regression/H0000/DirectByteBufferTest.c?view=diff&rev=527979&r1=527978&r2=527979
==============================================================================
--- harmony/enhanced/drlvm/trunk/src/test/regression/H0000/DirectByteBufferTest.c (original)
+++ harmony/enhanced/drlvm/trunk/src/test/regression/H0000/DirectByteBufferTest.c Thu Apr
12 08:27:49 2007
@@ -3,17 +3,15 @@
 #include <stdlib.h>
 #include <string.h>
 
-JNIEXPORT jstring JNICALL Java_org_apache_harmony_drlvm_tests_regression_h0000_DirectByteBufferTest_testValidBuffer0
-  (JNIEnv *, jobject);
+JNIEXPORT jstring JNICALL Java_org_apache_harmony_drlvm_tests_regression_h0000_DirectByteBufferTest_tryDirectBuffer
+  (JNIEnv *, jclass);
 
+JNIEXPORT jstring JNICALL Java_org_apache_harmony_drlvm_tests_regression_h0000_DirectByteBufferTest_checkSameDirectStorage
+(JNIEnv *, jclass, jobject, jobject);
 
-/*
- * Class:     DirectByteBufferTest
- * Method:    testValidBuffer0
- * Signature: ()Ljava/lang/String;
- */
-JNIEXPORT jstring JNICALL Java_org_apache_harmony_drlvm_tests_regression_h0000_DirectByteBufferTest_testValidBuffer0
-  (JNIEnv *jenv, jobject unused)
+
+JNIEXPORT jstring JNICALL Java_org_apache_harmony_drlvm_tests_regression_h0000_DirectByteBufferTest_tryDirectBuffer
+  (JNIEnv *jenv, jclass unused)
 {
     char* error = (char*)calloc(256, 1);
     const jlong BUF_SIZE = 100;
@@ -38,12 +36,35 @@
                 "GetDirectBufferAddress() returned %p\n"
                 "GetDirectBufferCapacity() returned %d\n", addr, size);
         } else {
-            sprintf(error, "no NIO support\n");
+            sprintf(error, "no JNI NIO support\n");
         }
     }
 
     jstr = strlen(error) ? (*jenv)->NewStringUTF(jenv, error) : NULL;
     free(buf);
+    free(error);
+
+    return jstr;
+}
+
+JNIEXPORT jstring JNICALL Java_org_apache_harmony_drlvm_tests_regression_h0000_DirectByteBufferTest_checkSameDirectStorage
+(JNIEnv *jenv, jclass unused, jobject jbuf1, jobject jbuf2)
+{
+    char* error = (char*)calloc(256, 1);
+    void* addr1 = (*jenv)->GetDirectBufferAddress(jenv, jbuf1);
+    void* addr2 = (*jenv)->GetDirectBufferAddress(jenv, jbuf2);
+    jlong size1 = (*jenv)->GetDirectBufferCapacity(jenv, jbuf1);
+    jlong size2 = (*jenv)->GetDirectBufferCapacity(jenv, jbuf2);
+    jstring jstr;
+    if (addr1 != addr2) {
+        sprintf(error, "buffer address is not the same: expected %p but was %p\n", addr1,
addr2);
+    }
+    if (size1 != size2) {
+        sprintf(error + strlen(error), 
+            "buffer capacity is not the same: expected %d but was %d\n", size1, size2);
+    }
+
+    jstr = strlen(error) ? (*jenv)->NewStringUTF(jenv, error) : NULL;
     free(error);
 
     return jstr;

Modified: harmony/enhanced/drlvm/trunk/src/test/regression/H0000/DirectByteBufferTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/src/test/regression/H0000/DirectByteBufferTest.java?view=diff&rev=527979&r1=527978&r2=527979
==============================================================================
--- harmony/enhanced/drlvm/trunk/src/test/regression/H0000/DirectByteBufferTest.java (original)
+++ harmony/enhanced/drlvm/trunk/src/test/regression/H0000/DirectByteBufferTest.java Thu Apr
12 08:27:49 2007
@@ -1,5 +1,7 @@
 package org.apache.harmony.drlvm.tests.regression.h0000;
 
+import java.nio.Buffer;
+import java.nio.ByteBuffer;
 import junit.framework.TestCase;
 
 public class DirectByteBufferTest extends TestCase {
@@ -10,9 +12,33 @@
         new DirectByteBufferTest().testValidBuffer();
     }
 
-    private native String testValidBuffer0();
+    private static native String tryDirectBuffer();
+    private static native String checkSameDirectStorage(Buffer b1, Buffer b2);
+    
+    private static void assertView(String message, ByteBuffer b1, Buffer b2, int capacityRatio)
{
+        assertEquals(message + ":capacity", b1.capacity()/capacityRatio, b2.capacity());
+        String err = checkSameDirectStorage(b1, b2);
+        assertNull(message + " : " + err, err);
+    }
     
     public void testValidBuffer() {
-        assertNull(testValidBuffer0());
+        String err = tryDirectBuffer();
+        assertNull(err, err);
+    }
+
+    /**
+     * A regression test for HARMONY-3591: 
+     * JNI operations fail on non-byte views of a direct buffer.
+     */
+    public void testBufferView() {
+        ByteBuffer b = ByteBuffer.allocateDirect(100);
+        assertTrue(b.isDirect());
+        assertView("duplicate", b, b.duplicate(), 1);
+        assertView("char view", b, b.asCharBuffer(), 2);
+        assertView("short view", b, b.asShortBuffer(), 2);
+        assertView("int view", b, b.asIntBuffer(), 4);
+        assertView("float view", b, b.asFloatBuffer(), 4);
+        assertView("double view", b, b.asDoubleBuffer(), 8);
+        assertView("long view", b, b.asLongBuffer(), 8);
     }
 }



Mime
View raw message