{"id":172295,"date":"2013-03-11T18:42:03","date_gmt":"2013-03-11T14:42:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=172295"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=172295","title":{"rendered":"<span class=\"post_title\">\u0422\u0430\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 FrontCache<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t\u0412\u0441\u0451 \u043d\u0430\u0447\u0430\u043b\u043e\u0441\u044c \u0441 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u044f \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0439 \u0440\u0430\u0437 \u043a\u043e\u0432\u044b\u0440\u044f\u043b \u0432 <a href=\"http:\/\/www.eclipse.org\/mat\/\">Eclipse Memory Analyzer<\/a> \u0434\u0430\u043c\u043f \u043f\u0430\u043c\u044f\u0442\u0438 Java-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438 \u0443\u0432\u0438\u0434\u0435\u043b \u0442\u0430\u043a\u0443\u044e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0443\u044e \u0432\u0435\u0449\u044c:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/1d2\/e51\/ce7\/1d2e51ce7b0d5493be839a8aa844145f.png\"\/><br \/>  \u0421 \u043a\u043e\u0434\u043e\u043c HashMap \u044f \u0437\u043d\u0430\u043a\u043e\u043c \u0432\u0435\u0441\u044c\u043c\u0430 \u043d\u0435\u043f\u043b\u043e\u0445\u043e, \u043d\u043e \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 FrontCache \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u0442\u0430\u043c \u043d\u0435 \u0432\u0438\u0434\u0435\u043b. \u041c\u043e\u0436\u0435\u0442, \u0441 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u043c \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435\u043c JDK \u043c\u043d\u0435 \u043f\u0440\u0438\u0441\u043b\u0430\u043b\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0451\u043d\u043d\u044b\u0439 HashMap? \u042f \u0437\u0430\u0433\u043b\u044f\u043d\u0443\u043b \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438, \u043d\u043e \u0441\u043b\u043e\u0432\u0430 \u00abfront\u00bb \u0442\u0430\u043c \u043d\u0435 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043b\u043e\u0441\u044c. \u0421\u0442\u0430\u043b\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u043e\u0442\u043a\u0443\u0434\u0430 \u0436\u0435 \u044d\u0442\u043e\u0442 \u043a\u043b\u0430\u0441\u0441 \u0431\u0435\u0440\u0451\u0442\u0441\u044f \u0438 \u0447\u0442\u043e \u043e\u043d \u0434\u0435\u043b\u0430\u0435\u0442.<br \/>  <a name=\"habracut\"><\/a><br \/>  \u041f\u043e\u0440\u044b\u0432\u0448\u0438\u0441\u044c \u0432 JRE (\u0443 \u043c\u0435\u043d\u044f 1.7u10, \u043d\u043e \u0438 \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0445 1.6 \u0442\u043e\u0436\u0435 \u044d\u0442\u043e \u0435\u0441\u0442\u044c), \u044f \u043d\u0430\u0448\u0451\u043b \u043b\u044e\u0431\u043e\u043f\u044b\u0442\u043d\u044b\u0439 \u0434\u0436\u0430\u0440\u0438\u043a: alt-rt.jar, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0438 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043b\u0441\u044f HashMap$FrontCache.class, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u0440\u0443\u0433\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 (LinkedHashMap, TreeMap, BigDecimal, BigInteger, MutableBigInteger \u0438 \u0438\u0445 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b). \u041e\u0431\u044b\u0447\u043d\u043e \u044d\u0442\u0438 \u043a\u043b\u0430\u0441\u0441\u044b \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u044e\u0442\u0441\u044f \u0438\u0437 rt.jar. \u041f\u043e\u0447\u0435\u043c\u0443 \u0436\u0435 \u043e\u043d\u0438 \u0441\u0442\u0430\u043b\u0438 \u0433\u0440\u0443\u0437\u0438\u0442\u044c\u0441\u044f \u0438\u0437 \u044d\u0442\u043e\u0433\u043e \u0437\u0430\u0433\u0430\u0434\u043e\u0447\u043d\u043e\u0433\u043e \u0434\u0436\u0430\u0440\u0438\u043a\u0430?<\/p>\n<p>  \u042f \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u043b, \u0447\u0442\u043e \u043d\u0435\u0434\u0430\u0432\u043d\u043e \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043b \u0441 \u043e\u043f\u0446\u0438\u044f\u043c\u0438 Java-\u043c\u0430\u0448\u0438\u043d\u044b \u0438, \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u0432\u043a\u043b\u044e\u0447\u0438\u043b -XX:+AggressiveOpts. \u041d\u0430 \u0441\u0430\u0439\u0442\u0435 \u041e\u0440\u0430\u043a\u043b\u0430 \u043f\u0440\u043e \u044d\u0442\u043e\u0442 \u043a\u043b\u044e\u0447 <a href=\"http:\/\/www.oracle.com\/technetwork\/java\/javase\/tech\/vmoptions-jsp-140102.html\">\u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e<\/a> \u0441\u043a\u0443\u043f\u043e:  <\/p>\n<blockquote><p>Turn on point performance compiler optimizations that are expected to be default in upcoming releases. <\/p><\/blockquote>\n<p>  \u041d\u0430 \u0425\u0430\u0431\u0440\u0435 <a href=\"http:\/\/habrahabr.ru\/post\/160049\/#habracut\">\u0431\u044b\u043b\u0430 \u043f\u043e\u043f\u044b\u0442\u043a\u0430<\/a> \u043e\u0431\u044a\u044f\u0441\u043d\u0438\u0442\u044c \u044d\u0442\u0443 \u043e\u043f\u0446\u0438\u044e \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435, \u043c\u043e\u043b, \u044d\u0442\u043e \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u044f \u0434\u0440\u0443\u0433\u0438\u0445 \u043a\u043b\u044e\u0447\u0438\u043a\u043e\u0432. \u041f\u043e\u0440\u044b\u0432\u0448\u0438\u0441\u044c \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0430\u0445 <a href=\"http:\/\/openjdk.java.net\/\">OpenJDK<\/a> 7-\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u044f \u043f\u043e\u043d\u044f\u043b, \u0447\u0442\u043e \u043a\u043b\u044e\u0447\u0438\u043a\u0430\u043c\u0438 \u0434\u0435\u043b\u043e \u043d\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f. \u0412\u043e\u0442 \u0447\u0442\u043e \u043c\u044b \u0432\u0438\u0434\u0438\u043c \u0432 hotspot\/src\/share\/vm\/runtime\/arguments.cpp:  <\/p>\n<pre><code class=\"cpp\">jint Arguments::parse_vm_init_args(const JavaVMInitArgs* args) { ...   if (AggressiveOpts) {     \/\/ Insert alt-rt.jar between user-specified bootclasspath     \/\/ prefix and the default bootclasspath.  os::set_boot_path()     \/\/ uses meta_index_dir as the default bootclasspath directory.     const char* altclasses_jar = &quot;alt-rt.jar&quot;;     size_t altclasses_path_len = strlen(get_meta_index_dir()) + 1 +                                  strlen(altclasses_jar);     char* altclasses_path = NEW_C_HEAP_ARRAY(char, altclasses_path_len);     strcpy(altclasses_path, get_meta_index_dir());     strcat(altclasses_path, altclasses_jar);     scp.add_suffix_to_prefix(altclasses_path);     scp_assembly_required = true;     FREE_C_HEAP_ARRAY(char, altclasses_path);   } <\/code><\/pre>\n<p>  \u0410\u0433\u0430! \u0421 \u044d\u0442\u043e\u0439 \u043e\u043f\u0446\u0438\u0435\u0439 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u043c\u0438\u043c\u043e \u0432\u0441\u0435\u0433\u043e \u043f\u0440\u043e\u0447\u0435\u0433\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f alt-rt.jar. \u0412 \u044d\u0442\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f \u0438 \u0438\u0437 \u0441\u0432\u043e\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0432\u0448\u0438\u0441\u044c <code>System.getProperty(&quot;sun.boot.class.path&quot;)<\/code>. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0434\u043b\u044f \u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043f\u0440\u0438 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u044b\u0445 AggressiveOpts \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f.<\/p>\n<p>  \u041d\u043e \u0432 \u0447\u0451\u043c \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u0435 \u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 HashMap? \u042f \u0441\u0442\u0430\u043b \u0438\u0441\u043a\u0430\u0442\u044c \u0438\u0437\u043c\u0435\u043d\u0451\u043d\u043d\u044b\u0439 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a, \u043d\u043e \u0442\u0443\u0442 \u043c\u0435\u043d\u044f \u043f\u043e\u0441\u0442\u0438\u0433\u043b\u0430 \u043d\u0435\u0443\u0434\u0430\u0447\u0430. \u0412\u044b\u044f\u0441\u043d\u0438\u043b\u043e\u0441\u044c, \u0447\u0442\u043e \u044d\u0442\u043e\u0442 jar \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e jdk\/make\/altclasses\/Makefile, \u0430 \u043a\u0430\u0442\u0430\u043b\u043e\u0433 \u0441 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0430\u043c\u0438 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0435\u043d \u043a\u0430\u043a  <\/p>\n<pre><code class=\"cmake\">ALTCLASSES_SRCDIR = $(CLOSED_SRC)\/share\/altclasses<\/code><\/pre>\n<p>  \u042d\u0442\u043e \u0437\u0430\u043f\u0430\u0445\u043b\u043e \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0440\u043e\u0448\u043e, \u0438 \u0444\u0430\u0439\u043b jdk\/make\/common\/Defs.gmk \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0434\u0438\u043b \u043c\u043e\u0438 \u043e\u043f\u0430\u0441\u0435\u043d\u0438\u044f:  <\/p>\n<pre><code class=\"cmake\"># Files that cannot be included in the OpenJDK distribution are # collected under a parent directory which contains just those files. ifndef CLOSED_SRC   CLOSED_SRC  = $(BUILDDIR)\/..\/src\/closed endif<\/code><\/pre>\n<p>  \u0420\u0430\u0437\u0443\u043c\u0435\u0435\u0442\u0441\u044f, \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0430 \u0432 \u043a\u043e\u043c\u043f\u043b\u0435\u043a\u0442\u0435 \u043d\u0435 \u0438\u0434\u0451\u0442. \u041d\u0430 \u0432\u0441\u044f\u043a\u0438\u0439 \u0441\u043b\u0443\u0447\u0430\u0439 \u044f \u0432\u044b\u043a\u0430\u0447\u0430\u043b JDK 8, \u043d\u043e \u0442\u0430\u043c \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f \u0431\u044b\u043b\u0430 \u043d\u0435 \u043b\u0443\u0447\u0448\u0435. Oracle \u043f\u0440\u044f\u0447\u0435\u0442 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 HashMap.<\/p>\n<p>  \u041f\u043e\u0440\u044b\u0432\u0448\u0438\u0441\u044c \u0432 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0435, \u044f \u043d\u0430\u043f\u043e\u0440\u043e\u043b\u0441\u044f \u043d\u0430 <a href=\"http:\/\/jdk7src.sourceforge.net\/\">\u043f\u0440\u043e\u0435\u043a\u0442<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0431\u043d\u0430\u0434\u0451\u0436\u0438\u043b \u043c\u0435\u043d\u044f, \u043d\u043e \u043d\u0430\u043f\u0440\u0430\u0441\u043d\u043e. \u041d\u0430 \u0433\u043b\u0430\u0432\u043d\u043e\u0439 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e, \u0447\u0442\u043e \u0442\u0430\u043c \u0435\u0441\u0442\u044c \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0438\u0437 jre\\lib\\alt-rt.jar, \u043f\u043e \u0444\u0430\u043a\u0442\u0443 \u0436\u0435 \u0442\u0430\u043c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f HashMap \u0438 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432. \u0412\u0438\u0434\u0438\u043c\u043e, \u0430\u0432\u0442\u043e\u0440 \u043d\u0435 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0441\u044f, \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u0434\u0432\u0430 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430.<\/p>\n<p>  \u041e\u0441\u0442\u0430\u043b\u0441\u044f \u043e\u0434\u0438\u043d \u0441\u043f\u043e\u0441\u043e\u0431 \u2014 \u0434\u0438\u0437\u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0431\u0430\u0439\u0442\u043a\u043e\u0434 (javap -c -private) \u0438 \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0435\u0433\u043e \u0442\u0430\u043a. \u0427\u0442\u043e\u0431\u044b \u0431\u044b\u043b\u043e \u043f\u0440\u043e\u0449\u0435, \u044f \u0434\u0438\u0437\u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043b \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u0438 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 HashMap, \u043f\u0430\u0440\u043e\u0439 \u0440\u0435\u0433\u0435\u043a\u0441\u043f\u043e\u0432 \u0432\u044b\u043a\u0438\u043d\u0443\u043b \u043d\u0435\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0432\u0435\u0449\u0438 \u0438 \u0441\u0440\u0430\u0432\u043d\u0438\u043b diff&#8217;\u043e\u043c. \u0421\u043f\u0435\u0440\u0432\u0430 \u0432\u0441\u0451 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u043b\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0441\u0442\u0440\u0430\u0448\u043d\u043e, \u043d\u043e \u043f\u043e\u0442\u043e\u043c \u044f \u0434\u043e\u0433\u0430\u0434\u0430\u043b\u0441\u044f, \u0447\u0442\u043e \u043a\u043e\u0434 \u043e\u0431\u044b\u0447\u043d\u043e\u0433\u043e \u0438 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u043e\u0433\u043e HashMap \u044d\u0432\u043e\u043b\u044e\u0446\u0438\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0442\u044c \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 HashMap \u043d\u0430\u0434\u043e \u0441 \u043e\u0431\u0449\u0438\u043c \u043f\u0440\u0435\u0434\u043a\u043e\u043c, \u043a\u043e\u0438\u043c \u043e\u043a\u0430\u0437\u0430\u043b\u0441\u044f HashMap \u0438\u0437 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0445 \u0430\u043f\u0434\u0435\u0439\u0442\u043e\u0432 6-\u0439 JDK. \u0422\u0443\u0442 \u043a\u0430\u0440\u0442\u0438\u043d\u0430 \u0441\u0442\u0430\u043b\u0430 \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u0435\u0439, \u043d\u0435 \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u043e\u0441\u044c \u0434\u0430\u0436\u0435 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0434\u043b\u044f \u0434\u0435\u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u0432 Java-\u043a\u043e\u0434. \u0412 HashMap \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u044f\u0432\u0438\u043b\u043e\u0441\u044c HashMap.FrontCache frontCache, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435. \u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 FrontCache \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 capacity \u2014 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0445\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u0435. \u0412 \u043c\u0435\u0442\u043e\u0434 get(Object key) \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u0434:  <\/p>\n<pre><code class=\"java\">if(frontCache != null) { \tV value = frontCache.get(key); \tif(value != null) return value; }<\/code><\/pre>\n<p>  \u0412 \u043c\u0435\u0442\u043e\u0434 put(K key, V value) \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:  <\/p>\n<pre><code class=\"java\">if(frontCache != null) { \tfrontCache.put(key, value); }<\/code><\/pre>\n<p>  \u0415\u0441\u0442\u044c \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0438 \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u0430\u0445, \u043d\u043e \u0441\u0443\u0442\u044c \u0437\u0434\u0435\u0441\u044c. \u042f\u0441\u043d\u043e, \u0447\u0442\u043e frontCache \u2014 \u043a\u0430\u043a\u043e\u0435-\u0442\u043e \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u043e\u0435 (\u0432\u0438\u0434\u0438\u043c\u043e, \u0431\u043e\u043b\u0435\u0435 \u0431\u044b\u0441\u0442\u0440\u043e\u0435) \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u0434\u0430\u043d\u043d\u044b\u0445. \u041f\u0440\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u043e\u043d \u0432 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0438\u0449\u0435\u0442\u0441\u044f \u0432 frontCache, \u0430 \u043f\u0440\u0438 \u0437\u0430\u043d\u0435\u0441\u0435\u043d\u0438\u0438 \u043d\u043e\u0432\u043e\u0433\u043e \u0437\u0430\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u0438 \u0432 frontCache, \u0438 \u0432 \u043e\u0431\u044b\u0447\u043d\u0443\u044e \u0445\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u0443. \u0427\u0442\u043e \u0436\u0435 \u0442\u0430\u043a\u043e\u0433\u043e \u0443\u0441\u043a\u043e\u0440\u044f\u0435\u0442 \u043a\u043b\u0430\u0441\u0441 FrontCache? \u0412\u043e\u0442 \u043a\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u0441\u0430\u043c\u044b\u0435 \u0432\u0430\u0436\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0438\u0437 \u043d\u0435\u0433\u043e:  <\/p>\n<pre><code class=\"java\">private class FrontCache { \tprivate Object[] cache; \tprivate int bitMask; \t \tpublic FrontCache(int capacity) { \t\tthis.cache = new Object[capacity]; \t\tthis.bitMask = makeBitMask(capacity); \t}  \tpublic int makeBitMask(int capacity) { \t\treturn -1 &lt;&lt; (32 - Integer.numberOfLeadingZeros(capacity - 1)); \t} \t \tpublic boolean inRange(int value) { \t\treturn (value & bitMask) == 0; \t} \t \tpublic V get(Object key) { \t\tif(key instanceof Integer) { \t\t\tint intKey = ((Integer)key).intValue(); \t\t\tif(inRange(intKey)) { \t\t\t\treturn (V) cache[intKey]; \t\t\t} \t\t} \t\treturn null; \t} \t \tprivate void put(K key, V value) { \t\tif(key instanceof Integer) { \t\t\tint intKey = ((Integer)key).intValue(); \t\t\tif(inRange(intKey)) { \t\t\t\tcache[intKey] = value; \t\t\t} \t\t} \t} }<\/code><\/pre>\n<p>\u041f\u0440\u043e\u0447\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0441\u043b\u0443\u0436\u0430\u0442 \u0434\u043b\u044f \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u043a\u044d\u0448\u0430 \u0438 \u0442. \u0434. \u041d\u043e \u0438\u0434\u0435\u044f \u0438\u0437 \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u043f\u043e\u043d\u044f\u0442\u043d\u0430: \u0435\u0441\u043b\u0438 \u043a\u043b\u044e\u0447 \u2014 Integer \u0438 \u043e\u043d \u043f\u043e\u043f\u0430\u0434\u0430\u0435\u0442 \u0432 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d \u043e\u0442 0 \u0434\u043e capacity-1 (\u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u043e \u0441\u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u0430), \u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0437\u0430\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u0432 \u043c\u0430\u0441\u0441\u0438\u0432 \u043f\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0443 \u0441 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u043e\u0432\u044b\u043c \u043d\u043e\u043c\u0435\u0440\u043e\u043c \u0431\u0435\u0437 \u0432\u0441\u044f\u043a\u0438\u0445 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0439 \u0438 \u0445\u044d\u0448-\u0444\u0443\u043d\u043a\u0446\u0438\u0439. <\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0436\u0435 \u043a\u043b\u044e\u0447\u0438 \u043d\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0446\u0435\u043b\u044b\u043c\u0438 \u0447\u0438\u0441\u043b\u0430\u043c\u0438, \u0442\u043e FrontCache \u043f\u0440\u043e\u0441\u0442\u043e \u0431\u0435\u0441\u043f\u043e\u043b\u0435\u0437\u0435\u043d. \u041e\u0434\u043d\u0430\u043a\u043e \u043c\u0430\u0441\u0441\u0438\u0432 \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0434\u0435\u043b\u0430\u044e\u0442\u0441\u044f \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0441 HashMap.<\/p>\n<p>  \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0442\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u0434\u0430\u0436\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u0430\u043c\u044f\u0442\u0438, \u0442\u0430\u043a \u043a\u0430\u043a HashMap.Entry \u0438\u043c\u0435\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 setValue, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0442\u0435\u043f\u0435\u0440\u044c \u0434\u043e\u043b\u0436\u0435\u043d \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 FrontCache \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u043a\u0430\u0436\u0434\u044b\u0439 Entry \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0430 \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0441\u0430\u043c HashMap, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0434\u043e 8 \u043b\u0438\u0448\u043d\u0438\u0445 \u0431\u0430\u0439\u0442 \u043d\u0430 \u0437\u0430\u043f\u0438\u0441\u044c.<\/p>\n<p>  \u041e\u0442\u043a\u0440\u044b\u0442\u0438\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0448\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043b\u043e \u043c\u0435\u043d\u044f. \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u043c\u044b \u0432\u043e \u0441\u043b\u0430\u0432\u0443 <a href=\"https:\/\/bitbucket.org\/robeden\/trove\/\">Trove<\/a> \u043f\u043e\u0447\u0442\u0438 \u043d\u0435 \u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u043a\u043b\u044e\u0447\u0430\u043c\u0438 \u0432\u0440\u043e\u0434\u0435 Integer, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c, \u0447\u0442\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u043f\u0440\u0430\u0441\u043d\u043e \u0435\u0441\u0442 \u0432\u0440\u0435\u043c\u044f \u0438 \u043f\u0430\u043c\u044f\u0442\u044c. \u0412 \u043e\u0431\u0449\u0435\u043c, \u044f \u0440\u0435\u0448\u0438\u043b, \u0447\u0442\u043e AggressiveOpts \u043b\u0443\u0447\u0448\u0435 \u043e\u0442\u043a\u043b\u044e\u0447\u0438\u0442\u044c. \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u044f \u043d\u0435 \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u043b\u0441\u044f, \u0447\u0442\u043e \u0442\u0430\u043c \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u043e\u0441\u044c \u0432 TreeMap \u0438 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u0430\u0445 (\u0432 LinkedHashMap \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u0441\u043c\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u043a\u0430\u043a \u0440\u0430\u0437 \u0441 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f\u043c\u0438 \u0432 HashMap.Entry \u0434\u043b\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 FrontCache). \u0411\u0443\u0434\u044c\u0442\u0435 \u043e\u0441\u0442\u043e\u0440\u043e\u0436\u043d\u0435\u0435 \u0438 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u043e\u043f\u0446\u0438\u0439, \u0441\u043c\u044b\u0441\u043b\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0432\u044b \u0434\u043e \u043a\u043e\u043d\u0446\u0430 \u043d\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442\u0435.    \t \t\t   \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/172295\/\"> http:\/\/habrahabr.ru\/post\/172295\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t\u0412\u0441\u0451 \u043d\u0430\u0447\u0430\u043b\u043e\u0441\u044c \u0441 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u044f \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0439 \u0440\u0430\u0437 \u043a\u043e\u0432\u044b\u0440\u044f\u043b \u0432 <a href=\"http:\/\/www.eclipse.org\/mat\/\">Eclipse Memory Analyzer<\/a> \u0434\u0430\u043c\u043f \u043f\u0430\u043c\u044f\u0442\u0438 Java-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438 \u0443\u0432\u0438\u0434\u0435\u043b \u0442\u0430\u043a\u0443\u044e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0443\u044e \u0432\u0435\u0449\u044c:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/1d2\/e51\/ce7\/1d2e51ce7b0d5493be839a8aa844145f.png\"\/><br \/>  \u0421 \u043a\u043e\u0434\u043e\u043c HashMap \u044f \u0437\u043d\u0430\u043a\u043e\u043c \u0432\u0435\u0441\u044c\u043c\u0430 \u043d\u0435\u043f\u043b\u043e\u0445\u043e, \u043d\u043e \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 FrontCache \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u0442\u0430\u043c \u043d\u0435 \u0432\u0438\u0434\u0435\u043b. \u041c\u043e\u0436\u0435\u0442, \u0441 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u043c \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435\u043c JDK \u043c\u043d\u0435 \u043f\u0440\u0438\u0441\u043b\u0430\u043b\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0451\u043d\u043d\u044b\u0439 HashMap? \u042f \u0437\u0430\u0433\u043b\u044f\u043d\u0443\u043b \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438, \u043d\u043e \u0441\u043b\u043e\u0432\u0430 \u00abfront\u00bb \u0442\u0430\u043c \u043d\u0435 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043b\u043e\u0441\u044c. \u0421\u0442\u0430\u043b\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u043e\u0442\u043a\u0443\u0434\u0430 \u0436\u0435 \u044d\u0442\u043e\u0442 \u043a\u043b\u0430\u0441\u0441 \u0431\u0435\u0440\u0451\u0442\u0441\u044f \u0438 \u0447\u0442\u043e \u043e\u043d \u0434\u0435\u043b\u0430\u0435\u0442.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-172295","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/172295","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=172295"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/172295\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=172295"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=172295"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=172295"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}