< prev index next >

src/hotspot/share/runtime/threads.cpp

Print this page
*** 22,28 ***
--- 22,35 ---
   * questions.
   *
   */
  
  #include "precompiled.hpp"
+ #include "c1/c1_Runtime1.hpp"
  #include "cds/cds_globals.hpp"
  #include "cds/cdsConfig.hpp"
+ #include "cds/classPrelinker.hpp"
+ #include "cds/heapShared.hpp"
  #include "cds/metaspaceShared.hpp"
+ #include "cds/methodProfiler.hpp"
  #include "classfile/classLoader.hpp"
  #include "classfile/javaClasses.hpp"
  #include "classfile/javaThreadStatus.hpp"
  #include "classfile/systemDictionary.hpp"
+ #include "classfile/systemDictionaryShared.hpp"
  #include "classfile/vmClasses.hpp"
  #include "classfile/vmSymbols.hpp"
+ #include "code/SCCache.hpp"
  #include "compiler/compileBroker.hpp"
  #include "compiler/compileTask.hpp"
  #include "compiler/compilerThread.hpp"
  #include "gc/shared/barrierSet.hpp"
  #include "gc/shared/barrierSetNMethod.hpp"
  #include "gc/shared/gcVMOperations.hpp"
  #include "gc/shared/oopStorage.hpp"
  #include "gc/shared/oopStorageSet.hpp"
  #include "gc/shared/stringdedup/stringDedup.hpp"
+ #include "interpreter/interpreterRuntime.hpp"
  #include "jfr/jfrEvents.hpp"
  #include "jvm.h"
  #include "jvmtifiles/jvmtiEnv.hpp"
  #include "logging/log.hpp"
  #include "logging/logAsyncWriter.hpp"

*** 55,10 ***
--- 62,11 ---
  #include "memory/universe.hpp"
  #include "nmt/memTracker.hpp"
  #include "oops/instanceKlass.hpp"
  #include "oops/klass.inline.hpp"
  #include "oops/oop.inline.hpp"
+ #include "opto/runtime.hpp"
  #include "oops/symbol.hpp"
  #include "prims/jvm_misc.hpp"
  #include "prims/jvmtiAgentList.hpp"
  #include "runtime/arguments.hpp"
  #include "runtime/fieldDescriptor.inline.hpp"

*** 317,10 ***
--- 325,21 ---
    if (result.get_jint() != JNI_OK) {
      vm_exit_during_initialization(); // no message or exception
    }
  
    universe_post_module_init();
+ 
+   // Preload all boot classes outside of java.base module
+   ClassPrelinker::runtime_preload(THREAD, Handle());
+   if (CDSConfig::is_loading_full_module_graph()) {
+     // SystemDictionary::java_{platform,system}_loader are already assigned. We can spin
+     // this up a little quicker.
+     assert(SystemDictionary::java_platform_loader() != nullptr, "must be");
+     assert(SystemDictionary::java_system_loader() != nullptr,   "must be");
+     ClassPrelinker::runtime_preload(THREAD, Handle(THREAD, SystemDictionary::java_platform_loader()));
+     ClassPrelinker::runtime_preload(THREAD, Handle(THREAD, SystemDictionary::java_system_loader()));
+   }
  }
  
  // Phase 3. final setup - set security manager, system class loader and TCCL
  //
  //     This will instantiate and set the security manager, set the system class

*** 350,10 ***
--- 369,12 ---
    Handle thread_group = create_initial_thread_group(CHECK);
    Universe::set_main_thread_group(thread_group());
    initialize_class(vmSymbols::java_lang_Thread(), CHECK);
    create_initial_thread(thread_group, main_thread, CHECK);
  
+   HeapShared::init_box_classes(CHECK);
+ 
    // The VM creates objects of this class.
    initialize_class(vmSymbols::java_lang_Module(), CHECK);
  
  #ifdef ASSERT
    InstanceKlass *k = vmClasses::UnsafeConstants_klass();

*** 398,17 ***
--- 419,53 ---
    initialize_class(vmSymbols::java_lang_StackOverflowError(), CHECK);
    initialize_class(vmSymbols::java_lang_IllegalMonitorStateException(), CHECK);
    initialize_class(vmSymbols::java_lang_IllegalArgumentException(), CHECK);
  }
  
+ bool Threads::initialize_compilation(TRAPS) {
+   // initialize compiler(s)
+   bool force_JVMCI_initialization = false;
+ 
+ #if defined(COMPILER1) || COMPILER2_OR_JVMCI
+   bool init_compilation = true;
+ #if INCLUDE_JVMCI
+   if (EnableJVMCI) {
+     // Initialize JVMCI eagerly when it is explicitly requested.
+     // Or when JVMCILibDumpJNIConfig or JVMCIPrintProperties is enabled.
+     force_JVMCI_initialization = EagerJVMCI || JVMCIPrintProperties || JVMCILibDumpJNIConfig;
+     if (!force_JVMCI_initialization && UseJVMCICompiler && !UseJVMCINativeLibrary && (!UseInterpreter || !BackgroundCompilation)) {
+       // Force initialization of jarjvmci otherwise requests for blocking
+       // compilations will not actually block until jarjvmci is initialized.
+       force_JVMCI_initialization = true;
+     }
+     if (JVMCIPrintProperties || JVMCILibDumpJNIConfig) {
+       // Both JVMCILibDumpJNIConfig and JVMCIPrintProperties exit the VM
+       // so compilation should be disabled. This prevents dumping or
+       // printing from happening more than once.
+       init_compilation = false;
+     }
+   }
+ #endif
+   if (init_compilation) {
+     CompileBroker::compilation_init(CHECK_false);
+   }
+ #endif
+ 
+   return force_JVMCI_initialization;
+ }
+ 
  void Threads::initialize_jsr292_core_classes(TRAPS) {
    TraceTime timer("Initialize java.lang.invoke classes", TRACETIME_LOG(Info, startuptime));
  
    initialize_class(vmSymbols::java_lang_invoke_MethodHandle(), CHECK);
    initialize_class(vmSymbols::java_lang_invoke_ResolvedMethodName(), CHECK);
    initialize_class(vmSymbols::java_lang_invoke_MemberName(), CHECK);
    initialize_class(vmSymbols::java_lang_invoke_MethodHandleNatives(), CHECK);
+ 
+   if (UseSharedSpaces) {
+     HeapShared::initialize_java_lang_invoke(CHECK);
+   }
  }
  
  jint Threads::create_vm(JavaVMInitArgs* args, bool* canTryAgain) {
    extern void JDK_Version_init();
  

*** 530,10 ***
--- 587,12 ---
    main_thread->record_stack_base_and_size();
    main_thread->register_thread_stack_with_NMT();
    main_thread->set_active_handles(JNIHandleBlock::allocate_block());
    MACOS_AARCH64_ONLY(main_thread->init_wx());
  
+   MutexLockerImpl::init_counters(); // depends on mutex_init(), perfMemory_init(), and Thread::initialize_thread_current().
+ 
    if (!main_thread->set_as_starting_thread()) {
      vm_shutdown_during_initialization(
                                        "Failed necessary internal allocation. Out of swap space");
      main_thread->smr_delete();
      *canTryAgain = false; // don't let caller call JNI_CreateJavaVM again

*** 546,17 ***
--- 605,23 ---
  
    // Initialize Java-Level synchronization subsystem
    ObjectMonitor::Initialize();
    ObjectSynchronizer::initialize();
  
+   Deoptimization::init_counters();
+   VMThread::init_counters();
+ 
    // Initialize global modules
    jint status = init_globals();
    if (status != JNI_OK) {
      main_thread->smr_delete();
      *canTryAgain = false; // don't let caller call JNI_CreateJavaVM again
      return status;
    }
+   if (xtty != nullptr)
+     xtty->elem("vm_main_thread thread='" UINTX_FORMAT "'",
+                (uintx) main_thread->osthread()->thread_id());
  
    // Create WatcherThread as soon as we can since we need it in case
    // of hangs during error reporting.
    WatcherThread::start();
  

*** 690,36 ***
    ServiceThread::initialize();
  
    // Start the monitor deflation thread:
    MonitorDeflationThread::initialize();
  
!   // initialize compiler(s)
! #if defined(COMPILER1) || COMPILER2_OR_JVMCI
!   bool init_compilation = true;
- #if INCLUDE_JVMCI
    bool force_JVMCI_initialization = false;
!   if (EnableJVMCI) {
!     // Initialize JVMCI eagerly when it is explicitly requested.
-     // Or when JVMCILibDumpJNIConfig or JVMCIPrintProperties is enabled.
-     force_JVMCI_initialization = EagerJVMCI || JVMCIPrintProperties || JVMCILibDumpJNIConfig;
-     if (!force_JVMCI_initialization && UseJVMCICompiler && !UseJVMCINativeLibrary && (!UseInterpreter || !BackgroundCompilation)) {
-       // Force initialization of jarjvmci otherwise requests for blocking
-       // compilations will not actually block until jarjvmci is initialized.
-       force_JVMCI_initialization = true;
-     }
-     if (JVMCIPrintProperties || JVMCILibDumpJNIConfig) {
-       // Both JVMCILibDumpJNIConfig and JVMCIPrintProperties exit the VM
-       // so compilation should be disabled. This prevents dumping or
-       // printing from happening more than once.
-       init_compilation = false;
-     }
    }
! #endif
!   if (init_compilation) {
-     CompileBroker::compilation_init(CHECK_JNI_ERR);
-   }
- #endif
  
    // Start string deduplication thread if requested.
    if (StringDedup::is_enabled()) {
      StringDedup::start();
    }
--- 755,19 ---
    ServiceThread::initialize();
  
    // Start the monitor deflation thread:
    MonitorDeflationThread::initialize();
  
!   // Start the method sampler
!   MethodProfiler::initialize();
! 
    bool force_JVMCI_initialization = false;
!   if (!CDSConfig::has_preloaded_classes()) {
!     force_JVMCI_initialization = initialize_compilation(CHECK_JNI_ERR);
    }
! 
!   ClassPrelinker::init_javabase_preloaded_classes(CHECK_JNI_ERR);
  
    // Start string deduplication thread if requested.
    if (StringDedup::is_enabled()) {
      StringDedup::start();
    }

*** 728,10 ***
--- 776,15 ---
    // It is done after compilers are initialized, because otherwise compilations of
    // signature polymorphic MH intrinsics can be missed
    // (see SystemDictionary::find_method_handle_intrinsic).
    initialize_jsr292_core_classes(CHECK_JNI_ERR);
  
+   if (CDSConfig::has_preloaded_classes()) {
+     force_JVMCI_initialization = initialize_compilation(CHECK_JNI_ERR);
+     ClassPrelinker::replay_training_at_init_for_javabase_preloaded_classes(CHECK_JNI_ERR);
+   }
+ 
    // This will initialize the module system.  Only java.base classes can be
    // loaded until phase 2 completes
    call_initPhase2(CHECK_JNI_ERR);
  
    JFR_ONLY(Jfr::on_create_vm_2();)

*** 769,10 ***
--- 822,15 ---
    if (force_JVMCI_initialization) {
      JVMCI::initialize_compiler(CHECK_JNI_ERR);
    }
  #endif
  
+ #if defined(COMPILER2)
+   // Pre-load cached compiled methods
+   SCCache::preload_code(THREAD);
+ #endif
+ 
    if (NativeHeapTrimmer::enabled()) {
      NativeHeapTrimmer::initialize();
    }
  
    // Always call even when there are not JVMTI environments yet, since environments

*** 821,12 ***
    create_vm_timer.end();
  #ifdef ASSERT
    _vm_complete = true;
  #endif
  
!   if (CDSConfig::is_dumping_static_archive()) {
      MetaspaceShared::preload_and_dump();
    }
  
    return JNI_OK;
  }
  
--- 879,37 ---
    create_vm_timer.end();
  #ifdef ASSERT
    _vm_complete = true;
  #endif
  
!   if (CDSConfig::is_dumping_classic_static_archive()) {
+     // Classic -Xshare:dump, aka "old workflow"
+     MetaspaceShared::preload_and_dump();
+   } else if (CDSConfig::is_dumping_final_static_archive()) {
+     // TODO: copy the verification and loader constraints from preimage to final image
+     // TODO: load archived classes for custom loaders as well.
+     log_info(cds)("Dumping final image of CacheDataStore %s", CacheDataStore);
      MetaspaceShared::preload_and_dump();
+     vm_direct_exit(0, "CacheDataStore dumping is complete");
+   }
+ 
+   log_info(init)("Before main:");
+   log_vm_init_stats();
+ 
+   if (UsePerfData) {
+     if (ProfileVMLocks) {
+       main_thread->set_profile_vm_locks(true);
+     }
+     if (ProfileVMCalls) {
+       main_thread->set_profile_vm_calls(true);
+     }
+     if (ProfileRuntimeCalls) {
+       main_thread->set_profile_rt_calls(true);
+     }
+     if (ProfileVMOps) {
+       main_thread->set_profile_vm_ops(true);
+     }
    }
  
    return JNI_OK;
  }
  
< prev index next >