* src/native/jni.cpp: [OPENJDK] Implemented jni_GetDirectBufferCapacity.
authorStefan Ring <stefan@complang.tuwien.ac.at>
Sat, 22 Oct 2011 18:42:05 +0000 (20:42 +0200)
committerStefan Ring <stefan@complang.tuwien.ac.at>
Sat, 22 Oct 2011 18:42:05 +0000 (20:42 +0200)
* src/vm/javaobjects.hpp: Added java_nio_Buffer::get_capacity.

src/native/jni.cpp
src/vm/javaobjects.hpp

index 6e850fd2bac0db539175b06ad3fe7c06ea6b6b8a..661780662a239c07a46fd157f4ccce0377900621 100644 (file)
@@ -1,6 +1,6 @@
 /* src/native/jni.cpp - implementation of the Java Native Interface functions
 
-   Copyright (C) 1996-2005, 2006, 2007, 2008, 2009
+   Copyright (C) 1996-2011
    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
 
    This file is part of CACAO.
@@ -3565,7 +3565,8 @@ void* jni_GetDirectBufferAddress(JNIEnv *env, jobject buf)
 
 jlong jni_GetDirectBufferCapacity(JNIEnv* env, jobject buf)
 {
-#if defined(ENABLE_JAVASE) && defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
+#if defined(ENABLE_JAVASE)
+# if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
        TRACEJNICALLS(("jni_GetDirectBufferCapacity(env=%p, buf=%p)", env, buf));
 
        java_handle_t* h = (java_handle_t *) buf;
@@ -3577,6 +3578,23 @@ jlong jni_GetDirectBufferCapacity(JNIEnv* env, jobject buf)
        jlong capacity = b.get_cap();
 
        return capacity;
+# elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
+
+       TRACEJNICALLS(("jni_GetDirectBufferCapacity(env=%p, buf=%p)", env, buf));
+
+       java_nio_Buffer jnb(buf);
+
+       if (!builtin_instanceof(jnb.get_handle(), class_sun_nio_ch_DirectBuffer))
+               return -1;
+
+       jlong capacity = jnb.get_capacity();
+
+       return capacity;
+
+# else
+#  error unknown classpath configuration
+# endif
+
 #else
        vm_abort("jni_GetDirectBufferCapacity: not implemented in this configuration");
 
index f60026b97deffd601c0f8c6df31cca6d280c7641..b6061a1b8258f02210274a653fb8179155de4157 100644 (file)
@@ -2570,6 +2570,7 @@ public:
 
        // Getters.
        void* get_address() const;
+       int32_t get_capacity() const;
 };
 
 
@@ -2578,6 +2579,11 @@ inline void* java_nio_Buffer::get_address() const
        return get<void*>(_handle, offset_address);
 }
 
+inline int32_t java_nio_Buffer::get_capacity() const
+{
+       return get<int32_t>(_handle, offset_capacity);
+}
+
 #endif // WITH_JAVA_RUNTIME_LIBRARY_OPENJDK