性能问答>docker导致jdk11GC收集器变化吗?>
7回复
2年前

docker导致jdk11GC收集器变化吗?



各位大佬,jdk11默认的GC 应该是G1但是我的docker容器java -XX:+PrintCommandLineFlags -version 为啥是串行UseSerialGC.难道是因为我docker分配的内存小导致的吗?

3400 阅读
请先登录,再评论

如果core个数小于2或者物理内存小于1.75G,会默认使用UseSerialGC

2年前
回复 墨书:

大牛这个临界值哪里可以找到依据呢?特别想了解下这块。

2年前回复
回复 墨书:

谢谢

2年前回复

可以看下这段代码

void GCConfig::select_gc_ergonomically() {
  if (os::is_server_class_machine()) {
#if INCLUDE_G1GC
    FLAG_SET_ERGO_IF_DEFAULT(bool, UseG1GC, true);
#elif INCLUDE_PARALLELGC
    FLAG_SET_ERGO_IF_DEFAULT(bool, UseParallelGC, true);
#elif INCLUDE_SERIALGC
    FLAG_SET_ERGO_IF_DEFAULT(bool, UseSerialGC, true);
#endif
  } else {
#if INCLUDE_SERIALGC
    FLAG_SET_ERGO_IF_DEFAULT(bool, UseSerialGC, true);
#endif
  }
}

bool os::is_server_class_machine() {
  // First check for the early returns
  if (NeverActAsServerClassMachine) {
    return false;
  }
  if (AlwaysActAsServerClassMachine) {
    return true;
  }
  // Then actually look at the machine
  bool         result            = false;
  const unsigned int    server_processors = 2;
  const julong server_memory     = 2UL * G;
  // We seem not to get our full complement of memory.
  //     We allow some part (1/8?) of the memory to be "missing",
  //     based on the sizes of DIMMs, and maybe graphics cards.
  const julong missing_memory   = 256UL * M;

  /* Is this a server class machine? */
  if ((os::active_processor_count() >= (int)server_processors) &&
      (os::physical_memory() >= (server_memory - missing_memory))) {
    const unsigned int logical_processors =
      VM_Version::logical_processors_per_package();
    if (logical_processors > 1) {
      const unsigned int physical_packages =
        os::active_processor_count() / logical_processors;
      if (physical_packages >= server_processors) {
        result = true;
      }
    } else {
      result = true;
    }
  }
  return result;
}

其实也是Server Mode和Clinet Mode的区别

2年前
回复 你假笨:

谢谢大佬,小弟学习下

2年前回复

整个执行输出截图出来看看?包括JDK的版本输出

2年前
回复 墨书:

docker 已经调整了参数,原来只分配了1c

2年前回复