docs: @VisibleForTesting
    Map<String, Plugin> instantiatePluginClasses(Map<PluginClassLoaderDef, ClassLoader> classloaders) {
      // instantiate plugins
      Map<String, Plugin> instancesByPluginKey = new HashMap<>();
      for (Map.Entry<PluginClassLoaderDef, ClassLoader> entry : classloaders.entrySet()) {
        PluginClassLoaderDef def = entry.getKey();
        ClassLoader classLoader = entry.getValue();
  
        // the same classloader can be used by multiple plugins
        for (Map.Entry<String, String> mainClassEntry : def.getMainClassesByPluginKey().entrySet()) {
          String pluginKey = mainClassEntry.getKey();
          String mainClass = mainClassEntry.getValue();
          try {
            instancesByPluginKey.put(pluginKey, (Plugin) classLoader.loadClass(mainClass).newInstance());
          } catch (UnsupportedClassVersionError e) {
            throw new IllegalStateException(String.format("The plugin [%s] does not support Java %s",
              pluginKey, SystemUtils.JAVA_VERSION_TRIMMED), e);
          } catch (Throwable e) {
            throw new IllegalStateException(String.format(
              "Fail to instantiate class [%s] of plugin [%s]", mainClass, pluginKey), e);
          }
        }
      }
      return instancesByPluginKey;
    }