-
Bug
-
Resolution: Not an Issue
-
P3
-
None
-
1.4.0
-
sparc
-
solaris_8
Name: viR10068 Date: 08/13/2001
The simple test for jni function GetDirectBufferCapacity() is failed
on the jdk1.4.0-beta_refresh-b74 due to wrong behavior of function.
This function returns 0 instead of size of buffer.
To reproduce:
1. compile the gdbc00101m1.java
Used: javac -d . gdbc00101m1.java
2. compile the gdbc00101m1.c
Used: cc -G -KPIC -o libjckjni.so -Iinclude gdbc00101m1.c
In 'include' directory you should place 3 files (see attachments):
% ls include
jckjlong_md.h jckjni.h jckjni_md.h
3. set environment variable LD_LIBRARY_PATH to working directory
4. run gdbc00101m1
Used: java -Xfuture javasoft.sqe.tests.vm.jni.gdbc001.gdbc00101m1.gdbc00101m1
Execution log:
% java -version
java version "1.4.0-beta_refresh"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta_refresh-b74)
Java HotSpot(TM) Client VM (build 1.4.0-beta_refresh-b74, mixed mode)
% java -Xfuture javasoft.sqe.tests.vm.jni.gdbc001.gdbc00101m1.gdbc00101m1
Create new direct buffer: java.nio.DirectByteBuffer[pos=0 lim=8 cap=8]
Check of buffer Capacity failed. Size 0 instead of 8
Change position in buffer: java.nio.DirectByteBuffer[pos=3 lim=8 cap=8]
sliced buffer size 0 should be 5
Check of sliced buffer Capacity failed
Buffer capacity in short 2
java.lang.IllegalArgumentException
at
javasoft.sqe.tests.vm.jni.gdbc001.gdbc00101m1.gdbc00101m1.getDirectBufferCapacit
y(Native
Method)
at
javasoft.sqe.tests.vm.jni.gdbc001.gdbc00101m1.gdbc00101m1.testChecks(gdbc00101m1
.java:42)
at
javasoft.sqe.tests.vm.jni.gdbc001.gdbc00101m1.gdbc00101m1.run(gdbc00101m1.java:8
9)
at
javasoft.sqe.tests.vm.jni.gdbc001.gdbc00101m1.gdbc00101m1.main(gdbc00101m1.java:
93)
Unexpected exception: java.lang.IllegalArgumentException
%
---------------------------gdbc00101m1.java ---------------------------
package javasoft.sqe.tests.vm.jni.gdbc001.gdbc00101m1;
import java.io.PrintStream;
import java.nio.ByteBuffer;
import java.nio.ShortBuffer;
import java.nio.IntBuffer;
public class gdbc00101m1 {
private static native long getDirectBufferCapacity(Object buf);
public static int testChecks(PrintStream out) {
boolean res = false;
try {
ByteBuffer buf = ByteBuffer.allocateDirect(8);
out.println("Create new direct buffer: "+buf);
if (getDirectBufferCapacity(buf) != 8) {
out.println("Check of buffer Capacity failed. Size "
+getDirectBufferCapacity(buf)+ " instead of "+buf.capacity() );
res = true;
}
buf.position(3);
out.println("Change position in buffer: "+buf);
ByteBuffer buf2 = buf.slice();
out.println("sliced buffer size "+getDirectBufferCapacity(buf2)+ "
should be "
+buf2.capacity());
if (getDirectBufferCapacity(buf2) != 5) {
out.println("Check of sliced buffer Capacity failed");
res = true;
}
ShortBuffer shortBuf = buf.asShortBuffer();
out.println("Buffer capacity in short "+shortBuf.capacity());
if (getDirectBufferCapacity(shortBuf) != shortBuf.capacity()) {
out.println("Check of ShortBuffer Capacity failed");
res = true;
}
IntBuffer intBuf = buf.asIntBuffer();
out.println("Buffer capacity in int "+intBuf.capacity());
if (getDirectBufferCapacity(intBuf) != intBuf.capacity()) {
out.println("Check of IntBuffer Capacity failed");
res = true;
}
} catch (Exception e) {
e.printStackTrace();
out.println("Unexpected exception: " + e);
res = true;
}
if(res)
return 2/*STATUS_FAILED*/;
return 0/*STATUS_PASSED*/;
}
static String loadLibraryStatus = "";
static {
if(!loadLib("gdbc00101m1"))
loadLib("jckjni");
}
static boolean loadLib(String libName){
try {
System.loadLibrary(libName);
loadLibraryStatus = null;
return true;
} catch (SecurityException e) {
loadLibraryStatus += "loadLibrary(\"" + libName + "\") throws: " +
e + "\n";
} catch (UnsatisfiedLinkError e) {
loadLibraryStatus += "loadLibrary(\"" + libName + "\") throws: " +
e + "\n";
}
return false;
}
public static int run(String argv[], PrintStream out) {
if (loadLibraryStatus!=null) {
out.println("Library loading:\n" + loadLibraryStatus);
}
return testChecks(out);
}
public static void main(String argv[]) {
System.exit(run(argv, System.out) + 95/*STATUS_TEMP*/);
}
}
---------------------------gdbc00101m1.c ---------------------------
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "jckjni.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifndef JNI_ENV_ARG
#ifdef __cplusplus
#define JNI_ENV_ARG(x, y) y
#define JNI_ENV_PTR(x) x
#else
#define JNI_ENV_ARG(x,y) x, y
#define JNI_ENV_PTR(x) (*x)
#endif
#endif
JNIEXPORT jlong JNICALL
Java_javasoft_sqe_tests_vm_jni_gdbc001_gdbc00101m1_gdbc00101m1_getDirectBufferCa
pacity
(JNIEnv *env, jobject obj, jobject buf) {
return JNI_ENV_PTR(env)->GetDirectBufferCapacity(JNI_ENV_ARG(env,buf));
}
#ifdef __cplusplus
}
#endif
---------------------------
The new JCK test
vm/jni/GetDirectBufferCapacity/gdbc001/gdbc00101m1/gdbc00101m1.html
is failed due to this bug.
======================================================================
- duplicates
-
JDK-4492062 the jni function NewDirectByteBuffer() crashes JVM
-
- Closed
-
-
JDK-4492063 the jni function GetDirectBufferAddress() works incorrectly
-
- Closed
-