src/hotspot/share/prims/jvm.cpp
changeset 58056 db92a157dd70
parent 58043 647d623650d3
child 58095 adc72cd1d1f2
equal deleted inserted replaced
58055:734f7711f87c 58056:db92a157dd70
   715 
   715 
   716 
   716 
   717 // Misc. class handling ///////////////////////////////////////////////////////////
   717 // Misc. class handling ///////////////////////////////////////////////////////////
   718 
   718 
   719 
   719 
       
   720 JVM_ENTRY(void, JVM_LinkClass(JNIEnv* env, jclass classClass, jclass arg))
       
   721   JVMWrapper("JVM_LinkClass");
       
   722 
       
   723   oop r = JNIHandles::resolve(arg);
       
   724   Klass* klass = java_lang_Class::as_Klass(r);
       
   725 
       
   726   if (!ClassForNameDeferLinking && klass->is_instance_klass()) {
       
   727     InstanceKlass::cast(klass)->link_class(CHECK);
       
   728   }
       
   729 JVM_END
       
   730 
   720 JVM_ENTRY(jclass, JVM_GetCallerClass(JNIEnv* env))
   731 JVM_ENTRY(jclass, JVM_GetCallerClass(JNIEnv* env))
   721   JVMWrapper("JVM_GetCallerClass");
   732   JVMWrapper("JVM_GetCallerClass");
   722 
   733 
   723   // Getting the class of the caller frame.
   734   // Getting the class of the caller frame.
   724   //
   735   //
   825     protection_domain = java_lang_Class::as_Klass(from_class)->protection_domain();
   836     protection_domain = java_lang_Class::as_Klass(from_class)->protection_domain();
   826   }
   837   }
   827 
   838 
   828   Handle h_loader(THREAD, loader_oop);
   839   Handle h_loader(THREAD, loader_oop);
   829   Handle h_prot(THREAD, protection_domain);
   840   Handle h_prot(THREAD, protection_domain);
   830   jclass result = find_class_from_class_loader(env, h_name, init, h_loader,
   841 
       
   842   jboolean link = !ClassForNameDeferLinking;
       
   843   jclass result = find_class_from_class_loader(env, h_name, init, link, h_loader,
   831                                                h_prot, false, THREAD);
   844                                                h_prot, false, THREAD);
   832 
       
   833   if (log_is_enabled(Debug, class, resolve) && result != NULL) {
   845   if (log_is_enabled(Debug, class, resolve) && result != NULL) {
   834     trace_class_resolution(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(result)));
   846     trace_class_resolution(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(result)));
   835   }
   847   }
   836   return result;
   848   return result;
   837 JVM_END
   849 JVM_END
   864     class_loader = from_class->class_loader();
   876     class_loader = from_class->class_loader();
   865     protection_domain = from_class->protection_domain();
   877     protection_domain = from_class->protection_domain();
   866   }
   878   }
   867   Handle h_loader(THREAD, class_loader);
   879   Handle h_loader(THREAD, class_loader);
   868   Handle h_prot  (THREAD, protection_domain);
   880   Handle h_prot  (THREAD, protection_domain);
   869   jclass result = find_class_from_class_loader(env, h_name, init, h_loader,
   881   jclass result = find_class_from_class_loader(env, h_name, init, false, h_loader,
   870                                                h_prot, true, thread);
   882                                                h_prot, true, thread);
   871 
   883 
   872   if (log_is_enabled(Debug, class, resolve) && result != NULL) {
   884   if (log_is_enabled(Debug, class, resolve) && result != NULL) {
   873     // this function is generally only used for class loading during verification.
   885     // this function is generally only used for class loading during verification.
   874     ResourceMark rm;
   886     ResourceMark rm;
  3422 }
  3434 }
  3423 
  3435 
  3424 
  3436 
  3425 // Shared JNI/JVM entry points //////////////////////////////////////////////////////////////
  3437 // Shared JNI/JVM entry points //////////////////////////////////////////////////////////////
  3426 
  3438 
  3427 jclass find_class_from_class_loader(JNIEnv* env, Symbol* name, jboolean init,
  3439 jclass find_class_from_class_loader(JNIEnv* env, Symbol* name, jboolean init, jboolean link,
  3428                                     Handle loader, Handle protection_domain,
  3440                                     Handle loader, Handle protection_domain,
  3429                                     jboolean throwError, TRAPS) {
  3441                                     jboolean throwError, TRAPS) {
       
  3442   // Initialization also implies linking - check for coherent args
       
  3443   assert((init && link) || !init, "incorrect use of init/link arguments");
       
  3444 
  3430   // Security Note:
  3445   // Security Note:
  3431   //   The Java level wrapper will perform the necessary security check allowing
  3446   //   The Java level wrapper will perform the necessary security check allowing
  3432   //   us to pass the NULL as the initiating class loader.  The VM is responsible for
  3447   //   us to pass the NULL as the initiating class loader.  The VM is responsible for
  3433   //   the checkPackageAccess relative to the initiating class loader via the
  3448   //   the checkPackageAccess relative to the initiating class loader via the
  3434   //   protection_domain. The protection_domain is passed as NULL by the java code
  3449   //   protection_domain. The protection_domain is passed as NULL by the java code
  3435   //   if there is no security manager in 3-arg Class.forName().
  3450   //   if there is no security manager in 3-arg Class.forName().
  3436   Klass* klass = SystemDictionary::resolve_or_fail(name, loader, protection_domain, throwError != 0, CHECK_NULL);
  3451   Klass* klass = SystemDictionary::resolve_or_fail(name, loader, protection_domain, throwError != 0, CHECK_NULL);
  3437 
  3452 
  3438   // Check if we should initialize the class
  3453   // Check if we should initialize the class (which implies linking), or just link it
  3439   if (init && klass->is_instance_klass()) {
  3454   if (init && klass->is_instance_klass()) {
  3440     klass->initialize(CHECK_NULL);
  3455     klass->initialize(CHECK_NULL);
       
  3456   } else if (link && klass->is_instance_klass()) {
       
  3457     InstanceKlass::cast(klass)->link_class(CHECK_NULL);
  3441   }
  3458   }
  3442   return (jclass) JNIHandles::make_local(env, klass->java_mirror());
  3459   return (jclass) JNIHandles::make_local(env, klass->java_mirror());
  3443 }
  3460 }
  3444 
  3461 
  3445 
  3462