src/hotspot/share/prims/jvm.cpp
changeset 58920 d67ebc838ab8
parent 58901 2700c409ff10
child 59056 15936b142f86
equal deleted inserted replaced
58919:1d1f9c43138f 58920:d67ebc838ab8
   740 
   740 
   741 
   741 
   742 // Misc. class handling ///////////////////////////////////////////////////////////
   742 // Misc. class handling ///////////////////////////////////////////////////////////
   743 
   743 
   744 
   744 
   745 JVM_ENTRY(void, JVM_LinkClass(JNIEnv* env, jclass classClass, jclass arg))
       
   746   JVMWrapper("JVM_LinkClass");
       
   747 
       
   748   oop r = JNIHandles::resolve(arg);
       
   749   Klass* klass = java_lang_Class::as_Klass(r);
       
   750 
       
   751   if (!ClassForNameDeferLinking && klass->is_instance_klass()) {
       
   752     InstanceKlass::cast(klass)->link_class(CHECK);
       
   753   }
       
   754 JVM_END
       
   755 
       
   756 JVM_ENTRY(jclass, JVM_GetCallerClass(JNIEnv* env))
   745 JVM_ENTRY(jclass, JVM_GetCallerClass(JNIEnv* env))
   757   JVMWrapper("JVM_GetCallerClass");
   746   JVMWrapper("JVM_GetCallerClass");
   758 
   747 
   759   // Getting the class of the caller frame.
   748   // Getting the class of the caller frame.
   760   //
   749   //
   861     protection_domain = java_lang_Class::as_Klass(from_class)->protection_domain();
   850     protection_domain = java_lang_Class::as_Klass(from_class)->protection_domain();
   862   }
   851   }
   863 
   852 
   864   Handle h_loader(THREAD, loader_oop);
   853   Handle h_loader(THREAD, loader_oop);
   865   Handle h_prot(THREAD, protection_domain);
   854   Handle h_prot(THREAD, protection_domain);
   866 
   855   jclass result = find_class_from_class_loader(env, h_name, init, h_loader,
   867   jboolean link = !ClassForNameDeferLinking;
       
   868   jclass result = find_class_from_class_loader(env, h_name, init, link, h_loader,
       
   869                                                h_prot, false, THREAD);
   856                                                h_prot, false, THREAD);
       
   857 
   870   if (log_is_enabled(Debug, class, resolve) && result != NULL) {
   858   if (log_is_enabled(Debug, class, resolve) && result != NULL) {
   871     trace_class_resolution(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(result)));
   859     trace_class_resolution(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(result)));
   872   }
   860   }
   873   return result;
   861   return result;
   874 JVM_END
   862 JVM_END
   901     class_loader = from_class->class_loader();
   889     class_loader = from_class->class_loader();
   902     protection_domain = from_class->protection_domain();
   890     protection_domain = from_class->protection_domain();
   903   }
   891   }
   904   Handle h_loader(THREAD, class_loader);
   892   Handle h_loader(THREAD, class_loader);
   905   Handle h_prot  (THREAD, protection_domain);
   893   Handle h_prot  (THREAD, protection_domain);
   906   jclass result = find_class_from_class_loader(env, h_name, init, false, h_loader,
   894   jclass result = find_class_from_class_loader(env, h_name, init, h_loader,
   907                                                h_prot, true, thread);
   895                                                h_prot, true, thread);
   908 
   896 
   909   if (log_is_enabled(Debug, class, resolve) && result != NULL) {
   897   if (log_is_enabled(Debug, class, resolve) && result != NULL) {
   910     // this function is generally only used for class loading during verification.
   898     // this function is generally only used for class loading during verification.
   911     ResourceMark rm;
   899     ResourceMark rm;
  3408 }
  3396 }
  3409 
  3397 
  3410 
  3398 
  3411 // Shared JNI/JVM entry points //////////////////////////////////////////////////////////////
  3399 // Shared JNI/JVM entry points //////////////////////////////////////////////////////////////
  3412 
  3400 
  3413 jclass find_class_from_class_loader(JNIEnv* env, Symbol* name, jboolean init, jboolean link,
  3401 jclass find_class_from_class_loader(JNIEnv* env, Symbol* name, jboolean init,
  3414                                     Handle loader, Handle protection_domain,
  3402                                     Handle loader, Handle protection_domain,
  3415                                     jboolean throwError, TRAPS) {
  3403                                     jboolean throwError, TRAPS) {
  3416   // Initialization also implies linking - check for coherent args
       
  3417   assert((init && link) || !init, "incorrect use of init/link arguments");
       
  3418 
       
  3419   // Security Note:
  3404   // Security Note:
  3420   //   The Java level wrapper will perform the necessary security check allowing
  3405   //   The Java level wrapper will perform the necessary security check allowing
  3421   //   us to pass the NULL as the initiating class loader.  The VM is responsible for
  3406   //   us to pass the NULL as the initiating class loader.  The VM is responsible for
  3422   //   the checkPackageAccess relative to the initiating class loader via the
  3407   //   the checkPackageAccess relative to the initiating class loader via the
  3423   //   protection_domain. The protection_domain is passed as NULL by the java code
  3408   //   protection_domain. The protection_domain is passed as NULL by the java code
  3424   //   if there is no security manager in 3-arg Class.forName().
  3409   //   if there is no security manager in 3-arg Class.forName().
  3425   Klass* klass = SystemDictionary::resolve_or_fail(name, loader, protection_domain, throwError != 0, CHECK_NULL);
  3410   Klass* klass = SystemDictionary::resolve_or_fail(name, loader, protection_domain, throwError != 0, CHECK_NULL);
  3426 
  3411 
  3427   // Check if we should initialize the class (which implies linking), or just link it
  3412   // Check if we should initialize the class
  3428   if (init && klass->is_instance_klass()) {
  3413   if (init && klass->is_instance_klass()) {
  3429     klass->initialize(CHECK_NULL);
  3414     klass->initialize(CHECK_NULL);
  3430   } else if (link && klass->is_instance_klass()) {
       
  3431     InstanceKlass::cast(klass)->link_class(CHECK_NULL);
       
  3432   }
  3415   }
  3433   return (jclass) JNIHandles::make_local(env, klass->java_mirror());
  3416   return (jclass) JNIHandles::make_local(env, klass->java_mirror());
  3434 }
  3417 }
  3435 
  3418 
  3436 
  3419