场景
有探索欲的同学,应该会跟我一样,在看JDK源码时,跟到最后,会出现native方法,类似下面这个方法查了下这两个目录的差别:
因为OpenJDK里,Java标准库和部分工具的源码repo(jdk目录)里,BSD和Linux的平台相关源码都是在solaris目录里的。 原本Sun JDK的源码里平台相关的目录就是从solaris和windows这两个目录开始的,后来Unix系的平台相关代码全都放在solaris目录下了,共用大部分代码。 作者:RednaxelaFX 链接:https://www.zhihu.com/question/58982441/answer/170264788 来源:知乎
unix系的平台
findJavaTz_md()方法的注释上写得很清楚了:将平台时区ID映射为Java时区ID
/* * findJavaTZ_md() maps platform time zone ID to Java time zone ID * using <java_home>/lib/tzmappings. If the TZ value is not found, it * trys some libc implementation dependent mappings. If it still * can't map to a Java time zone ID, it falls back to the GMT+/-hh:mm * form. `country', which can be null, is not used for UNIX platforms. */ /*ARGSUSED1*/ char * findJavaTZ_md(const char *java_home_dir, const char *country) { char *tz; char *javatz = NULL; char *freetz = NULL; tz = getenv("TZ"); #ifdef __linux__ if (tz == NULL) { #else #ifdef __solaris__ if (tz == NULL || *tz == '\0') { #endif #endif tz = getPlatformTimeZoneID(); freetz = tz; } /* * Remove any preceding ':' */ if (tz != NULL && *tz == ':') { tz++; } #ifdef __solaris__ if (strcmp(tz, "localtime") == 0) { tz = getSolarisDefaultZoneID(); freetz = tz; } #endif if (tz != NULL) { #ifdef __linux__ /* * Ignore "posix/" prefix. */ if (strncmp(tz, "posix/", 6) == 0) { tz += 6; } #endif javatz = strdup(tz); if (freetz != NULL) { free((void *) freetz); } } return javatz; }