1 /*
   2  * Copyright (c) 2001, 2010, 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 "precompiled.hpp"
  26 #include "classfile/systemDictionary.hpp"
  27 #include "classfile/vmSymbols.hpp"
  28 #include "oops/instanceKlass.hpp"
  29 #include "oops/oop.inline.hpp"
  30 #include "oops/symbolOop.hpp"
  31 #include "prims/jni.h"
  32 #include "prims/jniCheck.hpp"
  33 #include "prims/jvm_misc.hpp"
  34 #include "runtime/fieldDescriptor.hpp"
  35 #include "runtime/handles.hpp"
  36 #include "runtime/interfaceSupport.hpp"
  37 #include "runtime/jfieldIDWorkaround.hpp"
  38 #include "runtime/thread.hpp"
  39 #ifdef TARGET_ARCH_x86
  40 # include "jniTypes_x86.hpp"
  41 #endif
  42 #ifdef TARGET_ARCH_sparc
  43 # include "jniTypes_sparc.hpp"
  44 #endif
  45 #ifdef TARGET_ARCH_zero
  46 # include "jniTypes_zero.hpp"
  47 #endif
  48 
  49 
  50 // Heap objects are allowed to be directly referenced only in VM code,
  51 // not in native code.
  52 
  53 #define ASSERT_OOPS_ALLOWED                                          \
  54     assert(JavaThread::current()->thread_state() == _thread_in_vm,   \
  55            "jniCheck examining oops in bad state.")
  56 
  57 
  58 // Execute the given block of source code with the thread in VM state.
  59 // To do this, transition from the NATIVE state to the VM state, execute
  60 // the code, and transtition back.  The ThreadInVMfromNative constructor
  61 // performs the transition to VM state, its destructor restores the
  62 // NATIVE state.
  63 
  64 #define IN_VM(source_code)   {                                         \
  65     {                                                                  \
  66       ThreadInVMfromNative __tiv(thr);                                 \
  67       source_code                                                      \
  68     }                                                                  \
  69   }
  70 
  71 
  72 /*
  73  * DECLARATIONS
  74  */
  75 
  76 static struct JNINativeInterface_ * unchecked_jni_NativeInterface;
  77 
  78 
  79 /*
  80  * MACRO DEFINITIONS
  81  */
  82 
  83 // All JNI checked functions here use JNI_ENTRY_CHECKED() instead of the
  84 // QUICK_ENTRY or LEAF variants found in jni.cpp.  This allows handles
  85 // to be created if a fatal error should occur.
  86 
  87 // Check for thread not attached to VM;  need to catch this before
  88 // assertions in the wrapper routines might fire
  89 
  90 // Check for env being the one value appropriate for this thread.
  91 
  92 #define JNI_ENTRY_CHECKED(result_type, header)                           \
  93 extern "C" {                                                             \
  94   result_type JNICALL header {                                           \
  95     JavaThread* thr = (JavaThread*)ThreadLocalStorage::get_thread_slow();\
  96     if (thr == NULL || !thr->is_Java_thread()) {                         \
  97       tty->print_cr(fatal_using_jnienv_in_nonjava);                      \
  98       os::abort(true);                                                   \
  99     }                                                                    \
 100     JNIEnv* xenv = thr->jni_environment();                               \
 101     if (env != xenv) {                                                   \
 102       NativeReportJNIFatalError(thr, warn_wrong_jnienv);                 \
 103     }                                                                    \
 104     __ENTRY(result_type, header, thr)
 105 
 106 
 107 #define UNCHECKED() (unchecked_jni_NativeInterface)
 108 
 109 static const char * warn_wrong_jnienv = "Using JNIEnv in the wrong thread";
 110 static const char * warn_bad_class_descriptor = "JNI FindClass received a bad class descriptor \"%s\".  A correct class descriptor " \
 111   "has no leading \"L\" or trailing \";\".  Incorrect descriptors will not be accepted in future releases.";
 112 static const char * fatal_using_jnienv_in_nonjava = "FATAL ERROR in native method: Using JNIEnv in non-Java thread";
 113 static const char * warn_other_function_in_critical = "Warning: Calling other JNI functions in the scope of " \
 114   "Get/ReleasePrimitiveArrayCritical or Get/ReleaseStringCritical";
 115 static const char * fatal_bad_ref_to_jni = "Bad global or local ref passed to JNI";
 116 static const char * fatal_received_null_class = "JNI received a null class";
 117 static const char * fatal_class_not_a_class = "JNI received a class argument that is not a class";
 118 static const char * fatal_class_not_a_throwable_class = "JNI Throw or ThrowNew received a class argument that is not a Throwable or Throwable subclass";
 119 static const char * fatal_wrong_class_or_method = "Wrong object class or methodID passed to JNI call";
 120 static const char * fatal_non_weak_method = "non-weak methodID passed to JNI call";
 121 static const char * fatal_unknown_array_object = "Unknown array object passed to JNI array operations";
 122 static const char * fatal_object_array_expected = "Object array expected but not received for JNI array operation";
 123 static const char * fatal_non_array  = "Non-array passed to JNI array operations";
 124 static const char * fatal_element_type_mismatch = "Array element type mismatch in JNI";
 125 static const char * fatal_should_be_static = "Non-static field ID passed to JNI";
 126 static const char * fatal_wrong_static_field = "Wrong static field ID passed to JNI";
 127 static const char * fatal_static_field_not_found = "Static field not found in JNI get/set field operations";
 128 static const char * fatal_static_field_mismatch = "Field type (static) mismatch in JNI get/set field operations";
 129 static const char * fatal_should_be_nonstatic = "Static field ID passed to JNI";
 130 static const char * fatal_null_object = "Null object passed to JNI";
 131 static const char * fatal_wrong_field = "Wrong field ID passed to JNI";
 132 static const char * fatal_instance_field_not_found = "Instance field not found in JNI get/set field operations";
 133 static const char * fatal_instance_field_mismatch = "Field type (instance) mismatch in JNI get/set field operations";
 134 static const char * fatal_non_string = "JNI string operation received a non-string";
 135 
 136 
 137 // When in VM state:
 138 static void ReportJNIWarning(JavaThread* thr, const char *msg) {
 139   tty->print_cr("WARNING in native method: %s", msg);
 140   thr->print_stack();
 141 }
 142 
 143 // When in NATIVE state:
 144 static void NativeReportJNIFatalError(JavaThread* thr, const char *msg) {
 145   IN_VM(
 146     ReportJNIFatalError(thr, msg);
 147   )
 148 }
 149 
 150 static void NativeReportJNIWarning(JavaThread* thr, const char *msg) {
 151   IN_VM(
 152     ReportJNIWarning(thr, msg);
 153   )
 154 }
 155 
 156 
 157 
 158 
 159 /*
 160  * SUPPORT FUNCTIONS
 161  */
 162 
 163 static inline void
 164 functionEnterCritical(JavaThread* thr)
 165 {
 166   if (thr->has_pending_exception()) {
 167     NativeReportJNIWarning(thr, "JNI call made with exception pending");
 168   }
 169 }
 170 
 171 static inline void
 172 functionEnterCriticalExceptionAllowed(JavaThread* thr)
 173 {
 174 }
 175 
 176 static inline void
 177 functionEnter(JavaThread* thr)
 178 {
 179   if (thr->in_critical()) {
 180     tty->print_cr(warn_other_function_in_critical);
 181   }
 182   if (thr->has_pending_exception()) {
 183     NativeReportJNIWarning(thr, "JNI call made with exception pending");
 184   }
 185 }
 186 
 187 static inline void
 188 functionEnterExceptionAllowed(JavaThread* thr)
 189 {
 190   if (thr->in_critical()) {
 191     tty->print_cr(warn_other_function_in_critical);
 192   }
 193 }
 194 
 195 static inline void
 196 functionExit(JNIEnv *env)
 197 {
 198   /* nothing to do at this time */
 199 }
 200 
 201 static inline void
 202 checkStaticFieldID(JavaThread* thr, jfieldID fid, jclass cls, int ftype)
 203 {
 204   fieldDescriptor fd;
 205 
 206   /* make sure it is a static field */
 207   if (!jfieldIDWorkaround::is_static_jfieldID(fid))
 208     ReportJNIFatalError(thr, fatal_should_be_static);
 209 
 210   /* validate the class being passed */
 211   ASSERT_OOPS_ALLOWED;
 212   klassOop k_oop = jniCheck::validate_class(thr, cls, false);
 213 
 214   /* check for proper subclass hierarchy */
 215   JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fid);
 216   klassOop f_oop = id->holder();
 217   if (!instanceKlass::cast(k_oop)->is_subtype_of(f_oop))
 218     ReportJNIFatalError(thr, fatal_wrong_static_field);
 219 
 220   /* check for proper field type */
 221   if (!instanceKlass::cast(f_oop)->find_local_field_from_offset(
 222           id->offset(), true, &fd))
 223     ReportJNIFatalError(thr, fatal_static_field_not_found);
 224   if ((fd.field_type() != ftype) &&
 225       !(fd.field_type() == T_ARRAY && ftype == T_OBJECT)) {
 226     ReportJNIFatalError(thr, fatal_static_field_mismatch);
 227   }
 228 }
 229 
 230 static inline void
 231 checkInstanceFieldID(JavaThread* thr, jfieldID fid, jobject obj, int ftype)
 232 {
 233   fieldDescriptor fd;
 234 
 235   /* make sure it is an instance field */
 236   if (jfieldIDWorkaround::is_static_jfieldID(fid))
 237     ReportJNIFatalError(thr, fatal_should_be_nonstatic);
 238 
 239   /* validate the object being passed and then get its class */
 240   ASSERT_OOPS_ALLOWED;
 241   oop oopObj = jniCheck::validate_object(thr, obj);
 242   if (!oopObj) {
 243     ReportJNIFatalError(thr, fatal_null_object);
 244   }
 245   klassOop k_oop = oopObj->klass();
 246 
 247   if (!jfieldIDWorkaround::is_valid_jfieldID(k_oop, fid)) {
 248     ReportJNIFatalError(thr, fatal_wrong_field);
 249   }
 250 
 251   /* make sure the field exists */
 252   int offset = jfieldIDWorkaround::from_instance_jfieldID(k_oop, fid);
 253   if (!instanceKlass::cast(k_oop)->contains_field_offset(offset))
 254     ReportJNIFatalError(thr, fatal_wrong_field);
 255 
 256   /* check for proper field type */
 257   if (!instanceKlass::cast(k_oop)->find_field_from_offset(offset,
 258                                                               false, &fd))
 259     ReportJNIFatalError(thr, fatal_instance_field_not_found);
 260 
 261   if ((fd.field_type() != ftype) &&
 262       !(fd.field_type() == T_ARRAY && ftype == T_OBJECT)) {
 263     ReportJNIFatalError(thr, fatal_instance_field_mismatch);
 264   }
 265 }
 266 
 267 static inline void
 268 checkString(JavaThread* thr, jstring js)
 269 {
 270   ASSERT_OOPS_ALLOWED;
 271   oop s = jniCheck::validate_object(thr, js);
 272   if (!s || !java_lang_String::is_instance(s))
 273     ReportJNIFatalError(thr, fatal_non_string);
 274 }
 275 
 276 static inline void
 277 checkArray(JavaThread* thr, jarray jArray, int elementType)
 278 {
 279   ASSERT_OOPS_ALLOWED;
 280   arrayOop aOop;
 281 
 282   aOop = (arrayOop)jniCheck::validate_object(thr, jArray);
 283   if (aOop == NULL || !aOop->is_array())
 284     ReportJNIFatalError(thr, fatal_non_array);
 285 
 286   if (elementType != -1) {
 287     if (aOop->is_typeArray()) {
 288       BasicType array_type = typeArrayKlass::cast(aOop->klass())->element_type();
 289       if (array_type != elementType)
 290         ReportJNIFatalError(thr, fatal_element_type_mismatch);
 291       } else if (aOop->is_objArray()) {
 292         if ( T_OBJECT != elementType)
 293           ReportJNIFatalError(thr, fatal_object_array_expected);
 294       } else {
 295         ReportJNIFatalError(thr, fatal_unknown_array_object);
 296     }
 297   }
 298 }
 299 
 300 
 301 oop jniCheck::validate_handle(JavaThread* thr, jobject obj) {
 302   if (JNIHandles::is_frame_handle(thr, obj) ||
 303       JNIHandles::is_local_handle(thr, obj) ||
 304       JNIHandles::is_global_handle(obj) ||
 305       JNIHandles::is_weak_global_handle(obj)) {
 306     ASSERT_OOPS_ALLOWED;
 307     return JNIHandles::resolve_external_guard(obj);
 308   }
 309   ReportJNIFatalError(thr, fatal_bad_ref_to_jni);
 310   return NULL;
 311 }
 312 
 313 
 314 methodOop jniCheck::validate_jmethod_id(JavaThread* thr, jmethodID method_id) {
 315   ASSERT_OOPS_ALLOWED;
 316   // do the fast jmethodID check first
 317   methodOop moop = JNIHandles::checked_resolve_jmethod_id(method_id);
 318   if (moop == NULL) {
 319     ReportJNIFatalError(thr, fatal_wrong_class_or_method);
 320   }
 321   // jmethodIDs are supposed to be weak global handles, but that
 322   // can be expensive so check it last
 323   else if (!JNIHandles::is_weak_global_handle((jobject) method_id)) {
 324     ReportJNIFatalError(thr, fatal_non_weak_method);
 325   }
 326   return moop;
 327 }
 328 
 329 
 330 oop jniCheck::validate_object(JavaThread* thr, jobject obj) {
 331     if (!obj)
 332         return NULL;
 333     ASSERT_OOPS_ALLOWED;
 334     oop oopObj = jniCheck::validate_handle(thr, obj);
 335     if (!oopObj) {
 336       ReportJNIFatalError(thr, fatal_bad_ref_to_jni);
 337     }
 338     return oopObj;
 339 }
 340 
 341 // Warn if a class descriptor is in decorated form; class descriptors
 342 // passed to JNI findClass should not be decorated unless they are
 343 // array descriptors.
 344 void jniCheck::validate_class_descriptor(JavaThread* thr, const char* name) {
 345   if (name == NULL) return;  // implementation accepts NULL so just return
 346 
 347   size_t len = strlen(name);
 348 
 349   if (len >= 2 &&
 350       name[0] == JVM_SIGNATURE_CLASS &&            // 'L'
 351       name[len-1] == JVM_SIGNATURE_ENDCLASS ) {    // ';'
 352     char msg[JVM_MAXPATHLEN];
 353     jio_snprintf(msg, JVM_MAXPATHLEN, warn_bad_class_descriptor, name);
 354     ReportJNIWarning(thr, msg);
 355   }
 356 }
 357 
 358 klassOop jniCheck::validate_class(JavaThread* thr, jclass clazz, bool allow_primitive) {
 359   ASSERT_OOPS_ALLOWED;
 360   oop mirror = jniCheck::validate_handle(thr, clazz);
 361   if (!mirror) {
 362     ReportJNIFatalError(thr, fatal_received_null_class);
 363   }
 364 
 365   if (mirror->klass() != SystemDictionary::Class_klass()) {
 366     ReportJNIFatalError(thr, fatal_class_not_a_class);
 367   }
 368 
 369   klassOop k = java_lang_Class::as_klassOop(mirror);
 370   // Make allowances for primitive classes ...
 371   if (!(k != NULL || allow_primitive && java_lang_Class::is_primitive(mirror))) {
 372     ReportJNIFatalError(thr, fatal_class_not_a_class);
 373   }
 374   return k;
 375 }
 376 
 377 void jniCheck::validate_throwable_klass(JavaThread* thr, klassOop klass) {
 378   ASSERT_OOPS_ALLOWED;
 379   assert(klass != NULL, "klass argument must have a value");
 380 
 381   if (!Klass::cast(klass)->oop_is_instance() ||
 382       !instanceKlass::cast(klass)->is_subclass_of(SystemDictionary::Throwable_klass())) {
 383     ReportJNIFatalError(thr, fatal_class_not_a_throwable_class);
 384   }
 385 }
 386 
 387 void jniCheck::validate_call_object(JavaThread* thr, jobject obj, jmethodID method_id) {
 388   /* validate the object being passed */
 389   ASSERT_OOPS_ALLOWED;
 390   jniCheck::validate_jmethod_id(thr, method_id);
 391   jniCheck::validate_object(thr, obj);
 392 }
 393 
 394 void jniCheck::validate_call_class(JavaThread* thr, jclass clazz, jmethodID method_id) {
 395   /* validate the class being passed */
 396   ASSERT_OOPS_ALLOWED;
 397   jniCheck::validate_jmethod_id(thr, method_id);
 398   jniCheck::validate_class(thr, clazz, false);
 399 }
 400 
 401 
 402 /*
 403  * IMPLEMENTATION OF FUNCTIONS IN CHECKED TABLE
 404  */
 405 
 406 JNI_ENTRY_CHECKED(jclass,
 407   checked_jni_DefineClass(JNIEnv *env,
 408                           const char *name,
 409                           jobject loader,
 410                           const jbyte *buf,
 411                           jsize len))
 412     functionEnter(thr);
 413     IN_VM(
 414       jniCheck::validate_object(thr, loader);
 415     )
 416     jclass result = UNCHECKED()->DefineClass(env, name, loader, buf, len);
 417     functionExit(env);
 418     return result;
 419 JNI_END
 420 
 421 JNI_ENTRY_CHECKED(jclass,
 422   checked_jni_FindClass(JNIEnv *env,
 423                         const char *name))
 424     functionEnter(thr);
 425     IN_VM(
 426       jniCheck::validate_class_descriptor(thr, name);
 427     )
 428     jclass result = UNCHECKED()->FindClass(env, name);
 429     functionExit(env);
 430     return result;
 431 JNI_END
 432 
 433 JNI_ENTRY_CHECKED(jmethodID,
 434   checked_jni_FromReflectedMethod(JNIEnv *env,
 435                                   jobject method))
 436     functionEnter(thr);
 437     IN_VM(
 438       jniCheck::validate_object(thr, method);
 439     )
 440     jmethodID result = UNCHECKED()->FromReflectedMethod(env, method);
 441     functionExit(env);
 442     return result;
 443 JNI_END
 444 
 445 JNI_ENTRY_CHECKED(jfieldID,
 446   checked_jni_FromReflectedField(JNIEnv *env,
 447                                  jobject field))
 448     functionEnter(thr);
 449     IN_VM(
 450       jniCheck::validate_object(thr, field);
 451     )
 452     jfieldID result = UNCHECKED()->FromReflectedField(env, field);
 453     functionExit(env);
 454     return result;
 455 JNI_END
 456 
 457 JNI_ENTRY_CHECKED(jobject,
 458   checked_jni_ToReflectedMethod(JNIEnv *env,
 459                                 jclass cls,
 460                                 jmethodID methodID,
 461                                 jboolean isStatic))
 462     functionEnter(thr);
 463     IN_VM(
 464       jniCheck::validate_class(thr, cls, false);
 465       jniCheck::validate_jmethod_id(thr, methodID);
 466     )
 467     jobject result = UNCHECKED()->ToReflectedMethod(env, cls, methodID,
 468                                                     isStatic);
 469     functionExit(env);
 470     return result;
 471 JNI_END
 472 
 473 JNI_ENTRY_CHECKED(jclass,
 474   checked_jni_GetSuperclass(JNIEnv *env,
 475                             jclass sub))
 476     functionEnter(thr);
 477     IN_VM(
 478       jniCheck::validate_class(thr, sub, true);
 479     )
 480     jclass result = UNCHECKED()->GetSuperclass(env, sub);
 481     functionExit(env);
 482     return result;
 483 JNI_END
 484 
 485 JNI_ENTRY_CHECKED(jboolean,
 486   checked_jni_IsAssignableFrom(JNIEnv *env,
 487                                jclass sub,
 488                                jclass sup))
 489     functionEnter(thr);
 490     IN_VM(
 491       jniCheck::validate_class(thr, sub, true);
 492       jniCheck::validate_class(thr, sup, true);
 493     )
 494     jboolean result = UNCHECKED()->IsAssignableFrom(env, sub, sup);
 495     functionExit(env);
 496     return result;
 497 JNI_END
 498 
 499 JNI_ENTRY_CHECKED(jobject,
 500   checked_jni_ToReflectedField(JNIEnv *env,
 501                                jclass cls,
 502                                jfieldID fieldID,
 503                                jboolean isStatic))
 504     functionEnter(thr);
 505     IN_VM(
 506       jniCheck::validate_class(thr, cls, false);
 507     )
 508     jobject result = UNCHECKED()->ToReflectedField(env, cls, fieldID,
 509                                                    isStatic);
 510     functionExit(env);
 511     return result;
 512 JNI_END
 513 
 514 JNI_ENTRY_CHECKED(jint,
 515   checked_jni_Throw(JNIEnv *env,
 516                     jthrowable obj))
 517     functionEnter(thr);
 518     IN_VM(
 519       oop oopObj = jniCheck::validate_object(thr, obj);
 520       if (oopObj == NULL) {
 521         // Unchecked Throw tolerates a NULL obj, so just warn
 522         ReportJNIWarning(thr, "JNI Throw called with NULL throwable");
 523       } else {
 524         jniCheck::validate_throwable_klass(thr, oopObj->klass());
 525       }
 526     )
 527     jint result = UNCHECKED()->Throw(env, obj);
 528     functionExit(env);
 529     return result;
 530 JNI_END
 531 
 532 JNI_ENTRY_CHECKED(jint,
 533   checked_jni_ThrowNew(JNIEnv *env,
 534                        jclass clazz,
 535                        const char *msg))
 536     functionEnter(thr);
 537     IN_VM(
 538       klassOop k = jniCheck::validate_class(thr, clazz, false);
 539       assert(k != NULL, "validate_class shouldn't return NULL klassOop");
 540       jniCheck::validate_throwable_klass(thr, k);
 541     )
 542     jint result = UNCHECKED()->ThrowNew(env, clazz, msg);
 543     functionExit(env);
 544     return result;
 545 JNI_END
 546 
 547 JNI_ENTRY_CHECKED(jthrowable,
 548   checked_jni_ExceptionOccurred(JNIEnv *env))
 549     functionEnterExceptionAllowed(thr);
 550     jthrowable result = UNCHECKED()->ExceptionOccurred(env);
 551     functionExit(env);
 552     return result;
 553 JNI_END
 554 
 555 JNI_ENTRY_CHECKED(void,
 556   checked_jni_ExceptionDescribe(JNIEnv *env))
 557     functionEnterExceptionAllowed(thr);
 558     UNCHECKED()->ExceptionDescribe(env);
 559     functionExit(env);
 560 JNI_END
 561 
 562 JNI_ENTRY_CHECKED(void,
 563   checked_jni_ExceptionClear(JNIEnv *env))
 564     functionEnterExceptionAllowed(thr);
 565     UNCHECKED()->ExceptionClear(env);
 566     functionExit(env);
 567 JNI_END
 568 
 569 JNI_ENTRY_CHECKED(void,
 570   checked_jni_FatalError(JNIEnv *env,
 571                          const char *msg))
 572     functionEnter(thr);
 573     UNCHECKED()->FatalError(env, msg);
 574     functionExit(env);
 575 JNI_END
 576 
 577 JNI_ENTRY_CHECKED(jint,
 578   checked_jni_PushLocalFrame(JNIEnv *env,
 579                              jint capacity))
 580     functionEnterExceptionAllowed(thr);
 581     if (capacity < 0)
 582       NativeReportJNIFatalError(thr, "negative capacity");
 583     jint result = UNCHECKED()->PushLocalFrame(env, capacity);
 584     functionExit(env);
 585     return result;
 586 JNI_END
 587 
 588 JNI_ENTRY_CHECKED(jobject,
 589   checked_jni_PopLocalFrame(JNIEnv *env,
 590                             jobject result))
 591     functionEnterExceptionAllowed(thr);
 592     jobject res = UNCHECKED()->PopLocalFrame(env, result);
 593     functionExit(env);
 594     return res;
 595 JNI_END
 596 
 597 JNI_ENTRY_CHECKED(jobject,
 598   checked_jni_NewGlobalRef(JNIEnv *env,
 599                            jobject lobj))
 600     functionEnter(thr);
 601     IN_VM(
 602       if (lobj != NULL) {
 603         jniCheck::validate_handle(thr, lobj);
 604       }
 605     )
 606     jobject result = UNCHECKED()->NewGlobalRef(env,lobj);
 607     functionExit(env);
 608     return result;
 609 JNI_END
 610 
 611 JNI_ENTRY_CHECKED(void,
 612   checked_jni_DeleteGlobalRef(JNIEnv *env,
 613                               jobject gref))
 614     functionEnterExceptionAllowed(thr);
 615     IN_VM(
 616       jniCheck::validate_object(thr, gref);
 617       if (gref && !JNIHandles::is_global_handle(gref)) {
 618         ReportJNIFatalError(thr,
 619             "Invalid global JNI handle passed to DeleteGlobalRef");
 620       }
 621     )
 622     UNCHECKED()->DeleteGlobalRef(env,gref);
 623     functionExit(env);
 624 JNI_END
 625 
 626 JNI_ENTRY_CHECKED(void,
 627   checked_jni_DeleteLocalRef(JNIEnv *env,
 628                              jobject obj))
 629     functionEnterExceptionAllowed(thr);
 630     IN_VM(
 631       jniCheck::validate_object(thr, obj);
 632       if (obj && !(JNIHandles::is_local_handle(thr, obj) ||
 633                    JNIHandles::is_frame_handle(thr, obj)))
 634         ReportJNIFatalError(thr,
 635             "Invalid local JNI handle passed to DeleteLocalRef");
 636     )
 637     UNCHECKED()->DeleteLocalRef(env, obj);
 638     functionExit(env);
 639 JNI_END
 640 
 641 JNI_ENTRY_CHECKED(jboolean,
 642   checked_jni_IsSameObject(JNIEnv *env,
 643                            jobject obj1,
 644                            jobject obj2))
 645     functionEnterExceptionAllowed(thr);
 646     IN_VM(
 647       /* This JNI function can be used to compare weak global references
 648        * to NULL objects. If the handles are valid, but contain NULL,
 649        * then don't attempt to validate the object.
 650        */
 651       if (obj1 != NULL && jniCheck::validate_handle(thr, obj1) != NULL) {
 652         jniCheck::validate_object(thr, obj1);
 653       }
 654       if (obj2 != NULL && jniCheck::validate_handle(thr, obj2) != NULL) {
 655         jniCheck::validate_object(thr, obj2);
 656       }
 657     )
 658     jboolean result = UNCHECKED()->IsSameObject(env,obj1,obj2);
 659     functionExit(env);
 660     return result;
 661 JNI_END
 662 
 663 JNI_ENTRY_CHECKED(jobject,
 664   checked_jni_NewLocalRef(JNIEnv *env,
 665                           jobject ref))
 666     functionEnter(thr);
 667     IN_VM(
 668       if (ref != NULL) {
 669         jniCheck::validate_handle(thr, ref);
 670       }
 671     )
 672     jobject result = UNCHECKED()->NewLocalRef(env, ref);
 673     functionExit(env);
 674     return result;
 675 JNI_END
 676 
 677 JNI_ENTRY_CHECKED(jint,
 678   checked_jni_EnsureLocalCapacity(JNIEnv *env,
 679                                   jint capacity))
 680     functionEnter(thr);
 681     if (capacity < 0) {
 682       NativeReportJNIFatalError(thr, "negative capacity");
 683     }
 684     jint result = UNCHECKED()->EnsureLocalCapacity(env, capacity);
 685     functionExit(env);
 686     return result;
 687 JNI_END
 688 
 689 JNI_ENTRY_CHECKED(jobject,
 690   checked_jni_AllocObject(JNIEnv *env,
 691                           jclass clazz))
 692     functionEnter(thr);
 693     IN_VM(
 694       jniCheck::validate_class(thr, clazz, false);
 695     )
 696     jobject result = UNCHECKED()->AllocObject(env,clazz);
 697     functionExit(env);
 698     return result;
 699 JNI_END
 700 
 701 JNI_ENTRY_CHECKED(jobject,
 702   checked_jni_NewObject(JNIEnv *env,
 703                         jclass clazz,
 704                         jmethodID methodID,
 705                         ...))
 706     functionEnter(thr);
 707     va_list args;
 708     IN_VM(
 709       jniCheck::validate_class(thr, clazz, false);
 710       jniCheck::validate_jmethod_id(thr, methodID);
 711     )
 712     va_start(args, methodID);
 713     jobject result = UNCHECKED()->NewObjectV(env,clazz,methodID,args);
 714     va_end(args);
 715     functionExit(env);
 716     return result;
 717 JNI_END
 718 
 719 JNI_ENTRY_CHECKED(jobject,
 720   checked_jni_NewObjectV(JNIEnv *env,
 721                          jclass clazz,
 722                          jmethodID methodID,
 723                          va_list args))
 724     functionEnter(thr);
 725     IN_VM(
 726       jniCheck::validate_class(thr, clazz, false);
 727       jniCheck::validate_jmethod_id(thr, methodID);
 728     )
 729     jobject result = UNCHECKED()->NewObjectV(env,clazz,methodID,args);
 730     functionExit(env);
 731     return result;
 732 JNI_END
 733 
 734 JNI_ENTRY_CHECKED(jobject,
 735   checked_jni_NewObjectA(JNIEnv *env,
 736                          jclass clazz,
 737                          jmethodID methodID,
 738                          const jvalue *args))
 739     functionEnter(thr);
 740     IN_VM(
 741       jniCheck::validate_class(thr, clazz, false);
 742       jniCheck::validate_jmethod_id(thr, methodID);
 743     )
 744     jobject result = UNCHECKED()->NewObjectA(env,clazz,methodID,args);
 745     functionExit(env);
 746     return result;
 747 JNI_END
 748 
 749 JNI_ENTRY_CHECKED(jclass,
 750   checked_jni_GetObjectClass(JNIEnv *env,
 751                              jobject obj))
 752     functionEnter(thr);
 753     IN_VM(
 754       jniCheck::validate_object(thr, obj);
 755     )
 756     jclass result = UNCHECKED()->GetObjectClass(env,obj);
 757     functionExit(env);
 758     return result;
 759 JNI_END
 760 
 761 JNI_ENTRY_CHECKED(jboolean,
 762   checked_jni_IsInstanceOf(JNIEnv *env,
 763                            jobject obj,
 764                            jclass clazz))
 765     functionEnter(thr);
 766     IN_VM(
 767       jniCheck::validate_object(thr, obj);
 768       jniCheck::validate_class(thr, clazz, true);
 769     )
 770     jboolean result = UNCHECKED()->IsInstanceOf(env,obj,clazz);
 771     functionExit(env);
 772     return result;
 773 JNI_END
 774 
 775 JNI_ENTRY_CHECKED(jmethodID,
 776   checked_jni_GetMethodID(JNIEnv *env,
 777                           jclass clazz,
 778                           const char *name,
 779                           const char *sig))
 780     functionEnter(thr);
 781     IN_VM(
 782       jniCheck::validate_class(thr, clazz, false);
 783     )
 784     jmethodID result = UNCHECKED()->GetMethodID(env,clazz,name,sig);
 785     functionExit(env);
 786     return result;
 787 JNI_END
 788 
 789 #define WRAPPER_CallMethod(ResultType, Result) \
 790 JNI_ENTRY_CHECKED(ResultType,  \
 791   checked_jni_Call##Result##Method(JNIEnv *env, \
 792                                    jobject obj, \
 793                                    jmethodID methodID, \
 794                                    ...)) \
 795     functionEnter(thr); \
 796     va_list args; \
 797     IN_VM( \
 798       jniCheck::validate_call_object(thr, obj, methodID); \
 799     ) \
 800     va_start(args,methodID); \
 801     ResultType result =UNCHECKED()->Call##Result##MethodV(env, obj, methodID, \
 802                                                           args); \
 803     va_end(args); \
 804     functionExit(env); \
 805     return result; \
 806 JNI_END \
 807 \
 808 JNI_ENTRY_CHECKED(ResultType,  \
 809   checked_jni_Call##Result##MethodV(JNIEnv *env, \
 810                                     jobject obj, \
 811                                     jmethodID methodID, \
 812                                     va_list args)) \
 813     functionEnter(thr); \
 814     IN_VM(\
 815       jniCheck::validate_call_object(thr, obj, methodID); \
 816     ) \
 817     ResultType result = UNCHECKED()->Call##Result##MethodV(env, obj, methodID,\
 818                                                            args); \
 819     functionExit(env); \
 820     return result; \
 821 JNI_END \
 822 \
 823 JNI_ENTRY_CHECKED(ResultType,  \
 824   checked_jni_Call##Result##MethodA(JNIEnv *env, \
 825                                     jobject obj, \
 826                                     jmethodID methodID, \
 827                                     const jvalue * args)) \
 828     functionEnter(thr); \
 829     IN_VM( \
 830       jniCheck::validate_call_object(thr, obj, methodID); \
 831     ) \
 832     ResultType result = UNCHECKED()->Call##Result##MethodA(env, obj, methodID,\
 833                                                            args); \
 834     functionExit(env); \
 835     return result; \
 836 JNI_END
 837 
 838 WRAPPER_CallMethod(jobject,Object)
 839 WRAPPER_CallMethod(jboolean,Boolean)
 840 WRAPPER_CallMethod(jbyte,Byte)
 841 WRAPPER_CallMethod(jshort,Short)
 842 WRAPPER_CallMethod(jchar,Char)
 843 WRAPPER_CallMethod(jint,Int)
 844 WRAPPER_CallMethod(jlong,Long)
 845 WRAPPER_CallMethod(jfloat,Float)
 846 WRAPPER_CallMethod(jdouble,Double)
 847 
 848 JNI_ENTRY_CHECKED(void,
 849   checked_jni_CallVoidMethod(JNIEnv *env, \
 850                              jobject obj, \
 851                              jmethodID methodID, \
 852                              ...))
 853     functionEnter(thr);
 854     va_list args;
 855     IN_VM(
 856       jniCheck::validate_call_object(thr, obj, methodID);
 857     )
 858     va_start(args,methodID);
 859     UNCHECKED()->CallVoidMethodV(env,obj,methodID,args);
 860     va_end(args);
 861     functionExit(env);
 862 JNI_END
 863 
 864 JNI_ENTRY_CHECKED(void,
 865   checked_jni_CallVoidMethodV(JNIEnv *env,
 866                               jobject obj,
 867                               jmethodID methodID,
 868                               va_list args))
 869     functionEnter(thr);
 870     IN_VM(
 871       jniCheck::validate_call_object(thr, obj, methodID);
 872     )
 873     UNCHECKED()->CallVoidMethodV(env,obj,methodID,args);
 874     functionExit(env);
 875 JNI_END
 876 
 877 JNI_ENTRY_CHECKED(void,
 878   checked_jni_CallVoidMethodA(JNIEnv *env,
 879                               jobject obj,
 880                               jmethodID methodID,
 881                               const jvalue * args))
 882     functionEnter(thr);
 883     IN_VM(
 884       jniCheck::validate_call_object(thr, obj, methodID);
 885     )
 886     UNCHECKED()->CallVoidMethodA(env,obj,methodID,args);
 887     functionExit(env);
 888 JNI_END
 889 
 890 #define WRAPPER_CallNonvirtualMethod(ResultType, Result) \
 891 JNI_ENTRY_CHECKED(ResultType,  \
 892   checked_jni_CallNonvirtual##Result##Method(JNIEnv *env, \
 893                                              jobject obj, \
 894                                              jclass clazz, \
 895                                              jmethodID methodID, \
 896                                              ...)) \
 897     functionEnter(thr); \
 898     va_list args; \
 899     IN_VM( \
 900       jniCheck::validate_call_object(thr, obj, methodID); \
 901       jniCheck::validate_call_class(thr, clazz, methodID); \
 902     ) \
 903     va_start(args,methodID); \
 904     ResultType result = UNCHECKED()->CallNonvirtual##Result##MethodV(env, \
 905                                                                      obj, \
 906                                                                      clazz, \
 907                                                                      methodID,\
 908                                                                      args); \
 909     va_end(args); \
 910     functionExit(env); \
 911     return result; \
 912 JNI_END \
 913 \
 914 JNI_ENTRY_CHECKED(ResultType,  \
 915   checked_jni_CallNonvirtual##Result##MethodV(JNIEnv *env, \
 916                                               jobject obj, \
 917                                               jclass clazz, \
 918                                               jmethodID methodID, \
 919                                               va_list args)) \
 920     functionEnter(thr); \
 921     IN_VM( \
 922       jniCheck::validate_call_object(thr, obj, methodID); \
 923       jniCheck::validate_call_class(thr, clazz, methodID); \
 924     ) \
 925     ResultType result = UNCHECKED()->CallNonvirtual##Result##MethodV(env, \
 926                                                                      obj, \
 927                                                                      clazz, \
 928                                                                      methodID,\
 929                                                                      args); \
 930     functionExit(env); \
 931     return result; \
 932 JNI_END \
 933 \
 934 JNI_ENTRY_CHECKED(ResultType,  \
 935   checked_jni_CallNonvirtual##Result##MethodA(JNIEnv *env, \
 936                                               jobject obj, \
 937                                               jclass clazz, \
 938                                               jmethodID methodID, \
 939                                               const jvalue * args)) \
 940     functionEnter(thr); \
 941     IN_VM( \
 942       jniCheck::validate_call_object(thr, obj, methodID); \
 943       jniCheck::validate_call_class(thr, clazz, methodID); \
 944     ) \
 945     ResultType result = UNCHECKED()->CallNonvirtual##Result##MethodA(env, \
 946                                                                      obj, \
 947                                                                      clazz, \
 948                                                                      methodID,\
 949                                                                      args); \
 950     functionExit(env); \
 951     return result; \
 952 JNI_END
 953 
 954 WRAPPER_CallNonvirtualMethod(jobject,Object)
 955 WRAPPER_CallNonvirtualMethod(jboolean,Boolean)
 956 WRAPPER_CallNonvirtualMethod(jbyte,Byte)
 957 WRAPPER_CallNonvirtualMethod(jshort,Short)
 958 WRAPPER_CallNonvirtualMethod(jchar,Char)
 959 WRAPPER_CallNonvirtualMethod(jint,Int)
 960 WRAPPER_CallNonvirtualMethod(jlong,Long)
 961 WRAPPER_CallNonvirtualMethod(jfloat,Float)
 962 WRAPPER_CallNonvirtualMethod(jdouble,Double)
 963 
 964 JNI_ENTRY_CHECKED(void,
 965   checked_jni_CallNonvirtualVoidMethod(JNIEnv *env,
 966                                        jobject obj,
 967                                        jclass clazz,
 968                                        jmethodID methodID,
 969                                        ...))
 970     functionEnter(thr);
 971     va_list args;
 972     IN_VM(
 973       jniCheck::validate_call_object(thr, obj, methodID);
 974       jniCheck::validate_call_class(thr, clazz, methodID);
 975     )
 976     va_start(args,methodID);
 977     UNCHECKED()->CallNonvirtualVoidMethodV(env,obj,clazz,methodID,args);
 978     va_end(args);
 979     functionExit(env);
 980 JNI_END
 981 
 982 JNI_ENTRY_CHECKED(void,
 983   checked_jni_CallNonvirtualVoidMethodV(JNIEnv *env,
 984                                         jobject obj,
 985                                         jclass clazz,
 986                                         jmethodID methodID,
 987                                         va_list args))
 988     functionEnter(thr);
 989     IN_VM(
 990       jniCheck::validate_call_object(thr, obj, methodID);
 991       jniCheck::validate_call_class(thr, clazz, methodID);
 992     )
 993     UNCHECKED()->CallNonvirtualVoidMethodV(env,obj,clazz,methodID,args);
 994     functionExit(env);
 995 JNI_END
 996 
 997 JNI_ENTRY_CHECKED(void,
 998   checked_jni_CallNonvirtualVoidMethodA(JNIEnv *env,
 999                                         jobject obj,
1000                                         jclass clazz,
1001                                         jmethodID methodID,
1002                                         const jvalue * args))
1003     functionEnter(thr);
1004     IN_VM(
1005       jniCheck::validate_call_object(thr, obj, methodID);
1006       jniCheck::validate_call_class(thr, clazz, methodID);
1007     )
1008     UNCHECKED()->CallNonvirtualVoidMethodA(env,obj,clazz,methodID,args);
1009     functionExit(env);
1010 JNI_END
1011 
1012 JNI_ENTRY_CHECKED(jfieldID,
1013   checked_jni_GetFieldID(JNIEnv *env,
1014                          jclass clazz,
1015                          const char *name,
1016                          const char *sig))
1017     functionEnter(thr);
1018     IN_VM(
1019       jniCheck::validate_class(thr, clazz, false);
1020     )
1021     jfieldID result = UNCHECKED()->GetFieldID(env,clazz,name,sig);
1022     functionExit(env);
1023     return result;
1024 JNI_END
1025 
1026 #define WRAPPER_GetField(ReturnType,Result,FieldType) \
1027 JNI_ENTRY_CHECKED(ReturnType,  \
1028   checked_jni_Get##Result##Field(JNIEnv *env, \
1029                                  jobject obj, \
1030                                  jfieldID fieldID)) \
1031     functionEnter(thr); \
1032     IN_VM( \
1033       checkInstanceFieldID(thr, fieldID, obj, FieldType); \
1034     ) \
1035     ReturnType result = UNCHECKED()->Get##Result##Field(env,obj,fieldID); \
1036     functionExit(env); \
1037     return result; \
1038 JNI_END
1039 
1040 WRAPPER_GetField(jobject,  Object,  T_OBJECT)
1041 WRAPPER_GetField(jboolean, Boolean, T_BOOLEAN)
1042 WRAPPER_GetField(jbyte,    Byte,    T_BYTE)
1043 WRAPPER_GetField(jshort,   Short,   T_SHORT)
1044 WRAPPER_GetField(jchar,    Char,    T_CHAR)
1045 WRAPPER_GetField(jint,     Int,     T_INT)
1046 WRAPPER_GetField(jlong,    Long,    T_LONG)
1047 WRAPPER_GetField(jfloat,   Float,   T_FLOAT)
1048 WRAPPER_GetField(jdouble,  Double,  T_DOUBLE)
1049 
1050 #define WRAPPER_SetField(ValueType,Result,FieldType) \
1051 JNI_ENTRY_CHECKED(void,  \
1052   checked_jni_Set##Result##Field(JNIEnv *env, \
1053                                  jobject obj, \
1054                                  jfieldID fieldID, \
1055                                  ValueType val)) \
1056     functionEnter(thr); \
1057     IN_VM( \
1058       checkInstanceFieldID(thr, fieldID, obj, FieldType); \
1059     ) \
1060     UNCHECKED()->Set##Result##Field(env,obj,fieldID,val); \
1061     functionExit(env); \
1062 JNI_END
1063 
1064 WRAPPER_SetField(jobject,  Object,  T_OBJECT)
1065 WRAPPER_SetField(jboolean, Boolean, T_BOOLEAN)
1066 WRAPPER_SetField(jbyte,    Byte,    T_BYTE)
1067 WRAPPER_SetField(jshort,   Short,   T_SHORT)
1068 WRAPPER_SetField(jchar,    Char,    T_CHAR)
1069 WRAPPER_SetField(jint,     Int,     T_INT)
1070 WRAPPER_SetField(jlong,    Long,    T_LONG)
1071 WRAPPER_SetField(jfloat,   Float,   T_FLOAT)
1072 WRAPPER_SetField(jdouble,  Double,  T_DOUBLE)
1073 
1074 
1075 JNI_ENTRY_CHECKED(jmethodID,
1076   checked_jni_GetStaticMethodID(JNIEnv *env,
1077                                 jclass clazz,
1078                                 const char *name,
1079                                 const char *sig))
1080     functionEnter(thr);
1081     IN_VM(
1082       jniCheck::validate_class(thr, clazz, false);
1083     )
1084     jmethodID result = UNCHECKED()->GetStaticMethodID(env,clazz,name,sig);
1085     functionExit(env);
1086     return result;
1087 JNI_END
1088 
1089 #define WRAPPER_CallStaticMethod(ReturnType,Result) \
1090 JNI_ENTRY_CHECKED(ReturnType,  \
1091   checked_jni_CallStatic##Result##Method(JNIEnv *env, \
1092                                          jclass clazz, \
1093                                          jmethodID methodID, \
1094                                          ...)) \
1095     functionEnter(thr); \
1096     va_list args; \
1097     IN_VM( \
1098       jniCheck::validate_jmethod_id(thr, methodID); \
1099       jniCheck::validate_class(thr, clazz, false); \
1100     ) \
1101     va_start(args,methodID); \
1102     ReturnType result = UNCHECKED()->CallStatic##Result##MethodV(env, \
1103                                                                  clazz, \
1104                                                                  methodID, \
1105                                                                  args); \
1106     va_end(args); \
1107     functionExit(env); \
1108     return result; \
1109 JNI_END \
1110 \
1111 JNI_ENTRY_CHECKED(ReturnType,  \
1112   checked_jni_CallStatic##Result##MethodV(JNIEnv *env, \
1113                                           jclass clazz, \
1114                                           jmethodID methodID,\
1115                                           va_list args)) \
1116     functionEnter(thr); \
1117     IN_VM( \
1118       jniCheck::validate_jmethod_id(thr, methodID); \
1119       jniCheck::validate_class(thr, clazz, false); \
1120     ) \
1121     ReturnType result = UNCHECKED()->CallStatic##Result##MethodV(env, \
1122                                                                  clazz, \
1123                                                                  methodID, \
1124                                                                  args); \
1125     functionExit(env); \
1126     return result; \
1127 JNI_END \
1128 \
1129 JNI_ENTRY_CHECKED(ReturnType,  \
1130   checked_jni_CallStatic##Result##MethodA(JNIEnv *env, \
1131                                           jclass clazz, \
1132                                           jmethodID methodID, \
1133                                           const jvalue *args)) \
1134     functionEnter(thr); \
1135     IN_VM( \
1136       jniCheck::validate_jmethod_id(thr, methodID); \
1137       jniCheck::validate_class(thr, clazz, false); \
1138     ) \
1139     ReturnType result = UNCHECKED()->CallStatic##Result##MethodA(env, \
1140                                                                  clazz, \
1141                                                                  methodID, \
1142                                                                  args); \
1143     functionExit(env); \
1144     return result; \
1145 JNI_END
1146 
1147 WRAPPER_CallStaticMethod(jobject,Object)
1148 WRAPPER_CallStaticMethod(jboolean,Boolean)
1149 WRAPPER_CallStaticMethod(jbyte,Byte)
1150 WRAPPER_CallStaticMethod(jshort,Short)
1151 WRAPPER_CallStaticMethod(jchar,Char)
1152 WRAPPER_CallStaticMethod(jint,Int)
1153 WRAPPER_CallStaticMethod(jlong,Long)
1154 WRAPPER_CallStaticMethod(jfloat,Float)
1155 WRAPPER_CallStaticMethod(jdouble,Double)
1156 
1157 JNI_ENTRY_CHECKED(void,
1158   checked_jni_CallStaticVoidMethod(JNIEnv *env,
1159                                    jclass cls,
1160                                    jmethodID methodID,
1161                                    ...))
1162     functionEnter(thr);
1163     va_list args;
1164     IN_VM(
1165       jniCheck::validate_jmethod_id(thr, methodID);
1166       jniCheck::validate_class(thr, cls, false);
1167     )
1168     va_start(args,methodID);
1169     UNCHECKED()->CallStaticVoidMethodV(env,cls,methodID,args);
1170     va_end(args);
1171     functionExit(env);
1172 JNI_END
1173 
1174 JNI_ENTRY_CHECKED(void,
1175   checked_jni_CallStaticVoidMethodV(JNIEnv *env,
1176                                     jclass cls,
1177                                     jmethodID methodID,
1178                                     va_list args))
1179     functionEnter(thr);
1180     IN_VM(
1181       jniCheck::validate_jmethod_id(thr, methodID);
1182       jniCheck::validate_class(thr, cls, false);
1183     )
1184     UNCHECKED()->CallStaticVoidMethodV(env,cls,methodID,args);
1185     functionExit(env);
1186 JNI_END
1187 
1188 JNI_ENTRY_CHECKED(void,
1189   checked_jni_CallStaticVoidMethodA(JNIEnv *env,
1190                                     jclass cls,
1191                                     jmethodID methodID,
1192                                     const jvalue * args))
1193     functionEnter(thr);
1194     IN_VM(
1195       jniCheck::validate_jmethod_id(thr, methodID);
1196       jniCheck::validate_class(thr, cls, false);
1197     )
1198     UNCHECKED()->CallStaticVoidMethodA(env,cls,methodID,args);
1199     functionExit(env);
1200 JNI_END
1201 
1202 JNI_ENTRY_CHECKED(jfieldID,
1203   checked_jni_GetStaticFieldID(JNIEnv *env,
1204                                jclass clazz,
1205                                const char *name,
1206                                const char *sig))
1207     functionEnter(thr);
1208     IN_VM(
1209       jniCheck::validate_class(thr, clazz, false);
1210     )
1211     jfieldID result = UNCHECKED()->GetStaticFieldID(env,clazz,name,sig);
1212     functionExit(env);
1213     return result;
1214 JNI_END
1215 
1216 #define WRAPPER_GetStaticField(ReturnType,Result,FieldType) \
1217 JNI_ENTRY_CHECKED(ReturnType,  \
1218   checked_jni_GetStatic##Result##Field(JNIEnv *env, \
1219                                        jclass clazz, \
1220                                        jfieldID fieldID)) \
1221     functionEnter(thr); \
1222     IN_VM( \
1223       jniCheck::validate_class(thr, clazz, false); \
1224       checkStaticFieldID(thr, fieldID, clazz, FieldType); \
1225     ) \
1226     ReturnType result = UNCHECKED()->GetStatic##Result##Field(env, \
1227                                                               clazz, \
1228                                                               fieldID); \
1229     functionExit(env); \
1230     return result; \
1231 JNI_END
1232 
1233 WRAPPER_GetStaticField(jobject,  Object,  T_OBJECT)
1234 WRAPPER_GetStaticField(jboolean, Boolean, T_BOOLEAN)
1235 WRAPPER_GetStaticField(jbyte,    Byte,    T_BYTE)
1236 WRAPPER_GetStaticField(jshort,   Short,   T_SHORT)
1237 WRAPPER_GetStaticField(jchar,    Char,    T_CHAR)
1238 WRAPPER_GetStaticField(jint,     Int,     T_INT)
1239 WRAPPER_GetStaticField(jlong,    Long,    T_LONG)
1240 WRAPPER_GetStaticField(jfloat,   Float,   T_FLOAT)
1241 WRAPPER_GetStaticField(jdouble,  Double,  T_DOUBLE)
1242 
1243 #define WRAPPER_SetStaticField(ValueType,Result,FieldType) \
1244 JNI_ENTRY_CHECKED(void,  \
1245   checked_jni_SetStatic##Result##Field(JNIEnv *env, \
1246                                        jclass clazz, \
1247                                        jfieldID fieldID, \
1248                                        ValueType value)) \
1249     functionEnter(thr); \
1250     IN_VM( \
1251       jniCheck::validate_class(thr, clazz, false); \
1252       checkStaticFieldID(thr, fieldID, clazz, FieldType); \
1253     ) \
1254     UNCHECKED()->SetStatic##Result##Field(env,clazz,fieldID,value); \
1255     functionExit(env); \
1256 JNI_END
1257 
1258 WRAPPER_SetStaticField(jobject,  Object,  T_OBJECT)
1259 WRAPPER_SetStaticField(jboolean, Boolean, T_BOOLEAN)
1260 WRAPPER_SetStaticField(jbyte,    Byte,    T_BYTE)
1261 WRAPPER_SetStaticField(jshort,   Short,   T_SHORT)
1262 WRAPPER_SetStaticField(jchar,    Char,    T_CHAR)
1263 WRAPPER_SetStaticField(jint,     Int,     T_INT)
1264 WRAPPER_SetStaticField(jlong,    Long,    T_LONG)
1265 WRAPPER_SetStaticField(jfloat,   Float,   T_FLOAT)
1266 WRAPPER_SetStaticField(jdouble,  Double,  T_DOUBLE)
1267 
1268 
1269 JNI_ENTRY_CHECKED(jstring,
1270   checked_jni_NewString(JNIEnv *env,
1271                         const jchar *unicode,
1272                         jsize len))
1273     functionEnter(thr);
1274     jstring result = UNCHECKED()->NewString(env,unicode,len);
1275     functionExit(env);
1276     return result;
1277 JNI_END
1278 
1279 JNI_ENTRY_CHECKED(jsize,
1280   checked_jni_GetStringLength(JNIEnv *env,
1281                               jstring str))
1282     functionEnter(thr);
1283     IN_VM(
1284       checkString(thr, str);
1285     )
1286     jsize result = UNCHECKED()->GetStringLength(env,str);
1287     functionExit(env);
1288     return result;
1289 JNI_END
1290 
1291 // Arbitrary (but well-known) tag
1292 #define STRING_TAG 0x47114711
1293 
1294 JNI_ENTRY_CHECKED(const jchar *,
1295   checked_jni_GetStringChars(JNIEnv *env,
1296                              jstring str,
1297                              jboolean *isCopy))
1298     functionEnter(thr);
1299     IN_VM(
1300       checkString(thr, str);
1301     )
1302     const jchar *result = UNCHECKED()->GetStringChars(env,str,isCopy);
1303 
1304     size_t len = UNCHECKED()->GetStringLength(env,str) + 1; // + 1 for NULL termination
1305     jint* tagLocation = (jint*) AllocateHeap(len * sizeof(jchar) + sizeof(jint), "checked_jni_GetStringChars"); 
1306     *tagLocation = STRING_TAG;
1307     jchar* newResult = (jchar*) (tagLocation + 1);
1308     memcpy(newResult, result, len * sizeof(jchar));
1309     // Avoiding call to UNCHECKED()->ReleaseStringChars() since that will fire unexpected dtrace probes
1310     FreeHeap((char*)result);
1311 
1312     functionExit(env);
1313     return newResult;
1314 JNI_END
1315 
1316 JNI_ENTRY_CHECKED(void,
1317   checked_jni_ReleaseStringChars(JNIEnv *env,
1318                                  jstring str,
1319                                  const jchar *chars))
1320     functionEnterExceptionAllowed(thr);
1321     IN_VM(
1322       checkString(thr, str);
1323     )
1324     jint *tagLocation = ((jint*) chars) - 1;
1325     if (*tagLocation != STRING_TAG) {
1326        NativeReportJNIFatalError(thr, "ReleaseStringChars called on something not allocated by GetStringChars");
1327     }
1328     UNCHECKED()->ReleaseStringChars(env,str,(const jchar*)tagLocation);
1329     functionExit(env);
1330 JNI_END
1331 
1332 JNI_ENTRY_CHECKED(jstring,
1333   checked_jni_NewStringUTF(JNIEnv *env,
1334                            const char *utf))
1335     functionEnter(thr);
1336     jstring result = UNCHECKED()->NewStringUTF(env,utf);
1337     functionExit(env);
1338     return result;
1339 JNI_END
1340 
1341 JNI_ENTRY_CHECKED(jsize,
1342   checked_jni_GetStringUTFLength(JNIEnv *env,
1343                                  jstring str))
1344     functionEnter(thr);
1345     IN_VM(
1346       checkString(thr, str);
1347     )
1348     jsize result = UNCHECKED()->GetStringUTFLength(env,str);
1349     functionExit(env);
1350     return result;
1351 JNI_END
1352 
1353 // Arbitrary (but well-known) tag - different than GetStringChars
1354 #define STRING_UTF_TAG 0x48124812
1355 
1356 JNI_ENTRY_CHECKED(const char *,
1357   checked_jni_GetStringUTFChars(JNIEnv *env,
1358                                 jstring str,
1359                                 jboolean *isCopy))
1360     functionEnter(thr);
1361     IN_VM(
1362       checkString(thr, str);
1363     )
1364     const char *result = UNCHECKED()->GetStringUTFChars(env,str,isCopy);
1365 
1366     size_t len = strlen(result) + 1; // + 1 for NULL termination
1367     jint* tagLocation = (jint*) AllocateHeap(len + sizeof(jint), "checked_jni_GetStringUTFChars");
1368     *tagLocation = STRING_UTF_TAG;
1369     char* newResult = (char*) (tagLocation + 1);
1370     strcpy(newResult, result);
1371     // Avoiding call to UNCHECKED()->ReleaseStringUTFChars() since that will fire unexpected dtrace probes
1372     FreeHeap((char*)result);
1373 
1374     functionExit(env);
1375     return newResult;
1376 JNI_END
1377 
1378 JNI_ENTRY_CHECKED(void,
1379   checked_jni_ReleaseStringUTFChars(JNIEnv *env,
1380                                     jstring str,
1381                                     const char* chars))
1382     functionEnterExceptionAllowed(thr);
1383     IN_VM(
1384       checkString(thr, str);
1385     )
1386     jint* tagLocation = ((jint*) chars) - 1;
1387     if (*tagLocation != STRING_UTF_TAG) {
1388        NativeReportJNIFatalError(thr, "ReleaseStringUTFChars called on something not allocated by GetStringUTFChars");
1389     }
1390     UNCHECKED()->ReleaseStringUTFChars(env,str,(const char*)tagLocation);
1391     functionExit(env);
1392 JNI_END
1393 
1394 JNI_ENTRY_CHECKED(jsize,
1395   checked_jni_GetArrayLength(JNIEnv *env,
1396                              jarray array))
1397     functionEnter(thr);
1398     IN_VM(
1399       checkArray(thr, array, -1);
1400     )
1401     jsize result = UNCHECKED()->GetArrayLength(env,array);
1402     functionExit(env);
1403     return result;
1404 JNI_END
1405 
1406 JNI_ENTRY_CHECKED(jobjectArray,
1407   checked_jni_NewObjectArray(JNIEnv *env,
1408                              jsize len,
1409                              jclass clazz,
1410                              jobject init))
1411     functionEnter(thr);
1412     jobjectArray result = UNCHECKED()->NewObjectArray(env,len,clazz,init);
1413     functionExit(env);
1414     return result;
1415 JNI_END
1416 
1417 JNI_ENTRY_CHECKED(jobject,
1418   checked_jni_GetObjectArrayElement(JNIEnv *env,
1419                                     jobjectArray array,
1420                                     jsize index))
1421     functionEnter(thr);
1422     IN_VM(
1423       checkArray(thr, array, T_OBJECT);
1424     )
1425     jobject result = UNCHECKED()->GetObjectArrayElement(env,array,index);
1426     functionExit(env);
1427     return result;
1428 JNI_END
1429 
1430 JNI_ENTRY_CHECKED(void,
1431   checked_jni_SetObjectArrayElement(JNIEnv *env,
1432                                     jobjectArray array,
1433                                     jsize index,
1434                                     jobject val))
1435     functionEnter(thr);
1436     IN_VM(
1437       checkArray(thr, array, T_OBJECT);
1438     )
1439     UNCHECKED()->SetObjectArrayElement(env,array,index,val);
1440     functionExit(env);
1441 JNI_END
1442 
1443 #define WRAPPER_NewScalarArray(Return, Result) \
1444 JNI_ENTRY_CHECKED(Return, \
1445   checked_jni_New##Result##Array(JNIEnv *env, \
1446                                  jsize len)) \
1447     functionEnter(thr); \
1448     Return result = UNCHECKED()->New##Result##Array(env,len); \
1449     functionExit(env); \
1450     return (Return) result; \
1451 JNI_END
1452 
1453 WRAPPER_NewScalarArray(jbooleanArray, Boolean)
1454 WRAPPER_NewScalarArray(jbyteArray, Byte)
1455 WRAPPER_NewScalarArray(jshortArray, Short)
1456 WRAPPER_NewScalarArray(jcharArray, Char)
1457 WRAPPER_NewScalarArray(jintArray, Int)
1458 WRAPPER_NewScalarArray(jlongArray, Long)
1459 WRAPPER_NewScalarArray(jfloatArray, Float)
1460 WRAPPER_NewScalarArray(jdoubleArray, Double)
1461 
1462 #define WRAPPER_GetScalarArrayElements(ElementTag,ElementType,Result) \
1463 JNI_ENTRY_CHECKED(ElementType *,  \
1464   checked_jni_Get##Result##ArrayElements(JNIEnv *env, \
1465                                          ElementType##Array array, \
1466                                          jboolean *isCopy)) \
1467     functionEnter(thr); \
1468     IN_VM( \
1469       checkArray(thr, array, ElementTag); \
1470     ) \
1471     ElementType *result = UNCHECKED()->Get##Result##ArrayElements(env, \
1472                                                                   array, \
1473                                                                   isCopy); \
1474     functionExit(env); \
1475     return result; \
1476 JNI_END
1477 
1478 WRAPPER_GetScalarArrayElements(T_BOOLEAN, jboolean, Boolean)
1479 WRAPPER_GetScalarArrayElements(T_BYTE,    jbyte,    Byte)
1480 WRAPPER_GetScalarArrayElements(T_SHORT,   jshort,   Short)
1481 WRAPPER_GetScalarArrayElements(T_CHAR,    jchar,    Char)
1482 WRAPPER_GetScalarArrayElements(T_INT,     jint,     Int)
1483 WRAPPER_GetScalarArrayElements(T_LONG,    jlong,    Long)
1484 WRAPPER_GetScalarArrayElements(T_FLOAT,   jfloat,   Float)
1485 WRAPPER_GetScalarArrayElements(T_DOUBLE,  jdouble,  Double)
1486 
1487 #define WRAPPER_ReleaseScalarArrayElements(ElementTag,ElementType,Result,Tag) \
1488 JNI_ENTRY_CHECKED(void,  \
1489   checked_jni_Release##Result##ArrayElements(JNIEnv *env, \
1490                                              ElementType##Array array, \
1491                                              ElementType *elems, \
1492                                              jint mode)) \
1493     functionEnterExceptionAllowed(thr); \
1494     IN_VM( \
1495       checkArray(thr, array, ElementTag); \
1496       ASSERT_OOPS_ALLOWED; \
1497       typeArrayOop a = typeArrayOop(JNIHandles::resolve_non_null(array)); \
1498       /* cannot check validity of copy, unless every request is logged by
1499        * checking code.  Implementation of this check is deferred until a
1500        * subsequent release.
1501        */ \
1502     ) \
1503     UNCHECKED()->Release##Result##ArrayElements(env,array,elems,mode); \
1504     functionExit(env); \
1505 JNI_END
1506 
1507 WRAPPER_ReleaseScalarArrayElements(T_BOOLEAN,jboolean, Boolean, bool)
1508 WRAPPER_ReleaseScalarArrayElements(T_BYTE,   jbyte,    Byte,    byte)
1509 WRAPPER_ReleaseScalarArrayElements(T_SHORT,  jshort,   Short,   short)
1510 WRAPPER_ReleaseScalarArrayElements(T_CHAR,   jchar,    Char,    char)
1511 WRAPPER_ReleaseScalarArrayElements(T_INT,    jint,     Int,     int)
1512 WRAPPER_ReleaseScalarArrayElements(T_LONG,   jlong,    Long,    long)
1513 WRAPPER_ReleaseScalarArrayElements(T_FLOAT,  jfloat,   Float,   float)
1514 WRAPPER_ReleaseScalarArrayElements(T_DOUBLE, jdouble,  Double,  double)
1515 
1516 #define WRAPPER_GetScalarArrayRegion(ElementTag,ElementType,Result) \
1517 JNI_ENTRY_CHECKED(void,  \
1518   checked_jni_Get##Result##ArrayRegion(JNIEnv *env, \
1519                                        ElementType##Array array, \
1520                                        jsize start, \
1521                                        jsize len, \
1522                                        ElementType *buf)) \
1523     functionEnter(thr); \
1524     IN_VM( \
1525       checkArray(thr, array, ElementTag); \
1526     ) \
1527     UNCHECKED()->Get##Result##ArrayRegion(env,array,start,len,buf); \
1528     functionExit(env); \
1529 JNI_END
1530 
1531 WRAPPER_GetScalarArrayRegion(T_BOOLEAN, jboolean, Boolean)
1532 WRAPPER_GetScalarArrayRegion(T_BYTE,    jbyte,    Byte)
1533 WRAPPER_GetScalarArrayRegion(T_SHORT,   jshort,   Short)
1534 WRAPPER_GetScalarArrayRegion(T_CHAR,    jchar,    Char)
1535 WRAPPER_GetScalarArrayRegion(T_INT,     jint,     Int)
1536 WRAPPER_GetScalarArrayRegion(T_LONG,    jlong,    Long)
1537 WRAPPER_GetScalarArrayRegion(T_FLOAT,   jfloat,   Float)
1538 WRAPPER_GetScalarArrayRegion(T_DOUBLE,  jdouble,  Double)
1539 
1540 #define WRAPPER_SetScalarArrayRegion(ElementTag,ElementType,Result) \
1541 JNI_ENTRY_CHECKED(void,  \
1542   checked_jni_Set##Result##ArrayRegion(JNIEnv *env, \
1543                                        ElementType##Array array, \
1544                                        jsize start, \
1545                                        jsize len, \
1546                                        const ElementType *buf)) \
1547     functionEnter(thr); \
1548     IN_VM( \
1549       checkArray(thr, array, ElementTag); \
1550     ) \
1551     UNCHECKED()->Set##Result##ArrayRegion(env,array,start,len,buf); \
1552     functionExit(env); \
1553 JNI_END
1554 
1555 WRAPPER_SetScalarArrayRegion(T_BOOLEAN, jboolean, Boolean)
1556 WRAPPER_SetScalarArrayRegion(T_BYTE,    jbyte,    Byte)
1557 WRAPPER_SetScalarArrayRegion(T_SHORT,   jshort,   Short)
1558 WRAPPER_SetScalarArrayRegion(T_CHAR,    jchar,    Char)
1559 WRAPPER_SetScalarArrayRegion(T_INT,     jint,     Int)
1560 WRAPPER_SetScalarArrayRegion(T_LONG,    jlong,    Long)
1561 WRAPPER_SetScalarArrayRegion(T_FLOAT,   jfloat,   Float)
1562 WRAPPER_SetScalarArrayRegion(T_DOUBLE,  jdouble,  Double)
1563 
1564 JNI_ENTRY_CHECKED(jint,
1565   checked_jni_RegisterNatives(JNIEnv *env,
1566                               jclass clazz,
1567                               const JNINativeMethod *methods,
1568                               jint nMethods))
1569     functionEnter(thr);
1570     jint result = UNCHECKED()->RegisterNatives(env,clazz,methods,nMethods);
1571     functionExit(env);
1572     return result;
1573 JNI_END
1574 
1575 JNI_ENTRY_CHECKED(jint,
1576   checked_jni_UnregisterNatives(JNIEnv *env,
1577                                 jclass clazz))
1578     functionEnter(thr);
1579     jint result = UNCHECKED()->UnregisterNatives(env,clazz);
1580     functionExit(env);
1581     return result;
1582 JNI_END
1583 
1584 JNI_ENTRY_CHECKED(jint,
1585   checked_jni_MonitorEnter(JNIEnv *env,
1586                            jobject obj))
1587     functionEnter(thr);
1588     IN_VM(
1589       jniCheck::validate_object(thr, obj);
1590     )
1591     jint result = UNCHECKED()->MonitorEnter(env,obj);
1592     functionExit(env);
1593     return result;
1594 JNI_END
1595 
1596 JNI_ENTRY_CHECKED(jint,
1597   checked_jni_MonitorExit(JNIEnv *env,
1598                           jobject obj))
1599     functionEnterExceptionAllowed(thr);
1600     IN_VM(
1601       jniCheck::validate_object(thr, obj);
1602     )
1603     jint result = UNCHECKED()->MonitorExit(env,obj);
1604     functionExit(env);
1605     return result;
1606 JNI_END
1607 
1608 JNI_ENTRY_CHECKED(jint,
1609   checked_jni_GetJavaVM(JNIEnv *env,
1610                         JavaVM **vm))
1611     functionEnter(thr);
1612     jint result = UNCHECKED()->GetJavaVM(env,vm);
1613     functionExit(env);
1614     return result;
1615 JNI_END
1616 
1617 JNI_ENTRY_CHECKED(void,
1618   checked_jni_GetStringRegion(JNIEnv *env,
1619                               jstring str,
1620                               jsize start,
1621                               jsize len,
1622                               jchar *buf))
1623     functionEnter(thr);
1624     IN_VM(
1625       checkString(thr, str);
1626     )
1627     UNCHECKED()->GetStringRegion(env, str, start, len, buf);
1628     functionExit(env);
1629 JNI_END
1630 
1631 JNI_ENTRY_CHECKED(void,
1632   checked_jni_GetStringUTFRegion(JNIEnv *env,
1633                                  jstring str,
1634                                  jsize start,
1635                                  jsize len,
1636                                  char *buf))
1637     functionEnter(thr);
1638     IN_VM(
1639       checkString(thr, str);
1640     )
1641     UNCHECKED()->GetStringUTFRegion(env, str, start, len, buf);
1642     functionExit(env);
1643 JNI_END
1644 
1645 JNI_ENTRY_CHECKED(void *,
1646   checked_jni_GetPrimitiveArrayCritical(JNIEnv *env,
1647                                         jarray array,
1648                                         jboolean *isCopy))
1649     functionEnterCritical(thr);
1650     IN_VM(
1651       checkArray(thr, array, -1);
1652     )
1653     void *result = UNCHECKED()->GetPrimitiveArrayCritical(env, array, isCopy);
1654     functionExit(env);
1655     return result;
1656 JNI_END
1657 
1658 JNI_ENTRY_CHECKED(void,
1659   checked_jni_ReleasePrimitiveArrayCritical(JNIEnv *env,
1660                                             jarray array,
1661                                             void *carray,
1662                                             jint mode))
1663     functionEnterCriticalExceptionAllowed(thr);
1664     IN_VM(
1665       checkArray(thr, array, -1);
1666     )
1667     /* The Hotspot JNI code does not use the parameters, so just check the
1668      * array parameter as a minor sanity check
1669      */
1670     UNCHECKED()->ReleasePrimitiveArrayCritical(env, array, carray, mode);
1671     functionExit(env);
1672 JNI_END
1673 
1674 JNI_ENTRY_CHECKED(const jchar*,
1675   checked_jni_GetStringCritical(JNIEnv *env,
1676                                 jstring string,
1677                                 jboolean *isCopy))
1678     functionEnterCritical(thr);
1679     IN_VM(
1680       checkString(thr, string);
1681     )
1682     const jchar *result = UNCHECKED()->GetStringCritical(env, string, isCopy);
1683     functionExit(env);
1684     return result;
1685 JNI_END
1686 
1687 JNI_ENTRY_CHECKED(void,
1688   checked_jni_ReleaseStringCritical(JNIEnv *env,
1689                                     jstring str,
1690                                     const jchar *chars))
1691     functionEnterCriticalExceptionAllowed(thr);
1692     IN_VM(
1693       checkString(thr, str);
1694     )
1695     /* The Hotspot JNI code does not use the parameters, so just check the
1696      * string parameter as a minor sanity check
1697      */
1698     UNCHECKED()->ReleaseStringCritical(env, str, chars);
1699     functionExit(env);
1700 JNI_END
1701 
1702 JNI_ENTRY_CHECKED(jweak,
1703   checked_jni_NewWeakGlobalRef(JNIEnv *env,
1704                                jobject obj))
1705     functionEnter(thr);
1706     IN_VM(
1707       if (obj != NULL) {
1708         jniCheck::validate_handle(thr, obj);
1709       }
1710     )
1711     jweak result = UNCHECKED()->NewWeakGlobalRef(env, obj);
1712     functionExit(env);
1713     return result;
1714 JNI_END
1715 
1716 JNI_ENTRY_CHECKED(void,
1717   checked_jni_DeleteWeakGlobalRef(JNIEnv *env,
1718                                   jweak ref))
1719     functionEnterExceptionAllowed(thr);
1720     UNCHECKED()->DeleteWeakGlobalRef(env, ref);
1721     functionExit(env);
1722 JNI_END
1723 
1724 JNI_ENTRY_CHECKED(jboolean,
1725   checked_jni_ExceptionCheck(JNIEnv *env))
1726     functionEnterExceptionAllowed(thr);
1727     jboolean result = UNCHECKED()->ExceptionCheck(env);
1728     functionExit(env);
1729     return result;
1730 JNI_END
1731 
1732 JNI_ENTRY_CHECKED(jobject,
1733   checked_jni_NewDirectByteBuffer(JNIEnv *env,
1734                                   void *address,
1735                                   jlong capacity))
1736     functionEnter(thr);
1737     jobject result = UNCHECKED()->NewDirectByteBuffer(env, address, capacity);
1738     functionExit(env);
1739     return result;
1740 JNI_END
1741 
1742 JNI_ENTRY_CHECKED(void *,
1743   checked_jni_GetDirectBufferAddress(JNIEnv *env,
1744                                      jobject buf))
1745     functionEnter(thr);
1746     void* result = UNCHECKED()->GetDirectBufferAddress(env, buf);
1747     functionExit(env);
1748     return result;
1749 JNI_END
1750 
1751 JNI_ENTRY_CHECKED(jlong,
1752   checked_jni_GetDirectBufferCapacity(JNIEnv *env,
1753                                       jobject buf))
1754     functionEnter(thr);
1755     jlong result = UNCHECKED()->GetDirectBufferCapacity(env, buf);
1756     functionExit(env);
1757     return result;
1758 JNI_END
1759 
1760 JNI_ENTRY_CHECKED(jobjectRefType,
1761   checked_jni_GetObjectRefType(JNIEnv *env,
1762                                jobject obj))
1763     functionEnter(thr);
1764     /* validate the object being passed */
1765     IN_VM(
1766       jniCheck::validate_object(thr, obj);
1767     )
1768     jobjectRefType result = UNCHECKED()->GetObjectRefType(env, obj);
1769     functionExit(env);
1770     return result;
1771 JNI_END
1772 
1773 
1774 JNI_ENTRY_CHECKED(jint,
1775   checked_jni_GetVersion(JNIEnv *env))
1776     functionEnter(thr);
1777     jint result = UNCHECKED()->GetVersion(env);
1778     functionExit(env);
1779     return result;
1780 JNI_END
1781 
1782 
1783 
1784 /*
1785  * Structure containing all checked jni functions
1786  */
1787 struct JNINativeInterface_  checked_jni_NativeInterface = {
1788     NULL,
1789     NULL,
1790     NULL,
1791 
1792     NULL,
1793 
1794     checked_jni_GetVersion,
1795 
1796     checked_jni_DefineClass,
1797     checked_jni_FindClass,
1798 
1799     checked_jni_FromReflectedMethod,
1800     checked_jni_FromReflectedField,
1801 
1802     checked_jni_ToReflectedMethod,
1803 
1804     checked_jni_GetSuperclass,
1805     checked_jni_IsAssignableFrom,
1806 
1807     checked_jni_ToReflectedField,
1808 
1809     checked_jni_Throw,
1810     checked_jni_ThrowNew,
1811     checked_jni_ExceptionOccurred,
1812     checked_jni_ExceptionDescribe,
1813     checked_jni_ExceptionClear,
1814     checked_jni_FatalError,
1815 
1816     checked_jni_PushLocalFrame,
1817     checked_jni_PopLocalFrame,
1818 
1819     checked_jni_NewGlobalRef,
1820     checked_jni_DeleteGlobalRef,
1821     checked_jni_DeleteLocalRef,
1822     checked_jni_IsSameObject,
1823 
1824     checked_jni_NewLocalRef,
1825     checked_jni_EnsureLocalCapacity,
1826 
1827     checked_jni_AllocObject,
1828     checked_jni_NewObject,
1829     checked_jni_NewObjectV,
1830     checked_jni_NewObjectA,
1831 
1832     checked_jni_GetObjectClass,
1833     checked_jni_IsInstanceOf,
1834 
1835     checked_jni_GetMethodID,
1836 
1837     checked_jni_CallObjectMethod,
1838     checked_jni_CallObjectMethodV,
1839     checked_jni_CallObjectMethodA,
1840     checked_jni_CallBooleanMethod,
1841     checked_jni_CallBooleanMethodV,
1842     checked_jni_CallBooleanMethodA,
1843     checked_jni_CallByteMethod,
1844     checked_jni_CallByteMethodV,
1845     checked_jni_CallByteMethodA,
1846     checked_jni_CallCharMethod,
1847     checked_jni_CallCharMethodV,
1848     checked_jni_CallCharMethodA,
1849     checked_jni_CallShortMethod,
1850     checked_jni_CallShortMethodV,
1851     checked_jni_CallShortMethodA,
1852     checked_jni_CallIntMethod,
1853     checked_jni_CallIntMethodV,
1854     checked_jni_CallIntMethodA,
1855     checked_jni_CallLongMethod,
1856     checked_jni_CallLongMethodV,
1857     checked_jni_CallLongMethodA,
1858     checked_jni_CallFloatMethod,
1859     checked_jni_CallFloatMethodV,
1860     checked_jni_CallFloatMethodA,
1861     checked_jni_CallDoubleMethod,
1862     checked_jni_CallDoubleMethodV,
1863     checked_jni_CallDoubleMethodA,
1864     checked_jni_CallVoidMethod,
1865     checked_jni_CallVoidMethodV,
1866     checked_jni_CallVoidMethodA,
1867 
1868     checked_jni_CallNonvirtualObjectMethod,
1869     checked_jni_CallNonvirtualObjectMethodV,
1870     checked_jni_CallNonvirtualObjectMethodA,
1871     checked_jni_CallNonvirtualBooleanMethod,
1872     checked_jni_CallNonvirtualBooleanMethodV,
1873     checked_jni_CallNonvirtualBooleanMethodA,
1874     checked_jni_CallNonvirtualByteMethod,
1875     checked_jni_CallNonvirtualByteMethodV,
1876     checked_jni_CallNonvirtualByteMethodA,
1877     checked_jni_CallNonvirtualCharMethod,
1878     checked_jni_CallNonvirtualCharMethodV,
1879     checked_jni_CallNonvirtualCharMethodA,
1880     checked_jni_CallNonvirtualShortMethod,
1881     checked_jni_CallNonvirtualShortMethodV,
1882     checked_jni_CallNonvirtualShortMethodA,
1883     checked_jni_CallNonvirtualIntMethod,
1884     checked_jni_CallNonvirtualIntMethodV,
1885     checked_jni_CallNonvirtualIntMethodA,
1886     checked_jni_CallNonvirtualLongMethod,
1887     checked_jni_CallNonvirtualLongMethodV,
1888     checked_jni_CallNonvirtualLongMethodA,
1889     checked_jni_CallNonvirtualFloatMethod,
1890     checked_jni_CallNonvirtualFloatMethodV,
1891     checked_jni_CallNonvirtualFloatMethodA,
1892     checked_jni_CallNonvirtualDoubleMethod,
1893     checked_jni_CallNonvirtualDoubleMethodV,
1894     checked_jni_CallNonvirtualDoubleMethodA,
1895     checked_jni_CallNonvirtualVoidMethod,
1896     checked_jni_CallNonvirtualVoidMethodV,
1897     checked_jni_CallNonvirtualVoidMethodA,
1898 
1899     checked_jni_GetFieldID,
1900 
1901     checked_jni_GetObjectField,
1902     checked_jni_GetBooleanField,
1903     checked_jni_GetByteField,
1904     checked_jni_GetCharField,
1905     checked_jni_GetShortField,
1906     checked_jni_GetIntField,
1907     checked_jni_GetLongField,
1908     checked_jni_GetFloatField,
1909     checked_jni_GetDoubleField,
1910 
1911     checked_jni_SetObjectField,
1912     checked_jni_SetBooleanField,
1913     checked_jni_SetByteField,
1914     checked_jni_SetCharField,
1915     checked_jni_SetShortField,
1916     checked_jni_SetIntField,
1917     checked_jni_SetLongField,
1918     checked_jni_SetFloatField,
1919     checked_jni_SetDoubleField,
1920 
1921     checked_jni_GetStaticMethodID,
1922 
1923     checked_jni_CallStaticObjectMethod,
1924     checked_jni_CallStaticObjectMethodV,
1925     checked_jni_CallStaticObjectMethodA,
1926     checked_jni_CallStaticBooleanMethod,
1927     checked_jni_CallStaticBooleanMethodV,
1928     checked_jni_CallStaticBooleanMethodA,
1929     checked_jni_CallStaticByteMethod,
1930     checked_jni_CallStaticByteMethodV,
1931     checked_jni_CallStaticByteMethodA,
1932     checked_jni_CallStaticCharMethod,
1933     checked_jni_CallStaticCharMethodV,
1934     checked_jni_CallStaticCharMethodA,
1935     checked_jni_CallStaticShortMethod,
1936     checked_jni_CallStaticShortMethodV,
1937     checked_jni_CallStaticShortMethodA,
1938     checked_jni_CallStaticIntMethod,
1939     checked_jni_CallStaticIntMethodV,
1940     checked_jni_CallStaticIntMethodA,
1941     checked_jni_CallStaticLongMethod,
1942     checked_jni_CallStaticLongMethodV,
1943     checked_jni_CallStaticLongMethodA,
1944     checked_jni_CallStaticFloatMethod,
1945     checked_jni_CallStaticFloatMethodV,
1946     checked_jni_CallStaticFloatMethodA,
1947     checked_jni_CallStaticDoubleMethod,
1948     checked_jni_CallStaticDoubleMethodV,
1949     checked_jni_CallStaticDoubleMethodA,
1950     checked_jni_CallStaticVoidMethod,
1951     checked_jni_CallStaticVoidMethodV,
1952     checked_jni_CallStaticVoidMethodA,
1953 
1954     checked_jni_GetStaticFieldID,
1955 
1956     checked_jni_GetStaticObjectField,
1957     checked_jni_GetStaticBooleanField,
1958     checked_jni_GetStaticByteField,
1959     checked_jni_GetStaticCharField,
1960     checked_jni_GetStaticShortField,
1961     checked_jni_GetStaticIntField,
1962     checked_jni_GetStaticLongField,
1963     checked_jni_GetStaticFloatField,
1964     checked_jni_GetStaticDoubleField,
1965 
1966     checked_jni_SetStaticObjectField,
1967     checked_jni_SetStaticBooleanField,
1968     checked_jni_SetStaticByteField,
1969     checked_jni_SetStaticCharField,
1970     checked_jni_SetStaticShortField,
1971     checked_jni_SetStaticIntField,
1972     checked_jni_SetStaticLongField,
1973     checked_jni_SetStaticFloatField,
1974     checked_jni_SetStaticDoubleField,
1975 
1976     checked_jni_NewString,
1977     checked_jni_GetStringLength,
1978     checked_jni_GetStringChars,
1979     checked_jni_ReleaseStringChars,
1980 
1981     checked_jni_NewStringUTF,
1982     checked_jni_GetStringUTFLength,
1983     checked_jni_GetStringUTFChars,
1984     checked_jni_ReleaseStringUTFChars,
1985 
1986     checked_jni_GetArrayLength,
1987 
1988     checked_jni_NewObjectArray,
1989     checked_jni_GetObjectArrayElement,
1990     checked_jni_SetObjectArrayElement,
1991 
1992     checked_jni_NewBooleanArray,
1993     checked_jni_NewByteArray,
1994     checked_jni_NewCharArray,
1995     checked_jni_NewShortArray,
1996     checked_jni_NewIntArray,
1997     checked_jni_NewLongArray,
1998     checked_jni_NewFloatArray,
1999     checked_jni_NewDoubleArray,
2000 
2001     checked_jni_GetBooleanArrayElements,
2002     checked_jni_GetByteArrayElements,
2003     checked_jni_GetCharArrayElements,
2004     checked_jni_GetShortArrayElements,
2005     checked_jni_GetIntArrayElements,
2006     checked_jni_GetLongArrayElements,
2007     checked_jni_GetFloatArrayElements,
2008     checked_jni_GetDoubleArrayElements,
2009 
2010     checked_jni_ReleaseBooleanArrayElements,
2011     checked_jni_ReleaseByteArrayElements,
2012     checked_jni_ReleaseCharArrayElements,
2013     checked_jni_ReleaseShortArrayElements,
2014     checked_jni_ReleaseIntArrayElements,
2015     checked_jni_ReleaseLongArrayElements,
2016     checked_jni_ReleaseFloatArrayElements,
2017     checked_jni_ReleaseDoubleArrayElements,
2018 
2019     checked_jni_GetBooleanArrayRegion,
2020     checked_jni_GetByteArrayRegion,
2021     checked_jni_GetCharArrayRegion,
2022     checked_jni_GetShortArrayRegion,
2023     checked_jni_GetIntArrayRegion,
2024     checked_jni_GetLongArrayRegion,
2025     checked_jni_GetFloatArrayRegion,
2026     checked_jni_GetDoubleArrayRegion,
2027 
2028     checked_jni_SetBooleanArrayRegion,
2029     checked_jni_SetByteArrayRegion,
2030     checked_jni_SetCharArrayRegion,
2031     checked_jni_SetShortArrayRegion,
2032     checked_jni_SetIntArrayRegion,
2033     checked_jni_SetLongArrayRegion,
2034     checked_jni_SetFloatArrayRegion,
2035     checked_jni_SetDoubleArrayRegion,
2036 
2037     checked_jni_RegisterNatives,
2038     checked_jni_UnregisterNatives,
2039 
2040     checked_jni_MonitorEnter,
2041     checked_jni_MonitorExit,
2042 
2043     checked_jni_GetJavaVM,
2044 
2045     checked_jni_GetStringRegion,
2046     checked_jni_GetStringUTFRegion,
2047 
2048     checked_jni_GetPrimitiveArrayCritical,
2049     checked_jni_ReleasePrimitiveArrayCritical,
2050 
2051     checked_jni_GetStringCritical,
2052     checked_jni_ReleaseStringCritical,
2053 
2054     checked_jni_NewWeakGlobalRef,
2055     checked_jni_DeleteWeakGlobalRef,
2056 
2057     checked_jni_ExceptionCheck,
2058 
2059     checked_jni_NewDirectByteBuffer,
2060     checked_jni_GetDirectBufferAddress,
2061     checked_jni_GetDirectBufferCapacity,
2062 
2063     // New 1.6 Features
2064 
2065     checked_jni_GetObjectRefType
2066 };
2067 
2068 
2069 // Returns the function structure
2070 struct JNINativeInterface_* jni_functions_check() {
2071 
2072   unchecked_jni_NativeInterface = jni_functions_nocheck();
2073 
2074   // make sure the last pointer in the checked table is not null, indicating
2075   // an addition to the JNINativeInterface_ structure without initializing
2076   // it in the checked table.
2077   debug_only(int *lastPtr = (int *)((char *)&checked_jni_NativeInterface + \
2078              sizeof(*unchecked_jni_NativeInterface) - sizeof(char *));)
2079   assert(*lastPtr != 0,
2080          "Mismatched JNINativeInterface tables, check for new entries");
2081 
2082   // with -verbose:jni this message will print
2083   if (PrintJNIResolving) {
2084     tty->print_cr("Checked JNI functions are being used to " \
2085                   "validate JNI usage");
2086   }
2087 
2088   return &checked_jni_NativeInterface;
2089 }