< prev index next >

src/hotspot/share/prims/jniCheck.cpp

Print this page

   1 /*
   2  * Copyright (c) 2001, 2025, 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  *

2038 JNI_END
2039 
2040 JNI_ENTRY_CHECKED(jobject,
2041   checked_jni_GetModule(JNIEnv *env,
2042                         jclass clazz))
2043     functionEnter(thr);
2044     jobject result = UNCHECKED()->GetModule(env, clazz);
2045     functionExit(thr);
2046     return result;
2047 JNI_END
2048 
2049 JNI_ENTRY_CHECKED(jboolean,
2050   checked_jni_IsVirtualThread(JNIEnv *env,
2051                               jobject obj))
2052     functionEnter(thr);
2053     jboolean result = UNCHECKED()->IsVirtualThread(env, obj);
2054     functionExit(thr);
2055     return result;
2056 JNI_END
2057 









2058 /*
2059  * Structure containing all checked jni functions
2060  */
2061 struct JNINativeInterface_  checked_jni_NativeInterface = {
2062     nullptr,
2063     nullptr,
2064     nullptr,
2065 
2066     nullptr,
2067 
2068     checked_jni_GetVersion,
2069 
2070     checked_jni_DefineClass,
2071     checked_jni_FindClass,
2072 
2073     checked_jni_FromReflectedMethod,
2074     checked_jni_FromReflectedField,
2075 
2076     checked_jni_ToReflectedMethod,
2077 

2331     checked_jni_ExceptionCheck,
2332 
2333     checked_jni_NewDirectByteBuffer,
2334     checked_jni_GetDirectBufferAddress,
2335     checked_jni_GetDirectBufferCapacity,
2336 
2337     // New 1.6 Features
2338 
2339     checked_jni_GetObjectRefType,
2340 
2341     // Module Features
2342 
2343     checked_jni_GetModule,
2344 
2345     // Virtual threads
2346 
2347     checked_jni_IsVirtualThread,
2348 
2349     // Large UTF8 support
2350 
2351     checked_jni_GetStringUTFLengthAsLong




2352 
2353 };
2354 
2355 
2356 // Returns the function structure
2357 struct JNINativeInterface_* jni_functions_check() {
2358 
2359   unchecked_jni_NativeInterface = jni_functions_nocheck();
2360 
2361   // make sure the last pointer in the checked table is not null, indicating
2362   // an addition to the JNINativeInterface_ structure without initializing
2363   // it in the checked table.
2364   DEBUG_ONLY(intptr_t *lastPtr = (intptr_t *)((char *)&checked_jni_NativeInterface + \
2365              sizeof(*unchecked_jni_NativeInterface) - sizeof(char *));)
2366   assert(*lastPtr != 0,
2367          "Mismatched JNINativeInterface tables, check for new entries");
2368 
2369   // with -verbose:jni this message will print
2370   log_debug(jni, resolve)("Checked JNI functions are being used to validate JNI usage");
2371 

   1 /*
   2  * Copyright (c) 2001, 2026, 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  *

2038 JNI_END
2039 
2040 JNI_ENTRY_CHECKED(jobject,
2041   checked_jni_GetModule(JNIEnv *env,
2042                         jclass clazz))
2043     functionEnter(thr);
2044     jobject result = UNCHECKED()->GetModule(env, clazz);
2045     functionExit(thr);
2046     return result;
2047 JNI_END
2048 
2049 JNI_ENTRY_CHECKED(jboolean,
2050   checked_jni_IsVirtualThread(JNIEnv *env,
2051                               jobject obj))
2052     functionEnter(thr);
2053     jboolean result = UNCHECKED()->IsVirtualThread(env, obj);
2054     functionExit(thr);
2055     return result;
2056 JNI_END
2057 
2058 JNI_ENTRY_CHECKED(jboolean,
2059   checked_jni_IsValueObject(JNIEnv *env,
2060                             jobject obj))
2061     functionEnter(thr);
2062     jboolean result = UNCHECKED()->IsValueObject(env, obj);
2063     functionExit(thr);
2064     return result;
2065 JNI_END
2066 
2067 /*
2068  * Structure containing all checked jni functions
2069  */
2070 struct JNINativeInterface_  checked_jni_NativeInterface = {
2071     nullptr,
2072     nullptr,
2073     nullptr,
2074 
2075     nullptr,
2076 
2077     checked_jni_GetVersion,
2078 
2079     checked_jni_DefineClass,
2080     checked_jni_FindClass,
2081 
2082     checked_jni_FromReflectedMethod,
2083     checked_jni_FromReflectedField,
2084 
2085     checked_jni_ToReflectedMethod,
2086 

2340     checked_jni_ExceptionCheck,
2341 
2342     checked_jni_NewDirectByteBuffer,
2343     checked_jni_GetDirectBufferAddress,
2344     checked_jni_GetDirectBufferCapacity,
2345 
2346     // New 1.6 Features
2347 
2348     checked_jni_GetObjectRefType,
2349 
2350     // Module Features
2351 
2352     checked_jni_GetModule,
2353 
2354     // Virtual threads
2355 
2356     checked_jni_IsVirtualThread,
2357 
2358     // Large UTF8 support
2359 
2360     checked_jni_GetStringUTFLengthAsLong,
2361 
2362     // Value classes
2363 
2364     checked_jni_IsValueObject
2365 
2366 };
2367 
2368 
2369 // Returns the function structure
2370 struct JNINativeInterface_* jni_functions_check() {
2371 
2372   unchecked_jni_NativeInterface = jni_functions_nocheck();
2373 
2374   // make sure the last pointer in the checked table is not null, indicating
2375   // an addition to the JNINativeInterface_ structure without initializing
2376   // it in the checked table.
2377   DEBUG_ONLY(intptr_t *lastPtr = (intptr_t *)((char *)&checked_jni_NativeInterface + \
2378              sizeof(*unchecked_jni_NativeInterface) - sizeof(char *));)
2379   assert(*lastPtr != 0,
2380          "Mismatched JNINativeInterface tables, check for new entries");
2381 
2382   // with -verbose:jni this message will print
2383   log_debug(jni, resolve)("Checked JNI functions are being used to validate JNI usage");
2384 
< prev index next >