1 /* 2 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "jni.h" 26 #include <stdio.h> 27 28 JNIEXPORT jbyte JNICALL 29 Java_TestNative_getByteRaw(JNIEnv *env, jclass cls, jlong addr, jint index) { 30 jbyte *arr = (jbyte*)addr; 31 return arr[index]; 32 } 33 34 JNIEXPORT jbyte JNICALL 35 Java_TestNative_getByteBuffer(JNIEnv *env, jclass cls, jobject buf, jint index) { 36 jlong addr = (jlong)(*env)->GetDirectBufferAddress(env, buf); 37 return Java_TestNative_getByteRaw(env, cls, addr, index); 38 } 39 40 JNIEXPORT jchar JNICALL 41 Java_TestNative_getCharRaw(JNIEnv *env, jclass cls, jlong addr, jint index) { 42 jchar *arr = (jchar*)addr; 43 return arr[index]; 44 } 45 46 JNIEXPORT jchar JNICALL 47 Java_TestNative_getCharBuffer(JNIEnv *env, jclass cls, jobject buf, jint index) { 48 jlong addr = (jlong)(*env)->GetDirectBufferAddress(env, buf); 49 return Java_TestNative_getCharRaw(env, cls, addr, index); 50 } 51 52 JNIEXPORT jshort JNICALL 53 Java_TestNative_getShortRaw(JNIEnv *env, jclass cls, jlong addr, jint index) { 54 jshort *arr = (jshort*)addr; 55 return arr[index]; 56 } 57 58 JNIEXPORT jshort JNICALL 59 Java_TestNative_getShortBuffer(JNIEnv *env, jclass cls, jobject buf, jint index) { 60 jlong addr = (jlong)(*env)->GetDirectBufferAddress(env, buf); 61 return Java_TestNative_getShortRaw(env, cls, addr, index); 62 } 63 64 JNIEXPORT jint JNICALL 65 Java_TestNative_getIntRaw(JNIEnv *env, jclass cls, jlong addr, jint index) { 66 jint *arr = (jint*)addr; 67 return arr[index]; 68 } 69 70 JNIEXPORT jint JNICALL 71 Java_TestNative_getIntBuffer(JNIEnv *env, jclass cls, jobject buf, jint index) { 72 jlong addr = (jlong)(*env)->GetDirectBufferAddress(env, buf); 73 return Java_TestNative_getIntRaw(env, cls, addr, index); 74 } 75 76 JNIEXPORT jfloat JNICALL 77 Java_TestNative_getFloatRaw(JNIEnv *env, jclass cls, jlong addr, jint index) { 78 jfloat *arr = (jfloat*)addr; 79 return arr[index]; 80 } 81 82 JNIEXPORT jfloat JNICALL 83 Java_TestNative_getFloatBuffer(JNIEnv *env, jclass cls, jobject buf, jint index) { 84 jlong addr = (jlong)(*env)->GetDirectBufferAddress(env, buf); 85 return Java_TestNative_getFloatRaw(env, cls, addr, index); 86 } 87 88 JNIEXPORT jlong JNICALL 89 Java_TestNative_getLongRaw(JNIEnv *env, jclass cls, jlong addr, jint index) { 90 jlong *arr = (jlong*)addr; 91 return arr[index]; 92 } 93 94 JNIEXPORT jlong JNICALL 95 Java_TestNative_getLongBuffer(JNIEnv *env, jclass cls, jobject buf, jint index) { 96 jlong addr = (jlong)(*env)->GetDirectBufferAddress(env, buf); 97 return Java_TestNative_getLongRaw(env, cls, addr, index); 98 } 99 100 JNIEXPORT jdouble JNICALL 101 Java_TestNative_getDoubleRaw(JNIEnv *env, jclass cls, jlong addr, jint index) { 102 jdouble *arr = (jdouble*)addr; 103 return arr[index]; 104 } 105 106 JNIEXPORT jdouble JNICALL 107 Java_TestNative_getDoubleBuffer(JNIEnv *env, jclass cls, jobject buf, jint index) { 108 jlong addr = (jlong)(*env)->GetDirectBufferAddress(env, buf); 109 return Java_TestNative_getDoubleRaw(env, cls, addr, index); 110 } 111 112 JNIEXPORT jlong JNICALL 113 Java_TestNative_getCapacity(JNIEnv *env, jclass cls, jobject buf) { 114 return (*env)->GetDirectBufferCapacity(env, buf); 115 }